Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_naviframe_page_tc1.c
1 /*
2  * Tested interface: AtkObject
3  *
4  * Tested AtkObject: EailNaviframePage
5  *
6  * Description: Test AtkAction interface
7  *
8  * Test input: accessible object representing EailNaviframePage
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("EailNaviframe")
19
20 #define BUTTON_TEXT_SET(BT, TEXT) \
21    elm_object_text_set((BT), (TEXT)); \
22    elm_object_tooltip_text_set((BT), (TEXT)); \
23    elm_object_tooltip_window_mode_set((BT), EINA_TRUE)
24
25 #define PACKAGE_DATA_DIR "./data"
26
27 static const char *img1 = PACKAGE_DATA_DIR "/whiterabbit01.jpg";
28 static const char *img2 = PACKAGE_DATA_DIR "/01.jpg";
29 static const char *img3 = PACKAGE_DATA_DIR "/02.jpg";
30 static const char *img4 = PACKAGE_DATA_DIR "/03.jpg";
31 static const char *img5 = PACKAGE_DATA_DIR "/04.jpg";
32 static const char *img8 = PACKAGE_DATA_DIR "/small-01.jpg";
33
34 Evas_Object *
35 _content_new(Evas_Object *parent, const char *img)
36 {
37    Evas_Object *photo = elm_photo_add(parent);
38    elm_photo_file_set(photo, img);
39    elm_photo_fill_inside_set(photo, EINA_TRUE);
40    elm_object_style_set(photo, "shadow");
41    return photo;
42 }
43
44 static void
45 _page5(Evas_Object *nf)
46 {
47    Evas_Object *bt, *bt2, *content;
48    Elm_Object_Item *it;
49
50    bt = elm_button_add(nf);
51    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
52    BUTTON_TEXT_SET(bt, "Page 4");
53
54    bt2 = elm_button_add(nf);
55    evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL, EVAS_HINT_FILL);
56    BUTTON_TEXT_SET(bt2, "Page 1");
57
58    content = _content_new(nf, img5);
59    it = elm_naviframe_item_insert_after(nf,
60                                         elm_naviframe_top_item_get(nf),
61                                         "Page 5",
62                                         bt,
63                                         bt2,
64                                         content,
65                                         NULL);
66    elm_object_item_part_text_set(it, "subtitle",
67                                  "This page is inserted without transition");
68
69    evas_object_data_set(nf, "page5", it);
70    elm_naviframe_item_promote(it);
71 }
72
73 static void
74 _page4(Evas_Object *nf)
75 {
76    Evas_Object *bt, *ic, *content;
77    char buf[PATH_MAX];
78    Elm_Object_Item *it;
79
80    ic = elm_icon_add(nf);
81    elm_icon_standard_set(ic, "arrow_right");
82
83    bt = elm_button_add(nf);
84    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
85    elm_layout_content_set(bt, "icon", ic);
86
87    content = _content_new(nf, img4);
88
89    it = elm_naviframe_item_push(nf,
90                                 "Page 4",
91                                 NULL,
92                                 bt,
93                                 content,
94                                 NULL);
95    elm_object_item_part_text_set(it, "subtitle", "Title area visibility test");
96
97    ic = elm_icon_add(nf);
98    g_snprintf(buf, sizeof(buf), "%s",
99             img8);
100    elm_image_file_set(ic, buf, NULL);
101    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
102    elm_object_item_part_content_set(it, "icon", ic);
103    elm_naviframe_item_title_visible_set(it, EINA_FALSE);
104
105    evas_object_data_set(nf, "page4", it);
106 }
107
108 static void
109 _page3(Evas_Object *nf)
110 {
111    Evas_Object *bt2, *ic, *content;
112    char buf[PATH_MAX];
113    Elm_Object_Item *it;
114
115    bt2 = elm_button_add(nf);
116    evas_object_size_hint_align_set(bt2, EVAS_HINT_FILL, EVAS_HINT_FILL);
117    BUTTON_TEXT_SET(bt2, "Next");
118
119    content = _content_new(nf, img3);
120
121    it = elm_naviframe_item_push(nf,
122                                 "Page 3",
123                                 NULL,
124                                 bt2,
125                                 content,
126                                 NULL);
127    ic = elm_icon_add(nf);
128    g_snprintf(buf, sizeof(buf), "%s", img8);
129    elm_image_file_set(ic, buf, NULL);
130    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
131
132    elm_object_item_part_content_set(it, "icon", ic);
133
134    evas_object_data_set(nf, "page3", it);
135 }
136
137 static void
138 _page2(Evas_Object *nf)
139 {
140    Evas_Object *bt, *content, *ic;
141    Elm_Object_Item *it;
142
143    bt = elm_button_add(nf);
144    evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
145
146    ic = elm_icon_add(nf);
147    elm_icon_standard_set(ic, "arrow_right");
148    evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
149    elm_layout_content_set(bt, "icon", ic);
150
151    content = _content_new(nf, img2);
152
153    it = elm_naviframe_item_push(nf, "Page 2 - Long Title Here",
154                                 NULL, bt, content,  NULL);
155    elm_object_item_part_text_set(it, "subtitle", "Here is sub-title part!");
156    evas_object_data_set(nf, "page2", it);
157
158 }
159
160 static void
161 _page1(Evas_Object *nf)
162 {
163    Evas_Object *btn, *content;
164    Elm_Object_Item *it;
165
166    btn = elm_button_add(nf);
167    evas_object_size_hint_align_set(btn, EVAS_HINT_FILL, EVAS_HINT_FILL);
168    BUTTON_TEXT_SET(btn, "Next");
169    evas_object_show(btn);
170
171    content = _content_new(nf, img1);
172    it = elm_naviframe_item_push(nf, "Page 1", NULL, btn, content, NULL);
173    evas_object_data_set(nf, "page1", it);
174 }
175
176
177 static void
178 _test_naviframe_page(AtkObject *obj, int index)
179 {
180    int child_count = atk_object_get_n_accessible_children(obj);
181
182    atk_object_set_description(obj, "test");
183    g_assert_cmpstr(atk_object_get_description(obj), ==, "test");
184
185    g_assert(child_count > 0);
186    AtkStateSet *state_set = atk_object_ref_state_set(obj);
187    if (index == 4)
188      {
189         AtkStateType states[3] = {ATK_STATE_SHOWING, ATK_STATE_VISIBLE,
190              ATK_STATE_ENABLED};
191         /*we are showing last page*/
192         gboolean contains = atk_state_set_contains_states(state_set, states, 3);
193         g_assert(contains);
194      }
195    g_object_unref(state_set);
196
197    int index_in_parent = atk_object_get_index_in_parent(obj);
198    g_assert(index_in_parent == index);
199
200    /*check if last child is naviframe page content*/
201    AtkObject *child = atk_object_ref_accessible_child(obj, child_count - 1);
202    g_assert(eailu_is_object_with_type(child, "EailPhoto"));
203    g_object_unref(child);
204
205    AtkObject *parent = atk_object_get_parent(obj);
206    g_object_ref(parent);
207    g_assert(ATK_IS_OBJECT(parent));
208    g_assert(eailu_is_object_with_type(parent, "EailNaviframe"));
209    g_object_unref(parent);
210
211    int x = -1;
212    int y = -1;
213    int width = -1;
214    int height = -1;
215
216    atk_component_get_extents(ATK_COMPONENT(obj),
217                              &x, &y,
218                              &width, &height,
219                              ATK_XY_SCREEN);
220    g_assert(x > 0);
221    g_assert(y > 0);
222    g_assert(height > 0);
223    g_assert(width > 0);
224
225 }
226
227 static void
228 _do_test(AtkObject *obj)
229 {
230    int child_count = 0;
231
232    g_object_ref(obj);
233    child_count = atk_object_get_n_accessible_children(obj);
234    g_assert(child_count == 5);
235
236    for (int i = 0; i < child_count; i++)
237      {
238         AtkObject *child = atk_object_ref_accessible_child(obj, i);
239         g_assert(ATK_IS_OBJECT(child));
240         g_assert(eailu_is_object_with_type(child, "EailNaviframePage"));
241         g_assert(ATK_ROLE_PAGE_TAB == atk_object_get_role(child));
242         _test_naviframe_page(child, i);
243         g_object_unref(child);
244      }
245    g_object_unref(obj);
246
247    eailu_test_code_called = 1;
248 }
249
250 static void
251 _init_naviframe(Evas_Object *win)
252 {
253     Evas_Object *nf;
254
255    nf = elm_naviframe_add(win);
256    evas_object_size_hint_weight_set(nf, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
257    elm_win_resize_object_add(win, nf);
258    evas_object_show(nf);
259
260    _page1(nf);
261    _page2(nf);
262    _page3(nf);
263    _page4(nf);
264    _page5(nf);
265
266    evas_object_resize(win, 800, 600);
267 }
268
269 EAPI_MAIN int
270 elm_main(int argc, char **argv)
271 {
272    Evas_Object *win;
273    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
274    _init_naviframe(win);
275    evas_object_show(win);
276
277    elm_run();
278    elm_shutdown();
279
280    return 0;
281 }
282 ELM_MAIN()