snorenotify/autotest/snorebenchmark.cpp

104 lines
3.1 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()
{
SnoreLog::setDebugLvl(3);
SnoreCore &instance = SnoreCore::instance();
instance.loadPlugins(SnorePlugin::BACKEND);
instance.setSettingsValue(QLatin1String("Timeout"), 1, LOCAL_SETTING);
}
2015-07-02 12:24:11 +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>");
2015-07-02 12:24:11 +00:00
private Q_SLOTS:
void benchmarkUtilsToHtml();
void benchmarkUtilsToHtmlAllMarkup();
void benchmarkUtilsToPlain();
void benchmarkNotifications();
};
void SnoreBenchmark::benchmarkUtilsToHtml()
{
2015-07-02 12:24:11 +00:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP), 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-07-02 12:24:11 +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-06-29 10:09:34 +00:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::HREF | Utils::BOLD | Utils::BREAK |
Utils::UNDERLINE | Utils::FONT | Utils::ITALIC), htmlTestString);
QBENCHMARK{
2015-06-29 10:09:34 +00:00
Utils::normalizeMarkup(htmlTestString, Utils::HREF);
}
}
2015-06-23 15:13:01 +00:00
void SnoreBenchmark::benchmarkUtilsToHtmlAllMarkup()
{
2015-06-29 10:09:34 +00:00
QCOMPARE(Utils::normalizeMarkup(htmlTestString, Utils::ALL_MARKUP), htmlTestString);
2015-06-23 15:13:01 +00:00
QBENCHMARK{
2015-06-29 10:09:34 +00:00
Utils::normalizeMarkup(htmlTestString, Utils::ALL_MARKUP);
2015-06-23 15:13:01 +00:00
}
}
void SnoreBenchmark::benchmarkUtilsToPlain()
{
QBENCHMARK{
2015-06-29 10:09:34 +00:00
Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP);
}
}
void SnoreBenchmark::benchmarkNotifications()
{
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-07-29 14:16:21 +00:00
// QBENCHMARK_ONCE{
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"