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 = 100000; 36 } 37 class TimerInfoTest : public ITimerInfo { 38 public: 39 TimerInfoTest(); 40 virtual ~TimerInfoTest(); 41 virtual void OnTrigger() override; 42 virtual void SetType(const int &type) override; 43 virtual void SetRepeat(bool repeat) override; 44 virtual void SetInterval(const uint64_t &interval) override; 45 void SetDisposable(const bool &disposable); 46 virtual void SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent) override; 47 void SetCallbackInfo(const std::function<void()> &callBack); 48 49 private: 50 std::function<void()> callBack_ = nullptr; 51 }; 52 TimerInfoTest()53TimerInfoTest::TimerInfoTest() 54 { 55 } 56 ~TimerInfoTest()57TimerInfoTest::~TimerInfoTest() 58 { 59 } 60 OnTrigger()61void TimerInfoTest::OnTrigger() 62 { 63 TIME_HILOGD(TIME_MODULE_SERVICE, "start."); 64 if (callBack_ != nullptr) { 65 TIME_HILOGD(TIME_MODULE_SERVICE, "call back."); 66 callBack_(); 67 } 68 TIME_HILOGD(TIME_MODULE_SERVICE, "end."); 69 } 70 SetCallbackInfo(const std::function<void ()> & callBack)71void TimerInfoTest::SetCallbackInfo(const std::function<void()> &callBack) 72 { 73 callBack_ = callBack; 74 } 75 SetType(const int & _type)76void TimerInfoTest::SetType(const int &_type) 77 { 78 type = _type; 79 } 80 SetRepeat(bool _repeat)81void TimerInfoTest::SetRepeat(bool _repeat) 82 { 83 repeat = _repeat; 84 } 85 SetInterval(const uint64_t & _interval)86void TimerInfoTest::SetInterval(const uint64_t &_interval) 87 { 88 interval = _interval; 89 } 90 SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent)91void TimerInfoTest::SetWantAgent(std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> _wantAgent) 92 { 93 wantAgent = _wantAgent; 94 } 95 SetDisposable(const bool & _disposable)96void TimerInfoTest::SetDisposable(const bool &_disposable) 97 { 98 disposable = _disposable; 99 } 100 101 } // namespace MiscServices 102 } // namespace OHOS 103 #endif