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
16 #include <iostream>
17 #include <string>
18 #include <unistd.h>
19
20 #include "dm_constants.h"
21 #include "dm_timer.h"
22 #include "UTTest_dm_timer.h"
23
24 namespace OHOS {
25 namespace DistributedHardware {
SetUp()26 void TimeHeapTest::SetUp()
27 {
28 }
29
TearDown()30 void TimeHeapTest::TearDown()
31 {
32 }
33
SetUpTestCase()34 void TimeHeapTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void TimeHeapTest::TearDownTestCase()
39 {
40 }
41
42 namespace {
TimeOut(std::string timerName)43 static void TimeOut(std::string timerName) {}
44
45 /**
46 * @tc.name: TimeHeapTest::StartTimer_001
47 * @tc.desc: Timeout event trigger
48 * @tc.type: FUNC
49 * @tc.require: AR000GHSJK
50 */
51 HWTEST_F(TimeHeapTest, StartTimer_001, testing::ext::TestSize.Level0)
52 {
53 std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK);
54 int32_t timeout = 10;
55
56 std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
57 int32_t ret = timer->StartTimer("", timeout, TimeOut);
58 EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
59
60 ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), 400, TimeOut);
61 EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
62
63 ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), -20, TimeOut);
64 EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
65
66 ret = timer->StartTimer(std::string(AUTHENTICATE_TIMEOUT_TASK), timeout, nullptr);
67 EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
68 }
69
70 /**
71 * @tc.name: TimeHeapTest::StartTimer_002
72 * @tc.desc: Timeout event trigger
73 * @tc.type: FUNC
74 * @tc.require: AR000GHSJK
75 */
76 HWTEST_F(TimeHeapTest, StartTimer_002, testing::ext::TestSize.Level0)
77 {
78 std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK);
79 std::string name2 = "test2";
80 int32_t timeOut = 10;
81 int32_t timeOut2 = 40;
82 std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
83 int32_t ret = timer->StartTimer(name, timeOut, TimeOut);
84 EXPECT_EQ(DM_OK, ret);
85
86 ret = timer->StartTimer(name2, timeOut2, TimeOut);
87 EXPECT_EQ(DM_OK, ret);
88 }
89
90 /**
91 * @tc.name: TimeHeapTest::DeleteTimer_001
92 * @tc.desc: Timeout event trigger
93 * @tc.type: FUNC
94 * @tc.require: AR000GHSJK
95 */
96 HWTEST_F(TimeHeapTest, DeleteTimer_001, testing::ext::TestSize.Level0)
97 {
98 std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK);
99 std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
100 int32_t ret = timer->DeleteTimer("");
101 EXPECT_EQ(ERR_DM_INPUT_PARA_INVALID, ret);
102
103 ret = timer->DeleteTimer(name);
104 EXPECT_EQ(ret, ERR_DM_FAILED);
105 }
106
107 /**
108 * @tc.name: TimeHeapTest::DeleteTimer_002
109 * @tc.desc: Timeout event trigger
110 * @tc.type: FUNC
111 * @tc.require: AR000GHSJK
112 */
113 HWTEST_F(TimeHeapTest, DeleteTimer_002, testing::ext::TestSize.Level0)
114 {
115 std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK);
116 int32_t timeOut = 10;
117 std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
118 timer->StartTimer(name, timeOut, TimeOut);
119 int32_t ret = timer->DeleteTimer(name);
120 EXPECT_EQ(DM_OK, ret);
121 }
122
123 /**
124 * @tc.name: TimeHeapTest::DeleteAll_001
125 * @tc.desc: Timeout event trigger
126 * @tc.type: FUNC
127 * @tc.require: AR000GHSJK
128 */
129 HWTEST_F(TimeHeapTest, DeleteAll_001, testing::ext::TestSize.Level0)
130 {
131 std::string name = std::string(AUTHENTICATE_TIMEOUT_TASK);
132 int32_t timeOut = 10;
133 std::shared_ptr<DmTimer> timer = std::make_shared<DmTimer>();
134 int32_t ret = timer->DeleteAll();
135 EXPECT_EQ(DM_OK, ret);
136
137 timer->StartTimer(name, timeOut, TimeOut);
138 ret = timer->DeleteAll();
139 EXPECT_EQ(DM_OK, ret);
140 }
141 }
142 }
143 }
144