• 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 
49 /*
50  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0100
51  * @tc.name: testColorSetArgbNormal
52  * @tc.desc: test for testColorSetArgbNormal.
53  * @tc.size  : SmallTest
54  * @tc.type  : Function
55  * @tc.level : Level 0
56  */
57 HWTEST_F(DrawingNativeColorTest, testColorSetArgbNormal, TestSize.Level0) {
58     // 1
59     OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0xFF);
60     // 2
61     OH_Drawing_ColorSetArgb(0, 0, 0, 0);
62     // 3 Compilation error, unable to test
63 }
64 
65 /*
66  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0101
67  * @tc.name: testColorSetArgbNULL
68  * @tc.desc: test for testColorSetArgbNULL.
69  * @tc.size  : SmallTest
70  * @tc.type  : Function
71  * @tc.level : Level 3
72  */
73 HWTEST_F(DrawingNativeColorTest, testColorSetArgbNULL, TestSize.Level3) {
74     // 1、Passing empty for the first argument of OH_Drawing_ColorSetArgb
75     OH_Drawing_ColorSetArgb(0, 0xFF, 0xFF, 0xFF);
76     // 2、Passing empty for the second argument of OH_Drawing_ColorSetArgb
77     OH_Drawing_ColorSetArgb(0xFF, 0, 0xFF, 0xFF);
78     // 3、Passing empty for the third argument of OH_Drawing_ColorSetArgb
79     OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0, 0xFF);
80     // 4、Passing empty for the fourth argument of OH_Drawing_ColorSetArgb
81     OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, 0);
82 }
83 
84 /*
85  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0102
86  * @tc.name: testColorSetArgbMultipleCalls
87  * @tc.desc: test for testColorSetArgbMultipleCalls.
88  * @tc.size  : SmallTest
89  * @tc.type  : Function
90  * @tc.level : Level 3
91  */
92 HWTEST_F(DrawingNativeColorTest, testColorSetArgbMultipleCalls, TestSize.Level3) {
93     // 1. Call OH_Drawing_ColorSetArgb with random numbers between 0 and 255, 10 times
94     for (int i = 0; i < 10; i++) {
95         OH_Drawing_ColorSetArgb(rand() % 256, rand() % 256, rand() % 256, rand() % 256);
96     }
97 }
98 
99 /*
100  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0103
101  * @tc.name: testColorSetArgbAbnormal
102  * @tc.desc: test for testColorSetArgbAbnormal.
103  * @tc.size  : SmallTest
104  * @tc.type  : Function
105  * @tc.level : Level 3
106  */
107 HWTEST_F(DrawingNativeColorTest, testColorSetArgbAbnormal, TestSize.Level3) {
108     // 1. The first argument of OH_Drawing_ColorSetArgb is a negative number
109     OH_Drawing_ColorSetArgb(-0x01, 0xFF, 0xFF, 0xFF);
110     // 2. The second argument of OH_Drawing_ColorSetArgb is a negative number
111     OH_Drawing_ColorSetArgb(0xFF, -0x01, 0xFF, 0xFF);
112     // 3. The third argument of OH_Drawing_ColorSetArgb is a negative number
113     OH_Drawing_ColorSetArgb(0xFF, 0xFF, -0x01, 0xFF);
114     // 4. The fourth argument of OH_Drawing_ColorSetArgb is a negative number
115     OH_Drawing_ColorSetArgb(0xFF, 0xFF, 0xFF, -0x01);
116 }
117 
118 /*
119  * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_COLOR_0104
120  * @tc.name: testColorSetArgbMaximum
121  * @tc.desc: test for testColorSetArgbMaximum.
122  * @tc.size  : SmallTest
123  * @tc.type  : Function
124  * @tc.level : Level 3
125  */
126 HWTEST_F(DrawingNativeColorTest, testColorSetArgbMaximum, TestSize.Level3) {
127     // 1
128     OH_Drawing_ColorSetArgb(0xFF + 1, 0x00, 0x00, 0xFF);
129     // 2
130     OH_Drawing_ColorSetArgb(0xFF, 0xFF + 1, 0x00, 0xFF);
131     // 3
132     OH_Drawing_ColorSetArgb(0xFF, 0x00, 0xFF + 1, 0xFF);
133     // 4
134     OH_Drawing_ColorSetArgb(0xFF, 0x00, 0x00, 0xFF + 1);
135 }
136 
137 } // namespace Drawing
138 } // namespace Rosen
139 } // namespace OHOS