• 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_brush.h"
20 #include "drawing_canvas.h"
21 #include "drawing_color.h"
22 #include "drawing_color_filter.h"
23 #include "drawing_filter.h"
24 #include "drawing_font.h"
25 #include "drawing_image.h"
26 #include "drawing_mask_filter.h"
27 #include "drawing_matrix.h"
28 #include "drawing_memory_stream.h"
29 #include "drawing_path.h"
30 #include "drawing_pen.h"
31 #include "drawing_point.h"
32 #include "drawing_rect.h"
33 #include "drawing_region.h"
34 #include "drawing_round_rect.h"
35 #include "drawing_sampling_options.h"
36 #include "drawing_shader_effect.h"
37 #include "drawing_shadow_layer.h"
38 #include "drawing_text_blob.h"
39 #include "drawing_typeface.h"
40 
41 using namespace testing;
42 using namespace testing::ext;
43 
44 namespace OHOS {
45 namespace Rosen {
46 namespace Drawing {
47 class DrawingNativeColorTest : public testing::Test {
48     protected:
49     // 在每个测试用例执行前调用
SetUp()50     void SetUp() override
51     {
52         // 设置代码
53         std::cout << "DrawingNativeColorTest Setup code called before each test case." << std::endl;
54         OH_Drawing_ErrorCodeReset();
55         std::cout << "DrawingNativeColorTest errorCodeReset before each test case." << std::endl;
56     }
TearDown()57     void TearDown() override
58     {
59         std::cout << "DrawingNativeColorTest Setup code called after each test case." << std::endl;
60         OH_Drawing_ErrorCodeReset();
61         std::cout << "DrawingNativeColorTest errorCodeReset after each test case." << std::endl;
62     }
63 };
64 
65 /*
66  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0100
67  * @tc.name: testColorSetArgbNormal
68  * @tc.desc: test for testColorSetArgbNormal.
69  * @tc.size  : SmallTest
70  * @tc.type  : Function
71  * @tc.level : Level 0
72  */
73 HWTEST_F(DrawingNativeColorTest, testColorSetArgbNormal, Function | SmallTest | Level0) {
74     // 1
75     uint32_t color = OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF);
76     // add assert
77     EXPECT_NE(color, 0);
78     // 2
79     uint32_t color2 = OH_Drawing_ColorSetArgb(0, 0, 0, 0);
80     // add assert
81     EXPECT_EQ(color2, 0);
82     // 3 Compilation error, unable to test
83 }
84 
85 /*
86  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0101
87  * @tc.name: testColorSetArgbNULL
88  * @tc.desc: test for testColorSetArgbNULL.
89  * @tc.size  : SmallTest
90  * @tc.type  : Function
91  * @tc.level : Level 3
92  */
93 HWTEST_F(DrawingNativeColorTest, testColorSetArgbNULL, Function | SmallTest | Level3) {
94     // 1、Passing empty for the first argument of OH_Drawing_ColorSetArgb
95     uint32_t color1 = OH_Drawing_ColorSetArgb(0, 0xFF, 0xFF, 0xFF);
96     // add assert
97     EXPECT_NE(color1, 0);
98     // 2、Passing empty for the second argument of OH_Drawing_ColorSetArgb
99     uint32_t color2 = OH_Drawing_ColorSetArgb(0xFF, 0, 0xFF, 0xFF);
100     // add assert
101     EXPECT_NE(color2, 0);
102     // 3、Passing empty for the third argument of OH_Drawing_ColorSetArgb
103     uint32_t color3 = OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0, 0xFF);
104     // add assert
105     EXPECT_NE(color3, 0);
106     // 4、Passing empty for the fourth argument of OH_Drawing_ColorSetArgb
107     uint32_t color4 = OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0);
108     // add assert
109     EXPECT_NE(color4, 0);
110 }
111 
112 /*
113  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0102
114  * @tc.name: testColorSetArgbMultipleCalls
115  * @tc.desc: test for testColorSetArgbMultipleCalls.
116  * @tc.size  : SmallTest
117  * @tc.type  : Function
118  * @tc.level : Level 3
119  */
120 HWTEST_F(DrawingNativeColorTest, testColorSetArgbMultipleCalls, Function | SmallTest | Level3) {
121     // 1. Call OH_Drawing_ColorSetArgb with random numbers between 0 and 255, 10 times
122     for (int i = 0; i < 10; i++) {
123         uint32_t color = OH_Drawing_ColorSetArgb(rand() % 256, rand() % 256, rand() % 256, rand() % 256);
124         // add assert
125         EXPECT_NE(color, 0);
126     }
127 }
128 
129 /*
130  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0103
131  * @tc.name: testColorSetArgbAbnormal
132  * @tc.desc: test for testColorSetArgbAbnormal.
133  * @tc.size  : SmallTest
134  * @tc.type  : Function
135  * @tc.level : Level 3
136  */
137 HWTEST_F(DrawingNativeColorTest, testColorSetArgbAbnormal, Function | SmallTest | Level3) {
138     // 1. The first argument of OH_Drawing_ColorSetArgb is a negative number
139     uint32_t color1 = OH_Drawing_ColorSetArgb(-0x01, 0xFF, 0xFF, 0xFF);
140     // add assert
141     EXPECT_NE(color1, 0);
142     // 2. The second argument of OH_Drawing_ColorSetArgb is a negative number
143     uint32_t color2 = OH_Drawing_ColorSetArgb(0xFF, -0x01, 0xFF, 0xFF);
144     // add assert
145     EXPECT_NE(color2, 0);
146     // 3. The third argument of OH_Drawing_ColorSetArgb is a negative number
147     uint32_t color3 = OH_Drawing_ColorSetArgb(0xFF, 0xFF, -0x01, 0xFF);
148     // add assert
149     EXPECT_NE(color3, 0);
150     // 4. The fourth argument of OH_Drawing_ColorSetArgb is a negative number
151     uint32_t color4 = OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, -0x01);
152     // add assert
153     EXPECT_NE(color4, 0);
154 }
155 
156 /*
157  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0104
158  * @tc.name: testColorSetArgbMaximum
159  * @tc.desc: test for testColorSetArgbMaximum.
160  * @tc.size  : SmallTest
161  * @tc.type  : Function
162  * @tc.level : Level 3
163  */
164 HWTEST_F(DrawingNativeColorTest, testColorSetArgbMaximum, Function | SmallTest | Level3) {
165     // 1
166     uint32_t color1 = OH_Drawing_ColorSetArgb(0xFF + 1, 0x00, 0x00, 0xFF);
167     // add assert
168     EXPECT_NE(color1, 0);
169     // 2
170     uint32_t color2 = OH_Drawing_ColorSetArgb(0xFF, 0xFF + 1, 0x00, 0xFF);
171     // add assert
172     EXPECT_NE(color2, 0);
173     // 3
174     uint32_t color3 = OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF + 1, 0xFF);
175     // add assert
176     EXPECT_NE(color3, 0);
177     // 4
178     uint32_t color4 = OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0xFF + 1);
179     // add assert
180     EXPECT_NE(color4, 0);
181 }
182 
183 } // namespace Drawing
184 } // namespace Rosen
185 } // namespace OHOS