Merge branch 'devel/master' into sandbox/dkdk/tizen
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-Watch-Time.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <appcore-watch/watch_app.h>
19 #include <appcore-watch/watch_app_extension.h>
20 #include <dali-test-suite-utils.h>
21 #include <dali/dali.h>
22 #include <stdlib.h>
23 #include "public-api/dali-wearable.h"
24 #define TIMEZONE_BUFFER_MAX 102
25
26 using namespace Dali;
27
28 void utc_dali_watchtime_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_watchtime_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 namespace
39 {
40 struct MyTestApp : public ConnectionTracker
41 {
42   MyTestApp(WatchApplication& app)
43   : initCalled(false),
44     mApplication(app)
45   {
46     mApplication.InitSignal().Connect(this, &MyTestApp::Create);
47   }
48
49   void Create(Application& app)
50   {
51     initCalled = true;
52   }
53
54   void Quit()
55   {
56     mApplication.Quit();
57   }
58
59   // Data
60   bool              initCalled;
61   WatchApplication& mApplication;
62 };
63
64 } // unnamed namespace
65
66 int UtcDaliWatchTimeNew(void)
67 {
68   WatchTime  watchTime;
69   WatchTime* watchTimeRef = &watchTime;
70
71   DALI_TEST_CHECK(watchTimeRef);
72
73   END_TEST;
74 }
75
76 int UtcDaliWatchTimeGetHour(void)
77 {
78   int          ret, hour;
79   WatchTime    watchTime;
80   watch_time_h watch_time = {
81     0,
82   };
83
84   ret = watch_time_get_current_time(&watch_time);
85
86   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
87
88   ret = watch_time_get_hour(watch_time, &hour);
89
90   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
91
92   DALI_TEST_CHECK(watchTime.GetHour() == hour);
93
94   END_TEST;
95 }
96
97 int UtcDaliWatchTimeGetHour24(void)
98 {
99   int          ret, hour24;
100   WatchTime    watchTime;
101   watch_time_h watch_time = {
102     0,
103   };
104
105   ret = watch_time_get_current_time(&watch_time);
106   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
107
108   ret = watch_time_get_hour24(watch_time, &hour24);
109   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
110
111   DALI_TEST_CHECK(watchTime.GetHour24() == hour24);
112
113   END_TEST;
114 }
115
116 int UtcDaliWatchTimeGetMinute(void)
117 {
118   int          ret, minute;
119   WatchTime    watchTime;
120   watch_time_h watch_time = {
121     0,
122   };
123
124   ret = watch_time_get_current_time(&watch_time);
125   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
126
127   ret = watch_time_get_minute(watch_time, &minute);
128   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
129
130   DALI_TEST_CHECK(watchTime.GetMinute() == minute);
131
132   END_TEST;
133 }
134
135 int UtcDaliWatchTimeGetSecond(void)
136 {
137   int          ret, second;
138   WatchTime    watchTime;
139   watch_time_h watch_time = {
140     0,
141   };
142
143   ret = watch_time_get_current_time(&watch_time);
144   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
145
146   ret = watch_time_get_second(watch_time, &second);
147   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
148
149   DALI_TEST_CHECK(watchTime.GetSecond() == second);
150
151   END_TEST;
152 }
153
154 int UtcDaliWatchTimeGetMillisecond(void)
155 {
156   int          ret, millisecond;
157   WatchTime    watchTime;
158   watch_time_h watch_time = {
159     0,
160   };
161
162   ret = watch_time_get_current_time(&watch_time);
163   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
164
165   ret = watch_time_get_millisecond(watch_time, &millisecond);
166   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
167
168   DALI_TEST_CHECK(watchTime.GetMillisecond() == millisecond);
169
170   END_TEST;
171 }
172
173 int UtcDaliWatchTimeGetYear(void)
174 {
175   int          ret, year;
176   WatchTime    watchTime;
177   watch_time_h watch_time = {
178     0,
179   };
180
181   ret = watch_time_get_current_time(&watch_time);
182   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
183
184   ret = watch_time_get_year(watch_time, &year);
185   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
186
187   DALI_TEST_CHECK(watchTime.GetYear() == year);
188
189   END_TEST;
190 }
191
192 int UtcDaliWatchTimeGetMonth(void)
193 {
194   int          ret, month;
195   WatchTime    watchTime;
196   watch_time_h watch_time = {
197     0,
198   };
199
200   ret = watch_time_get_current_time(&watch_time);
201   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
202
203   ret = watch_time_get_month(watch_time, &month);
204   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
205
206   DALI_TEST_CHECK(watchTime.GetMonth() == month);
207
208   END_TEST;
209 }
210
211 int UtcDaliWatchTimeGetDay(void)
212 {
213   int          ret, day;
214   WatchTime    watchTime;
215   watch_time_h watch_time = {
216     0,
217   };
218
219   ret = watch_time_get_current_time(&watch_time);
220   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
221
222   ret = watch_time_get_day(watch_time, &day);
223   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
224
225   DALI_TEST_CHECK(watchTime.GetDay() == day);
226
227   END_TEST;
228 }
229
230 int UtcDaliWatchTimeGetDayOfWeek(void)
231 {
232   int          ret, dayOfWeek;
233   WatchTime    watchTime;
234   watch_time_h watch_time = {
235     0,
236   };
237
238   ret = watch_time_get_current_time(&watch_time);
239   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
240
241   ret = watch_time_get_day_of_week(watch_time, &dayOfWeek);
242   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
243
244   DALI_TEST_CHECK(watchTime.GetDayOfWeek() == dayOfWeek);
245
246   END_TEST;
247 }
248
249 int UtcDaliWatchTimeGetUtcTime(void)
250 {
251   int          ret;
252   struct tm*   utcTime = (struct tm*)calloc(1, sizeof(struct tm));
253   WatchTime    watchTime;
254   watch_time_h watch_time = {
255     0,
256   };
257
258   ret = watch_time_get_current_time(&watch_time);
259   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
260
261   ret = watch_time_get_day(watch_time, utcTime);
262   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
263
264   DALI_TEST_CHECK(watchTime.GetUtcTime().tm_sec == (*utcTime).tm_sec);
265
266   END_TEST;
267 }
268
269 int UtcDaliWatchTimeGetUtcTimeStamp(void)
270 {
271   int          ret;
272   time_t*      timeStamp = (time_t*)calloc(1, sizeof(time_t));
273   WatchTime    watchTime;
274   watch_time_h watch_time = {
275     0,
276   };
277
278   ret = watch_time_get_current_time(&watch_time);
279   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
280
281   ret = watch_time_get_day(watch_time, timeStamp);
282   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
283
284   DALI_TEST_CHECK(watchTime.GetUtcTimeStamp() == *timeStamp);
285
286   END_TEST;
287 }
288
289 int UtcDaliWatchTimeGetTimeZone(void)
290 {
291   int   ret;
292   char* timeZone[TIMEZONE_BUFFER_MAX] = {
293     0,
294   };
295   WatchTime    watchTime;
296   watch_time_h watch_time = {
297     0,
298   };
299
300   ret = watch_time_get_current_time(&watch_time);
301   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
302
303   ret = watch_time_get_day(watch_time, timeZone);
304   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
305
306   DALI_TEST_CHECK(watchTime.GetTimeZone() == timeZone);
307
308   END_TEST;
309 }
310
311 int UtcDaliWatchTimeGetDaylightSavingTimeStatus(void)
312 {
313   int          ret;
314   bool         daylight;
315   WatchTime    watchTime;
316   watch_time_h watch_time = {
317     0,
318   };
319
320   ret = watch_time_get_current_time(&watch_time);
321   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
322
323   ret = watch_time_get_day(watch_time, &daylight);
324   DALI_TEST_CHECK(ret == APP_ERROR_NONE);
325
326   DALI_TEST_CHECK(watchTime.GetDaylightSavingTimeStatus() == daylight);
327
328   END_TEST;
329 }