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 42 using namespace testing; 43 using namespace testing::ext; 44 45 namespace OHOS { 46 namespace Rosen { 47 namespace Drawing { 48 class DrawingNativePixelMapTest : public testing::Test { 49 protected: 50 // 在每个测试用例执行前调用 SetUp()51 void SetUp() override 52 { 53 // 设置代码 54 std::cout << "DrawingNativePixelMapTest Setup code called before each test case." << std::endl; 55 OH_Drawing_ErrorCodeReset(); 56 std::cout << "DrawingNativePixelMapTest errorCodeReset before each test case." << std::endl; 57 } TearDown()58 void TearDown() override 59 { 60 std::cout << "DrawingNativePixelMapTest Setup code called after each test case." << std::endl; 61 OH_Drawing_ErrorCodeReset(); 62 std::cout << "DrawingNativePixelMapTest errorCodeReset after each test case." << std::endl; 63 } 64 }; 65 66 /* 67 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0100 68 * @tc.name: testPixelMapGetFromNativePixelMapNormal 69 * @tc.desc: test for testPixelMapGetFromNativePixelMapNormal. 70 * @tc.size : SmallTest 71 * @tc.type : Function 72 * @tc.level : Level 0 73 */ 74 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapNormal, Function | SmallTest | Level0) { 75 // todo: how to get NativePixelMap_? 76 NativePixelMap_ *pixelMap = nullptr; 77 // 1. Call OH_Drawing_PixelMapGetFromNativePixelMap 78 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(pixelMap); 79 EXPECT_EQ(drPixelMap, nullptr); 80 } 81 82 /* 83 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0101 84 * @tc.name: testPixelMapGetFromNativePixelMapNull 85 * @tc.desc: test for testPixelMapGetFromNativePixelMapNull. 86 * @tc.size : SmallTest 87 * @tc.type : Function 88 * @tc.level : Level 3 89 */ 90 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapNull, Function | SmallTest | Level3) { 91 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(nullptr); 92 EXPECT_EQ(drPixelMap, nullptr); 93 } 94 95 /* 96 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0102 97 * @tc.name: testPixelMapGetFromNativePixelMapMultipleCalls 98 * @tc.desc: test for testPixelMapGetFromNativePixelMapMultipleCalls. 99 * @tc.size : SmallTest 100 * @tc.type : Function 101 * @tc.level : Level 3 102 */ 103 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapMultipleCalls, Function | SmallTest | Level3) { 104 // todo: how to get NativePixelMap_? 105 NativePixelMap_ *pixelMap = nullptr; 106 // 1. Call OH_Drawing_PixelMapGetFromNativePixelMap 10 times 107 for (int i = 0; i < 10; i++) { 108 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(pixelMap); 109 EXPECT_EQ(drPixelMap, nullptr); 110 } 111 } 112 113 /* 114 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0102 115 * @tc.name: testPixelMapGetFromNativePixelMapBoundary 116 * @tc.desc: test for testPixelMapGetFromNativePixelMapBoundary. 117 * @tc.size : SmallTest 118 * @tc.type : Function 119 * @tc.level : Level 0 120 */ 121 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromNativePixelMapBoundary, Function | SmallTest | Level0) { 122 // todo: how to get NativePixelMap_? 123 NativePixelMap_ *pixelMap = nullptr; 124 // 1. Call OH_Drawing_PixelMapGetFromNativePixelMap 125 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromNativePixelMap(pixelMap); 126 EXPECT_EQ(drPixelMap, nullptr); 127 } 128 129 /* 130 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0200 131 * @tc.name: testPixelMapGetFromOhPixelMapNativeNormal 132 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeNormal. 133 * @tc.size : SmallTest 134 * @tc.type : Function 135 * @tc.level : Level 0 136 */ 137 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeNormal, Function | SmallTest | Level0) { 138 OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative(); 139 // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative 140 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap); 141 // add assert 142 EXPECT_NE(drPixelMap, nullptr); 143 // 2. Release memory 144 OH_Drawing_PixelMapDissolve(drPixelMap); 145 OH_PixelmapNative_Release(pixelMap); 146 } 147 148 /* 149 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0201 150 * @tc.name: testPixelMapGetFromOhPixelMapNativeNull 151 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeNull. 152 * @tc.size : SmallTest 153 * @tc.type : Function 154 * @tc.level : Level 3 155 */ 156 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeNull, Function | SmallTest | Level3) { 157 // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative with nullptr as parameter and check the error code using 158 // OH_Drawing_ErrorCodeGet 159 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(nullptr); 160 EXPECT_EQ(drPixelMap, nullptr); 161 } 162 163 /* 164 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0202 165 * @tc.name: testPixelMapGetFromOhPixelMapNativeMultipleCalls 166 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeMultipleCalls. 167 * @tc.size : SmallTest 168 * @tc.type : Function 169 * @tc.level : Level 3 170 */ 171 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeMultipleCalls, Function | SmallTest | Level3) { 172 OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative(); 173 // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative 10 times 174 for (int i = 0; i < 10; i++) { 175 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap); 176 // add assert 177 EXPECT_NE(drPixelMap, nullptr); 178 OH_Drawing_PixelMapDissolve(drPixelMap); 179 } 180 OH_PixelmapNative_Release(pixelMap); 181 } 182 183 /* 184 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0203 185 * @tc.name: testPixelMapGetFromOhPixelMapNativeBoundary 186 * @tc.desc: test for testPixelMapGetFromOhPixelMapNativeBoundary. 187 * @tc.size : SmallTest 188 * @tc.type : Function 189 * @tc.level : Level 0 190 */ 191 HWTEST_F(DrawingNativePixelMapTest, testPixelMapGetFromOhPixelMapNativeBoundary, Function | SmallTest | Level0) { 192 uint32_t width = 4096; 193 uint32_t height = 2160; 194 OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative(width, height); 195 // add assert 196 EXPECT_EQ(pixelMap, nullptr); 197 // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative 198 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap); 199 // add assert 200 EXPECT_EQ(drPixelMap, nullptr); 201 // 2. Release memory 202 OH_Drawing_PixelMapDissolve(drPixelMap); 203 OH_PixelmapNative_Release(pixelMap); 204 EXPECT_EQ(pixelMap, nullptr); 205 } 206 207 /* 208 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0300 209 * @tc.name: testPixelMapDissolveNormal 210 * @tc.desc: test for testPixelMapDissolveNormal. 211 * @tc.size : SmallTest 212 * @tc.type : Function 213 * @tc.level : Level 0 214 */ 215 HWTEST_F(DrawingNativePixelMapTest, testPixelMapDissolveNormal, Function | SmallTest | Level0) { 216 OH_PixelmapNative *pixelMap = GET_OH_PixelmapNative(); 217 // add assert 218 EXPECT_NE(pixelMap, nullptr); 219 // 1. Call OH_Drawing_PixelMapGetFromOhPixelMapNative 220 OH_Drawing_PixelMap *drPixelMap = OH_Drawing_PixelMapGetFromOhPixelMapNative(pixelMap); 221 // add assert 222 EXPECT_NE(drPixelMap, nullptr); 223 // 2. Call OH_Drawing_PixelMapDissolve 224 OH_Drawing_PixelMapDissolve(drPixelMap); 225 OH_PixelmapNative_Release(pixelMap); 226 } 227 228 /* 229 * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_PIXEL_MAP_0301 230 * @tc.name: testPixelMapDissolveNull 231 * @tc.desc: test for testPixelMapDissolveNull. 232 * @tc.size : SmallTest 233 * @tc.type : Function 234 * @tc.level : Level 3 235 */ 236 HWTEST_F(DrawingNativePixelMapTest, testPixelMapDissolveNull, Function | SmallTest | Level3) { 237 // 1. OH_Drawing_PixelMapDissolve parameter is null 238 OH_Drawing_PixelMapDissolve(nullptr); 239 // add assert 240 EXPECT_TRUE(true); 241 } 242 243 } // namespace Drawing 244 } // namespace Rosen 245 } // namespace OHOS