• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "vsync_distributor.h"
17 #include "vsync_controller.h"
18 
19 using namespace testing;
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace Rosen {
24 class VSyncDistributorTest : public testing::Test {
25 public:
26     static void SetUpTestCase();
27     static void TearDownTestCase();
28 
29     static inline sptr<VSyncController> vsyncController = nullptr;
30     static inline sptr<VSyncDistributor> vsyncDistributor = nullptr;
31     static inline sptr<VSyncGenerator> vsyncGenerator = nullptr;
32 };
33 
SetUpTestCase()34 void VSyncDistributorTest::SetUpTestCase()
35 {
36     vsyncGenerator = CreateVSyncGenerator();
37     vsyncController = new VSyncController(vsyncGenerator, 0);
38     vsyncDistributor = new VSyncDistributor(vsyncController, "VSyncConnection");
39 }
40 
TearDownTestCase()41 void VSyncDistributorTest::TearDownTestCase()
42 {
43     vsyncGenerator = nullptr;
44     DestroyVSyncGenerator();
45     vsyncController = nullptr;
46     vsyncDistributor = nullptr;
47 }
48 
49 namespace {
50 /*
51 * Function: AddConnection001
52 * Type: Function
53 * Rank: Important(2)
54 * EnvConditions: N/A
55 * CaseDescription: 1. call AddConnection
56  */
57 HWTEST_F(VSyncDistributorTest, AddConnection001, Function | MediumTest| Level3)
58 {
59     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(nullptr), VSYNC_ERROR_NULLPTR);
60 }
61 
62 /*
63 * Function: AddConnection002
64 * Type: Function
65 * Rank: Important(2)
66 * EnvConditions: N/A
67 * CaseDescription: 1. call AddConnection
68  */
69 HWTEST_F(VSyncDistributorTest, AddConnection002, Function | MediumTest| Level3)
70 {
71     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
72     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(conn), VSYNC_ERROR_OK);
73     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->AddConnection(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
74 }
75 
76 /*
77 * Function: RemoveConnection001
78 * Type: Function
79 * Rank: Important(2)
80 * EnvConditions: N/A
81 * CaseDescription: 1. call RemoveConnection
82  */
83 HWTEST_F(VSyncDistributorTest, RemoveConnection001, Function | MediumTest| Level3)
84 {
85     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(nullptr), VSYNC_ERROR_NULLPTR);
86 }
87 
88 /*
89 * Function: RemoveConnection002
90 * Type: Function
91 * Rank: Important(2)
92 * EnvConditions: N/A
93 * CaseDescription: 1. call RemoveConnection
94  */
95 HWTEST_F(VSyncDistributorTest, RemoveConnection002, Function | MediumTest| Level3)
96 {
97     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
98     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
99 }
100 
101 /*
102 * Function: RemoveConnection003
103 * Type: Function
104 * Rank: Important(2)
105 * EnvConditions: N/A
106 * CaseDescription: 1. call RemoveConnection
107  */
108 HWTEST_F(VSyncDistributorTest, RemoveConnection003, Function | MediumTest| Level3)
109 {
110     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
111     VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
112     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RemoveConnection(conn), VSYNC_ERROR_OK);
113 }
114 
115 /*
116 * Function: RequestNextVSync001
117 * Type: Function
118 * Rank: Important(2)
119 * EnvConditions: N/A
120 * CaseDescription: 1. call RequestNextVSync
121  */
122 HWTEST_F(VSyncDistributorTest, RequestNextVSync001, Function | MediumTest| Level3)
123 {
124     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(nullptr), VSYNC_ERROR_NULLPTR);
125 }
126 
127 /*
128 * Function: RequestNextVSync002
129 * Type: Function
130 * Rank: Important(2)
131 * EnvConditions: N/A
132 * CaseDescription: 1. call RequestNextVSync
133  */
134 HWTEST_F(VSyncDistributorTest, RequestNextVSync002, Function | MediumTest| Level3)
135 {
136     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
137     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn), VSYNC_ERROR_INVALID_ARGUMENTS);
138 }
139 
140 /*
141 * Function: RequestNextVSync003
142 * Type: Function
143 * Rank: Important(2)
144 * EnvConditions: N/A
145 * CaseDescription: 1. call RequestNextVSync
146  */
147 HWTEST_F(VSyncDistributorTest, RequestNextVSync003, Function | MediumTest| Level3)
148 {
149     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
150     VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
151     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn), VSYNC_ERROR_OK);
152 }
153 
154 /*
155 * Function: RequestNextVSync004
156 * Type: Function
157 * Rank: Important(2)
158 * EnvConditions: N/A
159 * CaseDescription: 1. call RequestNextVSync
160  */
161 HWTEST_F(VSyncDistributorTest, RequestNextVSync004, Function | MediumTest| Level3)
162 {
163     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
164     VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
165     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->RequestNextVSync(conn, "unknown", 0), VSYNC_ERROR_OK);
166 }
167 
168 /*
169 * Function: SetVSyncRate001
170 * Type: Function
171 * Rank: Important(2)
172 * EnvConditions: N/A
173 * CaseDescription: 1. call SetVSyncRate
174  */
175 HWTEST_F(VSyncDistributorTest, SetVSyncRate001, Function | MediumTest| Level3)
176 {
177     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(0, nullptr), VSYNC_ERROR_INVALID_ARGUMENTS);
178 }
179 
180 /*
181 * Function: SetVSyncRate002
182 * Type: Function
183 * Rank: Important(2)
184 * EnvConditions: N/A
185 * CaseDescription: 1. call SetVSyncRate
186  */
187 HWTEST_F(VSyncDistributorTest, SetVSyncRate002, Function | MediumTest| Level3)
188 {
189     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
190     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
191 }
192 
193 /*
194 * Function: SetVSyncRate003
195 * Type: Function
196 * Rank: Important(2)
197 * EnvConditions: N/A
198 * CaseDescription: 1. call SetVSyncRate
199  */
200 HWTEST_F(VSyncDistributorTest, SetVSyncRate003, Function | MediumTest| Level3)
201 {
202     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
203     VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
204     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_OK);
205 }
206 
207 /*
208 * Function: SetVSyncRate004
209 * Type: Function
210 * Rank: Important(2)
211 * EnvConditions: N/A
212 * CaseDescription: 1. call SetVSyncRate
213  */
214 HWTEST_F(VSyncDistributorTest, SetVSyncRate004, Function | MediumTest| Level3)
215 {
216     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
217     VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
218     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_OK);
219     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
220 }
221 
222 /*
223 * Function: SetHighPriorityVSyncRate001
224 * Type: Function
225 * Rank: Important(2)
226 * EnvConditions: N/A
227 * CaseDescription: 1. call SetHighPriorityVSyncRate with abnormal parameters and check ret
228  */
229 HWTEST_F(VSyncDistributorTest, SetHighPriorityVSyncRate001, Function | MediumTest| Level3)
230 {
231     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(0, nullptr),
232               VSYNC_ERROR_INVALID_ARGUMENTS);
233     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, nullptr),
234               VSYNC_ERROR_INVALID_ARGUMENTS);
235     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
236     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
237 }
238 
239 /*
240 * Function: SetHighPriorityVSyncRate002
241 * Type: Function
242 * Rank: Important(2)
243 * EnvConditions: N/A
244 * CaseDescription: 1. call SetHighPriorityVSyncRate with normal parameters and check ret
245  */
246 HWTEST_F(VSyncDistributorTest, SetHighPriorityVSyncRate002, Function | MediumTest| Level3)
247 {
248     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
249     VSyncDistributorTest::vsyncDistributor->AddConnection(conn);
250     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_OK);
251     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(1, conn), VSYNC_ERROR_INVALID_ARGUMENTS);
252     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetHighPriorityVSyncRate(2, conn), VSYNC_ERROR_OK);
253 }
254 
255 /*
256 * Function: SetFrameIsRender001
257 * Type: Function
258 * Rank: Important(2)
259 * EnvConditions: N/A
260 * CaseDescription: 1. call SetFrameIsRender with render is true
261  */
262 HWTEST_F(VSyncDistributorTest, SetFrameIsRender001, Function | MediumTest| Level3)
263 {
264     VSyncDistributorTest::vsyncDistributor->SetFrameIsRender(true);
265 }
266 
267 /*
268 * Function: SetFrameIsRender002
269 * Type: Function
270 * Rank: Important(2)
271 * EnvConditions: N/A
272 * CaseDescription: 1. call SetFrameIsRender with render is false
273  */
274 HWTEST_F(VSyncDistributorTest, SetFrameIsRender002, Function | MediumTest| Level3)
275 {
276     VSyncDistributorTest::vsyncDistributor->SetFrameIsRender(false);
277 }
278 
279 /*
280 * Function: MarkRSAnimate001
281 * Type: Function
282 * Rank: Important(2)
283 * EnvConditions: N/A
284 * CaseDescription: 1. call MarkRSAnimate
285  */
286 HWTEST_F(VSyncDistributorTest, MarkRSAnimate001, Function | MediumTest| Level3)
287 {
288     VSyncDistributorTest::vsyncDistributor->MarkRSAnimate();
289 }
290 
291 /*
292 * Function: UnmarkRSAnimate001
293 * Type: Function
294 * Rank: Important(2)
295 * EnvConditions: N/A
296 * CaseDescription: 1. call UnmarkRSAnimate
297  */
298 HWTEST_F(VSyncDistributorTest, UnmarkRSAnimate001, Function | MediumTest| Level3)
299 {
300     VSyncDistributorTest::vsyncDistributor->UnmarkRSAnimate();
301 }
302 
303 /*
304 * Function: HasPendingUIRNV001
305 * Type: Function
306 * Rank: Important(2)
307 * EnvConditions: N/A
308 * CaseDescription: 1. call HasPendingUIRNV
309  */
310 HWTEST_F(VSyncDistributorTest, HasPendingUIRNV001, Function | MediumTest| Level3)
311 {
312     VSyncDistributorTest::vsyncDistributor->HasPendingUIRNV();
313 }
314 
315 /*
316 * Function: UpdatePendingReferenceTime001
317 * Type: Function
318 * Rank: Important(2)
319 * EnvConditions: N/A
320 * CaseDescription: 1. call UpdatePendingReferenceTime
321  */
322 HWTEST_F(VSyncDistributorTest, UpdatePendingReferenceTime001, Function | MediumTest| Level3)
323 {
324     int64_t timeStamp = 0;
325     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
326     VSyncDistributorTest::vsyncDistributor->SetUiDvsyncSwitch(true, conn);
327     VSyncDistributorTest::vsyncDistributor->UpdatePendingReferenceTime(timeStamp);
328 }
329 
330 /*
331 * Function: SetHardwareTaskNum001
332 * Type: Function
333 * Rank: Important(2)
334 * EnvConditions: N/A
335 * CaseDescription: 1. call SetHardwareTaskNum
336  */
337 HWTEST_F(VSyncDistributorTest, SetHardwareTaskNum001, Function | MediumTest| Level3)
338 {
339     uint32_t num = 0;
340     sptr<VSyncConnection> conn = new VSyncConnection(vsyncDistributor, "VSyncDistributorTest");
341     VSyncDistributorTest::vsyncDistributor->SetUiDvsyncSwitch(true, conn);
342     VSyncDistributorTest::vsyncDistributor->SetHardwareTaskNum(num);
343 }
344 
345 /*
346 * Function: GetUiCommandDelayTime001
347 * Type: Function
348 * Rank: Important(2)
349 * EnvConditions: N/A
350 * CaseDescription: 1. call GetUiCommandDelayTime
351  */
352 HWTEST_F(VSyncDistributorTest, GetUiCommandDelayTime001, Function | MediumTest| Level3)
353 {
354     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->GetUiCommandDelayTime(), 0);
355 }
356 
357 /*
358 * Function: SetUiDvsyncConfig001
359 * Type: Function
360 * Rank: Important(2)
361 * EnvConditions: N/A
362 * CaseDescription: 1. call SetUiDvsyncConfig
363  */
364 HWTEST_F(VSyncDistributorTest, SetUiDvsyncConfig001, Function | MediumTest| Level3)
365 {
366     uint32_t bufferCount = 2;
367     ASSERT_EQ(VSyncDistributorTest::vsyncDistributor->SetUiDvsyncConfig(bufferCount), VSYNC_ERROR_OK);
368 }
369 } // namespace
370 } // namespace Rosen
371 } // namespace OHOS