~unity-api-team/unity-notifications/trunk

« back to all changes in this revision

Viewing changes to test/notificationservertest.cpp

  • Committer: CI Train Bot
  • Author(s): Pete Woods
  • Date: 2015-06-23 15:50:11 UTC
  • mfrom: (224.1.8 add-dbus-tests)
  • Revision ID: ci-train-bot@canonical.com-20150623155011-bnt9ubw5elnay015
Add end to end DBus tests and use XML introspection data
Approved by: Charles Kerr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include <notify-backend.h>
 
3
#include <NotificationsInterface.h>
 
4
 
 
5
#include <libqtdbustest/DBusTestRunner.h>
 
6
#include <libqtdbustest/QProcessDBusService.h>
 
7
#include <QtTest/QtTest>
 
8
 
 
9
using namespace QtDBusTest;
 
10
 
 
11
class TestNotificationServer: public QObject {
 
12
Q_OBJECT
 
13
 
 
14
    QSharedPointer<DBusTestRunner> dbus;
 
15
 
 
16
    QSharedPointer<OrgFreedesktopNotificationsInterface> notificationsInterface;
 
17
 
 
18
private Q_SLOTS:
 
19
 
 
20
void init() {
 
21
    DBusTypes::registerNotificationMetaTypes();
 
22
 
 
23
    dbus.reset(new DBusTestRunner);
 
24
 
 
25
    dbus->registerService(
 
26
            DBusServicePtr(
 
27
                    new QProcessDBusService(DBUS_SERVICE_NAME,
 
28
                                            QDBusConnection::SessionBus,
 
29
                                            DBUS_SERVER_BINARY,
 
30
                                            QStringList{"--no-gui"})));
 
31
    dbus->startServices();
 
32
 
 
33
    notificationsInterface.reset(
 
34
                new OrgFreedesktopNotificationsInterface(DBUS_SERVICE_NAME,
 
35
                                                         DBUS_PATH,
 
36
                                                         dbus->sessionConnection()));
 
37
}
 
38
 
 
39
void cleanup() {
 
40
    notificationsInterface.reset();
 
41
 
 
42
    dbus.reset();
 
43
}
 
44
 
 
45
int notify(const QString& name) {
 
46
        return int(
 
47
                notificationsInterface->Notify("my app", 0, "icon " + name,
 
48
                                               "summary " + name,
 
49
                                               "body " + name, QStringList(),
 
50
                                               QVariantMap(), 0));
 
51
}
 
52
 
 
53
void expectNotification(const NotificationDataList& notifications, int index, int id, const QString& name) {
 
54
    QCOMPARE(
 
55
        notifications.at(index),
 
56
        NotificationData()
 
57
            .setAppName("my app")
 
58
            .setId(id)
 
59
            .setAppIcon("image://theme/icon " + name)
 
60
            .setBody("body " + name)
 
61
            .setSummary("summary " + name)
 
62
            .setExpireTimeout(5000)
 
63
        );
 
64
}
 
65
 
 
66
void testNotify() {
 
67
    uint id1 = notify("1");
 
68
    QCOMPARE(id1, uint(1));
 
69
 
 
70
    uint id2 = notify("2");
 
71
    QCOMPARE(id2, uint(2));
 
72
 
 
73
    NotificationDataList notifications = notificationsInterface->GetNotifications("my app");
 
74
    QCOMPARE(notifications.size(), 2);
 
75
 
 
76
    expectNotification(notifications, 0, id1, "1");
 
77
    expectNotification(notifications, 1, id2, "2");
 
78
}
 
79
 
 
80
void testClose() {
 
81
    uint id1 = notify("1");
 
82
    QCOMPARE(id1, uint(1));
 
83
 
 
84
    uint id2 = notify("2");
 
85
    QCOMPARE(id2, uint(2));
 
86
 
 
87
    {
 
88
        NotificationDataList notifications = notificationsInterface->GetNotifications("my app");
 
89
        QCOMPARE(notifications.size(), 2);
 
90
 
 
91
        expectNotification(notifications, 0, id1, "1");
 
92
        expectNotification(notifications, 1, id2, "2");
 
93
    }
 
94
 
 
95
    notificationsInterface->CloseNotification(id1).waitForFinished();
 
96
 
 
97
    {
 
98
        NotificationDataList notifications = notificationsInterface->GetNotifications("my app");
 
99
        QCOMPARE(notifications.size(), 1);
 
100
 
 
101
        expectNotification(notifications, 0, id2, "2");
 
102
    }
 
103
}
 
104
 
 
105
void testGetCapabilities() {
 
106
    QStringList capabilities = notificationsInterface->GetCapabilities();
 
107
    QStringList expected {"actions",
 
108
        "body",
 
109
        "body-markup",
 
110
        "icon-static",
 
111
        "image/svg+xml",
 
112
        VALUE_HINT,
 
113
        VALUE_TINT_HINT,
 
114
        URGENCY_HINT,
 
115
        SOUND_HINT,
 
116
        SUPPRESS_SOUND_HINT,
 
117
        SYNCH_HINT,
 
118
        ICON_ONLY_HINT,
 
119
        AFFIRMATIVE_TINT_HINT,
 
120
        REJECTION_TINT_HINT,
 
121
        TRUNCATION_HINT,
 
122
        SNAP_HINT,
 
123
        SECONDARY_ICON_HINT,
 
124
        NON_SHAPED_ICON_HINT,
 
125
        MENU_MODEL_HINT,
 
126
        INTERACTIVE_HINT,
 
127
        TIMEOUT_HINT,
 
128
        SWIPE_HINT
 
129
    };
 
130
    QCOMPARE(capabilities, expected);
 
131
}
 
132
 
 
133
void testGetServerInformation() {
 
134
    QString vendor, version, specVersion;
 
135
    QString name = notificationsInterface->GetServerInformation(vendor, version, specVersion);
 
136
 
 
137
    QCOMPARE(name, QString("Unity notification server"));
 
138
    QCOMPARE(vendor, QString("Canonical Ltd"));
 
139
    QCOMPARE(version, QString("1.2"));
 
140
    QCOMPARE(specVersion, QString("1.1"));
 
141
}
 
142
 
 
143
};
 
144
 
 
145
QTEST_MAIN(TestNotificationServer)
 
146
#include "notificationservertest.moc"