snorenotify/autotest/snorebenchmark.cpp

105 lines
3.2 KiB
C++
Raw Normal View History

#include <libsnore/snore.h>
#include <libsnore/snore_p.h>
#include <libsnore/utils.h>
2017-08-01 06:50:40 +00:00
#include <libsnore/snoreconstants.h>
#include <QTextDocument>
#include <QtTest>
using namespace Snore;
class SnoreBenchmark : public QObject
{
Q_OBJECT
public:
2015-12-23 14:13:31 +00:00
SnoreBenchmark()
{
SnoreCore &instance = SnoreCore::instance();
2015-12-03 13:36:54 +00:00
instance.loadPlugins(SnorePlugin::Backend);
2017-08-01 06:50:40 +00:00
instance.setSettingsValue(Snore::Constants::SettingsKeys::Timeout, 1);
}
// clazy is complaining about this string but QStringLiteral won't work for the multiline string, so use QStringBuilder to silence it.
2015-11-27 13:50:59 +00:00
QString htmlTestString = QLatin1String("<i>Italic A</i><br>"
"<i>Italic B</i><br>"
"<b>Bold</b><br>"
"<u>Underline</u><br>"
"<font color=\"blue\">Font</font><br>"
"&lt;&amp;&gt;<br>"
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>") + QLatin1String("");
2015-07-02 12:24:11 +00:00
private Q_SLOTS:
void benchmarkUtilsToHtml();
void benchmarkUtilsToHtmlAllMarkup();
void benchmarkUtilsToPlain();
void benchmarkNotifications();
};
void SnoreBenchmark::benchmarkUtilsToHtml()
{
2015-12-03 13:36:54 +00:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NoMarkup), QLatin1String("Italic A\n"
2015-07-29 14:16:21 +00:00
"Italic B\n"
"Bold\n"
"Underline\n"
"Font\n"
"<&>\n"
"Website\n"));
2015-12-03 13:36:54 +00:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::Href), QLatin1String("Italic A\n"
2015-07-29 14:16:21 +00:00
"Italic B\n"
"Bold\n"
"Underline\n"
"Font\n"
"&lt;&amp;&gt;\n"
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a>\n"));
2015-12-03 13:36:54 +00:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::Href | Utils::Bold | Utils::Break |
Utils::Underline | Utils::Font | Utils::Italic), htmlTestString);
2015-09-29 11:28:27 +00:00
QBENCHMARK {
2015-12-03 13:36:54 +00:00
Utils::normalizeMarkup(htmlTestString, Utils::Href);
}
}
2015-06-23 15:13:01 +00:00
void SnoreBenchmark::benchmarkUtilsToHtmlAllMarkup()
{
2015-12-03 13:36:54 +00:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::AllMarkup), htmlTestString);
2015-06-23 15:13:01 +00:00
2015-09-29 11:28:27 +00:00
QBENCHMARK {
2015-12-03 13:36:54 +00:00
Utils::normalizeMarkup(htmlTestString, Utils::AllMarkup);
2015-06-23 15:13:01 +00:00
}
}
void SnoreBenchmark::benchmarkUtilsToPlain()
{
2015-09-29 11:28:27 +00:00
QBENCHMARK {
2015-12-03 13:36:54 +00:00
Utils::normalizeMarkup(htmlTestString, Utils::NoMarkup);
}
}
void SnoreBenchmark::benchmarkNotifications()
{
2015-12-23 14:13:31 +00:00
SnoreCore &instance = SnoreCore::instance();
int closed = 0;
2015-07-29 14:49:17 +00:00
connect(&instance, &SnoreCore::notificationClosed, [&closed](Notification) {
closed++;
});
Application app = SnoreCorePrivate::instance()->defaultApplication();
2015-11-27 13:50:59 +00:00
// QBENCHMARK_ONCE{
2015-07-29 14:16:21 +00:00
for (int i = 0; i < 100; ++i) {
QString number = QString::number(i);
Notification n(app, app.defaultAlert(), QLatin1String("Test ") + number, QLatin1String("Message ") + number, app.icon());
instance.broadcastNotification(n);
}
// }
while (closed < 100) {
QTest::qWait(100);
}
}
QTEST_MAIN(SnoreBenchmark)
#include "snorebenchmark.moc"