2 #include "gdbus-object-manager-example/objectmanager-gen.h"
4 /* ---------------------------------------------------------------------------------------------------- */
6 /* The fixture contains a GTestDBus object and
7 * a proxy to the service we're going to be testing.
11 GDBusObjectManager *manager;
15 fixture_setup (TestFixture *fixture, gconstpointer unused)
18 gchar *relative, *servicesdir;
20 /* Create the global dbus-daemon for this test suite
22 fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
24 /* Add the private directory with our in-tree service files.
26 relative = g_test_build_filename (G_TEST_BUILT, "services", NULL);
27 servicesdir = g_canonicalize_filename (relative, NULL);
30 g_test_dbus_add_service_dir (fixture->dbus, servicesdir);
33 /* Start the private D-Bus daemon
35 g_test_dbus_up (fixture->dbus);
37 /* Create the proxy that we're going to test
40 example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
41 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
42 "org.gtk.GDBus.Examples.ObjectManager",
44 NULL, /* GCancellable */
46 if (fixture->manager == NULL)
47 g_error ("Error getting object manager client: %s", error->message);
51 fixture_teardown (TestFixture *fixture, gconstpointer unused)
53 /* Tear down the proxy
56 g_object_unref (fixture->manager);
58 /* Stop the private D-Bus daemon
60 g_test_dbus_down (fixture->dbus);
61 g_object_unref (fixture->dbus);
64 /* The gdbus-example-objectmanager-server exports 10 objects,
65 * to test the server has actually activated, let's ensure
66 * that 10 objects exist.
69 test_gtest_dbus (TestFixture *fixture, gconstpointer unused)
73 objects = g_dbus_object_manager_get_objects (fixture->manager);
75 g_assert_cmpint (g_list_length (objects), ==, 10);
76 g_list_free_full (objects, g_object_unref);
83 g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
85 /* This test simply ensures that we can bring the GTestDBus up and down a hand
86 * full of times in a row, each time successfully activating the in-tree service
88 g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL,
89 fixture_setup, test_gtest_dbus, fixture_teardown);
90 g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL,
91 fixture_setup, test_gtest_dbus, fixture_teardown);
92 g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL,
93 fixture_setup, test_gtest_dbus, fixture_teardown);
94 g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL,
95 fixture_setup, test_gtest_dbus, fixture_teardown);
96 g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL,
97 fixture_setup, test_gtest_dbus, fixture_teardown);