Merge branch 'test-ip_mreq_source-android-only' into 'master'
[glib.git] / tests / refcount / objects2.c
blobe19bc67ca76b0b73b956d0b716775611aa24f229
1 #include <glib.h>
2 #include <glib-object.h>
4 #ifdef G_OS_UNIX
5 #include <unistd.h>
6 #endif
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))
15 typedef struct _GTest GTest;
16 typedef struct _GTestClass GTestClass;
18 struct _GTest
20 GObject object;
23 struct _GTestClass
25 GObjectClass parent_class;
28 static GType my_test_get_type (void);
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);
34 static GObjectClass *parent_class = NULL;
36 static GType
37 my_test_get_type (void)
39 static GType test_type = 0;
41 if (!test_type) {
42 const GTypeInfo test_info = {
43 sizeof (GTestClass),
44 NULL,
45 NULL,
46 (GClassInitFunc) my_test_class_init,
47 NULL,
48 NULL,
49 sizeof (GTest),
51 (GInstanceInitFunc) my_test_init,
52 NULL
55 test_type = g_type_register_static (G_TYPE_OBJECT, "GTest",
56 &test_info, 0);
58 return test_type;
61 static void
62 my_test_class_init (GTestClass * klass)
64 GObjectClass *gobject_class;
66 gobject_class = (GObjectClass *) klass;
68 parent_class = g_type_class_ref (G_TYPE_OBJECT);
70 gobject_class->dispose = my_test_dispose;
73 static void
74 my_test_init (GTest * test)
76 g_print ("init %p\n", test);
79 static void
80 my_test_dispose (GObject * object)
82 GTest *test;
84 test = MY_TEST (object);
86 g_print ("dispose %p!\n", test);
88 G_OBJECT_CLASS (parent_class)->dispose (object);
91 static void
92 my_test_do_refcount (GTest * test)
94 static guint i = 1;
95 if (i++ % 100000 == 0)
96 g_print (".");
97 g_object_ref (test);
98 g_object_unref (test);
102 main (int argc, char **argv)
104 gint i;
105 GTest *test;
107 g_print ("START: %s\n", argv[0]);
108 g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | g_log_set_always_fatal (G_LOG_FATAL_MASK));
110 test = g_object_new (G_TYPE_TEST, NULL);
112 for (i=0; i<100000000; i++) {
113 my_test_do_refcount (test);
116 g_object_unref (test);
118 g_print ("\n");
120 return 0;