|
Packit |
ae235b |
|
|
Packit |
ae235b |
#include "gdbus-object-manager-example/gdbus-example-objectmanager-generated.h"
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* ---------------------------------------------------------------------------------------------------- */
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* The fixture contains a GTestDBus object and
|
|
Packit |
ae235b |
* a proxy to the service we're going to be testing.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
typedef struct {
|
|
Packit |
ae235b |
GTestDBus *dbus;
|
|
Packit |
ae235b |
GDBusObjectManager *manager;
|
|
Packit |
ae235b |
} TestFixture;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
fixture_setup (TestFixture *fixture, gconstpointer unused)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GError *error = NULL;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* Create the global dbus-daemon for this test suite
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* Add the private directory with our in-tree service files,
|
|
Packit |
ae235b |
* TEST_SERVICES is defined by the build system to point
|
|
Packit |
ae235b |
* to the right directory.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
g_test_dbus_add_service_dir (fixture->dbus, TEST_SERVICES);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* Start the private D-Bus daemon
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
g_test_dbus_up (fixture->dbus);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* Create the proxy that we're going to test
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
fixture->manager =
|
|
Packit |
ae235b |
example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
|
|
Packit |
ae235b |
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
|
Packit |
ae235b |
"org.gtk.GDBus.Examples.ObjectManager",
|
|
Packit |
ae235b |
"/example/Animals",
|
|
Packit |
ae235b |
NULL, /* GCancellable */
|
|
Packit |
ae235b |
&error);
|
|
Packit |
ae235b |
if (fixture->manager == NULL)
|
|
Packit |
ae235b |
g_error ("Error getting object manager client: %s", error->message);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
fixture_teardown (TestFixture *fixture, gconstpointer unused)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
/* Tear down the proxy
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
if (fixture->manager)
|
|
Packit |
ae235b |
g_object_unref (fixture->manager);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* Stop the private D-Bus daemon
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
g_test_dbus_down (fixture->dbus);
|
|
Packit |
ae235b |
g_object_unref (fixture->dbus);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* The gdbus-example-objectmanager-server exports 10 objects,
|
|
Packit |
ae235b |
* to test the server has actually activated, let's ensure
|
|
Packit |
ae235b |
* that 10 objects exist.
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
static void
|
|
Packit |
ae235b |
test_gtest_dbus (TestFixture *fixture, gconstpointer unused)
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
GList *objects;
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
objects = g_dbus_object_manager_get_objects (fixture->manager);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
g_assert_cmpint (g_list_length (objects), ==, 10);
|
|
Packit |
ae235b |
g_list_free_full (objects, g_object_unref);
|
|
Packit |
ae235b |
}
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
int
|
|
Packit |
ae235b |
main (int argc,
|
|
Packit |
ae235b |
char *argv[])
|
|
Packit |
ae235b |
{
|
|
Packit |
ae235b |
g_test_init (&argc, &argv, NULL);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
/* This test simply ensures that we can bring the GTestDBus up and down a hand
|
|
Packit |
ae235b |
* full of times in a row, each time successfully activating the in-tree service
|
|
Packit |
ae235b |
*/
|
|
Packit |
ae235b |
g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL,
|
|
Packit |
ae235b |
fixture_setup, test_gtest_dbus, fixture_teardown);
|
|
Packit |
ae235b |
g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL,
|
|
Packit |
ae235b |
fixture_setup, test_gtest_dbus, fixture_teardown);
|
|
Packit |
ae235b |
g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL,
|
|
Packit |
ae235b |
fixture_setup, test_gtest_dbus, fixture_teardown);
|
|
Packit |
ae235b |
g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL,
|
|
Packit |
ae235b |
fixture_setup, test_gtest_dbus, fixture_teardown);
|
|
Packit |
ae235b |
g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL,
|
|
Packit |
ae235b |
fixture_setup, test_gtest_dbus, fixture_teardown);
|
|
Packit |
ae235b |
|
|
Packit |
ae235b |
return g_test_run ();
|
|
Packit |
ae235b |
}
|