• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gtest/gtest.h"
17 
18 #include "drawing_error_code.h"
19 #include "drawing_path.h"
20 #include "drawing_point.h"
21 #include "drawing_rect.h"
22 #include "drawing_region.h"
23 
24 using namespace testing;
25 using namespace testing::ext;
26 
27 namespace OHOS {
28 namespace Rosen {
29 namespace Drawing {
30 class DrawingNativeRegionTest : public testing::Test {
31     protected:
32     // 在每个测试用例执行前调用
SetUp()33     void SetUp() override
34     {
35         // 设置代码
36         std::cout << "DrawingNativeRegionTest Setup code called before each test case." << std::endl;
37         OH_Drawing_ErrorCodeReset();
38         std::cout << "DrawingNativeRegionTest errorCodeReset before each test case." << std::endl;
39     }
TearDown()40     void TearDown() override
41     {
42         std::cout << "DrawingNativeRegionTest Setup code called after each test case." << std::endl;
43         OH_Drawing_ErrorCodeReset();
44         std::cout << "DrawingNativeRegionTest errorCodeReset after each test case." << std::endl;
45     }
46 };
47 
48 /*
49  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0100
50  * @tc.name: testRegionCreateNormal
51  * @tc.desc: test for testRegionCreateNormal.
52  * @tc.size  : SmallTest
53  * @tc.type  : Function
54  * @tc.level : Level 0
55  */
56 HWTEST_F(DrawingNativeRegionTest, testRegionCreateNormal, Function | SmallTest | Level0) {
57     // 1. OH_Drawing_RegionCreate
58     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
59     EXPECT_NE(region, nullptr);
60     OH_Drawing_RegionDestroy(region);
61 }
62 
63 /*
64  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0101
65  * @tc.name: testRegionCreateMoreTimes
66  * @tc.desc: test for testRegionCreateMoreTimes.
67  * @tc.size  : SmallTest
68  * @tc.type  : Function
69  * @tc.level : Level 1
70  */
71 HWTEST_F(DrawingNativeRegionTest, testRegionCreateMoreTimes, Function | SmallTest | Level1) {
72     // 1. OH_Drawing_RegionCreate
73     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
74     EXPECT_NE(region, nullptr);
75 
76     // 2. Create another region object using OH_Drawing_RegionCreate
77     OH_Drawing_Region *region2 = OH_Drawing_RegionCreate();
78     EXPECT_NE(region2, nullptr);
79 
80     OH_Drawing_RegionDestroy(region);
81     OH_Drawing_RegionDestroy(region2);
82 }
83 
84 /*
85  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0200
86  * @tc.name: testRegionDestroyNormal
87  * @tc.desc: test for testRegionDestroyNormal.
88  * @tc.size  : SmallTest
89  * @tc.type  : Function
90  * @tc.level : Level 0
91  */
92 HWTEST_F(DrawingNativeRegionTest, testRegionDestroyNormal, Function | SmallTest | Level0) {
93     // 1. OH_Drawing_RegionCreate returns a pointer value regionObject
94     OH_Drawing_Region *regionObject = OH_Drawing_RegionCreate();
95     EXPECT_NE(regionObject, nullptr);
96     // 2. OH_Drawing_RegionDestroy takes regionObject as input
97     OH_Drawing_RegionDestroy(regionObject);
98 }
99 
100 /*
101  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0201
102  * @tc.name: testRegionDestroyNull
103  * @tc.desc: test for testRegionDestroyNull.
104  * @tc.size  : SmallTest
105  * @tc.type  : Function
106  * @tc.level : Level 1
107  */
108 HWTEST_F(DrawingNativeRegionTest, testRegionDestroyNull, Function | SmallTest | Level1) {
109     // 1. OH_Drawing_RegionDestroy takes nullptr as input
110     OH_Drawing_RegionDestroy(nullptr);
111     // add assert
112     EXPECT_TRUE(true);
113 }
114 
115 /*
116  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0300
117  * @tc.name: testRegionContainsInRange
118  * @tc.desc: test for testRegionContainsInRange.
119  * @tc.size  : SmallTest
120  * @tc.type  : Function
121  * @tc.level : Level 0
122  */
123 HWTEST_F(DrawingNativeRegionTest, testRegionContainsInRange, Function | SmallTest | Level0) {
124     // 1. OH_Drawing_RegionCreate returns a pointer value regionObject, the call is successful and the return value is
125     // not nullptr
126     OH_Drawing_Region *regionObject = OH_Drawing_RegionCreate();
127     EXPECT_NE(regionObject, nullptr);
128 
129     // 2. OH_Drawing_RegionContains takes regionObject as input, x: a value within the range, y: a value within the
130     // range, the call is successful and the return value is true
131     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
132     // add assert
133     EXPECT_NE(rect, nullptr);
134     OH_Drawing_RegionSetRect(regionObject, rect);
135     bool ret = OH_Drawing_RegionContains(regionObject, 100, 100);
136     EXPECT_TRUE(ret);
137     // add assert
138     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
139 
140     OH_Drawing_RegionDestroy(regionObject);
141     OH_Drawing_RectDestroy(rect);
142 }
143 
144 /*
145  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0301
146  * @tc.name: testRegionContainsXvalueNotInRange
147  * @tc.desc: test for testRegionContainsXvalueNotInRange.
148  * @tc.size  : SmallTest
149  * @tc.type  : Function
150  * @tc.level : Level 1
151  */
152 HWTEST_F(DrawingNativeRegionTest, testRegionContainsXvalueNotInRange, Function | SmallTest | Level1) {
153     // 1. OH_Drawing_RegionCreate returns a pointer value regionObject
154     OH_Drawing_Region *regionObject = OH_Drawing_RegionCreate();
155     EXPECT_NE(regionObject, nullptr);
156     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
157     // add assert
158     EXPECT_NE(rect, nullptr);
159     OH_Drawing_RegionSetRect(regionObject, rect);
160 
161     // 2. OH_Drawing_RegionContains takes regionObject as input, x: a value not within the range, y: a value within the
162     // range
163     bool ret = OH_Drawing_RegionContains(regionObject, 300, 100);
164     EXPECT_FALSE(ret);
165     // add assert
166     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
167 
168     OH_Drawing_RegionDestroy(regionObject);
169     OH_Drawing_RectDestroy(rect);
170 }
171 
172 /*
173  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0302
174  * @tc.name: testRegionContainsYvalueNotInRange
175  * @tc.desc: test for testRegionContainsYvalueNotInRange.
176  * @tc.size  : SmallTest
177  * @tc.type  : Function
178  * @tc.level : Level 1
179  */
180 HWTEST_F(DrawingNativeRegionTest, testRegionContainsYvalueNotInRange, Function | SmallTest | Level1) {
181     // 1. OH_Drawing_RegionCreate returns a pointer value regionObject
182     OH_Drawing_Region *regionObject = OH_Drawing_RegionCreate();
183     EXPECT_NE(regionObject, nullptr);
184     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
185     // add assert
186     EXPECT_NE(rect, nullptr);
187     OH_Drawing_RegionSetRect(regionObject, rect);
188 
189     // 2. OH_Drawing_RegionContains takes regionObject as input, x: a value within the range, y: a value not within the
190     // range
191     bool ret = OH_Drawing_RegionContains(regionObject, 100, 300);
192     EXPECT_FALSE(ret);
193     // add assert
194     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
195 
196     OH_Drawing_RegionDestroy(regionObject);
197     OH_Drawing_RectDestroy(rect);
198 }
199 
200 /*
201  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0303
202  * @tc.name: testRegionContainsAllNotInRange
203  * @tc.desc: test for testRegionContainsAllNotInRange.
204  * @tc.size  : SmallTest
205  * @tc.type  : Function
206  * @tc.level : Level 1
207  */
208 HWTEST_F(DrawingNativeRegionTest, testRegionContainsAllNotInRange, Function | SmallTest | Level1) {
209     // 1. OH_Drawing_RegionCreate returns a pointer value regionObject
210     OH_Drawing_Region *regionObject = OH_Drawing_RegionCreate();
211     EXPECT_NE(regionObject, nullptr);
212     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
213     // add assert
214     EXPECT_NE(rect, nullptr);
215     OH_Drawing_RegionSetRect(regionObject, rect);
216 
217     // 2. OH_Drawing_RegionContains takes regionObject as input, x: a value not within the range, y: a value not within
218     // the range
219     bool ret = OH_Drawing_RegionContains(regionObject, 300, 300);
220     EXPECT_FALSE(ret);
221     // add assert
222     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
223 
224     OH_Drawing_RegionDestroy(regionObject);
225     OH_Drawing_RectDestroy(rect);
226 }
227 
228 /*
229  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0304
230  * @tc.name: testRegionContainsRegionNull
231  * @tc.desc: test for testRegionContainsRegionNull.
232  * @tc.size  : SmallTest
233  * @tc.type  : Function
234  * @tc.level : Level 1
235  */
236 HWTEST_F(DrawingNativeRegionTest, testRegionContainsRegionNull, Function | SmallTest | Level1) {
237     // 1. OH_Drawing_RegionContains takes nullptr as input, x: a value within the range, y: a value within the range
238     OH_Drawing_RegionContains(nullptr, 100, 100);
239     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
240 }
241 
242 /*
243  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0400
244  * @tc.name: testRegionOpNormal
245  * @tc.desc: test for testRegionOpNormal.
246  * @tc.size  : SmallTest
247  * @tc.type  : Function
248  * @tc.level : Level 0
249  */
250 HWTEST_F(DrawingNativeRegionTest, testRegionOpNormal, Function | SmallTest | Level0) {
251     // 1. OH_Drawing_RegionCreate returns a pointer value regionObject
252     OH_Drawing_Region *regionObject = OH_Drawing_RegionCreate();
253     EXPECT_NE(regionObject, nullptr);
254     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
255     // add assert
256     EXPECT_NE(rect, nullptr);
257     OH_Drawing_RegionSetRect(regionObject, rect);
258     // 2. OH_Drawing_RegionCreate returns a pointer value dst
259     OH_Drawing_Region *dst = OH_Drawing_RegionCreate();
260     EXPECT_NE(dst, nullptr);
261     OH_Drawing_RegionSetRect(dst, rect);
262     // 3. OH_Drawing_RegionOp takes regionObject, dst, and op: perform OH_Drawing_RegionOpMode operations in sequence
263     OH_Drawing_RegionOpMode modes[] = {
264         REGION_OP_MODE_DIFFERENCE, REGION_OP_MODE_INTERSECT,          REGION_OP_MODE_UNION,
265         REGION_OP_MODE_XOR,        REGION_OP_MODE_REVERSE_DIFFERENCE, REGION_OP_MODE_REPLACE,
266     };
267     for (OH_Drawing_RegionOpMode mode : modes) {
268         OH_Drawing_ErrorCodeReset();
269         OH_Drawing_RegionOp(regionObject, dst, mode);
270         // add assert
271         EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
272     }
273 
274     OH_Drawing_RegionDestroy(regionObject);
275     OH_Drawing_RectDestroy(rect);
276     OH_Drawing_RegionDestroy(dst);
277 }
278 
279 /*
280  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0401
281  * @tc.name: testRegionOpRegionNull
282  * @tc.desc: test for testRegionOpRegionNull.
283  * @tc.size  : SmallTest
284  * @tc.type  : Function
285  * @tc.level : Level 1
286  */
287 HWTEST_F(DrawingNativeRegionTest, testRegionOpRegionNull, Function | SmallTest | Level1) {
288     // 1. OH_Drawing_RegionCreate returns a pointer value dst
289     OH_Drawing_Region *dst = OH_Drawing_RegionCreate();
290     EXPECT_NE(dst, nullptr);
291     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
292     // add assert
293     EXPECT_NE(rect, nullptr);
294     OH_Drawing_RegionSetRect(dst, rect);
295     // 2. OH_Drawing_RegionOp takes nullptr as input for region, dst as input, and op: REGION_OP_MODE_DIFFERENCE,
296     // returns OH_DRAWING_ERROR_INVALID_PARAMETER
297     OH_Drawing_RegionOp(nullptr, dst, REGION_OP_MODE_DIFFERENCE);
298     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
299 
300     OH_Drawing_RectDestroy(rect);
301     OH_Drawing_RegionDestroy(dst);
302 }
303 
304 /*
305  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0402
306  * @tc.name: testRegionOpRegionDstNull
307  * @tc.desc: test for testRegionOpRegionDstNull.
308  * @tc.size  : SmallTest
309  * @tc.type  : Function
310  * @tc.level : Level 1
311  */
312 HWTEST_F(DrawingNativeRegionTest, testRegionOpRegionDstNull, Function | SmallTest | Level1) {
313     // 1. OH_Drawing_RegionCreate returns a pointer value region
314     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
315     EXPECT_NE(region, nullptr);
316     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
317     // add assert
318     EXPECT_NE(rect, nullptr);
319     OH_Drawing_RegionSetRect(region, rect);
320     // 2. OH_Drawing_RegionOp takes region as input, dst: nullptr, op: REGION_OP_MODE_DIFFERENCE
321     OH_Drawing_RegionOp(region, nullptr, REGION_OP_MODE_DIFFERENCE);
322     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
323 
324     OH_Drawing_RectDestroy(rect);
325     OH_Drawing_RegionDestroy(region);
326 }
327 
328 /*
329  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0500
330  * @tc.name: testRegionSetRectResultTrue
331  * @tc.desc: test for testRegionSetRectResultTrue.
332  * @tc.size  : SmallTest
333  * @tc.type  : Function
334  * @tc.level : Level 0
335  */
336 HWTEST_F(DrawingNativeRegionTest, testRegionSetRectResultTrue, Function | SmallTest | Level0) {
337     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
338     EXPECT_NE(region, nullptr);
339     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
340     // add assert
341     EXPECT_NE(rect, nullptr);
342     // 1. OH_Drawing_RegionSetRect takes correct region and rect object pointers as input
343     bool ret = OH_Drawing_RegionSetRect(region, rect);
344     EXPECT_TRUE(ret);
345 
346     OH_Drawing_RectDestroy(rect);
347     OH_Drawing_RegionDestroy(region);
348 }
349 
350 /*
351  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0501
352  * @tc.name: testRegionSetRectRegionNull
353  * @tc.desc: test for testRegionSetRectRegionNull.
354  * @tc.size  : SmallTest
355  * @tc.type  : Function
356  * @tc.level : Level 1
357  */
358 HWTEST_F(DrawingNativeRegionTest, testRegionSetRectRegionNull, Function | SmallTest | Level1) {
359     // 1. OH_Drawing_RegionSetRect takes a correct rect object pointer as input, region is nullptr, returns
360     // OH_DRAWING_ERROR_INVALID_PARAMETER
361     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 256.0f, 256.0f);
362     // add assert
363     EXPECT_NE(rect, nullptr);
364     OH_Drawing_RegionSetRect(nullptr, rect);
365     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
366     OH_Drawing_RectDestroy(rect);
367 }
368 
369 /*
370  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0502
371  * @tc.name: testRegionSetRectRectNull
372  * @tc.desc: test for testRegionSetRectRectNull.
373  * @tc.size  : SmallTest
374  * @tc.type  : Function
375  * @tc.level : Level 1
376  */
377 HWTEST_F(DrawingNativeRegionTest, testRegionSetRectRectNull, Function | SmallTest | Level1) {
378     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
379     // add assert
380     EXPECT_NE(region, nullptr);
381     // 1. OH_Drawing_RegionSetRect takes a correct region object pointer as input, rect is nullptr
382     OH_Drawing_RegionSetRect(region, nullptr);
383     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
384     OH_Drawing_RegionDestroy(region);
385 }
386 
387 /*
388  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0503
389  * @tc.name: testRegionSetRectResultFalse
390  * @tc.desc: test for testRegionSetRectResultFalse.
391  * @tc.size  : SmallTest
392  * @tc.type  : Function
393  * @tc.level : Level 1
394  */
395 HWTEST_F(DrawingNativeRegionTest, testRegionSetRectResultFalse, Function | SmallTest | Level1) {
396     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
397     EXPECT_NE(region, nullptr);
398     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f);
399     // add assert
400     EXPECT_NE(rect, nullptr);
401 
402     // 1. OH_Drawing_RegionSetRect takes correct region and rect object pointers as input
403     bool ret = OH_Drawing_RegionSetRect(region, rect);
404     EXPECT_FALSE(ret);
405 
406     OH_Drawing_RectDestroy(rect);
407     OH_Drawing_RegionDestroy(region);
408 }
409 
410 /*
411  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0600
412  * @tc.name: testRegionSetPathResultTrue
413  * @tc.desc: test for testRegionSetPathResultTrue.
414  * @tc.size  : SmallTest
415  * @tc.type  : Function
416  * @tc.level : Level 0
417  */
418 HWTEST_F(DrawingNativeRegionTest, testRegionSetPathResultTrue, Function | SmallTest | Level0) {
419     OH_Drawing_Path *path = OH_Drawing_PathCreate();
420     // add assert
421     EXPECT_NE(path, nullptr);
422     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
423     // add assert
424     EXPECT_NE(region, nullptr);
425     OH_Drawing_Region *clip = OH_Drawing_RegionCreate();
426     // add assert
427     EXPECT_NE(clip, nullptr);
428     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(150.0f, 180.0f, 200.0f, 200.0f);
429     // add assert
430     EXPECT_NE(rect, nullptr);
431     OH_Drawing_RegionSetRect(clip, rect);
432     OH_Drawing_PathAddRect(path, 100.0f, 100.0f, 256.0f, 256.0f, OH_Drawing_PathDirection::PATH_DIRECTION_CW);
433 
434     // 1. OH_Drawing_RegionSetPath takes correct region, path, and clip object pointers as input
435     EXPECT_TRUE(OH_Drawing_RegionSetPath(region, path, clip));
436     // add assert
437     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
438 
439     OH_Drawing_PathDestroy(path);
440     OH_Drawing_RegionDestroy(region);
441     OH_Drawing_RegionDestroy(clip);
442     OH_Drawing_RectDestroy(rect);
443 }
444 
445 /*
446  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0601
447  * @tc.name: testRegionSetPathRegionNull
448  * @tc.desc: test for testRegionSetPathRegionNull.
449  * @tc.size  : SmallTest
450  * @tc.type  : Function
451  * @tc.level : Level 1
452  */
453 HWTEST_F(DrawingNativeRegionTest, testRegionSetPathRegionNull, Function | SmallTest | Level1) {
454     OH_Drawing_Path *path = OH_Drawing_PathCreate();
455     // add assert
456     EXPECT_NE(path, nullptr);
457     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
458     // add assert
459     EXPECT_NE(region, nullptr);
460     OH_Drawing_Region *clip = OH_Drawing_RegionCreate();
461     // add assert
462     EXPECT_NE(clip, nullptr);
463     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(150.0f, 180.0f, 200.0f, 200.0f);
464     // add assert
465     EXPECT_NE(rect, nullptr);
466     OH_Drawing_RegionSetRect(clip, rect);
467 
468     // 1. OH_Drawing_RegionSetPath takes correct path and clip object pointers as input, region is nullptr
469     OH_Drawing_RegionSetPath(nullptr, path, clip);
470     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
471 
472     OH_Drawing_PathDestroy(path);
473     OH_Drawing_RegionDestroy(region);
474     OH_Drawing_RegionDestroy(clip);
475     OH_Drawing_RectDestroy(rect);
476 }
477 
478 /*
479  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0602
480  * @tc.name: testRegionSetPathPathNull
481  * @tc.desc: test for testRegionSetPathPathNull.
482  * @tc.size  : SmallTest
483  * @tc.type  : Function
484  * @tc.level : Level 1
485  */
486 HWTEST_F(DrawingNativeRegionTest, testRegionSetPathPathNull, Function | SmallTest | Level1) {
487     OH_Drawing_Path *path = OH_Drawing_PathCreate();
488     // add assert
489     EXPECT_NE(path, nullptr);
490     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
491     // add assert
492     EXPECT_NE(region, nullptr);
493     OH_Drawing_Region *clip = OH_Drawing_RegionCreate();
494     // add assert
495     EXPECT_NE(clip, nullptr);
496     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(150.0f, 180.0f, 200.0f, 200.0f);
497     // add assert
498     EXPECT_NE(rect, nullptr);
499     OH_Drawing_RegionSetRect(clip, rect);
500 
501     // 1. OH_Drawing_RegionSetPath takes correct region and clip object pointers as input, path is nullptr
502     OH_Drawing_RegionSetPath(region, nullptr, clip);
503     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
504 
505     OH_Drawing_PathDestroy(path);
506     OH_Drawing_RegionDestroy(region);
507     OH_Drawing_RegionDestroy(clip);
508     OH_Drawing_RectDestroy(rect);
509 }
510 
511 /*
512  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0603
513  * @tc.name: testRegionSetPathClipNull
514  * @tc.desc: test for testRegionSetPathClipNull.
515  * @tc.size  : SmallTest
516  * @tc.type  : Function
517  * @tc.level : Level 1
518  */
519 HWTEST_F(DrawingNativeRegionTest, testRegionSetPathClipNull, Function | SmallTest | Level1) {
520     OH_Drawing_Path *path = OH_Drawing_PathCreate();
521     // add assert
522     EXPECT_NE(path, nullptr);
523     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
524     // add assert
525     EXPECT_NE(region, nullptr);
526     OH_Drawing_Region *clip = OH_Drawing_RegionCreate();
527     // add assert
528     EXPECT_NE(clip, nullptr);
529     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(150.0f, 180.0f, 200.0f, 200.0f);
530     // add assert
531     EXPECT_NE(rect, nullptr);
532     OH_Drawing_RegionSetRect(clip, rect);
533 
534     // 1. OH_Drawing_RegionSetPath takes correct region, path object pointers as input, and clip is nullptr
535     OH_Drawing_RegionSetPath(region, path, nullptr);
536     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
537 
538     OH_Drawing_PathDestroy(path);
539     OH_Drawing_RegionDestroy(region);
540     OH_Drawing_RegionDestroy(clip);
541     OH_Drawing_RectDestroy(rect);
542 }
543 
544 /*
545  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0604
546  * @tc.name: testRegionSetPathResultFalse
547  * @tc.desc: test for testRegionSetPathResultFalse.
548  * @tc.size  : SmallTest
549  * @tc.type  : Function
550  * @tc.level : Level 1
551  */
552 HWTEST_F(DrawingNativeRegionTest, testRegionSetPathResultFalse, Function | SmallTest | Level1) {
553     OH_Drawing_Path *path = OH_Drawing_PathCreate();
554     // add assert
555     EXPECT_NE(path, nullptr);
556     OH_Drawing_Region *region = OH_Drawing_RegionCreate();
557     // add assert
558     EXPECT_NE(region, nullptr);
559     OH_Drawing_Region *clip = OH_Drawing_RegionCreate();
560     // add assert
561     EXPECT_NE(clip, nullptr);
562     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f);
563     // add assert
564     EXPECT_NE(rect, nullptr);
565     OH_Drawing_RegionSetRect(clip, rect);
566 
567     // 1. OH_Drawing_RegionSetPath takes correct region, path, and clip object pointers as input
568     bool ret = OH_Drawing_RegionSetPath(region, path, clip);
569     EXPECT_FALSE(ret);
570     // add assert
571     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_SUCCESS);
572 
573     OH_Drawing_PathDestroy(path);
574     OH_Drawing_RegionDestroy(region);
575     OH_Drawing_RegionDestroy(clip);
576     OH_Drawing_RectDestroy(rect);
577 }
578 
579 /*
580  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0700
581  * @tc.name: testRegionCopyNormal
582  * @tc.desc: test for testRegionCopyNormal.
583  * @tc.size  : SmallTest
584  * @tc.type  : Function
585  * @tc.level : Level 0
586  */
587 HWTEST_F(DrawingNativeRegionTest, testRegionCopyNormal, Function | SmallTest | Level0) {
588     // 1. Create a region object by OH_Drawing_RegionCreate.
589     OH_Drawing_Region *region1 = OH_Drawing_RegionCreate();
590     EXPECT_NE(region1, nullptr);
591     // 2. Create a region object by OH_Drawing_RectCreate.
592     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 200.0f);
593     EXPECT_NE(rect, nullptr);
594     // 3. Set the region1 as the rectangle.
595     OH_Drawing_RegionSetRect(region1, rect);
596     // 4. Create another region object by OH_Drawing_RegionCreate.
597     OH_Drawing_Region *region2 = OH_Drawing_RegionCopy(region1);
598     EXPECT_NE(region2, nullptr);
599     // 5. Free memory.
600     OH_Drawing_RectDestroy(rect);
601     OH_Drawing_RegionDestroy(region1);
602     OH_Drawing_RegionDestroy(region2);
603 }
604 
605 /*
606  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0701
607  * @tc.name: testRegionCopyNull
608  * @tc.desc: test for testRegionCopyNull
609  * @tc.size  : SmallTest
610  * @tc.type  : Function
611  * @tc.level : Level 3
612  */
613 HWTEST_F(DrawingNativeRegionTest, testRegionCopyNull, Function | SmallTest | Level3) {
614     // 1. Create a region object by OH_Drawing_RegionCreate.
615     OH_Drawing_Region *region1 = OH_Drawing_RegionCreate();
616     EXPECT_NE(region1, nullptr);
617     // 2. Create a region object by OH_Drawing_RectCreate.
618     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 200.0f);
619     EXPECT_NE(rect, nullptr);
620     // 3. Set the region1 as the rectangle.
621     OH_Drawing_RegionSetRect(region1, rect);
622     // 4. Copy a region object by OH_Drawing_RegionCopy.
623     OH_Drawing_Region *region2 = OH_Drawing_RegionCopy(nullptr);
624     EXPECT_EQ(region2, nullptr);
625     // 5. Free memory.
626     OH_Drawing_RectDestroy(rect);
627     OH_Drawing_RegionDestroy(region1);
628     OH_Drawing_RegionDestroy(region2);
629 }
630 
631 /*
632  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0702
633  * @tc.name: testRegionCopyAbnormal
634  * @tc.desc: test for testRegionCopyAbnormal
635  * @tc.size  : SmallTest
636  * @tc.type  : Function
637  * @tc.level : Level 3
638  */
639 HWTEST_F(DrawingNativeRegionTest, testRegionCopyAbnormal, Function | SmallTest | Level3) {
640     // 1. Create a region object by OH_Drawing_RegionCreate.
641     OH_Drawing_Region *region1 = OH_Drawing_RegionCreate();
642     EXPECT_NE(region1, nullptr);
643     // 2. The ordinate coordinates of the upper left corner and the lower right corner are equal.
644     OH_Drawing_Rect *rect1 = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 0.0f);
645     EXPECT_NE(rect1, nullptr);
646     // 3. Set the region1 as the rectangle.
647     OH_Drawing_RegionSetRect(region1, rect1);
648     // 4. Copy a region object by OH_Drawing_RegionCopy.
649     OH_Drawing_Region *region2 = OH_Drawing_RegionCopy(region1);
650     EXPECT_NE(region2, nullptr);
651     // 5. The horizontal coordinates of the upper left corner and the lower right corner are equal.
652     OH_Drawing_Rect *rect2 = OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 200.0f);
653     EXPECT_NE(rect2, nullptr);
654     // 6. Set the region1 as the rectangle.
655     OH_Drawing_RegionSetRect(region1, rect2);
656     // 7. Copy a region object by OH_Drawing_RegionCopy.
657     region2 = OH_Drawing_RegionCopy(region1);
658     EXPECT_NE(region2, nullptr);
659     // 8. The coordinates of the upper left corner and the lower right corner are equal.
660     OH_Drawing_Rect *rect3 = OH_Drawing_RectCreate(0.0f, 0.0f, 0.0f, 0.0f);
661     EXPECT_NE(rect3, nullptr);
662     // 9. Set the region1 as the rectangle.
663     OH_Drawing_RegionSetRect(region1, rect3);
664     // 10. Copy a region object by OH_Drawing_RegionCopy.
665     region2 = OH_Drawing_RegionCopy(region1);
666     EXPECT_NE(region2, nullptr);
667     // 11. The coordinates of the upper left corner are greater than those of the lower right corner.
668     OH_Drawing_Rect *rect4 = OH_Drawing_RectCreate(400.0f, 400.0f, 200.0f, 200.0f);
669     EXPECT_NE(rect4, nullptr);
670     // 12. Set the region1 as the rectangle.
671     OH_Drawing_RegionSetRect(region1, rect4);
672     // 13. Copy a region object by OH_Drawing_RegionCopy.
673     region2 = OH_Drawing_RegionCopy(region1);
674     EXPECT_NE(region2, nullptr);
675     // 14. Free memory.
676     OH_Drawing_RectDestroy(rect1);
677     OH_Drawing_RectDestroy(rect2);
678     OH_Drawing_RectDestroy(rect3);
679     OH_Drawing_RectDestroy(rect4);
680     OH_Drawing_RegionDestroy(region1);
681     OH_Drawing_RegionDestroy(region2);
682 }
683 
684 /*
685  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_REGION_0703
686  * @tc.name: testRegionCopyMultipleCalls
687  * @tc.desc: test for testRegionCopyMultipleCalls
688  * @tc.size  : SmallTest
689  * @tc.type  : Function
690  * @tc.level : Level 3
691  */
692 HWTEST_F(DrawingNativeRegionTest, testRegionCopyMultipleCalls, Function | SmallTest | Level0) {
693     // 1. Create a region object by OH_Drawing_RegionCreate.
694     OH_Drawing_Region *region1 = OH_Drawing_RegionCreate();
695     EXPECT_NE(region1, nullptr);
696     // 2. Create a region object by OH_Drawing_RectCreate.
697     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0.0f, 0.0f, 200.0f, 200.0f);
698     EXPECT_NE(rect, nullptr);
699     // 3. Set the region1 as the rectangle.
700     OH_Drawing_RegionSetRect(region1, rect);
701     // 4. Create another region object by OH_Drawing_RegionCreate.
702     OH_Drawing_Region *region2 = OH_Drawing_RegionCreate();
703     // 5. The function OH_Drawing_RegionCopy is called 10 times.
704     for (int i = 0; i < 10; i++) {
705         region2 = OH_Drawing_RegionCopy(region1);
706         EXPECT_NE(region2, nullptr);
707     }
708     // 5. Free memory.
709     OH_Drawing_RectDestroy(rect);
710     OH_Drawing_RegionDestroy(region1);
711     OH_Drawing_RegionDestroy(region2);
712 }
713 } // namespace Drawing
714 } // namespace Rosen
715 } // namespace OHOS