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 <cinttypes> 19 #include <cstdint> 20 #include <functional> 21 #include <gtest/gtest.h> 22 #include <string> 23 #include <sys/time.h> 24 #include <thread> 25 #include <vector> 26 27 #include "time_common.h" 28 #include "time_service_client.h" 29 30 namespace OHOS { 31 namespace MiscServices { 32 namespace { 33 constexpr uint64_t NANO_TO_MILESECOND = 100000; 34 } 35 class TimerInfoTest : public ITimerInfo { 36 public: 37 TimerInfoTest(); 38 virtual ~TimerInfoTest(); 39 virtual void OnTrigger() override; 40 virtual void SetType(const int &type) override; 41 virtual void SetRepeat(bool repeat) override; 42 virtual void SetInterval(const uint64_t &interval) override; 43 virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override; 44 void SetCallbackInfo(const std::function<void()> &callBack); 45 46 private: 47 std::function<void()> callBack_ = nullptr; 48 }; 49 TimerInfoTest()50TimerInfoTest::TimerInfoTest() 51 { 52 } 53 ~TimerInfoTest()54TimerInfoTest::~TimerInfoTest() 55 { 56 } 57 OnTrigger()58void TimerInfoTest::OnTrigger() 59 { 60 TIME_HILOGD(TIME_MODULE_SERVICE, "start."); 61 if (callBack_ != nullptr) { 62 TIME_HILOGD(TIME_MODULE_SERVICE, "call back."); 63 callBack_(); 64 } 65 TIME_HILOGD(TIME_MODULE_SERVICE, "end."); 66 } 67 SetCallbackInfo(const std::function<void ()> & callBack)68void TimerInfoTest::SetCallbackInfo(const std::function<void()> &callBack) 69 { 70 callBack_ = callBack; 71 } 72 SetType(const int & _type)73void TimerInfoTest::SetType(const int &_type) 74 { 75 type = _type; 76 } 77 SetRepeat(bool _repeat)78void TimerInfoTest::SetRepeat(bool _repeat) 79 { 80 repeat = _repeat; 81 } SetInterval(const uint64_t & _interval)82void TimerInfoTest::SetInterval(const uint64_t &_interval) 83 { 84 interval = _interval; 85 } SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)86void TimerInfoTest::SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent) 87 { 88 wantAgent = _wantAgent; 89 } 90 } 91 } 92 #endif