• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_bitmap.h"
19 #include "drawing_color.h"
20 #include "drawing_color_filter.h"
21 #include "drawing_error_code.h"
22 #include "drawing_image.h"
23 #include "drawing_image_filter.h"
24 #include "drawing_mask_filter.h"
25 
26 using namespace testing;
27 using namespace testing::ext;
28 
29 namespace OHOS {
30 namespace Rosen {
31 namespace Drawing {
32 class DrawingNativeMaskFilterTest : public testing::Test {};
33 
34 /*
35  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0100
36  * @tc.name: testMaskFilterCreateBlurDestroyNormal
37  * @tc.desc: Test for creating and destroying a blur mask filter with normal parameters.
38  * @tc.size  : SmallTest
39  * @tc.type  : Function
40  * @tc.level : Level 0
41  */
42 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyNormal, TestSize.Level0) {
43     OH_Drawing_BlurType types[] = {
44         NORMAL,
45         SOLID,
46         OUTER,
47         INNER,
48     };
49     // 1. Enumerate through the blurType values in OH_Drawing_MaskFilterCreateBlur
50     for (OH_Drawing_BlurType type : types) {
51         OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(type, 10, true);
52         EXPECT_NE(maskFilter, nullptr);
53         OH_Drawing_MaskFilterDestroy(maskFilter);
54     }
55     // 2. Call OH_Drawing_MaskFilterCreateBlur with a floating-point value for sigma
56     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10.0f, true);
57     // 3. Call OH_Drawing_MaskFilterCreateBlur with an integer value for sigma
58     maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
59     // 4. Call OH_Drawing_MaskFilterCreateBlur with respectCTM set to false
60     maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, false);
61     // 5. Call OH_Drawing_MaskFilterCreateBlur with respectCTM set to true
62     maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
63     // 6. Call OH_Drawing_MaskFilterDestroy
64     OH_Drawing_MaskFilterDestroy(maskFilter);
65 }
66 
67 /*
68  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0101
69  * @tc.name: testMaskFilterCreateBlurDestroyNULL
70  * @tc.desc: Test for creating and destroying a blur mask filter with NULL parameters.
71  * @tc.size  : SmallTest
72  * @tc.type  : Function
73  * @tc.level : Level 3
74  */
75 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyNULL, TestSize.Level3) {
76     // 1. Call OH_Drawing_MaskFilterCreateBlur with the second parameter as zero and check the error code using
77     // OH_Drawing_ErrorCodeGet
78     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 0, true);
79     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
80     // 2. Call OH_Drawing_MaskFilterDestroy with a null parameter
81     OH_Drawing_MaskFilterDestroy(nullptr);
82     // 3. Free memory
83     OH_Drawing_MaskFilterDestroy(maskFilter);
84 }
85 
86 /*
87  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0102
88  * @tc.name: testMaskFilterCreateBlurDestroyMultipleCalls
89  * @tc.desc: Test for multiple calls of creating and destroying a blur mask filter.
90  * @tc.size  : SmallTest
91  * @tc.type  : Function
92  * @tc.level : Level 3
93  */
94 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyMultipleCalls, TestSize.Level3) {
95     // 1. Call OH_Drawing_MaskFilterCreateBlur and OH_Drawing_MaskFilterDestroy 10 times in a loop
96     for (int i = 0; i < 10; i++) {
97         OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
98         EXPECT_NE(maskFilter, nullptr);
99         OH_Drawing_MaskFilterDestroy(maskFilter);
100     }
101     // 2. Call OH_Drawing_MaskFilterCreateBlur 10 times consecutively
102     OH_Drawing_MaskFilter *maskFilters[10];
103     for (int i = 0; i < 10; i++) {
104         maskFilters[i] = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
105     }
106     // 3. Call OH_Drawing_MaskFilterDestroy 10 times consecutively
107     for (int i = 0; i < 10; i++) {
108         OH_Drawing_MaskFilterDestroy(maskFilters[i]);
109     }
110 }
111 
112 /*
113  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0103
114  * @tc.name: testMaskFilterCreateBlurDestroyAbnormal
115  * @tc.desc: Test for creating and destroying a blur mask filter with abnormal parameters.
116  * @tc.size  : SmallTest
117  * @tc.type  : Function
118  * @tc.level : Level 3
119  */
120 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyAbnormal, TestSize.Level3) {
121     // 1. Call OH_Drawing_MaskFilterCreateBlur with a negative value for sigma and check the error code using
122     // OH_Drawing_ErrorCodeGet
123     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, -10, true);
124     EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
125     // 2. Call OH_Drawing_MaskFilterDestroy to free memory
126     OH_Drawing_MaskFilterDestroy(maskFilter);
127 }
128 
129 /*
130  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0104
131  * @tc.name: testMaskFilterCreateBlurDestroyMaximum
132  * @tc.desc: Test for creating and destroying a blur mask filter with maximum values.
133  * @tc.size  : SmallTest
134  * @tc.type  : Function
135  * @tc.level : Level 3
136  */
137 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyMaximum, TestSize.Level3) {
138     // 1. Call OH_Drawing_MaskFilterCreateBlur with a maximum value for sigma
139     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, FLT_MAX, true);
140     // 2. Call OH_Drawing_MaskFilterDestroy to free memory
141     OH_Drawing_MaskFilterDestroy(maskFilter);
142 }
143 
144 } // namespace Drawing
145 } // namespace Rosen
146 } // namespace OHOS