1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci*/
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include <fstream>
17c29fa5a6Sopenharmony_ci
18c29fa5a6Sopenharmony_ci#include <gtest/gtest.h>
19c29fa5a6Sopenharmony_ci
20c29fa5a6Sopenharmony_ci#include "mmi_log.h"
21c29fa5a6Sopenharmony_ci#include "uds_server.h"
22c29fa5a6Sopenharmony_ci#include "timer_manager.h"
23c29fa5a6Sopenharmony_ci
24c29fa5a6Sopenharmony_cinamespace OHOS {
25c29fa5a6Sopenharmony_cinamespace MMI {
26c29fa5a6Sopenharmony_cinamespace {
27c29fa5a6Sopenharmony_ciusing namespace testing::ext;
28c29fa5a6Sopenharmony_ciconstexpr int32_t errCode { -1 };
29c29fa5a6Sopenharmony_ciconstexpr int32_t rationId { 0 };
30c29fa5a6Sopenharmony_ciconstexpr int32_t rightId { 1 };
31c29fa5a6Sopenharmony_ci} // namespace
32c29fa5a6Sopenharmony_ci
33c29fa5a6Sopenharmony_ciclass TimerManagerTest : public testing::Test {
34c29fa5a6Sopenharmony_cipublic:
35c29fa5a6Sopenharmony_ci    static void SetUpTestCase(void) {}
36c29fa5a6Sopenharmony_ci    static void TearDownTestCase(void) {}
37c29fa5a6Sopenharmony_ci};
38c29fa5a6Sopenharmony_ci
39c29fa5a6Sopenharmony_civoid AddTimerCallback()
40c29fa5a6Sopenharmony_ci{
41c29fa5a6Sopenharmony_ci    return;
42c29fa5a6Sopenharmony_ci}
43c29fa5a6Sopenharmony_ci
44c29fa5a6Sopenharmony_ci/**
45c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ManagerTimer_001
46c29fa5a6Sopenharmony_ci * @tc.desc: Test the function AddTimer
47c29fa5a6Sopenharmony_ci * @tc.type: FUNC
48c29fa5a6Sopenharmony_ci * @tc.require:
49c29fa5a6Sopenharmony_ci */
50c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ManagerTimer_001, TestSize.Level1)
51c29fa5a6Sopenharmony_ci{
52c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
53c29fa5a6Sopenharmony_ci    int32_t repeatCount = 3;
54c29fa5a6Sopenharmony_ci    int32_t intervalMs = 1000;
55c29fa5a6Sopenharmony_ci    int32_t timerld = TimerMgr->AddTimer(intervalMs, repeatCount, AddTimerCallback);
56c29fa5a6Sopenharmony_ci    EXPECT_EQ(timerld, rightId);
57c29fa5a6Sopenharmony_ci}
58c29fa5a6Sopenharmony_ci
59c29fa5a6Sopenharmony_ci/**
60c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ManagerTimer_002
61c29fa5a6Sopenharmony_ci * @tc.desc: Test the function RemoveTimer
62c29fa5a6Sopenharmony_ci * @tc.type: FUNC
63c29fa5a6Sopenharmony_ci * @tc.require:
64c29fa5a6Sopenharmony_ci */
65c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ManagerTimer_002, TestSize.Level1)
66c29fa5a6Sopenharmony_ci{
67c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
68c29fa5a6Sopenharmony_ci    int32_t repeatCount = 3;
69c29fa5a6Sopenharmony_ci    int32_t intervalMs = 1000;
70c29fa5a6Sopenharmony_ci    int32_t timerld = TimerMgr->AddTimer(intervalMs, repeatCount, AddTimerCallback);
71c29fa5a6Sopenharmony_ci    ASSERT_EQ(TimerMgr->RemoveTimer(timerld), rationId);
72c29fa5a6Sopenharmony_ci}
73c29fa5a6Sopenharmony_ci
74c29fa5a6Sopenharmony_ci/**
75c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ManagerTimer_003
76c29fa5a6Sopenharmony_ci * @tc.desc: Test the function ResetTimer
77c29fa5a6Sopenharmony_ci * @tc.type: FUNC
78c29fa5a6Sopenharmony_ci * @tc.require:
79c29fa5a6Sopenharmony_ci */
80c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ManagerTimer_003, TestSize.Level1)
81c29fa5a6Sopenharmony_ci{
82c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
83c29fa5a6Sopenharmony_ci    int32_t repeatCount = 3;
84c29fa5a6Sopenharmony_ci    int32_t intervalMs = 1000;
85c29fa5a6Sopenharmony_ci    int32_t timerld = TimerMgr->AddTimer(intervalMs, repeatCount, AddTimerCallback);
86c29fa5a6Sopenharmony_ci    int32_t result = TimerMgr->ResetTimer(timerld);
87c29fa5a6Sopenharmony_ci    EXPECT_EQ(result, rationId);
88c29fa5a6Sopenharmony_ci}
89c29fa5a6Sopenharmony_ci
90c29fa5a6Sopenharmony_ci/**
91c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ManagerTimer_004
92c29fa5a6Sopenharmony_ci * @tc.desc: Test the function IsExist
93c29fa5a6Sopenharmony_ci * @tc.type: FUNC
94c29fa5a6Sopenharmony_ci * @tc.require:
95c29fa5a6Sopenharmony_ci */
96c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ManagerTimer_004, TestSize.Level1)
97c29fa5a6Sopenharmony_ci{
98c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
99c29fa5a6Sopenharmony_ci    int32_t repeatCount = 3;
100c29fa5a6Sopenharmony_ci    int32_t intervalMs = 1000;
101c29fa5a6Sopenharmony_ci    int32_t timerld = TimerMgr->AddTimer(intervalMs, repeatCount, AddTimerCallback);
102c29fa5a6Sopenharmony_ci    ASSERT_TRUE(TimerMgr->IsExist(timerld));
103c29fa5a6Sopenharmony_ci}
104c29fa5a6Sopenharmony_ci
105c29fa5a6Sopenharmony_ci/**
106c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ManagerTimer_005
107c29fa5a6Sopenharmony_ci * @tc.desc: Test the function AddTimer
108c29fa5a6Sopenharmony_ci * @tc.type: FUNC
109c29fa5a6Sopenharmony_ci * @tc.require:
110c29fa5a6Sopenharmony_ci */
111c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ManagerTimer_005, TestSize.Level1)
112c29fa5a6Sopenharmony_ci{
113c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
114c29fa5a6Sopenharmony_ci    int32_t repeatCount = 3;
115c29fa5a6Sopenharmony_ci    int32_t intervalMs = 1000;
116c29fa5a6Sopenharmony_ci    int32_t timerld = TimerMgr->AddTimer(intervalMs, repeatCount, nullptr);
117c29fa5a6Sopenharmony_ci    EXPECT_EQ(timerld, errCode);
118c29fa5a6Sopenharmony_ci}
119c29fa5a6Sopenharmony_ci
120c29fa5a6Sopenharmony_ci/**
121c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_AddTimer_001
122c29fa5a6Sopenharmony_ci * @tc.desc: Test adding a timer to the TimerManager
123c29fa5a6Sopenharmony_ci * @tc.type: FUNC
124c29fa5a6Sopenharmony_ci * @tc.require:
125c29fa5a6Sopenharmony_ci */
126c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_AddTimer_001, TestSize.Level1)
127c29fa5a6Sopenharmony_ci{
128c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
129c29fa5a6Sopenharmony_ci    TimerManager timermanager;
130c29fa5a6Sopenharmony_ci    int32_t intervalMs = 0;
131c29fa5a6Sopenharmony_ci    int32_t repeatCount = 1;
132c29fa5a6Sopenharmony_ci    auto callback = []() {};
133c29fa5a6Sopenharmony_ci    auto ret = timermanager.AddTimer(intervalMs, repeatCount, callback);
134c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, 0);
135c29fa5a6Sopenharmony_ci    intervalMs = -1;
136c29fa5a6Sopenharmony_ci    repeatCount = 1;
137c29fa5a6Sopenharmony_ci    ret = timermanager.AddTimer(intervalMs, repeatCount, callback);
138c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, 1);
139c29fa5a6Sopenharmony_ci}
140c29fa5a6Sopenharmony_ci
141c29fa5a6Sopenharmony_ci/**
142c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_RemoveTimer_001
143c29fa5a6Sopenharmony_ci * @tc.desc: Test removing a timer from the TimerManager
144c29fa5a6Sopenharmony_ci * @tc.type: FUNC
145c29fa5a6Sopenharmony_ci * @tc.require:
146c29fa5a6Sopenharmony_ci */
147c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_RemoveTimer_001, TestSize.Level1)
148c29fa5a6Sopenharmony_ci{
149c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
150c29fa5a6Sopenharmony_ci    TimerManager timermanager;
151c29fa5a6Sopenharmony_ci    int32_t timerId = 1;
152c29fa5a6Sopenharmony_ci    auto ret = timermanager.RemoveTimer(timerId);
153c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);
154c29fa5a6Sopenharmony_ci    timerId = -1;
155c29fa5a6Sopenharmony_ci    ret = timermanager.RemoveTimer(timerId);
156c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);
157c29fa5a6Sopenharmony_ci}
158c29fa5a6Sopenharmony_ci
159c29fa5a6Sopenharmony_ci/**
160c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ResetTimer_001
161c29fa5a6Sopenharmony_ci * @tc.desc: Test resetting a timer in the TimerManager
162c29fa5a6Sopenharmony_ci * @tc.type: FUNC
163c29fa5a6Sopenharmony_ci * @tc.require:
164c29fa5a6Sopenharmony_ci */
165c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ResetTimer_001, TestSize.Level1)
166c29fa5a6Sopenharmony_ci{
167c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
168c29fa5a6Sopenharmony_ci    TimerManager timermanager;
169c29fa5a6Sopenharmony_ci    int32_t timerId = 1;
170c29fa5a6Sopenharmony_ci    auto ret = timermanager.ResetTimer(timerId);
171c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);
172c29fa5a6Sopenharmony_ci    timerId = -1;
173c29fa5a6Sopenharmony_ci    ret = timermanager.ResetTimer(timerId);
174c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);
175c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(timermanager.ProcessTimers());
176c29fa5a6Sopenharmony_ci}
177c29fa5a6Sopenharmony_ci
178c29fa5a6Sopenharmony_ci/**
179c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_IsExist_001
180c29fa5a6Sopenharmony_ci * @tc.desc: Test checking if a timer exists in the TimerManager
181c29fa5a6Sopenharmony_ci * @tc.type: FUNC
182c29fa5a6Sopenharmony_ci * @tc.require:
183c29fa5a6Sopenharmony_ci */
184c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_IsExist_001, TestSize.Level1)
185c29fa5a6Sopenharmony_ci{
186c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
187c29fa5a6Sopenharmony_ci    TimerManager timermanager;
188c29fa5a6Sopenharmony_ci    int32_t timerId = 1;
189c29fa5a6Sopenharmony_ci    auto ret = timermanager.IsExist(timerId);
190c29fa5a6Sopenharmony_ci    EXPECT_FALSE(ret);
191c29fa5a6Sopenharmony_ci    timerId = -1;
192c29fa5a6Sopenharmony_ci    ret = timermanager.IsExist(timerId);
193c29fa5a6Sopenharmony_ci    EXPECT_FALSE(ret);
194c29fa5a6Sopenharmony_ci}
195c29fa5a6Sopenharmony_ci
196c29fa5a6Sopenharmony_ci/**
197c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_CalcNextDelay_001
198c29fa5a6Sopenharmony_ci * @tc.desc: Test calculating the next delayed timer in the TimerManager
199c29fa5a6Sopenharmony_ci * @tc.type: FUNC
200c29fa5a6Sopenharmony_ci * @tc.require:
201c29fa5a6Sopenharmony_ci */
202c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_CalcNextDelay_001, TestSize.Level1)
203c29fa5a6Sopenharmony_ci{
204c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
205c29fa5a6Sopenharmony_ci    TimerManager timermanager;
206c29fa5a6Sopenharmony_ci    auto ret = timermanager.CalcNextDelay();
207c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);;
208c29fa5a6Sopenharmony_ci}
209c29fa5a6Sopenharmony_ci
210c29fa5a6Sopenharmony_ci/**
211c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_TakeNextTimerId_001
212c29fa5a6Sopenharmony_ci * @tc.desc: Test obtaining the ID of the next timer in the TimerManager
213c29fa5a6Sopenharmony_ci * @tc.type: FUNC
214c29fa5a6Sopenharmony_ci * @tc.require:
215c29fa5a6Sopenharmony_ci */
216c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_TakeNextTimerId_001, TestSize.Level1)
217c29fa5a6Sopenharmony_ci{
218c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
219c29fa5a6Sopenharmony_ci    TimerManager timermanager;
220c29fa5a6Sopenharmony_ci    auto ret = timermanager.TakeNextTimerId();
221c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, 0);
222c29fa5a6Sopenharmony_ci}
223c29fa5a6Sopenharmony_ci
224c29fa5a6Sopenharmony_ci/**
225c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_AddTimerInternal_001
226c29fa5a6Sopenharmony_ci * @tc.desc: Test adding a timer internally within the TimerManager
227c29fa5a6Sopenharmony_ci * @tc.type: FUNC
228c29fa5a6Sopenharmony_ci * @tc.require:
229c29fa5a6Sopenharmony_ci */
230c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_AddTimerInternal_001, TestSize.Level1)
231c29fa5a6Sopenharmony_ci{
232c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
233c29fa5a6Sopenharmony_ci    TimerManager timermanager;
234c29fa5a6Sopenharmony_ci    int32_t intervalMs = 50;
235c29fa5a6Sopenharmony_ci    int32_t repeatCount = 1;
236c29fa5a6Sopenharmony_ci    auto callback = []() {};
237c29fa5a6Sopenharmony_ci    auto ret = timermanager.AddTimerInternal(intervalMs, repeatCount, callback);
238c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, 0);
239c29fa5a6Sopenharmony_ci    intervalMs = 11000;
240c29fa5a6Sopenharmony_ci    repeatCount = 1;
241c29fa5a6Sopenharmony_ci    ret = timermanager.AddTimerInternal(intervalMs, repeatCount, callback);
242c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, 1);
243c29fa5a6Sopenharmony_ci    intervalMs = 500;
244c29fa5a6Sopenharmony_ci    repeatCount = 1;
245c29fa5a6Sopenharmony_ci    ret = timermanager.AddTimerInternal(intervalMs, repeatCount, callback);
246c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, 2);
247c29fa5a6Sopenharmony_ci}
248c29fa5a6Sopenharmony_ci
249c29fa5a6Sopenharmony_ci/**
250c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_RemoveTimerInternal_001
251c29fa5a6Sopenharmony_ci * @tc.desc: Test removing a timer internally within the TimerManager
252c29fa5a6Sopenharmony_ci * @tc.type: FUNC
253c29fa5a6Sopenharmony_ci * @tc.require:
254c29fa5a6Sopenharmony_ci */
255c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_RemoveTimerInternal_001, TestSize.Level1)
256c29fa5a6Sopenharmony_ci{
257c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
258c29fa5a6Sopenharmony_ci    TimerManager timermanager;
259c29fa5a6Sopenharmony_ci    int32_t timerId = 1;
260c29fa5a6Sopenharmony_ci    auto ret = timermanager.RemoveTimerInternal(timerId);
261c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);
262c29fa5a6Sopenharmony_ci    timerId = -1;
263c29fa5a6Sopenharmony_ci    ret = timermanager.RemoveTimerInternal(timerId);
264c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);
265c29fa5a6Sopenharmony_ci}
266c29fa5a6Sopenharmony_ci
267c29fa5a6Sopenharmony_ci/**
268c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ResetTimerInternal_001
269c29fa5a6Sopenharmony_ci * @tc.desc: Test resetting a timer internally within the TimerManager
270c29fa5a6Sopenharmony_ci * @tc.type: FUNC
271c29fa5a6Sopenharmony_ci * @tc.require:
272c29fa5a6Sopenharmony_ci */
273c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ResetTimerInternal_001, TestSize.Level1)
274c29fa5a6Sopenharmony_ci{
275c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
276c29fa5a6Sopenharmony_ci    TimerManager timermanager;
277c29fa5a6Sopenharmony_ci    int32_t timerId = 1;
278c29fa5a6Sopenharmony_ci    timermanager.AddTimer(timerId, 1000, []() {});
279c29fa5a6Sopenharmony_ci    auto ret = timermanager.ResetTimerInternal(timerId);
280c29fa5a6Sopenharmony_ci    EXPECT_EQ(ret, -1);
281c29fa5a6Sopenharmony_ci}
282c29fa5a6Sopenharmony_ci
283c29fa5a6Sopenharmony_ci/**
284c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_IsExistInternal_001
285c29fa5a6Sopenharmony_ci * @tc.desc: Test checking if a timer exists internally within the TimerManager
286c29fa5a6Sopenharmony_ci * @tc.type: FUNC
287c29fa5a6Sopenharmony_ci * @tc.require:
288c29fa5a6Sopenharmony_ci */
289c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_IsExistInternal_001, TestSize.Level1)
290c29fa5a6Sopenharmony_ci{
291c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
292c29fa5a6Sopenharmony_ci    TimerManager timermanager;
293c29fa5a6Sopenharmony_ci    int32_t timerId = 1;
294c29fa5a6Sopenharmony_ci    auto ret = timermanager.IsExistInternal(timerId);
295c29fa5a6Sopenharmony_ci    EXPECT_FALSE(ret);
296c29fa5a6Sopenharmony_ci    timerId = 2;
297c29fa5a6Sopenharmony_ci    ret = timermanager.IsExistInternal(timerId);
298c29fa5a6Sopenharmony_ci    EXPECT_FALSE(ret);
299c29fa5a6Sopenharmony_ci    timerId = -1;
300c29fa5a6Sopenharmony_ci    ret = timermanager.IsExistInternal(timerId);
301c29fa5a6Sopenharmony_ci    EXPECT_FALSE(ret);
302c29fa5a6Sopenharmony_ci}
303c29fa5a6Sopenharmony_ci
304c29fa5a6Sopenharmony_ci/**
305c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_InsertTimerInternal_001
306c29fa5a6Sopenharmony_ci * @tc.desc: Test inserting a timer internally within the TimerManager
307c29fa5a6Sopenharmony_ci * @tc.type: FUNC
308c29fa5a6Sopenharmony_ci * @tc.require:
309c29fa5a6Sopenharmony_ci */
310c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_InsertTimerInternal_001, TestSize.Level1)
311c29fa5a6Sopenharmony_ci{
312c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
313c29fa5a6Sopenharmony_ci    TimerManager timermanager;
314c29fa5a6Sopenharmony_ci    auto timer = std::make_unique<TimerManager::TimerItem>();
315c29fa5a6Sopenharmony_ci    timer->nextCallTime = 100;
316c29fa5a6Sopenharmony_ci    timermanager.InsertTimerInternal(timer);
317c29fa5a6Sopenharmony_ci    EXPECT_EQ(timermanager.timers_.front()->nextCallTime, 100);
318c29fa5a6Sopenharmony_ci}
319c29fa5a6Sopenharmony_ci
320c29fa5a6Sopenharmony_ci/**
321c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_InsertTimerInternal_002
322c29fa5a6Sopenharmony_ci * @tc.desc: Test inserting a timer internally within the TimerManager
323c29fa5a6Sopenharmony_ci * @tc.type: FUNC
324c29fa5a6Sopenharmony_ci * @tc.require:
325c29fa5a6Sopenharmony_ci */
326c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_InsertTimerInternal_002, TestSize.Level1)
327c29fa5a6Sopenharmony_ci{
328c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
329c29fa5a6Sopenharmony_ci    TimerManager timermanager;
330c29fa5a6Sopenharmony_ci    auto timer1 = std::make_unique<TimerManager::TimerItem>();
331c29fa5a6Sopenharmony_ci    timer1->nextCallTime = 100;
332c29fa5a6Sopenharmony_ci    timermanager.InsertTimerInternal(timer1);
333c29fa5a6Sopenharmony_ci    auto timer2 = std::make_unique<TimerManager::TimerItem>();
334c29fa5a6Sopenharmony_ci    timer2->nextCallTime = 50;
335c29fa5a6Sopenharmony_ci    timermanager.InsertTimerInternal(timer2);
336c29fa5a6Sopenharmony_ci    EXPECT_EQ(timermanager.timers_.front()->nextCallTime, 50);
337c29fa5a6Sopenharmony_ci}
338c29fa5a6Sopenharmony_ci
339c29fa5a6Sopenharmony_ci/**
340c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_InsertTimerInternal_003
341c29fa5a6Sopenharmony_ci * @tc.desc: Test inserting a timer internally within the TimerManager
342c29fa5a6Sopenharmony_ci * @tc.type: FUNC
343c29fa5a6Sopenharmony_ci * @tc.require:
344c29fa5a6Sopenharmony_ci */
345c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_InsertTimerInternal_003, TestSize.Level1)
346c29fa5a6Sopenharmony_ci{
347c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
348c29fa5a6Sopenharmony_ci    TimerManager timermanager;
349c29fa5a6Sopenharmony_ci    auto timer1 = std::make_unique<TimerManager::TimerItem>();
350c29fa5a6Sopenharmony_ci    timer1->nextCallTime = 100;
351c29fa5a6Sopenharmony_ci    timermanager.InsertTimerInternal(timer1);
352c29fa5a6Sopenharmony_ci    auto timer2 = std::make_unique<TimerManager::TimerItem>();
353c29fa5a6Sopenharmony_ci    timer2->nextCallTime = 200;
354c29fa5a6Sopenharmony_ci    timermanager.InsertTimerInternal(timer2);
355c29fa5a6Sopenharmony_ci    auto timer3 = std::make_unique<TimerManager::TimerItem>();
356c29fa5a6Sopenharmony_ci    timer3->nextCallTime = 200;
357c29fa5a6Sopenharmony_ci    timermanager.InsertTimerInternal(timer3);
358c29fa5a6Sopenharmony_ci    EXPECT_EQ(timermanager.timers_.front()->nextCallTime, 100);
359c29fa5a6Sopenharmony_ci}
360c29fa5a6Sopenharmony_ci
361c29fa5a6Sopenharmony_ci/**
362c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_CalcNextDelayInternal_001
363c29fa5a6Sopenharmony_ci * @tc.desc: Test calculating the next delay internally within the TimerManager
364c29fa5a6Sopenharmony_ci * @tc.type: FUNC
365c29fa5a6Sopenharmony_ci * @tc.require:
366c29fa5a6Sopenharmony_ci */
367c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_CalcNextDelayInternal_001, TestSize.Level1)
368c29fa5a6Sopenharmony_ci{
369c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
370c29fa5a6Sopenharmony_ci    TimerManager timermanager;
371c29fa5a6Sopenharmony_ci    int32_t timerId = 1;
372c29fa5a6Sopenharmony_ci    timermanager.AddTimer(timerId, 1000, []() {});
373c29fa5a6Sopenharmony_ci    int64_t millisTime = 36;
374c29fa5a6Sopenharmony_ci    EXPECT_EQ(timermanager.CalcNextDelayInternal(), millisTime);
375c29fa5a6Sopenharmony_ci}
376c29fa5a6Sopenharmony_ci
377c29fa5a6Sopenharmony_ci/**
378c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_CalcNextDelayInternal
379c29fa5a6Sopenharmony_ci * @tc.desc: Test calculating the next delay internally within the TimerManager
380c29fa5a6Sopenharmony_ci * @tc.type: FUNC
381c29fa5a6Sopenharmony_ci * @tc.require:
382c29fa5a6Sopenharmony_ci */
383c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_CalcNextDelayInternal, TestSize.Level1)
384c29fa5a6Sopenharmony_ci{
385c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
386c29fa5a6Sopenharmony_ci    TimerManager tMgr;
387c29fa5a6Sopenharmony_ci    auto timer = std::make_unique<TimerManager::TimerItem>();
388c29fa5a6Sopenharmony_ci    timer->nextCallTime = -1;
389c29fa5a6Sopenharmony_ci    tMgr.InsertTimerInternal(timer);
390c29fa5a6Sopenharmony_ci    EXPECT_EQ(tMgr.CalcNextDelayInternal(), 0);
391c29fa5a6Sopenharmony_ci}
392c29fa5a6Sopenharmony_ci
393c29fa5a6Sopenharmony_ci/**
394c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ProcessTimersInternal_001
395c29fa5a6Sopenharmony_ci * @tc.desc: Test processing timers internally within the TimerManager
396c29fa5a6Sopenharmony_ci * @tc.type: FUNC
397c29fa5a6Sopenharmony_ci * @tc.require:
398c29fa5a6Sopenharmony_ci */
399c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ProcessTimersInternal_001, TestSize.Level1)
400c29fa5a6Sopenharmony_ci{
401c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
402c29fa5a6Sopenharmony_ci    TimerManager timermanager;
403c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(timermanager.ProcessTimersInternal());
404c29fa5a6Sopenharmony_ci}
405c29fa5a6Sopenharmony_ci
406c29fa5a6Sopenharmony_ci/**
407c29fa5a6Sopenharmony_ci * @tc.name: TimerManagerTest_ProcessTimersInternal
408c29fa5a6Sopenharmony_ci * @tc.desc: Test processing timers internally within the TimerManager
409c29fa5a6Sopenharmony_ci * @tc.type: FUNC
410c29fa5a6Sopenharmony_ci * @tc.require:
411c29fa5a6Sopenharmony_ci */
412c29fa5a6Sopenharmony_ciHWTEST_F(TimerManagerTest, TimerManagerTest_ProcessTimersInternal, TestSize.Level1)
413c29fa5a6Sopenharmony_ci{
414c29fa5a6Sopenharmony_ci    CALL_TEST_DEBUG;
415c29fa5a6Sopenharmony_ci    TimerManager tMgr;
416c29fa5a6Sopenharmony_ci    auto timer = std::make_unique<TimerManager::TimerItem>();
417c29fa5a6Sopenharmony_ci    timer->nextCallTime = 10000000000;
418c29fa5a6Sopenharmony_ci    tMgr.InsertTimerInternal(timer);
419c29fa5a6Sopenharmony_ci    ASSERT_NO_FATAL_FAILURE(tMgr.ProcessTimersInternal());
420c29fa5a6Sopenharmony_ci}
421c29fa5a6Sopenharmony_ci} // namespace MMI
422c29fa5a6Sopenharmony_ci} // namespace OHOS