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:
|
2017-01-20 12:49:35 +00:00
|
|
|
void testString(const QStringList &messages)
|
2015-12-23 14:13:31 +00:00
|
|
|
{
|
|
|
|
SnoreCore &snore = SnoreCore::instance();
|
2017-01-20 12:49:35 +00:00
|
|
|
#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);
|
2017-01-20 12:49:35 +00:00
|
|
|
#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();
|
2017-01-20 12:49:35 +00:00
|
|
|
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) {
|
2017-01-20 12:49:35 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-01-20 12:49:35 +00:00
|
|
|
QTest::qWait(10000);
|
2015-08-25 20:35:42 +00:00
|
|
|
disconnect(con);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void DisplayTest::displayTest()
|
|
|
|
{
|
|
|
|
app.hints().setValue("use-markup", true);
|
2017-01-20 12:49:35 +00:00
|
|
|
testString({QStringLiteral("<b>TestΩ</b>💩😀"),
|
|
|
|
QString::fromUtf8("😀<b>💩TestΩ</b>💩😀")});
|
|
|
|
}
|
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);
|
2017-01-20 12:49:35 +00:00
|
|
|
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"
|