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