1 /*
2 * Copyright (c) 2022-2023 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 <gtest/gtest.h>
17 #include <thread>
18
19 #define private public
20 #define protected public
21 #include "watchdog.h"
22 #undef private
23 #undef protected
24
25 #include "main_thread.h"
26 #include "mock_app_thread.h"
27
28 using namespace testing::ext;
29 using namespace OHOS;
30 using namespace OHOS::AppExecFwk;
31
32 namespace OHOS {
33 namespace AppExecFwk {
34 constexpr int64_t TEST_INTERVAL_TIME = 5000;
35 class WatchdogTest : public testing::Test {
36 public:
WatchdogTest()37 WatchdogTest()
38 {}
~WatchdogTest()39 ~WatchdogTest()
40 {}
41 std::shared_ptr<MockHandler> mockHandler_ = nullptr;
42 std::shared_ptr<EventRunner> runner_ = nullptr;
43 std::shared_ptr<Watchdog> watchdog_ = nullptr;
44 static void SetUpTestCase(void);
45 static void TearDownTestCase(void);
46 void SetUp();
47 void TearDown();
48 };
49
SetUpTestCase(void)50 void WatchdogTest::SetUpTestCase(void)
51 {}
52
TearDownTestCase(void)53 void WatchdogTest::TearDownTestCase(void)
54 {}
55
SetUp(void)56 void WatchdogTest::SetUp(void)
57 {
58 runner_ = EventRunner::Create("");
59 mockHandler_ = std::make_shared<MockHandler>(runner_);
60
61 watchdog_ = std::make_shared<Watchdog>();
62 watchdog_->Init(mockHandler_);
63 }
64
TearDown(void)65 void WatchdogTest::TearDown(void)
66 {
67 watchdog_->Stop();
68 }
69
70 /**
71 * @tc.number: AppExecFwk_watchdog_IsReportEvent_0001
72 * @tc.name: IsReportEvent
73 * @tc.desc: Test the abnormal state of IsReportEvent.
74 * @tc.require: issueI5MGFU
75 */
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0001, Function | MediumTest | Level3)76 HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0001, Function | MediumTest | Level3)
77 {
78 watchdog_->SetAppMainThreadState(false);
79 bool ret = watchdog_->IsReportEvent();
80 EXPECT_TRUE(ret);
81 }
82
83 /**
84 * @tc.number: AppExecFwk_watchdog_IsReportEvent_0002
85 * @tc.name: IsReportEvent
86 * @tc.desc: Test the change state of IsReportEvent.
87 * @tc.require: issueI5MGFU
88 */
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0002, Function | MediumTest | Level3)89 HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0002, Function | MediumTest | Level3)
90 {
91 watchdog_->SetAppMainThreadState(true);
92 watchdog_->AllowReportEvent();
93 bool ret = watchdog_->IsReportEvent();
94 EXPECT_FALSE(ret);
95 }
96
97 /**
98 * @tc.number: AppExecFwk_watchdog_ReportEvent_0001
99 * @tc.name: ReportEvent
100 * @tc.desc: Test ReportEvent.
101 * @tc.require: I5UL6H
102 */
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0001, Function | MediumTest | Level3)103 HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0001, Function | MediumTest | Level3)
104 {
105 // be ready for ReportEvent
106 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::
107 steady_clock::now().time_since_epoch()).count() - TEST_INTERVAL_TIME;
108 watchdog_->needReport_ = true;
109
110 watchdog_->isSixSecondEvent_.store(true);
111
112 watchdog_->ReportEvent();
113 EXPECT_TRUE(1);
114 }
115
116 /**
117 * @tc.number: AppExecFwk_watchdog_ReportEvent_0002
118 * @tc.name: ReportEvent
119 * @tc.desc: Test ReportEvent.
120 * @tc.require: I5UL6H
121 */
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0002, Function | MediumTest | Level3)122 HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0002, Function | MediumTest | Level3)
123 {
124 // be ready for ReportEvent
125 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::
126 system_clock::now().time_since_epoch()).count() - TEST_INTERVAL_TIME;
127 watchdog_->needReport_ = true;
128
129 watchdog_->isSixSecondEvent_.store(false);
130
131 watchdog_->ReportEvent();
132 EXPECT_TRUE(1);
133 }
134
135 /**
136 * @tc.number: AppExecFwk_watchdog_ReportEvent_0003
137 * @tc.name: ReportEvent
138 * @tc.desc: Test ReportEvent.
139 * @tc.require: I5UL6H
140 */
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0003, Function | MediumTest | Level3)141 HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0003, Function | MediumTest | Level3)
142 {
143 watchdog_->isBgWorkingThread_.store(true);
144 watchdog_->ReportEvent();
145 EXPECT_TRUE(watchdog_->needReport_);
146 }
147
148 /**
149 * @tc.number: AppExecFwk_watchdog_ReportEvent_0004
150 * @tc.name: ReportEvent
151 * @tc.desc: Test ReportEvent.
152 * @tc.require: I5UL6H
153 */
HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0004, Function | MediumTest | Level3)154 HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0004, Function | MediumTest | Level3)
155 {
156 watchdog_->isBgWorkingThread_.store(false);
157 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::
158 system_clock::now().time_since_epoch()).count() - TEST_INTERVAL_TIME;
159 watchdog_->needReport_ = true;
160 watchdog_->isSixSecondEvent_.store(true);
161 watchdog_->isInBackground_.store(false);
162 watchdog_->ReportEvent();
163 watchdog_->needReport_ = false;
164 watchdog_->ReportEvent();
165 EXPECT_TRUE(!watchdog_->needReport_);
166 }
167
168 /**
169 * @tc.number: WatchdogTest_Init_001
170 * @tc.name: Init
171 * @tc.desc: Verify that function Init.
172 */
HWTEST_F(WatchdogTest, WatchdogTest_Init_001, TestSize.Level1)173 HWTEST_F(WatchdogTest, WatchdogTest_Init_001, TestSize.Level1)
174 {
175 GTEST_LOG_(INFO) << "WatchdogTest_Init_001 start";
176 std::shared_ptr<EventHandler> eventHandler = std::make_shared<EventHandler>();
177 watchdog_->Init(eventHandler);
178 EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr);
179 GTEST_LOG_(INFO) << "WatchdogTest_Init_001 end";
180 }
181
182 /**
183 * @tc.number: WatchdogTest_Init_002
184 * @tc.name: Init
185 * @tc.desc: Verify that function Init.
186 */
HWTEST_F(WatchdogTest, WatchdogTest_Init_002, TestSize.Level1)187 HWTEST_F(WatchdogTest, WatchdogTest_Init_002, TestSize.Level1)
188 {
189 GTEST_LOG_(INFO) << "WatchdogTest_Init_002 start";
190 std::shared_ptr<EventHandler> eventHandler = nullptr;
191 watchdog_->lastWatchTime_ = 2;
192 watchdog_->Init(eventHandler);
193 EXPECT_EQ(watchdog_->lastWatchTime_, 0);
194 GTEST_LOG_(INFO) << "WatchdogTest_Init_002 end";
195 }
196
197 /**
198 * @tc.number: WatchdogTest_Stop_001
199 * @tc.name: Stop
200 * @tc.desc: Verify that function Init.
201 */
HWTEST_F(WatchdogTest, WatchdogTest_Stop_001, TestSize.Level1)202 HWTEST_F(WatchdogTest, WatchdogTest_Stop_001, TestSize.Level1)
203 {
204 GTEST_LOG_(INFO) << "WatchdogTest_Stop_001 start";
205 std::shared_ptr<EventHandler> eventHandler = std::make_shared<EventHandler>();
206 watchdog_->Init(eventHandler);
207 EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr);
208 watchdog_->Stop();
209 EXPECT_TRUE(watchdog_->appMainHandler_ == nullptr);
210 GTEST_LOG_(INFO) << "WatchdogTest_Stop_001 end";
211 }
212
213 /**
214 * @tc.number: WatchdogTest_Stop_002
215 * @tc.name: Stop
216 * @tc.desc: Verify that function Stop.
217 */
HWTEST_F(WatchdogTest, WatchdogTest_Stop_002, TestSize.Level1)218 HWTEST_F(WatchdogTest, WatchdogTest_Stop_002, TestSize.Level1)
219 {
220 GTEST_LOG_(INFO) << "WatchdogTest_Stop_002 start";
221 std::shared_ptr<EventHandler> eventHandler = nullptr;
222 watchdog_->Stop();
223 EXPECT_TRUE(watchdog_->stopWatchdog_);
224 GTEST_LOG_(INFO) << "WatchdogTest_Stop_002 end";
225 }
226
227 /**
228 * @tc.number: WatchdogTest_SetAppMainThreadState_001
229 * @tc.name: SetAppMainThreadState
230 * @tc.desc: Verify that function SetAppMainThreadState.
231 */
HWTEST_F(WatchdogTest, WatchdogTest_SetAppMainThreadState_001, TestSize.Level1)232 HWTEST_F(WatchdogTest, WatchdogTest_SetAppMainThreadState_001, TestSize.Level1)
233 {
234 GTEST_LOG_(INFO) << "WatchdogTest_SetAppMainThreadState_001 start";
235 bool appMainThreadState = true;
236 EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
237 watchdog_->SetAppMainThreadState(appMainThreadState);
238 EXPECT_TRUE(watchdog_->appMainThreadIsAlive_);
239 GTEST_LOG_(INFO) << "WatchdogTest_SetAppMainThreadState_001 end";
240 }
241
242 /**
243 * @tc.number: WatchdogTest_SetBackgroundStatus_001
244 * @tc.name: SetBackgroundStatus
245 * @tc.desc: Verify that function SetBackgroundStatus.
246 */
HWTEST_F(WatchdogTest, WatchdogTest_SetBackgroundStatus_001, TestSize.Level1)247 HWTEST_F(WatchdogTest, WatchdogTest_SetBackgroundStatus_001, TestSize.Level1)
248 {
249 GTEST_LOG_(INFO) << "WatchdogTest_SetBackgroundStatus_001 start";
250 bool isInBackground = false;
251 EXPECT_TRUE(watchdog_->isInBackground_);
252 watchdog_->SetBackgroundStatus(isInBackground);
253 EXPECT_FALSE(watchdog_->isInBackground_);
254 GTEST_LOG_(INFO) << "WatchdogTest_SetBackgroundStatus_001 end";
255 }
256
257 /**
258 * @tc.number: WatchdogTest_AllowReportEvent_001
259 * @tc.name: AllowReportEvent
260 * @tc.desc: Verify that function AllowReportEvent.
261 */
HWTEST_F(WatchdogTest, WatchdogTest_AllowReportEvent_001, TestSize.Level1)262 HWTEST_F(WatchdogTest, WatchdogTest_AllowReportEvent_001, TestSize.Level1)
263 {
264 GTEST_LOG_(INFO) << "WatchdogTest_AllowReportEvent_001 start";
265 watchdog_->needReport_ = false;
266 watchdog_->AllowReportEvent();
267 EXPECT_TRUE(watchdog_->needReport_);
268 GTEST_LOG_(INFO) << "WatchdogTest_AllowReportEvent_001 end";
269 }
270
271 /**
272 * @tc.number: WatchdogTest_IsReportEvent_001
273 * @tc.name: IsReportEvent
274 * @tc.desc: Verify that function IsReportEvent.
275 */
HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_003, TestSize.Level1)276 HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_003, TestSize.Level1)
277 {
278 GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_003 start";
279 watchdog_->SetAppMainThreadState(false);
280 auto result = watchdog_->IsReportEvent();
281 EXPECT_TRUE(result);
282 GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_003 end";
283 }
284
285 /**
286 * @tc.number: WatchdogTest_IsReportEvent_002
287 * @tc.name: IsReportEvent
288 * @tc.desc: Verify that function IsReportEvent.
289 */
HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_004, TestSize.Level1)290 HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_004, TestSize.Level1)
291 {
292 GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_004 start";
293 bool appMainThreadState = true;
294 EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
295 watchdog_->SetAppMainThreadState(appMainThreadState);
296 auto result = watchdog_->IsReportEvent();
297 EXPECT_FALSE(result);
298 GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_004 end";
299 }
300
301 /**
302 * @tc.number: WatchdogTest_IsStopwatchdog_001
303 * @tc.name: IsStopWatchdog
304 * @tc.desc: Verify that function IsStopWatchdog.
305 */
HWTEST_F(WatchdogTest, WatchdogTest_IsStopwatchdog_001, TestSize.Level1)306 HWTEST_F(WatchdogTest, WatchdogTest_IsStopwatchdog_001, TestSize.Level1)
307 {
308 GTEST_LOG_(INFO) << "WatchdogTest_IsStopwatchdog_001 start";
309 auto result = watchdog_->IsStopWatchdog();
310 EXPECT_FALSE(result);
311 GTEST_LOG_(INFO) << "WatchdogTest_IsStopwatchdog_001 end";
312 }
313
314 /**
315 * @tc.number: WatchdogTest_Timer_001
316 * @tc.name: Timer
317 * @tc.desc: Verify that function Timer.
318 */
HWTEST_F(WatchdogTest, WatchdogTest_Timer_001, TestSize.Level1)319 HWTEST_F(WatchdogTest, WatchdogTest_Timer_001, TestSize.Level1)
320 {
321 GTEST_LOG_(INFO) << "WatchdogTest_Timer_001 start";
322 watchdog_->needReport_ = false;
323 watchdog_->Timer();
324 EXPECT_TRUE(!watchdog_->needReport_);
325 GTEST_LOG_(INFO) << "WatchdogTest_Timer_001 end";
326 }
327
328 /**
329 * @tc.number: WatchdogTest_Timer_002
330 * @tc.name: Timer
331 * @tc.desc: Verify that function Timer.
332 */
HWTEST_F(WatchdogTest, WatchdogTest_Timer_002, TestSize.Level1)333 HWTEST_F(WatchdogTest, WatchdogTest_Timer_002, TestSize.Level1)
334 {
335 GTEST_LOG_(INFO) << "WatchdogTest_Timer_002 start";
336 bool isInBackground = true;
337 EXPECT_TRUE(watchdog_->isInBackground_);
338 watchdog_->SetBackgroundStatus(isInBackground);
339 watchdog_->SetAppMainThreadState(true);
340 watchdog_->Timer();
341 EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
342 GTEST_LOG_(INFO) << "WatchdogTest_Timer_002 end";
343 }
344
345 /**
346 * @tc.number: WatchdogTest_Timer_003
347 * @tc.name: Timer
348 * @tc.desc: Verify that function Timer.
349 */
HWTEST_F(WatchdogTest, WatchdogTest_Timer_003, TestSize.Level1)350 HWTEST_F(WatchdogTest, WatchdogTest_Timer_003, TestSize.Level1)
351 {
352 GTEST_LOG_(INFO) << "WatchdogTest_Timer_003 start";
353 bool appMainThreadState = true;
354 EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
355 watchdog_->SetAppMainThreadState(appMainThreadState);
356 watchdog_->Timer();
357 bool isInBackground = false;
358 watchdog_->SetBackgroundStatus(isInBackground);
359 watchdog_->Timer();
360 watchdog_->stopWatchdog_ = true;
361 watchdog_->Timer();
362 EXPECT_TRUE(watchdog_->needReport_);
363 EXPECT_FALSE(watchdog_->isInBackground_);
364 EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
365 GTEST_LOG_(INFO) << "WatchdogTest_Timer_003 end";
366 }
367
368 /**
369 * @tc.number: WatchdogTest_Timer_004
370 * @tc.name: Timer
371 * @tc.desc: Verify that function Timer.
372 */
HWTEST_F(WatchdogTest, WatchdogTest_Timer_004, TestSize.Level1)373 HWTEST_F(WatchdogTest, WatchdogTest_Timer_004, TestSize.Level1)
374 {
375 GTEST_LOG_(INFO) << "WatchdogTest_Timer_004 start";
376 bool appMainThreadState = true;
377 EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
378 watchdog_->SetAppMainThreadState(appMainThreadState);
379 bool isInBackground = false;
380 watchdog_->SetBackgroundStatus(isInBackground);
381 watchdog_->appMainHandler_ = std::make_shared<EventHandler>();
382 watchdog_->Timer();
383 EXPECT_TRUE(watchdog_->needReport_);
384 EXPECT_FALSE(watchdog_->isInBackground_);
385 EXPECT_FALSE(watchdog_->appMainThreadIsAlive_);
386 EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr);
387 GTEST_LOG_(INFO) << "WatchdogTest_Timer_004 end";
388 }
389
390 /**
391 * @tc.number: WatchdogTest_ReportEvent_003
392 * @tc.name: ReportEvent
393 * @tc.desc: Verify that function ReportEvent.
394 */
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_003, TestSize.Level1)395 HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_003, TestSize.Level1)
396 {
397 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_003 start";
398 watchdog_->ReportEvent();
399 EXPECT_FALSE(watchdog_->isSixSecondEvent_);
400 EXPECT_TRUE(watchdog_->needReport_);
401 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_003 end";
402 }
403
404 /**
405 * @tc.number: WatchdogTest_ReportEvent_004
406 * @tc.name: ReportEvent
407 * @tc.desc: Verify that function ReportEvent.
408 */
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_004, TestSize.Level1)409 HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_004, TestSize.Level1)
410 {
411 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_002 start";
412 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::microseconds>(
413 std::chrono::steady_clock::now().time_since_epoch()).count();
414 watchdog_->ReportEvent();
415 EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr);
416 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_002 end";
417 }
418
419 /**
420 * @tc.number: WatchdogTest_ReportEvent_005
421 * @tc.name: ReportEvent
422 * @tc.desc: Verify that function ReportEvent.
423 */
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_005, TestSize.Level1)424 HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_005, TestSize.Level1)
425 {
426 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_005 start";
427 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::microseconds>(
428 std::chrono::steady_clock::now().time_since_epoch()).count();
429 watchdog_->needReport_ = false;
430 watchdog_->ReportEvent();
431 EXPECT_TRUE(watchdog_->needReport_ == false);
432 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_005 end";
433 }
434
435 /**
436 * @tc.number: WatchdogTest_ReportEvent_006
437 * @tc.name: ReportEvent
438 * @tc.desc: Verify that function ReportEvent.
439 */
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_006, TestSize.Level1)440 HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_006, TestSize.Level1)
441 {
442 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_006 start";
443 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::microseconds>(
444 std::chrono::steady_clock::now().time_since_epoch()).count();
445 watchdog_->isSixSecondEvent_ = true;
446 watchdog_->ReportEvent();
447 EXPECT_TRUE(watchdog_->needReport_);
448 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_006 end";
449 }
450
451 /**
452 * @tc.number: WatchdogTest_ReportEvent_007
453 * @tc.name: ReportEvent
454 * @tc.desc: Verify that function ReportEvent.
455 */
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_007, TestSize.Level1)456 HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_007, TestSize.Level1)
457 {
458 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_007 start";
459 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::microseconds>(
460 std::chrono::steady_clock::now().time_since_epoch()).count();
461 watchdog_->ReportEvent();
462 EXPECT_FALSE(watchdog_->isSixSecondEvent_);
463 GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_007 end";
464 }
465
466 /**
467 * @tc.number: WatchdogTest_ReportEvent_008
468 * @tc.name: ReportEvent
469 * @tc.desc: Verify that function ReportEvent.
470 */
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_008, TestSize.Level1)471 HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_008, TestSize.Level1)
472 {
473 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
474 system_clock::now().time_since_epoch()).count() - TEST_INTERVAL_TIME;
475 std::shared_ptr<EventHandler> eventHandler = std::make_shared<EventHandler>();
476 watchdog_->needReport_ = true;
477 watchdog_->isSixSecondEvent_.store(true);
478 EXPECT_TRUE(watchdog_->needReport_);
479 watchdog_->ReportEvent();
480 }
481
482 /**
483 * @tc.number: WatchdogTest_ReportEvent_009
484 * @tc.name: ReportEvent
485 * @tc.desc: Verify that function ReportEvent.
486 */
HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_009, TestSize.Level1)487 HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_009, TestSize.Level1)
488 {
489 watchdog_->lastWatchTime_ = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::
490 system_clock::now().time_since_epoch()).count() - TEST_INTERVAL_TIME;
491 watchdog_->isInBackground_ = true;
492 watchdog_->backgroundReportCount_ = 0;
493 watchdog_->ReportEvent();
494 EXPECT_EQ(watchdog_->backgroundReportCount_, 1);
495 watchdog_->SetBundleInfo("test", "1.1.0");
496 watchdog_->SetBgWorkingThreadStatus(false);
497 }
498 } // namespace AppExecFwk
499 } // namespace OHOS
500