1 /*
2  * Copyright (C) 2024 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 <gtest/gtest.h>
16 #include "dhcp_system_timer.h"
17 #include "dhcp_logger.h"
18 #include "common_timer_errors.h"
19 
20 DEFINE_DHCPLOG_DHCP_LABEL("DhcpSystemTimerTest");
21 using namespace testing::ext;
22 using namespace OHOS::DHCP;
23 
24 namespace OHOS {
25 constexpr uint64_t SLEEP_TIME = 2;
26 constexpr int TIMER_TYPE = 1;
27 class DhcpSystemTimerTest : public testing::Test {
28 public:
SetUpTestCase()29     static void SetUpTestCase()
30     {}
TearDownTestCase()31     static void TearDownTestCase()
32     {}
SetUp()33     virtual void SetUp()
34     {}
TearDown()35     virtual void TearDown()
36     {}
37 };
38 
SystemTimerTimeOut()39 void SystemTimerTimeOut()
40 {
41     DHCP_LOGI("SystemTimerTimeOut enter!");
42 }
43 
44 HWTEST_F(DhcpSystemTimerTest, SystemTimer1Test, TestSize.Level1)
45 {
46     DHCP_LOGI("SystemTimer1Test enter!");
47     DhcpSysTimer dhcpSysTimer;
48     dhcpSysTimer.OnTrigger();
49     dhcpSysTimer.SetRepeat(false);
50     dhcpSysTimer.SetInterval(SLEEP_TIME);
51 }
52 
53 HWTEST_F(DhcpSystemTimerTest, SystemTimer2Test, TestSize.Level1)
54 {
55     DHCP_LOGI("SystemTimer2Test enter!");
56     DhcpSysTimer dhcpSysTimer(false, 0, false, false);
57     dhcpSysTimer.SetCallbackInfo(SystemTimerTimeOut);
58     dhcpSysTimer.OnTrigger();
59     dhcpSysTimer.SetType(TIMER_TYPE);
60     dhcpSysTimer.SetRepeat(false);
61     dhcpSysTimer.SetInterval(SLEEP_TIME);
62 }
63 }