snorenotify/autotest/display_test.cpp

78 lines
2.3 KiB
C++
Raw Normal View History

2015-08-25 22:35:42 +02: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():
2015-11-27 14:30:54 +01:00
app(QStringLiteral("Test"), Icon::defaultIcon())
2015-08-25 22:35:42 +02:00
{
SnoreCore &instance = SnoreCore::instance();
instance.loadPlugins(SnorePlugin::BACKEND);
2015-11-27 14:30:54 +01:00
instance.setSettingsValue(QStringLiteral("Timeout"), 5, LOCAL_SETTING);
2015-08-25 22:35:42 +02:00
SnoreCore::instance().registerApplication(app);
}
Application app;
private Q_SLOTS:
void displayTest();
2015-08-27 13:40:09 +02:00
void displayTestPlain();
2015-08-25 22:35:42 +02:00
private:
2015-08-27 23:08:42 +02:00
void testString(QString message)
{
2015-08-25 22:35:42 +02:00
qDebug() << Utils::normalizeMarkup(message, Utils::NO_MARKUP);
SnoreCore &snore = SnoreCore::instance();
QStringList backends = snore.pluginNames(SnorePlugin::BACKEND);
2015-08-27 23:08:42 +02:00
auto notify = [&backends, &snore, &message, this](Notification n) {
2015-08-25 22:35:42 +02:00
qDebug() << n << "closed";
qDebug() << backends.size();
2015-08-27 23:08:42 +02:00
if (backends.empty()) {
2015-08-25 22:35:42 +02:00
return;
}
QString old = snore.primaryNotificationBackend();
2015-08-27 23:08:42 +02:00
while (snore.primaryNotificationBackend() == old) {
2015-08-25 22:35:42 +02:00
QString p = backends.takeLast();
2015-11-27 14:30:54 +01:00
snore.setSettingsValue(QStringLiteral("PrimaryBackend"), p, LOCAL_SETTING);
2015-08-25 22:35:42 +02:00
SnoreCorePrivate::instance()->syncSettings();
if (snore.primaryNotificationBackend() == p) {
qDebug() << p;
2015-11-27 14:30:54 +01:00
snore.broadcastNotification(Notification(app, app.defaultAlert(), QStringLiteral("Title"), message, app.icon()));
2015-08-25 22:35:42 +02:00
}
}
};
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);
2015-11-27 14:30:54 +01:00
testString(QStringLiteral("<b>Test&#937;</b>&#x1f4a9;&#x1f600;"));
2015-08-25 22:35:42 +02:00
}
2015-08-27 13:40:09 +02:00
void DisplayTest::displayTestPlain()
2015-08-25 22:35:42 +02:00
{
app.hints().setValue("use-markup", false);
2015-08-27 13:15:17 +02:00
testString(QString::fromWCharArray(L"Test\u03A9\U0001F4A9\U0001F600"));
2015-08-25 22:35:42 +02:00
}
QTEST_MAIN(DisplayTest)
#include "display_test.moc"