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 "DrawingNativeCanvasCommon.h"
17#include "drawing_bitmap.h"
18#include "drawing_brush.h"
19#include "drawing_canvas.h"
20#include "drawing_color.h"
21#include "drawing_color_filter.h"
22#include "drawing_filter.h"
23#include "drawing_font.h"
24#include "drawing_image.h"
25#include "drawing_mask_filter.h"
26#include "drawing_matrix.h"
27#include "drawing_memory_stream.h"
28#include "drawing_path.h"
29#include "drawing_pen.h"
30#include "drawing_pixel_map.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_text_blob.h"
38#include "drawing_typeface.h"
39#include "image/pixelmap_native.h"
40#include "gtest/gtest.h"
41
42using namespace testing;
43using namespace testing::ext;
44
45namespace OHOS {
46namespace Rosen {
47namespace Drawing {
48class DrawingNativePixelMapTest : public testing::Test {};
49
50/*
51 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0100
52 * @tc.name: testPixelMapGetFromNativePixelMapNormal
53 * @tc.desc: test for testPixelMapGetFromNativePixelMapNormal.
54 * @tc.size  : SmallTest
55 * @tc.type  : Function
56 * @tc.level : Level 0
57 */
58HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapNormal, TestSize.Level0) {
59    // todo: how to get NativePixelMap_?
60    NativePixelMap_ *pixelMap = nullptr;
61    // 1. Call OH_Drawing_PixelMapGetFromNativePixelMap
62    OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(pixelMap);
63    EXPECT_EQ(drPixelMap, nullptr);
64}
65
66/*
67 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0101
68 * @tc.name: testPixelMapGetFromNativePixelMapNull
69 * @tc.desc: test for testPixelMapGetFromNativePixelMapNull.
70 * @tc.size  : SmallTest
71 * @tc.type  : Function
72 * @tc.level : Level 3
73 */
74HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapNull, TestSize.Level3) {
75    // 1. Call OH_Drawing_PixelMapGetFromNativePixelMap with nullptr as parameter and check the error code using
76    // OH_Drawing_ErrorCodeGet
77    OH_Drawing_PixelMapGetFromNativePixelMap(nullptr);
78    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
79}
80
81/*
82 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0102
83 * @tc.name: testPixelMapGetFromNativePixelMapMultipleCalls
84 * @tc.desc: test for testPixelMapGetFromNativePixelMapMultipleCalls.
85 * @tc.size  : SmallTest
86 * @tc.type  : Function
87 * @tc.level : Level 3
88 */
89HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapMultipleCalls, TestSize.Level3) {
90    // todo: how to get NativePixelMap_?
91    NativePixelMap_ *pixelMap = nullptr;
92    // 1. Call OH_Drawing_PixelMapGetFromNativePixelMap 10 times
93    for (int i = 0; i < 10; i++) {
94        OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(pixelMap);
95        EXPECT_EQ(drPixelMap, nullptr);
96    }
97}
98
99/*
100 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0102
101 * @tc.name: testPixelMapGetFromNativePixelMapBoundary
102 * @tc.desc: test for testPixelMapGetFromNativePixelMapBoundary.
103 * @tc.size  : SmallTest
104 * @tc.type  : Function
105 * @tc.level : Level 0
106 */
107HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapBoundary, TestSize.Level0) {
108    // todo: how to get NativePixelMap_?
109    NativePixelMap_ *pixelMap = nullptr;
110    // 1. Call OH_Drawing_PixelMapGetFromNativePixelMap
111    OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(pixelMap);
112    EXPECT_EQ(drPixelMap, nullptr);
113}
114
115/*
116 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0200
117 * @tc.name: testPixelMapGetFromOhPixelMapNativeNormal
118 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeNormal.
119 * @tc.size  : SmallTest
120 * @tc.type  : Function
121 * @tc.level : Level 0
122 */
123HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeNormal, TestSize.Level0) {
124    OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative();
125    // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative
126    OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap);
127    // 2. Release memory
128    OH_Drawing_PixelMapDissolve(drPixelMap);
129    OH_PixelmapNative_Release(pixelMap);
130}
131
132/*
133 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0201
134 * @tc.name: testPixelMapGetFromOhPixelMapNativeNull
135 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeNull.
136 * @tc.size  : SmallTest
137 * @tc.type  : Function
138 * @tc.level : Level 3
139 */
140HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeNull, TestSize.Level3) {
141    // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative with nullptr as parameter and check the error code using
142    // OH_Drawing_ErrorCodeGet
143    OH_Drawing_PixelMapGetFromOhPixelMapNative(nullptr);
144    EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER);
145}
146
147/*
148 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0202
149 * @tc.name: testPixelMapGetFromOhPixelMapNativeMultipleCalls
150 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeMultipleCalls.
151 * @tc.size  : SmallTest
152 * @tc.type  : Function
153 * @tc.level : Level 3
154 */
155HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeMultipleCalls, TestSize.Level3) {
156    OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative();
157    // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative 10 times
158    for (int i = 0; i < 10; i++) {
159        OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap);
160        OH_Drawing_PixelMapDissolve(drPixelMap);
161    }
162    OH_PixelmapNative_Release(pixelMap);
163}
164
165/*
166 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0203
167 * @tc.name: testPixelMapGetFromOhPixelMapNativeBoundary
168 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeBoundary.
169 * @tc.size  : SmallTest
170 * @tc.type  : Function
171 * @tc.level : Level 0
172 */
173HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeBoundary, TestSize.Level0) {
174    uint32_t width = 4096;
175    uint32_t height = 2160;
176    OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative(width, height);
177    // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative
178    OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap);
179    // 2. Release memory
180    OH_Drawing_PixelMapDissolve(drPixelMap);
181    OH_PixelmapNative_Release(pixelMap);
182    EXPECT_EQ(pixelMap, nullptr);
183}
184
185/*
186 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0300
187 * @tc.name: testPixelMapDissolveNormal
188 * @tc.desc: test for testPixelMapDissolveNormal.
189 * @tc.size  : SmallTest
190 * @tc.type  : Function
191 * @tc.level : Level 0
192 */
193HWTEST_F(DrawingNativePixelMapTest, testPixelMapDissolveNormal, TestSize.Level0) {
194    OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative();
195    // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative
196    OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap);
197    // 2. Call OH_Drawing_PixelMapDissolve
198    OH_Drawing_PixelMapDissolve(drPixelMap);
199    OH_PixelmapNative_Release(pixelMap);
200}
201
202/*
203 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0301
204 * @tc.name: testPixelMapDissolveNull
205 * @tc.desc: test for testPixelMapDissolveNull.
206 * @tc.size  : SmallTest
207 * @tc.type  : Function
208 * @tc.level : Level 3
209 */
210HWTEST_F(DrawingNativePixelMapTest, testPixelMapDissolveNull, TestSize.Level3) {
211    // 1. OH_Drawing_PixelMapDissolve parameter is null
212    OH_Drawing_PixelMapDissolve(nullptr);
213}
214
215} // namespace Drawing
216} // namespace Rosen
217} // namespace OHOS