LCOV - code coverage report
Current view: top level - glib/gio/tests - gdbus-test-fixture.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 33 0.0 %
Date: 2024-04-23 05:16:05 Functions: 0 4 0.0 %
Branches: 0 4 0.0 %

           Branch data     Line data    Source code
       1                 :            : 
       2                 :            : #include "gdbus-object-manager-example/objectmanager-gen.h"
       3                 :            : 
       4                 :            : /* ---------------------------------------------------------------------------------------------------- */
       5                 :            : 
       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;
      13                 :            : 
      14                 :            : static void
      15                 :          0 : fixture_setup (TestFixture *fixture, gconstpointer unused)
      16                 :            : {
      17                 :          0 :   GError *error = NULL;
      18                 :            :   gchar *relative, *servicesdir;
      19                 :            : 
      20                 :            :   /* Create the global dbus-daemon for this test suite
      21                 :            :    */
      22                 :          0 :   fixture->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
      23                 :            : 
      24                 :            :   /* Add the private directory with our in-tree service files.
      25                 :            :    */
      26                 :          0 :   relative = g_test_build_filename (G_TEST_BUILT, "services", NULL);
      27                 :          0 :   servicesdir = g_canonicalize_filename (relative, NULL);
      28                 :          0 :   g_free (relative);
      29                 :            : 
      30                 :          0 :   g_test_dbus_add_service_dir (fixture->dbus, servicesdir);
      31                 :          0 :   g_free (servicesdir);
      32                 :            : 
      33                 :            :   /* Start the private D-Bus daemon
      34                 :            :    */
      35                 :          0 :   g_test_dbus_up (fixture->dbus);
      36                 :            : 
      37                 :            :   /* Create the proxy that we're going to test
      38                 :            :    */
      39                 :          0 :   fixture->manager =
      40                 :          0 :     example_object_manager_client_new_for_bus_sync (G_BUS_TYPE_SESSION,
      41                 :            :                                                     G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
      42                 :            :                                                     "org.gtk.GDBus.Examples.ObjectManager",
      43                 :            :                                                     "/example/Animals",
      44                 :            :                                                     NULL, /* GCancellable */
      45                 :            :                                                     &error);
      46         [ #  # ]:          0 :   if (fixture->manager == NULL)
      47                 :          0 :     g_error ("Error getting object manager client: %s", error->message);
      48                 :          0 : }
      49                 :            : 
      50                 :            : static void
      51                 :          0 : fixture_teardown (TestFixture *fixture, gconstpointer unused)
      52                 :            : {
      53                 :            :   /* Tear down the proxy
      54                 :            :    */
      55         [ #  # ]:          0 :   if (fixture->manager)
      56                 :          0 :     g_object_unref (fixture->manager);
      57                 :            : 
      58                 :            :   /* Stop the private D-Bus daemon
      59                 :            :    */
      60                 :          0 :   g_test_dbus_down (fixture->dbus);
      61                 :          0 :   g_object_unref (fixture->dbus);
      62                 :          0 : }
      63                 :            : 
      64                 :            : /* The gdbus-example-objectmanager-server exports 10 objects,
      65                 :            :  * to test the server has actually activated, let's ensure
      66                 :            :  * that 10 objects exist.
      67                 :            :  */
      68                 :            : static void
      69                 :          0 : test_gtest_dbus (TestFixture *fixture, gconstpointer unused)
      70                 :            : {
      71                 :            :   GList *objects;
      72                 :            : 
      73                 :          0 :   objects = g_dbus_object_manager_get_objects (fixture->manager);
      74                 :            : 
      75                 :          0 :   g_assert_cmpint (g_list_length (objects), ==, 10);
      76                 :          0 :   g_list_free_full (objects, g_object_unref);
      77                 :          0 : }
      78                 :            : 
      79                 :            : int
      80                 :          0 : main (int   argc,
      81                 :            :       char *argv[])
      82                 :            : {
      83                 :          0 :   g_test_init (&argc, &argv, G_TEST_OPTION_ISOLATE_DIRS, NULL);
      84                 :            : 
      85                 :            :   /* This test simply ensures that we can bring the GTestDBus up and down a hand
      86                 :            :    * full of times in a row, each time successfully activating the in-tree service
      87                 :            :    */
      88                 :          0 :   g_test_add ("/GTestDBus/Cycle1", TestFixture, NULL,
      89                 :            :               fixture_setup, test_gtest_dbus, fixture_teardown);
      90                 :          0 :   g_test_add ("/GTestDBus/Cycle2", TestFixture, NULL,
      91                 :            :               fixture_setup, test_gtest_dbus, fixture_teardown);
      92                 :          0 :   g_test_add ("/GTestDBus/Cycle3", TestFixture, NULL,
      93                 :            :               fixture_setup, test_gtest_dbus, fixture_teardown);
      94                 :          0 :   g_test_add ("/GTestDBus/Cycle4", TestFixture, NULL,
      95                 :            :               fixture_setup, test_gtest_dbus, fixture_teardown);
      96                 :          0 :   g_test_add ("/GTestDBus/Cycle5", TestFixture, NULL,
      97                 :            :               fixture_setup, test_gtest_dbus, fixture_teardown);
      98                 :            :   
      99                 :          0 :   return g_test_run ();
     100                 :            : }

Generated by: LCOV version 1.14