1 /* Integration tests for monitor-mode D-Bus connections
3 * Copyright © 2010-2011 Nokia Corporation
4 * Copyright © 2015 Collabora Ltd.
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction,
9 * including without limitation the rights to use, copy, modify, merge,
10 * publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include "test-utils-glib.h"
34 const char *config_file;
35 const char * const *match_rules;
36 gboolean care_about_our_names;
48 DBusConnection *monitor;
49 DBusConnection *sender;
50 DBusConnection *recipient;
54 const char *monitor_name;
55 const char *sender_name;
56 const char *recipient_name;
58 DBusConnection *systemd;
59 const char *systemd_name;
60 DBusMessage *systemd_message;
61 DBusConnection *activated;
62 const char *activated_name;
63 DBusMessage *activated_message;
66 static const char * const no_match_rules[] = {
70 static const char * const wildcard_match_rules[] = {
76 static const char * const eavesdrop_match_rules[] = {
82 static const char * const no_eavesdrop_match_rules[] = {
88 static const char * const selective_match_rules[] = {
89 "interface='com.example.Interesting'",
90 "interface='com.example.Fun'",
95 static Config forbidding_config = {
96 "valid-config-files/forbidding.conf",
101 static Config wildcard_config = {
103 wildcard_match_rules,
107 static Config selective_config = {
109 selective_match_rules,
113 static Config no_rules_config = {
119 static Config eavesdrop_config = {
121 eavesdrop_match_rules,
125 static Config no_eavesdrop_config = {
127 no_eavesdrop_match_rules,
132 static Config fake_systemd_config = {
133 "valid-config-files/systemd-activation.conf",
139 static Config side_effects_config = {
145 static inline const char *
146 not_null2 (const char *x,
147 const char *fallback)
155 static inline const char *
156 not_null (const char *x)
158 return not_null2 (x, "(null)");
161 #define log_message(m) _log_message (m, __FILE__, __LINE__)
165 _log_message (DBusMessage *m,
169 g_test_message ("%s:%d: message type %d (%s)", file, line,
170 dbus_message_get_type (m),
171 dbus_message_type_to_string (dbus_message_get_type (m)));
172 g_test_message ("\tfrom: %s",
173 not_null2 (dbus_message_get_sender (m), "(dbus-daemon)"));
174 g_test_message ("\tto: %s",
175 not_null2 (dbus_message_get_destination (m), "(broadcast)"));
176 g_test_message ("\tpath: %s",
177 not_null (dbus_message_get_path (m)));
178 g_test_message ("\tinterface: %s",
179 not_null (dbus_message_get_interface (m)));
180 g_test_message ("\tmember: %s",
181 not_null (dbus_message_get_member (m)));
182 g_test_message ("\tsignature: %s",
183 not_null (dbus_message_get_signature (m)));
184 g_test_message ("\terror name: %s",
185 not_null (dbus_message_get_error_name (m)));
187 if (strcmp ("s", dbus_message_get_signature (m)) == 0)
189 DBusError e = DBUS_ERROR_INIT;
192 dbus_message_get_args (m, &e,
193 DBUS_TYPE_STRING, &s,
195 test_assert_no_error (&e);
196 g_test_message ("\tstring payload: %s", s);
200 /* these are macros so they get the right line number */
202 #define assert_hello(m) \
204 g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
205 ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_CALL)); \
206 g_assert_cmpstr (dbus_message_get_destination (m), ==, DBUS_SERVICE_DBUS); \
207 g_assert_cmpstr (dbus_message_get_path (m), ==, DBUS_PATH_DBUS); \
208 g_assert_cmpstr (dbus_message_get_interface (m), ==, DBUS_INTERFACE_DBUS); \
209 g_assert_cmpstr (dbus_message_get_member (m), ==, "Hello"); \
210 g_assert_cmpstr (dbus_message_get_signature (m), ==, ""); \
211 g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
212 g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
215 #define assert_hello_reply(m) \
217 DBusError _e = DBUS_ERROR_INIT; \
220 g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
221 ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_RETURN)); \
222 g_assert_cmpstr (dbus_message_get_sender (m), ==, DBUS_SERVICE_DBUS); \
223 g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
224 g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
225 g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
226 g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
227 g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
228 g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
230 dbus_message_get_args (m, &_e, \
231 DBUS_TYPE_STRING, &_s, \
232 DBUS_TYPE_INVALID); \
233 test_assert_no_error (&_e); \
234 g_assert_cmpstr (dbus_message_get_destination (m), ==, _s); \
237 #define assert_name_acquired(m) \
239 DBusError _e = DBUS_ERROR_INIT; \
242 g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
243 ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_SIGNAL)); \
244 g_assert_cmpstr (dbus_message_get_sender (m), ==, DBUS_SERVICE_DBUS); \
245 g_assert_cmpstr (dbus_message_get_path (m), ==, DBUS_PATH_DBUS); \
246 g_assert_cmpstr (dbus_message_get_interface (m), ==, DBUS_INTERFACE_DBUS); \
247 g_assert_cmpstr (dbus_message_get_member (m), ==, "NameAcquired"); \
248 g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
249 g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
250 g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
252 dbus_message_get_args (m, &_e, \
253 DBUS_TYPE_STRING, &_s, \
254 DBUS_TYPE_INVALID); \
255 test_assert_no_error (&_e); \
256 g_assert_cmpstr (dbus_message_get_destination (m), ==, _s); \
259 #define assert_method_call(m, sender, \
260 destination, path, iface, method, signature) \
262 g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
263 ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_CALL)); \
264 g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
265 g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
266 g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
267 g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
268 g_assert_cmpstr (dbus_message_get_member (m), ==, method); \
269 g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
270 g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
271 g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
274 #define assert_signal(m, \
275 sender, path, iface, member, signature, \
278 g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
279 ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_SIGNAL)); \
280 g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
281 g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
282 g_assert_cmpstr (dbus_message_get_path (m), ==, path); \
283 g_assert_cmpstr (dbus_message_get_interface (m), ==, iface); \
284 g_assert_cmpstr (dbus_message_get_member (m), ==, member); \
285 g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
286 g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
287 g_assert_cmpint (dbus_message_get_reply_serial (m), ==, 0); \
290 #define assert_method_reply(m, sender, destination, signature) \
292 g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
293 ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_METHOD_RETURN)); \
294 g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
295 g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
296 g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
297 g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
298 g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
299 g_assert_cmpstr (dbus_message_get_signature (m), ==, signature); \
300 g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
301 g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
304 #define assert_error_reply(m, sender, destination, error_name) \
306 g_assert_cmpstr (dbus_message_type_to_string (dbus_message_get_type (m)), \
307 ==, dbus_message_type_to_string (DBUS_MESSAGE_TYPE_ERROR)); \
308 g_assert_cmpstr (dbus_message_get_sender (m), ==, sender); \
309 g_assert_cmpstr (dbus_message_get_destination (m), ==, destination); \
310 g_assert_cmpstr (dbus_message_get_error_name (m), ==, error_name); \
311 g_assert_cmpstr (dbus_message_get_path (m), ==, NULL); \
312 g_assert_cmpstr (dbus_message_get_interface (m), ==, NULL); \
313 g_assert_cmpstr (dbus_message_get_member (m), ==, NULL); \
314 g_assert_cmpstr (dbus_message_get_signature (m), ==, "s"); \
315 g_assert_cmpint (dbus_message_get_serial (m), !=, 0); \
316 g_assert_cmpint (dbus_message_get_reply_serial (m), !=, 0); \
319 /* This is called after processing pending replies to our own method
320 * calls, but before anything else.
322 static DBusHandlerResult
323 monitor_filter (DBusConnection *connection,
324 DBusMessage *message,
327 Fixture *f = user_data;
329 g_assert_cmpstr (dbus_message_get_interface (message), !=,
330 "com.example.Tedious");
332 /* we are not interested in the monitor getting NameAcquired or NameLost
334 if (f->config == NULL || !f->config->care_about_our_names)
336 if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
338 dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
341 DBusError e = DBUS_ERROR_INIT;
344 dbus_message_get_args (message, &e,
345 DBUS_TYPE_STRING, &s,
347 test_assert_no_error (&e);
349 if (strcmp (s, f->monitor_name) == 0)
352 return DBUS_HANDLER_RESULT_HANDLED;
357 g_queue_push_tail (&f->monitored, dbus_message_ref (message));
359 return DBUS_HANDLER_RESULT_HANDLED;
362 static DBusHandlerResult
363 recipient_filter (DBusConnection *connection,
364 DBusMessage *message,
367 g_assert_cmpstr (dbus_message_get_interface (message), !=,
368 "com.example.CannotSend");
369 g_assert_cmpstr (dbus_message_get_interface (message), !=,
370 "com.example.CannotReceive");
372 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
375 static DBusHandlerResult
376 systemd_filter (DBusConnection *connection,
377 DBusMessage *message,
380 Fixture *f = user_data;
382 if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
384 dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
387 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
390 g_assert (f->systemd_message == NULL);
391 f->systemd_message = dbus_message_ref (message);
393 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
396 static DBusHandlerResult
397 activated_filter (DBusConnection *connection,
398 DBusMessage *message,
401 Fixture *f = user_data;
403 if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
405 dbus_message_is_signal (message, DBUS_INTERFACE_DBUS,
408 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
411 g_assert (f->activated_message == NULL);
412 f->activated_message = dbus_message_ref (message);
414 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
419 gconstpointer context)
423 f->ctx = test_main_context_get ();
426 dbus_error_init (&f->e);
428 f->address = test_get_dbus_daemon (f->config ? f->config->config_file : NULL,
429 TEST_USER_ME, &f->daemon_pid);
431 if (f->address == NULL)
434 f->monitor = test_connect_to_bus (f->ctx, f->address);
435 f->monitor_name = dbus_bus_get_unique_name (f->monitor);
436 f->sender = test_connect_to_bus (f->ctx, f->address);
437 f->sender_name = dbus_bus_get_unique_name (f->sender);
438 f->recipient = test_connect_to_bus (f->ctx, f->address);
439 f->recipient_name = dbus_bus_get_unique_name (f->recipient);
441 if (!dbus_connection_add_filter (f->monitor, monitor_filter, f, NULL))
444 if (!dbus_connection_add_filter (f->recipient, recipient_filter, f, NULL))
449 become_monitor (Fixture *f)
454 DBusMessageIter appender, array_appender;
455 const char * const *match_rules;
457 dbus_uint32_t zero = 0;
459 dbus_connection_set_route_peer_messages (f->monitor, TRUE);
461 if (f->config != NULL && f->config->match_rules != NULL)
462 match_rules = f->config->match_rules;
464 match_rules = wildcard_match_rules;
466 m = dbus_message_new_method_call (DBUS_SERVICE_DBUS,
467 DBUS_PATH_DBUS, DBUS_INTERFACE_MONITORING, "BecomeMonitor");
472 dbus_message_iter_init_append (m, &appender);
474 if (!dbus_message_iter_open_container (&appender, DBUS_TYPE_ARRAY, "s",
478 for (i = 0; match_rules[i] != NULL; i++)
480 if (!dbus_message_iter_append_basic (&array_appender, DBUS_TYPE_STRING,
485 if (!dbus_message_iter_close_container (&appender, &array_appender) ||
486 !dbus_message_iter_append_basic (&appender, DBUS_TYPE_UINT32, &zero))
489 if (!dbus_connection_send_with_reply (f->monitor, m, &pc,
490 DBUS_TIMEOUT_USE_DEFAULT) ||
494 dbus_message_unref (m);
497 if (dbus_pending_call_get_completed (pc))
498 test_pending_call_store_reply (pc, &m);
499 else if (!dbus_pending_call_set_notify (pc, test_pending_call_store_reply,
504 test_main_context_iterate (f->ctx, TRUE);
506 ok = dbus_message_get_args (m, &f->e,
508 test_assert_no_error (&f->e);
511 dbus_pending_call_unref (pc);
512 dbus_message_unref (m);
517 * Test the side-effects of becoming a monitor.
520 test_become_monitor (Fixture *f,
521 gconstpointer context)
525 dbus_bool_t got_unique = FALSE, got_a = FALSE, got_b = FALSE, got_c = FALSE;
526 dbus_bool_t lost_unique = FALSE, lost_a = FALSE, lost_b = FALSE, lost_c = FALSE;
528 if (f->address == NULL)
531 ret = dbus_bus_request_name (f->monitor, "com.example.A",
532 DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
533 test_assert_no_error (&f->e);
534 g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
536 ret = dbus_bus_request_name (f->monitor, "com.example.B",
537 DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
538 test_assert_no_error (&f->e);
539 g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
541 ret = dbus_bus_request_name (f->monitor, "com.example.C",
542 DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
543 test_assert_no_error (&f->e);
544 g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
546 while (!got_unique || !got_a || !got_b || !got_c)
548 if (g_queue_is_empty (&f->monitored))
549 test_main_context_iterate (f->ctx, TRUE);
551 while ((m = g_queue_pop_head (&f->monitored)) != NULL)
553 if (dbus_message_is_signal (m, DBUS_INTERFACE_DBUS,
557 dbus_bool_t ok = dbus_message_get_args (m, &f->e,
558 DBUS_TYPE_STRING, &name,
561 g_assert_cmpstr (dbus_message_get_path (m), ==,
564 test_assert_no_error (&f->e);
567 if (g_str_equal (name, f->monitor_name))
569 g_assert (!got_unique);
572 else if (g_str_equal (name, "com.example.A"))
577 else if (g_str_equal (name, "com.example.B"))
584 g_assert_cmpstr (name, ==, "com.example.C");
591 g_error ("unexpected message %s.%s",
592 dbus_message_get_interface (m),
593 dbus_message_get_member (m));
596 dbus_message_unref (m);
602 while (!lost_unique || !lost_a || !lost_b || !lost_c)
604 if (g_queue_is_empty (&f->monitored))
605 test_main_context_iterate (f->ctx, TRUE);
607 while ((m = g_queue_pop_head (&f->monitored)) != NULL)
609 if (dbus_message_is_signal (m, DBUS_INTERFACE_DBUS,
613 dbus_bool_t ok = dbus_message_get_args (m, &f->e,
614 DBUS_TYPE_STRING, &name,
617 test_assert_no_error (&f->e);
620 if (g_str_equal (name, f->monitor_name))
622 g_assert (!lost_unique);
625 else if (g_str_equal (name, "com.example.A"))
630 else if (g_str_equal (name, "com.example.B"))
637 g_assert_cmpstr (name, ==, "com.example.C");
644 g_error ("unexpected message %s.%s",
645 dbus_message_get_interface (m),
646 dbus_message_get_member (m));
649 dbus_message_unref (m);
653 /* Calling methods is forbidden; we get disconnected. */
654 dbus_bus_add_match (f->monitor, "", &f->e);
655 g_assert_cmpstr (f->e.name, ==, DBUS_ERROR_NO_REPLY);
656 g_assert (!dbus_connection_get_is_connected (f->monitor));
660 if (g_queue_is_empty (&f->monitored))
661 test_main_context_iterate (f->ctx, TRUE);
663 /* When we iterate all the connection's messages, we see ourselves
664 * losing all our names, then we're disconnected. */
665 while ((m = g_queue_pop_head (&f->monitored)) != NULL)
667 if (dbus_message_is_signal (m, DBUS_INTERFACE_LOCAL, "Disconnected"))
669 dbus_message_unref (m);
674 g_error ("unexpected message %s.%s",
675 dbus_message_get_interface (m),
676 dbus_message_get_member (m));
679 dbus_message_unref (m);
691 test_broadcast (Fixture *f,
692 gconstpointer context)
696 if (f->address == NULL)
699 dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
700 test_assert_no_error (&f->e);
704 m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal1");
705 dbus_connection_send (f->sender, m, NULL);
706 dbus_message_unref (m);
708 m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal2");
709 dbus_connection_send (f->sender, m, NULL);
710 dbus_message_unref (m);
712 m = dbus_message_new_signal ("/foo", "com.example.bar", "BroadcastSignal3");
713 dbus_connection_send (f->sender, m, NULL);
714 dbus_message_unref (m);
716 while (g_queue_get_length (&f->monitored) < 3)
717 test_main_context_iterate (f->ctx, TRUE);
719 m = g_queue_pop_head (&f->monitored);
720 assert_signal (m, f->sender_name, "/foo", "com.example.bar",
721 "BroadcastSignal1", "", NULL);
722 dbus_message_unref (m);
724 m = g_queue_pop_head (&f->monitored);
725 assert_signal (m, f->sender_name, "/foo", "com.example.bar",
726 "BroadcastSignal2", "", NULL);
727 dbus_message_unref (m);
729 m = g_queue_pop_head (&f->monitored);
730 assert_signal (m, f->sender_name, "/foo", "com.example.bar",
731 "BroadcastSignal3", "", NULL);
732 dbus_message_unref (m);
734 m = g_queue_pop_head (&f->monitored);
735 g_assert (m == NULL);
739 test_forbidden_broadcast (Fixture *f,
740 gconstpointer context)
744 if (f->address == NULL)
747 dbus_bus_add_match (f->recipient, "type='signal'", &f->e);
748 test_assert_no_error (&f->e);
752 m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
754 dbus_connection_send (f->sender, m, NULL);
755 dbus_message_unref (m);
757 m = dbus_message_new_signal ("/foo", "com.example.CannotReceive",
759 dbus_connection_send (f->sender, m, NULL);
760 dbus_message_unref (m);
762 m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
764 dbus_connection_send (f->sender, m, NULL);
765 dbus_message_unref (m);
767 while (g_queue_get_length (&f->monitored) < 6)
768 test_main_context_iterate (f->ctx, TRUE);
770 m = g_queue_pop_head (&f->monitored);
771 assert_signal (m, f->sender_name, "/foo", "com.example.CannotSend",
772 "BroadcastSignal1", "", NULL);
773 dbus_message_unref (m);
775 m = g_queue_pop_head (&f->monitored);
776 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
777 DBUS_ERROR_ACCESS_DENIED);
778 dbus_message_unref (m);
780 m = g_queue_pop_head (&f->monitored);
781 assert_signal (m, f->sender_name, "/foo", "com.example.CannotReceive",
782 "BroadcastSignal2", "", NULL);
783 dbus_message_unref (m);
785 m = g_queue_pop_head (&f->monitored);
786 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
787 DBUS_ERROR_ACCESS_DENIED);
788 dbus_message_unref (m);
790 m = g_queue_pop_head (&f->monitored);
791 assert_signal (m, f->sender_name, "/foo", "com.example.CannotSend",
792 "BroadcastSignal3", "", NULL);
793 dbus_message_unref (m);
795 m = g_queue_pop_head (&f->monitored);
796 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
797 DBUS_ERROR_ACCESS_DENIED);
798 dbus_message_unref (m);
800 m = g_queue_pop_head (&f->monitored);
801 g_assert (m == NULL);
805 test_unicast_signal (Fixture *f,
806 gconstpointer context)
810 if (f->address == NULL)
815 m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
816 if (!dbus_message_set_destination (m, f->recipient_name))
818 dbus_connection_send (f->sender, m, NULL);
819 dbus_message_unref (m);
821 m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal2");
822 if (!dbus_message_set_destination (m, f->recipient_name))
824 dbus_connection_send (f->sender, m, NULL);
825 dbus_message_unref (m);
827 m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal3");
828 if (!dbus_message_set_destination (m, f->recipient_name))
830 dbus_connection_send (f->sender, m, NULL);
831 dbus_message_unref (m);
833 while (g_queue_get_length (&f->monitored) < 3)
834 test_main_context_iterate (f->ctx, TRUE);
836 m = g_queue_pop_head (&f->monitored);
837 assert_signal (m, f->sender_name, "/foo",
838 "com.example.bar", "UnicastSignal1", "", f->recipient_name);
839 dbus_message_unref (m);
841 m = g_queue_pop_head (&f->monitored);
842 assert_signal (m, f->sender_name, "/foo",
843 "com.example.bar", "UnicastSignal2", "", f->recipient_name);
844 dbus_message_unref (m);
846 m = g_queue_pop_head (&f->monitored);
847 assert_signal (m, f->sender_name, "/foo",
848 "com.example.bar", "UnicastSignal3", "", f->recipient_name);
849 dbus_message_unref (m);
851 m = g_queue_pop_head (&f->monitored);
852 g_assert (m == NULL);
856 test_forbidden (Fixture *f,
857 gconstpointer context)
861 if (f->address == NULL)
866 m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
868 if (!dbus_message_set_destination (m, f->recipient_name))
870 dbus_connection_send (f->sender, m, NULL);
871 dbus_message_unref (m);
873 m = dbus_message_new_signal ("/foo", "com.example.CannotReceive",
875 if (!dbus_message_set_destination (m, f->recipient_name))
877 dbus_connection_send (f->sender, m, NULL);
878 dbus_message_unref (m);
880 m = dbus_message_new_signal ("/foo", "com.example.CannotSend",
882 if (!dbus_message_set_destination (m, f->recipient_name))
884 dbus_connection_send (f->sender, m, NULL);
885 dbus_message_unref (m);
887 while (g_queue_get_length (&f->monitored) < 6)
888 test_main_context_iterate (f->ctx, TRUE);
890 m = g_queue_pop_head (&f->monitored);
891 assert_signal (m, f->sender_name, "/foo",
892 "com.example.CannotSend", "UnicastSignal1", "", f->recipient_name);
893 dbus_message_unref (m);
895 m = g_queue_pop_head (&f->monitored);
896 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
897 DBUS_ERROR_ACCESS_DENIED);
898 dbus_message_unref (m);
900 m = g_queue_pop_head (&f->monitored);
901 assert_signal (m, f->sender_name, "/foo",
902 "com.example.CannotReceive", "UnicastSignal2", "", f->recipient_name);
903 dbus_message_unref (m);
905 m = g_queue_pop_head (&f->monitored);
906 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
907 DBUS_ERROR_ACCESS_DENIED);
908 dbus_message_unref (m);
910 m = g_queue_pop_head (&f->monitored);
911 assert_signal (m, f->sender_name, "/foo",
912 "com.example.CannotSend", "UnicastSignal3", "", f->recipient_name);
913 dbus_message_unref (m);
915 m = g_queue_pop_head (&f->monitored);
916 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
917 DBUS_ERROR_ACCESS_DENIED);
918 dbus_message_unref (m);
920 m = g_queue_pop_head (&f->monitored);
921 g_assert (m == NULL);
925 test_method_call (Fixture *f,
926 gconstpointer context)
930 if (f->address == NULL)
935 /* regression test for
936 * https://bugs.freedesktop.org/show_bug.cgi?id=90952 */
937 m = dbus_message_new_method_call (f->recipient_name, "/foo",
938 DBUS_INTERFACE_PEER, "Ping");
939 dbus_connection_send (f->sender, m, NULL);
940 dbus_message_unref (m);
942 while (g_queue_get_length (&f->monitored) < 2)
943 test_main_context_iterate (f->ctx, TRUE);
945 m = g_queue_pop_head (&f->monitored);
946 assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
947 DBUS_INTERFACE_PEER, "Ping", "");
948 dbus_message_unref (m);
950 m = g_queue_pop_head (&f->monitored);
951 assert_method_reply (m, f->recipient_name, f->sender_name, "");
952 dbus_message_unref (m);
954 m = g_queue_pop_head (&f->monitored);
955 g_assert (m == NULL);
957 m = dbus_message_new_method_call (f->recipient_name, "/foo", "com.example.bar",
959 dbus_connection_send (f->sender, m, NULL);
960 dbus_message_unref (m);
962 while (g_queue_get_length (&f->monitored) < 2)
963 test_main_context_iterate (f->ctx, TRUE);
965 m = g_queue_pop_head (&f->monitored);
966 assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
967 "com.example.bar", "Call1", "");
968 dbus_message_unref (m);
970 m = g_queue_pop_head (&f->monitored);
971 assert_error_reply (m, f->recipient_name, f->sender_name,
972 DBUS_ERROR_UNKNOWN_METHOD);
973 dbus_message_unref (m);
975 m = g_queue_pop_head (&f->monitored);
976 g_assert (m == NULL);
980 test_forbidden_method_call (Fixture *f,
981 gconstpointer context)
985 if (f->address == NULL)
990 m = dbus_message_new_method_call (f->recipient_name, "/foo",
991 "com.example.CannotSend", "Call1");
992 dbus_connection_send (f->sender, m, NULL);
993 dbus_message_unref (m);
995 while (g_queue_get_length (&f->monitored) < 2)
996 test_main_context_iterate (f->ctx, TRUE);
998 m = g_queue_pop_head (&f->monitored);
999 assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
1000 "com.example.CannotSend", "Call1", "");
1001 dbus_message_unref (m);
1003 m = g_queue_pop_head (&f->monitored);
1004 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1005 DBUS_ERROR_ACCESS_DENIED);
1006 dbus_message_unref (m);
1008 m = g_queue_pop_head (&f->monitored);
1009 g_assert (m == NULL);
1011 m = dbus_message_new_method_call (f->recipient_name, "/foo",
1012 "com.example.CannotReceive", "Call2");
1013 dbus_connection_send (f->sender, m, NULL);
1014 dbus_message_unref (m);
1016 while (g_queue_get_length (&f->monitored) < 2)
1017 test_main_context_iterate (f->ctx, TRUE);
1019 m = g_queue_pop_head (&f->monitored);
1020 assert_method_call (m, f->sender_name, f->recipient_name, "/foo",
1021 "com.example.CannotReceive", "Call2", "");
1022 dbus_message_unref (m);
1024 m = g_queue_pop_head (&f->monitored);
1025 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1026 DBUS_ERROR_ACCESS_DENIED);
1027 dbus_message_unref (m);
1029 m = g_queue_pop_head (&f->monitored);
1030 g_assert (m == NULL);
1034 test_dbus_daemon (Fixture *f,
1035 gconstpointer context)
1040 if (f->address == NULL)
1045 res = dbus_bus_request_name (f->sender, "com.example.Sender",
1046 DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
1047 test_assert_no_error (&f->e);
1048 g_assert_cmpint (res, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
1050 res = dbus_bus_release_name (f->sender, "com.example.Sender", &f->e);
1051 test_assert_no_error (&f->e);
1052 g_assert_cmpint (res, ==, DBUS_RELEASE_NAME_REPLY_RELEASED);
1054 while (g_queue_get_length (&f->monitored) < 8)
1055 test_main_context_iterate (f->ctx, TRUE);
1057 m = g_queue_pop_head (&f->monitored);
1058 assert_method_call (m, f->sender_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1059 DBUS_INTERFACE_DBUS, "RequestName", "su");
1060 dbus_message_unref (m);
1062 m = g_queue_pop_head (&f->monitored);
1063 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1064 "NameOwnerChanged", "sss", NULL);
1065 dbus_message_unref (m);
1067 /* FIXME: should we get this? */
1068 m = g_queue_pop_head (&f->monitored);
1069 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1070 "NameAcquired", "s", f->sender_name);
1071 dbus_message_unref (m);
1073 m = g_queue_pop_head (&f->monitored);
1074 assert_method_reply (m, DBUS_SERVICE_DBUS, f->sender_name, "u");
1075 dbus_message_unref (m);
1077 m = g_queue_pop_head (&f->monitored);
1078 assert_method_call (m, f->sender_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1079 DBUS_INTERFACE_DBUS, "ReleaseName", "s");
1080 dbus_message_unref (m);
1082 /* FIXME: should we get this? */
1083 m = g_queue_pop_head (&f->monitored);
1084 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1085 "NameLost", "s", f->sender_name);
1086 dbus_message_unref (m);
1088 m = g_queue_pop_head (&f->monitored);
1089 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1090 "NameOwnerChanged", "sss", NULL);
1091 dbus_message_unref (m);
1093 m = g_queue_pop_head (&f->monitored);
1094 assert_method_reply (m, DBUS_SERVICE_DBUS, f->sender_name, "u");
1095 dbus_message_unref (m);
1097 m = g_queue_pop_head (&f->monitored);
1098 g_assert (m == NULL);
1102 test_selective (Fixture *f,
1103 gconstpointer context)
1107 if (f->address == NULL)
1110 /* Match rules added before becoming a monitor should be cleared:
1111 * if they weren't, this test would get Interesting twice, then Tedious,
1112 * and only see Fun after that. */
1113 dbus_bus_add_match (f->monitor,
1114 "eavesdrop='true',interface='com.example.Interesting'", &f->e);
1115 test_assert_no_error (&f->e);
1116 dbus_bus_add_match (f->monitor,
1117 "eavesdrop='true',interface='com.example.Tedious'", &f->e);
1118 test_assert_no_error (&f->e);
1122 m = dbus_message_new_signal ("/foo", "com.example.Interesting",
1124 if (!dbus_message_set_destination (m, f->recipient_name))
1126 dbus_connection_send (f->sender, m, NULL);
1127 dbus_message_unref (m);
1129 m = dbus_message_new_signal ("/foo", "com.example.Tedious",
1131 if (!dbus_message_set_destination (m, f->recipient_name))
1133 dbus_connection_send (f->sender, m, NULL);
1134 dbus_message_unref (m);
1136 m = dbus_message_new_signal ("/foo", "com.example.Fun",
1138 if (!dbus_message_set_destination (m, f->recipient_name))
1140 dbus_connection_send (f->sender, m, NULL);
1141 dbus_message_unref (m);
1143 while (g_queue_get_length (&f->monitored) < 2)
1144 test_main_context_iterate (f->ctx, TRUE);
1146 /* We get the interesting signal and the fun signal, but not the tedious
1149 m = g_queue_pop_head (&f->monitored);
1150 assert_signal (m, f->sender_name, "/foo",
1151 "com.example.Interesting", "UnicastSignal1", "", f->recipient_name);
1152 dbus_message_unref (m);
1154 m = g_queue_pop_head (&f->monitored);
1155 assert_signal (m, f->sender_name, "/foo",
1156 "com.example.Fun", "UnicastSignal3", "", f->recipient_name);
1157 dbus_message_unref (m);
1159 m = g_queue_pop_head (&f->monitored);
1160 g_assert (m == NULL);
1164 /* currently only used for the systemd activation test */
1166 expect_new_connection (Fixture *f)
1170 while (g_queue_get_length (&f->monitored) < 4)
1171 test_main_context_iterate (f->ctx, TRUE);
1173 m = g_queue_pop_head (&f->monitored);
1175 dbus_message_unref (m);
1177 m = g_queue_pop_head (&f->monitored);
1178 assert_hello_reply (m);
1179 dbus_message_unref (m);
1181 m = g_queue_pop_head (&f->monitored);
1182 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1183 "NameOwnerChanged", "sss", NULL);
1184 dbus_message_unref (m);
1186 m = g_queue_pop_head (&f->monitored);
1187 assert_name_acquired (m);
1188 dbus_message_unref (m);
1191 /* currently only used for the systemd activation test */
1193 take_well_known_name (Fixture *f,
1194 DBusConnection *connection,
1199 ret = dbus_bus_request_name (connection, name,
1200 DBUS_NAME_FLAG_DO_NOT_QUEUE, &f->e);
1201 test_assert_no_error (&f->e);
1202 g_assert_cmpint (ret, ==, DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER);
1205 /* currently only used for the systemd activation test */
1207 expect_take_well_known_name (Fixture *f,
1208 DBusConnection *connection,
1212 const char *connection_name = dbus_bus_get_unique_name (connection);
1214 while (g_queue_get_length (&f->monitored) < 4)
1215 test_main_context_iterate (f->ctx, TRUE);
1217 m = g_queue_pop_head (&f->monitored);
1218 assert_method_call (m, connection_name, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1219 DBUS_INTERFACE_DBUS, "RequestName", "su");
1220 dbus_message_unref (m);
1222 m = g_queue_pop_head (&f->monitored);
1223 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1224 "NameOwnerChanged", "sss", NULL);
1225 dbus_message_unref (m);
1227 m = g_queue_pop_head (&f->monitored);
1228 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS,
1229 "NameAcquired", "s", connection_name);
1230 dbus_message_unref (m);
1232 m = g_queue_pop_head (&f->monitored);
1233 assert_method_reply (m, DBUS_SERVICE_DBUS, connection_name, "u");
1234 dbus_message_unref (m);
1238 test_activation (Fixture *f,
1239 gconstpointer context)
1243 if (f->address == NULL)
1248 /* The sender sends a message to an activatable service. */
1249 m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal1");
1250 if (!dbus_message_set_destination (m, "com.example.SystemdActivatable1"))
1252 dbus_connection_send (f->sender, m, NULL);
1253 dbus_message_unref (m);
1255 /* We observe the activation request, and the message that caused it,
1256 * before systemd has even joined the bus. */
1257 while (g_queue_get_length (&f->monitored) < 2)
1258 test_main_context_iterate (f->ctx, TRUE);
1260 m = g_queue_pop_head (&f->monitored);
1261 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1262 "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1263 "org.freedesktop.systemd1");
1264 dbus_message_unref (m);
1265 m = g_queue_pop_head (&f->monitored);
1266 assert_signal (m, f->sender_name, "/foo",
1267 "com.example.bar", "UnicastSignal1", "",
1268 "com.example.SystemdActivatable1");
1269 dbus_message_unref (m);
1271 /* The fake systemd connects to the bus. */
1272 f->systemd = test_connect_to_bus (f->ctx, f->address);
1273 if (!dbus_connection_add_filter (f->systemd, systemd_filter, f, NULL))
1275 f->systemd_name = dbus_bus_get_unique_name (f->systemd);
1277 expect_new_connection (f);
1278 take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
1279 expect_take_well_known_name (f, f->systemd, "org.freedesktop.systemd1");
1281 /* It gets its activation request. */
1282 while (f->systemd_message == NULL)
1283 test_main_context_iterate (f->ctx, TRUE);
1285 m = f->systemd_message;
1286 f->systemd_message = NULL;
1287 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1288 "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1289 "org.freedesktop.systemd1");
1290 dbus_message_unref (m);
1292 /* systemd starts the activatable service. */
1293 f->activated = test_connect_to_bus (f->ctx, f->address);
1294 if (!dbus_connection_add_filter (f->activated, activated_filter,
1297 f->activated_name = dbus_bus_get_unique_name (f->activated);
1299 expect_new_connection (f);
1300 take_well_known_name (f, f->activated, "com.example.SystemdActivatable1");
1301 expect_take_well_known_name (f, f->activated,
1302 "com.example.SystemdActivatable1");
1304 /* The message is delivered to the activatable service. */
1305 while (f->activated_message == NULL)
1306 test_main_context_iterate (f->ctx, TRUE);
1308 m = f->activated_message;
1309 f->activated_message = NULL;
1310 assert_signal (m, f->sender_name, "/foo",
1311 "com.example.bar", "UnicastSignal1", "",
1312 "com.example.SystemdActivatable1");
1313 dbus_message_unref (m);
1315 /* The sender sends a message to a different activatable service. */
1316 m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal2");
1317 if (!dbus_message_set_destination (m, "com.example.SystemdActivatable2"))
1319 dbus_connection_send (f->sender, m, NULL);
1320 dbus_message_unref (m);
1322 /* This time systemd is already ready for it. */
1323 while (g_queue_get_length (&f->monitored) < 2 ||
1324 f->systemd_message == NULL)
1325 test_main_context_iterate (f->ctx, TRUE);
1327 m = f->systemd_message;
1328 f->systemd_message = NULL;
1329 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1330 "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1331 "org.freedesktop.systemd1");
1332 dbus_message_unref (m);
1334 /* The monitor sees the activation request and the signal that
1336 m = g_queue_pop_head (&f->monitored);
1337 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1338 "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1339 "org.freedesktop.systemd1");
1340 dbus_message_unref (m);
1341 m = g_queue_pop_head (&f->monitored);
1342 assert_signal (m, f->sender_name, "/foo",
1343 "com.example.bar", "UnicastSignal2", "",
1344 "com.example.SystemdActivatable2");
1345 dbus_message_unref (m);
1347 /* The activatable service takes its name. Here I'm faking it by using
1348 * an existing connection. */
1349 take_well_known_name (f, f->activated, "com.example.SystemdActivatable2");
1351 /* The message is delivered to the activatable service.
1352 * Implementation detail: the monitor sees this happen before it even
1353 * sees that the name request happened, which is pretty odd. */
1354 while (f->activated_message == NULL)
1355 test_main_context_iterate (f->ctx, TRUE);
1357 m = f->activated_message;
1358 f->activated_message = NULL;
1359 assert_signal (m, f->sender_name, "/foo",
1360 "com.example.bar", "UnicastSignal2", "",
1361 "com.example.SystemdActivatable2");
1362 dbus_message_unref (m);
1364 expect_take_well_known_name (f, f->activated,
1365 "com.example.SystemdActivatable2");
1367 /* A third activation. */
1368 m = dbus_message_new_signal ("/foo", "com.example.bar", "UnicastSignal3");
1369 if (!dbus_message_set_destination (m, "com.example.SystemdActivatable3"))
1371 dbus_connection_send (f->sender, m, NULL);
1372 dbus_message_unref (m);
1374 /* Once again, we see the activation request and the reason. */
1375 while (g_queue_get_length (&f->monitored) < 2)
1376 test_main_context_iterate (f->ctx, TRUE);
1378 m = g_queue_pop_head (&f->monitored);
1379 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1380 "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1381 "org.freedesktop.systemd1");
1382 dbus_message_unref (m);
1383 m = g_queue_pop_head (&f->monitored);
1384 assert_signal (m, f->sender_name, "/foo",
1385 "com.example.bar", "UnicastSignal3", "",
1386 "com.example.SystemdActivatable3");
1387 dbus_message_unref (m);
1389 /* systemd gets the request too. */
1390 while (f->systemd_message == NULL)
1391 test_main_context_iterate (f->ctx, TRUE);
1393 m = f->systemd_message;
1394 f->systemd_message = NULL;
1395 assert_signal (m, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS,
1396 "org.freedesktop.systemd1.Activator", "ActivationRequest", "s",
1397 "org.freedesktop.systemd1");
1398 dbus_message_unref (m);
1400 /* This time activation fails */
1401 m = dbus_message_new_signal ("/org/freedesktop/systemd1",
1402 "org.freedesktop.systemd1.Activator", "ActivationFailure");
1406 const char *unit = "dbus-com.example.SystemdActivatable3.service";
1407 const char *error_name = "com.example.Nope";
1408 const char *error_message = "Computer says no";
1410 if (!dbus_message_append_args (m,
1411 DBUS_TYPE_STRING, &unit,
1412 DBUS_TYPE_STRING, &error_name,
1413 DBUS_TYPE_STRING, &error_message,
1419 if (!dbus_message_set_destination (m, "org.freedesktop.DBus"))
1421 dbus_connection_send (f->systemd, m, NULL);
1422 dbus_message_unref (m);
1424 /* The monitor sees activation fail */
1426 /* Once again, we see the activation request and the reason. */
1427 while (g_queue_get_length (&f->monitored) < 1)
1428 test_main_context_iterate (f->ctx, TRUE);
1430 m = g_queue_pop_head (&f->monitored);
1431 assert_error_reply (m, DBUS_SERVICE_DBUS, f->sender_name,
1432 "com.example.Nope");
1433 dbus_message_unref (m);
1435 #endif /* DBUS_UNIX */
1438 teardown (Fixture *f,
1439 gconstpointer context G_GNUC_UNUSED)
1441 dbus_error_free (&f->e);
1442 g_clear_error (&f->ge);
1444 if (f->monitor != NULL)
1446 dbus_connection_remove_filter (f->monitor, monitor_filter, f);
1447 dbus_connection_close (f->monitor);
1448 dbus_connection_unref (f->monitor);
1452 if (f->sender != NULL)
1454 dbus_connection_close (f->sender);
1455 dbus_connection_unref (f->sender);
1459 if (f->recipient != NULL)
1461 dbus_connection_remove_filter (f->recipient, recipient_filter, f);
1462 dbus_connection_close (f->recipient);
1463 dbus_connection_unref (f->recipient);
1464 f->recipient = NULL;
1467 if (f->systemd != NULL)
1469 dbus_connection_remove_filter (f->systemd, systemd_filter, f);
1470 dbus_connection_close (f->systemd);
1471 dbus_connection_unref (f->systemd);
1475 if (f->activated != NULL)
1477 dbus_connection_remove_filter (f->activated, activated_filter, f);
1478 dbus_connection_close (f->activated);
1479 dbus_connection_unref (f->activated);
1480 f->activated = NULL;
1483 test_kill_pid (f->daemon_pid);
1484 g_spawn_close_pid (f->daemon_pid);
1486 test_main_context_unref (f->ctx);
1488 g_queue_foreach (&f->monitored, (GFunc) dbus_message_unref, NULL);
1489 g_queue_clear (&f->monitored);
1491 g_free (f->address);
1498 test_init (&argc, &argv);
1500 g_test_add ("/monitor/become", Fixture, &side_effects_config,
1501 setup, test_become_monitor, teardown);
1502 g_test_add ("/monitor/broadcast", Fixture, NULL,
1503 setup, test_broadcast, teardown);
1504 g_test_add ("/monitor/forbidden-broadcast", Fixture, &forbidding_config,
1505 setup, test_forbidden_broadcast, teardown);
1506 g_test_add ("/monitor/unicast-signal", Fixture, NULL,
1507 setup, test_unicast_signal, teardown);
1508 g_test_add ("/monitor/forbidden", Fixture, &forbidding_config,
1509 setup, test_forbidden, teardown);
1510 g_test_add ("/monitor/method-call", Fixture, NULL,
1511 setup, test_method_call, teardown);
1512 g_test_add ("/monitor/forbidden-method", Fixture, &forbidding_config,
1513 setup, test_forbidden_method_call, teardown);
1514 g_test_add ("/monitor/dbus-daemon", Fixture, NULL,
1515 setup, test_dbus_daemon, teardown);
1516 g_test_add ("/monitor/selective", Fixture, &selective_config,
1517 setup, test_selective, teardown);
1518 g_test_add ("/monitor/wildcard", Fixture, &wildcard_config,
1519 setup, test_unicast_signal, teardown);
1520 g_test_add ("/monitor/no-rule", Fixture, &no_rules_config,
1521 setup, test_unicast_signal, teardown);
1522 g_test_add ("/monitor/eavesdrop", Fixture, &eavesdrop_config,
1523 setup, test_unicast_signal, teardown);
1524 g_test_add ("/monitor/no-eavesdrop", Fixture, &no_eavesdrop_config,
1525 setup, test_unicast_signal, teardown);
1528 /* this relies on the systemd activation code path */
1529 g_test_add ("/monitor/activation", Fixture, &fake_systemd_config,
1530 setup, test_activation, teardown);
1533 return g_test_run ();