Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_genlist_tc1.c
1 /*
2  * Tested interface: AtkObject
3  *
4  * Tested AtkObject: EailGenlist
5  *
6  * Description: Test whether accessible object is successfully registered
7  *    in GObject type system and is visible in AtkObject tree. Test
8  *    accessible children availability.
9  *
10  * Test input: accessible object representing EailGenlist
11  *
12  * Expected test result: test should return 0 (success)
13  */
14
15 #include <Elementary.h>
16 #include <atk/atk.h>
17
18 #include "eail_test_utils.h"
19
20 INIT_TEST("EailGenlist")
21
22 #define EAIL_TYPE_FOR_LIST_ITEM "EailItem"
23 #define N_ITEMS 18
24
25 static Evas_Object *glob_genlist = NULL;
26 static Elm_Genlist_Item_Class *_itc_group = NULL;
27 static int nitems = 0;
28
29 Elm_Object_Item *glob_test_item = NULL;
30
31 static void
32 _do_test(AtkObject *aobj)
33 {
34    int child_amount = 0;
35
36    g_assert(ATK_IS_OBJECT(aobj));
37
38    g_assert(atk_object_get_role(aobj) == ATK_ROLE_LIST);
39
40    child_amount = atk_object_get_n_accessible_children(aobj);
41    g_assert(N_ITEMS == child_amount);
42
43    eailu_test_atk_focus(aobj, TRUE);
44
45    eailu_test_code_called = 1;
46 }
47
48 static char *
49 _item_label_get(void *data, Evas_Object *obj, const char *part)
50 {
51    time_t t = (time_t)ecore_time_unix_get();
52    char buf[256];
53    int i = (int)(long)data;
54    struct tm timeinfo;
55    localtime_r(&t, &timeinfo);
56
57    if (!strcmp(part, "elm.text"))
58      g_snprintf(buf, sizeof(buf), "Item # %i", i);
59    else
60      {
61         int n;
62         strftime(buf, sizeof(buf), "realized at %c", &timeinfo);
63         n = strlen(buf);
64         buf[n - 1] = '\0';
65      }
66
67    return strdup(buf);
68 }
69
70 static Evas_Object *
71 _item_content_get(void *data, Evas_Object *obj, const char *part)
72 {
73    Evas_Object *ic = elm_icon_add(obj);
74
75    if (!strcmp(part, "elm.swallow.icon"))
76      elm_icon_standard_set(ic, "clock");
77
78    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
79    return ic;
80 }
81
82 static char *
83 _group_label_get(void *data, Evas_Object *obj, const char *part)
84 {
85    char buf[256];
86    int i = (int)(long)data;
87
88    g_snprintf(buf, sizeof(buf), "Group %d (item #%d)", i / 7, i);
89
90    return strdup(buf);
91 }
92
93 static Evas_Object *
94 _group_content_get(void *data, Evas_Object *obj, const char *part)
95 {
96    Evas_Object *ic = elm_icon_add(obj);
97
98    if (!strcmp(part, "elm.swallow.icon"))
99      elm_icon_standard_set(ic, "home");
100
101    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
102    return ic;
103 }
104
105 static void
106 _item_sel_cb(void *data, Evas_Object *obj, void *event_info)
107 {
108    //   printf("sel item data [%p] on genlist obj [%p], item pointer [%p]\n",
109    //          data, obj, event_info);
110 }
111
112 void
113 _init_genlist(Evas_Object *win)
114 {
115    Evas_Object *box, *entry;
116    static Elm_Genlist_Item_Class *_itc = NULL;
117    int i = 0;
118
119    if (!_itc)
120      {
121         _itc = elm_genlist_item_class_new();
122         _itc->item_style = "default";
123         _itc->func.text_get = _item_label_get;
124         _itc->func.content_get = _item_content_get;
125         _itc->func.state_get = NULL;
126         _itc->func.del = NULL;
127      }
128
129    if (!_itc_group)
130      {
131         _itc_group = elm_genlist_item_class_new();
132         _itc_group->item_style = "group_index";
133         _itc_group->func.text_get = _group_label_get;
134         _itc_group->func.content_get = _group_content_get;
135         _itc_group->func.state_get = NULL;
136         _itc_group->func.del = NULL;
137      }
138
139    box = elm_box_add(win);
140    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
141    elm_win_resize_object_add(win, box);
142    evas_object_show(box);
143
144    glob_genlist = elm_genlist_add(win);
145
146    evas_object_size_hint_weight_set
147        (glob_genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148    evas_object_size_hint_align_set
149        (glob_genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
150    elm_box_pack_end(box, glob_genlist);
151    evas_object_show(glob_genlist);
152
153    entry = elm_entry_add(win);
154    elm_entry_single_line_set(entry, EINA_TRUE);
155    evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, 0.0);
156    evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
157    evas_object_show(entry);
158
159
160    /* filling genlist */
161    for (i = 0; i < N_ITEMS; i++)
162      {
163         Elm_Object_Item *gli = NULL, *glg = NULL;
164
165         if (i % 7 == 0)
166           {
167              glg = gli = elm_genlist_item_append(glob_genlist, _itc_group,
168                                                  (void *) (long) nitems++,
169                                                  NULL, ELM_GENLIST_ITEM_GROUP,
170                                                  _item_sel_cb, NULL );
171              elm_genlist_item_select_mode_set(
172                  gli, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
173           }
174         else
175           {
176              gli = elm_genlist_item_append(glob_genlist, _itc,
177                                            (void *) (long) nitems++, glg,
178                                            ELM_GENLIST_ITEM_NONE,
179                                            _item_sel_cb, NULL );
180           }
181
182         if (i == 1)
183           glob_test_item = gli;
184      }
185
186 }
187
188 EAPI_MAIN int
189 elm_main(int argc, char **argv)
190 {
191    Evas_Object *win;
192
193    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
194    _init_genlist(win);
195
196    /* and show the window */
197    evas_object_show(win);
198
199    elm_run();
200    elm_shutdown();
201
202    /* exit code */
203    return 0;
204 }
205 ELM_MAIN()