snorenotify/autotest/snorebenchmark.cpp

104 lines
3.2 KiB
C++
Raw Normal View History

#include <libsnore/snore.h>
#include <libsnore/snore_p.h>
#include <libsnore/utils.h>
#include <QTextDocument>
#include <QtTest>
using namespace Snore;
class SnoreBenchmark : public QObject
{
Q_OBJECT
public:
SnoreBenchmark()
{
SnoreCore &instance = SnoreCore::instance();
instance.loadPlugins(SnorePlugin::BACKEND);
2015-11-27 14:30:54 +01:00
instance.setSettingsValue(QStringLiteral("Timeout"), 1, LOCAL_SETTING);
}
// clazy is complaining about this string but QStringLiteral won't work for the multiline string, so use QStringBuilder to silence it.
2015-11-27 14:50:59 +01: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 14:24:11 +02:00
private Q_SLOTS:
void benchmarkUtilsToHtml();
void benchmarkUtilsToHtmlAllMarkup();
void benchmarkUtilsToPlain();
void benchmarkNotifications();
};
void SnoreBenchmark::benchmarkUtilsToHtml()
{
2015-07-02 14:24:11 +02:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP), QLatin1String("Italic A\n"
2015-07-29 16:16:21 +02:00
"Italic B\n"
"Bold\n"
"Underline\n"
"Font\n"
"<&>\n"
"Website\n"));
2015-07-02 14:24:11 +02:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::HREF), QLatin1String("Italic A\n"
2015-07-29 16:16:21 +02: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-06-29 12:09:34 +02:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::HREF | Utils::BOLD | Utils::BREAK |
Utils::UNDERLINE | Utils::FONT | Utils::ITALIC), htmlTestString);
2015-09-29 13:28:27 +02:00
QBENCHMARK {
2015-06-29 12:09:34 +02:00
Utils::normalizeMarkup(htmlTestString, Utils::HREF);
}
}
2015-06-23 17:13:01 +02:00
void SnoreBenchmark::benchmarkUtilsToHtmlAllMarkup()
{
2015-06-29 12:09:34 +02:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::ALL_MARKUP), htmlTestString);
2015-06-23 17:13:01 +02:00
2015-09-29 13:28:27 +02:00
QBENCHMARK {
2015-06-29 12:09:34 +02:00
Utils::normalizeMarkup(htmlTestString, Utils::ALL_MARKUP);
2015-06-23 17:13:01 +02:00
}
}
void SnoreBenchmark::benchmarkUtilsToPlain()
{
2015-09-29 13:28:27 +02:00
QBENCHMARK {
2015-06-29 12:09:34 +02:00
Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP);
}
}
void SnoreBenchmark::benchmarkNotifications()
{
SnoreCore &instance = SnoreCore::instance();
int closed = 0;
2015-07-29 16:49:17 +02:00
connect(&instance, &SnoreCore::notificationClosed, [&closed](Notification) {
closed++;
});
Application app = SnoreCorePrivate::instance()->defaultApplication();
2015-11-27 14:50:59 +01:00
// QBENCHMARK_ONCE{
2015-07-29 16:16:21 +02: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"