Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_focus_test.c
1 #include <Elementary.h>
2 #include <atk/atk.h>
3
4 #include "eail_test_utils.h"
5
6 #define EAIL_TEST_ENTRY_NAME "entry text"
7
8 /* used to determine if test code has been successfully called
9  * (sometimes may happen that ATK object to test in hierarchy cannot be found)*/
10 static gboolean eail_test_code_called = FALSE;
11
12 static void
13 _on_done(void *data, Evas_Object *obj, void *event_info)
14 {
15    elm_exit();
16 }
17
18 static void
19 _test_focus_on_entry(AtkObject *obj)
20 {
21    AtkObject *focused_obj = NULL;
22    gboolean success = FALSE;
23
24    _printf("Testing focus....\n");
25
26    /* changing focus */
27    g_assert(ATK_IS_COMPONENT(obj));
28    success = atk_component_grab_focus(ATK_COMPONENT(obj));
29    g_assert(success);
30
31    /* now focus should point to our button*/
32    focused_obj = atk_get_focus_object();
33    g_assert(focused_obj);
34
35    g_assert(focused_obj == obj);
36
37    _printf("DONE. All focus test passed successfully \n");
38    eail_test_code_called = TRUE;
39 }
40
41 static void
42 _on_focus_in(void *data, Evas_Object *obj, void *event_info)
43 {
44    AtkObject *aobj = atk_get_root();
45    g_assert(aobj);
46
47    eailu_traverse_children_for_type_call_cb
48                                  (aobj, "EailEntry", _test_focus_on_entry);
49
50    g_assert(eail_test_code_called);
51    elm_exit();
52 }
53
54 static void
55 _initialize_and_show_buttons(Evas_Object *win)
56 {
57    Evas_Object *bg  = NULL, *entry = NULL;
58
59    bg = elm_bg_add(win);
60    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61    elm_win_resize_object_add(win, bg);
62    evas_object_show(bg);
63
64    entry = elm_entry_add(win);
65    elm_entry_entry_set(entry, EAIL_TEST_ENTRY_NAME);
66    evas_object_resize(entry, 100, 60);
67    evas_object_move(entry, 50, 20);
68    evas_object_show(entry);
69 }
70
71 EAPI_MAIN int
72 elm_main(int argc, char **argv)
73 {
74    Evas_Object *win;
75
76    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
77    _initialize_and_show_buttons(win);
78
79    evas_object_show(win);
80
81    elm_run();
82    elm_shutdown();
83
84    /* exit code */
85    return 0;
86 }
87 ELM_MAIN()