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_point.h"
19#include <random>
20
21using namespace testing;
22using namespace testing::ext;
23
24namespace OHOS {
25namespace Rosen {
26namespace Drawing {
27class DrawingNativePointTest : public testing::Test {};
28
29/*
30 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0100
31 * @tc.name: testPointCreateNormal
32 * @tc.desc: test for testPointCreateNormal.
33 * @tc.size  : SmallTest
34 * @tc.type  : Function
35 * @tc.level : Level 0
36 */
37HWTEST_F(DrawingNativePointTest, testPointCreateNormal, TestSize.Level0) {
38    // 1. Pass integer values for X and Y coordinates to OH_Drawing_PointCreate interface
39    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
40    // 2. Pass floating-point values for X and Y coordinates to OH_Drawing_PointCreate interface
41    OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100.5f, 60.0f);
42    // 3. Free memory
43    OH_Drawing_PointDestroy(point);
44    OH_Drawing_PointDestroy(point2);
45}
46
47/*
48 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0101
49 * @tc.name: testPointCreateNull
50 * @tc.desc: test for testPointCreateNull.
51 * @tc.size  : SmallTest
52 * @tc.type  : Function
53 * @tc.level : Level 3
54 */
55HWTEST_F(DrawingNativePointTest, testPointCreateNull, TestSize.Level3) {
56    // 1. The first parameter of OH_Drawing_PointCreate is empty
57    OH_Drawing_Point *point = OH_Drawing_PointCreate(0, 60);
58    // 2. The second parameter of OH_Drawing_PointCreate is empty
59    OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100, 0);
60    // 3. Free memory
61    OH_Drawing_PointDestroy(point);
62    OH_Drawing_PointDestroy(point2);
63}
64
65/*
66 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0102
67 * @tc.name: testPointCreateAbnormal
68 * @tc.desc: test for testPointCreateAbnormal.
69 * @tc.size  : SmallTest
70 * @tc.type  : Function
71 * @tc.level : Level 3
72 */
73HWTEST_F(DrawingNativePointTest, testPointCreateAbnormal, TestSize.Level3) {
74    // 1. The first parameter of OH_Drawing_PointCreate is negative
75    OH_Drawing_Point *point = OH_Drawing_PointCreate(-100, 60);
76    // 2. The second parameter of OH_Drawing_PointCreate is negative
77    OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100, -60);
78    // 3. Free memory
79    OH_Drawing_PointDestroy(point);
80    OH_Drawing_PointDestroy(point2);
81}
82
83/*
84 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0103
85 * @tc.name: testPointCreateMaximum
86 * @tc.desc: test for testPointCreateMaximum.
87 * @tc.size  : SmallTest
88 * @tc.type  : Function
89 * @tc.level : Level 3
90 */
91HWTEST_F(DrawingNativePointTest, testPointCreateMaximum, TestSize.Level3) {
92    // 1. The first parameter of OH_Drawing_PointCreate is FLT_MAX
93    OH_Drawing_Point *point = OH_Drawing_PointCreate(FLT_MAX, 60);
94    // 2. The second parameter of OH_Drawing_PointCreate is FLT_MAX
95    OH_Drawing_Point *point2 = OH_Drawing_PointCreate(100, FLT_MAX);
96    // 3. Free memory
97    OH_Drawing_PointDestroy(point);
98    OH_Drawing_PointDestroy(point2);
99}
100
101/*
102 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0104
103 * @tc.name: testPointCreateMultipleCalls
104 * @tc.desc: test for testPointCreateMultipleCalls.
105 * @tc.size  : SmallTest
106 * @tc.type  : Function
107 * @tc.level : Level 3
108 */
109HWTEST_F(DrawingNativePointTest, testPointCreateMultipleCalls, TestSize.Level3) {
110    // 1. Call OH_Drawing_PointCreate 10 times with random values for X and Y coordinates
111    std::random_device rd;
112    std::mt19937 gen(rd());
113    std::uniform_real_distribution<float> dis(0, 100);
114    for (int i = 0; i < 10; i++) {
115        OH_Drawing_Point *point = OH_Drawing_PointCreate(dis(gen), dis(gen));
116        OH_Drawing_PointDestroy(point);
117    }
118}
119
120/*
121 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0200
122 * @tc.name: testPointDestroyNormal
123 * @tc.desc: test for testPointDestroyNormal.
124 * @tc.size  : SmallTest
125 * @tc.type  : Function
126 * @tc.level : Level 0
127 */
128HWTEST_F(DrawingNativePointTest, testPointDestroyNormal, TestSize.Level0) {
129    // 1. Call OH_Drawing_PointCreate
130    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
131    // 2. Call OH_Drawing_PointDestroy
132    OH_Drawing_PointDestroy(point);
133}
134
135/*
136 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0201
137 * @tc.name: testPointDestroyNull
138 * @tc.desc: test for testPointDestroyNull.
139 * @tc.size  : SmallTest
140 * @tc.type  : Function
141 * @tc.level : Level 3
142 */
143HWTEST_F(DrawingNativePointTest, testPointDestroyNull, TestSize.Level3) {
144    // 1. The parameter of OH_Drawing_PointDestroy is nullptr
145    OH_Drawing_PointDestroy(nullptr);
146}
147
148/*
149 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0300
150 * @tc.name: testPointGetXNormal
151 * @tc.desc: test for testPointGetXNormal.
152 * @tc.size  : SmallTest
153 * @tc.type  : Function
154 * @tc.level : Level 0
155 */
156HWTEST_F(DrawingNativePointTest, testPointGetXNormal, TestSize.Level0) {
157    //1. Pass integer values to OH_Drawing_PointGetX interface
158    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
159    float x;
160    OH_Drawing_PointGetX(point, &x);
161    //2. Pass floating-point values to OH_Drawing_PointGetX interface
162    OH_Drawing_Point *point1 = OH_Drawing_PointCreate(100.0f, 60.0f);
163    OH_Drawing_PointGetX(point1, &x);
164    //3. free memory
165    OH_Drawing_PointDestroy(point);
166    OH_Drawing_PointDestroy(point1);
167}
168
169/*
170 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0301
171 * @tc.name: testPointGetXNull
172 * @tc.desc: test for testPointGetXNull.
173 * @tc.size  : SmallTest
174 * @tc.type  : Function
175 * @tc.level : Level 3
176 */
177HWTEST_F(DrawingNativePointTest, testPointGetXNull, TestSize.Level3) {
178    //1. OH_Drawing_PointGetX with the first parameter as null
179    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
180    float x;
181    OH_Drawing_PointGetX(nullptr, &x);
182    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
183    //2. OH_Drawing_PointGetX with the second parameter as null
184    OH_Drawing_PointGetX(point, nullptr);
185    //3. free memory
186    OH_Drawing_PointDestroy(point);
187    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
188}
189
190/*
191 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0302
192 * @tc.name: testPointGetXMultipleCalls
193 * @tc.desc: test for testPointGetXMultipleCalls.
194 * @tc.size  : SmallTest
195 * @tc.type  : Function
196 * @tc.level : Level 3
197 */
198HWTEST_F(DrawingNativePointTest, testPointGetXMultipleCalls, TestSize.Level3) {
199    //1. Call OH_Drawing_PointGetX 10 times with random values
200    std::random_device rd;
201    std::mt19937 gen(rd());
202    std::uniform_real_distribution<float> dis(0, 100);
203    float x;
204    OH_Drawing_Point *point = nullptr;
205    for (int i = 0; i < 10; i++) {
206        point = OH_Drawing_PointCreate(dis(gen), dis(gen));
207        OH_Drawing_PointGetX(point, &x);
208    }
209    //2. free memory
210    OH_Drawing_PointDestroy(point);
211}
212
213/*
214 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0400
215 * @tc.name: testPointGetYNormal
216 * @tc.desc: test for testPointGetYNormal.
217 * @tc.size  : SmallTest
218 * @tc.type  : Function
219 * @tc.level : Level 0
220 */
221HWTEST_F(DrawingNativePointTest, testPointGetYNormal, TestSize.Level0) {
222    //1. Pass integer values to OH_Drawing_PointGetY interface
223    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
224    float y;
225    OH_Drawing_PointGetX(nullptr, &y);
226    //2. Pass floating-point values to OH_Drawing_PointGetX interface
227    OH_Drawing_Point *point1 = OH_Drawing_PointCreate(100.0f, 60.0f);
228    OH_Drawing_PointGetX(point1, &y);
229    //3. free memory
230    OH_Drawing_PointDestroy(point);
231    OH_Drawing_PointDestroy(point1);
232}
233
234/*
235 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0401
236 * @tc.name: testPointGetYNull
237 * @tc.desc: test for testPointGetYNull.
238 * @tc.size  : SmallTest
239 * @tc.type  : Function
240 * @tc.level : Level 3
241 */
242HWTEST_F(DrawingNativePointTest, testPointGetYNull, TestSize.Level3) {
243    //1. OH_Drawing_PointGetY with the first parameter as null
244    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
245    float y;
246    OH_Drawing_PointGetX(nullptr, &y);
247    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
248    //2. OH_Drawing_PointGetY with the second parameter as null
249    OH_Drawing_PointGetX(point, nullptr);
250    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
251    //3. free memory
252    OH_Drawing_PointDestroy(point);
253}
254
255/*
256 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0402
257 * @tc.name: testPointGetYMultipleCalls
258 * @tc.desc: test for testPointGetYMultipleCalls.
259 * @tc.size  : SmallTest
260 * @tc.type  : Function
261 * @tc.level : Level 3
262 */
263HWTEST_F(DrawingNativePointTest, testPointGetYMultipleCalls, TestSize.Level3) {
264    //1. Call OH_Drawing_PointGetX 10 times with random values
265    std::random_device rd;
266    std::mt19937 gen(rd());
267    std::uniform_real_distribution<float> dis(0, 100);
268    float y;
269    OH_Drawing_Point *point = nullptr;
270    for (int i = 0; i < 10; i++) {
271        OH_Drawing_Point *point = OH_Drawing_PointCreate(dis(gen), dis(gen));
272        OH_Drawing_PointGetX(point, &y);
273    }
274    //2. free memory
275    OH_Drawing_PointDestroy(point);
276}
277
278/*
279 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0400
280 * @tc.name: testPointSetNormal
281 * @tc.desc: test for testPointSetNormal.
282 * @tc.size  : SmallTest
283 * @tc.type  : Function
284 * @tc.level : Level 0
285 */
286HWTEST_F(DrawingNativePointTest, testPointSetNormal, TestSize.Level0) {
287    //1. Pass integar point values to OH_Drawing_PointSet interface
288    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
289    OH_Drawing_PointSet(point, 10, 10);
290    //2. Pass floating-point values to OH_Drawing_PointSet interface
291    OH_Drawing_PointSet(point, 20.f, 20.f);
292    //3. free memory
293    OH_Drawing_PointDestroy(point);
294}
295
296/*
297 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0401
298 * @tc.name: testPointSetNull
299 * @tc.desc: test for testPointSetNull.
300 * @tc.size  : SmallTest
301 * @tc.type  : Function
302 * @tc.level : Level 3
303 */
304HWTEST_F(DrawingNativePointTest, testPointSetNull, TestSize.Level3) {
305    //1. OH_Drawing_PointSet with the first parameter as null
306    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
307    OH_Drawing_PointSet(nullptr, 10, 10);
308    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
309    //2. OH_Drawing_PointSet with the second parameter as 0
310    OH_Drawing_PointSet(point, 0, 10);
311    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
312    //3. OH_Drawing_PointSet with the third parameter as 0
313    OH_Drawing_PointSet(point, 10, 0);
314    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_DRAWING_ERROR_INVALID_PARAMETER);
315    //4. free memory
316    OH_Drawing_PointDestroy(point);
317}
318
319/*
320 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_POINT_0402
321 * @tc.name: testPointSetMultipleCalls
322 * @tc.desc: test for testPointSetMultipleCalls.
323 * @tc.size  : SmallTest
324 * @tc.type  : Function
325 * @tc.level : Level 3
326 */
327HWTEST_F(DrawingNativePointTest, testPointSetMultipleCalls, TestSize.Level3) {
328    //1. Call OH_Drawing_PointSet 10 times with random values
329    OH_Drawing_Point *point = OH_Drawing_PointCreate(100, 60);
330    std::random_device rd;
331    std::mt19937 gen(rd());
332    std::uniform_real_distribution<float> dis(0, 100);
333    for (int i = 0; i < 10; i++) {
334        OH_Drawing_PointSet(point, dis(gen), dis(gen));
335    }
336    //2. free memory
337    OH_Drawing_PointDestroy(point);
338}
339
340} // namespace Drawing
341} // namespace Rosen
342} // namespace OHOS