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 #include <cmath>
16 
17 #include "gtest/gtest.h"
18 
19 #include "drawing_bitmap.h"
20 #include "drawing_brush.h"
21 #include "drawing_canvas.h"
22 #include "drawing_color.h"
23 #include "drawing_color_filter.h"
24 #include "drawing_filter.h"
25 #include "drawing_font.h"
26 #include "drawing_image.h"
27 #include "drawing_mask_filter.h"
28 #include "drawing_matrix.h"
29 #include "drawing_memory_stream.h"
30 #include "drawing_path.h"
31 #include "drawing_pen.h"
32 #include "drawing_point.h"
33 #include "drawing_rect.h"
34 #include "drawing_region.h"
35 #include "drawing_round_rect.h"
36 #include "drawing_sampling_options.h"
37 #include "drawing_shader_effect.h"
38 #include "drawing_shadow_layer.h"
39 #include "drawing_text_blob.h"
40 #include "drawing_typeface.h"
41 
42 using namespace testing;
43 using namespace testing::ext;
44 
45 namespace OHOS {
46 namespace Rosen {
47 namespace Drawing {
48 class DrawingNativeBrushTest : public testing::Test {};
49 
50 /*
51  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0100
52  * @tc.name: testBrushCreateNormal
53  * @tc.desc: test for testBrushCreateNormal.
54  * @tc.size  : SmallTest
55  * @tc.type  : Function
56  * @tc.level : Level 0
57  */
HWTEST_F(DrawingNativeBrushTest, testBrushCreateNormal, TestSize.Level0)58 HWTEST_F(DrawingNativeBrushTest, testBrushCreateNormal, TestSize.Level0) {
59     // 1. Call OH_Drawing_BrushCreate to create a brush object
60     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
61     // 2. Free memory
62     OH_Drawing_BrushDestroy(brush);
63 }
64 
65 /*
66  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0200
67  * @tc.name: testBrushCopyNormal
68  * @tc.desc: test for testBrushCopyNormal.
69  * @tc.size  : SmallTest
70  * @tc.type  : Function
71  * @tc.level : Level 0
72  */
HWTEST_F(DrawingNativeBrushTest, testBrushCopyNormal, TestSize.Level0)73 HWTEST_F(DrawingNativeBrushTest, testBrushCopyNormal, TestSize.Level0) {
74     // 1. Create a brush object 1 by calling OH_Drawing_BrushCreate
75     OH_Drawing_Brush *brush1 = OH_Drawing_BrushCreate();
76     // 2. Set the color of brush 1 by calling OH_Drawing_BrushSetColor
77     OH_Drawing_BrushSetColor(brush1, 0x12345678);
78     // 3. Copy brush 1 to create brush object 2 by calling OH_Drawing_BrushCopy
79     OH_Drawing_Brush *brush2 = OH_Drawing_BrushCopy(brush1);
80     // 4. Get the color of brush object 2 by calling OH_Drawing_BrushGetColor
81     uint32_t color = OH_Drawing_BrushGetColor(brush2);
82     EXPECT_EQ(color, 0x12345678);
83     // 5. Modify the color of brush object 1 by calling OH_Drawing_BrushSetColor
84     OH_Drawing_BrushSetColor(brush1, 0x87654321);
85     // 6. Get the color of brush object 2 again by calling OH_Drawing_BrushGetColor
86     color = OH_Drawing_BrushGetColor(brush2);
87     EXPECT_EQ(color, 0x12345678);
88     // 7. Free memory
89     OH_Drawing_BrushDestroy(brush1);
90     OH_Drawing_BrushDestroy(brush2);
91 }
92 
93 /*
94  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0201
95  * @tc.name: testBrushCopyNull
96  * @tc.desc: test for testBrushCopyNull.
97  * @tc.size  : SmallTest
98  * @tc.type  : Function
99  * @tc.level : Level 3
100  */
HWTEST_F(DrawingNativeBrushTest, testBrushCopyNull, TestSize.Level3)101 HWTEST_F(DrawingNativeBrushTest, testBrushCopyNull, TestSize.Level3) {
102     // 1. Create a brush object by calling OH_Drawing_BrushCreate
103     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
104     // 2. Copy a brush object by calling OH_Drawing_BrushCopy with nullptr as parameter
105     OH_Drawing_Brush *brushCopy = OH_Drawing_BrushCopy(nullptr);
106     // 3. Free memory
107     OH_Drawing_BrushDestroy(brush);
108     OH_Drawing_BrushDestroy(brushCopy);
109 }
110 
111 /*
112  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0202
113  * @tc.name: testBrushCopyInputDestroyed
114  * @tc.desc: test for testBrushCopyInputDestroyed.
115  * @tc.size  : SmallTest
116  * @tc.type  : Function
117  * @tc.level : Level 3
118  */
HWTEST_F(DrawingNativeBrushTest, testBrushCopyInputDestroyed, TestSize.Level3)119 HWTEST_F(DrawingNativeBrushTest, testBrushCopyInputDestroyed, TestSize.Level3) {
120     // 1. Call OH_Drawing_BrushCreate to create a brush object 1
121     OH_Drawing_Brush *brush1 = OH_Drawing_BrushCreate();
122     // 2. Copy brush object 1 to create brush object 2 by calling OH_Drawing_BrushCopy
123     OH_Drawing_Brush *brush2 = OH_Drawing_BrushCopy(brush1);
124     // 3. Destroy brush object 1 by calling OH_Drawing_BrushDestroy
125     OH_Drawing_BrushDestroy(brush1);
126     // 4. Set the color of brush object 2 by calling OH_Drawing_BrushSetColor
127     OH_Drawing_BrushSetColor(brush2, 0x12345678);
128     // 5. Get the color of brush object 2 by calling OH_Drawing_BrushGetColor
129     uint32_t color = OH_Drawing_BrushGetColor(brush2);
130     EXPECT_EQ(color, 0x12345678);
131     // 6. Free memory
132     OH_Drawing_BrushDestroy(brush2);
133 }
134 
135 /*
136  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0203
137  * @tc.name: testBrushCopyMultipleCalls
138  * @tc.desc: test for testBrushCopyMultipleCalls.
139  * @tc.size  : SmallTest
140  * @tc.type  : Function
141  * @tc.level : Level 3
142  */
HWTEST_F(DrawingNativeBrushTest, testBrushCopyMultipleCalls, TestSize.Level3)143 HWTEST_F(DrawingNativeBrushTest, testBrushCopyMultipleCalls, TestSize.Level3) {
144     // 1. Create a brush object by calling OH_Drawing_BrushCreate
145     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
146     // 2. Call OH_Drawing_BrushCopy ten times in a loop
147     for (int i = 0; i < 10; i++) {
148         OH_Drawing_Brush *brushCopy = OH_Drawing_BrushCopy(brush);
149         OH_Drawing_BrushDestroy(brushCopy);
150     }
151     // 3. Free memory
152     OH_Drawing_BrushDestroy(brush);
153 }
154 
155 /*
156  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0300
157  * @tc.name: testBrushDestroyNormal
158  * @tc.desc: test for testBrushDestroyNormal.
159  * @tc.size  : SmallTest
160  * @tc.type  : Function
161  * @tc.level : Level 0
162  */
HWTEST_F(DrawingNativeBrushTest, testBrushDestroyNormal, TestSize.Level0)163 HWTEST_F(DrawingNativeBrushTest, testBrushDestroyNormal, TestSize.Level0) {
164     // 1. Call OH_Drawing_BrushCreate to create a brush object
165     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
166     // 2. Call OH_Drawing_BrushDestroy to destroy the object
167     OH_Drawing_BrushDestroy(brush);
168 }
169 
170 /*
171  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0301
172  * @tc.name: testBrushDestroyNull
173  * @tc.desc: test for testBrushDestroyNull.
174  * @tc.size  : SmallTest
175  * @tc.type  : Function
176  * @tc.level : Level 3
177  */
HWTEST_F(DrawingNativeBrushTest, testBrushDestroyNull, TestSize.Level3)178 HWTEST_F(DrawingNativeBrushTest, testBrushDestroyNull, TestSize.Level3) {
179     // 1. Create a brush object by calling OH_Drawing_BrushCreate
180     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
181     // 2. Call OH_Drawing_BrushDestroy with nullptr as parameter
182     OH_Drawing_BrushDestroy(nullptr);
183     // 3. Free memory
184     OH_Drawing_BrushDestroy(brush);
185 }
186 
187 /*
188  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0400
189  * @tc.name: testBrushIsAntiAliasNormal
190  * @tc.desc: test for testBrushIsAntiAliasNormal.
191  * @tc.size  : SmallTest
192  * @tc.type  : Function
193  * @tc.level : Level 0
194  */
HWTEST_F(DrawingNativeBrushTest, testBrushIsAntiAliasNormal, TestSize.Level0)195 HWTEST_F(DrawingNativeBrushTest, testBrushIsAntiAliasNormal, TestSize.Level0) {
196     // 1. Call OH_Drawing_BrushCreate to create a brush object
197     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
198     // 2. Call OH_Drawing_BrushSetAntiAlias to set the anti-aliasing property to true
199     OH_Drawing_BrushSetAntiAlias(brush, true);
200     // 3. Call OH_Drawing_BrushIsAntiAlias to check the return value
201     bool isAntiAlias = OH_Drawing_BrushIsAntiAlias(brush);
202     EXPECT_EQ(isAntiAlias, true);
203     // 4. Free memory
204     OH_Drawing_BrushDestroy(brush);
205 }
206 
207 /*
208  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0401
209  * @tc.name: testBrushIsAntiAliasNull
210  * @tc.desc: test for testBrushIsAntiAliasNull.
211  * @tc.size  : SmallTest
212  * @tc.type  : Function
213  * @tc.level : Level 3
214  */
HWTEST_F(DrawingNativeBrushTest, testBrushIsAntiAliasNull, TestSize.Level3)215 HWTEST_F(DrawingNativeBrushTest, testBrushIsAntiAliasNull, TestSize.Level3) {
216     // 1. Create a brush object by calling OH_Drawing_BrushCreate
217     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
218     // 2. Call OH_Drawing_BrushIsAntiAlias with nullptr as parameter
219     OH_Drawing_BrushIsAntiAlias(nullptr);
220     // 3. Free memory
221     OH_Drawing_BrushDestroy(brush);
222 }
223 
224 /*
225  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0500
226  * @tc.name: testBrushSetAntiAliasNormal
227  * @tc.desc: test for testBrushSetAntiAliasNormal.
228  * @tc.size: SmallTest
229  * @tc.type: Function
230  * @tc.level: Level 0
231  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetAntiAliasNormal, TestSize.Level0)232 HWTEST_F(DrawingNativeBrushTest, testBrushSetAntiAliasNormal, TestSize.Level0) {
233     // 1. Call OH_Drawing_BrushCreate to create a brush object
234     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
235     // 2. Call OH_Drawing_BrushSetAntiAlias to set the anti-aliasing property to true
236     OH_Drawing_BrushSetAntiAlias(brush, true);
237     // 3. Call OH_Drawing_BrushIsAntiAlias to check the return value
238     bool isAntiAlias = OH_Drawing_BrushIsAntiAlias(brush);
239     EXPECT_EQ(isAntiAlias, true);
240     // 4. Free memory
241     OH_Drawing_BrushDestroy(brush);
242 }
243 
244 /*
245  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0501
246  * @tc.name: testBrushSetAntiAliasNull
247  * @tc.desc: test for testBrushSetAntiAliasNull.
248  * @tc.size: SmallTest
249  * @tc.type: Function
250  * @tc.level: Level 3
251  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetAntiAliasNull, TestSize.Level3)252 HWTEST_F(DrawingNativeBrushTest, testBrushSetAntiAliasNull, TestSize.Level3) {
253     // 1. Create a brush object by calling OH_Drawing_BrushCreate
254     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
255     // 2. Call OH_Drawing_BrushSetAntiAlias with nullptr as the first parameter
256     OH_Drawing_BrushSetAntiAlias(nullptr, true);
257     // 3. Free memory
258     OH_Drawing_BrushDestroy(brush);
259 }
260 
261 /*
262  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0600
263  * @tc.name: testBrushGetColorNormal
264  * @tc.desc: Test for testBrushGetColorNormal.
265  * @tc.size: SmallTest
266  * @tc.type: Function
267  * @tc.level: Level 0
268  */
HWTEST_F(DrawingNativeBrushTest, testBrushGetColorNormal, TestSize.Level0)269 HWTEST_F(DrawingNativeBrushTest, testBrushGetColorNormal, TestSize.Level0) {
270     // 1. Create a brush object by calling OH_Drawing_BrushCreate
271     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
272     // 2. Set the color of the brush object by calling OH_Drawing_BrushSetColor
273     OH_Drawing_BrushSetColor(brush, 0x12345678);
274     // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor
275     uint32_t color = OH_Drawing_BrushGetColor(brush);
276     EXPECT_EQ(color, 0x12345678);
277     // 4. Free memory
278     OH_Drawing_BrushDestroy(brush);
279 }
280 
281 /*
282  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0601
283  * @tc.name: testBrushGetColorNull
284  * @tc.desc: Test for testBrushGetColorNull.
285  * @tc.size: SmallTest
286  * @tc.type: Function
287  * @tc.level: Level 3
288  */
HWTEST_F(DrawingNativeBrushTest, testBrushGetColorNull, TestSize.Level3)289 HWTEST_F(DrawingNativeBrushTest, testBrushGetColorNull, TestSize.Level3) {
290     // 1. Create a brush object by calling OH_Drawing_BrushCreate
291     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
292     // 2. Call OH_Drawing_BrushGetColor with nullptr as parameter
293     OH_Drawing_BrushGetColor(nullptr);
294     // 3. Free memory
295     OH_Drawing_BrushDestroy(brush);
296 }
297 
298 /*
299  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0700
300  * @tc.name: testBrushSetColorNormal
301  * @tc.desc: Test for testBrushSetColorNormal.
302  * @tc.size: SmallTest
303  * @tc.type: Function
304  * @tc.level: Level 0
305  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetColorNormal, TestSize.Level0)306 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorNormal, TestSize.Level0) {
307     // 1. Create a brush object by calling OH_Drawing_BrushCreate
308     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
309     // 2. Set the color of the brush object by calling OH_Drawing_BrushSetColor
310     OH_Drawing_BrushSetColor(brush, 0x12345678);
311     // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor
312     uint32_t color = OH_Drawing_BrushGetColor(brush);
313     EXPECT_EQ(color, 0x12345678);
314     // 4. Free memory
315     OH_Drawing_BrushDestroy(brush);
316 }
317 
318 /*
319  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0701
320  * @tc.name: testBrushSetColorNull
321  * @tc.desc: Test for testBrushSetColorNull.
322  * @tc.size: SmallTest
323  * @tc.type: Function
324  * @tc.level: Level 3
325  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetColorNull, TestSize.Level3)326 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorNull, TestSize.Level3) {
327     // 1. Create a brush object by calling OH_Drawing_BrushCreate
328     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
329     // 2. Call OH_Drawing_BrushSetColor with nullptr as the first parameter
330     OH_Drawing_BrushSetColor(nullptr, 0x12345678);
331     // 3. Call OH_Drawing_BrushSetColor with 0 as the second parameter
332     OH_Drawing_BrushSetColor(brush, 0);
333     // 4. Call OH_Drawing_BrushGetColor to get the brush color
334     uint32_t color = OH_Drawing_BrushGetColor(brush);
335     EXPECT_EQ(color, 0);
336     // 5. Free memory
337     OH_Drawing_BrushDestroy(brush);
338 }
339 
340 /*
341  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0702
342  * @tc.name: testBrushSetColorAbnormal
343  * @tc.desc: Test for testBrushSetColorAbnormal.
344  * @tc.size: SmallTest
345  * @tc.type: Function
346  * @tc.level: Level 3
347  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetColorAbnormal, TestSize.Level3)348 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorAbnormal, TestSize.Level3) {
349     // 1. Create a brush object by calling OH_Drawing_BrushCreate
350     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
351     // 2. Call OH_Drawing_BrushSetColor with a negative number or a non-uint32_t type parameter as the second argument
352     OH_Drawing_BrushSetColor(brush, -1);
353     // Ignoring the test for passing a floating-point number, as it will result in an error
354     // 3. Call OH_Drawing_BrushGetColor to get the brush color
355     uint32_t color = OH_Drawing_BrushGetColor(brush);
356     EXPECT_EQ(color, std::pow(2, 32) - 1);
357     // 4. Free memory
358     OH_Drawing_BrushDestroy(brush);
359 }
360 
361 /*
362  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0703
363  * @tc.name: testBrushSetColorMaximum
364  * @tc.desc: Test for testBrushSetColorMaximum.
365  * @tc.size: SmallTest
366  * @tc.type: Function
367  * @tc.level: Level 3
368  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetColorMaximum, TestSize.Level3)369 HWTEST_F(DrawingNativeBrushTest, testBrushSetColorMaximum, TestSize.Level3) {
370     // 1. Create a brush object by calling OH_Drawing_BrushCreate
371     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
372     // 2. Set the color of the brush object by calling OH_Drawing_BrushSetColor with a value greater than the maximum
373     // value of uint32_t (0xFFFFFFFF)
374     OH_Drawing_BrushSetColor(brush, 0xFFFFFFFF + 1);
375     // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor
376     uint32_t color = OH_Drawing_BrushGetColor(brush);
377     EXPECT_EQ(color, 0);
378     // 4. Free memory
379     OH_Drawing_BrushDestroy(brush);
380 }
381 
382 /*
383  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0800
384  * @tc.name: testBrushGetAlphaNormal
385  * @tc.desc: Test for testBrushGetAlphaNormal.
386  * @tc.size: SmallTest
387  * @tc.type: Function
388  * @tc.level: Level 0
389  */
HWTEST_F(DrawingNativeBrushTest, testBrushGetAlphaNormal, TestSize.Level0)390 HWTEST_F(DrawingNativeBrushTest, testBrushGetAlphaNormal, TestSize.Level0) {
391     // 1. Create a brush object by calling OH_Drawing_BrushCreate
392     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
393     // 2. Set the alpha value of the brush object by calling OH_Drawing_BrushSetAlpha
394     OH_Drawing_BrushSetAlpha(brush, 128);
395     // 3. Get the alpha value of the brush object by calling OH_Drawing_BrushGetAlpha
396     uint8_t alpha = OH_Drawing_BrushGetAlpha(brush);
397     EXPECT_EQ(alpha, 128);
398     // 4. Free memory
399     OH_Drawing_BrushDestroy(brush);
400 }
401 
402 /*
403  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0801
404  * @tc.name: testBrushGetAlphaNull
405  * @tc.desc: Test for testBrushGetAlphaNull.
406  * @tc.size: SmallTest
407  * @tc.type: Function
408  * @tc.level: Level 3
409  */
HWTEST_F(DrawingNativeBrushTest, testBrushGetAlphaNull, TestSize.Level3)410 HWTEST_F(DrawingNativeBrushTest, testBrushGetAlphaNull, TestSize.Level3) {
411     // 1. Create a brush object by calling OH_Drawing_BrushCreate
412     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
413     // 2. Call OH_Drawing_BrushGetAlpha with nullptr as parameter
414     OH_Drawing_BrushGetAlpha(nullptr);
415     // 3. Free memory
416     OH_Drawing_BrushDestroy(brush);
417 }
418 
419 /*
420  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0900
421  * @tc.name: testBrushSetAlphaNormal
422  * @tc.desc: Test for testBrushSetAlphaNormal.
423  * @tc.size: SmallTest
424  * @tc.type: Function
425  * @tc.level: Level 0
426  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaNormal, TestSize.Level0)427 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaNormal, TestSize.Level0) {
428     // 1. Create a brush object by calling OH_Drawing_BrushCreate
429     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
430     // 2. Set the alpha value of the brush object by calling OH_Drawing_BrushSetAlpha
431     OH_Drawing_BrushSetAlpha(brush, 128);
432     // 3. Get the alpha value of the brush object by calling OH_Drawing_BrushGetAlpha
433     uint8_t alpha = OH_Drawing_BrushGetAlpha(brush);
434     EXPECT_EQ(alpha, 128);
435     // 4. Free memory
436     OH_Drawing_BrushDestroy(brush);
437 }
438 
439 /*
440  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0901
441  * @tc.name: testBrushSetAlphaNull
442  * @tc.desc: Test for testBrushSetAlphaNull.
443  * @tc.size: SmallTest
444  * @tc.type: Function
445  * @tc.level: Level 3
446  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaNull, TestSize.Level3)447 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaNull, TestSize.Level3) {
448     // 1. Create a brush object by calling OH_Drawing_BrushCreate
449     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
450     // 2. Call OH_Drawing_BrushSetAlpha with nullptr as the first parameter
451     OH_Drawing_BrushSetAlpha(nullptr, 128);
452     // 3. Call OH_Drawing_BrushSetAlpha with 0 as the second parameter
453     OH_Drawing_BrushSetAlpha(brush, 0);
454     // 4. Free memory
455     OH_Drawing_BrushDestroy(brush);
456 }
457 
458 /*
459  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0902
460  * @tc.name: testBrushSetAlphaAbnormal
461  * @tc.desc: Test for testBrushSetAlphaAbnormal.
462  * @tc.size: SmallTest
463  * @tc.type: Function
464  * @tc.level: Level 3
465  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaAbnormal, TestSize.Level3)466 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaAbnormal, TestSize.Level3) {
467     // 1. Create a brush object by calling OH_Drawing_BrushCreate
468     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
469     // 2. Call OH_Drawing_BrushSetAlpha with a negative number or a non-uint8_t type parameter as the second argument
470     OH_Drawing_BrushSetAlpha(brush, -1);
471     // 3. Call OH_Drawing_BrushGetAlpha to get the alpha value
472     uint8_t alpha = OH_Drawing_BrushGetAlpha(brush);
473     EXPECT_EQ(alpha, 0xff);
474     // 4. Free memory
475     OH_Drawing_BrushDestroy(brush);
476 }
477 
478 /*
479  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_0903
480  * @tc.name: testBrushSetAlphaMaximum
481  * @tc.desc: Test for testBrushSetAlphaMaximum.
482  * @tc.size: SmallTest
483  * @tc.type: Function
484  * @tc.level: Level 3
485  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaMaximum, TestSize.Level3)486 HWTEST_F(DrawingNativeBrushTest, testBrushSetAlphaMaximum, TestSize.Level3) {
487     // 1. Create a brush object by calling OH_Drawing_BrushCreate
488     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
489     // 2. Set the alpha value of the brush object by calling OH_Drawing_BrushSetAlpha with a value greater than the
490     // maximum value of uint8_t (0xFFFFFFFF + 1)
491     OH_Drawing_BrushSetAlpha(brush, 0xFFFFFFFF + 1);
492     // 3. Get the alpha value of the brush object by calling OH_Drawing_BrushGetAlpha
493     uint8_t alpha = OH_Drawing_BrushGetAlpha(brush);
494     EXPECT_EQ(alpha, 0);
495     // 4. Free memory
496     OH_Drawing_BrushDestroy(brush);
497 }
498 
499 /*
500  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1000
501  * @tc.name: testBrushSetShaderEffectNormal
502  * @tc.desc: Test for testBrushSetShaderEffectNormal.
503  * @tc.size: SmallTest
504  * @tc.type: Function
505  * @tc.level: Level 0
506  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetShaderEffectNormal, TestSize.Level0)507 HWTEST_F(DrawingNativeBrushTest, testBrushSetShaderEffectNormal, TestSize.Level0) {
508     // 1. Create a brush object by calling OH_Drawing_BrushCreate
509     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
510     // 2. Create a shader object by calling OH_Drawing_ShaderEffectCreate
511     OH_Drawing_Point *startPt = OH_Drawing_PointCreate(100, 400);
512     OH_Drawing_Point *endPt = OH_Drawing_PointCreate(200, 500);
513     uint32_t color[] = {0xffff0000, 0xff00ff00};
514     float pos[] = {0., 1.0};
515     OH_Drawing_ShaderEffect *linearGradient =
516         OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, color, pos, 2, OH_Drawing_TileMode::CLAMP);
517     // 3. Set the shader effect for the brush object by calling OH_Drawing_BrushSetShaderEffect
518     OH_Drawing_BrushSetShaderEffect(brush, linearGradient);
519     // 4. Free memory
520     OH_Drawing_ShaderEffectDestroy(linearGradient);
521     OH_Drawing_PointDestroy(startPt);
522     OH_Drawing_PointDestroy(endPt);
523     OH_Drawing_BrushDestroy(brush);
524 }
525 
526 /*
527  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1001
528  * @tc.name: testBrushSetShaderEffectNull
529  * @tc.desc: Test for testBrushSetShaderEffectNull.
530  * @tc.size: SmallTest
531  * @tc.type: Function
532  * @tc.level: Level 3
533  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetShaderEffectNull, TestSize.Level3)534 HWTEST_F(DrawingNativeBrushTest, testBrushSetShaderEffectNull, TestSize.Level3) {
535     // 1. Create a brush object by calling OH_Drawing_BrushCreate
536     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
537     OH_Drawing_Point *startPt = OH_Drawing_PointCreate(100, 400);
538     OH_Drawing_Point *endPt = OH_Drawing_PointCreate(200, 500);
539     uint32_t color[] = {0xffff0000, 0xff00ff00};
540     float pos[] = {0., 1.0};
541     OH_Drawing_ShaderEffect *linearGradient =
542         OH_Drawing_ShaderEffectCreateLinearGradient(startPt, endPt, color, pos, 2, OH_Drawing_TileMode::CLAMP);
543     // 2. Call OH_Drawing_BrushSetShaderEffect with nullptr as the first parameter
544     OH_Drawing_BrushSetShaderEffect(nullptr, linearGradient);
545     // 3. Call OH_Drawing_BrushSetShaderEffect with nullptr as the second parameter
546     OH_Drawing_BrushSetShaderEffect(brush, nullptr);
547     // 4. Free memory
548     OH_Drawing_ShaderEffectDestroy(linearGradient);
549     OH_Drawing_PointDestroy(startPt);
550     OH_Drawing_PointDestroy(endPt);
551     OH_Drawing_BrushDestroy(brush);
552 }
553 
554 /*
555  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1100
556  * @tc.name: testBrushSetShadowLayerNormal
557  * @tc.desc: Test for testBrushSetShadowLayerNormal.
558  * @tc.size: SmallTest
559  * @tc.type: Function
560  * @tc.level: Level 0
561  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetShadowLayerNormal, TestSize.Level0)562 HWTEST_F(DrawingNativeBrushTest, testBrushSetShadowLayerNormal, TestSize.Level0) {
563     // 1. Create a brush object by calling OH_Drawing_BrushCreate
564     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
565     // 2. Create a shadow layer object by calling OH_Drawing_ShadowLayerCreate
566     OH_Drawing_ShadowLayer *shadowLayer = OH_Drawing_ShadowLayerCreate(10, 10, 10, 0x12345678);
567     // 3. Set the shadow layer for the brush object by calling OH_Drawing_BrushSetShadowLayer
568     OH_Drawing_BrushSetShadowLayer(brush, shadowLayer);
569     // 4. Free memory
570     OH_Drawing_ShadowLayerDestroy(shadowLayer);
571 }
572 
573 /*
574  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1101
575  * @tc.name: testBrushSetShadowLayerNull
576  * @tc.desc: Test for testBrushSetShadowLayerNull.
577  * @tc.size: SmallTest
578  * @tc.type: Function
579  * @tc.level: Level 3
580  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetShadowLayerNull, TestSize.Level3)581 HWTEST_F(DrawingNativeBrushTest, testBrushSetShadowLayerNull, TestSize.Level3) {
582     // 1. Create a brush object by calling OH_Drawing_BrushCreate
583     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
584     OH_Drawing_ShadowLayer *shadowLayer = OH_Drawing_ShadowLayerCreate(10, 10, 10, 0x12345678);
585     // 2. Call OH_Drawing_BrushSetShadowLayer with nullptr as the first parameter
586     OH_Drawing_BrushSetShadowLayer(nullptr, shadowLayer);
587     // 3. Call OH_Drawing_BrushSetShadowLayer with nullptr as the second parameter
588     OH_Drawing_BrushSetShadowLayer(brush, nullptr);
589     // 4. Free memory
590     OH_Drawing_ShadowLayerDestroy(shadowLayer);
591 }
592 
593 /*
594  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1200
595  * @tc.name: testBrushSetFilterNormal
596  * @tc.desc: Test for testBrushSetFilterNormal.
597  * @tc.size: SmallTest
598  * @tc.type: Function
599  * @tc.level: Level 0
600  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetFilterNormal, TestSize.Level0)601 HWTEST_F(DrawingNativeBrushTest, testBrushSetFilterNormal, TestSize.Level0) {
602     // 1. Create a brush object by calling OH_Drawing_BrushCreate
603     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
604     // 2. Create a filter object by calling OH_Drawing_FilterCreate
605     OH_Drawing_Filter *filter = OH_Drawing_FilterCreate();
606     // 3. Set the filter for the brush object by calling OH_Drawing_BrushSetFilter
607     OH_Drawing_BrushSetFilter(brush, filter);
608     // 4. Free memory
609     OH_Drawing_FilterDestroy(filter);
610     OH_Drawing_BrushDestroy(brush);
611 }
612 
613 /*
614  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1201
615  * @tc.name: testBrushSetFilterNull
616  * @tc.desc: Test for testBrushSetFilterNull.
617  * @tc.size: SmallTest
618  * @tc.type: Function
619  * @tc.level: Level 3
620  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetFilterNull, TestSize.Level3)621 HWTEST_F(DrawingNativeBrushTest, testBrushSetFilterNull, TestSize.Level3) {
622     // 1. Create a brush object by calling OH_Drawing_BrushCreate
623     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
624     OH_Drawing_Filter *filter = OH_Drawing_FilterCreate();
625     // 2. Call OH_Drawing_BrushSetFilter with nullptr as the first parameter
626     OH_Drawing_BrushSetFilter(nullptr, filter);
627     // 3. Call OH_Drawing_BrushSetFilter with nullptr as the second parameter
628     OH_Drawing_BrushSetFilter(brush, nullptr);
629     // 4. Free memory
630     OH_Drawing_FilterDestroy(filter);
631     OH_Drawing_BrushDestroy(brush);
632 }
633 
634 /*
635  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1300
636  * @tc.name: testBrushGetFilterNormal
637  * @tc.desc: Test for testBrushGetFilterNormal.
638  * @tc.size: SmallTest
639  * @tc.type: Function
640  * @tc.level: Level 0
641  */
HWTEST_F(DrawingNativeBrushTest, testBrushGetFilterNormal, TestSize.Level0)642 HWTEST_F(DrawingNativeBrushTest, testBrushGetFilterNormal, TestSize.Level0) {
643     // 1. Create a brush object by calling OH_Drawing_BrushCreate
644     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
645     // 2. Create a filter object by calling OH_Drawing_FilterCreate
646     OH_Drawing_Filter *filter = OH_Drawing_FilterCreate();
647     // 3. Set the filter for the brush object by calling OH_Drawing_BrushSetFilter
648     OH_Drawing_BrushSetFilter(brush, filter);
649     // 4. Get the filter by calling OH_Drawing_BrushGetFilter
650     OH_Drawing_Filter *tmpFilter = OH_Drawing_FilterCreate();
651     OH_Drawing_BrushGetFilter(brush, tmpFilter);
652     // 5. Free memory
653     OH_Drawing_FilterDestroy(filter);
654     OH_Drawing_FilterDestroy(tmpFilter);
655     OH_Drawing_BrushDestroy(brush);
656 }
657 
658 /*
659  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1301
660  * @tc.name: testBrushGetFilterNull
661  * @tc.desc: Test for testBrushGetFilterNull.
662  * @tc.size: SmallTest
663  * @tc.type: Function
664  * @tc.level: Level 3
665  */
HWTEST_F(DrawingNativeBrushTest, testBrushGetFilterNull, TestSize.Level3)666 HWTEST_F(DrawingNativeBrushTest, testBrushGetFilterNull, TestSize.Level3) {
667     // 1. Create a brush object by calling OH_Drawing_BrushCreate
668     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
669     OH_Drawing_Filter *filter = OH_Drawing_FilterCreate();
670     // 2. Call OH_Drawing_BrushGetFilter with nullptr as the first parameter
671     OH_Drawing_BrushGetFilter(nullptr, filter);
672     // 3. Call OH_Drawing_BrushGetFilter with nullptr as the second parameter
673     OH_Drawing_BrushGetFilter(brush, nullptr);
674     // 4. Free memory
675     OH_Drawing_FilterDestroy(filter);
676     OH_Drawing_BrushDestroy(brush);
677 }
678 
679 /*
680  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1400
681  * @tc.name: testBrushSetBlendModeNormal
682  * @tc.desc: Test for testBrushSetBlendModeNormal.
683  * @tc.size: SmallTest
684  * @tc.type: Function
685  * @tc.level: Level 0
686  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetBlendModeNormal, TestSize.Level0)687 HWTEST_F(DrawingNativeBrushTest, testBrushSetBlendModeNormal, TestSize.Level0) {
688     // 1. Create a brush object by calling OH_Drawing_BrushCreate
689     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
690     // 2. Call OH_Drawing_BrushSetBlendMode with the second parameter being an enumeration
691     OH_Drawing_BlendMode blendMode[] = {
692         BLEND_MODE_CLEAR,      BLEND_MODE_SRC,        BLEND_MODE_DST,         BLEND_MODE_SRC_OVER,
693         BLEND_MODE_DST_OVER,   BLEND_MODE_SRC_IN,     BLEND_MODE_DST_IN,      BLEND_MODE_SRC_OUT,
694         BLEND_MODE_DST_OUT,    BLEND_MODE_SRC_ATOP,   BLEND_MODE_DST_ATOP,    BLEND_MODE_XOR,
695         BLEND_MODE_PLUS,       BLEND_MODE_MODULATE,   BLEND_MODE_SCREEN,      BLEND_MODE_OVERLAY,
696         BLEND_MODE_DARKEN,     BLEND_MODE_LIGHTEN,    BLEND_MODE_COLOR_DODGE, BLEND_MODE_COLOR_BURN,
697         BLEND_MODE_HARD_LIGHT, BLEND_MODE_SOFT_LIGHT, BLEND_MODE_DIFFERENCE,  BLEND_MODE_EXCLUSION,
698         BLEND_MODE_MULTIPLY,   BLEND_MODE_HUE,        BLEND_MODE_SATURATION,  BLEND_MODE_COLOR,
699         BLEND_MODE_LUMINOSITY,
700     };
701     for (int i = 0; i < sizeof(blendMode) / sizeof(OH_Drawing_BlendMode); i++) {
702         OH_Drawing_BrushSetBlendMode(brush, blendMode[i]);
703     }
704     // 3. Free memory
705     OH_Drawing_BrushDestroy(brush);
706 }
707 
708 /*
709  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1401
710  * @tc.name: testBrushSetBlendModeNull
711  * @tc.desc: Test for testBrushSetBlendModeNull.
712  * @tc.size: SmallTest
713  * @tc.type: Function
714  * @tc.level: Level 3
715  */
HWTEST_F(DrawingNativeBrushTest, testBrushSetBlendModeNull, TestSize.Level3)716 HWTEST_F(DrawingNativeBrushTest, testBrushSetBlendModeNull, TestSize.Level3) {
717     // 1. Create a brush object by calling OH_Drawing_BrushCreate
718     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
719     // 2. Call OH_Drawing_BrushSetBlendMode with nullptr as the first parameter
720     OH_Drawing_BrushSetBlendMode(nullptr, BLEND_MODE_CLEAR);
721     // 3. Free memory
722     OH_Drawing_BrushDestroy(brush);
723 }
724 
725 /*
726  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1500
727  * @tc.name: testBrushResetNormal
728  * @tc.desc: Test for testBrushResetNormal.
729  * @tc.size: SmallTest
730  * @tc.type: Function
731  * @tc.level: Level 0
732  */
HWTEST_F(DrawingNativeBrushTest, testBrushResetNormal, TestSize.Level0)733 HWTEST_F(DrawingNativeBrushTest, testBrushResetNormal, TestSize.Level0) {
734     // 1. Create a brush object by calling OH_Drawing_BrushCreate
735     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
736     uint32_t color1 = OH_Drawing_BrushGetColor(brush);
737     // 2. Set the color for the brush object by calling OH_Drawing_BrushSetColor
738     OH_Drawing_BrushSetColor(brush, 0x12345678);
739     // 3. Get the color of the brush object by calling OH_Drawing_BrushGetColor
740     uint32_t color2 = OH_Drawing_BrushGetColor(brush);
741     EXPECT_EQ(color2, 0x12345678);
742     // 4. Reset the state of the brush object by calling OH_Drawing_BrushReset
743     OH_Drawing_BrushReset(brush);
744     // 5. Get the color of the brush object by calling OH_Drawing_BrushGetColor
745     uint32_t color3 = OH_Drawing_BrushGetColor(brush);
746     EXPECT_EQ(color3, color1);
747     // 6. Free memory
748     OH_Drawing_BrushDestroy(brush);
749 }
750 
751 /*
752  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_BRUSH_1501
753  * @tc.name: testBrushResetNull
754  * @tc.desc: Test for testBrushResetNull.
755  * @tc.size: SmallTest
756  * @tc.type: Function
757  * @tc.level: Level 3
758  */
HWTEST_F(DrawingNativeBrushTest, testBrushResetNull, TestSize.Level3)759 HWTEST_F(DrawingNativeBrushTest, testBrushResetNull, TestSize.Level3) {
760     // 1. Create a brush object by calling OH_Drawing_BrushCreate
761     OH_Drawing_Brush *brush = OH_Drawing_BrushCreate();
762     // 2. Call OH_Drawing_BrushReset with nullptr as the parameter
763     OH_Drawing_BrushReset(nullptr);
764     // 3. Free memory
765     OH_Drawing_BrushDestroy(brush);
766 }
767 
768 } // namespace Drawing
769 } // namespace Rosen
770 } // namespace OHOS