@@ -36,6 +36,25 @@ struct signal_closed {
3636 GDBusConnection * conn ;
3737};
3838
39+ struct signal_historyremoved {
40+ guint32 id ;
41+ bool removed ;
42+ guint subscription_id ;
43+ GDBusConnection * conn ;
44+ };
45+
46+ struct signal_historycleared {
47+ guint32 count ;
48+ guint subscription_id ;
49+ GDBusConnection * conn ;
50+ };
51+
52+ struct signal_configreloaded {
53+ gchar * * configs ;
54+ guint subscription_id ;
55+ GDBusConnection * conn ;
56+ };
57+
3958void dbus_signal_cb_actioninvoked (GDBusConnection * connection ,
4059 const gchar * sender_name ,
4160 const gchar * object_path ,
@@ -208,6 +227,153 @@ void dbus_signal_unsubscribe_closed(struct signal_closed *closed)
208227 closed -> subscription_id = -1 ;
209228}
210229
230+ void dbus_signal_cb_historyremoved (GDBusConnection * connection ,
231+ const gchar * sender_name ,
232+ const gchar * object_path ,
233+ const gchar * interface_name ,
234+ const gchar * signal_name ,
235+ GVariant * parameters ,
236+ gpointer user_data )
237+ {
238+ g_return_if_fail (user_data );
239+
240+ guint32 id ;
241+
242+ struct signal_historyremoved * sig = (struct signal_historyremoved * ) user_data ;
243+ g_variant_get (parameters , "(u)" , & id );
244+
245+ if (id == sig -> id ) {
246+ sig -> removed = true;
247+ }
248+ }
249+
250+ void dbus_signal_subscribe_historyremoved (struct signal_historyremoved * sig )
251+ {
252+ assert (sig );
253+
254+ sig -> conn = g_bus_get_sync (G_BUS_TYPE_SESSION , NULL , NULL );
255+ sig -> subscription_id =
256+ g_dbus_connection_signal_subscribe (
257+ sig -> conn ,
258+ FDN_NAME ,
259+ DUNST_IFAC ,
260+ "NotificationHistoryRemoved" ,
261+ FDN_PATH ,
262+ NULL ,
263+ G_DBUS_SIGNAL_FLAGS_NONE ,
264+ dbus_signal_cb_historyremoved ,
265+ sig ,
266+ NULL );
267+ }
268+
269+ void dbus_signal_unsubscribe_historyremoved (struct signal_historyremoved * sig )
270+ {
271+ assert (sig );
272+
273+ g_dbus_connection_signal_unsubscribe (sig -> conn , sig -> subscription_id );
274+ g_object_unref (sig -> conn );
275+
276+ sig -> conn = NULL ;
277+ sig -> subscription_id = -1 ;
278+ }
279+
280+ void dbus_signal_cb_historycleared (GDBusConnection * connection ,
281+ const gchar * sender_name ,
282+ const gchar * object_path ,
283+ const gchar * interface_name ,
284+ const gchar * signal_name ,
285+ GVariant * parameters ,
286+ gpointer user_data )
287+ {
288+ g_return_if_fail (user_data );
289+
290+ guint32 count ;
291+
292+ struct signal_historycleared * sig = (struct signal_historycleared * ) user_data ;
293+ g_variant_get (parameters , "(u)" , & count );
294+
295+ sig -> count = count ;
296+ }
297+
298+ void dbus_signal_subscribe_historycleared (struct signal_historycleared * sig )
299+ {
300+ assert (sig );
301+
302+ sig -> conn = g_bus_get_sync (G_BUS_TYPE_SESSION , NULL , NULL );
303+ sig -> subscription_id =
304+ g_dbus_connection_signal_subscribe (
305+ sig -> conn ,
306+ FDN_NAME ,
307+ DUNST_IFAC ,
308+ "NotificationHistoryCleared" ,
309+ FDN_PATH ,
310+ NULL ,
311+ G_DBUS_SIGNAL_FLAGS_NONE ,
312+ dbus_signal_cb_historycleared ,
313+ sig ,
314+ NULL );
315+ }
316+
317+ void dbus_signal_unsubscribe_historycleared (struct signal_historycleared * sig )
318+ {
319+ assert (sig );
320+
321+ g_dbus_connection_signal_unsubscribe (sig -> conn , sig -> subscription_id );
322+ g_object_unref (sig -> conn );
323+
324+ sig -> conn = NULL ;
325+ sig -> subscription_id = -1 ;
326+ }
327+
328+
329+ void dbus_signal_cb_configreloaded (GDBusConnection * connection ,
330+ const gchar * sender_name ,
331+ const gchar * object_path ,
332+ const gchar * interface_name ,
333+ const gchar * signal_name ,
334+ GVariant * parameters ,
335+ gpointer user_data )
336+ {
337+ g_return_if_fail (user_data );
338+
339+ gchar * * configs ;
340+
341+ struct signal_configreloaded * sig = (struct signal_configreloaded * ) user_data ;
342+ g_variant_get (parameters , "(^as)" , & configs );
343+
344+ sig -> configs = configs ;
345+ }
346+
347+ void dbus_signal_subscribe_configreloaded (struct signal_configreloaded * sig )
348+ {
349+ assert (sig );
350+
351+ sig -> conn = g_bus_get_sync (G_BUS_TYPE_SESSION , NULL , NULL );
352+ sig -> subscription_id =
353+ g_dbus_connection_signal_subscribe (
354+ sig -> conn ,
355+ FDN_NAME ,
356+ DUNST_IFAC ,
357+ "ConfigReloaded" ,
358+ FDN_PATH ,
359+ NULL ,
360+ G_DBUS_SIGNAL_FLAGS_NONE ,
361+ dbus_signal_cb_configreloaded ,
362+ sig ,
363+ NULL );
364+ }
365+
366+ void dbus_signal_unsubscribe_configreloaded (struct signal_configreloaded * sig )
367+ {
368+ assert (sig );
369+
370+ g_dbus_connection_signal_unsubscribe (sig -> conn , sig -> subscription_id );
371+ g_object_unref (sig -> conn );
372+
373+ sig -> conn = NULL ;
374+ sig -> subscription_id = -1 ;
375+ }
376+
211377static GVariant * dbus_invoke_ifac (const char * method , GVariant * params , const char * ifac )
212378{
213379 GDBusConnection * connection_client ;
@@ -1344,6 +1510,86 @@ TEST test_timeout(void)
13441510 PASS ();
13451511}
13461512
1513+ TEST test_clearhistory_and_signal (void )
1514+ {
1515+ GVariant * ret ;
1516+ struct signal_historycleared sig = {0 , -1 };
1517+
1518+ dbus_signal_subscribe_historycleared (& sig );
1519+
1520+ guint count = queues_length_history ();
1521+
1522+ ret = dbus_invoke_ifac ("NotificationClearHistory" , NULL , DUNST_IFAC );
1523+
1524+ ASSERT (ret );
1525+ g_variant_unref (ret );
1526+
1527+ uint waiting = 0 ;
1528+ while (sig .count == 0 && waiting < 2000 ) {
1529+ usleep (500 );
1530+ waiting ++ ;
1531+ }
1532+
1533+ ASSERT (sig .count == count );
1534+
1535+ sig .count = 0 ;
1536+ queues_history_clear ();
1537+
1538+ struct notification * n = notification_create ();
1539+ n -> appname = g_strdup ("dunstify" );
1540+ n -> summary = g_strdup ("Testing" );
1541+ queues_history_push (n );
1542+
1543+ ret = dbus_invoke_ifac ("NotificationClearHistory" , NULL , DUNST_IFAC );
1544+ ASSERT (ret );
1545+ g_variant_unref (ret );
1546+
1547+ waiting = 0 ;
1548+ while (sig .count == 0 && waiting < 2000 ) {
1549+ usleep (500 );
1550+ waiting ++ ;
1551+ }
1552+
1553+ ASSERT (sig .count == 1 );
1554+
1555+ queues_history_clear ();
1556+ dbus_signal_unsubscribe_historycleared (& sig );
1557+ PASS ();
1558+ }
1559+
1560+ TEST test_removehistory_and_signal (void )
1561+ {
1562+ GVariant * data , * ret ;
1563+ struct signal_historyremoved sig = {0 , false, -1 };
1564+
1565+ dbus_signal_subscribe_historyremoved (& sig );
1566+ queues_history_clear ();
1567+
1568+ struct notification * n = notification_create ();
1569+ n -> appname = g_strdup ("dunstify" );
1570+ n -> summary = g_strdup ("Testing" );
1571+ queues_history_push (n );
1572+
1573+ data = g_variant_new ("(u)" , sig .id );
1574+ ret = dbus_invoke_ifac ("NotificationRemoveFromHistory" , data , DUNST_IFAC );
1575+
1576+ ASSERT (ret );
1577+
1578+ uint waiting = 0 ;
1579+ while (!sig .removed && waiting < 2000 ) {
1580+ usleep (500 );
1581+ waiting ++ ;
1582+ }
1583+
1584+ ASSERT (sig .removed );
1585+ ASSERT (queues_length_history () == 0 );
1586+
1587+ queues_history_clear ();
1588+ dbus_signal_unsubscribe_historyremoved (& sig );
1589+ g_variant_unref (ret );
1590+ PASS ();
1591+ }
1592+
13471593// TESTS END
13481594
13491595GMainLoop * loop ;
@@ -1379,6 +1625,8 @@ gpointer run_threaded_tests(gpointer data)
13791625 RUN_TEST (test_override_dbus_timeout );
13801626 RUN_TEST (test_match_dbus_timeout );
13811627 RUN_TEST (test_timeout );
1628+ RUN_TEST (test_clearhistory_and_signal );
1629+ RUN_TEST (test_removehistory_and_signal );
13821630 RUN_TEST (test_dbus_cb_dunst_NotificationListHistory );
13831631 RUN_TEST (test_dbus_cb_dunst_RuleEnable );
13841632 RUN_TEST (test_dbus_cb_dunst_RuleList );
0 commit comments