snorenotify/autotest/display_test.cpp

79 lines
2.3 KiB
C++
Raw Normal View History

2015-08-25 20:35:42 +00:00
#include <libsnore/snore.h>
#include <libsnore/snore_p.h>
#include <libsnore/utils.h>
#include <QTextDocument>
#include <QtTest>
using namespace Snore;
class DisplayTest : public QObject
{
Q_OBJECT
public:
DisplayTest():
app(QLatin1String("Test"), Icon::defaultIcon())
{
SnoreLog::setDebugLvl(3);
SnoreCore &instance = SnoreCore::instance();
instance.loadPlugins(SnorePlugin::BACKEND);
instance.setSettingsValue(QLatin1String("Timeout"), 5, LOCAL_SETTING);
SnoreCore::instance().registerApplication(app);
}
Application app;
private Q_SLOTS:
void displayTest();
2015-08-27 11:40:09 +00:00
void displayTestPlain();
2015-08-25 20:35:42 +00:00
private:
2015-08-27 21:08:42 +00:00
void testString(QString message)
{
2015-08-25 20:35:42 +00:00
qDebug() << Utils::normalizeMarkup(message, Utils::NO_MARKUP);
SnoreCore &snore = SnoreCore::instance();
QStringList backends = snore.pluginNames(SnorePlugin::BACKEND);
2015-08-27 21:08:42 +00:00
auto notify = [&backends, &snore, &message, this](Notification n) {
2015-08-25 20:35:42 +00:00
qDebug() << n << "closed";
qDebug() << backends.size();
2015-08-27 21:08:42 +00:00
if (backends.empty()) {
2015-08-25 20:35:42 +00:00
return;
}
QString old = snore.primaryNotificationBackend();
2015-08-27 21:08:42 +00:00
while (snore.primaryNotificationBackend() == old) {
2015-08-25 20:35:42 +00:00
QString p = backends.takeLast();
snore.setSettingsValue(QLatin1String("PrimaryBackend"), p, LOCAL_SETTING);
SnoreCorePrivate::instance()->syncSettings();
if (snore.primaryNotificationBackend() == p) {
qDebug() << p;
snore.broadcastNotification(Notification(app, app.defaultAlert(), QLatin1String("Title"), message, app.icon()));
}
}
};
auto con = connect(&snore, &SnoreCore::notificationClosed, notify);
notify(Notification());
while (!backends.empty()) {
QTest::qWait(100);
}
QTest::qWait(100);
disconnect(con);
}
};
void DisplayTest::displayTest()
{
app.hints().setValue("use-markup", true);
testString(QLatin1String("<b>Test&#937;</b>&#x1f4a9;&#x1f600;"));
}
2015-08-27 11:40:09 +00:00
void DisplayTest::displayTestPlain()
2015-08-25 20:35:42 +00:00
{
app.hints().setValue("use-markup", false);
2015-08-27 11:15:17 +00:00
testString(QString::fromWCharArray(L"Test\u03A9\U0001F4A9\U0001F600"));
2015-08-25 20:35:42 +00:00
}
QTEST_MAIN(DisplayTest)
#include "display_test.moc"