summaryrefslogtreecommitdiff
path: root/src/tests/elementary/spec/efl_test_pack.c
blob: 05f1e1f9ed616bf259706bcc650748198f2b3387 (plain)
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Efl_Ui.h>
#include "efl_ui_spec_suite.h"
#include "suite_helpers.h"

/* spec-meta-start
      {"test-interface":"Efl.Pack",
       "test-widgets": ["Efl.Ui.Table", "Efl.Ui.Relative_Container"]}

   spec-meta-end */

/*
  In general:
    - If a subobject is deleted the box simply forgets about it. Never return this element again container.
*/

EFL_START_TEST(base2)
{
   ck_assert(win);
   ck_assert(widget);
}
EFL_END_TEST

static void
_setup_std_pack(Efl_Ui_Widget *wid[3])
{
   unsigned int i;

   for (i = 0; i < 3; ++i)
     {
        wid[i] = create_test_widget();
        ck_assert_int_eq(efl_pack(widget, wid[i]), EINA_TRUE);
        efl_gfx_entity_visible_set(widget, EINA_TRUE);
     }
}

/*
  pack_clear function:
  - each element must be deleted after the call
  - the container must have 0 contents after the call
  - the call must return true even if the container is empty
*/

EFL_START_TEST(pack_clear1)
{
   Efl_Ui_Widget *wid[3];
   unsigned int i;

   _setup_std_pack(wid);

   for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i)
     {
        efl_wref_add(wid[i], &wid[i]);
     }

   ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE);

   for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i)
     {
        ck_assert_ptr_eq(wid[i], NULL);
     }

   efl_test_container_content_equal(NULL, 0);
}
EFL_END_TEST

EFL_START_TEST(pack_clear2)
{
   Efl_Ui_Widget *wid[3];

   _setup_std_pack(wid);

   ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE);
   ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE);
   ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE);
   ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE);
   ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE);
}
EFL_END_TEST

/*
  unpack_all function:
  - each element must have exactly one reference after the call
  - the container must have 0 contents after the call
  - the call must return true even if the container is empty
*/

EFL_START_TEST(unpack_all1)
{
   Efl_Ui_Widget *wid[3];
   unsigned int i;

   _setup_std_pack(wid);

   ck_assert_int_eq(efl_pack_unpack_all(widget), EINA_TRUE);

   for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i)
     {
        ck_assert_int_eq(efl_ref_count(wid[i]), 1);
     }
   efl_test_container_content_equal(NULL, 0);
}
EFL_END_TEST

EFL_START_TEST(unpack_all2)
{
   Efl_Ui_Widget *wid[3];
   unsigned int i;

   _setup_std_pack(wid);

   ck_assert_int_eq(efl_pack_unpack_all(widget), EINA_TRUE);
   ck_assert_int_eq(efl_pack_clear(widget), EINA_TRUE);

   for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i)
     {
        ck_assert_int_eq(efl_ref_count(wid[i]), 1);
     }
   efl_test_container_content_equal(NULL, 0);
}
EFL_END_TEST

/*
  unpack function:
  - the element must have exactly one reference after the call
  - the container must have one content less after the call
  - the widget parent must be different from the parent
  - unpacking something invalid can return EINA_FALSE but must not print an error
*/

EFL_START_TEST(unpack1)
{
   Efl_Ui_Widget *wid[3];
   _setup_std_pack(wid);

   ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_TRUE);
   ck_assert_ptr_ne(efl_test_parent_get(wid[2]), widget);
   ck_assert_int_eq(efl_ref_count(wid[2]), 1);
   efl_test_container_content_equal(wid, 2);
}
EFL_END_TEST

EFL_START_TEST(unpack2)
{
   Efl_Ui_Widget *wid[3];
   _setup_std_pack(wid);

   ck_assert_int_eq(efl_pack_unpack(widget, wid[0]), EINA_TRUE);
   ck_assert_int_eq(efl_pack(widget, wid[0]), EINA_TRUE);
   ck_assert_int_eq(efl_pack_unpack(widget, wid[0]), EINA_TRUE);
   ck_assert_int_eq(efl_pack(widget, wid[0]), EINA_TRUE);

   efl_test_container_content_equal(wid, 3);
}
EFL_END_TEST

