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 #include <random>
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace Drawing {
32 class DrawingNativeRoundRectTest : public testing::Test {};
33 
34 /*
35  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0100
36  * @tc.name: testRoundRectCreateNormal
37  * @tc.desc: test for testRoundRectCreateNormal.
38  * @tc.size  : SmallTest
39  * @tc.type  : Function
40  * @tc.level : Level 0
41  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateNormal, TestSize.Level0)42 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateNormal, TestSize.Level0) {
43     // 1. OH_Drawing_RoundRectCreate
44     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
45     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
46     // 2. Free memory
47     OH_Drawing_RoundRectDestroy(roundRect);
48     OH_Drawing_RectDestroy(rect);
49 }
50 
51 /*
52  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0101
53  * @tc.name: testRoundRectCreateNull
54  * @tc.desc: test for testRoundRectCreateNull.
55  * @tc.size  : SmallTest
56  * @tc.type  : Function
57  * @tc.level : Level 3
58  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateNull, TestSize.Level3)59 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateNull, TestSize.Level3) {
60     // 1. OH_Drawing_RoundRectCreate with nullptr as the first parameter, check the error code using
61     // OH_Drawing_ErrorCodeGet
62     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
63     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(nullptr, 20, 20);
64     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
65     // 2. OH_Drawing_RoundRectCreate with 0 as the second parameter
66     OH_Drawing_RoundRect *roundRect2 = OH_Drawing_RoundRectCreate(rect, 0, 20);
67     // 3. OH_Drawing_RoundRectCreate with 0 as the third parameter
68     OH_Drawing_RoundRect *roundRect3 = OH_Drawing_RoundRectCreate(rect, 20, 0);
69     // 4. Free memory
70     OH_Drawing_RoundRectDestroy(roundRect);
71     OH_Drawing_RoundRectDestroy(roundRect2);
72     OH_Drawing_RoundRectDestroy(roundRect3);
73     OH_Drawing_RectDestroy(rect);
74 }
75 
76 /*
77  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0102
78  * @tc.name: testRoundRectCreateAbnormal
79  * @tc.desc: test for testRoundRectCreateAbnormal.
80  * @tc.size  : SmallTest
81  * @tc.type  : Function
82  * @tc.level : Level 3
83  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateAbnormal, TestSize.Level3)84 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateAbnormal, TestSize.Level3) {
85     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
86     // 1. OH_Drawing_RoundRectCreate with a negative value for the second parameter xRad
87     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, -20, 20);
88     // 2. OH_Drawing_RoundRectCreate with a negative value for the third parameter yRad
89     OH_Drawing_RoundRect *roundRect2 = OH_Drawing_RoundRectCreate(rect, 20, -20);
90     // 3. Free memory
91     OH_Drawing_RoundRectDestroy(roundRect);
92     OH_Drawing_RoundRectDestroy(roundRect2);
93     OH_Drawing_RectDestroy(rect);
94 }
95 
96 /*
97  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0103
98  * @tc.name: testRoundRectCreateMaximum
99  * @tc.desc: test for testRoundRectCreateMaximum.
100  * @tc.size  : SmallTest
101  * @tc.type  : Function
102  * @tc.level : Level 3
103  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateMaximum, TestSize.Level3)104 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateMaximum, TestSize.Level3) {
105     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
106     // 1. OH_Drawing_RoundRectCreate with the second parameter xRad as the maximum value
107     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, FLT_MAX, 20);
108     // 2. OH_Drawing_RoundRectCreate with the third parameter yRad as the maximum value
109     OH_Drawing_RoundRect *roundRect2 = OH_Drawing_RoundRectCreate(rect, 20, FLT_MAX);
110     // 3. Free memory
111     OH_Drawing_RoundRectDestroy(roundRect);
112     OH_Drawing_RoundRectDestroy(roundRect2);
113     OH_Drawing_RectDestroy(rect);
114 }
115 
116 /*
117  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0104
118  * @tc.name: testRoundRectCreateMultipleCalls
119  * @tc.desc: test for testRoundRectCreateMultipleCalls.
120  * @tc.size  : SmallTest
121  * @tc.type  : Function
122  * @tc.level : Level 3
123  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateMultipleCalls, TestSize.Level3)124 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectCreateMultipleCalls, TestSize.Level3) {
125     // 1. Call OH_Drawing_RoundRectCreate 10 times
126     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
127     for (int i = 0; i < 10; i++) {
128         OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
129         EXPECT_NE(roundRect, nullptr);
130         OH_Drawing_RoundRectDestroy(roundRect);
131     }
132 }
133 
134 /*
135  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0200
136  * @tc.name: testRoundRectSetGetCornerNormal
137  * @tc.desc: test for testRoundRectSetGetCornerNormal.
138  * @tc.size  : SmallTest
139  * @tc.type  : Function
140  * @tc.level : Level 0
141  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerNormal, TestSize.Level0)142 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerNormal, TestSize.Level0) {
143     // 1. OH_Drawing_RoundRectCreate
144     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
145     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
146     // 2. Enumerate OH_Drawing_RoundRectSetCorner and OH_Drawing_RoundRectGetCorner with OH_Drawing_CornerPos values
147     OH_Drawing_CornerPos posArray[] = {
148         CORNER_POS_TOP_LEFT,
149         CORNER_POS_TOP_RIGHT,
150         CORNER_POS_BOTTOM_RIGHT,
151         CORNER_POS_BOTTOM_LEFT,
152     };
153     for (OH_Drawing_CornerPos pos : posArray) {
154         OH_Drawing_RoundRectSetCorner(roundRect, pos, {10.0f, 10.0f});
155         OH_Drawing_Corner_Radii radii = OH_Drawing_RoundRectGetCorner(roundRect, pos);
156         EXPECT_EQ(IsScalarAlmostEqual(radii.x, 10.0f), true);
157         EXPECT_EQ(IsScalarAlmostEqual(radii.y, 10.0f), true);
158     }
159     // 3. OH_Drawing_RoundRectSetCorner with integer values for x and y radii, and call OH_Drawing_RoundRectGetCorner to
160     // retrieve the values
161     OH_Drawing_RoundRectSetCorner(roundRect, CORNER_POS_TOP_LEFT, {10, 10});
162     OH_Drawing_Corner_Radii radii = OH_Drawing_RoundRectGetCorner(roundRect, CORNER_POS_TOP_LEFT);
163     EXPECT_EQ(IsScalarAlmostEqual(radii.x, 10), true);
164     EXPECT_EQ(IsScalarAlmostEqual(radii.y, 10), true);
165     // 4. OH_Drawing_RoundRectSetCorner with decimal values for x and y radii, and call OH_Drawing_RoundRectGetCorner to
166     // retrieve the values
167     OH_Drawing_RoundRectSetCorner(roundRect, CORNER_POS_TOP_LEFT, {10.1f, 10.1f});
168     OH_Drawing_Corner_Radii radii2 = OH_Drawing_RoundRectGetCorner(roundRect, CORNER_POS_TOP_LEFT);
169     EXPECT_EQ(IsScalarAlmostEqual(radii2.x, 10.1f), true);
170     EXPECT_EQ(IsScalarAlmostEqual(radii2.y, 10.1f), true);
171     // 5. Free memory
172     OH_Drawing_RoundRectDestroy(roundRect);
173     OH_Drawing_RectDestroy(rect);
174 }
175 
176 /*
177  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0201
178  * @tc.name: testRoundRectSetGetCornerNull
179  * @tc.desc: test for testRoundRectSetGetCornerNull.
180  * @tc.size  : SmallTest
181  * @tc.type  : Function
182  * @tc.level : Level 3
183  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerNull, TestSize.Level3)184 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerNull, TestSize.Level3) {
185     // 1. OH_Drawing_RoundRectCreate
186     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
187     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
188     // 2. OH_Drawing_RoundRectSetCorner with nullptr as the first parameter, check the error code using
189     // OH_Drawing_ErrorCodeGet
190     OH_Drawing_RoundRectSetCorner(nullptr, CORNER_POS_TOP_LEFT, {10.0f, 10.0f});
191     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
192     // 3. OH_Drawing_RoundRectSetCorner with 0 as the third parameter
193     OH_Drawing_RoundRectSetCorner(roundRect, CORNER_POS_TOP_LEFT, {0, 0});
194     // 4. OH_Drawing_RoundRectGetCorner with nullptr as the first parameter, check the error code using
195     // OH_Drawing_ErrorCodeGet
196     OH_Drawing_RoundRectGetCorner(nullptr, CORNER_POS_TOP_LEFT);
197     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
198     // 5. Free memory
199     OH_Drawing_RoundRectDestroy(roundRect);
200     OH_Drawing_RectDestroy(rect);
201 }
202 
203 /*
204  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0202
205  * @tc.name: testRoundRectSetGetCornerAbnormal
206  * @tc.desc: test for testRoundRectSetGetCornerAbnormal.
207  * @tc.size  : SmallTest
208  * @tc.type  : Function
209  * @tc.level : Level 3
210  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerAbnormal, TestSize.Level3)211 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerAbnormal, TestSize.Level3) {
212     // 1. OH_Drawing_RoundRectCreate
213     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
214     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
215     // 2. OH_Drawing_RoundRectSetCorner with negative value for x-axis in OH_Drawing_Corner_Radii, followed by
216     // OH_Drawing_RoundRectGetCorner
217     OH_Drawing_RoundRectSetCorner(roundRect, CORNER_POS_TOP_LEFT, {-10.0f, 10.0f});
218     OH_Drawing_Corner_Radii radii = OH_Drawing_RoundRectGetCorner(roundRect, CORNER_POS_TOP_LEFT);
219     EXPECT_EQ(IsScalarAlmostEqual(radii.x, -10.0f), true);
220     EXPECT_EQ(IsScalarAlmostEqual(radii.y, 10.0f), true);
221     // 3. OH_Drawing_RoundRectSetCorner with negative value for y-axis in OH_Drawing_Corner_Radii, followed by
222     // OH_Drawing_RoundRectGetCorner
223     OH_Drawing_RoundRectSetCorner(roundRect, CORNER_POS_TOP_LEFT, {10.0f, -10.0f});
224     OH_Drawing_Corner_Radii radii2 = OH_Drawing_RoundRectGetCorner(roundRect, CORNER_POS_TOP_LEFT);
225     EXPECT_EQ(IsScalarAlmostEqual(radii2.x, 10.0f), true);
226     EXPECT_EQ(IsScalarAlmostEqual(radii2.y, -10.0f), true);
227     // 4. Free memory
228     OH_Drawing_RoundRectDestroy(roundRect);
229     OH_Drawing_RectDestroy(rect);
230 }
231 
232 /*
233  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0203
234  * @tc.name: testRoundRectSetGetCornerMaximum
235  * @tc.desc: test for testRoundRectSetGetCornerMaximum.
236  * @tc.size  : SmallTest
237  * @tc.type  : Function
238  * @tc.level : Level 3
239  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerMaximum, TestSize.Level3)240 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerMaximum, TestSize.Level3) {
241     // 1. OH_Drawing_RoundRectCreate
242     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
243     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
244     // 2. Call OH_Drawing_RoundRectSetCorner with the maximum value for the x-axis in OH_Drawing_Corner_Radii, followed
245     // by OH_Drawing_RoundRectGetCorner
246     OH_Drawing_RoundRectSetCorner(roundRect, CORNER_POS_TOP_LEFT, {FLT_MAX, 10.0f});
247     OH_Drawing_Corner_Radii radii = OH_Drawing_RoundRectGetCorner(roundRect, CORNER_POS_TOP_LEFT);
248     EXPECT_EQ(IsScalarAlmostEqual(radii.x, FLT_MAX), true);
249     EXPECT_EQ(IsScalarAlmostEqual(radii.y, 10.0f), true);
250     // 3. Call OH_Drawing_RoundRectSetCorner with the maximum value for the y-axis in OH_Drawing_Corner_Radii, followed
251     // by OH_Drawing_RoundRectGetCorner
252     OH_Drawing_RoundRectSetCorner(roundRect, CORNER_POS_TOP_LEFT, {10.0f, FLT_MAX});
253     OH_Drawing_Corner_Radii radii2 = OH_Drawing_RoundRectGetCorner(roundRect, CORNER_POS_TOP_LEFT);
254     EXPECT_EQ(IsScalarAlmostEqual(radii2.x, 10.0f), true);
255     EXPECT_EQ(IsScalarAlmostEqual(radii2.y, FLT_MAX), true);
256     // 4. Free memory
257     OH_Drawing_RoundRectDestroy(roundRect);
258     OH_Drawing_RectDestroy(rect);
259 }
260 
261 /*
262  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0204
263  * @tc.name: testRoundRectSetGetCornerMultipleCalls
264  * @tc.desc: test for testRoundRectSetGetCornerMultipleCalls.
265  * @tc.size  : SmallTest
266  * @tc.type  : Function
267  * @tc.level : Level 3
268  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerMultipleCalls, TestSize.Level3)269 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectSetGetCornerMultipleCalls, TestSize.Level3) {
270     // 1. OH_Drawing_RoundRectCreate
271     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
272     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
273     // 2. OH_Drawing_RoundRectSetCorner (pass random values for x-axis and y-axis radii, and a random enum value for
274     // OH_Drawing_CornerPos), followed by calling OH_Drawing_RoundRectGetCorner
275     std::random_device rd;
276     std::mt19937 gen(rd());
277     std::uniform_real_distribution<float> dis(0, 100);
278     std::uniform_int_distribution<int> dis2(0, 3);
279     for (int i = 0; i < 10; i++) {
280         float x = dis(gen);
281         float y = dis(gen);
282         OH_Drawing_CornerPos pos = static_cast<OH_Drawing_CornerPos>(dis2(gen));
283         OH_Drawing_RoundRectSetCorner(roundRect, pos, {x, y});
284         OH_Drawing_Corner_Radii radii = OH_Drawing_RoundRectGetCorner(roundRect, pos);
285         EXPECT_EQ(IsScalarAlmostEqual(radii.x, x), true);
286         EXPECT_EQ(IsScalarAlmostEqual(radii.y, y), true);
287     }
288     // 3. Free memory
289     OH_Drawing_RoundRectDestroy(roundRect);
290     OH_Drawing_RectDestroy(rect);
291 }
292 
293 /*
294  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0205
295  * @tc.name: testRoundRectGetCornerWhenNoSet
296  * @tc.desc: test for testRoundRectGetCornerWhenNoSet.
297  * @tc.size  : SmallTest
298  * @tc.type  : Function
299  * @tc.level : Level 2
300  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectGetCornerWhenNoSet, TestSize.Level2)301 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectGetCornerWhenNoSet, TestSize.Level2) {
302     // 1. OH_Drawing_RoundRectCreate
303     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
304     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
305     // 2. Call OH_Drawing_RoundRectGetCorner directly
306     OH_Drawing_Corner_Radii radii = OH_Drawing_RoundRectGetCorner(roundRect, CORNER_POS_TOP_LEFT);
307     EXPECT_EQ(IsScalarAlmostEqual(radii.x, 20), true);
308     EXPECT_EQ(IsScalarAlmostEqual(radii.y, 20), true);
309     // 3. Free memory
310     OH_Drawing_RoundRectDestroy(roundRect);
311     OH_Drawing_RectDestroy(rect);
312 }
313 
314 /*
315  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0300
316  * @tc.name: testRoundRectDestroyNormal
317  * @tc.desc: test for testRoundRectDestroyNormal.
318  * @tc.size  : SmallTest
319  * @tc.type  : Function
320  * @tc.level : Level 0
321  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectDestroyNormal, TestSize.Level0)322 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectDestroyNormal, TestSize.Level0) {
323     // 1. OH_Drawing_RoundRectCreate
324     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
325     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
326     // 2. OH_Drawing_RoundRectDestroy
327     OH_Drawing_RoundRectDestroy(roundRect);
328     OH_Drawing_RectDestroy(rect);
329 }
330 
331 /*
332  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0301
333  * @tc.name: testRoundRectDestroyNull
334  * @tc.desc: test for testRoundRectDestroyNull.
335  * @tc.size  : SmallTest
336  * @tc.type  : Function
337  * @tc.level : Level 3
338  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectDestroyNull, TestSize.Level3)339 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectDestroyNull, TestSize.Level3) {
340     // 1. OH_Drawing_RoundRectDestroy with nullptr as the parameter
341     OH_Drawing_RoundRectDestroy(nullptr);
342 }
343 
344 /*
345  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0400
346  * @tc.name: testRoundRectOffsetNormal
347  * @tc.desc: test for testRoundRectOffsetNormal.
348  * @tc.size  : SmallTest
349  * @tc.type  : Function
350  * @tc.level : Level 0
351  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectOffsetNormal, TestSize.Level0)352 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectOffsetNormal, TestSize.Level0) {
353     //1. OH_Drawing_RoundRectCreate with the second parameter as integar values
354     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
355     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
356     //2. OH_Drawing_RoundRectCreate with the second parameter as floating-point values
357     OH_Drawing_RoundRect *roundRect1 = OH_Drawing_RoundRectCreate(rect, 20.f, 20);
358     //3. OH_Drawing_RoundRectCreate with the first parameter as integar values
359     OH_Drawing_RoundRect *roundRect2 = OH_Drawing_RoundRectCreate(rect, 20, 20);
360     //4. OH_Drawing_RoundRectCreate with the first parameter as floating-point values
361     OH_Drawing_Rect *rect1 = OH_Drawing_RectCreate(0.f, 0.f, 100.f, 100.f);
362     OH_Drawing_RoundRect *roundRect3 = OH_Drawing_RoundRectCreate(rect1, 20, 20);
363     OH_Drawing_RoundRectDestroy(roundRect);
364     OH_Drawing_RoundRectDestroy(roundRect1);
365     OH_Drawing_RoundRectDestroy(roundRect2);
366     OH_Drawing_RoundRectDestroy(roundRect3);
367 }
368 
369 /*
370  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0401
371  * @tc.name: testRoundRectOffsetNull
372  * @tc.desc: test for testRoundRectOffsetNull.
373  * @tc.size  : SmallTest
374  * @tc.type  : Function
375  * @tc.level : Level 3
376  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectOffsetNull, TestSize.Level3)377 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectOffsetNull, TestSize.Level3) {
378     // 1. Call OH_Drawing_RoundRectOffset with nullptr as the first parameter, check the error code using
379     // OH_Drawing_ErrorCodeGet
380     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
381     OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, 20, 20);
382     OH_Drawing_RoundRectOffset(nullptr, 1.0f, 1.0f);
383     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
384     // 2. Call OH_Drawing_RoundRectOffset with 0 as the second parameter, check the error code using
385     // OH_Drawing_ErrorCodeGet
386     OH_Drawing_RoundRectOffset(roundRect, 0, 1.0f);
387     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
388     // 3. Call OH_Drawing_RoundRectOffset with 0 as the third parameter, check the error code using
389     // OH_Drawing_ErrorCodeGet
390     OH_Drawing_RoundRectOffset(roundRect, 1.0f, 0);
391     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
392     //4. free memory
393     OH_Drawing_RoundRectDestroy(roundRect);
394     OH_Drawing_RectDestroy(rect);
395 }
396 
397 /*
398  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_ROUND_RECT_0402
399  * @tc.name: testRoundRectOffsetMultipleCalls
400  * @tc.desc: test for testRoundRectOffsetMultipleCalls.
401  * @tc.size  : SmallTest
402  * @tc.type  : Function
403  * @tc.level : Level 3
404  */
HWTEST_F(DrawingNativeRoundRectTest, testRoundRectOffsetMultipleCalls, TestSize.Level3)405 HWTEST_F(DrawingNativeRoundRectTest, testRoundRectOffsetMultipleCalls, TestSize.Level3) {
406     //1. Call OH_Drawing_RoundRectCreate with random values
407     OH_Drawing_Rect *rect = OH_Drawing_RectCreate(0, 0, 100, 100);
408     std::random_device rd;
409     std::mt19937 gen(rd());
410     std::uniform_real_distribution<float> dis(0, 100);
411     for (int i = 0; i < 10; i++) {
412         OH_Drawing_RoundRect *roundRect = OH_Drawing_RoundRectCreate(rect, dis(gen), dis(gen));
413         OH_Drawing_RoundRectDestroy(roundRect);
414     }
415     //2. free memory
416     OH_Drawing_RectDestroy(rect);
417 }
418 
419 } // namespace Drawing
420 } // namespace Rosen
421 } // namespace OHOS