summaryrefslogtreecommitdiff
path: root/src/tests/elementary/efl_ui_test_grid.c
blob: 1ac7b960b38ef2b931dc151eda223d5b452dd0b7 (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#define EFL_ACCESS_OBJECT_BETA
#include <Elementary.h>
#include "efl_ui_suite.h"

static Eo *win;
static Efl_Ui_Grid *grid;

static void
grid_setup()
{
   win = win_add();

   grid = efl_add(EFL_UI_GRID_CLASS, win);

   efl_ui_grid_item_size_set(grid, EINA_SIZE2D(100, 100));
   efl_gfx_entity_size_set(grid, EINA_SIZE2D(500, 50));
   efl_gfx_entity_size_set(win, EINA_SIZE2D(500, 50));
   efl_gfx_entity_visible_set(win, EINA_TRUE);
}

static void
grid_teardown()
{
   if (grid)
     {
	    efl_del(grid);
	    grid = NULL;
	 }
   if (win)
     {
	    efl_del(win);
	    win = NULL;
	 }
}

static Eina_Bool
grid_item_pack(Eo *grid, int count, Eina_List **l)
{
	int i;
	Efl_Ui_Grid_Item *item;
	for (i = 0; i < count; i++)
	  {
		  item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
		  if (!item) return EINA_FALSE;
		  if (l) *l = eina_list_append(*l, item);
		  efl_pack(grid, item);
	  }
	return EINA_TRUE;
}

EFL_START_TEST(efl_ui_grid_class_check)
{
   const char *class;

   class = efl_class_name_get(grid);

   ck_assert(class != NULL);
   ck_assert(!strcmp(class, "Efl.Ui.Grid"));
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_pack)
{
   Efl_Ui_Grid_Item *item;
   int count;

   item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
   efl_pack(grid, item);

   count = efl_content_count(grid);

   ck_assert(count == 1);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_unpack)
{
   Efl_Ui_Grid_Item *item;
   int count;

   item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
   efl_pack(grid, item);

   efl_pack_unpack(grid, item);

   count = efl_content_count(grid);
   ck_assert(count == 0);

   efl_del(item);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_unpack_all)
{
   Efl_Ui_Grid_Item *item;
   int count_before = 10;
   int count;
   Eina_Iterator *itor;

   ck_assert(grid_item_pack(grid, count_before, NULL) != EINA_FALSE);

   itor = efl_content_iterate(grid);
   efl_pack_unpack_all(grid);

   count = efl_content_count(grid);
   ck_assert(count == 0);

   EINA_ITERATOR_FOREACH(itor, item)
     efl_del(item);

   free(itor);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_pack_clear)
{
   int count_before = 10;
   int count;

   ck_assert(grid_item_pack(grid, count_before, NULL) != EINA_FALSE);

   efl_pack_clear(grid);

   count = efl_content_count(grid);
   ck_assert(count == 0);
}
EFL_END_TEST


EFL_START_TEST(efl_ui_grid_pack_end)
{
   Efl_Ui_Grid_Item *item, *compare;
   int count_before = 10;
   int count;

   ck_assert(grid_item_pack(grid, count_before, NULL) != EINA_FALSE);

   item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
   ck_assert(item != NULL);
   efl_pack_end(grid, item);

   count = efl_content_count(grid);
   ck_assert(count == (count_before + 1));

   compare = efl_pack_content_get(grid, (count - 1));
   ck_assert(compare != NULL);
   ck_assert(item == compare);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_pack_begin)
{
   Efl_Ui_Grid_Item *item, *compare;
   int count_before = 10;
   int count;

   ck_assert(grid_item_pack(grid, count_before, NULL) != EINA_FALSE);

   item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
   ck_assert(item != NULL);
   efl_pack_begin(grid, item);

   count = efl_content_count(grid);
   ck_assert(count == (count_before + 1));

   compare = efl_pack_content_get(grid, 0);
   ck_assert(compare != NULL);
   ck_assert(item == compare);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_pack_after)
{
   Efl_Ui_Grid_Item *item, *after, *compare;
   int count_before = 10;
   int count;
   int index = 5;

   ck_assert(grid_item_pack(grid, count_before, NULL) != EINA_FALSE);

   after = efl_pack_content_get(grid, index);
   ck_assert(after != NULL);

   item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
   ck_assert(item != NULL);
   efl_pack_after(grid, item, after);

   count = efl_content_count(grid);
   ck_assert(count == (count_before + 1));

   compare = efl_pack_content_get(grid, index + 1);
   ck_assert(compare != NULL);
   ck_assert(item == compare);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_pack_before)
{
   Efl_Ui_Grid_Item *item, *before, *compare;
   int count_before = 10;
   int count;
   int index = 5;

   ck_assert(grid_item_pack(grid, count_before, NULL) != EINA_FALSE);

   before = efl_pack_content_get(grid, index);
   ck_assert(before != NULL);

   item = efl_add(EFL_UI_GRID_DEFAULT_ITEM_CLASS, grid);
   ck_assert(item != NULL);
   efl_pack_before(grid, item, before);

   count = efl_content_count(grid);
   ck_assert(count == (count_before + 1));

   compare = efl_pack_content_get(grid, index);
   ck_assert(compare != NULL);
   ck_assert(item == compare);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_content_count)
{
   int count = 10, compare;

   ck_assert(grid_item_pack(grid, count, NULL) != EINA_FALSE);

   compare = efl_content_count(grid);

   ck_assert(count == compare);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_grid_content_iterate)
{
   int count = 10;
   Efl_Ui_Grid_Item *item;
   Eina_List *item_list = NULL;
   Eina_Iterator *item_itr;

   ck_assert(grid_item_pack(grid, count, &item_list) != EINA_FALSE);

   /* Get Item Content Iterator */
   item_itr = efl_content_iterate(grid);

   EINA_ITERATOR_FOREACH(item_itr, item)
     {
        /* Compare the iterator data and list data */
		ck_assert(item ==  eina_list_data_get(item_list));
		item_list = eina_list_remove(item_list, item);
     }
   eina_iterator_free(item_itr);

   ck_assert(item_list == NULL);
}
EFL_END_TEST


int tcount = 0;

static void
grid_timer_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
   ck_assert(0);
   efl_del(event->object);
   ecore_main_loop_quit();
}

