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 test_gtest_dbus (TestFixture *fixture, gconstpointer unused)
76 example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
77 G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
78 "org.gtk.GDBus.Examples.ObjectManager",
80 NULL, /* GCancellable */
82 if (fixture->manager == NULL)
83 g_error ("Error getting object manager client: %s", error->message);
85 assert_ten_objects (fixture->manager);
92 #if !GLIB_CHECK_VERSION (2, 35, 1)
95 g_test_init (&argc, &argv, NULL);
97 /* Ensure that we can bring the GTestDBus up and down a hand full of times
98 * in a row, each time successfully activating the in-tree service
100 g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL,
101 fixture_setup, test_gtest_dbus, fixture_teardown);
102 g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL,
103 fixture_setup, test_gtest_dbus, fixture_teardown);
104 g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL,
105 fixture_setup, test_gtest_dbus, fixture_teardown);
106 g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL,
107 fixture_setup, test_gtest_dbus, fixture_teardown);
108 g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL,
109 fixture_setup, test_gtest_dbus, fixture_teardown);
111 return g_test_run ();