• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #ifndef OHOS_GLOBAL_TIME_SERVICE_TEST_H
16 #define OHOS_GLOBAL_TIME_SERVICE_TEST_H
17 
18 #include <cstdint>
19 #include <functional>
20 #include <gtest/gtest.h>
21 #include <inttypes.h>
22 #include <string>
23 #include <sys/time.h>
24 #include <thread>
25 #include <vector>
26 
27 #include "time_common.h"
28 
29 #define private public
30 #include "time_service_client.h"
31 
32 namespace OHOS {
33 namespace MiscServices {
34 namespace {
35 constexpr uint64_t NANO_TO_MILESECOND = 1000000;
36 constexpr uint64_t NANO_TO_SECOND = 1000000000;
37 }
38 class TimerInfoTest : public ITimerInfo {
39 public:
40     TimerInfoTest();
41     virtual ~TimerInfoTest();
42     virtual void OnTrigger() override;
43     virtual void SetType(const int &type) override;
44     virtual void SetRepeat(bool repeat) override;
45     virtual void SetInterval(const uint64_t &interval) override;
46     void SetDisposable(const bool &disposable);
47     virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override;
48     void SetCallbackInfo(const std::function<void()> &callBack);
49 
50 private:
51     std::function<void()> callBack_ = nullptr;
52 };
53 
TimerInfoTest()54 TimerInfoTest::TimerInfoTest()
55 {
56 }
57 
~TimerInfoTest()58 TimerInfoTest::~TimerInfoTest()
59 {
60 }
61 
OnTrigger()62 void TimerInfoTest::OnTrigger()
63 {
64     TIME_HILOGD(TIME_MODULE_SERVICE, "start.");
65     if (callBack_ != nullptr) {
66         TIME_HILOGD(TIME_MODULE_SERVICE, "call back.");
67         callBack_();
68     }
69     TIME_HILOGD(TIME_MODULE_SERVICE, "end.");
70 }
71 
SetCallbackInfo(const std::function<void ()> & callBack)72 void TimerInfoTest::SetCallbackInfo(const std::function<void()> &callBack)
73 {
74     callBack_ = callBack;
75 }
76 
SetType(const int & _type)77 void TimerInfoTest::SetType(const int &_type)
78 {
79     type = _type;
80 }
81 
SetRepeat(bool _repeat)82 void TimerInfoTest::SetRepeat(bool _repeat)
83 {
84     repeat = _repeat;
85 }
86 
SetInterval(const uint64_t & _interval)87 void TimerInfoTest::SetInterval(const uint64_t &_interval)
88 {
89     interval = _interval;
90 }
91 
SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)92 void TimerInfoTest::SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)
93 {
94     wantAgent = _wantAgent;
95 }
96 
SetDisposable(const bool & _disposable)97 void TimerInfoTest::SetDisposable(const bool &_disposable)
98 {
99     disposable = _disposable;
100 }
101 
102 } // namespace MiscServices
103 } // namespace OHOS
104 #endif