Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_ctxpopup_tc1.c
1 /*
2  * Tested interface: AtkObject
3  *
4  * Tested AtkObject: EailCtxpopup
5  *
6  * Description: Test AtkObject interface
7  *
8  * Test input: accessible object representing EailCtxpopup
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("EailCtxpopup")
19
20 static void
21 _do_test(AtkObject *obj)
22 {
23    int child_amount = 0;
24    AtkObject *nested_obj;
25    AtkStateSet *state_set = NULL;
26
27    _printf("Testing ctxpopup instance....\n");
28
29    atk_object_set_description(obj, "test");
30    g_assert_cmpstr(atk_object_get_description(obj), ==, "test");
31
32    atk_object_set_name(obj, "test name");
33    g_assert_cmpstr(atk_object_get_name(obj), ==, "test name");
34
35    child_amount = atk_object_get_n_accessible_children(obj);
36    /* we have to check if there is nested label in Notify */
37    g_assert(1 == child_amount);
38
39    /* test if ctxpopup child  is list-type*/
40    nested_obj = atk_object_ref_accessible_child(obj, 0);
41    g_assert(eailu_is_object_with_type(nested_obj, "EailList"));
42
43    /* check if atk sees proper amount of list items in ctxpopup */
44    child_amount = atk_object_get_n_accessible_children(nested_obj);
45    g_assert(6 == child_amount);
46
47    /* NOTE: in ctxpopup object focus automatically goes to nested
48     * label */
49    atk_component_grab_focus(ATK_COMPONENT(obj));
50    state_set = atk_object_ref_state_set(nested_obj);
51    /* checking if nested label is now focused... */
52    g_assert(atk_state_set_contains_state(state_set, ATK_STATE_FOCUSED));
53
54    _printf("Tests passed successfully\n");
55
56    eailu_test_code_called = 1;
57 }
58
59 static void
60 _ctxpopup_item_cb(void *data, Evas_Object *obj, void *event_info)
61 {
62    _printf("ctxpopup item selected: %s\n", elm_object_item_text_get(event_info));
63 }
64
65 Elm_Object_Item *item_new(Evas_Object *ctxpopup, const char * label, const char *icon)
66 {
67    Evas_Object *ic = elm_icon_add(ctxpopup);
68    elm_icon_standard_set(ic, icon);
69    elm_image_resizable_set(ic, EINA_FALSE, EINA_FALSE);
70    return elm_ctxpopup_item_append(ctxpopup, label, ic, _ctxpopup_item_cb, NULL);
71 }
72
73 static void
74 _init_ctxpopup(Evas_Object *win)
75 {
76    Evas_Object *ctxpopup, *box;
77    Elm_Object_Item *object_it;
78
79    box = elm_box_add(win);
80    evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
81    elm_win_resize_object_add(win, box);
82    evas_object_show(box);
83
84    ctxpopup = elm_ctxpopup_add(win);
85    item_new(ctxpopup, "Go to home folder", "home");
86    item_new(ctxpopup, "Save file", "file");
87    item_new(ctxpopup, "Delete file", "delete");
88    object_it = item_new(ctxpopup, "Navigate to folder", "folder");
89    elm_object_item_disabled_set(object_it, EINA_TRUE);
90    item_new(ctxpopup, "Edit entry", "edit");
91    object_it = item_new(ctxpopup, "Set date and time", "clock");
92
93    evas_object_size_hint_weight_set(ctxpopup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
94    evas_object_show(ctxpopup);
95    elm_box_pack_end(box, ctxpopup);
96 }
97
98 EAPI_MAIN int
99 elm_main(int argc, char **argv)
100 {
101    Evas_Object *win;
102
103    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
104    _init_ctxpopup(win);
105    evas_object_show(win);
106    elm_run();
107    elm_shutdown();
108
109    return 0;
110 }
111 ELM_MAIN()