[3.0] Add WatchTime APIs
[platform/core/uifw/dali-adaptor.git] / automated-tests / src / dali-adaptor / utc-Dali-Watch-Time.cpp
1 /*
2  * Copyright (c) 2017 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 <dali/dali.h>
19 #include <dali-test-suite-utils.h>
20 #include "public-api/dali-wearable.h"
21 #include <appcore-watch/watch_app.h>
22 #include <appcore-watch/watch_app_extension.h>
23 #include <stdlib.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
41 struct MyTestApp : public ConnectionTracker
42 {
43   MyTestApp( WatchApplication& app)
44   : initCalled( false ),
45     mApplication( app )
46   {
47     mApplication.InitSignal().Connect( this, &MyTestApp::Create );
48   }
49
50   void Create(Application& app)
51   {
52     initCalled = true;
53   }
54
55   void Quit()
56   {
57     mApplication.Quit();
58   }
59
60   // Data
61   bool initCalled;
62   WatchApplication&  mApplication;
63 };
64
65 } // unnamed namespace
66
67 int UtcDaliWatchTimeNew(void)
68 {
69   WatchTime watchTime;
70   WatchTime *watchTimeRef = &watchTime;
71
72   DALI_TEST_CHECK( watchTimeRef );
73
74   END_TEST;
75 }
76
77 int UtcDaliWatchTimeGetHour(void)
78 {
79   int ret, hour;
80   WatchTime watchTime;
81   watch_time_h watch_time = {0,};
82
83   ret = watch_time_get_current_time(&watch_time);
84
85   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
86
87   ret = watch_time_get_hour(watch_time, &hour);
88
89   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
90
91   DALI_TEST_CHECK( watchTime.GetHour() == hour );
92
93   END_TEST;
94 }
95
96 int UtcDaliWatchTimeGetHour24(void)
97 {
98   int ret, hour24;
99   WatchTime watchTime;
100   watch_time_h watch_time = {0,};
101
102   ret = watch_time_get_current_time(&watch_time);
103   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
104
105   ret = watch_time_get_hour24(watch_time, &hour24);
106   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
107
108   DALI_TEST_CHECK( watchTime.GetHour24() == hour24 );
109
110   END_TEST;
111 }
112
113 int UtcDaliWatchTimeGetMinute(void)
114 {
115   int ret, minute;
116   WatchTime watchTime;
117   watch_time_h watch_time = {0,};
118
119   ret = watch_time_get_current_time(&watch_time);
120   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
121
122   ret = watch_time_get_minute(watch_time, &minute);
123   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
124
125   DALI_TEST_CHECK( watchTime.GetMinute() == minute );
126
127   END_TEST;
128 }
129
130 int UtcDaliWatchTimeGetSecond(void)
131 {
132   int ret, second;
133   WatchTime watchTime;
134   watch_time_h watch_time = {0,};
135
136   ret = watch_time_get_current_time(&watch_time);
137   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
138
139   ret = watch_time_get_second(watch_time, &second);
140   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
141
142   DALI_TEST_CHECK( watchTime.GetSecond() == second );
143
144   END_TEST;
145 }
146
147 int UtcDaliWatchTimeGetMillisecond(void)
148 {
149   int ret, millisecond;
150   WatchTime watchTime;
151   watch_time_h watch_time = {0,};
152
153   ret = watch_time_get_current_time(&watch_time);
154   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
155
156   ret = watch_time_get_millisecond(watch_time, &millisecond);
157   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
158
159   DALI_TEST_CHECK( watchTime.GetMillisecond() == millisecond );
160
161   END_TEST;
162 }
163
164 int UtcDaliWatchTimeGetYear(void)
165 {
166   int ret, year;
167   WatchTime watchTime;
168   watch_time_h watch_time = {0,};
169
170   ret = watch_time_get_current_time(&watch_time);
171   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
172
173   ret = watch_time_get_year(watch_time, &year);
174   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
175
176   DALI_TEST_CHECK( watchTime.GetYear() == year );
177
178   END_TEST;
179 }
180
181 int UtcDaliWatchTimeGetMonth(void)
182 {
183   int ret, month;
184   WatchTime watchTime;
185   watch_time_h watch_time = {0,};
186
187   ret = watch_time_get_current_time(&watch_time);
188   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
189
190   ret = watch_time_get_month(watch_time, &month);
191   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
192
193   DALI_TEST_CHECK( watchTime.GetMonth() == month );
194
195   END_TEST;
196 }
197
198 int UtcDaliWatchTimeGetDay(void)
199 {
200   int ret, day;
201   WatchTime watchTime;
202   watch_time_h watch_time = {0,};
203
204   ret = watch_time_get_current_time(&watch_time);
205   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
206
207   ret = watch_time_get_day(watch_time, &day);
208   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
209
210   DALI_TEST_CHECK( watchTime.GetDay() == day );
211
212   END_TEST;
213 }
214
215 int UtcDaliWatchTimeGetDayOfWeek(void)
216 {
217   int ret, dayOfWeek;
218   WatchTime watchTime;
219   watch_time_h watch_time = {0,};
220
221   ret = watch_time_get_current_time(&watch_time);
222   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
223
224   ret = watch_time_get_day_of_week(watch_time, &dayOfWeek);
225   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
226
227   DALI_TEST_CHECK( watchTime.GetDayOfWeek() == dayOfWeek );
228
229   END_TEST;
230 }
231
232 int UtcDaliWatchTimeGetUtcTime(void)
233 {
234   int ret;
235   struct tm *utcTime = (struct tm *)calloc( 1, sizeof( struct tm ) );
236   WatchTime watchTime;
237   watch_time_h watch_time = {0,};
238
239   ret = watch_time_get_current_time(&watch_time);
240   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
241
242   ret = watch_time_get_day(watch_time, utcTime);
243   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
244
245   DALI_TEST_CHECK( watchTime.GetUtcTime().tm_sec == (*utcTime).tm_sec );
246
247   END_TEST;
248 }
249
250 int UtcDaliWatchTimeGetUtcTimeStamp(void)
251 {
252   int ret;
253   time_t *timeStamp = (time_t *)calloc( 1, sizeof( time_t ) );
254   WatchTime watchTime;
255   watch_time_h watch_time = {0,};
256
257   ret = watch_time_get_current_time(&watch_time);
258   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
259
260   ret = watch_time_get_day(watch_time, timeStamp);
261   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
262
263   DALI_TEST_CHECK( watchTime.GetUtcTimeStamp() == *timeStamp );
264
265   END_TEST;
266 }
267
268 int UtcDaliWatchTimeGetTimeZone(void)
269 {
270   int ret;
271   char *timeZone[TIMEZONE_BUFFER_MAX] = {0,};
272   WatchTime watchTime;
273   watch_time_h watch_time = {0,};
274
275   ret = watch_time_get_current_time(&watch_time);
276   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
277
278   ret = watch_time_get_day(watch_time, timeZone);
279   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
280
281   DALI_TEST_CHECK( watchTime.GetTimeZone() == timeZone );
282
283   END_TEST;
284 }
285
286 int UtcDaliWatchTimeGetDaylightSavingTimeStatus(void)
287 {
288   int ret;
289   bool daylight;
290   WatchTime watchTime;
291   watch_time_h watch_time = {0,};
292
293   ret = watch_time_get_current_time(&watch_time);
294   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
295
296   ret = watch_time_get_day(watch_time, &daylight);
297   DALI_TEST_CHECK( ret == APP_ERROR_NONE );
298
299   DALI_TEST_CHECK( watchTime.GetDaylightSavingTimeStatus() == daylight );
300
301   END_TEST;
302 }