• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_Destroy
230 * Type: Function
231 * Rank: Important(2)
232 * EnvConditions: N/A
233 * CaseDescription: 1. call OH_NativeVSync_Destroy by abnormal input
234 *                  2. check ret
235  */
236 HWTEST_F(NativeVsyncTest, OH_NativeVSync_Destroy001, Function | MediumTest | Level2)
237 {
238     OH_NativeVSync_Destroy(nullptr);
239 }
240 
241 /*
242 * Function: OH_NativeVSync_Destroy
243 * Type: Function
244 * Rank: Important(2)
245 * EnvConditions: N/A
246 * CaseDescription: 1. call OH_NativeVSync_Destroy
247 *                  2. check ret
248  */
249 HWTEST_F(NativeVsyncTest, OH_NativeVSync_Destroy002, Function | MediumTest | Level2)
250 {
251     OH_NativeVSync_Destroy(native_vsync);
252 }
253 
254 /*
255 * Function: OH_NativeVSync_GetPeriod
256 * Type: Function
257 * Rank: Important(2)
258 * EnvConditions: N/A
259 * CaseDescription: 1. call OH_NativeVSync_GetPeriod by abnormal input
260 *                  2. check ret
261  */
262 HWTEST_F(NativeVsyncTest, OH_NativeVSync_GetPeriod001, Function | MediumTest | Level2)
263 {
264     ASSERT_NE(OH_NativeVSync_GetPeriod(nullptr, nullptr), 0);
265 }
266 
267 /*
268 * Function: OH_NativeVSync_GetPeriod
269 * Type: Function
270 * Rank: Important(2)
271 * EnvConditions: N/A
272 * CaseDescription: 1. call OH_NativeVSync_GetPeriod
273 *                  2. check ret
274  */
275 HWTEST_F(NativeVsyncTest, OH_NativeVSync_GetPeriod002, Function | MediumTest | Level2)
276 {
277     ASSERT_NE(OH_NativeVSync_GetPeriod(native_vsync, nullptr), 0);
278 }
279 
280 } // namespace
281 } // namespace Rosen
282 } // namespace OHOS