Debian Codegraph @

tests/online-accounts-ui/tst_notification/tst_notification.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Canonical Ltd.
3 *
4 * Contact: Alberto Mardegan <[email protected]>
5 *
6 * This file is part of lomiri-online-accounts-ui
7 *
8 * This program is free software: you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 3, as published
10 * by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranties of
14 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "notification.h"cxx . . $ `<file>/online-accounts-service/src/notification.h`/
22
23 #include <QDebug>
24 #include <QList>
25 #include <QMap>
26 #include <QPair>
27 #include <QSignalSpy>
28 #include <QTest>
29 #include <QVariantMap>
30 #include <libnotify/notification.h>
31 #include <libnotify/notify.h>
32
33 using namespace OnlineAccountsUi;
34
35 /* Mocking libnotify: */
36
37 static char *appNamecxx . . $ appName. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
38
39 gboolean notify_initcxx . . $ notify_init(5c4306d8553b3696).(const char *app_name)
40 {
41 appNamecxx . . $ appName. = g_strdupcxx . . $ `<external>/7822753393113922331/gstrfuncs.h:324:9`!(app_name);
42 return true;
43 }
44
45 gboolean notify_is_inittedcxx . . $ notify_is_initted(b126dc7c1de90089).()
46 {
47 return appNamecxx . . $ appName. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!;
48 }
49
50 typedef QPaircxx . . $ QPair#<QByteArraycxx . . $ QByteArray#,QByteArraycxx . . $ QByteArray#> ActionPaircxx . . $ ActionPair#;
51
52 struct MockNotificationcxx . . $ MockNotification# {
53 QStringcxx . . $ QString# summarycxx . . $ MockNotification#summary.;
54 QStringcxx . . $ QString# bodycxx . . $ MockNotification#body.;
55 QListcxx . . $ QList#<ActionPaircxx . . $ ActionPair#> actionscxx . . $ MockNotification#actions.;
56 QVariantMapcxx . . $ QVariantMap# hintscxx . . $ MockNotification#hints.;
57 bool visiblecxx . . $ MockNotification#visible.;
58
59 MockNotificationcxx . . $ MockNotification#MockNotification(49f6e7a06ebc5aa8).();
60 ~cxx . . $ MockNotification#`~MockNotification`(ced63f7c635d850d).MockNotificationcxx . . $ MockNotification#();
61 bool invokeActioncxx . . $ MockNotification#invokeAction(544790aa27d183a0).(const QByteArraycxx . . $ QByteArray# &action);
62 void closecxx . . $ MockNotification#close(49f6e7a06ebc5aa8).();
63
64 struct CallbackDatacxx . . $ MockNotification#CallbackData# {
65 NotifyActionCallback callbackcxx . . $ MockNotification#CallbackData#callback.;
66 gpointer userDatacxx . . $ MockNotification#CallbackData#userData.;
67 };
68
69 QMapcxx . . $ QMap#<QByteArraycxx . . $ QByteArray#,CallbackDatacxx . . $ MockNotification#CallbackData#> callbackscxx . . $ MockNotification#callbacks.;
70
71 /* "closed" signal connection */
72 void (*closedCallbackcxx . . $ MockNotification#closedCallback.)(gpointer, gpointer);
73 gpointer closedUserDatacxx . . $ MockNotification#closedUserData.;
74 };
75
76 static QSetcxx . . $ QSet#<MockNotificationcxx . . $ MockNotification#*> notificationscxx . . $ notifications.;
77
78 MockNotificationcxx . . $ MockNotification#::MockNotificationcxx . . $ MockNotification#MockNotification(49f6e7a06ebc5aa8).():
79 visiblecxx . . $ MockNotification#visible.(false)
80 {
81 notificationscxx . . $ notifications..insertcxx . . $ QSet#insert(b1720532d625d779).(this);
82 }
83
84 MockNotificationcxx . . $ MockNotification#::~cxx . . $ MockNotification#`~MockNotification`(ced63f7c635d850d).MockNotificationcxx . . $ MockNotification#()
85 {
86 notificationscxx . . $ notifications..removecxx . . $ QSet#remove(fe1ba53999e710f3).(this);
87 }
88
89 bool MockNotificationcxx . . $ MockNotification#::invokeActioncxx . . $ MockNotification#invokeAction(544790aa27d183a0).(const QByteArraycxx . . $ QByteArray# &action)
90 {
91 if (!callbackscxx . . $ MockNotification#callbacks..containscxx . . $ QMap#contains(8877ebe272b9620d).(action)) return false;
92 CallbackDatacxx . . $ MockNotification#CallbackData# &callbackData = callbackscxx . . $ MockNotification#callbacks.[cxx . . $ QMap#`operator[]`(bbd415b616967878).action];
93 callbackData.callbackcxx . . $ MockNotification#CallbackData#callback.(reinterpret_cast<NotifyNotification*>(this),
94 (char *)action.datacxx . . $ QByteArray#data(a9f41ea0e82d88cf).(), callbackData.userDatacxx . . $ MockNotification#CallbackData#userData.);
95 return true;
96 }
97
98 void MockNotificationcxx . . $ MockNotification#::closecxx . . $ MockNotification#close(49f6e7a06ebc5aa8).()
99 {
100 if (!closedCallbackcxx . . $ MockNotification#closedCallback.) return;
101
102 closedCallbackcxx . . $ MockNotification#closedCallback.(closedUserDatacxx . . $ MockNotification#closedUserData., this);
103 }
104
105 gulong g_signal_connect_datacxx . . $ g_signal_connect_data(2a7b3bd665ea804c).(gpointer instance,
106 const gchar *detailed_signal,
107 GCallback c_handler,
108 gpointer data,
109 GClosureNotify destroy_data,
110 GConnectFlags connect_flags)
111 {
112 Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(destroy_data);
113 Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(connect_flags);
114
115 MockNotificationcxx . . $ MockNotification# *mock = reinterpret_cast<MockNotificationcxx . . $ MockNotification#*>(instance);
116 if (qstrcmpcxx . . $ qstrcmp(5ae29d726ae57f88).(detailed_signal, "closed") == 0) {
117 mock->closedCallbackcxx . . $ MockNotification#closedCallback. = (void (*)(gpointer,gpointer))c_handler;
118 mock->closedUserDatacxx . . $ MockNotification#closedUserData. = data;
119 } else {
120 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Unmocked signal" <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). detailed_signal;
121 return 0;
122 }
123
124 return 1;
125 }
126
127 void g_object_unrefcxx . . $ g_object_unref(5d22bdacc48458e8).(gpointer object)
128 {
129 MockNotificationcxx . . $ MockNotification# *mock = reinterpret_cast<MockNotificationcxx . . $ MockNotification#*>(object);
130 delete mock;
131 }
132
133 NotifyNotification *
134 notify_notification_newcxx . . $ notify_notification_new(7bd4af346ab09523).(const char *summary,
135 const char *body,
136 const char *icon)
137 {
138 Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(icon);
139 MockNotificationcxx . . $ MockNotification# *notification = new MockNotificationcxx . . $ MockNotification#;
140 notification->summarycxx . . $ MockNotification#summary. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(5ac70cc0fa2a874e).(summary);
141 notification->bodycxx . . $ MockNotification#body. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(5ac70cc0fa2a874e).(body);
142 return reinterpret_cast<NotifyNotification*>(notification);
143 }
144
145 gboolean
146 notify_notification_showcxx . . $ notify_notification_show(41527e62f969f77e).(NotifyNotification *notification,
147 GError **error)
148 {
149 Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(error);
150 MockNotificationcxx . . $ MockNotification# *mock =
151 reinterpret_cast<MockNotificationcxx . . $ MockNotification#*>(notification);
152 mock->visiblecxx . . $ MockNotification#visible. = true;
153 return true;
154 }
155
156 void notify_notification_add_actioncxx . . $ notify_notification_add_action(ee8098306cc15d00).(NotifyNotification *notification,
157 const char *action,
158 const char *label,
159 NotifyActionCallback callback,
160 gpointer user_data,
161 GFreeFunc free_func)
162 {
163 Q_UNUSEDcxx . . $ `<external>/15045578679651060896/qglobal.h:117:9`!(free_func);
164 MockNotificationcxx . . $ MockNotification# *mock =
165 reinterpret_cast<MockNotificationcxx . . $ MockNotification#*>(notification);
166 mock->actionscxx . . $ MockNotification#actions..appendcxx . . $ QList#append(77d9f17553126ecb).(ActionPaircxx . . $ QPair#QPair(ce1e23113bcdb2b4).(actioncxx . . $ QByteArray#QByteArray(34d26762b42c433a)., labelcxx . . $ QByteArray#QByteArray(34d26762b42c433a).));
167 MockNotificationcxx . . $ MockNotification#::CallbackDatacxx . . $ MockNotification#CallbackData# &callbackData = mock->callbackscxx . . $ MockNotification#callbacks.[cxx . . $ QMap#`operator[]`(bbd415b616967878).actioncxx . . $ QByteArray#QByteArray(34d26762b42c433a).];
168 callbackData.callbackcxx . . $ MockNotification#CallbackData#callback. = callback;
169 callbackData.userDatacxx . . $ MockNotification#CallbackData#userData. = user_data;
170 }
171
172 void notify_notification_set_hintcxx . . $ notify_notification_set_hint(ecfa3c7872886e63).(NotifyNotification *notification,
173 const char *key,
174 GVariant *value)
175 {
176 MockNotificationcxx . . $ MockNotification# *mock =
177 reinterpret_cast<MockNotificationcxx . . $ MockNotification#*>(notification);
178 QVariantcxx . . $ QVariant# variantcxx . . $ QVariant#QVariant(ced63f7c635d850d).;
179 if (g_variant_is_of_type(value, G_VARIANT_TYPE_BOOLEANcxx . . $ `<external>/14064154155447831270/gvarianttype.h:41:9`!)) {
180 variant =cxx . . $ QVariant#`operator=`(79a68221451e88b7). boolcxx . . $ QVariant#QVariant(b45ddcbc8423892c).(g_variant_get_boolean(value));
181 } else {
182 /* Add support for any needed types */
183 qWarningcxx . . $ `<external>/10450329605257866924/qlogging.h:166:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Unsupported variant type";
184 }
185 mock->hintscxx . . $ MockNotification#hints..insertcxx . . $ QMap#insert(929a1ed410fe8423).(QStringcxx . . $ QString#::fromUtf8cxx . . $ QString#fromUtf8(5ac70cc0fa2a874e).(key), variant);
186 }
187
188 /* End of mock code */
189
190 class NotificationTestcxx . . $ NotificationTest#: public QObjectcxx . . $ QObject#
191 {
192 Q_OBJECTcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:170:9`!
193
194 public:
195 NotificationTestcxx . . $ NotificationTest#NotificationTest(49f6e7a06ebc5aa8).();
196
197 private Q_SLOTScxx . . $ `<external>/1208926524888476972/qobjectdefs.h:92:10`!:
198 void testInitializationcxx . . $ NotificationTest#testInitialization(49f6e7a06ebc5aa8).();
199 void testDestructioncxx . . $ NotificationTest#testDestruction(49f6e7a06ebc5aa8).();
200 void testContentscxx . . $ NotificationTest#testContents(49f6e7a06ebc5aa8).();
201 void testSnapDecisioncxx . . $ NotificationTest#testSnapDecision(49f6e7a06ebc5aa8).();
202 void testVisibilitycxx . . $ NotificationTest#testVisibility(49f6e7a06ebc5aa8).();
203 void testClosingcxx . . $ NotificationTest#testClosing(49f6e7a06ebc5aa8).();
204 void testActionscxx . . $ NotificationTest#testActions(49f6e7a06ebc5aa8).();
205 };
206
207 NotificationTestcxx . . $ NotificationTest#::NotificationTestcxx . . $ NotificationTest#NotificationTest(49f6e7a06ebc5aa8).():
208 QObjectcxx . . $ QObject#QObject(749de1b6ae65bddd).(0)
209 {
210 }
211
212 void NotificationTestcxx . . $ NotificationTest#::testInitializationcxx . . $ NotificationTest#testInitialization(49f6e7a06ebc5aa8).()
213 {
214 Notificationcxx . . $ OnlineAccountsUi/Notification# firstcxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("summary"cxx . . $ QString#QString(85c52e162fed56f9)., "body"cxx . . $ QString#QString(85c52e162fed56f9).);
215 QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(notify_is_initted());
216 }
217
218 void NotificationTestcxx . . $ NotificationTest#::testDestructioncxx . . $ NotificationTest#testDestruction(49f6e7a06ebc5aa8).()
219 {
220 QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(notifications.isEmpty());
221
222 {
223 Notificationcxx . . $ OnlineAccountsUi/Notification# onecxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("one"cxx . . $ QString#QString(85c52e162fed56f9)., "One"cxx . . $ QString#QString(85c52e162fed56f9).);
224 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(notifications.count(), 1);
225
226 {
227 Notificationcxx . . $ OnlineAccountsUi/Notification# twocxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("two"cxx . . $ QString#QString(85c52e162fed56f9)., "Two"cxx . . $ QString#QString(85c52e162fed56f9).);
228 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(notifications.count(), 2);
229 }
230 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(notifications.count(), 1);
231 }
232
233 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(notifications.count(), 0);
234 }
235
236 void NotificationTestcxx . . $ NotificationTest#::testContentscxx . . $ NotificationTest#testContents(49f6e7a06ebc5aa8).()
237 {
238 Notificationcxx . . $ OnlineAccountsUi/Notification# firstcxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("Summary"cxx . . $ QString#QString(85c52e162fed56f9)., "Body"cxx . . $ QString#QString(85c52e162fed56f9).);
239 MockNotificationcxx . . $ MockNotification# *mock = *cxx . . $ QSet#iterator#`operator*`(ea465e50d690edfe).(notificationscxx . . $ notifications..begincxx . . $ QSet#begin(d7eb3e99549f6811).());
240 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(mock->summary, QString("Summary"));
241 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(mock->body, QString("Body"));
242 QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(mock->hints.isEmpty());
243 }
244
245 void NotificationTestcxx . . $ NotificationTest#::testSnapDecisioncxx . . $ NotificationTest#testSnapDecision(49f6e7a06ebc5aa8).()
246 {
247 Notificationcxx . . $ OnlineAccountsUi/Notification# firstcxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("Summary"cxx . . $ QString#QString(85c52e162fed56f9)., "Body"cxx . . $ QString#QString(85c52e162fed56f9).);
248 MockNotificationcxx . . $ MockNotification# *mock = *cxx . . $ QSet#iterator#`operator*`(ea465e50d690edfe).(notificationscxx . . $ notifications..begincxx . . $ QSet#begin(d7eb3e99549f6811).());
249 QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(mock->hints.isEmpty());
250
251 first.setSnapDecisioncxx . . $ OnlineAccountsUi/Notification#setSnapDecision(b45ddcbc8423892c).(true);
252 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(mock->hints["x-lomiri-snap-decisions"].toBool(), true);
253
254 first.setSnapDecisioncxx . . $ OnlineAccountsUi/Notification#setSnapDecision(b45ddcbc8423892c).(false);
255 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(mock->hints["x-lomiri-snap-decisions"].toBool(), false);
256 }
257
258 void NotificationTestcxx . . $ NotificationTest#::testVisibilitycxx . . $ NotificationTest#testVisibility(49f6e7a06ebc5aa8).()
259 {
260 Notificationcxx . . $ OnlineAccountsUi/Notification# firstcxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("Summary"cxx . . $ QString#QString(85c52e162fed56f9)., "Body"cxx . . $ QString#QString(85c52e162fed56f9).);
261 MockNotificationcxx . . $ MockNotification# *mock = *cxx . . $ QSet#iterator#`operator*`(ea465e50d690edfe).(notificationscxx . . $ notifications..begincxx . . $ QSet#begin(d7eb3e99549f6811).());
262 QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(!mock->visible);
263
264 first.showcxx . . $ OnlineAccountsUi/Notification#show(49f6e7a06ebc5aa8).();
265 QVERIFYcxx . . $ `<external>/8602788698586413231/qtestcase.h:63:9`!(mock->visible);
266 }
267
268 void NotificationTestcxx . . $ NotificationTest#::testClosingcxx . . $ NotificationTest#testClosing(49f6e7a06ebc5aa8).()
269 {
270 Notificationcxx . . $ OnlineAccountsUi/Notification# notificationcxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("Something"cxx . . $ QString#QString(85c52e162fed56f9)., "Here"cxx . . $ QString#QString(85c52e162fed56f9).);
271 MockNotificationcxx . . $ MockNotification# *mock = *cxx . . $ QSet#iterator#`operator*`(ea465e50d690edfe).(notificationscxx . . $ notifications..begincxx . . $ QSet#begin(d7eb3e99549f6811).());
272
273 QSignalSpycxx . . $ QSignalSpy# closedcxx . . $ QSignalSpy#QSignalSpy(593025bf41bda872).(&notification, SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(closed()));
274 mock->closecxx . . $ MockNotification#close(49f6e7a06ebc5aa8).();
275 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(closed.count(), 1);
276 }
277
278 void NotificationTestcxx . . $ NotificationTest#::testActionscxx . . $ NotificationTest#testActions(49f6e7a06ebc5aa8).()
279 {
280 Notificationcxx . . $ OnlineAccountsUi/Notification# notificationcxx . . $ OnlineAccountsUi/Notification#Notification(b05324713c9ab95e).("Something"cxx . . $ QString#QString(85c52e162fed56f9)., "Here"cxx . . $ QString#QString(85c52e162fed56f9).);
281 MockNotificationcxx . . $ MockNotification# *mock = *cxx . . $ QSet#iterator#`operator*`(ea465e50d690edfe).(notificationscxx . . $ notifications..begincxx . . $ QSet#begin(d7eb3e99549f6811).());
282
283 QSignalSpycxx . . $ QSignalSpy# actionInvokedcxx . . $ QSignalSpy#QSignalSpy(593025bf41bda872).(&notification,
284 SIGNALcxx . . $ `<external>/1208926524888476972/qobjectdefs.h:271:10`!(actionInvoked(const QString &)));
285 notification.addActioncxx . . $ OnlineAccountsUi/Notification#addAction(c1427772cd1877b0).("SayHello"cxx . . $ QString#QString(85c52e162fed56f9)., "Say Hello"cxx . . $ QString#QString(85c52e162fed56f9).);
286 notification.addActioncxx . . $ OnlineAccountsUi/Notification#addAction(c1427772cd1877b0).("ok"cxx . . $ QString#QString(85c52e162fed56f9)., "OK"cxx . . $ QString#QString(85c52e162fed56f9).);
287 notification.addActioncxx . . $ OnlineAccountsUi/Notification#addAction(c1427772cd1877b0).("cancel"cxx . . $ QString#QString(85c52e162fed56f9)., "Cancel"cxx . . $ QString#QString(85c52e162fed56f9).);
288
289 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(actionInvoked.count(), 0);
290
291 mock->invokeActioncxx . . $ MockNotification#invokeAction(544790aa27d183a0).("ok"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
292 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(actionInvoked.count(), 1);
293 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(actionInvoked.at(0).at(0).toString(), QString("ok"));
294 actionInvoked.clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).();
295
296 mock->invokeActioncxx . . $ MockNotification#invokeAction(544790aa27d183a0).("cancel"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
297 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(actionInvoked.count(), 1);
298 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(actionInvoked.at(0).at(0).toString(), QString("cancel"));
299 actionInvoked.clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).();
300
301 mock->invokeActioncxx . . $ MockNotification#invokeAction(544790aa27d183a0).("SayHello"cxx . . $ QByteArray#QByteArray(34d26762b42c433a).);
302 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(actionInvoked.count(), 1);
303 QCOMPAREcxx . . $ `<external>/8602788698586413231/qtestcase.h:86:9`!(actionInvoked.at(0).at(0).toString(), QString("SayHello"));
304 }
305
306 QTEST_MAINcxx . . $ `<external>/4204159469433502174/qtest.h:508:9`!(NotificationTest);
307
308 #include "tst_notification.moc"cxx . . $ `<file>/build/tests/online-accounts-ui/tst_notification/tst_notification_autogen/include/tst_notification.moc`/