~ci-train-bot/unity-notifications/unity-notifications-ubuntu-zesty-2022

« back to all changes in this revision

Viewing changes to test/notificationtest.cpp

  • Committer: Bileto Bot
  • Author(s): Lukáš Tinkl
  • Date: 2016-08-09 22:59:53 UTC
  • mfrom: (237.1.8 unity-notifications)
  • Revision ID: ci-train-bot@canonical.com-20160809225953-7846289hn9vp0wbn
Visible queue improvements (LP: #1606202)

Approved by: Michael Zanetti, Unity8 CI Bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
#include <QtTest/QtTest>
6
6
 
7
 
typedef struct {
8
 
    const char* before;
9
 
    const char* expected;
10
 
} TextComparisons;
11
 
 
12
7
class TestNotifications: public QObject
13
8
{
14
9
    Q_OBJECT
33
28
    QSharedPointer<Notification> n(new Notification(42, timeout, Notification::Low, "this is text"));
34
29
    NotificationModel m;
35
30
 
36
 
    QCOMPARE(m.numNotifications(), 1);
 
31
    QCOMPARE(m.numNotifications(), 0);
37
32
    m.insertNotification(n);
38
 
    QCOMPARE(m.numNotifications(), 2);
 
33
    QCOMPARE(m.numNotifications(), 1);
39
34
    m.removeNotification(n->getID());
40
 
    QCOMPARE(m.numNotifications(), 1);
 
35
    QCOMPARE(m.numNotifications(), 0);
41
36
}
42
37
 
43
38
void TestNotifications::testTypeSimple() {
60
55
    const int timeout = 1000;
61
56
    static NotificationModel *m = new NotificationModel(this);
62
57
    static NotificationServer *s = new NotificationServer(QDBusConnection::sessionBus(), *m);
63
 
    QStringList actions = QStringList();
 
58
    QStringList actions;
64
59
    QVariantMap hints;
65
 
    int id[3];
 
60
    int id[4];
66
61
 
67
62
    hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Low);
68
63
    id[0] = s->Notify ("test-name-low", 0, "icon-low", "summary-low", "body-low", actions, hints, timeout);
70
65
 
71
66
    hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Normal);
72
67
    id[1] = s->Notify ("test-name-normal", 0, "icon-normal", "summary-normal", "body-normal", actions, hints, timeout);
73
 
    QVERIFY(!m->showingNotification(id[0]));
 
68
    QVERIFY(m->showingNotification(id[0]));
74
69
    QVERIFY(m->showingNotification(id[1]));
75
 
    QVERIFY(m->queued() == 1);
 
70
    QVERIFY(m->getNotification(id[1]) == m->getDisplayedNotification(0)); // verify it's ordered by urgency
 
71
    QVERIFY(m->queued() == 0);
76
72
 
77
73
    hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Critical);
78
74
    id[2] = s->Notify ("test-name-critical", 0, "icon-critical", "summary-critical", "body-critical", actions, hints, timeout);
79
 
    QVERIFY(!m->showingNotification(id[0]));
80
 
    QVERIFY(!m->showingNotification(id[1]));
81
 
    QVERIFY(m->showingNotification(id[2]));
82
 
    QCOMPARE(m->queued(), 2);
 
75
    QVERIFY(m->showingNotification(id[0]));
 
76
    QVERIFY(m->showingNotification(id[1]));
 
77
    QVERIFY(m->showingNotification(id[2]));
 
78
    QVERIFY(m->getNotification(id[2]) == m->getDisplayedNotification(0)); // verify it's ordered by urgency
 
79
    QCOMPARE(m->queued(), 0);
 
80
 
 
81
    hints[SNAP_HINT] = QStringLiteral("true");
 
82
    hints[URGENCY_HINT] = QVariant::fromValue(Notification::Urgency::Normal);
 
83
    id[3] = s->Notify ("test-name-snap", 0, "icon-snap", "summary-snap", "body-snap", {"snap", "decision", "needs", "actions"}, hints, timeout);
 
84
    QVERIFY(m->showingNotification(id[0]));
 
85
    QVERIFY(m->showingNotification(id[1]));
 
86
    QVERIFY(m->showingNotification(id[2]));
 
87
    QVERIFY(m->showingNotification(id[3]));
 
88
    QVERIFY(m->getNotification(id[3]) == m->getDisplayedNotification(0)); // verify it's ordered by urgency and type, snap comes first
 
89
    QCOMPARE(m->queued(), 0);
 
90
 
 
91
    m->removeNotification(id[3]);
 
92
    QVERIFY(m->showingNotification(id[0]));
 
93
    QVERIFY(m->showingNotification(id[1]));
 
94
    QVERIFY(m->showingNotification(id[2]));
 
95
    QVERIFY(!m->showingNotification(id[3]));
 
96
    QCOMPARE(m->queued(), 0);
83
97
 
84
98
    m->removeNotification(id[2]);
85
 
    QVERIFY(!m->showingNotification(id[0]));
 
99
    QVERIFY(m->showingNotification(id[0]));
86
100
    QVERIFY(m->showingNotification(id[1]));
87
101
    QVERIFY(!m->showingNotification(id[2]));
88
 
    QCOMPARE(m->queued(), 1);
 
102
    QCOMPARE(m->queued(), 0);
89
103
 
90
104
    m->removeNotification(id[1]);
91
105
    QVERIFY(m->showingNotification(id[0]));
173
187
    m.insertNotification(n3);
174
188
    m.insertNotification(n4);
175
189
 
176
 
    QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("snap-decision-critical"));
 
190
    QCOMPARE(m.getDisplayedNotification(0)->getBody(), QString("snap-decision-critical"));
177
191
}
178
192
 
179
193
void TestNotifications::testVisualSDQueueWithoutCritical() {
190
204
    m.insertNotification(n3);
191
205
    m.insertNotification(n4);
192
206
 
193
 
    QCOMPARE(m.getDisplayedNotification(4)->getBody(), QString("snap-decision-1"));
194
 
    QCOMPARE(m.getDisplayedNotification(3)->getBody(), QString("snap-decision-2"));
195
 
    QCOMPARE(m.getDisplayedNotification(2)->getBody(), QString("snap-decision-3"));
196
 
    QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("snap-decision-4"));
 
207
    QCOMPARE(m.getDisplayedNotification(3)->getBody(), QString("snap-decision-1"));
 
208
    QCOMPARE(m.getDisplayedNotification(2)->getBody(), QString("snap-decision-2"));
 
209
    QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("snap-decision-3"));
 
210
    QCOMPARE(m.getDisplayedNotification(0)->getBody(), QString("snap-decision-4"));
197
211
}
198
212
 
199
213
void TestNotifications::testConfirmationValue() {
213
227
    m.insertNotification(ephemeral);
214
228
    m.insertNotification(confirmation);
215
229
 
216
 
    QCOMPARE(m.getDisplayedNotification(2)->getBody(), QString("ephemeral"));
217
 
    QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString(""));
 
230
    QCOMPARE(m.getDisplayedNotification(1)->getBody(), QString("ephemeral"));
 
231
    QCOMPARE(m.getDisplayedNotification(0)->getBody(), QString(""));
218
232
}
219
233
 
220
234
void TestNotifications::testTextFilter_data() {
273
287
    const int max = 20;
274
288
    static NotificationModel *m = new NotificationModel();
275
289
    static NotificationServer *s = new NotificationServer(QDBusConnection::sessionBus(), *m);
276
 
    QStringList actions = QStringList();
 
290
    QStringList actions;
277
291
    QVariantMap hints;
278
292
    int before = m->numNotifications();
279
293
 
280
 
    for (int i = 1; i <= max; i++) {
 
294
    for (int i = 0; i < max; i++) {
281
295
        s->Notify ("test-app-name",
282
296
                   0,
283
297
                   "test-icon",
288
302
                   timeout);
289
303
    }
290
304
 
291
 
    QCOMPARE(m->numNotifications(), max+1);
 
305
    QCOMPARE(m->numNotifications(), max);
292
306
 
293
307
    for (int i = max; i >= 1; i--) {
294
308
        m->getNotification(i)->close();
295
 
        QCOMPARE(m->numNotifications(), i);
 
309
        QCOMPARE(m->numNotifications(), i-1);
296
310
    }
297
311
 
298
312
    QCOMPARE(m->numNotifications(), before);