• 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 "draw/color.h"
19 #include "image/bitmap.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace Drawing {
27 class BitmapTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33 };
34 
SetUpTestCase()35 void BitmapTest::SetUpTestCase() {}
TearDownTestCase()36 void BitmapTest::TearDownTestCase() {}
SetUp()37 void BitmapTest::SetUp() {}
TearDown()38 void BitmapTest::TearDown() {}
39 
40 /**
41  * @tc.name: BitmapCreateAndDestroy001
42  * @tc.desc:
43  * @tc.type: FUNC
44  * @tc.require:AR000GGNV3
45  * @tc.author:
46  */
47 HWTEST_F(BitmapTest, BitmapCreateAndDestroy001, TestSize.Level1)
48 {
49     // The best way to create Bitmap.
50     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
51     ASSERT_TRUE(bitmap != nullptr);
52 }
53 
54 /**
55  * @tc.name: BitmapBuildTest001
56  * @tc.desc:
57  * @tc.type: FUNC
58  * @tc.require:AR000GGNV3
59  * @tc.author:
60  */
61 HWTEST_F(BitmapTest, BitmapBuildTest001, TestSize.Level1)
62 {
63     // The best way to Build Bitmap.
64     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
65     ASSERT_TRUE(bitmap != nullptr);
66     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
67     bitmap->Build(100, 200, bitmapFormat);
68 
69     bitmapFormat = { COLORTYPE_RGB_565, ALPHATYPE_PREMUL };
70     bitmap->Build(100, 200, bitmapFormat);
71 
72     bitmapFormat = { COLORTYPE_ARGB_4444, ALPHATYPE_UNPREMUL };
73     bitmap->Build(100, 200, bitmapFormat);
74 
75     bitmapFormat.colorType = COLORTYPE_RGBA_8888;
76     bitmap->Build(100, 200, bitmapFormat);
77 
78     bitmapFormat.colorType = COLORTYPE_BGRA_8888;
79     bitmap->Build(100, 200, bitmapFormat);
80 
81     bitmapFormat.colorType = COLORTYPE_N32;
82     bitmap->Build(100, 200, bitmapFormat);
83 }
84 
85 /**
86  * @tc.name: BitmapBuildTest002
87  * @tc.desc:
88  * @tc.type: FUNC
89  * @tc.require:AR000GGNV3
90  * @tc.author:
91  */
92 HWTEST_F(BitmapTest, BitmapBuildTest002, TestSize.Level1)
93 {
94     // The best way to Build Bitmap.
95     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
96     ASSERT_TRUE(bitmap != nullptr);
97     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
98     bitmap->Build(150, 99, bitmapFormat);
99 }
100 
101 /**
102  * @tc.name: BitmapBuildTest003
103  * @tc.desc:
104  * @tc.type: FUNC
105  * @tc.require:AR000GGNV3
106  * @tc.author:
107  */
108 HWTEST_F(BitmapTest, BitmapBuildTest003, TestSize.Level1)
109 {
110     // The best way to Build Bitmap.
111     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
112     ASSERT_TRUE(bitmap != nullptr);
113     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
114     bitmap->Build(111, 450, bitmapFormat);
115 }
116 
117 /**
118  * @tc.name: BitmapGetWidthTest001
119  * @tc.desc:
120  * @tc.type: FUNC
121  * @tc.require:AR000GGNV3
122  * @tc.author:
123  */
124 HWTEST_F(BitmapTest, BitmapGetWidthTest001, TestSize.Level1)
125 {
126     // The best way to get width.
127     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
128     ASSERT_TRUE(bitmap != nullptr);
129     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
130     bitmap->Build(111, 450, bitmapFormat);
131     ASSERT_EQ(111, bitmap->GetWidth());
132 }
133 
134 /**
135  * @tc.name: BitmapGetWidthTest002
136  * @tc.desc:
137  * @tc.type: FUNC
138  * @tc.require:AR000GGNV3
139  * @tc.author:
140  */
141 HWTEST_F(BitmapTest, BitmapGetWidthTest002, TestSize.Level1)
142 {
143     // The best way to get width.
144     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
145     ASSERT_TRUE(bitmap != nullptr);
146     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
147     bitmap->Build(151, 150, bitmapFormat);
148     ASSERT_EQ(151, bitmap->GetWidth());
149 }
150 
151 /**
152  * @tc.name: BitmapGetHeightTest001
153  * @tc.desc:
154  * @tc.type: FUNC
155  * @tc.require:AR000GGNV3
156  * @tc.author:
157  */
158 HWTEST_F(BitmapTest, BitmapGetHeightTest001, TestSize.Level1)
159 {
160     // The best way to get height.
161     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
162     ASSERT_TRUE(bitmap != nullptr);
163     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
164     bitmap->Build(111, 450, bitmapFormat);
165     ASSERT_EQ(450, bitmap->GetHeight());
166 }
167 
168 /**
169  * @tc.name: BitmapGetHeightTest002
170  * @tc.desc:
171  * @tc.type: FUNC
172  * @tc.require:AR000GGNV3
173  * @tc.author:
174  */
175 HWTEST_F(BitmapTest, BitmapGetHeightTest002, TestSize.Level1)
176 {
177     // The best way to get height.
178     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
179     ASSERT_TRUE(bitmap != nullptr);
180     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
181     bitmap->Build(151, 150, bitmapFormat);
182     ASSERT_EQ(150, bitmap->GetHeight());
183 }
184 
185 /**
186  * @tc.name: BitmapSetAndPixelsTest001
187  * @tc.desc:
188  * @tc.type: FUNC
189  * @tc.require:AR000GGNV3
190  * @tc.author:
191  */
192 HWTEST_F(BitmapTest, BitmapSetAndPixelsTest001, TestSize.Level1)
193 {
194     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
195     ASSERT_TRUE(bitmap != nullptr);
196     BitmapFormat* bitmapFormat1 = nullptr;
197     bitmap->SetPixels(bitmapFormat1);
198     EXPECT_EQ(bitmapFormat1, bitmap->GetPixels());
199 }
200 
201 /**
202  * @tc.name: BitmapSetAndPixelsTest002
203  * @tc.desc:
204  * @tc.type: FUNC
205  * @tc.require:AR000GGNV3
206  * @tc.author:
207  */
208 HWTEST_F(BitmapTest, BitmapSetAndPixelsTest002, TestSize.Level1)
209 {
210     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
211     ASSERT_TRUE(bitmap != nullptr);
212     BitmapFormat* bitmapFormat2 = nullptr;
213     bitmap->SetPixels(bitmapFormat2);
214     EXPECT_EQ(bitmapFormat2, bitmap->GetPixels());
215 }
216 
217 /**
218  * @tc.name: BitmapCopyPixelsTest001
219  * @tc.desc:
220  * @tc.type: FUNC
221  * @tc.require:AR000GGNV3
222  * @tc.author:
223  */
224 HWTEST_F(BitmapTest, BitmapCopyPixelsTest001, TestSize.Level1)
225 {
226     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
227     ASSERT_TRUE(bitmap != nullptr);
228     Bitmap bitmap1;
229     bitmap->CopyPixels(bitmap1, 100, 105, 201, 845);
230 }
231 
232 /**
233  * @tc.name: BitmapCopyPixelsTest002
234  * @tc.desc:
235  * @tc.type: FUNC
236  * @tc.require:AR000GGNV3
237  * @tc.author:
238  */
239 HWTEST_F(BitmapTest, BitmapCopyPixelsTest002, TestSize.Level1)
240 {
241     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
242     ASSERT_TRUE(bitmap != nullptr);
243     Bitmap bitmap1;
244     bitmap->CopyPixels(bitmap1, 66, 5, 99, 320);
245 }
246 
247 /**
248  * @tc.name: BitmapClearWithColor001
249  * @tc.desc:
250  * @tc.type: FUNC
251  * @tc.require:AR000GGNV3
252  * @tc.author:
253  */
254 HWTEST_F(BitmapTest, BitmapClearWithColor001, TestSize.Level1)
255 {
256     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
257     ASSERT_TRUE(bitmap != nullptr);
258     bitmap->ClearWithColor(COLORTYPE_UNKNOWN);
259 }
260 
261 /**
262  * @tc.name: BitmapClearWithColor002
263  * @tc.desc:
264  * @tc.type: FUNC
265  * @tc.require:AR000GGNV3
266  * @tc.author:
267  */
268 HWTEST_F(BitmapTest, BitmapClearWithColor002, TestSize.Level1)
269 {
270     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
271     ASSERT_TRUE(bitmap != nullptr);
272     bitmap->ClearWithColor(COLORTYPE_ALPHA_8);
273 }
274 
275 /**
276  * @tc.name: BitmapIsValid001
277  * @tc.desc:
278  * @tc.type: FUNC
279  * @tc.require:AR000GGNV3
280  * @tc.author:
281  */
282 HWTEST_F(BitmapTest, BitmapIsValid001, TestSize.Level1)
283 {
284     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
285     ASSERT_TRUE(bitmap != nullptr);
286     ASSERT_TRUE(bitmap->IsValid());
287 }
288 
289 /**
290  * @tc.name: BitmapIsValid002
291  * @tc.desc:
292  * @tc.type: FUNC
293  * @tc.require:AR000GGNV3
294  * @tc.author:
295  */
296 HWTEST_F(BitmapTest, BitmapIsValid002, TestSize.Level1)
297 {
298     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
299     ASSERT_TRUE(bitmap != nullptr);
300     ASSERT_FALSE(!bitmap->IsValid());
301 }
302 
303 /**
304  * @tc.name: BitmapBitmapGetColorTest001
305  * @tc.desc:
306  * @tc.type: FUNC
307  * @tc.require:AR000GGNV3
308  * @tc.author:
309  */
310 HWTEST_F(BitmapTest, BitmapBitmapGetColorTest001, TestSize.Level1)
311 {
312     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
313     ASSERT_TRUE(bitmap != nullptr);
314     ASSERT_EQ(Color::COLOR_TRANSPARENT, bitmap->GetColor(0, 0));
315 }
316 
317 /**
318  * @tc.name: BitmapGetColorTest002
319  * @tc.desc:
320  * @tc.type: FUNC
321  * @tc.require:AR000GGNV3
322  * @tc.author:
323  */
324 HWTEST_F(BitmapTest, BitmapGetColorTest002, TestSize.Level1)
325 {
326     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
327     ASSERT_TRUE(bitmap != nullptr);
328     ASSERT_EQ(Color::COLOR_TRANSPARENT, bitmap->GetColor(1, 2));
329 }
330 
331 /**
332  * @tc.name: BitmapGetFormatTest001
333  * @tc.desc:
334  * @tc.type: FUNC
335  * @tc.require:AR000GGNV3
336  * @tc.author:
337  */
338 HWTEST_F(BitmapTest, BitmapGetFormatTest001, TestSize.Level1)
339 {
340     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
341     ASSERT_TRUE(bitmap != nullptr);
342     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
343     bitmap->Build(111, 450, bitmapFormat);
344     ASSERT_EQ(ColorType::COLORTYPE_ALPHA_8, bitmap->GetFormat().colorType);
345     ASSERT_EQ(AlphaType::ALPHATYPE_OPAQUE, bitmap->GetFormat().alphaType);
346     bitmap->Free();
347 }
348 
349 /**
350  * @tc.name: BitmapGetFormatTest002
351  * @tc.desc:
352  * @tc.type: FUNC
353  * @tc.require:AR000GGNV3
354  * @tc.author:
355  */
356 HWTEST_F(BitmapTest, BitmapGetFormatTest002, TestSize.Level1)
357 {
358     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
359     ASSERT_TRUE(bitmap != nullptr);
360     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
361     bitmap->Build(151, 150, bitmapFormat);
362     ASSERT_EQ(ColorType::COLORTYPE_ALPHA_8, bitmap->GetFormat().colorType);
363     ASSERT_EQ(AlphaType::ALPHATYPE_OPAQUE, bitmap->GetFormat().alphaType);
364     bitmap->Free();
365 }
366 } // namespace Drawing
367 } // namespace Rosen
368 } // namespace OHOS