2015-06-23 15:04:57 +00:00
|
|
|
#include <libsnore/snore.h>
|
2015-07-29 14:09:54 +00:00
|
|
|
#include <libsnore/snore_p.h>
|
2015-06-23 15:04:57 +00:00
|
|
|
#include <libsnore/utils.h>
|
|
|
|
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
using namespace Snore;
|
|
|
|
|
2015-07-03 09:43:18 +00:00
|
|
|
class SnoreBenchmark : public QObject
|
|
|
|
{
|
2015-06-23 15:04:57 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2015-07-03 09:43:18 +00:00
|
|
|
SnoreBenchmark()
|
|
|
|
{
|
2015-07-29 14:09:54 +00:00
|
|
|
SnoreLog::setDebugLvl(3);
|
|
|
|
SnoreCore &instance = SnoreCore::instance();
|
|
|
|
instance.loadPlugins(SnorePlugin::BACKEND);
|
|
|
|
instance.setSettingsValue(QLatin1String("Timeout"), 1, LOCAL_SETTING);
|
2015-06-23 15:04:57 +00:00
|
|
|
}
|
|
|
|
|
2015-07-02 12:24:11 +00:00
|
|
|
QString htmlTestString = QLatin1String("<i>Italic A</i><br>"
|
2015-07-03 09:43:18 +00:00
|
|
|
"<i>Italic B</i><br>"
|
|
|
|
"<b>Bold</b><br>"
|
|
|
|
"<u>Underline</u><br>"
|
|
|
|
"<font color=\"blue\">Font</font><br>"
|
|
|
|
"<&><br>"
|
|
|
|
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>");
|
2015-07-29 14:09:54 +00:00
|
|
|
|
2015-07-02 12:24:11 +00:00
|
|
|
private Q_SLOTS:
|
2015-07-03 09:43:18 +00:00
|
|
|
void benchmarkUtilsToHtml();
|
|
|
|
void benchmarkUtilsToHtmlAllMarkup();
|
|
|
|
void benchmarkUtilsToPlain();
|
2015-07-29 14:09:54 +00:00
|
|
|
void benchmarkNotifications();
|
2015-06-23 15:04:57 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-07-03 09:43:18 +00:00
|
|
|
void SnoreBenchmark::benchmarkUtilsToHtml()
|
|
|
|
{
|
2015-06-23 15:04:57 +00:00
|
|
|
|
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"
|
|
|
|
"<&>\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 |
|
2015-06-23 15:04:57 +00:00
|
|
|
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:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:04:57 +00:00
|
|
|
void SnoreBenchmark::benchmarkUtilsToPlain()
|
|
|
|
{
|
|
|
|
QBENCHMARK{
|
2015-06-29 10:09:34 +00:00
|
|
|
Utils::normalizeMarkup(htmlTestString, Utils::NO_MARKUP);
|
2015-06-23 15:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-29 14:09:54 +00:00
|
|
|
|
|
|
|
void SnoreBenchmark::benchmarkNotifications()
|
|
|
|
{
|
|
|
|
SnoreCore &instance = SnoreCore::instance();
|
|
|
|
int closed = 0;
|
2015-07-29 14:49:17 +00:00
|
|
|
connect(&instance, &SnoreCore::notificationClosed, [&closed](Notification) {
|
2015-07-29 14:09:54 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-07-29 14:09:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:04:57 +00:00
|
|
|
QTEST_MAIN(SnoreBenchmark)
|
|
|
|
|
|
|
|
#include "snorebenchmark.moc"
|