LCOV - code coverage report
Current view: top level - glib/gobject/tests - objects-refcount2.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 37 37 100.0 %
Date: 2024-04-30 05:17:35 Functions: 7 7 100.0 %
Branches: 6 6 100.0 %

           Branch data     Line data    Source code
       1                 :            : #include <glib.h>
       2                 :            : #include <glib-object.h>
       3                 :            : 
       4                 :            : #ifdef G_OS_UNIX
       5                 :            : #include <unistd.h>
       6                 :            : #endif
       7                 :            : 
       8                 :            : #define G_TYPE_TEST                (my_test_get_type ())
       9                 :            : #define MY_TEST(test)              (G_TYPE_CHECK_INSTANCE_CAST ((test), G_TYPE_TEST, GTest))
      10                 :            : #define MY_IS_TEST(test)           (G_TYPE_CHECK_INSTANCE_TYPE ((test), G_TYPE_TEST))
      11                 :            : #define MY_TEST_CLASS(tclass)      (G_TYPE_CHECK_CLASS_CAST ((tclass), G_TYPE_TEST, GTestClass))
      12                 :            : #define MY_IS_TEST_CLASS(tclass)   (G_TYPE_CHECK_CLASS_TYPE ((tclass), G_TYPE_TEST))
      13                 :            : #define MY_TEST_GET_CLASS(test)    (G_TYPE_INSTANCE_GET_CLASS ((test), G_TYPE_TEST, GTestClass))
      14                 :            : 
      15                 :            : typedef struct _GTest GTest;
      16                 :            : typedef struct _GTestClass GTestClass;
      17                 :            : 
      18                 :            : struct _GTest
      19                 :            : {
      20                 :            :   GObject object;
      21                 :            : };
      22                 :            : 
      23                 :            : struct _GTestClass
      24                 :            : {
      25                 :            :   GObjectClass parent_class;
      26                 :            : };
      27                 :            : 
      28                 :            : static GType my_test_get_type (void);
      29                 :            : 
      30                 :            : static void my_test_class_init (GTestClass * klass);
      31                 :            : static void my_test_init (GTest * test);
      32                 :            : static void my_test_dispose (GObject * object);
      33                 :            : 
      34                 :            : static GObjectClass *parent_class = NULL;
      35                 :            : 
      36                 :            : static GType
      37                 :          2 : my_test_get_type (void)
      38                 :            : {
      39                 :            :   static GType test_type = 0;
      40                 :            : 
      41         [ +  + ]:          2 :   if (!test_type) {
      42                 :          1 :     const GTypeInfo test_info = {
      43                 :            :       sizeof (GTestClass),
      44                 :            :       NULL,
      45                 :            :       NULL,
      46                 :            :       (GClassInitFunc) my_test_class_init,
      47                 :            :       NULL,
      48                 :            :       NULL,
      49                 :            :       sizeof (GTest),
      50                 :            :       0,
      51                 :            :       (GInstanceInitFunc) my_test_init,
      52                 :            :       NULL
      53                 :            :     };
      54                 :            : 
      55                 :          1 :     test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
      56                 :            :         &test_info, 0);
      57                 :            :   }
      58                 :          2 :   return test_type;
      59                 :            : }
      60                 :            : 
      61                 :            : static void
      62                 :          1 : my_test_class_init (GTestClass * klass)
      63                 :            : {
      64                 :            :   GObjectClass *gobject_class;
      65                 :            : 
      66                 :          1 :   gobject_class = (GObjectClass *) klass;
      67                 :            : 
      68                 :          1 :   parent_class = g_type_class_ref (G_TYPE_OBJECT);
      69                 :            : 
      70                 :          1 :   gobject_class->dispose = my_test_dispose;
      71                 :          1 : }
      72                 :            : 
      73                 :            : static void
      74                 :          1 : my_test_init (GTest * test)
      75                 :            : {
      76                 :          1 :   g_test_message ("init %p\n", test);
      77                 :          1 : }
      78                 :            : 
      79                 :            : static void
      80                 :          1 : my_test_dispose (GObject * object)
      81                 :            : {
      82                 :            :   GTest *test;
      83                 :            : 
      84                 :          1 :   test = MY_TEST (object);
      85                 :            : 
      86                 :          1 :   g_test_message ("dispose %p!\n", test);
      87                 :            : 
      88                 :          1 :   G_OBJECT_CLASS (parent_class)->dispose (object);
      89                 :          1 : }
      90                 :            : 
      91                 :            : static void
      92                 :  100000000 : my_test_do_refcount (GTest * test)
      93                 :            : {
      94                 :            :   static guint i = 1;
      95                 :            : 
      96         [ +  + ]:  100000000 :   if (i++ % 100000 == 0)
      97                 :       1000 :     g_test_message (".");
      98                 :            : 
      99                 :  100000000 :   g_object_ref (test);
     100                 :  100000000 :   g_object_unref (test);
     101                 :  100000000 : }
     102                 :            : 
     103                 :            : static void
     104                 :          1 : test_refcount_object_advanced (void)
     105                 :            : {
     106                 :            :   gint i;
     107                 :            :   GTest *test;
     108                 :            : 
     109                 :          1 :   test = g_object_new (G_TYPE_TEST, NULL);
     110                 :            : 
     111         [ +  + ]:  100000001 :   for (i = 0; i < 100000000; i++)
     112                 :            :     {
     113                 :  100000000 :       my_test_do_refcount (test);
     114                 :            :     }
     115                 :            : 
     116                 :          1 :   g_object_unref (test);
     117                 :          1 : }
     118                 :            : 
     119                 :            : int
     120                 :          1 : main (int argc, char **argv)
     121                 :            : {
     122                 :          1 :   g_log_set_always_fatal (G_LOG_LEVEL_WARNING |
     123                 :          1 :                           G_LOG_LEVEL_CRITICAL |
     124                 :          1 :                           g_log_set_always_fatal (G_LOG_FATAL_MASK));
     125                 :            : 
     126                 :          1 :   g_test_init (&argc, &argv, NULL);
     127                 :            : 
     128                 :          1 :   g_test_add_func ("/gobject/refcount/object-advanced", test_refcount_object_advanced);
     129                 :            : 
     130                 :          1 :   return g_test_run ();
     131                 :            : }

Generated by: LCOV version 1.14