Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_gengrid_tc1.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 #include "eail_test_utils.h"
17
18 INIT_TEST("EailGengrid")
19
20 typedef struct _Example_Item
21 {
22    const char *path;
23 } Example_Item;
24
25 static Elm_Gengrid_Item_Class *gic = NULL;
26 static Evas_Object *grid;
27
28 static const char *imgs[9] =
29 {
30    "./data/01.jpg",
31    "./data/02.jpg",
32    "./data/03.jpg",
33    "./data/04.jpg",
34    "./data/05.jpg",
35    "./data/06.jpg",
36    "./data/07.jpg",
37    "./data/08.jpg",
38    "./data/09.jpg"
39 };
40
41 static char *
42 _grid_label_get(void *data, Evas_Object *obj, const char *part)
43 {
44    const Example_Item *it = data;
45    char buf[256];
46    g_snprintf(buf, sizeof(buf), "Photo %s", it->path);
47    return strdup(buf);
48 }
49
50 static Evas_Object *
51 _grid_content_get(void *data, Evas_Object *obj, const char *part)
52 {
53    const Example_Item *it = data;
54    if (!strcmp(part, "elm.swallow.icon"))
55      {
56         Evas_Object *icon = elm_bg_add(obj);
57         char buf[256];
58         g_snprintf(buf, sizeof(buf),"%s", it->path);
59         elm_bg_file_set(icon, buf, NULL);
60         evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
61         evas_object_show(icon);
62         return icon;
63      }
64    return NULL;
65
66 }
67
68 static Eina_Bool
69 _grid_state_get(void *data, Evas_Object *obj, const char *part)
70 {
71    return EINA_FALSE;
72 }
73
74 static void
75 _grid_del(void *data, Evas_Object *obj)
76 {
77    Example_Item *it = data;
78    eina_stringshare_del(it->path);
79    free(it);
80 }
81
82 static Example_Item *
83 _item_new(unsigned int index)
84 {
85    Example_Item *it = malloc(sizeof(*it));
86    if (index <= 8)
87      it->path = eina_stringshare_add(imgs[index]);
88    else
89      it->path = eina_stringshare_add(imgs[0]);
90    return it;
91 }
92
93 void _on_selected(void *data, Evas_Object *obj, void *event_info)
94 {
95    _printf("selected item with handle: %p\n", event_info);
96 }
97
98 static void
99 _print_object_info(AtkObject *obj)
100 {
101    AtkRole atk_role = atk_object_get_role(obj);
102    const char *name = atk_object_get_name(obj);
103    const char *type_name = g_type_name(G_TYPE_FROM_INSTANCE(obj));
104    const char *role_name = atk_role_get_name(atk_role);
105
106    _printf("atk_object_get_name: %s\n", name ? name : "NULL");
107    _printf("atk_object_get_role: %s\n", role_name ? role_name : "NULL");
108    _printf("atk_object_get_type_name: %s\n", type_name ? type_name : "NULL");
109 }
110
111 static void
112 _do_test(AtkObject *obj)
113 {
114    int child_count = atk_object_get_n_accessible_children(obj);
115
116    g_assert(ATK_IS_OBJECT(obj));
117
118    atk_object_set_description(obj, "test");
119    g_assert_cmpstr(atk_object_get_description(obj), ==, "test");
120
121    atk_object_set_name(obj, "test name");
122    g_assert_cmpstr(atk_object_get_name(obj), ==, "test name");
123
124    g_assert(atk_object_get_role(obj) == ATK_ROLE_TABLE);
125
126    for (int i = 0; i < child_count; i++)
127      {
128         AtkObject *child = atk_object_ref_accessible_child(obj, i);
129         _print_object_info(child);
130         g_assert(child);
131         g_object_unref(child);
132      }
133
134    eailu_test_code_called = 1;
135 }
136 static Ecore_Timer *timer_delay;
137
138 static Eina_Bool delay_test_run(void *data)
139 {
140    Eina_List *l, *list = elm_gengrid_realized_items_get(data);
141    Elm_Object_Item *it;
142    int i = 0;
143    Evas_Object *win = elm_object_parent_widget_get(data);
144    EINA_LIST_FOREACH(list, l, it)
145      {
146         unsigned int x, y;
147         elm_gengrid_item_pos_get(it, &x, &y);
148         i++;
149      }
150    _on_focus_in(NULL, win, NULL);
151    return EINA_FALSE;
152 }
153
154 static void
155 _init_gengrid(Evas_Object *win)
156 {
157    Evas_Object *bg;
158
159    bg = elm_bg_add(win);
160    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
161    elm_win_resize_object_add(win, bg);
162    evas_object_show(bg);
163    grid = elm_gengrid_add(win);
164
165    elm_gengrid_item_size_set(grid, 200, 200);
166    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
167    elm_win_resize_object_add(win, grid);
168    evas_object_smart_callback_add(grid, "selected", _on_selected, NULL);
169    elm_gengrid_horizontal_set(grid, EINA_FALSE);
170    elm_gengrid_multi_select_set(grid, EINA_TRUE);
171    evas_object_show(grid);
172
173    if (!gic)
174      {
175         gic = elm_gengrid_item_class_new();
176         gic->item_style = "default";
177         gic->func.text_get = _grid_label_get;
178         gic->func.content_get = _grid_content_get;
179         gic->func.state_get = _grid_state_get;
180         gic->func.del = _grid_del;
181      } // we only create the first time its needed. we dont unref/free
182
183    elm_gengrid_item_append(grid, gic, _item_new(0), NULL, NULL);
184    elm_gengrid_item_append(grid, gic, _item_new(1), NULL, NULL);
185    elm_gengrid_item_append(grid, gic, _item_new(2), NULL, NULL);
186    elm_gengrid_item_append(grid, gic, _item_new(3), NULL, NULL);
187    elm_gengrid_item_append(grid, gic, _item_new(4), NULL, NULL);
188    elm_gengrid_item_append(grid, gic, _item_new(5), NULL, NULL);
189    elm_gengrid_item_append(grid, gic, _item_new(6), NULL, NULL);
190    elm_gengrid_item_append(grid, gic, _item_new(7), NULL, NULL);
191    elm_gengrid_item_append(grid, gic, _item_new(8), NULL, NULL);
192    evas_object_resize(win, 800, 600);
193 }
194
195 EAPI_MAIN int
196 elm_main(int argc, char **argv)
197 {
198    Evas_Object *win;
199
200    win = eailu_create_test_window_with_glib_init(_on_done, NULL);
201    _init_gengrid(win);
202    evas_object_show(win);
203
204    timer_delay = ecore_timer_add(1, delay_test_run, grid);
205
206    elm_run();
207    elm_shutdown();
208    return 0;
209 }
210 ELM_MAIN()