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_color_filter.h"
18 #include "drawing_filter.h"
19 #include "drawing_image.h"
20 #include "drawing_matrix.h"
21 #include "drawing_path.h"
22 #include "drawing_path_effect.h"
23 #include "drawing_pen.h"
24 #include "drawing_point.h"
25 #include "drawing_rect.h"
26 #include "drawing_region.h"
27 #include "drawing_round_rect.h"
28 #include "utils/scalar.h"
29 #include "gtest/gtest.h"
30 
31 using namespace testing;
32 using namespace testing::ext;
33 
34 namespace OHOS {
35 namespace Rosen {
36 namespace Drawing {
37 class DrawingNativePathEffectTest : public testing::Test {};
38 
39 /*
40  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0100
41  * @tc.name: testCreateDashPathEffectNormal
42  * @tc.desc: test for testCreateDashPathEffectNormal.
43  * @tc.size  : SmallTest
44  * @tc.type  : Function
45  * @tc.level : Level 0
46  */
HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectNormal, TestSize.Level0)47 HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectNormal, TestSize.Level0) {
48     // 1. OH_Drawing_CreateDashPathEffect
49     float intervals[] = {1, 1, 1};
50     OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, 3, 0.0);
51     // 2. Free memory
52     OH_Drawing_PathEffectDestroy(pathEffect);
53 }
54 
55 /*
56  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0101
57  * @tc.name: testCreateDashPathEffectNull
58  * @tc.desc: test for testCreateDashPathEffectNull.
59  * @tc.size  : SmallTest
60  * @tc.type  : Function
61  * @tc.level : Level 3
62  */
HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectNull, TestSize.Level3)63 HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectNull, TestSize.Level3) {
64     float intervals[] = {1, 1};
65     // 1. OH_Drawing_CreateDashPathEffect with nullptr as the first parameter, check the error code with
66     // OH_Drawing_ErrorCodeGet
67     OH_Drawing_PathEffect *pathEffect1 = OH_Drawing_CreateDashPathEffect(nullptr, 2, 1.0);
68     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
69     // 2. OH_Drawing_CreateDashPathEffect with 0 as the second parameter, check the error code with
70     // OH_Drawing_ErrorCodeGet
71     OH_Drawing_PathEffect *pathEffect2 = OH_Drawing_CreateDashPathEffect(intervals, 0, 1.0);
72     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
73     // 3. OH_Drawing_CreateDashPathEffect with 0.0 as the third parameter
74     OH_Drawing_PathEffect *pathEffect3 = OH_Drawing_CreateDashPathEffect(intervals, 2, 0.0);
75     // 4. Free memory
76     OH_Drawing_PathEffectDestroy(pathEffect1);
77     OH_Drawing_PathEffectDestroy(pathEffect2);
78     OH_Drawing_PathEffectDestroy(pathEffect3);
79 }
80 
81 /*
82  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0102
83  * @tc.name: testCreateDashPathEffectAbnormal
84  * @tc.desc: test for testCreateDashPathEffectAbnormal.
85  * @tc.size  : SmallTest
86  * @tc.type  : Function
87  * @tc.level : Level 3
88  */
HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectAbnormal, TestSize.Level3)89 HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectAbnormal, TestSize.Level3) {
90     float intervals[] = {1, 1, 1};
91     // 1. OH_Drawing_CreateDashPathEffect with the first parameter not being even
92     OH_Drawing_PathEffect *pathEffect1 = OH_Drawing_CreateDashPathEffect(intervals, 3, 1.0);
93     // 2. OH_Drawing_CreateDashPathEffect with the second parameter being negative, check the error code with
94     // OH_Drawing_ErrorCodeGet
95     OH_Drawing_PathEffect *pathEffect2 = OH_Drawing_CreateDashPathEffect(intervals, -3, 1.0);
96     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
97     // 3. OH_Drawing_CreateDashPathEffect with the second parameter being 1
98     OH_Drawing_PathEffect *pathEffect3 = OH_Drawing_CreateDashPathEffect(intervals, 1, 1.0);
99     // 4. OH_Drawing_CreateDashPathEffect with the third parameter being negative
100     OH_Drawing_PathEffect *pathEffect4 = OH_Drawing_CreateDashPathEffect(intervals, 3, -1.0);
101     // 5. Free memory
102     OH_Drawing_PathEffectDestroy(pathEffect1);
103     OH_Drawing_PathEffectDestroy(pathEffect2);
104     OH_Drawing_PathEffectDestroy(pathEffect3);
105     OH_Drawing_PathEffectDestroy(pathEffect4);
106 }
107 
108 /*
109  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0104
110  * @tc.name: testCreateDashPathEffectMultipleCalls
111  * @tc.desc: test for testCreateDashPathEffectMultipleCalls.
112  * @tc.size  : SmallTest
113  * @tc.type  : Function
114  * @tc.level : Level 3
115  */
HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectMultipleCalls, TestSize.Level3)116 HWTEST_F(DrawingNativePathEffectTest, testCreateDashPathEffectMultipleCalls, TestSize.Level3) {
117     float intervals[] = {1, 1};
118     // 1. Call OH_Drawing_CreateDashPathEffect 10 times
119     for (int i = 0; i < 10; i++) {
120         OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, 2, 1.0);
121         // 2. Free memory
122         OH_Drawing_PathEffectDestroy(pathEffect);
123     }
124 }
125 
126 /*
127  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0200
128  * @tc.name: testPathEffectDestroyNormal
129  * @tc.desc: test for testPathEffectDestroyNormal.
130  * @tc.size  : SmallTest
131  * @tc.type  : Function
132  * @tc.level : Level 0
133  */
HWTEST_F(DrawingNativePathEffectTest, testPathEffectDestroyNormal, TestSize.Level0)134 HWTEST_F(DrawingNativePathEffectTest, testPathEffectDestroyNormal, TestSize.Level0) {
135     float intervals[] = {1, 1, 1};
136     // 1. OH_Drawing_CreateDashPathEffect
137     OH_Drawing_PathEffect *pathEffect = OH_Drawing_CreateDashPathEffect(intervals, 3, 0.0);
138     // 2. OH_Drawing_PathEffectDestroy
139     OH_Drawing_PathEffectDestroy(pathEffect);
140 }
141 
142 /*
143  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PATH_EFFECT_0201
144  * @tc.name: testPathEffectDestroyNull
145  * @tc.desc: test for testPathEffectDestroyNull.
146  * @tc.size  : SmallTest
147  * @tc.type  : Function
148  * @tc.level : Level 3
149  */
HWTEST_F(DrawingNativePathEffectTest, testPathEffectDestroyNull, TestSize.Level3)150 HWTEST_F(DrawingNativePathEffectTest, testPathEffectDestroyNull, TestSize.Level3) {
151     // 1. OH_Drawing_PathEffectDestroy with nullptr as the parameter
152     OH_Drawing_PathEffectDestroy(nullptr);
153 }
154 
155 } // namespace Drawing
156 } // namespace Rosen
157 } // namespace OHOS