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 "frame_report.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace {
22 static const int32_t FRT_GAME_ERROR_PID = -1;
23 static const int32_t FRT_GAME_PID = 1024;
24 static const int32_t FRT_GAME_ERROR_UNIQUEID = -1;
25 static const int32_t FRT_GAME_UNIQUEID = 1024;
26 static const int32_t FRT_GAME_ERROR_STATE = -1;
27 static const int32_t FRT_GAME_BACKGROUND = 0;
28 static const int32_t FRT_GAME_FOREGROUND = 1;
29 static const int32_t FRT_GAME_SCHED = 2;
30 static const int64_t FRT_GAME_BUFFER_TIME = 2048;
31 static std::string FRT_SURFACE_NAME_EMPTY = "";
32 static std::string FRT_SURFACE_NAME = "SurfaceTEST";
33 }
34
35 namespace OHOS::Rosen {
36 class FrameReportTest : public testing::Test {
37 public:
38 static void SetUpTestSuite(void);
39 static void TearDownTestSuite(void);
40 void SetUp();
41 void TearDown();
42 };
43
SetUpTestSuite(void)44 void FrameReportTest::SetUpTestSuite(void) {}
45
TearDownTestSuite(void)46 void FrameReportTest::TearDownTestSuite(void) {}
47
SetUp()48 void FrameReportTest::SetUp() {}
49
TearDown()50 void FrameReportTest::TearDown() {}
51
52 /*
53 * Function: SetGameScene
54 * Type: Function
55 * Rank: Important(2)
56 * EnvConditions: N/A
57 * CaseDescription: 1. call SetGameScene
58 * 2. check ret
59 */
60 HWTEST_F(FrameReportTest, SetGameScene001, Function | MediumTest | Level2)
61 {
62 Rosen::FrameReport::GetInstance().SetGameScene(FRT_GAME_PID, FRT_GAME_BACKGROUND);
63 ASSERT_TRUE(Rosen::FrameReport::GetInstance().activelyPid_.load() == FR_DEFAULT_PID);
64
65 Rosen::FrameReport::GetInstance().SetGameScene(FRT_GAME_PID, FRT_GAME_FOREGROUND);
66
67 Rosen::FrameReport::GetInstance().SetGameScene(FRT_GAME_PID, FRT_GAME_SCHED);
68 ASSERT_TRUE(Rosen::FrameReport::GetInstance().activelyPid_.load() == FRT_GAME_PID);
69
70 Rosen::FrameReport::GetInstance().SetGameScene(FRT_GAME_PID, FRT_GAME_BACKGROUND);
71 ASSERT_TRUE(Rosen::FrameReport::GetInstance().activelyPid_.load() == FR_DEFAULT_PID);
72
73 Rosen::FrameReport::GetInstance().SetGameScene(FRT_GAME_PID, FRT_GAME_ERROR_STATE);
74 ASSERT_TRUE(Rosen::FrameReport::GetInstance().activelyPid_.load() == FR_DEFAULT_PID);
75 }
76
77 /*
78 * Function: HasGameScene
79 * Type: Function
80 * Rank: Important(2)
81 * EnvConditions: N/A
82 * CaseDescription: 1. call HasGameScene
83 * 2. check ret
84 */
85 HWTEST_F(FrameReportTest, HasGameScene001, Function | MediumTest | Level2)
86 {
87 Rosen::FrameReport::GetInstance().SetGameScene(FRT_GAME_PID, FRT_GAME_BACKGROUND);
88 bool result = Rosen::FrameReport::GetInstance().HasGameScene();
89 ASSERT_TRUE(!result);
90
91 Rosen::FrameReport::GetInstance().SetGameScene(FRT_GAME_PID, FRT_GAME_SCHED);
92 result = Rosen::FrameReport::GetInstance().HasGameScene();
93 ASSERT_TRUE(result);
94 }
95
96 /*
97 * Function: IsActiveGameWithPid
98 * Type: Function
99 * Rank: Important(2)
100 * EnvConditions: N/A
101 * CaseDescription: 1. call IsActiveGameWithPid
102 * 2. check ret
103 */
104 HWTEST_F(FrameReportTest, IsActiveGameWithPid001, Function | MediumTest | Level2)
105 {
106 bool result = Rosen::FrameReport::GetInstance().IsActiveGameWithPid(FRT_GAME_ERROR_PID);
107 ASSERT_TRUE(!result);
108
109 result = Rosen::FrameReport::GetInstance().IsActiveGameWithPid(FRT_GAME_PID);
110 ASSERT_TRUE(result);
111 }
112
113 /*
114 * Function: IsActiveGameWithUniqueId
115 * Type: Function
116 * Rank: Important(2)
117 * EnvConditions: N/A
118 * CaseDescription: 1. call IsActiveGameWithUniqueId
119 * 2. check ret
120 */
121 HWTEST_F(FrameReportTest, IsActiveGameWithUniqueId001, Function | MediumTest | Level2)
122 {
123 bool result = Rosen::FrameReport::GetInstance().IsActiveGameWithUniqueId(FRT_GAME_ERROR_UNIQUEID);
124 ASSERT_TRUE(!result);
125
126 result = Rosen::FrameReport::GetInstance().IsActiveGameWithUniqueId(FR_DEFAULT_UNIQUEID);
127 ASSERT_TRUE(!result);
128
129 result = Rosen::FrameReport::GetInstance().IsActiveGameWithUniqueId(FRT_GAME_UNIQUEID);
130 ASSERT_TRUE(!result);
131 }
132
133 /*
134 * Function: SetLastSwapBufferTime
135 * Type: Function
136 * Rank: Important(2)
137 * EnvConditions: N/A
138 * CaseDescription: 1. call SetLastSwapBufferTime
139 * 2. check ret
140 */
141 HWTEST_F(FrameReportTest, SetLastSwapBufferTime001, Function | MediumTest | Level2)
142 {
143 Rosen::FrameReport::GetInstance().SetLastSwapBufferTime(FRT_GAME_BUFFER_TIME);
144 ASSERT_TRUE(Rosen::FrameReport::GetInstance().lastSwapBufferTime_.load() == FRT_GAME_BUFFER_TIME);
145 }
146
147 /*
148 * Function: SetDequeueBufferTime
149 * Type: Function
150 * Rank: Important(2)
151 * EnvConditions: N/A
152 * CaseDescription: 1. call SetDequeueBufferTime
153 * 2. check ret
154 */
155 HWTEST_F(FrameReportTest, SetDequeueBufferTime001, Function | MediumTest | Level2)
156 {
157 Rosen::FrameReport::GetInstance().SetDequeueBufferTime(FRT_SURFACE_NAME_EMPTY, FRT_GAME_BUFFER_TIME);
158 ASSERT_TRUE(Rosen::FrameReport::GetInstance().dequeueBufferTime_.load() == FRT_GAME_BUFFER_TIME);
159
160 Rosen::FrameReport::GetInstance().SetDequeueBufferTime(FRT_SURFACE_NAME, FRT_GAME_BUFFER_TIME);
161 ASSERT_TRUE(Rosen::FrameReport::GetInstance().dequeueBufferTime_.load() == FRT_GAME_BUFFER_TIME);
162 }
163
164 /*
165 * Function: SetQueueBufferTime
166 * Type: Function
167 * Rank: Important(2)
168 * EnvConditions: N/A
169 * CaseDescription: 1. call SetQueueBufferTime
170 * 2. check ret
171 */
172 HWTEST_F(FrameReportTest, SetQueueBufferTime001, Function | MediumTest | Level2)
173 {
174 Rosen::FrameReport::GetInstance().SetQueueBufferTime(FRT_GAME_UNIQUEID, FRT_SURFACE_NAME_EMPTY,
175 FRT_GAME_BUFFER_TIME);
176 ASSERT_TRUE(Rosen::FrameReport::GetInstance().queueBufferTime_.load() == FRT_GAME_BUFFER_TIME);
177
178 Rosen::FrameReport::GetInstance().SetQueueBufferTime(FRT_GAME_UNIQUEID, FRT_SURFACE_NAME, FRT_GAME_BUFFER_TIME);
179 ASSERT_TRUE(Rosen::FrameReport::GetInstance().queueBufferTime_.load() == FRT_GAME_BUFFER_TIME);
180 }
181
182 /*
183 * Function: SetPendingBufferNum
184 * Type: Function
185 * Rank: Important(2)
186 * EnvConditions: N/A
187 * CaseDescription: 1. call SetPendingBufferNum
188 * 2. check ret
189 */
190 HWTEST_F(FrameReportTest, SetPendingBufferNum001, Function | MediumTest | Level2)
191 {
192 Rosen::FrameReport::GetInstance().SetPendingBufferNum(FRT_SURFACE_NAME_EMPTY, FRT_GAME_BUFFER_TIME);
193 ASSERT_TRUE(Rosen::FrameReport::GetInstance().pendingBufferNum_.load() == FRT_GAME_BUFFER_TIME);
194
195 Rosen::FrameReport::GetInstance().SetPendingBufferNum(FRT_SURFACE_NAME, FRT_GAME_BUFFER_TIME);
196 ASSERT_TRUE(Rosen::FrameReport::GetInstance().pendingBufferNum_.load() == FRT_GAME_BUFFER_TIME);
197 }
198
199 /*
200 * Function: Report
201 * Type: Function
202 * Rank: Important(2)
203 * EnvConditions: N/A
204 * CaseDescription: 1. call Report
205 */
206 HWTEST_F(FrameReportTest, Report001, Function | MediumTest | Level2)
207 {
208 Rosen::FrameReport::GetInstance().Report(FRT_SURFACE_NAME_EMPTY);
209 Rosen::FrameReport::GetInstance().Report(FRT_SURFACE_NAME);
210 ASSERT_TRUE(Rosen::FrameReport::GetInstance().pendingBufferNum_.load() == FRT_GAME_BUFFER_TIME);
211 }
212
213 /*
214 * Function: CloseLibrary
215 * Type: Function
216 * Rank: Important(2)
217 * EnvConditions: N/A
218 * CaseDescription: 1. call CloseLibrary
219 */
220 HWTEST_F(FrameReportTest, CloseLibrary001, Function | MediumTest | Level2)
221 {
222 Rosen::FrameReport::GetInstance().CloseLibrary();
223 EXPECT_EQ(Rosen::FrameReport::GetInstance().notifyFrameInfoFunc_, nullptr);
224 EXPECT_EQ(Rosen::FrameReport::GetInstance().gameSoHandle_, nullptr);
225 EXPECT_EQ(Rosen::FrameReport::GetInstance().isGameSoLoaded_, false);
226 }
227
228 /*
229 * Function: DeletePidInfo
230 * Type: Function
231 * Rank: Important(2)
232 * EnvConditions: N/A
233 * CaseDescription: 1. call DeletePidInfo
234 * 2. check ret
235 */
236 HWTEST_F(FrameReportTest, DeletePidInfo001, Function | MediumTest | Level2)
237 {
238 Rosen::FrameReport::GetInstance().DeletePidInfo();
239 ASSERT_TRUE(Rosen::FrameReport::GetInstance().activelyPid_.load() == FR_DEFAULT_PID);
240 }
241
242 /*
243 * Function: NotifyFrameInfo
244 * Type: Function
245 * Rank: Important(2)
246 * EnvConditions: N/A
247 * CaseDescription: 1. call NotifyFrameInfo
248 * 2. check ret
249 */
250 HWTEST_F(FrameReportTest, NotifyFrameInfo001, Function | MediumTest | Level2)
251 {
252 Rosen::FrameReport::GetInstance().notifyFrameInfoFunc_ = nullptr;
253 Rosen::FrameReport::GetInstance().NotifyFrameInfo(FRT_GAME_PID, FRT_SURFACE_NAME, FRT_GAME_BUFFER_TIME,
254 FRT_SURFACE_NAME_EMPTY);
255 ASSERT_TRUE(Rosen::FrameReport::GetInstance().notifyFrameInfoFunc_ == nullptr);
256 }
257
258 } // namespace OHOS::Rosen
259