• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device 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, Hardware
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 "gtest/gtest.h"
17 
18 #include "c/drawing_bitmap.h"
19 #include "c/drawing_types.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class NativeDrawingBitmapTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33     protected:
34         OH_Drawing_Bitmap* bitmap_ = nullptr;
35 };
36 
SetUpTestCase()37 void NativeDrawingBitmapTest::SetUpTestCase() {}
TearDownTestCase()38 void NativeDrawingBitmapTest::TearDownTestCase() {}
SetUp()39 void NativeDrawingBitmapTest::SetUp()
40 {
41     bitmap_ = OH_Drawing_BitmapCreate();
42     ASSERT_NE(bitmap_, nullptr);
43 }
44 
TearDown()45 void NativeDrawingBitmapTest::TearDown()
46 {
47     if (bitmap_ != nullptr) {
48         OH_Drawing_BitmapDestroy(bitmap_);
49         bitmap_ = nullptr;
50     }
51 }
52 
53 /*
54  * @tc.name: NativeDrawingBitmapTest_bitmap002
55  * @tc.desc: test for drawing_bitmap build.
56  * @tc.type: FUNC
57  * @tc.require: AR000GTO5R
58  */
59 HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap002, TestSize.Level1)
60 {
61     const unsigned int width = 500;
62     const unsigned int height = 500;
63     OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_ALPHA_8, ALPHA_FORMAT_PREMUL };
64     OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat);
65     EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap_));
66     EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap_));
67 }
68 
69 /*
70  * @tc.name: NativeDrawingBitmapTest_bitmap003
71  * @tc.desc: test for drawing_bitmap build.
72  * @tc.type: FUNC
73  * @tc.require: AR000GTO5R
74  */
75 HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap003, TestSize.Level1)
76 {
77     const unsigned int width = 0;
78     const unsigned int height = 0;
79     OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_RGB_565, ALPHA_FORMAT_OPAQUE };
80     OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat);
81     EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap_));
82     EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap_));
83 }
84 
85 /*
86  * @tc.name: NativeDrawingBitmapTest_bitmap004
87  * @tc.desc: test for drawing_bitmap build.
88  * @tc.type: FUNC
89  * @tc.require: AR000GTO5R
90  */
91 HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap004, TestSize.Level1)
92 {
93     const unsigned int width = 500;
94     const unsigned int height = 500;
95     OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_ARGB_4444, ALPHA_FORMAT_UNPREMUL };
96     OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat);
97     EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap_));
98     EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap_));
99     EXPECT_EQ(OH_Drawing_BitmapGetPixels(bitmap_) == nullptr, false);
100 }
101 
102 /*
103  * @tc.name: NativeDrawingBitmapTest_bitmap005
104  * @tc.desc: test for drawing_bitmap build.
105  * @tc.type: FUNC
106  * @tc.require: AR000GTO5R
107  */
108 HWTEST_F(NativeDrawingBitmapTest, NativeDrawingBitmapTest_bitmap005, TestSize.Level1)
109 {
110     const unsigned int width = 500;
111     const unsigned int height = 500;
112     OH_Drawing_BitmapFormat bitmapFormat { COLOR_FORMAT_RGBA_8888, ALPHA_FORMAT_UNPREMUL };
113     OH_Drawing_BitmapBuild(bitmap_, width, height, &bitmapFormat);
114     EXPECT_EQ(width, OH_Drawing_BitmapGetWidth(bitmap_));
115     EXPECT_EQ(height, OH_Drawing_BitmapGetHeight(bitmap_));
116 }
117 } // namespace Drawing
118 } // namespace Rosen
119 } // namespace OHOS