1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2024 Shenzhen Kaihong Digital Industry Development Co., Ltd. 3f6603c60Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f6603c60Sopenharmony_ci * you may not use this file except in compliance with the License. 5f6603c60Sopenharmony_ci * You may obtain a copy of the License at 6f6603c60Sopenharmony_ci * 7f6603c60Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f6603c60Sopenharmony_ci * 9f6603c60Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f6603c60Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f6603c60Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f6603c60Sopenharmony_ci * See the License for the specific language governing permissions and 13f6603c60Sopenharmony_ci * limitations under the License. 14f6603c60Sopenharmony_ci */ 15f6603c60Sopenharmony_ci 16f6603c60Sopenharmony_ci#include "drawing_bitmap.h" 17f6603c60Sopenharmony_ci#include "drawing_error_code.h" 18f6603c60Sopenharmony_ci#include "drawing_image.h" 19f6603c60Sopenharmony_ci#include "gtest/gtest.h" 20f6603c60Sopenharmony_ci#include <cstdlib> 21f6603c60Sopenharmony_ci#include <ctime> 22f6603c60Sopenharmony_ci 23f6603c60Sopenharmony_ciusing namespace testing; 24f6603c60Sopenharmony_ciusing namespace testing::ext; 25f6603c60Sopenharmony_ci 26f6603c60Sopenharmony_cinamespace OHOS { 27f6603c60Sopenharmony_cinamespace Rosen { 28f6603c60Sopenharmony_cinamespace Drawing { 29f6603c60Sopenharmony_ciclass DrawingNativeImageTest : public testing::Test {}; 30f6603c60Sopenharmony_ci 31f6603c60Sopenharmony_ci/* 32f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0100 33f6603c60Sopenharmony_ci * @tc.name: testImageCreateDestroyNormal 34f6603c60Sopenharmony_ci * @tc.desc: Test for creating and destroying an image object with normal parameters. 35f6603c60Sopenharmony_ci * @tc.size : SmallTest 36f6603c60Sopenharmony_ci * @tc.type : Function 37f6603c60Sopenharmony_ci * @tc.level : Level 0 38f6603c60Sopenharmony_ci */ 39f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageCreateDestroyNormal, TestSize.Level0) { 40f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 41f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 42f6603c60Sopenharmony_ci // 2. OH_Drawing_ImageDestroy 43f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 44f6603c60Sopenharmony_ci} 45f6603c60Sopenharmony_ci 46f6603c60Sopenharmony_ci/* 47f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0101 48f6603c60Sopenharmony_ci * @tc.name: testImageCreateDestroyNULL 49f6603c60Sopenharmony_ci * @tc.desc: Test for destroying an image object with a NULL parameter. 50f6603c60Sopenharmony_ci * @tc.size : SmallTest 51f6603c60Sopenharmony_ci * @tc.type : Function 52f6603c60Sopenharmony_ci * @tc.level : Level 3 53f6603c60Sopenharmony_ci */ 54f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageCreateDestroyNULL, TestSize.Level3) { 55f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageDestroy with a NULL parameter 56f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(nullptr); 57f6603c60Sopenharmony_ci} 58f6603c60Sopenharmony_ci 59f6603c60Sopenharmony_ci/* 60f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0102 61f6603c60Sopenharmony_ci * @tc.name: testImageCreateDestroyMultipleCalls 62f6603c60Sopenharmony_ci * @tc.desc: Test for multiple calls of creating and destroying an image object. 63f6603c60Sopenharmony_ci * @tc.size : SmallTest 64f6603c60Sopenharmony_ci * @tc.type : Function 65f6603c60Sopenharmony_ci * @tc.level : Level 3 66f6603c60Sopenharmony_ci */ 67f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageCreateDestroyMultipleCalls, TestSize.Level3) { 68f6603c60Sopenharmony_ci // 1. Call OH_Drawing_ImageCreate and OH_Drawing_ImageDestroy 10 times 69f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 70f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 71f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 72f6603c60Sopenharmony_ci } 73f6603c60Sopenharmony_ci // 2. Call OH_Drawing_ImageCreate 10 times continuously 74f6603c60Sopenharmony_ci OH_Drawing_Image *images[10]; 75f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 76f6603c60Sopenharmony_ci images[i] = OH_Drawing_ImageCreate(); 77f6603c60Sopenharmony_ci } 78f6603c60Sopenharmony_ci // 3. Call OH_Drawing_ImageDestroy 10 times continuously 79f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 80f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(images[i]); 81f6603c60Sopenharmony_ci } 82f6603c60Sopenharmony_ci} 83f6603c60Sopenharmony_ci 84f6603c60Sopenharmony_ci/* 85f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0200 86f6603c60Sopenharmony_ci * @tc.name: testImageBuildFromBitmapNormal 87f6603c60Sopenharmony_ci * @tc.desc: Test for building an image from a bitmap with normal parameters. 88f6603c60Sopenharmony_ci * @tc.size : SmallTest 89f6603c60Sopenharmony_ci * @tc.type : Function 90f6603c60Sopenharmony_ci * @tc.level : Level 0 91f6603c60Sopenharmony_ci */ 92f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageBuildFromBitmapNormal, TestSize.Level0) { 93f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 94f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 95f6603c60Sopenharmony_ci // 2. OH_Drawing_BitmapCreate 96f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 97f6603c60Sopenharmony_ci // 3. OH_Drawing_ImageBuildFromBitmap successfully constructs the image content 98f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, bitmap); 99f6603c60Sopenharmony_ci EXPECT_NE(bitmap, nullptr); 100f6603c60Sopenharmony_ci // 4. OH_Drawing_ImageBuildFromBitmap fails to construct the image content 101f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, nullptr); 102f6603c60Sopenharmony_ci // 5. Free memory 103f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 104f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 105f6603c60Sopenharmony_ci} 106f6603c60Sopenharmony_ci 107f6603c60Sopenharmony_ci/* 108f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0201 109f6603c60Sopenharmony_ci * @tc.name: testImageBuildFromBitmapNULL 110f6603c60Sopenharmony_ci * @tc.desc: Test for building an image from a bitmap with NULL parameters. 111f6603c60Sopenharmony_ci * @tc.size : SmallTest 112f6603c60Sopenharmony_ci * @tc.type : Function 113f6603c60Sopenharmony_ci * @tc.level : Level 3 114f6603c60Sopenharmony_ci */ 115f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageBuildFromBitmapNULL, TestSize.Level3) { 116f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 117f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 118f6603c60Sopenharmony_ci // 2. OH_Drawing_BitmapCreate 119f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 120f6603c60Sopenharmony_ci // 3. OH_Drawing_ImageBuildFromBitmap with a null parameter, check the error code with OH_Drawing_ErrorCodeGet 121f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(nullptr, bitmap); 122f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 123f6603c60Sopenharmony_ci // 4. OH_Drawing_ImageBuildFromBitmap with a null parameter, check the error code with OH_Drawing_ErrorCodeGet 124f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, nullptr); 125f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 126f6603c60Sopenharmony_ci // 5. Free memory 127f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 128f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 129f6603c60Sopenharmony_ci} 130f6603c60Sopenharmony_ci 131f6603c60Sopenharmony_ci/* 132f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0202 133f6603c60Sopenharmony_ci * @tc.name: testImageBuildFromBitmapMultipleCalls 134f6603c60Sopenharmony_ci * @tc.desc: Test for multiple calls of building an image from a bitmap. 135f6603c60Sopenharmony_ci * @tc.size : SmallTest 136f6603c60Sopenharmony_ci * @tc.type : Function 137f6603c60Sopenharmony_ci * @tc.level : Level 3 138f6603c60Sopenharmony_ci */ 139f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageBuildFromBitmapMultipleCalls, TestSize.Level3) { 140f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 141f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 142f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 143f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 144f6603c60Sopenharmony_ci uint32_t width = 200 + i * 10; 145f6603c60Sopenharmony_ci uint32_t height = 200 + i * 10; 146f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 147f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, bitmap); 148f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 149f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 150f6603c60Sopenharmony_ci } 151f6603c60Sopenharmony_ci} 152f6603c60Sopenharmony_ci 153f6603c60Sopenharmony_ci/* 154f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0203 155f6603c60Sopenharmony_ci * @tc.name: testImageBuildFromBitmapMultipleCallsBoundary 156f6603c60Sopenharmony_ci * @tc.desc: Test for multiple calls of building an boundary value image from a bitmap. 157f6603c60Sopenharmony_ci * @tc.size : SmallTest 158f6603c60Sopenharmony_ci * @tc.type : Function 159f6603c60Sopenharmony_ci * @tc.level : Level 3 160f6603c60Sopenharmony_ci */ 161f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageBuildFromBitmapMultipleCallsBoundary, TestSize.Level3) { 162f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 163f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 164f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 165f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 166f6603c60Sopenharmony_ci uint32_t width = 4096; 167f6603c60Sopenharmony_ci uint32_t height = 2160; 168f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 169f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, bitmap); 170f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 171f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 172f6603c60Sopenharmony_ci } 173f6603c60Sopenharmony_ci} 174f6603c60Sopenharmony_ci 175f6603c60Sopenharmony_ci/* 176f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0300 177f6603c60Sopenharmony_ci * @tc.name: testImageGetWidthHeightNormal 178f6603c60Sopenharmony_ci * @tc.desc: Test for getting width and height of an image with normal parameters. 179f6603c60Sopenharmony_ci * @tc.size : SmallTest 180f6603c60Sopenharmony_ci * @tc.type : Function 181f6603c60Sopenharmony_ci * @tc.level : Level 0 182f6603c60Sopenharmony_ci */ 183f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetWidthHeightNormal, TestSize.Level0) { 184f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 185f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 186f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 187f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 188f6603c60Sopenharmony_ci constexpr uint32_t width = 200; 189f6603c60Sopenharmony_ci constexpr uint32_t height = 200; 190f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 191f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, bitmap); 192f6603c60Sopenharmony_ci // 2. OH_Drawing_ImageGetWidth 193f6603c60Sopenharmony_ci int32_t width_ = OH_Drawing_ImageGetWidth(image); 194f6603c60Sopenharmony_ci EXPECT_EQ(width_, 200); 195f6603c60Sopenharmony_ci // 3. OH_Drawing_ImageGetHeight 196f6603c60Sopenharmony_ci int32_t height_ = OH_Drawing_ImageGetHeight(image); 197f6603c60Sopenharmony_ci EXPECT_EQ(height_, 200); 198f6603c60Sopenharmony_ci // 4. Free memory 199f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 200f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 201f6603c60Sopenharmony_ci} 202f6603c60Sopenharmony_ci 203f6603c60Sopenharmony_ci/* 204f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0301 205f6603c60Sopenharmony_ci * @tc.name: testImageGetWidthHeightNULL 206f6603c60Sopenharmony_ci * @tc.desc: Test for getting width and height of an image with NULL parameters. 207f6603c60Sopenharmony_ci * @tc.size : SmallTest 208f6603c60Sopenharmony_ci * @tc.type : Function 209f6603c60Sopenharmony_ci * @tc.level : Level 3 210f6603c60Sopenharmony_ci */ 211f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetWidthHeightNULL, TestSize.Level3) { 212f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 213f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 214f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 215f6603c60Sopenharmony_ci uint32_t width = 200; 216f6603c60Sopenharmony_ci uint32_t height = 200; 217f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 218f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, bitmap); 219f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageGetWidth with a null parameter, check the error code with OH_Drawing_ErrorCodeGet 220f6603c60Sopenharmony_ci OH_Drawing_ImageGetWidth(nullptr); 221f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 222f6603c60Sopenharmony_ci // 2. OH_Drawing_ImageGetHeight with a null parameter, check the error code with OH_Drawing_ErrorCodeGet 223f6603c60Sopenharmony_ci OH_Drawing_ImageGetHeight(nullptr); 224f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 225f6603c60Sopenharmony_ci} 226f6603c60Sopenharmony_ci 227f6603c60Sopenharmony_ci/* 228f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0302 229f6603c60Sopenharmony_ci * @tc.name: testImageGetWidthHeightMultipleCalls 230f6603c60Sopenharmony_ci * @tc.desc: Test for multiple calls of getting width and height of an image. 231f6603c60Sopenharmony_ci * @tc.size : SmallTest 232f6603c60Sopenharmony_ci * @tc.type : Function 233f6603c60Sopenharmony_ci * @tc.level : Level 3 234f6603c60Sopenharmony_ci */ 235f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetWidthHeightMultipleCalls, TestSize.Level3) { 236f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 237f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 238f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 239f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 240f6603c60Sopenharmony_ci uint32_t width = 200 + i * 10; 241f6603c60Sopenharmony_ci uint32_t height = 200 + i * 10; 242f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 243f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, bitmap); 244f6603c60Sopenharmony_ci int32_t width_ = OH_Drawing_ImageGetWidth(image); 245f6603c60Sopenharmony_ci EXPECT_EQ(width_, 200 + i * 10); 246f6603c60Sopenharmony_ci int32_t height_ = OH_Drawing_ImageGetHeight(image); 247f6603c60Sopenharmony_ci EXPECT_EQ(height_, 200 + i * 10); 248f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 249f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 250f6603c60Sopenharmony_ci } 251f6603c60Sopenharmony_ci} 252f6603c60Sopenharmony_ci 253f6603c60Sopenharmony_ci/* 254f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0302 255f6603c60Sopenharmony_ci * @tc.name: testImageGetWidthHeightMultipleCallsBoundary 256f6603c60Sopenharmony_ci * @tc.desc: Test for multiple calls of getting width and height of an boundary value image. 257f6603c60Sopenharmony_ci * @tc.size : SmallTest 258f6603c60Sopenharmony_ci * @tc.type : Function 259f6603c60Sopenharmony_ci * @tc.level : Level 3 260f6603c60Sopenharmony_ci */ 261f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetWidthHeightMultipleCallsBoundary, TestSize.Level3) { 262f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 263f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 264f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 265f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 266f6603c60Sopenharmony_ci uint32_t width = 4096; 267f6603c60Sopenharmony_ci uint32_t height = 2160; 268f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 269f6603c60Sopenharmony_ci EXPECT_NE(bitmap, nullptr); 270f6603c60Sopenharmony_ci OH_Drawing_ImageBuildFromBitmap(image, bitmap); 271f6603c60Sopenharmony_ci EXPECT_NE(image, nullptr); 272f6603c60Sopenharmony_ci int32_t width_ = OH_Drawing_ImageGetWidth(image); 273f6603c60Sopenharmony_ci EXPECT_EQ(width_, 4096); 274f6603c60Sopenharmony_ci int32_t height_ = OH_Drawing_ImageGetHeight(image); 275f6603c60Sopenharmony_ci EXPECT_EQ(height_, 2160); 276f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 277f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 278f6603c60Sopenharmony_ci } 279f6603c60Sopenharmony_ci} 280f6603c60Sopenharmony_ci 281f6603c60Sopenharmony_ci/* 282f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0400 283f6603c60Sopenharmony_ci * @tc.name: testImageGetImageInfoNormal 284f6603c60Sopenharmony_ci * @tc.desc: Test for getting image info with normal parameters. 285f6603c60Sopenharmony_ci * @tc.size : SmallTest 286f6603c60Sopenharmony_ci * @tc.type : Function 287f6603c60Sopenharmony_ci * @tc.level : Level 0 288f6603c60Sopenharmony_ci */ 289f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetImageInfoNormal, TestSize.Level0) { 290f6603c60Sopenharmony_ci OH_Drawing_ColorFormat cfs[] = { 291f6603c60Sopenharmony_ci COLOR_FORMAT_UNKNOWN, COLOR_FORMAT_ALPHA_8, COLOR_FORMAT_RGB_565, 292f6603c60Sopenharmony_ci COLOR_FORMAT_ARGB_4444, COLOR_FORMAT_RGBA_8888, COLOR_FORMAT_BGRA_8888, 293f6603c60Sopenharmony_ci }; 294f6603c60Sopenharmony_ci OH_Drawing_AlphaFormat afs[] = { 295f6603c60Sopenharmony_ci ALPHA_FORMAT_UNKNOWN, 296f6603c60Sopenharmony_ci ALPHA_FORMAT_OPAQUE, 297f6603c60Sopenharmony_ci ALPHA_FORMAT_PREMUL, 298f6603c60Sopenharmony_ci ALPHA_FORMAT_UNPREMUL, 299f6603c60Sopenharmony_ci }; 300f6603c60Sopenharmony_ci for (OH_Drawing_ColorFormat cf : cfs) { 301f6603c60Sopenharmony_ci for (OH_Drawing_AlphaFormat af : afs) { 302f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 303f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 304f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{cf, af}; 305f6603c60Sopenharmony_ci uint32_t width = 400; 306f6603c60Sopenharmony_ci uint32_t height = 400; 307f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo; 308f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 309f6603c60Sopenharmony_ci OH_Drawing_ImageGetImageInfo(image, &imageInfo); 310f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 311f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 312f6603c60Sopenharmony_ci } 313f6603c60Sopenharmony_ci } 314f6603c60Sopenharmony_ci} 315f6603c60Sopenharmony_ci 316f6603c60Sopenharmony_ci/* 317f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0401 318f6603c60Sopenharmony_ci * @tc.name: testImageGetImageInfoNULL 319f6603c60Sopenharmony_ci * @tc.desc: Test for getting image info with NULL parameters. 320f6603c60Sopenharmony_ci * @tc.size : SmallTest 321f6603c60Sopenharmony_ci * @tc.type : Function 322f6603c60Sopenharmony_ci * @tc.level : Level 3 323f6603c60Sopenharmony_ci */ 324f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetImageInfoNULL, TestSize.Level3) { 325f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 326f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 327f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 328f6603c60Sopenharmony_ci // 2. OH_Drawing_Image_Info 329f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 330f6603c60Sopenharmony_ci uint32_t width = 400; 331f6603c60Sopenharmony_ci uint32_t height = 400; 332f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo; 333f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 334f6603c60Sopenharmony_ci OH_Drawing_ImageGetImageInfo(image, &imageInfo); 335f6603c60Sopenharmony_ci // 3. OH_Drawing_ImageGetImageInfo with a null parameter, check the error code with OH_Drawing_ErrorCodeGet 336f6603c60Sopenharmony_ci OH_Drawing_ImageGetImageInfo(nullptr, &imageInfo); 337f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_ErrorCodeGet(), OH_Drawing_ErrorCode::OH_DRAWING_ERROR_INVALID_PARAMETER); 338f6603c60Sopenharmony_ci // 4. Free memory 339f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 340f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 341f6603c60Sopenharmony_ci} 342f6603c60Sopenharmony_ci 343f6603c60Sopenharmony_ci/* 344f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0402 345f6603c60Sopenharmony_ci * @tc.name: testImageGetImageInfoMultipleCalls 346f6603c60Sopenharmony_ci * @tc.desc: Test for multiple calls of getting image info. 347f6603c60Sopenharmony_ci * @tc.size : SmallTest 348f6603c60Sopenharmony_ci * @tc.type : Function 349f6603c60Sopenharmony_ci * @tc.level : Level 3 350f6603c60Sopenharmony_ci */ 351f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetImageInfoMultipleCalls, TestSize.Level3) { 352f6603c60Sopenharmony_ci OH_Drawing_ColorFormat cf[] = { 353f6603c60Sopenharmony_ci COLOR_FORMAT_UNKNOWN, COLOR_FORMAT_ALPHA_8, COLOR_FORMAT_RGB_565, 354f6603c60Sopenharmony_ci COLOR_FORMAT_ARGB_4444, COLOR_FORMAT_RGBA_8888, COLOR_FORMAT_BGRA_8888, 355f6603c60Sopenharmony_ci }; 356f6603c60Sopenharmony_ci OH_Drawing_AlphaFormat af[] = { 357f6603c60Sopenharmony_ci ALPHA_FORMAT_UNKNOWN, 358f6603c60Sopenharmony_ci ALPHA_FORMAT_OPAQUE, 359f6603c60Sopenharmony_ci ALPHA_FORMAT_PREMUL, 360f6603c60Sopenharmony_ci ALPHA_FORMAT_UNPREMUL, 361f6603c60Sopenharmony_ci }; 362f6603c60Sopenharmony_ci for (int i = 0; i < 10; i++) { 363f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 364f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 365f6603c60Sopenharmony_ci srand(static_cast<unsigned int>(time(0))); 366f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{cf[rand() % 5 + 1], af[rand() % 3 + 1]}; 367f6603c60Sopenharmony_ci uint32_t width = rand() % 100 + 1; 368f6603c60Sopenharmony_ci uint32_t height = rand() % 100 + 1; 369f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 370f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo; 371f6603c60Sopenharmony_ci OH_Drawing_ImageGetImageInfo(image, &imageInfo); 372f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 373f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 374f6603c60Sopenharmony_ci } 375f6603c60Sopenharmony_ci} 376f6603c60Sopenharmony_ci 377f6603c60Sopenharmony_ci/* 378f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0403 379f6603c60Sopenharmony_ci * @tc.name: testImageGetImageInfoAbnormal 380f6603c60Sopenharmony_ci * @tc.desc: Test for getting image info with abnormal parameters. 381f6603c60Sopenharmony_ci * @tc.size : SmallTest 382f6603c60Sopenharmony_ci * @tc.type : Function 383f6603c60Sopenharmony_ci * @tc.level : Level 3 384f6603c60Sopenharmony_ci */ 385f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetImageInfoAbnormal, TestSize.Level3) { 386f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 387f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 388f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 389f6603c60Sopenharmony_ci // 2. OH_Drawing_ImageGetImageInfo creates OH_Drawing_Image_Info with width=-400 and height=-400 390f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 391f6603c60Sopenharmony_ci uint32_t width = -400; 392f6603c60Sopenharmony_ci uint32_t height = -400; 393f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo; 394f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 395f6603c60Sopenharmony_ci OH_Drawing_ImageGetImageInfo(image, &imageInfo); 396f6603c60Sopenharmony_ci // 3. Free memory 397f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 398f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 399f6603c60Sopenharmony_ci} 400f6603c60Sopenharmony_ci 401f6603c60Sopenharmony_ci/* 402f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0404 403f6603c60Sopenharmony_ci * @tc.name: testImageGetImageInfoMaximum 404f6603c60Sopenharmony_ci * @tc.desc: Test for getting image info with maximum values. 405f6603c60Sopenharmony_ci * @tc.size : SmallTest 406f6603c60Sopenharmony_ci * @tc.type : Function 407f6603c60Sopenharmony_ci * @tc.level : Level 3 408f6603c60Sopenharmony_ci */ 409f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetImageInfoMaximum, TestSize.Level3) { 410f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 411f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 412f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 413f6603c60Sopenharmony_ci // 2. OH_Drawing_ImageGetImageInfo creates OH_Drawing_Image_Info with width=maximum value and height=maximum value 414f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 415f6603c60Sopenharmony_ci uint32_t width = UINT32_MAX; 416f6603c60Sopenharmony_ci uint32_t height = UINT32_MAX; 417f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo; 418f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 419f6603c60Sopenharmony_ci OH_Drawing_ImageGetImageInfo(image, &imageInfo); 420f6603c60Sopenharmony_ci // 3. Free memory 421f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 422f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 423f6603c60Sopenharmony_ci} 424f6603c60Sopenharmony_ci 425f6603c60Sopenharmony_ci/* 426f6603c60Sopenharmony_ci * @tc.number: SUB_BASIC_GRAPHICS_SPECIAL_API_C_DRAWING_IMAGE_0405 427f6603c60Sopenharmony_ci * @tc.name: testImageGetImageInfoBoundary 428f6603c60Sopenharmony_ci * @tc.desc: Test for getting image info with Boundary value. 429f6603c60Sopenharmony_ci * @tc.size : SmallTest 430f6603c60Sopenharmony_ci * @tc.type : Function 431f6603c60Sopenharmony_ci * @tc.level : Level 3 432f6603c60Sopenharmony_ci */ 433f6603c60Sopenharmony_ciHWTEST_F(DrawingNativeImageTest, testImageGetImageInfoBoundary, TestSize.Level3) { 434f6603c60Sopenharmony_ci // 1. OH_Drawing_ImageCreate 435f6603c60Sopenharmony_ci OH_Drawing_Image *image = OH_Drawing_ImageCreate(); 436f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 437f6603c60Sopenharmony_ci // 2. OH_Drawing_ImageGetImageInfo creates OH_Drawing_Image_Info with width=maximum value and height=maximum value 438f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 439f6603c60Sopenharmony_ci uint32_t width = 4096; 440f6603c60Sopenharmony_ci uint32_t height = 2160; 441f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo; 442f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 443f6603c60Sopenharmony_ci EXPECT_NE(bitmap, nullptr); 444f6603c60Sopenharmony_ci OH_Drawing_ImageGetImageInfo(image, &imageInfo); 445f6603c60Sopenharmony_ci EXPECT_NE(image, nullptr); 446f6603c60Sopenharmony_ci // 3. Free memory 447f6603c60Sopenharmony_ci OH_Drawing_ImageDestroy(image); 448f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap); 449f6603c60Sopenharmony_ci} 450f6603c60Sopenharmony_ci 451f6603c60Sopenharmony_ci} // namespace Drawing 452f6603c60Sopenharmony_ci} // namespace Rosen 453f6603c60Sopenharmony_ci} // namespace OHOS