Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_slideshow_tc1.c
1 /*
2  * Tested interface: AtkObject
3  *
4  * Tested AtkObject: EailSlideshow
5  *
6  * Description: Test AtkObject 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;
59    AtkObject *child;
60    /*sometimes this is called several times*/
61    static int tested = 0;
62    if (tested > 0) return;
63    tested++;
64
65    g_assert(ATK_IS_OBJECT(obj));
66    atk_object_set_description(obj, "test");
67    g_assert_cmpstr(atk_object_get_description(obj), ==, "test");
68
69    atk_object_set_name(obj, "test name");
70    g_assert_cmpstr(atk_object_get_name(obj), ==, "test name");
71
72    g_object_ref(obj);
73
74    g_assert(eailu_is_object_with_role(obj, ATK_ROLE_DOCUMENT_PRESENTATION));
75
76    child_count = atk_object_get_n_accessible_children(obj);
77    g_assert(child_count == 9);
78
79    for (int i = 0; i < child_count; i++)
80      {
81         child = atk_object_ref_accessible_child(obj, i);
82         g_assert(eailu_is_object_with_role(child, ATK_ROLE_IMAGE));
83         g_object_unref(child);
84      }
85
86    eailu_test_atk_focus(obj, TRUE);
87
88    g_object_unref(obj);
89    eailu_test_code_called = 1;
90 }
91
92
93 static void
94 _init_slideshow(Evas_Object *win)
95 {
96    Evas_Object *bg;
97    Elm_Object_Item *it;
98    const char *data_dir;
99
100    data_dir = "./data";
101    g_snprintf(img1, sizeof(img1), "%s/01.jpg", data_dir);
102    g_snprintf(img2, sizeof(img2), "%s/02.jpg", data_dir);
103    g_snprintf(img3, sizeof(img3), "%s/03.jpg", data_dir);
104    g_snprintf(img4, sizeof(img4), "%s/04.jpg", data_dir);
105    g_snprintf(img5, sizeof(img5), "%s/05.jpg", data_dir);
106    g_snprintf(img6, sizeof(img6), "%s/06.jpg", data_dir);
107    g_snprintf(img7, sizeof(img7), "%s/07.jpg", data_dir);
108    g_snprintf(img8, sizeof(img8), "%s/08.jpg", data_dir);
109    g_snprintf(img9, sizeof(img9), "%s/09.jpg", data_dir);
110
111    evas_object_resize(win, 600, 400);
112
113    bg = elm_bg_add(win);
114    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
115    elm_win_resize_object_add(win, bg);
116    evas_object_show(bg);
117
118    slideshow = elm_slideshow_add(win);
119    elm_slideshow_loop_set(slideshow, EINA_TRUE);
120    elm_slideshow_cache_before_set(slideshow, 8);
121    elm_slideshow_cache_after_set(slideshow, 8);
122    evas_object_size_hint_weight_set(slideshow,
123                                     EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
124    elm_win_resize_object_add(win, slideshow);
125    evas_object_show(slideshow);
126
127    itc.func.get = _get;
128    itc.func.del = NULL;
129
130    elm_slideshow_item_sorted_insert(slideshow, &itc, img1, _cmp_func);
131    elm_slideshow_item_sorted_insert(slideshow, &itc, img2, _cmp_func);
132    elm_slideshow_item_sorted_insert(slideshow, &itc, img3, _cmp_func);
133    elm_slideshow_item_sorted_insert(slideshow, &itc, img4, _cmp_func);
134    elm_slideshow_item_sorted_insert(slideshow, &itc, img5, _cmp_func);
135    elm_slideshow_item_sorted_insert(slideshow, &itc, img6, _cmp_func);
136    elm_slideshow_item_sorted_insert(slideshow, &itc, img7, _cmp_func);
137    elm_slideshow_item_sorted_insert(slideshow, &itc, img8, _cmp_func);
138    elm_slideshow_item_sorted_insert(slideshow, &itc, img9, _cmp_func);
139
140    /*show last item, otherwise tests fail*/
141    it = elm_slideshow_item_nth_get(slideshow, 8);
142    elm_slideshow_item_show(it);
143 }
144
145 EAPI_MAIN int
146 elm_main(int    argc,
147          char **argv)
148 {
149    Evas_Object *win;
150    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
151    _init_slideshow(win);
152
153    evas_object_show(win);
154    elm_run();
155    elm_shutdown();
156
157    return 0;
158 }
159 ELM_MAIN()