1 /* gdbus-test-fixture.c - Test covering activation of in-tree servers.
3 * Copyright (C) 2012 Intel Corporation
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) version 3.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with the program; if not, see <http://www.gnu.org/licenses/>
18 * Authors: Tristan Van Berkom <tristanvb@openismus.com>
22 #include "gdbus-example-objectmanager-generated.h"
26 GDBusObjectManager *manager;
30 fixture_setup (TestFixture *fixture, gconstpointer unused)
32 /* Create the global dbus-daemon for this test suite */
33 fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
35 /* Add the private directory with our in-tree service files */
36 g_test_dbus_add_service_dir (fixture->dbus, TEST_SERVICES);
38 /* Start the private D-Bus daemon */
39 g_test_dbus_up (fixture->dbus);
43 fixture_teardown (TestFixture *fixture, gconstpointer unused)
46 g_object_unref (fixture->manager);
48 /* Stop the private D-Bus daemon */
49 g_test_dbus_down (fixture->dbus);
51 g_object_unref (fixture->dbus);
54 /* The gdbus-example-objectmanager-server exports 10 objects,
55 * to test the server has actually activated, let's ensure
56 * that 10 objects exist.
59 assert_ten_objects (GDBusObjectManager *manager)
63 objects = g_dbus_object_manager_get_objects (manager);
65 g_assert_cmpint (g_list_length (objects), ==, 10);
66 g_list_free_full (objects, g_object_unref);
70 quit_loop (gconstpointer data)
72 GMainLoop *loop = (GMainLoop *)data;
74 g_main_loop_quit (loop);
79 test_gtest_dbus (TestFixture *fixture, gconstpointer unused)
85 example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
86 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
87 "org.gtk.GDBus.Examples.ObjectManager",
89 NULL, /* GCancellable */
91 if (fixture->manager == NULL)
92 g_error ("Error getting object manager client: %s", error->message);
94 assert_ten_objects (fixture->manager);
101 #if !GLIB_CHECK_VERSION (2, 35, 1)
104 g_test_init (&argc, &argv, NULL);
106 /* Ensure that we can bring the GTestDBus up and down a hand full of times
107 * in a row, each time successfully activating the in-tree service
109 g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL,
110 fixture_setup, test_gtest_dbus, fixture_teardown);
111 g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL,
112 fixture_setup, test_gtest_dbus, fixture_teardown);
113 g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL,
114 fixture_setup, test_gtest_dbus, fixture_teardown);
115 g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL,
116 fixture_setup, test_gtest_dbus, fixture_teardown);
117 g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL,
118 fixture_setup, test_gtest_dbus, fixture_teardown);
120 return g_test_run ();