1 /*
2 * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development 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 "drawing_color.h"
17 #include "drawing_error_code.h"
18 #include "drawing_filter.h"
19 #include "drawing_mask_filter.h"
20 #include "drawing_rect.h"
21 #include "drawing_round_rect.h"
22 #include "utils/scalar.h"
23 #include "gtest/gtest.h"
24
25 using namespace testing;
26 using namespace testing::ext;
27
28 namespace OHOS {
29 namespace Rosen {
30 namespace Drawing {
31 class DrawingNativeRectTest : public testing::Test {};
32
33 /*
34 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0100
35 * @tc.name: testRectCreateNormal
36 * @tc.desc: Test for creating and destroying a rectangle object with normal parameters.
37 * @tc.size : SmallTest
38 * @tc.type : Function
39 * @tc.level : Level 0
40 */
HWTEST_F(DrawingNativeRectTest, testRectCreateNormal, TestSize.Level0)41 HWTEST_F(DrawingNativeRectTest, testRectCreateNormal, TestSize.Level0) {
42 // 1. Call OH_Drawing_RectCreate to create a rectangle object
43 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 200, 500, 600);
44 // 2. Free memory
45 OH_Drawing_RectDestroy(rect);
46 }
47
48 /*
49 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0200
50 * @tc.name: testRectIntersectNormal
51 * @tc.desc: Test for intersecting two rectangles with normal parameters.
52 * @tc.size : SmallTest
53 * @tc.type : Function
54 * @tc.level : Level 0
55 */
HWTEST_F(DrawingNativeRectTest, testRectIntersectNormal, TestSize.Level0)56 HWTEST_F(DrawingNativeRectTest, testRectIntersectNormal, TestSize.Level0) {
57 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
58 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 200, 500, 600);
59 // 2. Call OH_Drawing_RectCreate to create another rectangle object other
60 OH_Drawing_Rect *other = OH_Drawing_RectCreate(300, 400, 700, 800);
61 // 3. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect
62 OH_Drawing_RectSetLeft(rect, 0);
63 // 4. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect
64 OH_Drawing_RectSetTop(rect, 0);
65 // 5. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect
66 OH_Drawing_RectSetRight(rect, 200);
67 // 6. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect
68 OH_Drawing_RectSetBottom(rect, 200);
69 // 7. Repeat steps 3-6 to set the coordinates of the other rectangle object
70 OH_Drawing_RectSetLeft(other, 100);
71 OH_Drawing_RectSetTop(other, 100);
72 OH_Drawing_RectSetRight(other, 300);
73 OH_Drawing_RectSetBottom(other, 300);
74 // 8. Call OH_Drawing_RectIntersect to check if the two rectangles intersect, Returns true if they intersect,
75 // false otherwise
76 bool ret = OH_Drawing_RectIntersect(rect, other);
77 EXPECT_EQ(ret, true);
78 // 9. Free memory
79 OH_Drawing_RectDestroy(rect);
80 OH_Drawing_RectDestroy(other);
81 }
82
83 /*
84 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0201
85 * @tc.name: testRectIntersectNull
86 * @tc.desc: Test for intersecting rectangles with NULL parameters.
87 * @tc.size : SmallTest
88 * @tc.type : Function
89 * @tc.level : Level 3
90 */
HWTEST_F(DrawingNativeRectTest, testRectIntersectNull, TestSize.Level3)91 HWTEST_F(DrawingNativeRectTest, testRectIntersectNull, TestSize.Level3) {
92 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
93 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(100, 200, 500, 600);
94 // 2. Call OH_Drawing_RectCreate to create another rectangle object other
95 OH_Drawing_Rect *other = OH_Drawing_RectCreate(300, 400, 700, 800);
96 // 3. Call OH_Drawing_RectIntersect with the first parameter as nullptr, Returns error code
97 // OH_DRAWING_ERROR_INVALID_PARAMETER
98 OH_Drawing_RectIntersect(nullptr, other);
99 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
100 // 4. Call OH_Drawing_RectIntersect with the second parameter as nullptr, Returns error code
101 // OH_DRAWING_ERROR_INVALID_PARAMETER
102 OH_Drawing_RectIntersect(rect, nullptr);
103 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
104 // 5. Free memory
105 OH_Drawing_RectDestroy(rect);
106 OH_Drawing_RectDestroy(other);
107 }
108
109 /*
110 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0300
111 * @tc.name: testRectJoinNormal
112 * @tc.desc: Test for joining two rectangles with normal parameters.
113 * @tc.size : SmallTest
114 * @tc.type : Function
115 * @tc.level : Level 0
116 */
HWTEST_F(DrawingNativeRectTest, testRectJoinNormal, TestSize.Level0)117 HWTEST_F(DrawingNativeRectTest, testRectJoinNormal, TestSize.Level0) {
118 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
119 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
120 // 2. Call OH_Drawing_RectCreate to create another rectangle object other
121 OH_Drawing_Rect *other = OH_Drawing_RectCreate(100, 100, 300, 300);
122 // 3. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect
123 OH_Drawing_RectSetLeft(rect, 0);
124 // 4. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect
125 OH_Drawing_RectSetTop(rect, 0);
126 // 5. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect
127 OH_Drawing_RectSetRight(rect, 200);
128 // 6. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect
129 OH_Drawing_RectSetBottom(rect, 200);
130 // 7. Repeat steps 3-6 to set the coordinates of the other rectangle object
131 OH_Drawing_RectSetLeft(other, 100);
132 OH_Drawing_RectSetTop(other, 100);
133 OH_Drawing_RectSetRight(other, 300);
134 OH_Drawing_RectSetBottom(other, 300);
135 // 8. Call OH_Drawing_RectJoin to take the union of the two rectangles
136 bool ret = OH_Drawing_RectJoin(rect, other);
137 EXPECT_TRUE(ret);
138 // 9. Free memory
139 OH_Drawing_RectDestroy(rect);
140 OH_Drawing_RectDestroy(other);
141 }
142
143 /*
144 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0301
145 * @tc.name: testRectJoinNull
146 * @tc.desc: Test for joining rectangles with NULL parameters.
147 * @tc.size : SmallTest
148 * @tc.type : Function
149 * @tc.level : Level 3
150 */
HWTEST_F(DrawingNativeRectTest, testRectJoinNull, TestSize.Level3)151 HWTEST_F(DrawingNativeRectTest, testRectJoinNull, TestSize.Level3) {
152 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
153 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
154 // 2. Call OH_Drawing_RectCreate to create another rectangle object other
155 OH_Drawing_Rect *other = OH_Drawing_RectCreate(100, 100, 300, 300);
156 // 3. Call OH_Drawing_RectJoin with the first parameter as nullptr, Returns error code
157 // OH_DRAWING_ERROR_INVALID_PARAMETER
158 OH_Drawing_RectJoin(nullptr, other);
159 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
160 // 4. Call OH_Drawing_RectJoin with the second parameter as nullptr, Returns error code
161 // OH_DRAWING_ERROR_INVALID_PARAMETER
162 OH_Drawing_RectJoin(rect, nullptr);
163 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
164 // 5. Free memory
165 OH_Drawing_RectDestroy(rect);
166 OH_Drawing_RectDestroy(other);
167 }
168
169 /*
170 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0400
171 * @tc.name: testRectSetLeftNormal
172 * @tc.desc: Test for setting and getting the left coordinate of a rectangle with normal parameters.
173 * @tc.size : SmallTest
174 * @tc.type : Function
175 * @tc.level : Level 0
176 */
HWTEST_F(DrawingNativeRectTest, testRectSetLeftNormal, TestSize.Level0)177 HWTEST_F(DrawingNativeRectTest, testRectSetLeftNormal, TestSize.Level0) {
178 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
179 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
180 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect
181 OH_Drawing_RectSetLeft(rect, 100);
182 // 3. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of rect, Returns the value set
183 // in step 2
184 float left = OH_Drawing_RectGetLeft(rect);
185 EXPECT_TRUE(IsScalarAlmostEqual(left, 100));
186 // 4. Free memory
187 OH_Drawing_RectDestroy(rect);
188 }
189
190 /*
191 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0401
192 * @tc.name: testRectSetLeftNull
193 * @tc.desc: Test for setting the left coordinate of a rectangle with NULL parameters.
194 * @tc.size : SmallTest
195 * @tc.type : Function
196 * @tc.level : Level 3
197 */
HWTEST_F(DrawingNativeRectTest, testRectSetLeftNull, TestSize.Level3)198 HWTEST_F(DrawingNativeRectTest, testRectSetLeftNull, TestSize.Level3) {
199 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
200 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
201 // 2. Call OH_Drawing_RectSetLeft with the first parameter as nullptr, Returns error code
202 // OH_DRAWING_ERROR_INVALID_PARAMETER
203 OH_Drawing_RectSetLeft(nullptr, 0.00);
204 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
205 // 3. Call OH_Drawing_RectSetLeft with the second parameter as 0.00, Call fails without crashing
206 OH_Drawing_RectSetLeft(rect, 0.00);
207 // 4. Free memory
208 OH_Drawing_RectDestroy(rect);
209 }
210
211 /*
212 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0402
213 * @tc.name: testRectSetLeftAbnormal
214 * @tc.desc: Test for setting the left coordinate of a rectangle with abnormal parameters.
215 * @tc.size : SmallTest
216 * @tc.type : Function
217 * @tc.level : Level 3
218 */
HWTEST_F(DrawingNativeRectTest, testRectSetLeftAbnormal, TestSize.Level3)219 HWTEST_F(DrawingNativeRectTest, testRectSetLeftAbnormal, TestSize.Level3) {
220 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
221 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
222 // 2. Call OH_Drawing_RectSetLeft with the second parameter as an integer or character data
223 OH_Drawing_RectSetLeft(rect, 100);
224 // 3. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of rect, Returns the value set
225 // in step 2 (the passed parameter is forcibly converted)
226 float left = OH_Drawing_RectGetLeft(rect);
227 EXPECT_TRUE(IsScalarAlmostEqual(left, 100));
228 // 4. Free memory
229 OH_Drawing_RectDestroy(rect);
230 }
231
232 /*
233 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0403
234 * @tc.name: testRectSetLeftMultipleCalls
235 * @tc.desc: Test for repeatedly setting and getting the left coordinate of a rectangle.
236 * @tc.size : SmallTest
237 * @tc.type : Function
238 * @tc.level : Level 3
239 */
HWTEST_F(DrawingNativeRectTest, testRectSetLeftMultipleCalls, TestSize.Level3)240 HWTEST_F(DrawingNativeRectTest, testRectSetLeftMultipleCalls, TestSize.Level3) {
241 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
242 for (int i = 0; i < 10; i++) {
243 OH_Drawing_RectSetLeft(rect, i * 10);
244 float left = OH_Drawing_RectGetLeft(rect);
245 EXPECT_TRUE(IsScalarAlmostEqual(left, i * 10));
246 }
247 OH_Drawing_RectDestroy(rect);
248 }
249
250 /*
251 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0500
252 * @tc.name: testRectSetTopNormal
253 * @tc.desc: Test for setting and getting the top coordinate of a rectangle with normal parameters.
254 * @tc.size : SmallTest
255 * @tc.type : Function
256 * @tc.level : Level 0
257 */
HWTEST_F(DrawingNativeRectTest, testRectSetTopNormal, TestSize.Level0)258 HWTEST_F(DrawingNativeRectTest, testRectSetTopNormal, TestSize.Level0) {
259 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
260 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
261 // 2. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect
262 OH_Drawing_RectSetTop(rect, 100);
263 // 3. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect, Returns the value set in
264 // step 2
265 float top = OH_Drawing_RectGetTop(rect);
266 EXPECT_TRUE(IsScalarAlmostEqual(top, 100));
267 // 4. Free memory
268 OH_Drawing_RectDestroy(rect);
269 }
270
271 /*
272 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0501
273 * @tc.name: testRectSetTopNull
274 * @tc.desc: Test for setting the top coordinate of a rectangle with NULL parameters.
275 * @tc.size : SmallTest
276 * @tc.type : Function
277 * @tc.level : Level 3
278 */
HWTEST_F(DrawingNativeRectTest, testRectSetTopNull, TestSize.Level3)279 HWTEST_F(DrawingNativeRectTest, testRectSetTopNull, TestSize.Level3) {
280 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
281 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
282 // 2. Call OH_Drawing_RectSetTop with the first parameter as nullptr, Returns error code
283 // OH_DRAWING_ERROR_INVALID_PARAMETER
284 OH_Drawing_RectSetTop(nullptr, 0.00);
285 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
286 // 3. Call OH_Drawing_RectSetTop with the second parameter as 0.00, Call fails without crashing
287 OH_Drawing_RectSetTop(rect, 0.00);
288 // 4. Free memory
289 OH_Drawing_RectDestroy(rect);
290 }
291
292 /*
293 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0502
294 * @tc.name: testRectSetTopAbnormal
295 * @tc.desc: Test for setting the top coordinate of a rectangle with abnormal parameters.
296 * @tc.size : SmallTest
297 * @tc.type : Function
298 * @tc.level : Level 3
299 */
HWTEST_F(DrawingNativeRectTest, testRectSetTopAbnormal, TestSize.Level3)300 HWTEST_F(DrawingNativeRectTest, testRectSetTopAbnormal, TestSize.Level3) {
301 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
302 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
303 // 2. Call OH_Drawing_RectSetTop with the second parameter as an integer or character data
304 OH_Drawing_RectSetTop(rect, 100);
305 // 3. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect, Returns the value set in
306 // step 2 (the passed parameter is forcibly converted)
307 float top = OH_Drawing_RectGetTop(rect);
308 EXPECT_TRUE(IsScalarAlmostEqual(top, 100));
309 // 4. Free memory
310 OH_Drawing_RectDestroy(rect);
311 }
312
313 /*
314 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0503
315 * @tc.name: testRectSetTopMultipleCalls
316 * @tc.desc: Test for repeatedly setting and getting the top coordinate of a rectangle.
317 * @tc.size : SmallTest
318 * @tc.type : Function
319 * @tc.level : Level 3
320 */
HWTEST_F(DrawingNativeRectTest, testRectSetTopMultipleCalls, TestSize.Level3)321 HWTEST_F(DrawingNativeRectTest, testRectSetTopMultipleCalls, TestSize.Level3) {
322 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
323 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
324 // 2. Loop to call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect 10 times (each time
325 // with a different value)
326 for (int i = 0; i < 10; i++) {
327 OH_Drawing_RectSetTop(rect, i * 10);
328 // 3. Loop to call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect 10 times, Each
329 // time the returned value is consistent with the set value
330 float top = OH_Drawing_RectGetTop(rect);
331 EXPECT_TRUE(IsScalarAlmostEqual(top, i * 10));
332 }
333 // 3. Loop to call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect 10 times, Each time
334 // the returned value is consistent with the set value
335 for (int i = 0; i < 10; i++) {
336 OH_Drawing_RectSetTop(rect, 10);
337 // 3. Loop to call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect 10 times, Each
338 // time the returned value is consistent with the set value
339 float top = OH_Drawing_RectGetTop(rect);
340 EXPECT_TRUE(IsScalarAlmostEqual(top, 10));
341 }
342 // 4. Free memory
343 OH_Drawing_RectDestroy(rect);
344 }
345
346 /*
347 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0600
348 * @tc.name: testRectSetRightNormal
349 * @tc.desc: Test for setting and getting the right coordinate of a rectangle with normal parameters.
350 * @tc.size : SmallTest
351 * @tc.type : Function
352 * @tc.level : Level 0
353 */
HWTEST_F(DrawingNativeRectTest, testRectSetRightNormal, TestSize.Level0)354 HWTEST_F(DrawingNativeRectTest, testRectSetRightNormal, TestSize.Level0) {
355 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
356 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
357 // 2. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect
358 OH_Drawing_RectSetRight(rect, 300);
359 // 3. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect, Returns the value set
360 // in step 2
361 float right = OH_Drawing_RectGetRight(rect);
362 EXPECT_TRUE(IsScalarAlmostEqual(right, 300));
363 // 4. Free memory
364 OH_Drawing_RectDestroy(rect);
365 }
366
367 /*
368 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0601
369 * @tc.name: testRectSetRightNull
370 * @tc.desc: Test for setting the right coordinate of a rectangle with NULL parameters.
371 * @tc.size : SmallTest
372 * @tc.type : Function
373 * @tc.level : Level 3
374 */
HWTEST_F(DrawingNativeRectTest, testRectSetRightNull, TestSize.Level3)375 HWTEST_F(DrawingNativeRectTest, testRectSetRightNull, TestSize.Level3) {
376 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
377 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
378 // 2. Call OH_Drawing_RectSetRight with the first parameter as nullptr, Returns error code
379 // OH_DRAWING_ERROR_INVALID_PARAMETER
380 OH_Drawing_RectSetRight(nullptr, 0.00);
381 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
382 // 3. Call OH_Drawing_RectSetRight with the second parameter as 0.00, 3. Call fails without crashing
383 OH_Drawing_RectSetRight(rect, 0.00);
384 // 4. Free memory
385 OH_Drawing_RectDestroy(rect);
386 }
387
388 /*
389 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0602
390 * @tc.name: testRectSetRightAbnormal
391 * @tc.desc: Test for setting the right coordinate of a rectangle with abnormal parameters.
392 * @tc.size : SmallTest
393 * @tc.type : Function
394 * @tc.level : Level 3
395 */
HWTEST_F(DrawingNativeRectTest, testRectSetRightAbnormal, TestSize.Level3)396 HWTEST_F(DrawingNativeRectTest, testRectSetRightAbnormal, TestSize.Level3) {
397 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
398 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
399 // 2. Call OH_Drawing_RectSetRight with the second parameter as an integer or character data
400 OH_Drawing_RectSetRight(rect, 100);
401 // 3. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect, Returns the value set
402 // in step 2 (the passed parameter is forcibly converted)
403 float right = OH_Drawing_RectGetRight(rect);
404 EXPECT_TRUE(IsScalarAlmostEqual(right, 100));
405 // 4. Free memory
406 OH_Drawing_RectDestroy(rect);
407 }
408
409 /*
410 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0603
411 * @tc.name: testRectSetRightMultipleCalls
412 * @tc.desc: Test for repeatedly setting and getting the right coordinate of a rectangle.
413 * @tc.size : SmallTest
414 * @tc.type : Function
415 * @tc.level : Level 3
416 */
HWTEST_F(DrawingNativeRectTest, testRectSetRightMultipleCalls, TestSize.Level3)417 HWTEST_F(DrawingNativeRectTest, testRectSetRightMultipleCalls, TestSize.Level3) {
418 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
419 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
420 // 2. Loop to call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect 10 times (each
421 // time with a different value)
422 for (int i = 0; i < 10; i++) {
423 OH_Drawing_RectSetRight(rect, i * 10);
424 // 3. Loop to call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect 10 times,
425 // Each time the returned value is consistent with the set value
426 float right = OH_Drawing_RectGetRight(rect);
427 EXPECT_TRUE(IsScalarAlmostEqual(right, i * 10));
428 }
429 // 3. Loop to call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect 10 times, Each
430 // time the returned value is consistent with the set value
431 for (int i = 0; i < 10; i++) {
432 OH_Drawing_RectSetRight(rect, 10);
433 // 3. Loop to call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect 10 times,
434 // Each time the returned value is consistent with the set value
435 float right = OH_Drawing_RectGetRight(rect);
436 EXPECT_TRUE(IsScalarAlmostEqual(right, 10));
437 }
438 // 4. Free memory
439 OH_Drawing_RectDestroy(rect);
440 }
441
442 /*
443 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0700
444 * @tc.name: testRectSetBottomNormal
445 * @tc.desc: Test for setting and getting the bottom coordinate of a rectangle with normal parameters.
446 * @tc.size : SmallTest
447 * @tc.type : Function
448 * @tc.level : Level 0
449 */
HWTEST_F(DrawingNativeRectTest, testRectSetBottomNormal, TestSize.Level0)450 HWTEST_F(DrawingNativeRectTest, testRectSetBottomNormal, TestSize.Level0) {
451 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
452 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
453 // 2. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect
454 OH_Drawing_RectSetBottom(rect, 300);
455 // 3. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of rect, 3. Returns the value
456 // set in step 2
457 float bottom = OH_Drawing_RectGetBottom(rect);
458 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 300));
459 // 4. Free memory
460 OH_Drawing_RectDestroy(rect);
461 }
462
463 /*
464 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0701
465 * @tc.name: testRectSetBottomNull
466 * @tc.desc: Test for setting the bottom coordinate of a rectangle with NULL parameters.
467 * @tc.size : SmallTest
468 * @tc.type : Function
469 * @tc.level : Level 3
470 */
HWTEST_F(DrawingNativeRectTest, testRectSetBottomNull, TestSize.Level3)471 HWTEST_F(DrawingNativeRectTest, testRectSetBottomNull, TestSize.Level3) {
472 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
473 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
474 // 2. Call OH_Drawing_RectSetBottom with the first parameter as nullptr, returns error code
475 // OH_DRAWING_ERROR_INVALID_PARAMETER
476 OH_Drawing_RectSetBottom(nullptr, 0.00);
477 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
478 // 3. Call OH_Drawing_RectSetBottom with the second parameter as 0.00, the call fails without crashing
479 OH_Drawing_RectSetBottom(rect, 0.00);
480 // 4. Free memory
481 OH_Drawing_RectDestroy(rect);
482 }
483
484 /*
485 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0702
486 * @tc.name: testRectSetBottomAbnormal
487 * @tc.desc: Test for setting the bottom coordinate of a rectangle with abnormal parameters.
488 * @tc.size : SmallTest
489 * @tc.type : Function
490 * @tc.level : Level 3
491 */
HWTEST_F(DrawingNativeRectTest, testRectSetBottomAbnormal, TestSize.Level3)492 HWTEST_F(DrawingNativeRectTest, testRectSetBottomAbnormal, TestSize.Level3) {
493 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
494 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
495 // 2. Call OH_Drawing_RectSetBottom with the second parameter as an integer or character data
496 OH_Drawing_RectSetBottom(rect, 100);
497 // 3. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of rect
498 float bottom = OH_Drawing_RectGetBottom(rect);
499 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 100));
500 // 4. Free memory
501 OH_Drawing_RectDestroy(rect);
502 }
503
504 /*
505 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0703
506 * @tc.name: testRectSetBottomMultipleCalls
507 * @tc.desc: Test for repeatedly setting and getting the bottom coordinate of a rectangle.
508 * @tc.size : SmallTest
509 * @tc.type : Function
510 * @tc.level : Level 3
511 */
HWTEST_F(DrawingNativeRectTest, testRectSetBottomMultipleCalls, TestSize.Level3)512 HWTEST_F(DrawingNativeRectTest, testRectSetBottomMultipleCalls, TestSize.Level3) {
513 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
514
515 for (int i = 0; i < 10; i++) {
516 OH_Drawing_RectSetBottom(rect, i * 10);
517 float bottom = OH_Drawing_RectGetBottom(rect);
518 EXPECT_TRUE(IsScalarAlmostEqual(bottom, i * 10));
519 }
520
521 OH_Drawing_RectDestroy(rect);
522 }
523
524 /*
525 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0800
526 * @tc.name: testRectGetLeftNormal
527 * @tc.desc: Test for setting and getting the left coordinate of a rectangle with normal parameters.
528 * @tc.size : SmallTest
529 * @tc.type : Function
530 * @tc.level : Level 0
531 */
HWTEST_F(DrawingNativeRectTest, testRectGetLeftNormal, TestSize.Level0)532 HWTEST_F(DrawingNativeRectTest, testRectGetLeftNormal, TestSize.Level0) {
533 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
534 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
535 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect
536 OH_Drawing_RectSetLeft(rect, 100);
537 // 3. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of rect
538 float left = OH_Drawing_RectGetLeft(rect);
539 EXPECT_TRUE(IsScalarAlmostEqual(left, 100));
540 // 4. Free memory
541 OH_Drawing_RectDestroy(rect);
542 }
543
544 /*
545 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0801
546 * @tc.name: testRectGetLeftNull
547 * @tc.desc: Test for getting the left coordinate of a rectangle with NULL parameters.
548 * @tc.size : SmallTest
549 * @tc.type : Function
550 * @tc.level : Level 3
551 */
HWTEST_F(DrawingNativeRectTest, testRectGetLeftNull, TestSize.Level3)552 HWTEST_F(DrawingNativeRectTest, testRectGetLeftNull, TestSize.Level3) {
553 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
554 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
555 // 2. Call OH_Drawing_RectGetLeft with nullptr as the parameter
556 OH_Drawing_RectGetLeft(nullptr);
557 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
558 // 3. Free memory
559 OH_Drawing_RectDestroy(rect);
560 }
561
562 /*
563 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0900
564 * @tc.name: testRectGetTopNormal
565 * @tc.desc: Test for setting and getting the top coordinate of a rectangle with normal parameters.
566 * @tc.size : SmallTest
567 * @tc.type : Function
568 * @tc.level : Level 0
569 */
HWTEST_F(DrawingNativeRectTest, testRectGetTopNormal, TestSize.Level0)570 HWTEST_F(DrawingNativeRectTest, testRectGetTopNormal, TestSize.Level0) {
571 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
572 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
573 // 2. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect
574 OH_Drawing_RectSetTop(rect, 100);
575 // 3. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of rect
576 float top = OH_Drawing_RectGetTop(rect);
577 EXPECT_TRUE(IsScalarAlmostEqual(top, 100));
578 // 4. Free memory
579 OH_Drawing_RectDestroy(rect);
580 }
581
582 /*
583 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_0901
584 * @tc.name: testRectGetTopNull
585 * @tc.desc: Test for getting the top coordinate of a rectangle with NULL parameters.
586 * @tc.size : SmallTest
587 * @tc.type : Function
588 * @tc.level : Level 3
589 */
HWTEST_F(DrawingNativeRectTest, testRectGetTopNull, TestSize.Level3)590 HWTEST_F(DrawingNativeRectTest, testRectGetTopNull, TestSize.Level3) {
591 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
592 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
593 // 2. Call OH_Drawing_RectGetTop with nullptr as the parameter
594 OH_Drawing_RectGetTop(nullptr);
595 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
596 // 3. Free memory
597 OH_Drawing_RectDestroy(rect);
598 }
599
600 /*
601 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1000
602 * @tc.name: testRectGetRightNormal
603 * @tc.desc: Test for setting and getting the right coordinate of a rectangle with normal parameters.
604 * @tc.size : SmallTest
605 * @tc.type : Function
606 * @tc.level : Level 0
607 */
HWTEST_F(DrawingNativeRectTest, testRectGetRightNormal, TestSize.Level0)608 HWTEST_F(DrawingNativeRectTest, testRectGetRightNormal, TestSize.Level0) {
609 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
610 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
611 // 2. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect
612 OH_Drawing_RectSetRight(rect, 300);
613 // 3. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of rect
614 float right = OH_Drawing_RectGetRight(rect);
615 EXPECT_TRUE(IsScalarAlmostEqual(right, 300));
616 // 4. Free memory
617 OH_Drawing_RectDestroy(rect);
618 }
619
620 /*
621 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1001
622 * @tc.name: testRectGetRightNull
623 * @tc.desc: Test for getting the right coordinate of a rectangle with NULL parameters.
624 * @tc.size : SmallTest
625 * @tc.type : Function
626 * @tc.level : Level 3
627 */
HWTEST_F(DrawingNativeRectTest, testRectGetRightNull, TestSize.Level3)628 HWTEST_F(DrawingNativeRectTest, testRectGetRightNull, TestSize.Level3) {
629 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
630 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
631 // 2. Call OH_Drawing_RectGetRight with nullptr as the parameter, returns error code
632 // OH_DRAWING_ERROR_INVALID_PARAMETER
633 OH_Drawing_RectGetRight(nullptr);
634 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
635 // 3. Free memory
636 OH_Drawing_RectDestroy(rect);
637 }
638
639 /*
640 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1100
641 * @tc.name: testRectGetBottomNormal
642 * @tc.desc: Test for setting and getting the bottom coordinate of a rectangle with normal parameters.
643 * @tc.size : SmallTest
644 * @tc.type : Function
645 * @tc.level : Level 0
646 */
HWTEST_F(DrawingNativeRectTest, testRectGetBottomNormal, TestSize.Level0)647 HWTEST_F(DrawingNativeRectTest, testRectGetBottomNormal, TestSize.Level0) {
648 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
649 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
650 // 2. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect
651 OH_Drawing_RectSetBottom(rect, 300);
652 // 3. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of rect, the return value
653 // should be the same as the set value
654 float bottom = OH_Drawing_RectGetBottom(rect);
655 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 300));
656 // 4. Free memory
657 OH_Drawing_RectDestroy(rect);
658 }
659
660 /*
661 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1101
662 * @tc.name: testRectGetBottomNull
663 * @tc.desc: Test for getting the bottom coordinate of a rectangle with NULL parameters.
664 * @tc.size : SmallTest
665 * @tc.type : Function
666 * @tc.level : Level 3
667 */
HWTEST_F(DrawingNativeRectTest, testRectGetBottomNull, TestSize.Level3)668 HWTEST_F(DrawingNativeRectTest, testRectGetBottomNull, TestSize.Level3) {
669 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
670 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
671 // 2. Call OH_Drawing_RectGetBottom with nullptr as the parameter, returns error code
672 // OH_DRAWING_ERROR_INVALID_PARAMETER
673 OH_Drawing_RectGetBottom(nullptr);
674 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
675 // 3. Free memory
676 OH_Drawing_RectDestroy(rect);
677 }
678
679 /*
680 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1200
681 * @tc.name: testRectGetHeightNormal
682 * @tc.desc: Test for setting coordinates and getting the height of a rectangle with normal parameters.
683 * @tc.size : SmallTest
684 * @tc.type : Function
685 * @tc.level : Level 0
686 */
HWTEST_F(DrawingNativeRectTest, testRectGetHeightNormal, TestSize.Level0)687 HWTEST_F(DrawingNativeRectTest, testRectGetHeightNormal, TestSize.Level0) {
688 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
689 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
690 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of rect
691 OH_Drawing_RectSetLeft(rect, 0);
692 // 3. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of rect
693 OH_Drawing_RectSetTop(rect, 0);
694 // 4. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of rect
695 OH_Drawing_RectSetRight(rect, 200);
696 // 5. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of rect
697 OH_Drawing_RectSetBottom(rect, 200);
698 // 6. Call OH_Drawing_RectGetHeight to get the height of the rectangle, which is the difference between the
699 // y-coordinate of the bottom-right corner and the y-coordinate of the top-left corner
700 float height = OH_Drawing_RectGetHeight(rect);
701 EXPECT_TRUE(IsScalarAlmostEqual(height, 200 - 0));
702 // 7. Free memory
703 OH_Drawing_RectDestroy(rect);
704 }
705
706 /*
707 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1201
708 * @tc.name: testRectGetHeightNull
709 * @tc.desc: Test for getting the height of a rectangle with NULL parameters.
710 * @tc.size : SmallTest
711 * @tc.type : Function
712 * @tc.level : Level 3
713 */
HWTEST_F(DrawingNativeRectTest, testRectGetHeightNull, TestSize.Level3)714 HWTEST_F(DrawingNativeRectTest, testRectGetHeightNull, TestSize.Level3) {
715 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
716 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
717 // 2. Call OH_Drawing_RectGetHeight with nullptr as the parameter, returns error code
718 // OH_DRAWING_ERROR_INVALID_PARAMETER
719 OH_Drawing_RectGetHeight(nullptr);
720 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
721 // 3. Free memory
722 OH_Drawing_RectDestroy(rect);
723 }
724
725 /*
726 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1300
727 * @tc.name: testRectGetWidthNormal
728 * @tc.desc: Test for setting coordinates and getting the width of a rectangle with normal parameters.
729 * @tc.size : SmallTest
730 * @tc.type : Function
731 * @tc.level : Level 0
732 */
HWTEST_F(DrawingNativeRectTest, testRectGetWidthNormal, TestSize.Level0)733 HWTEST_F(DrawingNativeRectTest, testRectGetWidthNormal, TestSize.Level0) {
734 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
735 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
736 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner
737 OH_Drawing_RectSetLeft(rect, 0);
738 // 3. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner
739 OH_Drawing_RectSetTop(rect, 0);
740 // 4. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner
741 OH_Drawing_RectSetRight(rect, 200);
742 // 5. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner
743 OH_Drawing_RectSetBottom(rect, 200);
744 // 6. Call OH_Drawing_RectGetWidth to get the width of the rectangle, which is the difference between the
745 // x-coordinate of the bottom-right corner and the x-coordinate of the top-left corner
746 float width = OH_Drawing_RectGetWidth(rect);
747 EXPECT_TRUE(IsScalarAlmostEqual(width, 200 - 0));
748 // 7. Free memory
749 OH_Drawing_RectDestroy(rect);
750 }
751
752 /*
753 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1301
754 * @tc.name: testRectGetWidthNull
755 * @tc.desc: Test for getting the width of a rectangle with NULL parameters.
756 * @tc.size : SmallTest
757 * @tc.type : Function
758 * @tc.level : Level 3
759 */
HWTEST_F(DrawingNativeRectTest, testRectGetWidthNull, TestSize.Level3)760 HWTEST_F(DrawingNativeRectTest, testRectGetWidthNull, TestSize.Level3) {
761 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
762 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
763 // 2. Call OH_Drawing_RectGetWidth with nullptr as the parameter, returns error code
764 // OH_DRAWING_ERROR_INVALID_PARAMETER
765 OH_Drawing_RectGetWidth(nullptr);
766 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
767 // 3. Free memory
768 OH_Drawing_RectDestroy(rect);
769 }
770
771 /*
772 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1302
773 * @tc.name: testRectGetWidthBoundary
774 * @tc.desc: Test for setting coordinates and getting the width of a rectangle with normal parameters.
775 * @tc.size : SmallTest
776 * @tc.type : Function
777 * @tc.level : Level 0
778 */
HWTEST_F(DrawingNativeRectTest, testRectGetWidthBoundary, TestSize.Level0)779 HWTEST_F(DrawingNativeRectTest, testRectGetWidthBoundary, TestSize.Level0) {
780 // 1. Call OH_Drawing_RectCreate to create a rectangle object rect
781 uint32_t width = 4096;
782 uint32_t height = 2160;
783 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, width, height);
784 // 2. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner
785 OH_Drawing_RectSetLeft(rect, 0);
786 // 3. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner
787 OH_Drawing_RectSetTop(rect, 0);
788 // 4. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner
789 OH_Drawing_RectSetRight(rect, width);
790 // 5. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner
791 OH_Drawing_RectSetBottom(rect, height);
792 // 6. Call OH_Drawing_RectGetWidth to get the width of the rectangle, which is the difference between the
793 // x-coordinate of the bottom-right corner and the x-coordinate of the top-left corner
794 float getWidth = OH_Drawing_RectGetWidth(rect);
795 EXPECT_TRUE(IsScalarAlmostEqual(getWidth, width - 0));
796 // 7. Free memory
797 OH_Drawing_RectDestroy(rect);
798 }
799
800 /*
801 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1400
802 * @tc.name: testRectCopyNormal
803 * @tc.desc: Test for copying a rectangle with normal parameters and checking the copied values.
804 * @tc.size : SmallTest
805 * @tc.type : Function
806 * @tc.level : Level 0
807 */
HWTEST_F(DrawingNativeRectTest, testRectCopyNormal, TestSize.Level0)808 HWTEST_F(DrawingNativeRectTest, testRectCopyNormal, TestSize.Level0) {
809 // 1. Call OH_Drawing_RectCreate to create a rectangle object src
810 OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, 200, 200);
811 // 2. Call OH_Drawing_RectCreate to create a rectangle object dst
812 OH_Drawing_Rect *dst = OH_Drawing_RectCreate(0, 0, 0, 0);
813 // 3. Call OH_Drawing_RectSetLeft to set the x-coordinate of the top-left corner of src
814 OH_Drawing_RectSetLeft(src, 100);
815 // 4. Call OH_Drawing_RectSetTop to set the y-coordinate of the top-left corner of src
816 OH_Drawing_RectSetTop(src, 100);
817 // 5. Call OH_Drawing_RectSetRight to set the x-coordinate of the bottom-right corner of src
818 OH_Drawing_RectSetRight(src, 300);
819 // 6. Call OH_Drawing_RectSetBottom to set the y-coordinate of the bottom-right corner of src
820 OH_Drawing_RectSetBottom(src, 300);
821 // 7. Call OH_Drawing_RectCopy to copy the source rectangle object src to the destination rectangle object dst
822 OH_Drawing_RectCopy(src, dst);
823 // 8. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of dst, which should be the same as
824 // the value set in src
825 float left = OH_Drawing_RectGetLeft(dst);
826 EXPECT_TRUE(IsScalarAlmostEqual(left, 100));
827 // 9. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of dst, which should be the same as
828 // the value set in src
829 float top = OH_Drawing_RectGetTop(dst);
830 EXPECT_TRUE(IsScalarAlmostEqual(top, 100));
831 // 10. Call OH_Drawing_RectGetRight to get the x-coordinate of the bottom-right corner of dst, which should be the
832 // same as the value set in src
833 float right = OH_Drawing_RectGetRight(dst);
834 EXPECT_TRUE(IsScalarAlmostEqual(right, 300));
835 // 11. Call OH_Drawing_RectGetBottom to get the y-coordinate of the bottom-right corner of dst, which should be the
836 // same as the value set in src
837 float bottom = OH_Drawing_RectGetBottom(dst);
838 EXPECT_TRUE(IsScalarAlmostEqual(bottom, 300));
839 // 12. Call OH_Drawing_RectSetLeft to modify the x-coordinate of the top-left corner of src
840 OH_Drawing_RectSetLeft(src, 200);
841 // 13. Call OH_Drawing_RectSetTop to modify the y-coordinate of the top-left corner of src
842 OH_Drawing_RectSetTop(src, 200);
843 // 14. Call OH_Drawing_RectGetLeft to get the x-coordinate of the top-left corner of dst, which should be the same
844 // as the previous value (indicating that the modification in src does not affect the result in dst)
845 left = OH_Drawing_RectGetLeft(dst);
846 EXPECT_TRUE(IsScalarAlmostEqual(left, 100));
847 // 15. Call OH_Drawing_RectGetTop to get the y-coordinate of the top-left corner of dst, which should be the same as
848 // the previous value (indicating that the modification in src does not affect the result in dst)
849 top = OH_Drawing_RectGetTop(dst);
850 EXPECT_TRUE(IsScalarAlmostEqual(top, 100));
851 // 16. Free memory
852 OH_Drawing_RectDestroy(src);
853 OH_Drawing_RectDestroy(dst);
854 }
855
856 /*
857 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1401
858 * @tc.name: testRectCopyNull
859 * @tc.desc: Test for copying a rectangle with NULL parameters.
860 * @tc.size : SmallTest
861 * @tc.type : Function
862 * @tc.level : Level 3
863 */
HWTEST_F(DrawingNativeRectTest, testRectCopyNull, TestSize.Level3)864 HWTEST_F(DrawingNativeRectTest, testRectCopyNull, TestSize.Level3) {
865 // 1. Call OH_Drawing_RectCreate to create a rectangle object src
866 OH_Drawing_Rect *src = OH_Drawing_RectCreate(0, 0, 200, 200);
867 // 2. Call OH_Drawing_RectCreate to create a rectangle object dst
868 OH_Drawing_Rect *dst = OH_Drawing_RectCreate(0, 0, 0, 0);
869 // 3. Call OH_Drawing_RectCopy with nullptr as the first parameter, returns error code
870 // OH_DRAWING_ERROR_INVALID_PARAMETER
871 OH_Drawing_RectCopy(nullptr, dst);
872 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
873 // 4. Call OH_Drawing_RectCopy with nullptr as the second parameter, returns error code
874 // OH_DRAWING_ERROR_INVALID_PARAMETER
875 OH_Drawing_RectCopy(src, nullptr);
876 EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
877 // 5. Free memory
878 OH_Drawing_RectDestroy(src);
879 OH_Drawing_RectDestroy(dst);
880 }
881
882 /*
883 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1500
884 * @tc.name: testRectDestroyNormal
885 * @tc.desc: Test for creating and destroying a rectangle object with normal parameters.
886 * @tc.size : SmallTest
887 * @tc.type : Function
888 * @tc.level : Level 0
889 */
HWTEST_F(DrawingNativeRectTest, testRectDestroyNormal, TestSize.Level0)890 HWTEST_F(DrawingNativeRectTest, testRectDestroyNormal, TestSize.Level0) {
891 // 1. Call OH_Drawing_RectCreate to create a rectangle object
892 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
893 // 2. Call OH_Drawing_RectDestroy to destroy the rectangle object
894 OH_Drawing_RectDestroy(rect);
895 }
896
897 /*
898 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_RECT_1501
899 * @tc.name: testRectDestroyNull
900 * @tc.desc: Test for destroying a rectangle object with NULL parameters.
901 * @tc.size : SmallTest
902 * @tc.type : Function
903 * @tc.level : Level 3
904 */
HWTEST_F(DrawingNativeRectTest, testRectDestroyNull, TestSize.Level3)905 HWTEST_F(DrawingNativeRectTest, testRectDestroyNull, TestSize.Level3) {
906 // 1. Call OH_Drawing_RectCreate to create a rectangle object
907 OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 200, 200);
908 // 2. Call OH_Drawing_RectDestroy with nullptr as the parameter, returns error code
909 // OH_DRAWING_ERROR_INVALID_PARAMETER
910 OH_Drawing_RectDestroy(nullptr);
911 // 3. Call OH_Drawing_RectDestroy to destroy the rectangle object
912 OH_Drawing_RectDestroy(rect);
913 }
914
915 } // namespace Drawing
916 } // namespace Rosen
917 } // namespace OHOS