• 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     protected:
34     // 在每个测试用例执行前调用
SetUp()35     void SetUp() override
36     {
37         // 设置代码
38         std::cout << "DrawingNativeMaskFilterTest Setup code called before each test case." << std::endl;
39         OH_Drawing_ErrorCodeReset();
40         std::cout << "DrawingNativeMaskFilterTest errorCodeReset before each test case." << std::endl;
41     }
TearDown()42     void TearDown() override
43     {
44         std::cout << "DrawingNativeMaskFilterTest Setup code called after each test case." << std::endl;
45         OH_Drawing_ErrorCodeReset();
46         std::cout << "DrawingNativeMaskFilterTest errorCodeReset after each test case." << std::endl;
47     }
48 };
49 
50 /*
51  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0100
52  * @tc.name: testMaskFilterCreateBlurDestroyNormal
53  * @tc.desc: Test for creating and destroying a blur mask filter with normal parameters.
54  * @tc.size  : SmallTest
55  * @tc.type  : Function
56  * @tc.level : Level 0
57  */
58 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyNormal, Function | SmallTest | Level0) {
59     OH_Drawing_BlurType types[] = {
60         NORMAL,
61         SOLID,
62         OUTER,
63         INNER,
64     };
65     // 1. Enumerate through the blurType values in OH_Drawing_MaskFilterCreateBlur
66     for (OH_Drawing_BlurType type : types) {
67         OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(type, 10, true);
68         EXPECT_NE(maskFilter, nullptr);
69         OH_Drawing_MaskFilterDestroy(maskFilter);
70     }
71     // 2. Call OH_Drawing_MaskFilterCreateBlur with a floating-point value for sigma
72     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10.0f, true);
73     // add assert
74     EXPECT_NE(maskFilter, nullptr);
75     // 3. Call OH_Drawing_MaskFilterCreateBlur with an integer value for sigma
76     maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
77     // add assert
78     EXPECT_NE(maskFilter, nullptr);
79     // 4. Call OH_Drawing_MaskFilterCreateBlur with respectCTM set to false
80     maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, false);
81     // add assert
82     EXPECT_NE(maskFilter, nullptr);
83     // 5. Call OH_Drawing_MaskFilterCreateBlur with respectCTM set to true
84     maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
85     // add assert
86     EXPECT_NE(maskFilter, nullptr);
87     // 6. Call OH_Drawing_MaskFilterDestroy
88     OH_Drawing_MaskFilterDestroy(maskFilter);
89 }
90 
91 /*
92  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0101
93  * @tc.name: testMaskFilterCreateBlurDestroyNULL
94  * @tc.desc: Test for creating and destroying a blur mask filter with NULL parameters.
95  * @tc.size  : SmallTest
96  * @tc.type  : Function
97  * @tc.level : Level 3
98  */
99 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyNULL, Function | SmallTest | Level3) {
100     // 1. Call OH_Drawing_MaskFilterCreateBlur with the second parameter as zero and check the error code using
101     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 0, true);
102     EXPECT_NE(maskFilter, nullptr);
103     // 2. Free memory
104     OH_Drawing_MaskFilterDestroy(maskFilter);
105 }
106 
107 /*
108  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0102
109  * @tc.name: testMaskFilterCreateBlurDestroyMultipleCalls
110  * @tc.desc: Test for multiple calls of creating and destroying a blur mask filter.
111  * @tc.size  : SmallTest
112  * @tc.type  : Function
113  * @tc.level : Level 3
114  */
115 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyMultipleCalls, Function | SmallTest | Level3) {
116     // 1. Call OH_Drawing_MaskFilterCreateBlur and OH_Drawing_MaskFilterDestroy 10 times in a loop
117     for (int i = 0; i < 10; i++) {
118         OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
119         EXPECT_NE(maskFilter, nullptr);
120         OH_Drawing_MaskFilterDestroy(maskFilter);
121     }
122     // 2. Call OH_Drawing_MaskFilterCreateBlur 10 times consecutively
123     OH_Drawing_MaskFilter *maskFilters[10];
124     for (int i = 0; i < 10; i++) {
125         maskFilters[i] = OH_Drawing_MaskFilterCreateBlur(NORMAL, 10, true);
126         // add assert
127         EXPECT_NE(maskFilters[i], nullptr);
128     }
129     // 3. Call OH_Drawing_MaskFilterDestroy 10 times consecutively
130     for (int i = 0; i < 10; i++) {
131         OH_Drawing_MaskFilterDestroy(maskFilters[i]);
132     }
133 }
134 
135 /*
136  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0103
137  * @tc.name: testMaskFilterCreateBlurDestroyAbnormal
138  * @tc.desc: Test for creating and destroying a blur mask filter with abnormal parameters.
139  * @tc.size  : SmallTest
140  * @tc.type  : Function
141  * @tc.level : Level 3
142  */
143 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyAbnormal, Function | SmallTest | Level3) {
144     // 1. Call OH_Drawing_MaskFilterCreateBlur with a negative value for sigma and check the error code using
145     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, -10, true);
146     EXPECT_NE(maskFilter, nullptr);
147     OH_Drawing_MaskFilterDestroy(maskFilter);
148 }
149 
150 /*
151  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_MASK_FILTER_0104
152  * @tc.name: testMaskFilterCreateBlurDestroyMaximum
153  * @tc.desc: Test for creating and destroying a blur mask filter with maximum values.
154  * @tc.size  : SmallTest
155  * @tc.type  : Function
156  * @tc.level : Level 3
157  */
158 HWTEST_F(DrawingNativeMaskFilterTest, testMaskFilterCreateBlurDestroyMaximum, Function | SmallTest | Level3) {
159     // 1. Call OH_Drawing_MaskFilterCreateBlur with a maximum value for sigma
160     OH_Drawing_MaskFilter *maskFilter = OH_Drawing_MaskFilterCreateBlur(NORMAL, FLT_MAX, true);
161     // add assert
162     EXPECT_NE(maskFilter, nullptr);
163     // 2. Call OH_Drawing_MaskFilterDestroy to free memory
164     OH_Drawing_MaskFilterDestroy(maskFilter);
165 }
166 
167 } // namespace Drawing
168 } // namespace Rosen
169 } // namespace OHOS