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