Merge "custom eail widget implementation" into tizen
[platform/core/uifw/eail.git] / tests / eail_calendar_tc2.c
1 /*
2  * Tested interface: AtkValue
3  *
4  * Tested AtkObject: EailCalendar
5  *
6  * Description: Test AtkValue interface
7  *
8  * Test input: accessible object representing EailCalendar
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("EailCalendar")
19
20 static int year_limit_min = 2000;
21 static int year_limit_max = 2030;
22
23 static void
24 _printf_calendar_int(const char *str, time_t atime)
25 {
26    struct tm tmp;
27
28    localtime_r(&atime, &tmp);
29
30    _printf("[%04d-%02d-%02d] (%s)\n",
31            tmp.tm_year + 1900, tmp.tm_mon + 1, tmp.tm_mday, str);
32 }
33
34 static time_t
35 _val_min(int year)
36 {
37    struct tm minimum;
38
39    memset(&minimum, 0, sizeof(minimum));
40
41    minimum.tm_year = year - 1900;
42    minimum.tm_mon = 0;
43    minimum.tm_mday = 1;
44    minimum.tm_hour = 0;
45    minimum.tm_min = 0;
46    minimum.tm_sec = 0;
47
48    return mktime(&minimum);
49 }
50
51 static int
52 _val_date_cmp(time_t time1, time_t time2)
53 {
54    struct tm tmp1, tmp2;
55
56    localtime_r(&time1, &tmp1);
57    localtime_r(&time2, &tmp2);
58
59    if (tmp1.tm_year == tmp2.tm_year &&
60        tmp1.tm_mon == tmp2.tm_mon &&
61        tmp1.tm_mday == tmp2.tm_mday)
62      {
63         return TRUE;
64      }
65      else
66      {
67         return FALSE;
68      }
69 }
70
71 static time_t
72 _val_max(int year)
73 {
74    struct tm maximum;
75
76    memset(&maximum, 0, sizeof(maximum));
77
78    maximum.tm_year = year - 1900;
79    maximum.tm_mon = 11;
80    maximum.tm_mday = 31;
81    maximum.tm_hour = 23;
82    maximum.tm_min = 59;
83    maximum.tm_sec = 59;
84
85    return mktime(&maximum);
86 }
87
88 static void
89 _init_calendar(Evas_Object *win)
90 {
91    Evas_Object *bg, *cal;
92
93    bg = elm_bg_add(win);
94    elm_win_resize_object_add(win, bg);
95    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
96    evas_object_show(bg);
97
98    cal = elm_calendar_add(win);
99    elm_calendar_min_max_year_set(cal, year_limit_min, year_limit_max);
100    elm_win_resize_object_add(win, cal);
101    evas_object_size_hint_weight_set(cal, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
102    evas_object_show(cal);
103 }
104
105 static void
106 _do_test(AtkObject *obj)
107 {
108    int minimum, maximum, current, minimum_increment;
109    struct tm val_test_set;
110
111    g_assert(ATK_IS_VALUE(obj));
112
113    GValue value = G_VALUE_INIT;
114
115    atk_value_get_minimum_value(ATK_VALUE(obj), &value);
116    minimum = g_value_get_int(&value);
117    _printf_calendar_int("atk_value_get_minimum_value", minimum);
118    g_assert(_val_min(year_limit_min) == minimum);
119
120    atk_value_get_maximum_value(ATK_VALUE(obj), &value);
121    maximum = g_value_get_int(&value);
122    _printf_calendar_int("atk_value_get_maximum_value", maximum);
123    g_assert(_val_max(year_limit_max) == maximum);
124
125    atk_value_get_current_value(ATK_VALUE(obj), &value);
126    current = g_value_get_int(&value);
127    _printf_calendar_int("atk_value_get_current_value", current);
128    g_assert(_val_date_cmp(time(NULL), current));
129
130    atk_value_get_minimum_increment(ATK_VALUE(obj), &value);
131    minimum_increment = g_value_get_int(&value);
132    _printf_calendar_int("atk_value_get_minimum_increment", minimum_increment);
133    g_assert(1 == minimum_increment);
134
135    memset(&val_test_set, 0, sizeof(val_test_set));
136    val_test_set.tm_year = 120;  // 120 + 1900 = 2020 years
137    val_test_set.tm_mon = 2;
138    val_test_set.tm_mday = 15;
139    val_test_set.tm_hour = 7;
140    val_test_set.tm_min = 21;
141    val_test_set.tm_sec = 33;
142
143    g_value_set_int(&value, mktime(&val_test_set));
144    g_assert(atk_value_set_current_value(ATK_VALUE(obj), &value));
145    _printf_calendar_int("atk_value_set_current_value", mktime(&val_test_set));
146
147    atk_value_get_current_value(ATK_VALUE(obj), &value);
148    current = g_value_get_int(&value);
149    _printf_calendar_int("atk_value_get_current_value", current);
150    g_assert(_val_date_cmp(mktime(&val_test_set), current));
151
152    val_test_set.tm_year = 99;  // 99 + 1900 = 1999 years
153    g_value_set_int(&value, mktime(&val_test_set));
154    g_assert(!atk_value_set_current_value(ATK_VALUE(obj), &value));
155
156    val_test_set.tm_year = 131;  // 131 + 1900 = 2031 years
157    g_value_set_int(&value, mktime(&val_test_set));
158    g_assert(!atk_value_set_current_value(ATK_VALUE(obj), &value));
159
160    eailu_test_code_called = 1;
161 }
162
163 EAPI_MAIN int
164 elm_main(int argc, char **argv)
165 {
166    Evas_Object *win;
167
168    win = eailu_create_test_window_with_glib_init(_on_done, _on_focus_in);
169    g_assert(win);
170    _init_calendar(win);
171    evas_object_show(win);
172    elm_run();
173    elm_shutdown();
174
175    return 0;
176 }
177 ELM_MAIN()