summaryrefslogtreecommitdiff
path: root/src/tests/elementary/efl_ui_test_widget.c
blob: 74e8f2eac9d1147d2341aadf6f16b1d8902995e1 (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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
//#define EFL_NOLEGACY_API_SUPPORT
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#include <Elementary.h>
#include "elm_widget.h"
#include <Efl_Ui.h>
#include "efl_ui_suite.h"
#include "eo_internal.h"

typedef struct {
   Efl_Ui_Widget *btn1, *btn2;
   Efl_Ui_Widget *box;
   Efl_Ui_Widget *win;
   Efl_Ui_Widget *ic;
} State;

static void
_small_ui(State *s)
{
   s->win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                                  efl_text_set(efl_added, "Hello World"));

   s->ic = efl_add(EFL_UI_IMAGE_CLASS, s->win,
                 efl_ui_win_icon_object_set(s->win, efl_added));

   s->box = efl_add(EFL_UI_BOX_CLASS, s->win,
                efl_content_set(s->win, efl_added));

   s->btn1 = efl_add(EFL_UI_BUTTON_CLASS, s->box,
                efl_text_set(efl_added, "Quit1"),
                efl_pack(s->box, efl_added));

   s->btn2 = efl_add(EFL_UI_BUTTON_CLASS, s->box,
                efl_text_set(efl_added, "Quit"),
                efl_pack(s->box, efl_added));

}

EFL_START_TEST(efl_ui_test_widget_parent_iterator)
{
   Eina_Iterator *it;
   Efl_Ui_Widget *o;
   Eina_Array *a;
   State s;

   a = eina_array_new(10);
   _small_ui(&s);
   eina_array_push(a, s.win);
   eina_array_push(a, s.box);
   eina_array_push(a, s.btn1);

   it = efl_ui_widget_parent_iterator(s.btn1);
   EINA_ITERATOR_FOREACH(it, o)
     {
        ck_assert_ptr_eq(eina_array_pop(a), o);
     }
   eina_iterator_free(it);
   ck_assert_int_eq(eina_array_count(a), 0);
   eina_array_free(a);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_widget_iterator)
{
   Eina_Iterator *it;
   Efl_Ui_Widget *o;
   Eina_Array *a;
   State s;

   a = eina_array_new(10);
   _small_ui(&s);
   eina_array_push(a, s.btn2);
   eina_array_push(a, s.btn1);
   eina_array_push(a, s.box);
   eina_array_push(a, s.ic); //Hack arround the icon of the window
   eina_array_push(a, s.win);

   it = efl_ui_widget_tree_widget_iterator(s.win);
   EINA_ITERATOR_FOREACH(it, o)
     {
        Eo *c = eina_array_pop(a);
        ck_assert_ptr_eq(c, o);
     }
   eina_iterator_free(it);
   ck_assert_int_eq(eina_array_count(a), 0);
   eina_array_free(a);
}
EFL_END_TEST

static Evas_Object*
resize_object(Efl_Canvas_Object *o)
{
   Efl_Ui_Widget_Data *pd = efl_data_scope_safe_get(o, EFL_UI_WIDGET_CLASS);

   return eina_list_data_get(pd->subobjs);
}

