Merge branch '976-disable-assert-checks' into 'master'
[glib.git] / gio / tests / gdbus-test-fixture.c
blob1e0a3223c5cee3f95e1371b2d48b6ecfa677f8fa
2 #include "gdbus-object-manager-example/gdbus-example-objectmanager-generated.h"
4 /* ---------------------------------------------------------------------------------------------------- */
6 /* The fixture contains a GTestDBus object and
7 * a proxy to the service we're going to be testing.
8 */
9 typedef struct {
10 GTestDBus *dbus;
11 GDBusObjectManager *manager;
12 } TestFixture;
14 static void
15 fixture_setup (TestFixture *fixture, gconstpointer unused)
17 GError *error = NULL;
19 /* Create the global dbus-daemon for this test suite
21 fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
23 /* Add the private directory with our in-tree service files,
24 * TEST_SERVICES is defined by the build system to point
25 * to the right directory.
27 g_test_dbus_add_service_dir (fixture->dbus, TEST_SERVICES);
29 /* Start the private D-Bus daemon
31 g_test_dbus_up (fixture->dbus);
33 /* Create the proxy that we're going to test
35 fixture->manager =
36 example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
37 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
38 "org.gtk.GDBus.Examples.ObjectManager",
39 "/example/Animals",
40 NULL, /* GCancellable */
41 &error);
42 if (fixture->manager == NULL)
43 g_error ("Error getting object manager client: %s", error->message);
46 static void
47 fixture_teardown (TestFixture *fixture, gconstpointer unused)
49 /* Tear down the proxy
51 if (fixture->manager)
52 g_object_unref (fixture->manager);
54 /* Stop the private D-Bus daemon
56 g_test_dbus_down (fixture->dbus);
57 g_object_unref (fixture->dbus);
60 /* The gdbus-example-objectmanager-server exports 10 objects,
61 * to test the server has actually activated, let's ensure
62 * that 10 objects exist.
64 static void
65 test_gtest_dbus (TestFixture *fixture, gconstpointer unused)
67 GList *objects;
69 objects = g_dbus_object_manager_get_objects (fixture->manager);
71 g_assert_cmpint (g_list_length (objects), ==, 10);
72 g_list_free_full (objects, g_object_unref);
75 int
76 main (int argc,
77 char *argv[])
79 g_test_init (&argc, &argv, NULL);
81 /* This test simply ensures that we can bring the GTestDBus up and down a hand
82 * full of times in a row, each time successfully activating the in-tree service
84 g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL,
85 fixture_setup, test_gtest_dbus, fixture_teardown);
86 g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL,
87 fixture_setup, test_gtest_dbus, fixture_teardown);
88 g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL,
89 fixture_setup, test_gtest_dbus, fixture_teardown);
90 g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL,
91 fixture_setup, test_gtest_dbus, fixture_teardown);
92 g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL,
93 fixture_setup, test_gtest_dbus, fixture_teardown);
95 return g_test_run ();