EFL_START_TEST(unpack3)
{
   Efl_Ui_Widget *wid[3], *invalid;
   _setup_std_pack(wid);

   invalid = create_test_widget();
   ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_TRUE);
   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_FALSE);
   EXPECT_ERROR_END;
   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack_unpack(widget, wid[2]), EINA_FALSE);
   EXPECT_ERROR_END;
   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack_unpack(widget, (Eo*)0x111), EINA_FALSE);
   EXPECT_ERROR_END;
   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack_unpack(widget, invalid), EINA_FALSE);
   EXPECT_ERROR_END;
   efl_test_container_content_equal(wid, 2);
}
EFL_END_TEST

/*
  pack function:
  - element must be added to the content of the container
  - elements widget_parent must be the container
  - double adding a widdget must error
  - adding something invalid must error
*/

EFL_START_TEST(pack1)
{
   Efl_Ui_Widget *wid[3];
   unsigned int i;

   _setup_std_pack(wid);

   for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i)
     {
        ck_assert_int_eq(efl_ref_count(wid[i]), 1);
        ck_assert_ptr_eq(efl_test_parent_get(wid[i]), widget);
     }

   efl_test_container_content_equal(wid, 3);
}
EFL_END_TEST

EFL_START_TEST(pack2)
{
   Efl_Ui_Widget *wid[3];
   _setup_std_pack(wid);

   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack(widget, wid[0]), EINA_FALSE);
   EXPECT_ERROR_END;
   efl_test_container_content_equal(wid, 3);
}
EFL_END_TEST

EFL_START_TEST(pack3)
{
   Efl_Ui_Widget *wid[3];
   _setup_std_pack(wid);

   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack(widget, (Eo*)0x111F), EINA_FALSE);
   EXPECT_ERROR_END;
   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack(widget, widget), EINA_FALSE);
   EXPECT_ERROR_END;
   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_pack(widget, NULL), EINA_FALSE);
   EXPECT_ERROR_END;
   efl_test_container_content_equal(wid, 3);
}
EFL_END_TEST

EFL_START_TEST(evt_content_added)
{
   Eina_Bool called = EINA_TRUE;
   Efl_Ui_Widget *wid = create_test_widget();
   efl_test_container_expect_evt_content_added(widget, EFL_CONTAINER_EVENT_CONTENT_ADDED, &called, wid);
   efl_pack(widget, wid);
   ck_assert_int_eq(called, EINA_TRUE);
}
EFL_END_TEST

EFL_START_TEST(evt_content_removed)
{
   Eina_Bool called = EINA_TRUE;
   Efl_Ui_Widget *wid[3];

   _setup_std_pack(wid);

   efl_test_container_expect_evt_content_added(widget, EFL_CONTAINER_EVENT_CONTENT_REMOVED, &called, wid[1]);
   efl_pack_unpack(widget, wid[1]);
   ck_assert_int_eq(called, EINA_TRUE);
}
EFL_END_TEST

EFL_START_TEST(child_killed)
{
   Efl_Ui_Widget *wid[3];
   _setup_std_pack(wid);

   efl_wref_add(wid[0], &wid[0]);
   efl_del(wid[0]);
   efl_test_container_content_equal(&wid[1], 2);
   ck_assert_ptr_eq(wid[0], NULL);
}
EFL_END_TEST

EFL_START_TEST(container_killed)
{
   Efl_Ui_Widget *wid[3];
   unsigned int i = 0;

   _setup_std_pack(wid);

   for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i)
     {
        efl_wref_add(wid[i], &wid[i]);
     }
   efl_del(widget);
   for (i = 0; i < sizeof(wid)/sizeof(Efl_Ui_Widget*); ++i)
     {
        ck_assert_ptr_eq(wid[i], NULL);
     }
}
EFL_END_TEST

void
efl_pack_behavior_test(TCase *tc)
{
   tcase_add_test(tc, pack2);
   tcase_add_test(tc, base2);
   tcase_add_test(tc, pack_clear1);
   tcase_add_test(tc, pack_clear2);
   tcase_add_test(tc, unpack_all1);
   tcase_add_test(tc, unpack_all2);
   tcase_add_test(tc, unpack1);
   tcase_add_test(tc, unpack2);
   tcase_add_test(tc, unpack3);
   tcase_add_test(tc, pack1);
   tcase_add_test(tc, pack3);
   tcase_add_test(tc, evt_content_added);
   tcase_add_test(tc, evt_content_removed);
   tcase_add_test(tc, child_killed);
   tcase_add_test(tc, container_killed);
}