1 /*
2 * Copyright (c) 2025 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 "app_spawn_hisysevent_stub.h"
18
19 using namespace testing;
20 using namespace testing::ext;
21
22 namespace OHOS {
23 class AppSpawnHisysEventTest : public testing::Test {
24 public:
25 static void SetUpTestCase();
26 static void TearDownTestCase();
27 void SetUp();
28 void TearDown();
29 };
30
SetUpTestCase()31 void AppSpawnHisysEventTest::SetUpTestCase()
32 {
33 GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST SetUpTestCase";
34 }
35
TearDownTestCase()36 void AppSpawnHisysEventTest::TearDownTestCase()
37 {
38 GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST TearDownTestCase";
39 }
40
SetUp()41 void AppSpawnHisysEventTest::SetUp()
42 {
43 GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST SetUp";
44 }
45
TearDown()46 void AppSpawnHisysEventTest::TearDown()
47 {
48 GTEST_LOG_(INFO) << "AppSpawn_HisysEvent_TEST TearDown";
49 }
50
51 /**
52 * @tc.name: AppSpawnHisysEvent_001
53 * @tc.desc: Verify InitHisyseventTimer success.
54 * @tc.type: FUNC
55 */
56 HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_001, TestSize.Level0)
57 {
58 GTEST_LOG_(INFO) << "AppSpawnHisysEvent_001 test....";
59 SetCreateTimerStatus(true);
60 AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer();
61 EXPECT_NE(hisyseventInfo, NULL);
62 DeleteHisyseventInfo(hisyseventInfo);
63 hisyseventInfo = NULL;
64 }
65
66 /**
67 * @tc.name: AppSpawnHisysEvent_002
68 * @tc.desc: Verify InitHisyseventTimer fail.
69 * @tc.type: FUNC
70 */
71 HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_002, TestSize.Level0)
72 {
73 GTEST_LOG_(INFO) << "AppSpawnHisysEvent_002 test....";
74 SetCreateTimerStatus(false);
75 AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer();
76 EXPECT_NE(hisyseventInfo, NULL);
77 DeleteHisyseventInfo(hisyseventInfo);
78 hisyseventInfo = NULL;
79 }
80
81 /**
82 * @tc.name: AppSpawnHisysEvent_003
83 * @tc.desc: Verify Add bootevent count success.
84 * @tc.type: FUNC
85 */
86 HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_003, TestSize.Level0)
87 {
88 GTEST_LOG_(INFO) << "AppSpawnHisysEvent_003 test....";
89 SetCreateTimerStatus(true);
90 AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer();
91 EXPECT_NE(hisyseventInfo, NULL);
92 AddStatisticEventInfo(hisyseventInfo, 20, true);
93 int count = hisyseventInfo->bootEvent.eventCount;
94 EXPECT_EQ(count, 1);
95 DeleteHisyseventInfo(hisyseventInfo);
96 hisyseventInfo = NULL;
97 }
98
99 /**
100 * @tc.name: AppSpawnHisysEvent_004
101 * @tc.desc: Verify Add bootevent duration success.
102 * @tc.type: FUNC
103 */
104 HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_004, TestSize.Level0)
105 {
106 GTEST_LOG_(INFO) << "AppSpawnHisysEvent_004 test....";
107 SetCreateTimerStatus(true);
108 AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer();
109 EXPECT_NE(hisyseventInfo, NULL);
110 AddStatisticEventInfo(hisyseventInfo, 20, true);
111 int duration = hisyseventInfo->bootEvent.totalDuration;
112 EXPECT_EQ(duration, 20);
113 DeleteHisyseventInfo(hisyseventInfo);
114 hisyseventInfo = NULL;
115 }
116
117 /**
118 * @tc.name: AppSpawnHisysEvent_005
119 * @tc.desc: Verify Add manualevent duration success.
120 * @tc.type: FUNC
121 */
122 HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_005, TestSize.Level0)
123 {
124 GTEST_LOG_(INFO) << "AppSpawnHisysEvent_005 test....";
125 SetCreateTimerStatus(true);
126 AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer();
127 EXPECT_NE(hisyseventInfo, NULL);
128 AddStatisticEventInfo(hisyseventInfo, 20, false);
129 int duration = hisyseventInfo->manualEvent.totalDuration;
130 EXPECT_EQ(duration, 20);
131 DeleteHisyseventInfo(hisyseventInfo);
132 hisyseventInfo = NULL;
133 }
134
135 /**
136 * @tc.name: AppSpawnHisysEvent_006
137 * @tc.desc: Verify manualevent maxduration and minduration success.
138 * @tc.type: FUNC
139 */
140 HWTEST_F(AppSpawnHisysEventTest, AppSpawnHisysEvent_006, TestSize.Level0)
141 {
142 GTEST_LOG_(INFO) << "AppSpawnHisysEvent_006 test....";
143 SetCreateTimerStatus(true);
144 AppSpawnHisyseventInfo * hisyseventInfo = InitHisyseventTimer();
145 EXPECT_NE(hisyseventInfo, NULL);
146 AddStatisticEventInfo(hisyseventInfo, 10, true);
147 AddStatisticEventInfo(hisyseventInfo, 20, true);
148 AddStatisticEventInfo(hisyseventInfo, 30, true);
149 int maxduration = hisyseventInfo->bootEvent.maxDuration;
150 int minduration = hisyseventInfo->bootEvent.minDuration;
151 EXPECT_EQ(maxduration, 30);
152 EXPECT_EQ(minduration, 10);
153 DeleteHisyseventInfo(hisyseventInfo);
154 hisyseventInfo = NULL;
155 }
156 } // namespace OHOS
157