snorenotify/autotest/display_test.cpp

86 lines
2.6 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>
2017-08-01 06:50:40 +00:00
#include <libsnore/snoreconstants.h>
2015-08-25 20:35:42 +00:00
#include <QTextDocument>
#include <QtTest>
using namespace Snore;
class DisplayTest : public QObject
{
Q_OBJECT
public:
DisplayTest():
2015-12-23 14:13:31 +00:00
app(QStringLiteral("Test"), Icon::defaultIcon())
{
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, 10);
2015-08-25 20:35:42 +00:00
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:
void testString(const QStringList &messages)
2015-12-23 14:13:31 +00:00
{
SnoreCore &snore = SnoreCore::instance();
#if 0
qDebug() << snore.pluginNames(SnorePlugin::Backend);
QStringList backends({QStringLiteral("Snore")});
#else
2015-12-03 13:36:54 +00:00
QStringList backends = snore.pluginNames(SnorePlugin::Backend);
#endif
auto notify = [&backends, &snore, &messages, 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();
while (!backends.empty() && snore.primaryNotificationBackend() == old) {
2015-08-25 20:35:42 +00:00
QString p = backends.takeLast();
2017-08-01 06:50:40 +00:00
snore.setSettingsValue(Snore::Constants::SettingsKeys::PrimaryBackend, p);
2015-08-25 20:35:42 +00:00
SnoreCorePrivate::instance()->syncSettings();
if (snore.primaryNotificationBackend() == p) {
for (const auto &message : messages) {
snore.broadcastNotification(Notification(app, app.defaultAlert(), QStringLiteral("Title"), message, app.icon()));
}
2015-08-25 20:35:42 +00:00
}
}
};
auto con = connect(&snore, &SnoreCore::notificationClosed, notify);
notify(Notification());
while (!backends.empty()) {
QTest::qWait(100);
}
QTest::qWait(10000);
2015-08-25 20:35:42 +00:00
disconnect(con);
}
};
void DisplayTest::displayTest()
{
app.hints().setValue("use-markup", true);
testString({QStringLiteral("<b>Test&#937;</b>&#x1f4a9;&#x1f600;"),
QString::fromUtf8("😀<b>💩Test&#937;</b>&#x1f4a9;&#x1f600;")});
}
2015-08-25 20:35:42 +00:00
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);
testString({QString::fromWCharArray(L"Test\u03A9\U0001F4A9\U0001F600"),
QString::fromUtf8("TestΩ💩😀")});
2015-08-25 20:35:42 +00:00
}
QTEST_MAIN(DisplayTest)
#include "display_test.moc"