• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "time_service_test.h"
16 
17 #include <chrono>
18 #include <climits>
19 #include <cstdlib>
20 #include <ctime>
21 #include <fstream>
22 
23 #include "accesstoken_kit.h"
24 #include "ipc_skeleton.h"
25 #include "json/json.h"
26 #include "nativetoken_kit.h"
27 #include "time_common.h"
28 #include "timer_info_test.h"
29 #include "token_setproc.h"
30 #include "want_agent.h"
31 
32 #define private public
33 #include "time_system_ability.h"
34 
35 namespace {
36 using namespace testing::ext;
37 using namespace OHOS;
38 using namespace OHOS::MiscServices;
39 using namespace std::chrono;
40 using namespace OHOS::Security::AccessToken;
41 
42 static HapPolicyParams g_policyA = {
43     .apl = APL_SYSTEM_CORE,
44     .domain = "test.domain",
45     .permList = {
46         {
47             .permissionName = "ohos.permission.SET_TIME",
48             .bundleName = "ohos.permission_test.demoB",
49             .grantMode = 1,
50             .availableLevel = APL_NORMAL,
51             .label = "label",
52             .labelId = 1,
53             .description = "test",
54             .descriptionId = 1
55         },
56         {
57             .permissionName = "ohos.permission.SET_TIME_ZONE",
58             .bundleName = "ohos.permission_test.demoB",
59             .grantMode = 1,
60             .availableLevel = APL_NORMAL,
61             .label = "label",
62             .labelId = 1,
63             .description = "test",
64             .descriptionId = 1
65         }
66     },
67     .permStateList = {
68         {
69             .permissionName = "ohos.permission.SET_TIME",
70             .isGeneral = true,
71             .resDeviceID = { "local" },
72             .grantStatus = { PermissionState::PERMISSION_GRANTED },
73             .grantFlags = { 1 }
74         },
75         {
76             .permissionName = "ohos.permission.SET_TIME_ZONE",
77             .isGeneral = true,
78             .resDeviceID = { "local" },
79             .grantStatus = { PermissionState::PERMISSION_GRANTED },
80             .grantFlags = { 1 }
81         }
82     }
83 };
84 
85 HapInfoParams g_systemInfoParams = { .userID = 1,
86     .bundleName = "timer",
87     .instIndex = 0,
88     .appIDDesc = "test",
89     .apiVersion = 8,
90     .isSystemApp = true };
91 
92 static HapPolicyParams g_policyB = { .apl = APL_NORMAL, .domain = "test.domain" };
93 
94 HapInfoParams g_notSystemInfoParams = {
95     .userID = 100,
96     .bundleName = "timer",
97     .instIndex = 0,
98     .appIDDesc = "test",
99     .apiVersion = 9,
100     .isSystemApp = false
101 };
102 
103 class TimeClientTest : public testing::Test {
104 public:
105     static void SetUpTestCase(void);
106     static void TearDownTestCase(void);
107     void SetUp();
108     void TearDown();
109     void AddPermission();
110     void DeletePermission();
111 };
112 
AddPermission()113 void TimeClientTest::AddPermission()
114 {
115     AccessTokenIDEx tokenIdEx = { 0 };
116     tokenIdEx = AccessTokenKit::AllocHapToken(g_systemInfoParams, g_policyA);
117     SetSelfTokenID(tokenIdEx.tokenIDEx);
118 }
119 
DeletePermission()120 void TimeClientTest::DeletePermission()
121 {
122     AccessTokenIDEx tokenIdEx = { 0 };
123     tokenIdEx = AccessTokenKit::AllocHapToken(g_notSystemInfoParams, g_policyB);
124     SetSelfTokenID(tokenIdEx.tokenIDEx);
125 }
126 
SetUpTestCase(void)127 void TimeClientTest::SetUpTestCase(void)
128 {
129 }
130 
TearDownTestCase(void)131 void TimeClientTest::TearDownTestCase(void)
132 {
133 }
134 
SetUp(void)135 void TimeClientTest::SetUp(void)
136 {
137 }
138 
TearDown(void)139 void TimeClientTest::TearDown(void)
140 {
141 }
142 
143 /**
144 * @tc.name: SetTime001
145 * @tc.desc: set system time.
146 * @tc.type: FUNC
147 */
148 HWTEST_F(TimeClientTest, SetTime001, TestSize.Level1)
149 {
150     AddPermission();
151     struct timeval currentTime {};
152     gettimeofday(&currentTime, nullptr);
153     int64_t time = (currentTime.tv_sec + 1000) * 1000 + currentTime.tv_usec / 1000;
154     ASSERT_TRUE(time > 0);
155     TIME_HILOGI(TIME_MODULE_CLIENT, "Time now : %{public}" PRId64 "", time);
156     int32_t result = TimeServiceClient::GetInstance()->SetTimeV9(time);
157     EXPECT_TRUE(result == TimeError::E_TIME_OK);
158 }
159 
160 /**
161 * @tc.name: SetTime002
162 * @tc.desc: set system time.
163 * @tc.type: FUNC
164 */
165 HWTEST_F(TimeClientTest, SetTime002, TestSize.Level1)
166 {
167     AddPermission();
168     int32_t result = TimeServiceClient::GetInstance()->SetTimeV9(-1);
169     EXPECT_TRUE(result != TimeError::E_TIME_OK);
170 }
171 
172 /**
173 * @tc.name: SetTime003
174 * @tc.desc: set system time.
175 * @tc.type: FUNC
176 */
177 HWTEST_F(TimeClientTest, SetTime003, TestSize.Level1)
178 {
179     AddPermission();
180     int32_t result = TimeServiceClient::GetInstance()->SetTimeV9(LLONG_MAX);
181     EXPECT_TRUE(result != TimeError::E_TIME_OK);
182 }
183 
184 /**
185 * @tc.name: SetTime004
186 * @tc.desc: set system time.
187 * @tc.type: FUNC
188 */
189 HWTEST_F(TimeClientTest, SetTime004, TestSize.Level1)
190 {
191     DeletePermission();
192     struct timeval currentTime {};
193     gettimeofday(&currentTime, nullptr);
194     int64_t time = (currentTime.tv_sec + 1000) * 1000 + currentTime.tv_usec / 1000;
195     ASSERT_TRUE(time > 0);
196     int32_t result = TimeServiceClient::GetInstance()->SetTimeV9(time);
197     EXPECT_TRUE(result != TimeError::E_TIME_OK);
198     int32_t code;
199     bool ret = TimeServiceClient::GetInstance()->SetTime(time, code);
200     EXPECT_EQ(ret, false);
201     EXPECT_TRUE(code != TimeError::E_TIME_OK);
202 }
203 
204 /**
205 * @tc.name: SetTimeZone001
206 * @tc.desc: set system time zone.
207 * @tc.type: FUNC
208 */
209 HWTEST_F(TimeClientTest, SetTimeZone001, TestSize.Level1)
210 {
211     AddPermission();
212     time_t t;
213     (void)time(&t);
214     TIME_HILOGI(TIME_MODULE_CLIENT, "Time before: %{public}s", asctime(localtime(&t)));
215     auto getCurrentTimeZone = TimeServiceClient::GetInstance()->GetTimeZone();
216     EXPECT_FALSE(getCurrentTimeZone.empty());
217     std::string timeZoneNicosia("Asia/Nicosia");
218     int32_t result = TimeServiceClient::GetInstance()->SetTimeZoneV9(timeZoneNicosia);
219     EXPECT_TRUE(result == TimeError::E_TIME_OK);
220     std::string getTimeZoneNicosia;
221     int32_t getTimeZoneResult = TimeServiceClient::GetInstance()->GetTimeZone(getTimeZoneNicosia);
222     EXPECT_TRUE(getTimeZoneResult == TimeError::E_TIME_OK);;
223     EXPECT_EQ(timeZoneNicosia, getTimeZoneNicosia);
224     int32_t ret = TimeServiceClient::GetInstance()->SetTimeZoneV9(getCurrentTimeZone);
225     EXPECT_TRUE(ret == TimeError::E_TIME_OK);
226 }
227 
228 /**
229 * @tc.name: SetTimeZone002
230 * @tc.desc: set system time zone.
231 * @tc.type: FUNC
232 */
233 HWTEST_F(TimeClientTest, SetTimeZone002, TestSize.Level1)
234 {
235     AddPermission();
236     int32_t result = TimeServiceClient::GetInstance()->SetTimeZoneV9("123");
237     EXPECT_TRUE(result != TimeError::E_TIME_OK);
238 }
239 
240 /**
241 * @tc.name: SetTimeZone003
242 * @tc.desc: set system time zone.
243 * @tc.type: FUNC
244 */
245 HWTEST_F(TimeClientTest, SetTimeZone003, TestSize.Level1)
246 {
247     DeletePermission();
248     int32_t result = TimeServiceClient::GetInstance()->SetTimeZoneV9("Asia/Shanghai");
249     EXPECT_TRUE(result != TimeError::E_TIME_OK);
250     bool ret = TimeServiceClient::GetInstance()->SetTimeZone("Asia/Shanghai");
251     EXPECT_FALSE(ret);
252 }
253 
254 /**
255 * @tc.name: GetWallTimeMs001
256 * @tc.desc: get wall time (ms).
257 * @tc.type: FUNC
258 */
259 HWTEST_F(TimeClientTest, GetWallTimeMs001, TestSize.Level1)
260 {
261     int64_t time;
262     auto errCode = TimeServiceClient::GetInstance()->GetWallTimeMs(time);
263     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
264 }
265 
266 /**
267 * @tc.name: GetWallTimeNs001
268 * @tc.desc: get wall time (ns).
269 * @tc.type: FUNC
270 */
271 HWTEST_F(TimeClientTest, GetWallTimeNs001, TestSize.Level1)
272 {
273     int64_t time;
274     auto errCode = TimeServiceClient::GetInstance()->GetWallTimeNs(time);
275     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
276 }
277 
278 /**
279 * @tc.name: GetBootTimeNs001
280 * @tc.desc: get boot time (ns).
281 * @tc.type: FUNC
282 */
283 HWTEST_F(TimeClientTest, GetBootTimeNs001, TestSize.Level1)
284 {
285     int64_t time;
286     auto errCode = TimeServiceClient::GetInstance()->GetBootTimeNs(time);
287     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
288 }
289 
290 /**
291 * @tc.name: GetBootTimeMs001
292 * @tc.desc: get boot time (ms).
293 * @tc.type: FUNC
294 */
295 HWTEST_F(TimeClientTest, GetBootTimeMs001, TestSize.Level1)
296 {
297     int64_t time;
298     auto errCode = TimeServiceClient::GetInstance()->GetBootTimeMs(time);
299     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
300 }
301 
302 /**
303 * @tc.name: GetMonotonicTimeMs001
304 * @tc.desc: get monotonic time (ms).
305 * @tc.type: FUNC
306 */
307 HWTEST_F(TimeClientTest, GetMonotonicTimeMs001, TestSize.Level1)
308 {
309     int64_t time;
310     auto errCode = TimeServiceClient::GetInstance()->GetMonotonicTimeMs(time);
311     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
312 }
313 
314 /**
315 * @tc.name: GetMonotonicTimeNs001
316 * @tc.desc: get monotonic time (ns).
317 * @tc.type: FUNC
318 */
319 HWTEST_F(TimeClientTest, GetMonotonicTimeNs001, TestSize.Level1)
320 {
321     int64_t time;
322     auto errCode = TimeServiceClient::GetInstance()->GetMonotonicTimeNs(time);
323     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
324 }
325 
326 /**
327 * @tc.name: GetThreadTimeMs001
328 * @tc.desc: get thread time (ms).
329 * @tc.type: FUNC
330 */
331 HWTEST_F(TimeClientTest, GetThreadTimeMs001, TestSize.Level1)
332 {
333     int64_t time;
334     auto errCode = TimeServiceClient::GetInstance()->GetThreadTimeMs(time);
335     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
336 }
337 
338 /**
339 * @tc.name: GetThreadTimeNs001
340 * @tc.desc: get thread time (ns).
341 * @tc.type: FUNC
342 */
343 HWTEST_F(TimeClientTest, GetThreadTimeNs001, TestSize.Level1)
344 {
345     int64_t time;
346     auto errCode = TimeServiceClient::GetInstance()->GetThreadTimeNs(time);
347     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
348 }
349 
350 /**
351 * @tc.name: CreateTimer001
352 * @tc.desc: Create system timer.
353 * @tc.type: FUNC
354 */
355 HWTEST_F(TimeClientTest, CreateTimer001, TestSize.Level1)
356 {
357     AddPermission();
358     uint64_t timerId = 0;
359     TimeSystemAbility::GetInstance()->timerManagerHandler_ = nullptr;
360     auto ret = TimeServiceClient::GetInstance()->StartTimerV9(timerId, 5);
361     EXPECT_TRUE(ret != TimeError::E_TIME_OK);
362     ret = TimeServiceClient::GetInstance()->StopTimerV9(timerId);
363     EXPECT_TRUE(ret != TimeError::E_TIME_OK);
364     ret = TimeServiceClient::GetInstance()->DestroyTimerV9(timerId);
365     EXPECT_TRUE(ret != TimeError::E_TIME_OK);
366 }
367 
368 /**
369 * @tc.name: CreateTimer002
370 * @tc.desc: Create system timer.
371 * @tc.type: FUNC
372 */
373 HWTEST_F(TimeClientTest, CreateTimer002, TestSize.Level1)
374 {
375     AddPermission();
376     auto timerInfo = std::make_shared<TimerInfoTest>();
377     timerInfo->SetType(1);
378     timerInfo->SetRepeat(false);
379     timerInfo->SetInterval(0);
380     timerInfo->SetWantAgent(nullptr);
381     timerInfo->SetCallbackInfo(TimeOutCallback1);
382     uint64_t timerId;
383     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
384     TIME_HILOGI(TIME_MODULE_CLIENT, "timerId now : %{public}" PRId64 "", timerId);
385     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
386     auto ret = TimeServiceClient::GetInstance()->StartTimerV9(timerId, 2000);
387     EXPECT_TRUE(ret == TimeError::E_TIME_OK);
388     TimeSystemAbility::GetInstance()->timerManagerHandler_ = nullptr;
389     ret = TimeServiceClient::GetInstance()->StopTimerV9(timerId);
390     EXPECT_TRUE(ret == TimeError::E_TIME_OK);
391     ret = TimeServiceClient::GetInstance()->DestroyTimerV9(timerId);
392     EXPECT_TRUE(ret == TimeError::E_TIME_OK);
393 }
394 
395 /**
396 * @tc.name: CreateTimer003
397 * @tc.desc: Create system timer.
398 * @tc.type: FUNC
399 */
400 HWTEST_F(TimeClientTest, CreateTimer003, TestSize.Level1)
401 {
402     AddPermission();
403     auto timerInfo = std::make_shared<TimerInfoTest>();
404     timerInfo->SetType(1);
405     timerInfo->SetRepeat(false);
406     timerInfo->SetInterval(0);
407     auto ability = std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent>();
408     timerInfo->SetWantAgent(ability);
409     timerInfo->SetCallbackInfo(TimeOutCallback1);
410     uint64_t timerId;
411     TimeSystemAbility::GetInstance()->timerManagerHandler_ = nullptr;
412     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
413     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
414 }
415 
416 /**
417 * @tc.name: CreateTimer004
418 * @tc.desc: Create system timer.
419 * @tc.type: FUNC
420 */
421 HWTEST_F(TimeClientTest, CreateTimer004, TestSize.Level1)
422 {
423     AddPermission();
424     g_data1 = 0;
425     auto timerInfo = std::make_shared<TimerInfoTest>();
426     timerInfo->SetType(1);
427     timerInfo->SetRepeat(false);
428     timerInfo->SetInterval(0);
429     timerInfo->SetWantAgent(nullptr);
430     timerInfo->SetCallbackInfo(TimeOutCallback1);
431     uint64_t timerId;
432     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
433     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
434     auto bootTimeNano = system_clock::now().time_since_epoch().count();
435     auto bootTimeMilli = bootTimeNano / NANO_TO_MILESECOND;
436     errCode = TimeServiceClient::GetInstance()->StartTimerV9(timerId, bootTimeMilli + 2000);
437     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
438     TimeSystemAbility::GetInstance()->timerManagerHandler_ = nullptr;
439     errCode = TimeServiceClient::GetInstance()->DestroyTimerV9(timerId);
440     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
441     EXPECT_TRUE(g_data1 == 0);
442     errCode = TimeServiceClient::GetInstance()->StopTimerV9(timerId);
443     EXPECT_TRUE(errCode != TimeError::E_TIME_OK);
444 }
445 
446 /**
447 * @tc.name: CreateTimer005
448 * @tc.desc: Create system timer.
449 * @tc.type: FUNC
450 */
451 HWTEST_F(TimeClientTest, CreateTimer005, TestSize.Level1)
452 {
453     AddPermission();
454     g_data1 = 1;
455     auto timerInfo = std::make_shared<TimerInfoTest>();
456     timerInfo->SetType(0);
457     timerInfo->SetRepeat(false);
458     timerInfo->SetInterval(0);
459     timerInfo->SetWantAgent(nullptr);
460     timerInfo->SetCallbackInfo(TimeOutCallback1);
461 
462     struct timeval timeOfDay {};
463     gettimeofday(&timeOfDay, NULL);
464     int64_t currentTime = (timeOfDay.tv_sec + 100) * 1000 + timeOfDay.tv_usec / 1000;
465     if (currentTime < 0) {
466         currentTime = 0;
467     }
468     uint64_t timerId;
469     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
470     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
471 
472     errCode = TimeServiceClient::GetInstance()->StartTimerV9(timerId, static_cast<uint64_t>(currentTime));
473     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
474     errCode = TimeServiceClient::GetInstance()->DestroyTimerV9(timerId);
475     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
476     EXPECT_TRUE(g_data1 == 1);
477     errCode = TimeServiceClient::GetInstance()->StopTimerV9(timerId);
478     EXPECT_TRUE(errCode != TimeError::E_TIME_OK);
479 }
480 
481 /**
482 * @tc.name: CreateTimer006
483 * @tc.desc: Create system timer.
484 * @tc.type: FUNC
485 */
486 HWTEST_F(TimeClientTest, CreateTimer006, TestSize.Level1)
487 {
488     AddPermission();
489     uint64_t timerId;
490     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(nullptr, timerId);
491     uint64_t ret = 0;
492     EXPECT_TRUE(errCode != TimeError::E_TIME_OK);
493     EXPECT_EQ(timerId, ret);
494 }
495 
496 /**
497 * @tc.name: CreateTimer007
498 * @tc.desc: Create system timer.
499 * @tc.type: FUNC
500 */
501 HWTEST_F(TimeClientTest, CreateTimer007, TestSize.Level1)
502 {
503     DeletePermission();
504     auto timerInfo = std::make_shared<TimerInfoTest>();
505     timerInfo->SetType(0);
506     timerInfo->SetRepeat(false);
507     timerInfo->SetCallbackInfo(TimeOutCallback1);
508 
509     struct timeval timeOfDay {};
510     gettimeofday(&timeOfDay, nullptr);
511     int64_t currentTime = (timeOfDay.tv_sec + 100) * 1000 + timeOfDay.tv_usec / 1000;
512     if (currentTime < 0) {
513         currentTime = 0;
514     }
515     uint64_t timerId = TimeServiceClient::GetInstance()->CreateTimer(timerInfo);
516     uint64_t ret = 0;
517     EXPECT_EQ(timerId, ret);
518     auto codeCreateTimer = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
519     EXPECT_TRUE(codeCreateTimer != TimeError::E_TIME_OK);
520     auto codeStartTimer = TimeServiceClient::GetInstance()->StartTimerV9(timerId, currentTime + 1000);
521     EXPECT_TRUE(codeStartTimer != TimeError::E_TIME_OK);
522     auto codeStopTimer = TimeServiceClient::GetInstance()->StopTimerV9(timerId);
523     EXPECT_TRUE(codeStopTimer != TimeError::E_TIME_OK);
524     auto codeDestroyTimer = TimeServiceClient::GetInstance()->DestroyTimerV9(timerId);
525     EXPECT_TRUE(codeDestroyTimer != TimeError::E_TIME_OK);
526 }
527 
528 /**
529 * @tc.name: StartTimer001
530 * @tc.desc: Start system timer.
531 * @tc.type: FUNC
532 */
533 HWTEST_F(TimeClientTest, StartTimer001, TestSize.Level1)
534 {
535     AddPermission();
536     g_data1 = 0;
537     uint64_t timerId;
538     auto timerInfo = std::make_shared<TimerInfoTest>();
539     timerInfo->SetType(1<<2);
540     timerInfo->SetRepeat(false);
541     timerInfo->SetCallbackInfo(TimeOutCallback1);
542     auto wantAgent = std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent>();
543     timerInfo->SetWantAgent(wantAgent);
544     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
545     uint64_t ret = 0;
546     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
547     EXPECT_NE(timerId, ret);
548     auto triggerTime = TimeServiceClient::GetInstance()->GetWallTimeMs();
549     TimeServiceClient::GetInstance()->StartTimerV9(timerId, triggerTime + 1000);
550     sleep(2);
551     EXPECT_EQ(g_data1, 1);
552     TimeServiceClient::GetInstance()->DestroyTimerV9(timerId);
553 }
554 
555 /**
556 * @tc.name: StartTimer002
557 * @tc.desc: Start system timer.
558 * @tc.type: FUNC
559 */
560 HWTEST_F(TimeClientTest, StartTimer002, TestSize.Level1)
561 {
562     AddPermission();
563     uint64_t timerId;
564     auto timerInfo = std::make_shared<TimerInfoTest>();
565     timerInfo->SetType(1<<2);
566     timerInfo->SetRepeat(false);
567     auto wantAgent = std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent>();
568     timerInfo->SetWantAgent(wantAgent);
569     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
570     uint64_t ret = 0;
571     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
572     EXPECT_NE(timerId, ret);
573     auto triggerTime = TimeServiceClient::GetInstance()->GetWallTimeMs();
574     auto result = TimeServiceClient::GetInstance()->StartTimerV9(timerId, triggerTime + 1000);
575     EXPECT_EQ(result, TimeError::E_TIME_OK);
576     TimeServiceClient::GetInstance()->DestroyTimerV9(timerId);
577 }
578 
579 /**
580 * @tc.name: StartTimer003
581 * @tc.desc: Start system timer.
582 * @tc.type: FUNC
583 */
584 HWTEST_F(TimeClientTest, StartTimer003, TestSize.Level1)
585 {
586     AddPermission();
587     g_data1 = 0;
588     uint64_t timerId;
589     auto timerInfo = std::make_shared<TimerInfoTest>();
590     timerInfo->SetType(1<<2 | 1<<1);
591     timerInfo->SetRepeat(true);
592     timerInfo->SetInterval(1000);
593     timerInfo->SetCallbackInfo(TimeOutCallback1);
594     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
595     uint64_t ret = 0;
596     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
597     EXPECT_NE(timerId, ret);
598     auto triggerTime = TimeServiceClient::GetInstance()->GetWallTimeMs();
599     TimeServiceClient::GetInstance()->StartTimerV9(timerId, triggerTime + 1000);
600     sleep(3);
601     EXPECT_GT(g_data1, 1);
602 }
603 
604 /**
605 * @tc.name: StartTimer004
606 * @tc.desc: Start system timer.
607 * @tc.type: FUNC
608 */
609 HWTEST_F(TimeClientTest, StartTimer004, TestSize.Level1)
610 {
611     AddPermission();
612     g_data1 = 0;
613     uint64_t timerId;
614     auto timerInfo = std::make_shared<TimerInfoTest>();
615     timerInfo->SetType(4);
616     timerInfo->SetRepeat(true);
617     timerInfo->SetInterval(1000);
618     timerInfo->SetCallbackInfo(TimeOutCallback1);
619     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
620     uint64_t ret = 0;
621     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
622     EXPECT_NE(timerId, ret);
623     auto triggerTime = TimeServiceClient::GetInstance()->GetWallTimeMs();
624     TimeServiceClient::GetInstance()->StartTimerV9(timerId, triggerTime + 1000);
625     sleep(3);
626     EXPECT_GT(g_data1, 1);
627 }
628 
629 /**
630 * @tc.name: StartTimer005
631 * @tc.desc: Start system timer.
632 * @tc.type: FUNC
633 */
634 HWTEST_F(TimeClientTest, StartTimer005, TestSize.Level1)
635 {
636     AddPermission();
637     g_data1 = 0;
638     uint64_t timerId;
639     auto timerInfo = std::make_shared<TimerInfoTest>();
640     timerInfo->SetType(4);
641     timerInfo->SetRepeat(false);
642     timerInfo->SetCallbackInfo(TimeOutCallback1);
643     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
644     uint64_t ret = 0;
645     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
646     EXPECT_NE(timerId, ret);
647     auto triggerTime = TimeServiceClient::GetInstance()->GetWallTimeMs();
648     TimeServiceClient::GetInstance()->StartTimerV9(timerId, triggerTime + 2000);
649     pid_t uid = IPCSkeleton::GetCallingUid();
650     TimeSystemAbility::GetInstance()->timerManagerHandler_ = nullptr;
651     TimeServiceClient::GetInstance()->ProxyTimer(uid, true, true);
652     sleep(2);
653     TimeServiceClient::GetInstance()->ProxyTimer(uid, false, true);
654     EXPECT_GT(g_data1, 0);
655 }
656 
657 /**
658 * @tc.name: StartTimer006
659 * @tc.desc: Start system timer.
660 * @tc.type: FUNC
661 */
662 HWTEST_F(TimeClientTest, StartTimer006, TestSize.Level1)
663 {
664     AddPermission();
665     g_data1 = 0;
666     uint64_t timerId;
667     auto timerInfo = std::make_shared<TimerInfoTest>();
668     timerInfo->SetType(1<<2);
669     timerInfo->SetRepeat(false);
670     timerInfo->SetCallbackInfo(TimeOutCallback1);
671     auto errCode = TimeServiceClient::GetInstance()->CreateTimerV9(timerInfo, timerId);
672     uint64_t ret = 0;
673     EXPECT_TRUE(errCode == TimeError::E_TIME_OK);
674     EXPECT_NE(timerId, ret);
675     auto triggerTime = TimeServiceClient::GetInstance()->GetWallTimeMs();
676     TimeServiceClient::GetInstance()->StartTimerV9(timerId, triggerTime + 2000);
677     pid_t uid = IPCSkeleton::GetCallingUid();
678     TimeServiceClient::GetInstance()->ProxyTimer(uid, true, true);
679     sleep(2);
680     TimeSystemAbility::GetInstance()->timerManagerHandler_ = nullptr;
681     TimeServiceClient::GetInstance()->ResetAllProxy();
682     EXPECT_GT(g_data1, 0);
683 }
684 } // namespace