EFL_START_TEST(efl_ui_test_widget_widget_sub_iterator)
{
   Eina_Iterator *it;
   Efl_Ui_Widget *o;
   Eina_Array *a;
   State s;

   a = eina_array_new(10);
   _small_ui(&s);
   eina_array_push(a, s.btn2);
   eina_array_push(a, s.btn1);
   eina_array_push(a, s.box);

   it = efl_ui_widget_tree_widget_iterator(s.box);
   EINA_ITERATOR_FOREACH(it, o)
     {
        ck_assert_ptr_eq(eina_array_pop(a), o);
     }
   eina_iterator_free(it);
   ck_assert_int_eq(eina_array_count(a), 0);
   eina_array_free(a);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_iterator)
{
   Eina_Iterator *it;
   Efl_Ui_Widget *o;
   Eina_Array *a;
   State s;

   a = eina_array_new(10);
   _small_ui(&s);
   eina_array_push(a, resize_object(s.btn2));
   eina_array_push(a, s.btn2);
   eina_array_push(a, resize_object(s.btn1));
   eina_array_push(a, s.btn1);
   eina_array_push(a, resize_object(s.box));
   eina_array_push(a, s.box);
   eina_array_push(a, resize_object(s.ic));
   eina_array_push(a, s.ic);
   eina_array_push(a, s.win);

   it = efl_ui_widget_tree_iterator(s.win);
   EINA_ITERATOR_FOREACH(it, o)
     {
        ck_assert_ptr_eq(eina_array_pop(a), o);
     }
   eina_iterator_free(it);
   ck_assert_int_eq(eina_array_count(a), 0);
   eina_array_free(a);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_sub_iterator)
{
   Eina_Iterator *it;
   Efl_Ui_Widget *o;
   Eina_Array *a;
   State s;

   a = eina_array_new(10);
   _small_ui(&s);
   eina_array_push(a, resize_object(s.btn2));
   eina_array_push(a, s.btn2);
   eina_array_push(a, resize_object(s.btn1));
   eina_array_push(a, s.btn1);
   eina_array_push(a, resize_object(s.box));
   eina_array_push(a, s.box);

   it = efl_ui_widget_tree_iterator(s.box);
   EINA_ITERATOR_FOREACH(it, o)
     {
        ck_assert_ptr_eq(eina_array_pop(a), o);
     }
   eina_iterator_free(it);
   ck_assert_int_eq(eina_array_count(a), 0);
   eina_array_free(a);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_sub_object_add_del)
{
   State s;

   _small_ui(&s);
   DISABLE_ABORT_ON_CRITICAL_START;
   ck_assert(!efl_ui_widget_sub_object_add(s.btn1, s.btn1));
   DISABLE_ABORT_ON_CRITICAL_END;
   ck_assert(efl_ui_widget_sub_object_add(s.box, s.btn1));
   DISABLE_ABORT_ON_CRITICAL_START;
   ck_assert(!efl_ui_widget_sub_object_add(s.box, NULL));
   ck_assert(!efl_ui_widget_sub_object_del(s.btn1, s.btn1));
   ck_assert(!efl_ui_widget_sub_object_del(s.box, NULL));
   ck_assert(!efl_ui_widget_sub_object_del(s.btn1, s.box));
   DISABLE_ABORT_ON_CRITICAL_END;
   ck_assert(efl_ui_widget_sub_object_del(s.box, s.btn1));
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_sub_object_theme_sync)
{
   State s;
   Efl_Canvas_Layout *edje;

   _small_ui(&s);
   edje = elm_widget_resize_object_get(s.btn1);

   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn1), 1.0));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(edje), 1.0));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn2), 1.0));

   efl_gfx_entity_scale_set(s.win, 0.123);
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn1), 0.123));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(edje), 0.123));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn2), 0.123));

   efl_ui_widget_sub_object_del(s.box, s.btn1);
   efl_gfx_entity_scale_set(s.win, 0.456);
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn1), 1.0));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(edje), 0.123));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn2), 0.456));

   efl_gfx_entity_scale_set(s.win, 0.789);
   efl_ui_widget_sub_object_add(s.box, s.btn1);
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn1), 0.789));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(edje), 0.789));
   ck_assert(EINA_DBL_EQ(efl_gfx_entity_scale_get(s.btn2), 0.789));
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_parent_relation)
{
   Efl_Ui_Win *win, *w1, *w2, *w3;

   win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                                  efl_text_set(efl_added, "Hello World"));
   //first check the initial state
   w1 = efl_add(efl_ui_widget_realized_class_get(), win);
   ck_assert_ptr_eq(efl_ui_widget_parent_get(w1), win);
   w2 = efl_add(efl_ui_widget_realized_class_get(), w1);
   ck_assert_ptr_eq(efl_ui_widget_parent_get(w2), w1);
   w3 = efl_add(efl_ui_widget_realized_class_get(), w1);
   ck_assert_ptr_eq(efl_ui_widget_parent_get(w3), w1);

   //check if widget_parent is working correctly
   efl_ui_widget_sub_object_add(w2, w3);
   ck_assert_ptr_eq(efl_ui_widget_parent_get(w3), w2);

   efl_del(win);
}
EFL_END_TEST


