Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_popup_tc1.c
1 /*
2  * Tested interface: AtkText
3  *
4  * Tested AtkObject: EailPopup
5  *
6  * Description: Test AtkPopup interface
7  *
8  * Test input: accessible object representing EailPopup
9  *
10  * Expected test result: test should return 0 (success)
11  */
12
13 #include <Elementary.h>
14 #include <atk/atk.h>
15
16
17 #include "eail_test_utils.h"
18
19 #define EAIL_TYPE_FOR_POPUP "EailPopup"
20 #define EAIL_TEST_LABEL_TITTLE "Test popup obj"
21 #define EAIL_TEST_CONTENT_LABEL_TEXT "Test content label text"
22 #define EAIL_TEST_CONTENT_TEXT "seseeseese"
23
24 /* used to determine if test code has been successfully called
25  * (sometimes may happen that ATK object to test in hierarchy cannot be found)*/
26 static gboolean eail_test_code_called = FALSE;
27
28 static void
29 _test_popup_object_with_text(AtkObject *obj);
30
31 static void
32 _test_popup_object_with_label(AtkObject *obj);
33
34 static Evas_Object *popup = NULL;
35
36 static void
37 _on_done(void *data, Evas_Object *obj, void *event_info)
38 {
39    elm_exit();
40 }
41
42 static void
43 _set_label_content_on_popup(Evas_Object *popup)
44 {
45    Evas_Object *label_content;
46
47    label_content = elm_label_add(popup);
48    elm_object_text_set(label_content, EAIL_TEST_CONTENT_LABEL_TEXT);
49
50    elm_object_content_set(popup, label_content);
51 }
52
53 static void
54 on_focus_in(void *data, Evas_Object *obj, void *event_info)
55 {
56    AtkObject *aobj = atk_get_root();
57    g_assert(aobj);
58
59    /* testing popup with text content */
60    eailu_traverse_children_for_type_call_cb
61                   (aobj, EAIL_TYPE_FOR_POPUP, _test_popup_object_with_text);
62
63    _set_label_content_on_popup(popup);
64    /* testing popup with label content */
65    eailu_traverse_children_for_type_call_cb
66                   (aobj, EAIL_TYPE_FOR_POPUP, _test_popup_object_with_label);
67
68    g_assert(eail_test_code_called);
69    _on_done(NULL, obj, NULL);
70 }
71
72 static void
73 _test_popup_object_with_text(AtkObject *obj)
74 {
75    AtkText *text_obj = NULL;
76    char *text = NULL;
77    int child_amount = 0;
78
79    atk_object_set_name(obj, EAIL_TEST_CONTENT_TEXT);
80    g_assert_cmpstr(atk_object_get_name(obj), ==, EAIL_TEST_CONTENT_TEXT);
81    _printf("Testing popup instance with text....\n");
82    g_assert(ATK_IS_TEXT(obj));
83    text_obj =  ATK_TEXT(obj);
84    text = atk_text_get_text(text_obj, 0, -1);
85    g_assert(text);
86    g_assert(strcmp(text, EAIL_TEST_CONTENT_TEXT) == 0);
87    g_assert((atk_text_get_character_count(text_obj)) ==
88                                  (g_utf8_strlen(EAIL_TEST_CONTENT_TEXT, -1)));
89
90    /* only 2 buttons should be listed as children when text content is set */
91    child_amount = atk_object_get_n_accessible_children(obj);
92    g_assert(1 == child_amount);
93
94    _printf("Tests passed successfully\n");
95    eail_test_code_called = TRUE;
96 }
97
98 static void
99 _test_popup_object_with_label(AtkObject *obj)
100 {
101    AtkText *text_obj = NULL;
102    char *text = NULL;
103    int child_amount = 0;
104    AtkObject *nested_obj;
105    atk_object_set_description(obj, "test");
106    g_assert_cmpstr(atk_object_get_description(obj), ==, "test");
107
108    atk_object_set_name(obj, "test name");
109    g_assert_cmpstr(atk_object_get_name(obj), ==, "test name");
110
111    _printf("Testing popup instance with label....\n");
112    g_assert(ATK_IS_TEXT(obj));
113    text_obj =  ATK_TEXT(obj);
114    text = atk_text_get_text(text_obj, 0, -1);
115    g_assert(NULL == text);
116    g_assert((atk_text_get_character_count(text_obj)) == 0);
117
118    /* only 2 buttons + one widget with content should be listed as childrens */
119    child_amount = atk_object_get_n_accessible_children(obj);
120    g_assert(2 == child_amount);
121
122    nested_obj = atk_object_ref_accessible_child(obj, 0);
123    g_assert(eailu_is_object_with_type(nested_obj, "EailLabel"));
124    g_assert(eailu_is_object_with_name
125             (nested_obj, EAIL_TEST_CONTENT_LABEL_TEXT));
126
127    _printf("Tests passed successfully\n");
128 }
129
130 static void
131 _response_cb(void *data, Evas_Object *obj,
132              void *event_info)
133 {
134    evas_object_hide(data);
135 }
136
137 static void
138 _initialize_and_show_popup(Evas_Object *win)
139 {
140    Evas_Object *btn1, *btn2, *icon1;
141    char buf[256];
142
143    popup = elm_popup_add(win);
144
145    icon1 = elm_icon_add(popup);
146    g_snprintf(buf, sizeof(buf), "%s/images/logo_small.png",
147             elm_app_data_dir_get());
148    elm_image_file_set(icon1, buf, NULL );
149
150    /* Seting popup title-text */
151    elm_object_part_text_set(popup, "title,text", EAIL_TEST_LABEL_TITTLE);
152
153    elm_object_text_set(popup,EAIL_TEST_CONTENT_TEXT);
154    /* NOTE: RJ,list content of popup is not supported,
155     * so not adding list items. It is because there is no possibility to
156     * fetch those values from popup via popup API */
157
158    /* Creating the first action button */
159    btn1 = elm_button_add(popup);
160    elm_object_text_set(btn1, "OK");
161
162    /* NOTE: cannot add due to bug with popup inserting content for button3 */
163
164    /* Creating the second action button */
165    btn2 = elm_button_add(popup);
166    elm_object_text_set(btn2, "Cancel");
167    evas_object_smart_callback_add(btn2, "clicked", _response_cb, popup);
168
169    /* Appending the second action button */
170    elm_object_part_content_set(popup, "button1", btn2);
171
172    /* Display the popup object */
173    evas_object_show(popup);
174 }
175
176 EAPI_MAIN int
177 elm_main(int argc, char **argv)
178 {
179    Evas_Object *win;
180
181    win = eailu_create_test_window_with_glib_init(_on_done, on_focus_in);
182    _initialize_and_show_popup(win);
183
184    evas_object_show(win);
185
186    elm_run();
187    elm_shutdown();
188
189    /* exit code */
190    return 0;
191 }
192 ELM_MAIN()