• 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 
70 /**
71  * @tc.name: BitmapBuildTest002
72  * @tc.desc:
73  * @tc.type: FUNC
74  * @tc.require:AR000GGNV3
75  * @tc.author:
76  */
77 HWTEST_F(BitmapTest, BitmapBuildTest002, TestSize.Level1)
78 {
79     // The best way to Build Bitmap.
80     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
81     ASSERT_TRUE(bitmap != nullptr);
82     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
83     bitmap->Build(150, 99, bitmapFormat);
84 }
85 
86 /**
87  * @tc.name: BitmapBuildTest003
88  * @tc.desc:
89  * @tc.type: FUNC
90  * @tc.require:AR000GGNV3
91  * @tc.author:
92  */
93 HWTEST_F(BitmapTest, BitmapBuildTest003, TestSize.Level1)
94 {
95     // The best way to Build Bitmap.
96     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
97     ASSERT_TRUE(bitmap != nullptr);
98     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
99     bitmap->Build(111, 450, bitmapFormat);
100 }
101 
102 /**
103  * @tc.name: BitmapGetWidthTest001
104  * @tc.desc:
105  * @tc.type: FUNC
106  * @tc.require:AR000GGNV3
107  * @tc.author:
108  */
109 HWTEST_F(BitmapTest, BitmapGetWidthTest001, TestSize.Level1)
110 {
111     // The best way to get width.
112     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
113     ASSERT_TRUE(bitmap != nullptr);
114     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
115     bitmap->Build(111, 450, bitmapFormat);
116     ASSERT_EQ(111, bitmap->GetWidth());
117 }
118 
119 /**
120  * @tc.name: BitmapGetWidthTest002
121  * @tc.desc:
122  * @tc.type: FUNC
123  * @tc.require:AR000GGNV3
124  * @tc.author:
125  */
126 HWTEST_F(BitmapTest, BitmapGetWidthTest002, TestSize.Level1)
127 {
128     // The best way to get width.
129     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
130     ASSERT_TRUE(bitmap != nullptr);
131     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
132     bitmap->Build(151, 150, bitmapFormat);
133     ASSERT_EQ(151, bitmap->GetWidth());
134 }
135 
136 /**
137  * @tc.name: BitmapGetHeightTest001
138  * @tc.desc:
139  * @tc.type: FUNC
140  * @tc.require:AR000GGNV3
141  * @tc.author:
142  */
143 HWTEST_F(BitmapTest, BitmapGetHeightTest001, TestSize.Level1)
144 {
145     // The best way to get height.
146     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
147     ASSERT_TRUE(bitmap != nullptr);
148     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
149     bitmap->Build(111, 450, bitmapFormat);
150     ASSERT_EQ(450, bitmap->GetHeight());
151 }
152 
153 /**
154  * @tc.name: BitmapGetHeightTest002
155  * @tc.desc:
156  * @tc.type: FUNC
157  * @tc.require:AR000GGNV3
158  * @tc.author:
159  */
160 HWTEST_F(BitmapTest, BitmapGetHeightTest002, TestSize.Level1)
161 {
162     // The best way to get height.
163     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
164     ASSERT_TRUE(bitmap != nullptr);
165     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
166     bitmap->Build(151, 150, bitmapFormat);
167     ASSERT_EQ(150, bitmap->GetHeight());
168 }
169 
170 /**
171  * @tc.name: BitmapSetAndPixelsTest001
172  * @tc.desc:
173  * @tc.type: FUNC
174  * @tc.require:AR000GGNV3
175  * @tc.author:
176  */
177 HWTEST_F(BitmapTest, BitmapSetAndPixelsTest001, TestSize.Level1)
178 {
179     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
180     ASSERT_TRUE(bitmap != nullptr);
181     BitmapFormat* bitmapFormat1 = nullptr;
182     bitmap->SetPixels(bitmapFormat1);
183     EXPECT_EQ(bitmapFormat1, bitmap->GetPixels());
184 }
185 
186 /**
187  * @tc.name: BitmapSetAndPixelsTest002
188  * @tc.desc:
189  * @tc.type: FUNC
190  * @tc.require:AR000GGNV3
191  * @tc.author:
192  */
193 HWTEST_F(BitmapTest, BitmapSetAndPixelsTest002, TestSize.Level1)
194 {
195     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
196     ASSERT_TRUE(bitmap != nullptr);
197     BitmapFormat* bitmapFormat2 = nullptr;
198     bitmap->SetPixels(bitmapFormat2);
199     EXPECT_EQ(bitmapFormat2, bitmap->GetPixels());
200 }
201 
202 /**
203  * @tc.name: BitmapCopyPixelsTest001
204  * @tc.desc:
205  * @tc.type: FUNC
206  * @tc.require:AR000GGNV3
207  * @tc.author:
208  */
209 HWTEST_F(BitmapTest, BitmapCopyPixelsTest001, TestSize.Level1)
210 {
211     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
212     ASSERT_TRUE(bitmap != nullptr);
213     Bitmap bitmap1;
214     bitmap->CopyPixels(bitmap1, 100, 105, 201, 845);
215 }
216 
217 /**
218  * @tc.name: BitmapCopyPixelsTest002
219  * @tc.desc:
220  * @tc.type: FUNC
221  * @tc.require:AR000GGNV3
222  * @tc.author:
223  */
224 HWTEST_F(BitmapTest, BitmapCopyPixelsTest002, 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, 66, 5, 99, 320);
230 }
231 
232 /**
233  * @tc.name: BitmapClearWithColor001
234  * @tc.desc:
235  * @tc.type: FUNC
236  * @tc.require:AR000GGNV3
237  * @tc.author:
238  */
239 HWTEST_F(BitmapTest, BitmapClearWithColor001, TestSize.Level1)
240 {
241     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
242     ASSERT_TRUE(bitmap != nullptr);
243     bitmap->ClearWithColor(COLORTYPE_UNKNOWN);
244 }
245 
246 /**
247  * @tc.name: BitmapClearWithColor002
248  * @tc.desc:
249  * @tc.type: FUNC
250  * @tc.require:AR000GGNV3
251  * @tc.author:
252  */
253 HWTEST_F(BitmapTest, BitmapClearWithColor002, TestSize.Level1)
254 {
255     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
256     ASSERT_TRUE(bitmap != nullptr);
257     bitmap->ClearWithColor(COLORTYPE_ALPHA_8);
258 }
259 
260 /**
261  * @tc.name: BitmapIsValid001
262  * @tc.desc:
263  * @tc.type: FUNC
264  * @tc.require:AR000GGNV3
265  * @tc.author:
266  */
267 HWTEST_F(BitmapTest, BitmapIsValid001, TestSize.Level1)
268 {
269     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
270     ASSERT_TRUE(bitmap != nullptr);
271     ASSERT_TRUE(bitmap->IsValid());
272 }
273 
274 /**
275  * @tc.name: BitmapIsValid002
276  * @tc.desc:
277  * @tc.type: FUNC
278  * @tc.require:AR000GGNV3
279  * @tc.author:
280  */
281 HWTEST_F(BitmapTest, BitmapIsValid002, TestSize.Level1)
282 {
283     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
284     ASSERT_TRUE(bitmap != nullptr);
285     ASSERT_FALSE(!bitmap->IsValid());
286 }
287 
288 /**
289  * @tc.name: BitmapBitmapGetColorTest001
290  * @tc.desc:
291  * @tc.type: FUNC
292  * @tc.require:AR000GGNV3
293  * @tc.author:
294  */
295 HWTEST_F(BitmapTest, BitmapBitmapGetColorTest001, TestSize.Level1)
296 {
297     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
298     ASSERT_TRUE(bitmap != nullptr);
299     ASSERT_EQ(Color::COLOR_TRANSPARENT, bitmap->GetColor(0, 0));
300 }
301 
302 /**
303  * @tc.name: BitmapGetColorTest002
304  * @tc.desc:
305  * @tc.type: FUNC
306  * @tc.require:AR000GGNV3
307  * @tc.author:
308  */
309 HWTEST_F(BitmapTest, BitmapGetColorTest002, TestSize.Level1)
310 {
311     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
312     ASSERT_TRUE(bitmap != nullptr);
313     ASSERT_EQ(Color::COLOR_TRANSPARENT, bitmap->GetColor(1, 2));
314 }
315 
316 /**
317  * @tc.name: BitmapGetFormatTest001
318  * @tc.desc:
319  * @tc.type: FUNC
320  * @tc.require:AR000GGNV3
321  * @tc.author:
322  */
323 HWTEST_F(BitmapTest, BitmapGetFormatTest001, TestSize.Level1)
324 {
325     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
326     ASSERT_TRUE(bitmap != nullptr);
327     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
328     bitmap->Build(111, 450, bitmapFormat);
329     ASSERT_EQ(ColorType::COLORTYPE_UNKNOWN, bitmap->GetFormat().colorType);
330     ASSERT_EQ(AlphaType::ALPHATYPE_UNKNOWN, bitmap->GetFormat().alphaType);
331     bitmap->Free();
332 }
333 
334 /**
335  * @tc.name: BitmapGetFormatTest002
336  * @tc.desc:
337  * @tc.type: FUNC
338  * @tc.require:AR000GGNV3
339  * @tc.author:
340  */
341 HWTEST_F(BitmapTest, BitmapGetFormatTest002, TestSize.Level1)
342 {
343     std::unique_ptr<Bitmap> bitmap = std::make_unique<Bitmap>();
344     ASSERT_TRUE(bitmap != nullptr);
345     BitmapFormat bitmapFormat = { ColorType::COLORTYPE_ALPHA_8, AlphaType::ALPHATYPE_OPAQUE };
346     bitmap->Build(151, 150, bitmapFormat);
347     ASSERT_EQ(ColorType::COLORTYPE_UNKNOWN, bitmap->GetFormat().colorType);
348     ASSERT_EQ(AlphaType::ALPHATYPE_UNKNOWN, bitmap->GetFormat().alphaType);
349     bitmap->Free();
350 }
351 } // namespace Drawing
352 } // namespace Rosen
353 } // namespace OHOS