Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_menu_tc1.c
1 /*
2  * Tested interface: AtkObject
3  *
4  * Tested AtkObject: EailMenu
5  *
6  * Description: Test whether accessible object is successfully registered
7  *    in GObject type system and is visible in AtkObject tree. Test
8  *    accessible children availability.
9  *
10  * Test input: accessible object representing EailMenu
11  *
12  * Expected test result: test should return 0 (success)
13  */
14
15 #include <Elementary.h>
16 #include <atk/atk.h>
17
18 #include "eail_test_utils.h"
19
20 #define EAIL_TYPE_FOR_MENU "EailMenu"
21 #define EAIL_TYPE_FOR_MENU_ITEM "EailMenuItem"
22 #define T_MENU_ITEM_WITH_NO_CHILD_NAME "first item"
23 #define T_SUBM_WITH_ICON_NAME "RJ Menu 1 with icon"
24 #define T_NESTED_BUTTON_NAME "button - delete items (2nd level)"
25 #define T_MENU_WITH_SUB_AND_ICON_NAME "second item"
26 #define T_CUSTOM_NAME_FOR_ITEM "Custom name set to nested button"
27 #define T_CUSTOM_DESCRIPTION "Description for testing"
28
29 INIT_TEST("EailMenu")
30
31 static void
32 _show(void *data, Evas *e, Evas_Object *obj, void *event_info)
33 {
34    Evas_Event_Mouse_Down *ev = event_info;
35    elm_menu_move(data, ev->canvas.x, ev->canvas.y);
36    evas_object_show(data);
37 }
38
39 static void
40 _do_test(AtkObject *aobj)
41 {
42    AtkObject *found_obj = NULL;
43    int child_amount = 0;
44
45    found_obj = eailu_find_child_with_name(aobj, T_SUBM_WITH_ICON_NAME);
46    atk_object_set_description(aobj, "test");
47    g_assert_cmpstr(atk_object_get_description(aobj), ==, "test");
48
49    g_assert(found_obj);
50
51    /* checking if nested button can be found */
52    found_obj = eailu_find_child_with_name(aobj, T_NESTED_BUTTON_NAME);
53    g_assert(found_obj);
54
55    /* checking if menu with submenus AND nested icon can be found */
56    found_obj = eailu_find_child_with_name(aobj, T_MENU_WITH_SUB_AND_ICON_NAME);
57    g_assert(found_obj);
58    eailu_test_atk_focus(found_obj, FALSE);
59
60    /* cheking if name/description change can be done for item */
61    atk_object_set_name(found_obj, T_CUSTOM_NAME_FOR_ITEM);
62    g_assert(0 == g_strcmp0
63                     (T_CUSTOM_NAME_FOR_ITEM, atk_object_get_name(found_obj)));
64    atk_object_set_description(found_obj, T_CUSTOM_DESCRIPTION);
65    g_assert(0 == g_strcmp0
66                (T_CUSTOM_DESCRIPTION, atk_object_get_description(found_obj)));
67
68    /* submenu with icons should have 7 children - one for each of 5 submenus,
69     * plus 1 for separator, which is shown as MENU ITEM with empty name
70     * plus 1 for nested ICON */
71    child_amount = atk_object_get_n_accessible_children(found_obj);
72    g_assert(7 == child_amount);
73
74    eailu_test_code_called = TRUE;
75 }
76
77
78 static void
79 _init_menu(Evas_Object *win)
80 {
81    Evas_Object *menu, *button;
82    Elm_Object_Item *menu_it, *menu_it1;
83
84    menu = elm_menu_add(win);
85    elm_object_tree_focus_allow_set(win, EINA_TRUE);
86
87    elm_menu_item_add
88             (menu, NULL, NULL, T_MENU_ITEM_WITH_NO_CHILD_NAME, NULL, NULL);
89    menu_it = elm_menu_item_add
90                (menu, NULL, "mail-reply-all", T_MENU_WITH_SUB_AND_ICON_NAME,
91                 NULL, NULL );
92    elm_menu_item_add
93       (menu, menu_it, "object-rotate-left", T_SUBM_WITH_ICON_NAME, NULL, NULL);
94
95    button = elm_button_add(win);
96    elm_object_text_set(button, T_NESTED_BUTTON_NAME);
97    menu_it1 = elm_menu_item_add(menu, menu_it, NULL, NULL, NULL, NULL );
98    elm_object_item_content_set(menu_it1, button);
99
100    /* separator by atk is treated as empty MENU ITEM */
101    elm_menu_item_separator_add(menu, menu_it);
102    elm_menu_item_add(menu, menu_it, NULL, "third item (2nd lev)", NULL, NULL);
103    elm_menu_item_add(menu, menu_it, NULL, "fourth item (2nd lev)", NULL, NULL);
104    elm_menu_item_add
105          (menu, menu_it, "window-new", "sub menu (2nd lev)", NULL, NULL );
106
107    menu_it = elm_menu_item_add(menu, NULL, NULL, "third item", NULL, NULL );
108    elm_object_item_disabled_set(menu_it, EINA_TRUE );
109
110    evas_object_event_callback_add(win, EVAS_CALLBACK_MOUSE_DOWN, _show, menu);
111    evas_object_show(menu);
112 }
113
114 EAPI_MAIN int
115 elm_main(int argc, char **argv)
116 {
117    Evas_Object *win;
118
119    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
120    _init_menu(win);
121
122    evas_object_show(win);
123    elm_run();
124    elm_shutdown();
125
126    return 0;
127 }
128 ELM_MAIN()