Add refcounted data
[glib.git] / glib / tests / rcbox.c
blob19b3842e5c75871c356c01c48a445885005006fe
1 #include <glib.h>
3 typedef struct {
4 float x, y;
5 } Point;
7 static Point *global_point;
9 static void
10 test_rcbox_new (void)
12 Point *a = g_rc_box_new (Point);
14 g_assert_nonnull (a);
16 g_rc_box_release (a);
18 a = g_rc_box_new0 (Point);
19 g_assert_nonnull (a);
20 g_assert_cmpfloat (a->x, ==, 0.f);
21 g_assert_cmpfloat (a->y, ==, 0.f);
23 g_rc_box_release (a);
26 static void
27 point_clear (Point *p)
29 g_assert_nonnull (p);
31 g_assert_cmpfloat (p->x, ==, 42.0f);
32 g_assert_cmpfloat (p->y, ==, 47.0f);
34 g_assert_true (global_point == p);
35 global_point = NULL;
38 static void
39 test_rcbox_release_full (void)
41 Point *p = g_rc_box_new (Point);
43 g_assert_nonnull (p);
44 global_point = p;
46 p->x = 42.0f;
47 p->y = 47.0f;
49 g_assert_true (g_rc_box_acquire (p) == p);
51 g_rc_box_release_full (p, (GDestroyNotify) point_clear);
52 g_assert_nonnull (global_point);
53 g_assert_true (p == global_point);
55 g_rc_box_release_full (p, (GDestroyNotify) point_clear);
56 g_assert_null (global_point);
59 static void
60 test_rcbox_dup (void)
62 Point *a = g_rc_box_new (Point);
63 Point *b = g_rc_box_dup (a);
65 g_assert_true (a != b);
67 g_rc_box_release (a);
68 g_rc_box_release (b);
71 int
72 main (int argc,
73 char *argv[])
75 g_test_init (&argc, &argv, NULL);
77 g_test_add_func ("/rcbox/new", test_rcbox_new);
78 g_test_add_func ("/rcbox/dup", test_rcbox_dup);
79 g_test_add_func ("/rcbox/release-full", test_rcbox_release_full);
81 return g_test_run ();