Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_radio_tc2.c
1 /*
2  * Tested interface: AtkObject
3  *
4  * Tested AtkObject: EailRadio
5  *
6  * Description: Test whether accessible object is successfully registered
7  *    in GObject type system and is visible in AtkObject tree.
8  *
9  * Test input: accessible object representing EailRadio
10  *
11  * Expected test result: test should return 0 (success)
12  */
13
14 #include <Elementary.h>
15 #include <atk/atk.h>
16
17 #include "eail_test_utils.h"
18
19 #define RADIO1_SEL 1
20 #define RADIO2_SEL 2
21 #define RADIO3_SEL 3
22 #define RADIO1 "Radio 1"
23 #define RADIO2 "Radio 2"
24 #define RADIO3 "Radio 3"
25 #define TEST_NAME "Test Name"
26
27 int val = 1;
28 int name_test_passed;
29
30 static void _init_radio(Evas_Object *win);
31
32 INIT_TEST("EailRadioButton")
33
34 EAPI_MAIN int
35 elm_main(int argc, char **argv)
36 {
37    Evas_Object *win;
38
39    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
40    _init_radio(win);
41
42    evas_object_show(win);
43    elm_run();
44    elm_shutdown();
45
46    return 0;
47 }
48 ELM_MAIN()
49
50 static void
51 _init_radio(Evas_Object *win)
52 {
53    Evas_Object *bg, *radio, *group, *bx, *ic;
54
55    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
56    elm_win_autodel_set(win, EINA_TRUE);
57
58    bg = elm_bg_add(win);
59    elm_win_resize_object_add(win, bg);
60    evas_object_show(bg);
61
62    bx = elm_box_add(win);
63    elm_box_horizontal_set(bx, EINA_TRUE);
64    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
65    elm_win_resize_object_add(win, bx);
66    evas_object_show(bx);
67
68    group = radio = elm_radio_add(win);
69    elm_object_text_set(radio, RADIO1);
70    elm_radio_state_value_set(radio, 1);
71    elm_radio_value_pointer_set(radio, &val);
72    ic = elm_icon_add(win);
73    elm_icon_standard_set(ic, "home");
74    elm_object_part_content_set(radio, "icon", ic);
75    elm_box_pack_end(bx, radio);
76    evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
77    evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
78    evas_object_show(radio);
79
80    radio = elm_radio_add(win);
81    elm_object_text_set(radio, RADIO2);
82    elm_radio_state_value_set(radio, 2);
83    elm_radio_value_pointer_set(radio, &val);
84    elm_radio_group_add(radio, group);
85    ic = elm_icon_add(win);
86    elm_icon_standard_set(ic, "file");
87    elm_object_part_content_set(radio, "icon", ic);
88    elm_box_pack_end(bx, radio);
89    evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
90    evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
91    evas_object_show(radio);
92
93    radio = elm_radio_add(win);
94    elm_object_text_set(radio, RADIO3);
95    elm_radio_state_value_set(radio, 3);
96    elm_radio_value_pointer_set(radio, &val);
97    elm_radio_group_add(radio, group);
98    elm_box_pack_end(bx, radio);
99    evas_object_size_hint_weight_set(radio, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
100    evas_object_size_hint_align_set(radio, EVAS_HINT_FILL, EVAS_HINT_FILL);
101    evas_object_show(radio);
102
103    elm_radio_value_set(radio, RADIO2_SEL);
104 }
105
106 static void
107 _do_test(AtkObject *obj)
108 {
109    AtkStateSet *state_set = atk_object_ref_state_set(obj);
110    const char *name;
111
112    g_assert(ATK_IS_OBJECT(obj));
113    g_assert(atk_object_get_role(obj) == ATK_ROLE_RADIO_BUTTON);
114
115    atk_object_set_description(obj, "test");
116    g_assert_cmpstr(atk_object_get_description(obj), ==, "test");
117
118    name = atk_object_get_name(obj);
119
120    if (!strcmp(name, RADIO1))
121      {
122         state_set = atk_object_ref_state_set(obj);
123         g_assert(!atk_state_set_contains_state(state_set, ATK_STATE_CHECKED));
124         g_object_unref(state_set);
125         ++name_test_passed;
126
127         atk_object_set_name(obj, TEST_NAME);
128         g_assert_cmpstr(atk_object_get_name(obj), ==, TEST_NAME);
129      }
130    else if (!strcmp(name, RADIO2))
131      {
132         state_set = atk_object_ref_state_set(obj);
133         g_assert(atk_state_set_contains_state(state_set, ATK_STATE_CHECKED));
134         g_object_unref(state_set);
135         ++name_test_passed;
136         g_assert(name_test_passed == 2);
137
138         atk_object_set_name(obj, TEST_NAME);
139         g_assert_cmpstr(atk_object_get_name(obj), ==, TEST_NAME);
140      }
141    else if (!strcmp(name, RADIO3))
142      {
143         state_set = atk_object_ref_state_set(obj);
144         g_assert(!atk_state_set_contains_state(state_set, ATK_STATE_CHECKED));
145         g_object_unref(state_set);
146         ++name_test_passed;
147         g_assert(name_test_passed == 3);
148
149         atk_object_set_name(obj, TEST_NAME);
150         g_assert_cmpstr(atk_object_get_name(obj), ==, TEST_NAME);
151      }
152    else
153      {
154         g_assert(0);
155      }
156
157    eailu_test_code_called = 1;
158 }