1 /*
2  * Copyright (c) 2022 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 "native_vsync.h"
17 
18 using namespace testing;
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace Rosen {
23 class NativeVsyncTest : public testing::Test {
24 public:
25     static void SetUpTestCase();
26     static void TearDownTestCase();
27 
28     static inline OH_NativeVSync* native_vsync = nullptr;
29 };
30 
SetUpTestCase()31 void NativeVsyncTest::SetUpTestCase()
32 {
33 }
34 
TearDownTestCase()35 void NativeVsyncTest::TearDownTestCase()
36 {
37 }
38 
OnVSync(long long timestamp,void * data)39 static void OnVSync(long long timestamp, void* data)
40 {
41     if (data != nullptr) {
42         delete (std::string *)data;
43         data = nullptr;
44     }
45 }
46 
47 namespace {
48 /*
49 * Function: OH_NativeVSync_Create
50 * Type: Function
51 * Rank: Important(2)
52 * EnvConditions: N/A
53 * CaseDescription: 1. call OH_NativeVSync_Create by abnormal input
54 *                  2. check ret
55  */
56 HWTEST_F(NativeVsyncTest, OH_NativeVSync_Create001, Function | MediumTest | Level2)
57 {
58     ASSERT_EQ(OH_NativeVSync_Create(nullptr, 0), nullptr);
59 }
60 
61 /*
62 * Function: OH_NativeVSync_Create
63 * Type: Function
64 * Rank: Important(2)
65 * EnvConditions: N/A
66 * CaseDescription: 1. call OH_NativeVSync_Create
67 *                  2. check ret
68  */
69 HWTEST_F(NativeVsyncTest, OH_NativeVSync_Create002, Function | MediumTest | Level2)
70 {
71     char name[] = "test";
72     native_vsync = OH_NativeVSync_Create(name, sizeof(name));
73     ASSERT_NE(native_vsync, nullptr);
74 }
75 
76 /*
77 * Function: OH_NativeVSync_RequestFrame
78 * Type: Function
79 * Rank: Important(2)
80 * EnvConditions: N/A
81 * CaseDescription: 1. call OH_NativeVSync_RequestFrame by abnormal input
82 *                  2. check ret
83  */
84 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrame001, Function | MediumTest | Level2)
85 {
86     ASSERT_NE(OH_NativeVSync_RequestFrame(nullptr, nullptr, nullptr), 0);
87 }
88 
89 /*
90 * Function: OH_NativeVSync_RequestFrame
91 * Type: Function
92 * Rank: Important(2)
93 * EnvConditions: N/A
94 * CaseDescription: 1. call OH_NativeVSync_RequestFrame by abnormal input
95 *                  2. check ret
96  */
97 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrame002, Function | MediumTest | Level2)
98 {
99     ASSERT_NE(OH_NativeVSync_RequestFrame(native_vsync, nullptr, nullptr), 0);
100 }
101 
102 /*
103 * Function: OH_NativeVSync_RequestFrame
104 * Type: Function
105 * Rank: Important(2)
106 * EnvConditions: N/A
107 * CaseDescription: 1. call OH_NativeVSync_RequestFrame
108 *                  2. check ret
109  */
110 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrame003, Function | MediumTest | Level2)
111 {
112     OH_NativeVSync_FrameCallback callback = OnVSync;
113     ASSERT_EQ(OH_NativeVSync_RequestFrame(native_vsync, callback, nullptr), 0);
114 }
115 
116 /*
117 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
118 * Type: Function
119 * Rank: Important(2)
120 * EnvConditions: N/A
121 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
122 *                  2. check ret
123  */
124 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback001, Function | MediumTest | Level2)
125 {
126     std::string *userData = new std::string("userData");
127     OH_NativeVSync_FrameCallback callback = OnVSync;
128     ASSERT_NE(OH_NativeVSync_RequestFrameWithMultiCallback(nullptr, callback, userData), 0);
129 }
130 
131 /*
132 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
133 * Type: Function
134 * Rank: Important(2)
135 * EnvConditions: N/A
136 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
137 *                  2. check ret
138  */
139 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback002, Function | MediumTest | Level2)
140 {
141     std::string *userData = new std::string("userData");
142     ASSERT_NE(OH_NativeVSync_RequestFrameWithMultiCallback(native_vsync, nullptr, userData), 0);
143 }
144 
145 /*
146 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
147 * Type: Function
148 * Rank: Important(2)
149 * EnvConditions: N/A
150 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
151 *                  2. check ret
152  */
153 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback003, Function | MediumTest | Level2)
154 {
155     OH_NativeVSync_FrameCallback callback = OnVSync;
156     ASSERT_EQ(OH_NativeVSync_RequestFrameWithMultiCallback(native_vsync, callback, nullptr), 0);
157 }
158 
159 /*
160 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
161 * Type: Function
162 * Rank: Important(2)
163 * EnvConditions: N/A
164 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
165 *                  2. check ret
166  */
167 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback004, Function | MediumTest | Level2)
168 {
169     std::string *userData = new std::string("userData");
170     ASSERT_NE(OH_NativeVSync_RequestFrameWithMultiCallback(nullptr, nullptr, userData), 0);
171 }
172 
173 /*
174 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
175 * Type: Function
176 * Rank: Important(2)
177 * EnvConditions: N/A
178 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
179 *                  2. check ret
180  */
181 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback005, Function | MediumTest | Level2)
182 {
183     OH_NativeVSync_FrameCallback callback = OnVSync;
184     ASSERT_NE(OH_NativeVSync_RequestFrameWithMultiCallback(nullptr, callback, nullptr), 0);
185 }
186 
187 /*
188 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
189 * Type: Function
190 * Rank: Important(2)
191 * EnvConditions: N/A
192 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
193 *                  2. check ret
194  */
195 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback006, Function | MediumTest | Level2)
196 {
197     ASSERT_NE(OH_NativeVSync_RequestFrameWithMultiCallback(native_vsync, nullptr, nullptr), 0);
198 }
199 
200 /*
201 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
202 * Type: Function
203 * Rank: Important(2)
204 * EnvConditions: N/A
205 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
206 *                  2. check ret
207  */
208 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback007, Function | MediumTest | Level2)
209 {
210     ASSERT_NE(OH_NativeVSync_RequestFrameWithMultiCallback(nullptr, nullptr, nullptr), 0);
211 }
212 
213 /*
214 * Function: OH_NativeVSync_RequestFrameWithMultiCallback
215 * Type: Function
216 * Rank: Important(2)
217 * EnvConditions: N/A
218 * CaseDescription: 1. call OH_NativeVSync_RequestFrameWithMultiCallback with abnormal parameters
219 *                  2. check ret
220  */
221 HWTEST_F(NativeVsyncTest, OH_NativeVSync_RequestFrameWithMultiCallback008, Function | MediumTest | Level2)
222 {
223     std::string *userData = new std::string("userData");
224     OH_NativeVSync_FrameCallback callback = OnVSync;
225     ASSERT_EQ(OH_NativeVSync_RequestFrameWithMultiCallback(native_vsync, callback, userData), 0);
226 }
227 
228 /*
229 * Function: OH_NativeVSync_DVSyncSwitch
230 * Type: Function
231 * Rank: Important(2)
232 * EnvConditions: N/A
233 * CaseDescription: 1. call OH_NativeVSync_DVSyncSwitch with abnormal parameters
234 *                  2. check ret
235  */
236 HWTEST_F(NativeVsyncTest, OH_NativeVSync_DVSyncSwitch001, Function | MediumTest | Level2)
237 {
238     ASSERT_NE(OH_NativeVSync_DVSyncSwitch(nullptr, true), 0);
239     ASSERT_NE(OH_NativeVSync_DVSyncSwitch(nullptr, false), 0);
240 }
241 
242 /*
243 * Function: OH_NativeVSync_DVSyncSwitch
244 * Type: Function
245 * Rank: Important(2)
246 * EnvConditions: N/A
247 * CaseDescription: 1. call OH_NativeVSync_DVSyncSwitch with abnormal parameters
248 *                  2. check ret
249  */
250 HWTEST_F(NativeVsyncTest, OH_NativeVSync_DVSyncSwitch002, Function | MediumTest | Level2)
251 {
252     ASSERT_EQ(OH_NativeVSync_DVSyncSwitch(native_vsync, true), 0);
253     ASSERT_EQ(OH_NativeVSync_DVSyncSwitch(native_vsync, false), 0);
254 }
255 
256 /*
257 * Function: OH_NativeVSync_Destroy
258 * Type: Function
259 * Rank: Important(2)
260 * EnvConditions: N/A
261 * CaseDescription: 1. call OH_NativeVSync_Destroy with abnormal input
262 *                  2. call OH_NativeVSync_Destroy with normal input
263  */
264 HWTEST_F(NativeVsyncTest, OH_NativeVSync_Destroy001, Function | MediumTest | Level2)
265 {
266     OH_NativeVSync_Destroy(nullptr);
267 
268     ASSERT_NE(native_vsync, nullptr);
269     OH_NativeVSync_Destroy(native_vsync);
270     native_vsync = nullptr;
271 }
272 
273 
274 /*
275 * Function: OH_NativeVSync_GetPeriod
276 * Type: Function
277 * Rank: Important(2)
278 * EnvConditions: N/A
279 * CaseDescription: 1. call OH_NativeVSync_GetPeriod by abnormal input
280 *                  2. check ret
281  */
282 HWTEST_F(NativeVsyncTest, OH_NativeVSync_GetPeriod001, Function | MediumTest | Level2)
283 {
284     ASSERT_NE(OH_NativeVSync_GetPeriod(nullptr, nullptr), 0);
285 }
286 
287 /*
288 * Function: OH_NativeVSync_GetPeriod
289 * Type: Function
290 * Rank: Important(2)
291 * EnvConditions: N/A
292 * CaseDescription: 1. call OH_NativeVSync_GetPeriod
293 *                  2. check ret
294  */
295 HWTEST_F(NativeVsyncTest, OH_NativeVSync_GetPeriod002, Function | MediumTest | Level2)
296 {
297     ASSERT_NE(OH_NativeVSync_GetPeriod(native_vsync, nullptr), 0);
298 }
299 
300 } // namespace
301 } // namespace Rosen
302 } // namespace OHOS