1f6603c60Sopenharmony_ci/* 2f6603c60Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device 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, Hardware 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 "gtest/gtest.h" 17f6603c60Sopenharmony_ci 18f6603c60Sopenharmony_ci#include "drawing_bitmap.h" 19f6603c60Sopenharmony_ci#include "drawing_types.h" 20f6603c60Sopenharmony_ci 21f6603c60Sopenharmony_ciusing namespace testing; 22f6603c60Sopenharmony_ciusing namespace testing::ext; 23f6603c60Sopenharmony_ci 24f6603c60Sopenharmony_cinamespace OHOS { 25f6603c60Sopenharmony_cinamespace Rosen { 26f6603c60Sopenharmony_cinamespace Drawing { 27f6603c60Sopenharmony_ciclass NativeDrawingBitmapLargeValueTest : public testing::Test { 28f6603c60Sopenharmony_cipublic: 29f6603c60Sopenharmony_ci static void SetUpTestCase(); 30f6603c60Sopenharmony_ci static void TearDownTestCase(); 31f6603c60Sopenharmony_ci void SetUp() override; 32f6603c60Sopenharmony_ci void TearDown() override; 33f6603c60Sopenharmony_ci protected: 34f6603c60Sopenharmony_ci OH_Drawing_Bitmap* bitmap_ = nullptr; 35f6603c60Sopenharmony_ci}; 36f6603c60Sopenharmony_ci 37f6603c60Sopenharmony_civoid NativeDrawingBitmapLargeValueTest::SetUpTestCase() {} 38f6603c60Sopenharmony_civoid NativeDrawingBitmapLargeValueTest::TearDownTestCase() {} 39f6603c60Sopenharmony_civoid NativeDrawingBitmapLargeValueTest::SetUp() 40f6603c60Sopenharmony_ci{ 41f6603c60Sopenharmony_ci bitmap_ = OH_Drawing_BitmapCreate(); 42f6603c60Sopenharmony_ci ASSERT_NE(bitmap_, nullptr); 43f6603c60Sopenharmony_ci} 44f6603c60Sopenharmony_ci 45f6603c60Sopenharmony_civoid NativeDrawingBitmapLargeValueTest::TearDown() 46f6603c60Sopenharmony_ci{ 47f6603c60Sopenharmony_ci if (bitmap_ != nullptr) { 48f6603c60Sopenharmony_ci OH_Drawing_BitmapDestroy(bitmap_); 49f6603c60Sopenharmony_ci bitmap_ = nullptr; 50f6603c60Sopenharmony_ci } 51f6603c60Sopenharmony_ci} 52f6603c60Sopenharmony_ci 53f6603c60Sopenharmony_ci/* 54f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_bitmapBuild001 55f6603c60Sopenharmony_ci * @tc.desc: test for drawing_bitmap build. 56f6603c60Sopenharmony_ci * @tc.size : MediumTest 57f6603c60Sopenharmony_ci * @tc.type : Function 58f6603c60Sopenharmony_ci * @tc.level : Level 1 59f6603c60Sopenharmony_ci */ 60f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_bitmapBuild001, TestSize.Level1) 61f6603c60Sopenharmony_ci{ 62f6603c60Sopenharmony_ci const unsigned int width = 2160; 63f6603c60Sopenharmony_ci const unsigned int height = 4096; 64f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_ALPHA_8, ALPHA_FORMAT_PREMUL }; 65f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat); 66f6603c60Sopenharmony_ci EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap_)); 67f6603c60Sopenharmony_ci EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap_)); 68f6603c60Sopenharmony_ci} 69f6603c60Sopenharmony_ci 70f6603c60Sopenharmony_ci/* 71f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_bitmapBuild003 72f6603c60Sopenharmony_ci * @tc.desc: test for drawing_bitmap build. 73f6603c60Sopenharmony_ci * @tc.size : MediumTest 74f6603c60Sopenharmony_ci * @tc.type : Function 75f6603c60Sopenharmony_ci * @tc.level : Level 1 76f6603c60Sopenharmony_ci */ 77f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_bitmapBuild003, TestSize.Level1) 78f6603c60Sopenharmony_ci{ 79f6603c60Sopenharmony_ci const unsigned int width = 2160; 80f6603c60Sopenharmony_ci const unsigned int height = 4096; 81f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_ARGB_4444, ALPHA_FORMAT_UNPREMUL }; 82f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat); 83f6603c60Sopenharmony_ci EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap_)); 84f6603c60Sopenharmony_ci EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap_)); 85f6603c60Sopenharmony_ci EXPECT_EQ(OH_Drawing_BitmapGetPixels(bitmap_) == nullptr, false); 86f6603c60Sopenharmony_ci} 87f6603c60Sopenharmony_ci 88f6603c60Sopenharmony_ci/* 89f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_bitmapBuild004 90f6603c60Sopenharmony_ci * @tc.desc: test for drawing_bitmap build. 91f6603c60Sopenharmony_ci * @tc.size : MediumTest 92f6603c60Sopenharmony_ci * @tc.type : Function 93f6603c60Sopenharmony_ci * @tc.level : Level 1 94f6603c60Sopenharmony_ci */ 95f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_bitmapBuild004, TestSize.Level1) 96f6603c60Sopenharmony_ci{ 97f6603c60Sopenharmony_ci const unsigned int width = 2160; 98f6603c60Sopenharmony_ci const unsigned int height = 4096; 99f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_UNPREMUL }; 100f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat); 101f6603c60Sopenharmony_ci EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap_)); 102f6603c60Sopenharmony_ci EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap_)); 103f6603c60Sopenharmony_ci} 104f6603c60Sopenharmony_ci 105f6603c60Sopenharmony_ci/* 106f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_bitmapCreateFromPixels005 107f6603c60Sopenharmony_ci * @tc.desc: test for OH_Drawing_BitmapCreateFromPixels. 108f6603c60Sopenharmony_ci * @tc.size : MediumTest 109f6603c60Sopenharmony_ci * @tc.type : Function 110f6603c60Sopenharmony_ci * @tc.level : Level 1 111f6603c60Sopenharmony_ci */ 112f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_bitmapCreateFromPixels005, 113f6603c60Sopenharmony_ci TestSize.Level1) 114f6603c60Sopenharmony_ci{ 115f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo; 116f6603c60Sopenharmony_ci OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate(); 117f6603c60Sopenharmony_ci EXPECT_NE(bitmap, nullptr); 118f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE}; 119f6603c60Sopenharmony_ci constexpr uint32_t width = 2160; 120f6603c60Sopenharmony_ci constexpr uint32_t height = 4096; 121f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat); 122f6603c60Sopenharmony_ci void* pixels = OH_Drawing_BitmapGetPixels(bitmap); 123f6603c60Sopenharmony_ci EXPECT_NE(pixels, nullptr); 124f6603c60Sopenharmony_ci uint32_t rowBytes = width * height * 4; 125f6603c60Sopenharmony_ci bitmap_ = OH_Drawing_BitmapCreateFromPixels(&imageInfo, pixels, rowBytes); 126f6603c60Sopenharmony_ci EXPECT_NE(bitmap_, nullptr); 127f6603c60Sopenharmony_ci bitmap_ = OH_Drawing_BitmapCreateFromPixels(&imageInfo, pixels, 0); 128f6603c60Sopenharmony_ci EXPECT_EQ(bitmap_, nullptr); 129f6603c60Sopenharmony_ci bitmap_ = OH_Drawing_BitmapCreateFromPixels(&imageInfo, nullptr, 0); 130f6603c60Sopenharmony_ci EXPECT_EQ(bitmap_, nullptr); 131f6603c60Sopenharmony_ci bitmap_ = OH_Drawing_BitmapCreateFromPixels(nullptr, nullptr, 0); 132f6603c60Sopenharmony_ci EXPECT_EQ(bitmap_, nullptr); 133f6603c60Sopenharmony_ci} 134f6603c60Sopenharmony_ci/* 135f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_bitmapGetImageInfo006 136f6603c60Sopenharmony_ci * @tc.desc: test for drawing_bitmapGetImageInfo. 137f6603c60Sopenharmony_ci * @tc.size : MediumTest 138f6603c60Sopenharmony_ci * @tc.type : Function 139f6603c60Sopenharmony_ci * @tc.level : Level 1 140f6603c60Sopenharmony_ci */ 141f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_bitmapGetImageInfo006, TestSize.Level1) 142f6603c60Sopenharmony_ci{ 143f6603c60Sopenharmony_ci const unsigned int width = 2160; 144f6603c60Sopenharmony_ci const unsigned int height = 4096; 145f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_UNPREMUL }; 146f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat); 147f6603c60Sopenharmony_ci OH_Drawing_Image_Info* imageInfo = new OH_Drawing_Image_Info(); 148f6603c60Sopenharmony_ci OH_Drawing_BitmapGetImageInfo(bitmap_, imageInfo); 149f6603c60Sopenharmony_ci EXPECT_EQ(width, imageInfo->width); 150f6603c60Sopenharmony_ci EXPECT_EQ(height, imageInfo->height); 151f6603c60Sopenharmony_ci} 152f6603c60Sopenharmony_ci 153f6603c60Sopenharmony_ci/* 154f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_BitmapReadPixels007 155f6603c60Sopenharmony_ci * @tc.desc: test for drawing_BitmapReadPixels. 156f6603c60Sopenharmony_ci * @tc.size : MediumTest 157f6603c60Sopenharmony_ci * @tc.type : Function 158f6603c60Sopenharmony_ci * @tc.level : Level 1 159f6603c60Sopenharmony_ci */ 160f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_BitmapReadPixels007, TestSize.Level1) 161f6603c60Sopenharmony_ci{ 162f6603c60Sopenharmony_ci const unsigned int width = 2160; 163f6603c60Sopenharmony_ci const unsigned int height = 4096; 164f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat bitmapFormat {COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_UNPREMUL}; 165f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat); 166f6603c60Sopenharmony_ci OH_Drawing_Image_Info imageInfo {width, height, COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_UNPREMUL}; 167f6603c60Sopenharmony_ci void* pixels = new uint32_t[width * height]; 168f6603c60Sopenharmony_ci bool res = OH_Drawing_BitmapReadPixels(nullptr, nullptr, nullptr, width * 4, 0, 0); 169f6603c60Sopenharmony_ci EXPECT_EQ(res, false); 170f6603c60Sopenharmony_ci res = OH_Drawing_BitmapReadPixels(nullptr, &imageInfo, pixels, width * 4, 0, 0); 171f6603c60Sopenharmony_ci EXPECT_EQ(res, false); 172f6603c60Sopenharmony_ci res = OH_Drawing_BitmapReadPixels(bitmap_, nullptr, pixels, width * 4, 0, 0); 173f6603c60Sopenharmony_ci EXPECT_EQ(res, false); 174f6603c60Sopenharmony_ci res = OH_Drawing_BitmapReadPixels(bitmap_, &imageInfo, nullptr, width * 4, 0, 0); 175f6603c60Sopenharmony_ci EXPECT_EQ(res, false); 176f6603c60Sopenharmony_ci res = OH_Drawing_BitmapReadPixels(bitmap_, &imageInfo, pixels, width * 4, 0, 0); 177f6603c60Sopenharmony_ci EXPECT_EQ(res, true); 178f6603c60Sopenharmony_ci if (pixels != nullptr) { 179f6603c60Sopenharmony_ci delete[] reinterpret_cast<uint32_t*>(pixels); 180f6603c60Sopenharmony_ci pixels = nullptr; 181f6603c60Sopenharmony_ci } 182f6603c60Sopenharmony_ci} 183f6603c60Sopenharmony_ci 184f6603c60Sopenharmony_ci/* 185f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_GetColorFormat008 186f6603c60Sopenharmony_ci * @tc.desc: test for drawing_BitmapGetColorFormat. 187f6603c60Sopenharmony_ci * @tc.size : MediumTest 188f6603c60Sopenharmony_ci * @tc.type : Function 189f6603c60Sopenharmony_ci * @tc.level : Level 1 190f6603c60Sopenharmony_ci */ 191f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_GetColorFormat008, TestSize.Level1) 192f6603c60Sopenharmony_ci{ 193f6603c60Sopenharmony_ci const unsigned int width = 2160; 194f6603c60Sopenharmony_ci const unsigned int height = 4096; 195f6603c60Sopenharmony_ci OH_Drawing_ColorFormat formats[] = { 196f6603c60Sopenharmony_ci COLOR_FORMAT_UNKNOWN, 197f6603c60Sopenharmony_ci COLOR_FORMAT_ALPHA_8, 198f6603c60Sopenharmony_ci COLOR_FORMAT_RGB_565, 199f6603c60Sopenharmony_ci COLOR_FORMAT_ARGB_4444, 200f6603c60Sopenharmony_ci COLOR_FORMAT_RGBA_8888, 201f6603c60Sopenharmony_ci COLOR_FORMAT_BGRA_8888 202f6603c60Sopenharmony_ci }; 203f6603c60Sopenharmony_ci 204f6603c60Sopenharmony_ci OH_Drawing_AlphaFormat alphaFormats[] = { 205f6603c60Sopenharmony_ci ALPHA_FORMAT_UNKNOWN, 206f6603c60Sopenharmony_ci ALPHA_FORMAT_OPAQUE, 207f6603c60Sopenharmony_ci ALPHA_FORMAT_PREMUL, 208f6603c60Sopenharmony_ci ALPHA_FORMAT_UNPREMUL 209f6603c60Sopenharmony_ci }; 210f6603c60Sopenharmony_ci OH_Drawing_ColorFormat colorFormat_; 211f6603c60Sopenharmony_ci for (int i = 1; i < 6; i++) { 212f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 213f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat bitmapFormat = {formats[i], alphaFormats[2]}; 214f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &bitmapFormat); 215f6603c60Sopenharmony_ci if (bitmap == nullptr) { 216f6603c60Sopenharmony_ci colorFormat_ = OH_Drawing_BitmapGetColorFormat(bitmap); 217f6603c60Sopenharmony_ci EXPECT_EQ(colorFormat_, formats[0]); 218f6603c60Sopenharmony_ci } 219f6603c60Sopenharmony_ci colorFormat_ = OH_Drawing_BitmapGetColorFormat(bitmap); 220f6603c60Sopenharmony_ci EXPECT_EQ(colorFormat_, formats[i]); 221f6603c60Sopenharmony_ci } 222f6603c60Sopenharmony_ci} 223f6603c60Sopenharmony_ci 224f6603c60Sopenharmony_ci/* 225f6603c60Sopenharmony_ci * @tc.name: NativeDrawingBitmapLargeValueTest_GetAlphaFormat009 226f6603c60Sopenharmony_ci * @tc.desc: test for drawing_BitmapGetAlphaFormat. 227f6603c60Sopenharmony_ci * @tc.size : MediumTest 228f6603c60Sopenharmony_ci * @tc.type : Function 229f6603c60Sopenharmony_ci * @tc.level : Level 1 230f6603c60Sopenharmony_ci */ 231f6603c60Sopenharmony_ciHWTEST_F(NativeDrawingBitmapLargeValueTest, NativeDrawingBitmapLargeValueTest_GetAlphaFormat009, TestSize.Level1) 232f6603c60Sopenharmony_ci{ 233f6603c60Sopenharmony_ci const unsigned int width = 2160; 234f6603c60Sopenharmony_ci const unsigned int height = 4096; 235f6603c60Sopenharmony_ci OH_Drawing_ColorFormat formats[] = { 236f6603c60Sopenharmony_ci COLOR_FORMAT_UNKNOWN, 237f6603c60Sopenharmony_ci COLOR_FORMAT_ALPHA_8, 238f6603c60Sopenharmony_ci COLOR_FORMAT_RGB_565, 239f6603c60Sopenharmony_ci COLOR_FORMAT_ARGB_4444, 240f6603c60Sopenharmony_ci COLOR_FORMAT_RGBA_8888, 241f6603c60Sopenharmony_ci COLOR_FORMAT_BGRA_8888 242f6603c60Sopenharmony_ci }; 243f6603c60Sopenharmony_ci 244f6603c60Sopenharmony_ci OH_Drawing_AlphaFormat alphaFormats[] = { 245f6603c60Sopenharmony_ci ALPHA_FORMAT_UNKNOWN, 246f6603c60Sopenharmony_ci ALPHA_FORMAT_OPAQUE, 247f6603c60Sopenharmony_ci ALPHA_FORMAT_PREMUL, 248f6603c60Sopenharmony_ci ALPHA_FORMAT_UNPREMUL 249f6603c60Sopenharmony_ci }; 250f6603c60Sopenharmony_ci OH_Drawing_AlphaFormat alphaFormat_; 251f6603c60Sopenharmony_ci for (int i = 1; i < 4; i++) { 252f6603c60Sopenharmony_ci OH_Drawing_Bitmap *bitmap = OH_Drawing_BitmapCreate(); 253f6603c60Sopenharmony_ci OH_Drawing_BitmapFormat bitmapFormat = {formats[3], alphaFormats[i]}; 254f6603c60Sopenharmony_ci OH_Drawing_BitmapBuild(bitmap, width, height, &bitmapFormat); 255f6603c60Sopenharmony_ci if (bitmap == nullptr) { 256f6603c60Sopenharmony_ci alphaFormat_ = OH_Drawing_BitmapGetAlphaFormat(bitmap); 257f6603c60Sopenharmony_ci EXPECT_EQ(alphaFormat_, alphaFormats[0]); 258f6603c60Sopenharmony_ci } 259f6603c60Sopenharmony_ci alphaFormat_ = OH_Drawing_BitmapGetAlphaFormat(bitmap); 260f6603c60Sopenharmony_ci EXPECT_EQ(alphaFormat_, alphaFormats[i]); 261f6603c60Sopenharmony_ci } 262f6603c60Sopenharmony_ci} 263f6603c60Sopenharmony_ci} // namespace Drawing 264f6603c60Sopenharmony_ci} // namespace Rosen 265f6603c60Sopenharmony_ci} // namespace OHOS