Merge lp:~macslow/unity-notifications/qtest-transition into lp:unity-notifications

Proposed by Mirco Müller
Status: Merged
Approved by: Michael Zanetti
Approved revision: 192
Merged at revision: 192
Proposed branch: lp:~macslow/unity-notifications/qtest-transition
Merge into: lp:unity-notifications
Diff against target: 207 lines (+62/-65)
2 files modified
test/CMakeLists.txt (+1/-1)
test/notificationtest.cpp (+61/-64)
To merge this branch: bzr merge lp:~macslow/unity-notifications/qtest-transition
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+197764@code.launchpad.net

Commit message

Make notification unit-test Q-ified in order to allow nicer ouput in case of failures.

Description of the change

Make notification unit-test Q-ified in order to allow nicer ouput in case of failures.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/CMakeLists.txt'
2--- test/CMakeLists.txt 2013-06-18 11:05:42 +0000
3+++ test/CMakeLists.txt 2013-12-04 17:40:34 +0000
4@@ -1,6 +1,6 @@
5 add_executable(notificationtest notificationtest.cpp)
6 target_link_libraries(notificationtest notifybackend)
7-qt5_use_modules(notificationtest Gui Core Widgets)
8+qt5_use_modules(notificationtest Gui Test Core Widgets)
9
10 add_test(notification notificationtest)
11 set_tests_properties(notification PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")
12
13=== modified file 'test/notificationtest.cpp'
14--- test/notificationtest.cpp 2013-10-16 11:56:11 +0000
15+++ test/notificationtest.cpp 2013-12-04 17:40:34 +0000
16@@ -1,23 +1,33 @@
17 #include "Notification.h"
18 #include "NotificationModel.h"
19
20-#include<QApplication>
21-#include <cassert>
22-#include <cstdio>
23-
24-void testSimpleInsertion() {
25+#include <QtTest/QtTest>
26+
27+class TestNotifications: public QObject
28+{
29+ Q_OBJECT
30+
31+ private Q_SLOTS:
32+ void testFullQueue();
33+ void testHas();
34+ void testOrder();
35+ void testTypeSimple();
36+ void testSimpleInsertion();
37+};
38+
39+void TestNotifications::testSimpleInsertion() {
40 int timeout = 5000;
41 QSharedPointer<Notification> n(new Notification(42, timeout, Notification::Low, "this is text"));
42 NotificationModel m;
43
44- assert(m.numNotifications() == 1);
45+ QVERIFY(m.numNotifications() == 1);
46 m.insertNotification(n);
47- assert(m.numNotifications() == 2);
48+ QVERIFY(m.numNotifications() == 2);
49 m.removeNotification(n->getID());
50- assert(m.numNotifications() == 1);
51+ QVERIFY(m.numNotifications() == 1);
52 }
53
54-void testTypeSimple() {
55+void TestNotifications::testTypeSimple() {
56 int timeout = 5000;
57 QSharedPointer<Notification> n1(new Notification(1, timeout, Notification::Low, "low", Notification::Ephemeral));
58 QSharedPointer<Notification> n2(new Notification(2, timeout, Notification::Low, "low", Notification::SnapDecision));
59@@ -25,15 +35,15 @@
60 NotificationModel m;
61
62 m.insertNotification(n1);
63- assert(m.showingNotificationOfType(Notification::Ephemeral));
64+ QVERIFY(m.showingNotificationOfType(Notification::Ephemeral));
65 m.insertNotification(n2);
66- assert(m.showingNotificationOfType(Notification::SnapDecision));
67+ QVERIFY(m.showingNotificationOfType(Notification::SnapDecision));
68
69 m.insertNotification(n3);
70- assert(m.showingNotificationOfType(Notification::Confirmation));
71+ QVERIFY(m.showingNotificationOfType(Notification::Confirmation));
72 }
73
74-void testOrder() {
75+void TestNotifications::testOrder() {
76 const int timeout = 5000;
77 QSharedPointer<Notification> n1(new Notification(1, timeout, Notification::Low, "low", Notification::Ephemeral));
78 QSharedPointer<Notification> n2(new Notification(2, timeout, Notification::Normal, "high", Notification::Ephemeral));
79@@ -41,90 +51,77 @@
80 NotificationModel m;
81
82 m.insertNotification(n1);
83- assert(m.showingNotification(n1->getID()));
84+ QVERIFY(m.showingNotification(n1->getID()));
85
86 m.insertNotification(n2);
87- assert(!m.showingNotification(n1->getID()));
88- assert(m.showingNotification(n2->getID()));
89- assert(m.queued() == 1);
90+ QVERIFY(!m.showingNotification(n1->getID()));
91+ QVERIFY(m.showingNotification(n2->getID()));
92+ QVERIFY(m.queued() == 1);
93
94 m.insertNotification(n3);
95- assert(!m.showingNotification(n1->getID()));
96- assert(!m.showingNotification(n2->getID()));
97- assert(m.showingNotification(n3->getID()));
98- assert(m.queued() == 2);
99+ QVERIFY(!m.showingNotification(n1->getID()));
100+ QVERIFY(!m.showingNotification(n2->getID()));
101+ QVERIFY(m.showingNotification(n3->getID()));
102+ QVERIFY(m.queued() == 2);
103
104 m.removeNotification(n3->getID());
105- assert(!m.showingNotification(n1->getID()));
106- assert(m.showingNotification(n2->getID()));
107- assert(!m.showingNotification(n3->getID()));
108- assert(m.queued() == 1);
109+ QVERIFY(!m.showingNotification(n1->getID()));
110+ QVERIFY(m.showingNotification(n2->getID()));
111+ QVERIFY(!m.showingNotification(n3->getID()));
112+ QVERIFY(m.queued() == 1);
113
114 m.removeNotification(n2->getID());
115- assert(m.showingNotification(n1->getID()));
116- assert(!m.showingNotification(n2->getID()));
117- assert(!m.showingNotification(n3->getID()));
118- assert(m.queued() == 0);
119+ QVERIFY(m.showingNotification(n1->getID()));
120+ QVERIFY(!m.showingNotification(n2->getID()));
121+ QVERIFY(!m.showingNotification(n3->getID()));
122+ QVERIFY(m.queued() == 0);
123
124 m.removeNotification(n1->getID());
125- assert(!m.showingNotification(n1->getID()));
126- assert(!m.showingNotification(n2->getID()));
127- assert(!m.showingNotification(n3->getID()));
128- assert(m.queued() == 0);
129+ QVERIFY(!m.showingNotification(n1->getID()));
130+ QVERIFY(!m.showingNotification(n2->getID()));
131+ QVERIFY(!m.showingNotification(n3->getID()));
132+ QVERIFY(m.queued() == 0);
133 }
134
135-void testHas() {
136+void TestNotifications::testHas() {
137 const int timeout = 5000;
138 QSharedPointer<Notification> n1(new Notification(1, timeout, Notification::Low, "low", Notification::Ephemeral));
139 QSharedPointer<Notification> n2(new Notification(2, timeout, Notification::Low, "low", Notification::Ephemeral));
140 QSharedPointer<Notification> n3(new Notification(3, timeout, Notification::Low, "low", Notification::Ephemeral));
141 NotificationModel m;
142
143- assert(!m.hasNotification(1));
144- assert(!m.hasNotification(2));
145- assert(!m.hasNotification(3));
146+ QVERIFY(!m.hasNotification(1));
147+ QVERIFY(!m.hasNotification(2));
148+ QVERIFY(!m.hasNotification(3));
149
150 m.insertNotification(n1);
151- assert(m.hasNotification(1));
152- assert(!m.hasNotification(2));
153- assert(!m.hasNotification(3));
154+ QVERIFY(m.hasNotification(1));
155+ QVERIFY(!m.hasNotification(2));
156+ QVERIFY(!m.hasNotification(3));
157
158 m.insertNotification(n2);
159- assert(m.hasNotification(1));
160- assert(m.hasNotification(2));
161- assert(!m.hasNotification(3));
162+ QVERIFY(m.hasNotification(1));
163+ QVERIFY(m.hasNotification(2));
164+ QVERIFY(!m.hasNotification(3));
165
166 m.insertNotification(n3);
167- assert(m.hasNotification(1));
168- assert(m.hasNotification(2));
169- assert(m.hasNotification(3));
170+ QVERIFY(m.hasNotification(1));
171+ QVERIFY(m.hasNotification(2));
172+ QVERIFY(m.hasNotification(3));
173 }
174
175-
176-void testFullQueue() {
177+void TestNotifications::testFullQueue() {
178 int timeout = 5000;
179 NotificationModel m;
180 for(unsigned int i=0; i< MAX_NOTIFICATIONS; i++) {
181 QSharedPointer<Notification> n(new Notification(i, timeout, Notification::Low, "text", Notification::Ephemeral));
182 m.insertNotification(n);
183 }
184- assert((unsigned int)m.numNotifications() == MAX_NOTIFICATIONS);
185+ QVERIFY((unsigned int)m.numNotifications() == MAX_NOTIFICATIONS);
186 QSharedPointer<Notification> wontFit(new Notification(1111, timeout, Notification::Critical, "foo"));
187 m.insertNotification(wontFit);
188- assert((unsigned int)m.numNotifications() == MAX_NOTIFICATIONS);
189+ QVERIFY((unsigned int)m.numNotifications() == MAX_NOTIFICATIONS);
190 }
191
192-int main(int argc, char **argv) {
193- QApplication app(argc, argv);
194-#ifdef NDEBUG
195- fprintf(stderr, "NDEBUG is defined, tests will not work.");
196- return 1;
197-#else
198- testSimpleInsertion();
199- testTypeSimple();
200- testFullQueue();
201- testOrder();
202- testHas();
203- return 0;
204-#endif
205-}
206+QTEST_MAIN(TestNotifications)
207+#include "notificationtest.moc"

Subscribers

People subscribed via source and target branches

to all changes: