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>
|
2017-08-01 06:50:40 +00:00
|
|
|
#include <libsnore/snoreconstants.h>
|
2015-06-23 15:04:57 +00:00
|
|
|
|
|
|
|
#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-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);
|
2015-06-23 15:04:57 +00:00
|
|
|
}
|
|
|
|
|
2015-11-28 12:03:27 +00:00
|
|
|
// 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>"
|
|
|
|
"<&><br>"
|
2015-11-28 12:03:27 +00:00
|
|
|
"<a href=\"https://github.com/Snorenotify/Snorenotify\">Website</a><br>") + QLatin1String("");
|
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-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"
|
|
|
|
"<&>\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:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:04:57 +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);
|
2015-06-23 15:04:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-29 14:09:54 +00:00
|
|
|
|
|
|
|
void SnoreBenchmark::benchmarkNotifications()
|
|
|
|
{
|
2015-12-23 14:13:31 +00:00
|
|
|
SnoreCore &instance = SnoreCore::instance();
|
2015-07-29 14:09:54 +00:00
|
|
|
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-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);
|
|
|
|
}
|
2015-07-29 14:09:54 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-23 15:04:57 +00:00
|
|
|
QTEST_MAIN(SnoreBenchmark)
|
|
|
|
|
|
|
|
#include "snorebenchmark.moc"
|