This source file includes following definitions.
- widget_callback
- group_callback
- START_TEST
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 #define TEST_SUITE_NAME "lib/widget/group"
27
28 #include <config.h>
29
30 #include <check.h>
31
32 #include "lib/widget.h"
33
34 #include "tests/mctest.h"
35
36
37
38 static int ref = 0;
39
40
41
42 static cb_ret_t
43 widget_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
44 {
45 switch (msg)
46 {
47 case MSG_INIT:
48 ref++;
49 return widget_default_callback (w, NULL, MSG_INIT, 0, NULL);
50
51 case MSG_DESTROY:
52 ref--;
53 return widget_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
54
55 default:
56 return widget_default_callback (w, sender, msg, parm, data);
57 }
58 }
59
60
61
62 static cb_ret_t
63 group_callback (Widget *w, Widget *sender, widget_msg_t msg, int parm, void *data)
64 {
65 switch (msg)
66 {
67 case MSG_INIT:
68 ref++;
69 return group_default_callback (w, NULL, MSG_INIT, 0, NULL);
70
71 case MSG_DESTROY:
72 ref--;
73 return group_default_callback (w, NULL, MSG_DESTROY, 0, NULL);
74
75 default:
76 return group_default_callback (w, sender, msg, parm, data);
77 }
78 }
79
80
81
82
83 START_TEST (test_group_init_deinit)
84
85 {
86 WGroup *g, *g0;
87 Widget *w0;
88 WRect r;
89
90 g = g_new0 (WGroup, 1);
91 rect_init (&r, 0, 0, 20, 20);
92 group_init (g, &r, group_callback, NULL);
93
94 g0 = g_new0 (WGroup, 1);
95 rect_init (&r, 0, 0, 10, 10);
96 group_init (g0, &r, group_callback, NULL);
97 group_add_widget (g, g0);
98
99 w0 = g_new0 (Widget, 1);
100 rect_init (&r, 0, 0, 5, 5);
101 widget_init (w0, &r, widget_callback, NULL);
102 group_add_widget (g0, w0);
103
104 w0 = g_new0 (Widget, 1);
105 rect_init (&r, 5, 5, 5, 5);
106 widget_init (w0, &r, widget_callback, NULL);
107 group_add_widget (g0, w0);
108
109 g0 = g_new0 (WGroup, 1);
110 rect_init (&r, 10, 10, 10, 10);
111 group_init (g0, &r, group_callback, NULL);
112 group_add_widget (g, g0);
113
114 w0 = g_new0 (Widget, 1);
115 rect_init (&r, 10, 10, 5, 5);
116 widget_init (w0, &r, widget_callback, NULL);
117 group_add_widget (g0, w0);
118
119 w0 = g_new0 (Widget, 1);
120 rect_init (&r, 15, 15, 5, 5);
121 widget_init (w0, &r, widget_callback, NULL);
122 group_add_widget (g0, w0);
123
124 w0 = g_new0 (Widget, 1);
125 rect_init (&r, 5, 5, 10, 10);
126 widget_init (w0, &r, widget_callback, NULL);
127 group_add_widget (g, w0);
128
129 ck_assert_msg (w0->id == 7, "last id (%d) != 7", ref);
130
131 send_message (g, NULL, MSG_INIT, 0, NULL);
132
133 ck_assert_msg (ref == 8, "ref (%d) != 8", ref);
134
135 widget_destroy (WIDGET (g));
136
137 ck_assert_msg (ref == 0, "ref (%d) != 0", ref);
138 }
139
140 END_TEST
141
142
143
144
145 int
146 main (void)
147 {
148 TCase *tc_core;
149
150 tc_core = tcase_create ("Core");
151
152
153 tcase_add_test (tc_core, test_group_init_deinit);
154
155
156 return mctest_run_all (tc_core);
157 }
158
159