Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_slideshow_tc3.c
1 /*
2  * Tested interface: AtkAction
3  *
4  * Tested AtkObject: EailSlideshow
5  *
6  * Description: Test AtkSelection interface
7  *
8  * Test input: accessible object representing EailSlideshow
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("EailSlideshow")
19
20 static Evas_Object *slideshow;
21 static Elm_Slideshow_Item_Class itc;
22
23 static char img1[256], img2[256], img3[256], img4[256], img5[256], img6[256],
24             img7[256], img8[256], img9[256];
25
26 /* get our images to make slideshow items */
27 static Evas_Object *
28 _get(void        *data,
29      Evas_Object *obj)
30 {
31    Evas_Object *photo = elm_photo_add(obj);
32    elm_photo_file_set(photo, data);
33    elm_photo_fill_inside_set(photo, EINA_TRUE);
34    elm_object_style_set(photo, "shadow");
35
36    return photo;
37 }
38
39 /* ordering alphabetically */
40 static int
41 _cmp_func(const void *data1,
42           const void *data2)
43 {
44    const char *img_path1, *img_path2;
45
46    const Elm_Object_Item *slide_it1 = data1;
47    const Elm_Object_Item *slide_it2 = data2;
48
49    img_path1 = elm_object_item_data_get(slide_it1);
50    img_path2 = elm_object_item_data_get(slide_it2);
51
52    return strcasecmp(img_path1, img_path2);
53 }
54
55 static void
56 _do_test(AtkObject *obj)
57 {
58    int child_count, selection_count, action_count;
59    AtkObject *child, *selection;
60    gboolean result;
61    const gchar *action_name, *action_description;
62    /*sometimes this is called several times*/
63    static int tested = 0;
64    if (tested > 0) return;
65    tested++;
66
67    g_object_ref(obj);
68
69    g_assert(eailu_is_object_with_role(obj, ATK_ROLE_DOCUMENT_PRESENTATION));
70
71    child_count = atk_object_get_n_accessible_children(obj);
72    g_assert(child_count == 9);
73
74    for (int i = 0; i < child_count; i++)
75      {
76         child = atk_object_ref_accessible_child(obj, i);
77         g_assert(eailu_is_object_with_role(child, ATK_ROLE_IMAGE));
78         g_object_unref(child);
79      }
80
81    /*test AtkSelectionIface*/
82    g_assert(ATK_IS_SELECTION(obj));
83    selection = atk_selection_ref_selection(ATK_SELECTION(obj), 0);
84    /*this may fail due to a problem with  slideshow cache*/
85    g_assert(ATK_IS_OBJECT(selection));
86    g_assert(eailu_is_object_with_role(selection, ATK_ROLE_IMAGE));
87    g_object_unref(selection);
88    selection_count = atk_selection_get_selection_count(ATK_SELECTION(obj));
89    g_assert(selection_count == 1);
90    result = atk_selection_add_selection(ATK_SELECTION(obj), 5);
91    g_assert(result);
92    result = atk_selection_is_child_selected(ATK_SELECTION(obj), 5);
93    g_assert(result);
94
95    /*test AtkActionIface*/
96    g_assert(ATK_IS_ACTION(obj));
97    /* test set/get action description */
98    eailu_test_action_description_all(ATK_ACTION(obj));
99    action_count = atk_action_get_n_actions(ATK_ACTION(obj));
100    g_assert(4 == action_count);
101    action_name = atk_action_get_name(ATK_ACTION(obj), 0);
102    g_assert(!strcmp("next", action_name));
103    action_name = atk_action_get_name(ATK_ACTION(obj), 1);
104    g_assert(!strcmp("previous", action_name));
105    result = atk_action_set_description(ATK_ACTION(obj), 2,
106                                        "start the slideshow");
107    g_assert(result);
108    action_description = atk_action_get_description(ATK_ACTION(obj), 2);
109    g_assert(!strcmp("start the slideshow", action_description));
110    result = atk_action_do_action(ATK_ACTION(obj), 0);
111    g_assert(result);
112    result = atk_selection_is_child_selected(ATK_SELECTION(obj), 6);
113    g_assert(result);
114
115    eailu_test_atk_focus(obj, TRUE);
116
117    g_object_unref(obj);
118    eailu_test_code_called = 1;
119 }
120
121 static void
122 _init_slideshow(Evas_Object *win)
123 {
124    Evas_Object *bg;
125    Elm_Object_Item *it;
126    const char *data_dir;
127
128    data_dir = "./data";
129    g_snprintf(img1, sizeof(img1), "%s/01.jpg", data_dir);
130    g_snprintf(img2, sizeof(img2), "%s/02.jpg", data_dir);
131    g_snprintf(img3, sizeof(img3), "%s/03.jpg", data_dir);
132    g_snprintf(img4, sizeof(img4), "%s/04.jpg", data_dir);
133    g_snprintf(img5, sizeof(img5), "%s/05.jpg", data_dir);
134    g_snprintf(img6, sizeof(img6), "%s/06.jpg", data_dir);
135    g_snprintf(img7, sizeof(img7), "%s/07.jpg", data_dir);
136    g_snprintf(img8, sizeof(img8), "%s/08.jpg", data_dir);
137    g_snprintf(img9, sizeof(img9), "%s/09.jpg", data_dir);
138
139    evas_object_resize(win, 600, 400);
140
141    bg = elm_bg_add(win);
142    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
143    elm_win_resize_object_add(win, bg);
144    evas_object_show(bg);
145
146    slideshow = elm_slideshow_add(win);
147    elm_slideshow_loop_set(slideshow, EINA_TRUE);
148    elm_slideshow_cache_before_set(slideshow, 8);
149    elm_slideshow_cache_after_set(slideshow, 8);
150    evas_object_size_hint_weight_set(slideshow,
151                                     EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
152    elm_win_resize_object_add(win, slideshow);
153    evas_object_show(slideshow);
154
155    itc.func.get = _get;
156    itc.func.del = NULL;
157
158    elm_slideshow_item_sorted_insert(slideshow, &itc, img1, _cmp_func);
159    elm_slideshow_item_sorted_insert(slideshow, &itc, img2, _cmp_func);
160    elm_slideshow_item_sorted_insert(slideshow, &itc, img3, _cmp_func);
161    elm_slideshow_item_sorted_insert(slideshow, &itc, img4, _cmp_func);
162    elm_slideshow_item_sorted_insert(slideshow, &itc, img5, _cmp_func);
163    elm_slideshow_item_sorted_insert(slideshow, &itc, img6, _cmp_func);
164    elm_slideshow_item_sorted_insert(slideshow, &itc, img7, _cmp_func);
165    elm_slideshow_item_sorted_insert(slideshow, &itc, img8, _cmp_func);
166    elm_slideshow_item_sorted_insert(slideshow, &itc, img9, _cmp_func);
167
168    /*show last item, otherwise tests fail*/
169    it = elm_slideshow_item_nth_get(slideshow, 8);
170    elm_slideshow_item_show(it);
171 }
172
173 EAPI_MAIN int
174 elm_main(int    argc,
175          char **argv)
176 {
177
178    Evas_Object *win;
179    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
180    _init_slideshow(win);
181
182    evas_object_show(win);
183    elm_run();
184    elm_shutdown();
185
186    return 0;
187 }
188 ELM_MAIN()