Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_clock_tc1.c
1 /*
2  * Tested interface: AtkValue
3  *
4  * Tested AtkObject: EailClock
5  *
6  * Description: Test AtkValue interface
7  *
8  * Test input: accessible object representing EailClock
9  *
10  * Expected test result: test should return 0 (success)
11  */
12
13 #include <Elementary.h>
14 #include <atk/atk.h>
15 #include "eail_test_utils.h"
16
17 INIT_TEST("EailClock")
18
19 static void
20 _printf_clock_int(const char *str, int current_second_day)
21 {
22    int hour, minute, second;
23
24    hour = current_second_day / 3600;
25    minute = (current_second_day % 3600) / 60;
26    second = current_second_day % 60;
27
28    _printf("[%02d:%02d:%02d] (%s)\n", hour, minute, second, str);
29 }
30
31 static void
32 _do_test(AtkObject *obj)
33 {
34    int minimum, maximum, current, minimum_increment;
35    const int lambda = 5; /*tolerance for get time in case that test will take
36    longer than expected on very slow machine*/
37    const int val_test_init = 4 * 3600 + 44 * 60 + 22; // 04:44:22
38    const int val_test_set = 12 * 3600 + 4 * 60 + 7;   // 12:04:07
39
40    g_assert(atk_object_get_role(obj) == ATK_ROLE_TEXT);
41
42    GValue value = G_VALUE_INIT;
43
44    atk_value_get_minimum_value(ATK_VALUE(obj), &value);
45    minimum = g_value_get_int(&value);
46    _printf_clock_int("atk_value_get_minimum_value", minimum);
47    g_assert(0 == minimum);
48
49    atk_value_get_maximum_value(ATK_VALUE(obj), &value);
50    maximum = g_value_get_int(&value);
51    _printf_clock_int("atk_value_get_maximum_value", maximum);
52    g_assert((24 * 3600 - 1) == maximum);
53
54    atk_value_get_current_value(ATK_VALUE(obj), &value);
55    current = g_value_get_int(&value);
56    _printf_clock_int("atk_value_get_current_value", current);
57    g_assert(abs(current - val_test_init) < lambda);
58
59    atk_value_get_minimum_increment(ATK_VALUE(obj), &value);
60    minimum_increment = g_value_get_int(&value);
61    _printf_clock_int("atk_value_get_minimum_increment", minimum_increment);
62    g_assert(1 == minimum_increment);
63
64    g_value_set_int(&value, val_test_set);
65    g_assert(atk_value_set_current_value(ATK_VALUE(obj), &value));
66    _printf_clock_int("atk_value_set_current_value", val_test_set);
67
68    atk_value_get_current_value(ATK_VALUE(obj), &value);
69    current = g_value_get_int(&value);
70    _printf_clock_int("atk_value_get_current_value", current);
71    g_assert(abs(current - val_test_set) < lambda);
72
73    g_value_set_int(&value, 24 * 3600);
74    g_assert(!atk_value_set_current_value(ATK_VALUE(obj), &value));
75
76    eailu_test_code_called = 1;
77 }
78
79 void
80 _init_clock(Evas_Object *win)
81 {
82    Evas_Object *bg, *bx, *cl;
83
84    bg = elm_bg_add(win);
85    elm_win_resize_object_add(win, bg);
86    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
87    evas_object_show(bg);
88
89    bx = elm_box_add(win);
90    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
91    elm_win_resize_object_add(win, bx);
92    evas_object_show(bx);
93
94    cl = elm_clock_add(win);
95    elm_clock_show_seconds_set(cl, EINA_TRUE);
96    elm_box_pack_end(bx, cl);
97    elm_clock_time_set(cl, 4, 44, 22);
98    evas_object_show(cl);
99 }
100
101 EAPI_MAIN int
102 elm_main(int argc, char **argv)
103 {
104    Evas_Object *win;
105
106    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
107    g_assert(win);
108    _init_clock(win);
109    evas_object_show(win);
110    elm_run();
111    elm_shutdown();
112
113    return 0;
114 }
115 ELM_MAIN()