Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_gengrid_tc2.c
1 /*
2  * Tested interface: AtkTable
3  *
4  * Tested AtkObject: EailGengrid
5  *
6  * Description: Test AtkTable 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 rows, cols, row_at_index, column_at_index, index_at;
115    gboolean success;
116    AtkTable *table;
117    AtkObject *table_child;
118
119    g_assert(ATK_IS_TABLE(obj));
120    table = ATK_TABLE(obj);
121    rows = atk_table_get_n_rows(table);
122    g_assert(rows == 3);
123    cols = atk_table_get_n_columns(table);
124    g_assert(cols == 3);
125    row_at_index = atk_table_get_row_at_index(table, 4);
126    g_assert(row_at_index == 1);
127    column_at_index = atk_table_get_column_at_index(table, 2);
128    g_assert(column_at_index == 2);
129    index_at = atk_table_get_index_at(table, 2, 2);
130    g_assert(index_at == 8);
131    table_child = atk_table_ref_at(table, 1, 1);
132    g_assert(ATK_IS_OBJECT(table_child));
133    _print_object_info(table_child);
134    success = atk_table_add_column_selection(table, 1);
135    g_assert(success);
136    success =  atk_table_is_column_selected(table, 1);
137    g_assert(success);
138    success = atk_table_remove_column_selection(table, 1);
139    g_assert(success);
140    success = atk_table_add_row_selection(table, 1);
141    g_assert(success);
142    success = atk_table_is_row_selected(table, 1);
143    g_assert(success);
144    success = atk_table_remove_row_selection(table, 0);
145    g_assert(success);
146
147    eailu_test_code_called = 1;
148 }
149 static Ecore_Timer *timer_delay;
150
151 static Eina_Bool delay_test_run(void *data)
152 {
153    Eina_List *l, *list = elm_gengrid_realized_items_get(data);
154    Elm_Object_Item *it;
155    int i = 0;
156    Evas_Object *win = elm_object_parent_widget_get(data);
157    EINA_LIST_FOREACH(list, l, it)
158      {
159         unsigned int x, y;
160         elm_gengrid_item_pos_get(it, &x, &y);
161         i++;
162      }
163    _on_focus_in(NULL, win, NULL);
164    return EINA_FALSE;
165 }
166
167 static void
168 _init_gengrid(Evas_Object *win)
169 {
170    Evas_Object *bg;
171
172    bg = elm_bg_add(win);
173    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
174    elm_win_resize_object_add(win, bg);
175    evas_object_show(bg);
176    grid = elm_gengrid_add(win);
177
178    elm_gengrid_item_size_set(grid, 200, 200);
179    evas_object_size_hint_weight_set(grid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
180    elm_win_resize_object_add(win, grid);
181    evas_object_smart_callback_add(grid, "selected", _on_selected, NULL);
182    elm_gengrid_horizontal_set(grid, EINA_FALSE);
183    elm_gengrid_multi_select_set(grid, EINA_TRUE);
184    evas_object_show(grid);
185
186    if (!gic)
187      {
188         gic = elm_gengrid_item_class_new();
189         gic->item_style = "default";
190         gic->func.text_get = _grid_label_get;
191         gic->func.content_get = _grid_content_get;
192         gic->func.state_get = _grid_state_get;
193         gic->func.del = _grid_del;
194      } // we only create the first time its needed. we dont unref/free
195
196    elm_gengrid_item_append(grid, gic, _item_new(0), NULL, NULL);
197    elm_gengrid_item_append(grid, gic, _item_new(1), NULL, NULL);
198    elm_gengrid_item_append(grid, gic, _item_new(2), NULL, NULL);
199    elm_gengrid_item_append(grid, gic, _item_new(3), NULL, NULL);
200    elm_gengrid_item_append(grid, gic, _item_new(4), NULL, NULL);
201    elm_gengrid_item_append(grid, gic, _item_new(5), NULL, NULL);
202    elm_gengrid_item_append(grid, gic, _item_new(6), NULL, NULL);
203    elm_gengrid_item_append(grid, gic, _item_new(7), NULL, NULL);
204    elm_gengrid_item_append(grid, gic, _item_new(8), NULL, NULL);
205    evas_object_resize(win, 800, 600);
206 }
207
208 EAPI_MAIN int
209 elm_main(int argc, char **argv)
210 {
211    Evas_Object *win;
212
213    win = eailu_create_test_window_with_glib_init(_on_done, NULL);
214    _init_gengrid(win);
215    evas_object_show(win);
216
217    timer_delay = ecore_timer_add(1, delay_test_run, grid);
218
219    elm_run();
220    elm_shutdown();
221    return 0;
222 }
223 ELM_MAIN()