Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_gengrid_tc3.c
1 /*
2  * Tested interface: AtkObject
3  *
4  * Tested AtkObject: EailGengrid
5  *
6  * Description: Test AtkObject interface
7  *
8  * Test input: accessible object representing EailGengrid
9  *
10  * Expected test result: test should return 0 (success)
11  */
12
13 #include <Elementary.h>
14 #include <atk/atk.h>
15
16 #define DEBUG 1
17
18 #include "eail_test_utils.h"
19
20 INIT_TEST("EailGengrid")
21
22 typedef struct _Example_Item
23 {
24    const char *path;
25 } Example_Item;
26
27 static Elm_Gengrid_Item_Class *gic = NULL;
28 static Evas_Object *grid;
29
30 static const char *imgs[9] =
31 {
32    "./data/01.jpg",
33    "./data/02.jpg",
34    "./data/03.jpg",
35    "./data/04.jpg",
36    "./data/05.jpg",
37    "./data/06.jpg",
38    "./data/07.jpg",
39    "./data/08.jpg",
40    "./data/09.jpg"
41 };
42
43 static char *
44 _grid_label_get(void *data, Evas_Object *obj, const char *part)
45 {
46    const Example_Item *it = data;
47    char buf[256];
48    g_snprintf(buf, sizeof(buf), "Photo %s", it->path);
49    return strdup(buf);
50 }
51
52 static Evas_Object *
53 _grid_content_get(void *data, Evas_Object *obj, const char *part)
54 {
55    const Example_Item *it = data;
56    if (!strcmp(part, "elm.swallow.icon"))
57      {
58         Evas_Object *icon = elm_bg_add(obj);
59         char buf[256];
60         g_snprintf(buf, sizeof(buf),"%s", it->path);
61         elm_bg_file_set(icon, buf, NULL);
62         evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
63         evas_object_show(icon);
64         return icon;
65      }
66    return NULL;
67
68 }
69
70 static Eina_Bool
71 _grid_state_get(void *data, Evas_Object *obj, const char *part)
72 {
73    return EINA_FALSE;
74 }
75
76 static void
77 _grid_del(void *data, Evas_Object *obj)
78 {
79    Example_Item *it = data;
80    eina_stringshare_del(it->path);
81    free(it);
82 }
83
84 static Example_Item *
85 _item_new(unsigned int index)
86 {
87    Example_Item *it = malloc(sizeof(*it));
88    if (index <= 8)
89      it->path = eina_stringshare_add(imgs[index]);
90    else
91      it->path = eina_stringshare_add(imgs[0]);
92    return it;
93 }
94
95 void _on_selected(void *data, Evas_Object *obj, void *event_info)
96 {
97    _printf("selected item with handle: %p\n", event_info);
98 }
99
100 static void
101 _do_test(AtkObject *obj)
102 {
103    gint index = -1, column = -1, row = -1;
104    AtkObject *two_two_child = NULL, *zero_zero_child = NULL,
105                *zero_four_child = NULL, *zero_three_child = NULL;
106
107    /* 2-2 coords should NOT have any match*/
108    index = atk_table_get_index_at(ATK_TABLE(obj), 2, 2);
109    g_assert(-1 == index);
110    two_two_child = atk_table_ref_at(ATK_TABLE(obj), 2, 2);
111    g_assert(NULL == two_two_child);
112
113    /* 0-0 coords should be found*/
114    index = atk_table_get_index_at(ATK_TABLE(obj), 0, 0);
115    g_assert(-1 != index);
116    zero_zero_child = atk_table_ref_at(ATK_TABLE(obj), 0, 0);
117    g_assert(zero_zero_child);
118
119    /* 0-4 coords should NOT be found*/
120    index = atk_table_get_index_at(ATK_TABLE(obj), 0, 4);
121    g_assert(-1 == index);
122    zero_four_child = atk_table_ref_at(ATK_TABLE(obj), 0, 4);
123    g_assert(NULL == zero_four_child);
124
125    /*...but  0-3 coords should be found*/
126    index = atk_table_get_index_at(ATK_TABLE(obj), 0, 3);
127    g_assert(-1 != index);
128    zero_three_child = atk_table_ref_at(ATK_TABLE(obj), 0, 3);
129    g_assert(zero_three_child);
130
131    /* table - columns checks*/
132    /*...index-9 obj should not be found (slightly out of bounds)*/
133    column = atk_table_get_column_at_index(ATK_TABLE(obj), 9);
134    g_assert(-1 == column);
135
136    /*...index-8 obj should be found, and should be '0' */
137    column = atk_table_get_column_at_index(ATK_TABLE(obj), 8);
138    g_assert(0 == column);
139
140    /*...index-7 obj should be found, and column be '3' */
141    column = atk_table_get_column_at_index(ATK_TABLE(obj), 7);
142    g_assert(3 == column);
143
144    /*... index-2 obj should be found, and column be 2' */
145    column = atk_table_get_column_at_index(ATK_TABLE(obj), 2);
146    g_assert(2 == column);
147
148    /*... index-6 obj should be found, and column be 2' */
149    column = atk_table_get_column_at_index(ATK_TABLE(obj), 6);
150    g_assert(2 == column);
151
152    /* table -rows checks*/
153    /* index 9- should not be found in any row */
154    row = atk_table_get_row_at_index(ATK_TABLE(obj), 9);
155    g_assert(-1 == row);
156
157    /*...index-8 obj should be found, and row should be '2' */
158    row = atk_table_get_row_at_index(ATK_TABLE(obj), 8);
159    g_assert(2 == row);
160
161    /*...index-7 obj should be found, and row should be '1' */
162    row = atk_table_get_row_at_index(ATK_TABLE(obj), 7);
163    g_assert(1 == row);
164
165    /*...index-2 obj should be found, and row should be '0' */
166    row = atk_table_get_row_at_index(ATK_TABLE(obj), 2);
167    g_assert(0 == row);
168
169    /*...index-6 obj should be found, and row should be '1' */
170    row = atk_table_get_row_at_index(ATK_TABLE(obj), 6);
171    g_assert(1 == row);
172
173    /*...index-0 obj should be found, and row should be '0' */
174    row = atk_table_get_row_at_index(ATK_TABLE(obj), 0);
175    g_assert(0 == row);
176
177    eailu_test_code_called = 1;
178 }
179
180 static Ecore_Timer *timer_delay;
181
182 static Eina_Bool delay_test_run(void *data)
183 {
184    Eina_List *l, *list = elm_gengrid_realized_items_get(data);
185    Elm_Object_Item *it;
186    int i = 0;
187    Evas_Object *win = elm_object_parent_widget_get(data);
188    EINA_LIST_FOREACH(list, l, it)
189      {
190         unsigned int x, y;
191         elm_gengrid_item_pos_get(it, &x, &y);
192         i++;
193      }
194    _on_focus_in(NULL, win, NULL);
195    return EINA_FALSE;
196 }
197
198 static void
199 _init_gengrid(Evas_Object *win)
200 {
201    Evas_Object *bg;
202
203    bg = elm_bg_add(win);
204    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
205    elm_win_resize_object_add(win, bg);
206    evas_object_show(bg);
207    grid = elm_gengrid_add(win);
208
209    elm_gengrid_item_size_set(grid, 200, 200);
210    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
211    elm_win_resize_object_add(win, grid);
212    evas_object_smart_callback_add(grid, "selected", _on_selected, NULL);
213    elm_gengrid_horizontal_set(grid, EINA_FALSE);
214    elm_gengrid_multi_select_set(grid, EINA_TRUE);
215    evas_object_show(grid);
216
217    if (!gic)
218      {
219         gic = elm_gengrid_item_class_new();
220         gic->item_style = "default";
221         gic->func.text_get = _grid_label_get;
222         gic->func.content_get = _grid_content_get;
223         gic->func.state_get = _grid_state_get;
224         gic->func.del = _grid_del;
225      } // we only create the first time its needed. we dont unref/free
226
227    elm_gengrid_item_append(grid, gic, _item_new(0), NULL, NULL);
228    elm_gengrid_item_append(grid, gic, _item_new(1), NULL, NULL);
229    elm_gengrid_item_append(grid, gic, _item_new(2), NULL, NULL);
230    elm_gengrid_item_append(grid, gic, _item_new(3), NULL, NULL);
231    elm_gengrid_item_append(grid, gic, _item_new(4), NULL, NULL);
232    elm_gengrid_item_append(grid, gic, _item_new(5), NULL, NULL);
233    elm_gengrid_item_append(grid, gic, _item_new(6), NULL, NULL);
234    elm_gengrid_item_append(grid, gic, _item_new(7), NULL, NULL);
235    elm_gengrid_item_append(grid, gic, _item_new(8), NULL, NULL);
236    evas_object_resize(win, 1000, 300);
237 }
238
239 EAPI_MAIN int
240 elm_main(int argc, char **argv)
241 {
242    Evas_Object *win;
243
244    win = eailu_create_test_window_with_glib_init(_on_done, NULL);
245    _init_gengrid(win);
246    evas_object_show(win);
247
248    timer_delay = ecore_timer_add(1, delay_test_run, grid);
249
250    elm_run();
251    elm_shutdown();
252    return 0;
253 }
254 ELM_MAIN()