EFL_START_TEST(efl_ui_test_widget_disabled_parent)
{
   Efl_Ui_Win *win, *w1, *w2, *t;

   win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                                  efl_text_set(efl_added, "Hello World"));
   //first check the initial state
   w1 = efl_add(efl_ui_widget_realized_class_get(), win);
   efl_ui_widget_disabled_set(w1, EINA_TRUE);
   w2 = efl_add(efl_ui_widget_realized_class_get(), win);
   efl_ui_widget_disabled_set(w2, EINA_FALSE);
   ck_assert_int_eq(efl_ui_widget_disabled_get(w1), EINA_TRUE);
   ck_assert_int_eq(efl_ui_widget_disabled_get(w2), EINA_FALSE);

   //check if disalbed gets correctly setted on reparent
   t = efl_add(efl_ui_widget_realized_class_get(), win);
   efl_ui_widget_sub_object_add(w2, t);
   ck_assert_int_eq(efl_ui_widget_disabled_get(t), EINA_FALSE);
   efl_ui_widget_sub_object_add(w1, t);
   ck_assert_int_eq(efl_ui_widget_disabled_get(t), EINA_TRUE);
   efl_del(t);

   t = efl_add(efl_ui_widget_realized_class_get(), w2);
   ck_assert_int_eq(efl_ui_widget_disabled_get(t), EINA_FALSE);
   efl_del(t);

   t = efl_add(efl_ui_widget_realized_class_get(), w1);
   ck_assert_int_eq(efl_ui_widget_disabled_get(t), EINA_TRUE);
   efl_del(t);


   efl_del(win);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_disabled_behaviour)
{
   Efl_Ui_Win *win, *w1, *w2, *t;

   win = efl_add(EFL_UI_WIN_CLASS, efl_main_loop_get(),
                                  efl_text_set(efl_added, "Hello World"));
   //first check the initial state
   w1 = efl_add(efl_ui_widget_realized_class_get(), win);
   efl_ui_widget_disabled_set(w1, EINA_TRUE);
   w2 = efl_add(efl_ui_widget_realized_class_get(), win);
   efl_ui_widget_disabled_set(w2, EINA_FALSE);


   t = efl_add(efl_ui_widget_realized_class_get(), win);
   efl_ui_widget_sub_object_add(w1, t);
   //check that we never enable something under disabled parent
   DISABLE_ABORT_ON_CRITICAL_START;
   efl_ui_widget_disabled_set(t, EINA_FALSE);
   DISABLE_ABORT_ON_CRITICAL_END;
   ck_assert_int_eq(efl_ui_widget_disabled_get(t), EINA_TRUE);
   efl_del(t);

   t = efl_add(efl_ui_widget_realized_class_get(), win);
   efl_ui_widget_sub_object_add(w1, t);
   //check that we can disable something with a disabled tree
   efl_ui_widget_disabled_set(t, EINA_TRUE);
   ck_assert_int_eq(efl_ui_widget_disabled_get(t), EINA_TRUE);
   efl_ui_widget_sub_object_add(w2, t);
   ck_assert_int_eq(efl_ui_widget_disabled_get(t), EINA_TRUE);
   efl_del(t);

   efl_del(win);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_test_widget_win_provider_find)
{
   State s;

   _small_ui(&s);
   ck_assert_ptr_eq(efl_provider_find(s.btn1, EFL_UI_WIN_CLASS), s.win);
   efl_ui_widget_sub_object_del(s.box, s.btn1);
   ck_assert_ptr_eq(efl_ui_widget_parent_get(s.btn1), NULL);
   ck_assert_ptr_eq(efl_provider_find(s.btn1, EFL_UI_WIN_CLASS), s.win);
}
EFL_END_TEST

void efl_ui_test_widget(TCase *tc)
{
   tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
   tcase_add_test(tc, efl_ui_test_widget_parent_iterator);
   tcase_add_test(tc, efl_ui_test_widget_widget_iterator);
   tcase_add_test(tc, efl_ui_test_widget_widget_sub_iterator);
   tcase_add_test(tc, efl_ui_test_widget_iterator);
   tcase_add_test(tc, efl_ui_test_widget_sub_iterator);
   tcase_add_test(tc, efl_ui_test_widget_sub_object_add_del);
   tcase_add_test(tc, efl_ui_test_widget_sub_object_theme_sync);
   tcase_add_test(tc, efl_ui_test_widget_parent_relation);
   tcase_add_test(tc, efl_ui_test_widget_disabled_parent);
   tcase_add_test(tc, efl_ui_test_widget_disabled_behaviour);
   tcase_add_test(tc, efl_ui_test_widget_win_provider_find);
}