static void
grid_scroll_start_cb(void *data EINA_UNUSED, const Efl_Event *event EINA_UNUSED)
{
  //printf("LSH :: scroll start!!!\n");
}

static void
grid_scroll_stop_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
   Efl_Loop_Timer *timer = data;
   efl_del(timer);
   ecore_main_loop_quit();
}

EFL_CALLBACKS_ARRAY_DEFINE(grid_scroll_callbacks,
                           { EFL_UI_EVENT_SCROLL_START, grid_scroll_start_cb },
                           { EFL_UI_EVENT_SCROLL_STOP, grid_scroll_stop_cb });

EFL_START_TEST(efl_ui_grid_scroll)
{
   Efl_Ui_Grid_Item *item;
   Efl_Loop_Timer *timer;

   ck_assert(grid_item_pack(grid, 100, NULL) != EINA_FALSE);
   item = efl_pack_content_get(grid, 50);

   timer = efl_add(EFL_LOOP_TIMER_CLASS, efl_main_loop_get(), 
                   efl_event_callback_add(efl_added, EFL_LOOP_TIMER_EVENT_TICK, grid_timer_cb, NULL),
                   efl_loop_timer_loop_reset(efl_added),
                   efl_loop_timer_interval_set(efl_added, 3.0));

   efl_event_callback_array_add(grid, grid_scroll_callbacks(), timer);
   /*FIXME: efl_ui_scroll_interface only emit scroll event when animation exist */
   efl_ui_grid_item_scroll(grid, item, EINA_TRUE);
   ecore_main_loop_begin();
}
EFL_END_TEST


void efl_ui_test_grid(TCase *tc)
{
   tcase_add_checked_fixture(tc, grid_setup, grid_teardown);
   tcase_add_test(tc, efl_ui_grid_class_check);
   tcase_add_test(tc, efl_ui_grid_pack);
   tcase_add_test(tc, efl_ui_grid_unpack);
   tcase_add_test(tc, efl_ui_grid_unpack_all);
   tcase_add_test(tc, efl_ui_grid_pack_clear);
   tcase_add_test(tc, efl_ui_grid_pack_end);
   tcase_add_test(tc, efl_ui_grid_pack_begin);
   tcase_add_test(tc, efl_ui_grid_pack_after);
   tcase_add_test(tc, efl_ui_grid_pack_before);
   tcase_add_test(tc, efl_ui_grid_content_count);
   tcase_add_test(tc, efl_ui_grid_content_iterate);
   tcase_add_test(tc, efl_ui_grid_scroll);
}