| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-04 09:09:51 +02:00
										 |  |  | #include "gdbus-object-manager-example/objectmanager-gen.h"
 | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  | /* ---------------------------------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* The fixture contains a GTestDBus object and
 | 
					
						
							|  |  |  |  * a proxy to the service we're going to be testing. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | typedef struct { | 
					
						
							|  |  |  |   GTestDBus *dbus; | 
					
						
							|  |  |  |   GDBusObjectManager *manager; | 
					
						
							|  |  |  | } TestFixture; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | fixture_setup (TestFixture *fixture, gconstpointer unused) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  |   GError *error = NULL; | 
					
						
							| 
									
										
										
										
											2019-09-16 14:04:30 +02:00
										 |  |  |   gchar *relative, *servicesdir; | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Create the global dbus-daemon for this test suite
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  |   fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-16 14:04:30 +02:00
										 |  |  |   /* Add the private directory with our in-tree service files.
 | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2019-09-16 14:04:30 +02:00
										 |  |  |   relative = g_test_build_filename (G_TEST_BUILT, "services", NULL); | 
					
						
							|  |  |  |   servicesdir = g_canonicalize_filename (relative, NULL); | 
					
						
							|  |  |  |   g_free (relative); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   g_test_dbus_add_service_dir (fixture->dbus, servicesdir); | 
					
						
							|  |  |  |   g_free (servicesdir); | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  |   /* Start the private D-Bus daemon
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  |   g_test_dbus_up (fixture->dbus); | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /* Create the proxy that we're going to test
 | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   fixture->manager = | 
					
						
							|  |  |  |     example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION, | 
					
						
							|  |  |  |                                                     G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, | 
					
						
							|  |  |  |                                                     "org.gtk.GDBus.Examples.ObjectManager", | 
					
						
							|  |  |  |                                                     "/example/Animals", | 
					
						
							|  |  |  |                                                     NULL, /* GCancellable */ | 
					
						
							|  |  |  |                                                     &error); | 
					
						
							|  |  |  |   if (fixture->manager == NULL) | 
					
						
							|  |  |  |     g_error ("Error getting object manager client: %s", error->message); | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void | 
					
						
							|  |  |  | fixture_teardown (TestFixture *fixture, gconstpointer unused) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  |   /* Tear down the proxy
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  |   if (fixture->manager) | 
					
						
							|  |  |  |     g_object_unref (fixture->manager); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  |   /* Stop the private D-Bus daemon
 | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  |   g_test_dbus_down (fixture->dbus); | 
					
						
							|  |  |  |   g_object_unref (fixture->dbus); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* The gdbus-example-objectmanager-server exports 10 objects,
 | 
					
						
							|  |  |  |  * to test the server has actually activated, let's ensure | 
					
						
							|  |  |  |  * that 10 objects exist. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | static void | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  | test_gtest_dbus (TestFixture *fixture, gconstpointer unused) | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | { | 
					
						
							|  |  |  |   GList *objects; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  |   objects = g_dbus_object_manager_get_objects (fixture->manager); | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  |   g_assert_cmpint (g_list_length (objects), ==, 10); | 
					
						
							|  |  |  |   g_list_free_full (objects, g_object_unref); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int | 
					
						
							|  |  |  | main (int   argc, | 
					
						
							|  |  |  |       char *argv[]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2022-11-23 11:15:20 +00:00
										 |  |  |   g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL); | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-16 16:26:08 +09:00
										 |  |  |   /* This test simply ensures that we can bring the GTestDBus up and down a hand
 | 
					
						
							|  |  |  |    * full of times in a row, each time successfully activating the in-tree service | 
					
						
							| 
									
										
										
										
											2012-12-20 15:34:22 +09:00
										 |  |  |    */ | 
					
						
							|  |  |  |   g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL, | 
					
						
							|  |  |  |   	      fixture_setup, test_gtest_dbus, fixture_teardown); | 
					
						
							|  |  |  |   g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL, | 
					
						
							|  |  |  |   	      fixture_setup, test_gtest_dbus, fixture_teardown); | 
					
						
							|  |  |  |   g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL, | 
					
						
							|  |  |  |   	      fixture_setup, test_gtest_dbus, fixture_teardown); | 
					
						
							|  |  |  |   g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL, | 
					
						
							|  |  |  |   	      fixture_setup, test_gtest_dbus, fixture_teardown); | 
					
						
							|  |  |  |   g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL, | 
					
						
							|  |  |  |   	      fixture_setup, test_gtest_dbus, fixture_teardown); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   return g_test_run (); | 
					
						
							|  |  |  | } |