1f6603c60Sopenharmony_ci/*
2f6603c60Sopenharmony_ci * Copyright (c) 2022 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#include "drawing_bitmap.h"
18f6603c60Sopenharmony_ci#include "drawing_image.h"
19f6603c60Sopenharmony_ci
20f6603c60Sopenharmony_ciusing namespace testing;
21f6603c60Sopenharmony_ciusing namespace testing::ext;
22f6603c60Sopenharmony_ci
23f6603c60Sopenharmony_cinamespace OHOS {
24f6603c60Sopenharmony_cinamespace Rosen {
25f6603c60Sopenharmony_cinamespace Drawing {
26f6603c60Sopenharmony_ciclass NativeImageTest : public testing::Test {
27f6603c60Sopenharmony_cipublic:
28f6603c60Sopenharmony_ci    static void SetUpTestCase();
29f6603c60Sopenharmony_ci    static void TearDownTestCase();
30f6603c60Sopenharmony_ci    void SetUp() override;
31f6603c60Sopenharmony_ci    void TearDown() override;
32f6603c60Sopenharmony_ci};
33f6603c60Sopenharmony_ci
34f6603c60Sopenharmony_civoid NativeImageTest::SetUpTestCase() {}
35f6603c60Sopenharmony_civoid NativeImageTest::TearDownTestCase() {}
36f6603c60Sopenharmony_civoid NativeImageTest::SetUp() {}
37f6603c60Sopenharmony_civoid NativeImageTest::TearDown() {}
38f6603c60Sopenharmony_ci
39f6603c60Sopenharmony_ci/*
40f6603c60Sopenharmony_ci * @tc.name: NativeImageTest_BuildFromBitmap001
41f6603c60Sopenharmony_ci * @tc.desc: test BuildFromBitmap
42f6603c60Sopenharmony_ci * @tc.size  : MediumTest
43f6603c60Sopenharmony_ci * @tc.type  : Function
44f6603c60Sopenharmony_ci * @tc.level : Level 1
45f6603c60Sopenharmony_ci */
46f6603c60Sopenharmony_ciHWTEST_F(NativeImageTest, NativeImageTest_BuildFromBitmap001, TestSize.Level1)
47f6603c60Sopenharmony_ci{
48f6603c60Sopenharmony_ci    OH_Drawing_Image* image = OH_Drawing_ImageCreate();
49f6603c60Sopenharmony_ci    EXPECT_NE(image, nullptr);
50f6603c60Sopenharmony_ci    OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate();
51f6603c60Sopenharmony_ci    EXPECT_NE(bitmap, nullptr);
52f6603c60Sopenharmony_ci    OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
53f6603c60Sopenharmony_ci    constexpr uint32_t width = 200;
54f6603c60Sopenharmony_ci    constexpr uint32_t height = 200;
55f6603c60Sopenharmony_ci    OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat);
56f6603c60Sopenharmony_ci    EXPECT_TRUE(OH_Drawing_ImageBuildFromBitmap(image, bitmap));
57f6603c60Sopenharmony_ci    EXPECT_TRUE(!OH_Drawing_ImageBuildFromBitmap(image, nullptr));
58f6603c60Sopenharmony_ci    EXPECT_TRUE(!OH_Drawing_ImageBuildFromBitmap(nullptr, nullptr));
59f6603c60Sopenharmony_ci    OH_Drawing_BitmapDestroy(bitmap);
60f6603c60Sopenharmony_ci    OH_Drawing_ImageDestroy(image);
61f6603c60Sopenharmony_ci}
62f6603c60Sopenharmony_ci
63f6603c60Sopenharmony_ci/*
64f6603c60Sopenharmony_ci * @tc.name: NativeImageTest_GetWidth001
65f6603c60Sopenharmony_ci * @tc.desc: test GetWidth
66f6603c60Sopenharmony_ci * @tc.size  : MediumTest
67f6603c60Sopenharmony_ci * @tc.type  : Function
68f6603c60Sopenharmony_ci * @tc.level : Level 1
69f6603c60Sopenharmony_ci */
70f6603c60Sopenharmony_ciHWTEST_F(NativeImageTest, NativeImageTest_GetWidth001, TestSize.Level1)
71f6603c60Sopenharmony_ci{
72f6603c60Sopenharmony_ci    OH_Drawing_Image* image = OH_Drawing_ImageCreate();
73f6603c60Sopenharmony_ci    EXPECT_NE(image, nullptr);
74f6603c60Sopenharmony_ci    OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate();
75f6603c60Sopenharmony_ci    EXPECT_NE(bitmap, nullptr);
76f6603c60Sopenharmony_ci    OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
77f6603c60Sopenharmony_ci    constexpr uint32_t width = 200;
78f6603c60Sopenharmony_ci    constexpr uint32_t height = 200;
79f6603c60Sopenharmony_ci    OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat);
80f6603c60Sopenharmony_ci    OH_Drawing_ImageBuildFromBitmap(image, bitmap);
81f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ImageGetWidth(image), width);
82f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ImageGetWidth(nullptr), -1);
83f6603c60Sopenharmony_ci    OH_Drawing_BitmapDestroy(bitmap);
84f6603c60Sopenharmony_ci    OH_Drawing_ImageDestroy(image);
85f6603c60Sopenharmony_ci}
86f6603c60Sopenharmony_ci
87f6603c60Sopenharmony_ci/*
88f6603c60Sopenharmony_ci * @tc.name: NativeImageTest_GetHeight001
89f6603c60Sopenharmony_ci * @tc.desc: test GetHeight
90f6603c60Sopenharmony_ci * @tc.size  : MediumTest
91f6603c60Sopenharmony_ci * @tc.type  : Function
92f6603c60Sopenharmony_ci * @tc.level : Level 1
93f6603c60Sopenharmony_ci */
94f6603c60Sopenharmony_ciHWTEST_F(NativeImageTest, NativeImageTest_GetHeight001, TestSize.Level1)
95f6603c60Sopenharmony_ci{
96f6603c60Sopenharmony_ci    OH_Drawing_Image* image = OH_Drawing_ImageCreate();
97f6603c60Sopenharmony_ci    EXPECT_NE(image, nullptr);
98f6603c60Sopenharmony_ci    OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate();
99f6603c60Sopenharmony_ci    EXPECT_NE(bitmap, nullptr);
100f6603c60Sopenharmony_ci    OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
101f6603c60Sopenharmony_ci    constexpr uint32_t width = 200;
102f6603c60Sopenharmony_ci    constexpr uint32_t height = 200;
103f6603c60Sopenharmony_ci    OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat);
104f6603c60Sopenharmony_ci    OH_Drawing_ImageBuildFromBitmap(image, bitmap);
105f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ImageGetHeight(image), height);
106f6603c60Sopenharmony_ci    EXPECT_EQ(OH_Drawing_ImageGetHeight(nullptr), -1);
107f6603c60Sopenharmony_ci    OH_Drawing_BitmapDestroy(bitmap);
108f6603c60Sopenharmony_ci    OH_Drawing_ImageDestroy(image);
109f6603c60Sopenharmony_ci}
110f6603c60Sopenharmony_ci
111f6603c60Sopenharmony_ci/*
112f6603c60Sopenharmony_ci * @tc.name: NativeImageTest_GetImageInfo001
113f6603c60Sopenharmony_ci * @tc.desc: test GetImageInfo
114f6603c60Sopenharmony_ci * @tc.size  : MediumTest
115f6603c60Sopenharmony_ci * @tc.type  : Function
116f6603c60Sopenharmony_ci * @tc.level : Level 1
117f6603c60Sopenharmony_ci */
118f6603c60Sopenharmony_ciHWTEST_F(NativeImageTest, NativeImageTest_GetImageInfo001, TestSize.Level1)
119f6603c60Sopenharmony_ci{
120f6603c60Sopenharmony_ci    OH_Drawing_ImageGetImageInfo(nullptr, nullptr);
121f6603c60Sopenharmony_ci    OH_Drawing_Image* image = OH_Drawing_ImageCreate();
122f6603c60Sopenharmony_ci    EXPECT_NE(image, nullptr);
123f6603c60Sopenharmony_ci    OH_Drawing_Bitmap* bitmap = OH_Drawing_BitmapCreate();
124f6603c60Sopenharmony_ci    EXPECT_NE(bitmap, nullptr);
125f6603c60Sopenharmony_ci    OH_Drawing_BitmapFormat cFormat{COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_OPAQUE};
126f6603c60Sopenharmony_ci    constexpr uint32_t width = 200;
127f6603c60Sopenharmony_ci    constexpr uint32_t height = 200;
128f6603c60Sopenharmony_ci    OH_Drawing_BitmapBuild(bitmap, width, height, &cFormat);
129f6603c60Sopenharmony_ci    OH_Drawing_ImageBuildFromBitmap(image, bitmap);
130f6603c60Sopenharmony_ci    OH_Drawing_ImageGetImageInfo(image, nullptr);
131f6603c60Sopenharmony_ci    OH_Drawing_Image_Info imageInfo;
132f6603c60Sopenharmony_ci    OH_Drawing_ImageGetImageInfo(image, &imageInfo);
133f6603c60Sopenharmony_ci    EXPECT_EQ(imageInfo.width, width);
134f6603c60Sopenharmony_ci    OH_Drawing_BitmapDestroy(bitmap);
135f6603c60Sopenharmony_ci    OH_Drawing_ImageDestroy(image);
136f6603c60Sopenharmony_ci}
137f6603c60Sopenharmony_ci} // namespace Drawing
138f6603c60Sopenharmony_ci} // namespace Rosen
139f6603c60Sopenharmony_ci} // namespace OHOS