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