1 /*
2 * Copyright (c) 2024 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, software
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 <cstddef>
17 #include "gtest/gtest.h"
18 #include "skia_adapter/skia_bitmap.h"
19 #include "image/bitmap.h"
20 #include "draw/surface.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace Rosen {
27 namespace Drawing {
28 class SkiaBitmapTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp() override;
33 void TearDown() override;
34 };
35
SetUpTestCase()36 void SkiaBitmapTest::SetUpTestCase() {}
TearDownTestCase()37 void SkiaBitmapTest::TearDownTestCase() {}
SetUp()38 void SkiaBitmapTest::SetUp() {}
TearDown()39 void SkiaBitmapTest::TearDown() {}
40
41 /**
42 * @tc.name: Build001
43 * @tc.desc: Test Build
44 * @tc.type: FUNC
45 * @tc.require: I91F9L
46 */
47 HWTEST_F(SkiaBitmapTest, Build001, TestSize.Level1)
48 {
49 int width = 100;
50 int height = 50;
51 BitmapFormat bitmapFormat = { ColorType::COLORTYPE_BGRA_8888,
52 AlphaType::ALPHATYPE_PREMUL};
53 SkiaBitmap skiaBitmap;
54 skiaBitmap.Build(width, height, bitmapFormat, 0);
55 }
56
57 /**
58 * @tc.name: Build002
59 * @tc.desc: Test Build
60 * @tc.type: FUNC
61 * @tc.require: I91F9L
62 */
63 HWTEST_F(SkiaBitmapTest, Build002, TestSize.Level1)
64 {
65 int width = 100;
66 int height = 50;
67 ImageInfo offscreenInfo = { width, height, COLORTYPE_RGBA_8888,
68 ALPHATYPE_PREMUL, nullptr};
69 SkiaBitmap skiaBitmap;
70 skiaBitmap.Build(offscreenInfo, 0);
71 }
72
73 /**
74 * @tc.name: GetWidth001
75 * @tc.desc: Test GetWidth
76 * @tc.type: FUNC
77 * @tc.require: I91F9L
78 */
79 HWTEST_F(SkiaBitmapTest, GetWidth001, TestSize.Level1)
80 {
81 SkiaBitmap skiaBitmap;
82 ASSERT_TRUE(skiaBitmap.GetWidth() >= 0);
83 }
84
85 /**
86 * @tc.name: GetHeight001
87 * @tc.desc: Test GetHeight
88 * @tc.type: FUNC
89 * @tc.require: I91F9L
90 */
91 HWTEST_F(SkiaBitmapTest, GetHeight001, TestSize.Level1)
92 {
93 SkiaBitmap skiaBitmap;
94 ASSERT_TRUE(skiaBitmap.GetHeight() >= 0);
95 }
96
97 /**
98 * @tc.name: GetRowBytes001
99 * @tc.desc: Test GetRowBytes
100 * @tc.type: FUNC
101 * @tc.require: I91F9L
102 */
103 HWTEST_F(SkiaBitmapTest, GetRowBytes001, TestSize.Level1)
104 {
105 SkiaBitmap skiaBitmap;
106 ASSERT_TRUE(skiaBitmap.GetRowBytes() >= 0);
107 }
108
109 /**
110 * @tc.name: GetColorType001
111 * @tc.desc: Test GetColorType
112 * @tc.type: FUNC
113 * @tc.require: I91F9L
114 */
115 HWTEST_F(SkiaBitmapTest, GetColorType001, TestSize.Level1)
116 {
117 SkiaBitmap skiaBitmap;
118 skiaBitmap.GetColorType();
119 }
120
121 /**
122 * @tc.name: GetAlphaType001
123 * @tc.desc: Test GetAlphaType
124 * @tc.type: FUNC
125 * @tc.require: I91F9L
126 */
127 HWTEST_F(SkiaBitmapTest, GetAlphaType001, TestSize.Level1)
128 {
129 SkiaBitmap skiaBitmap;
130 skiaBitmap.GetAlphaType();
131 }
132
133 /**
134 * @tc.name: ExtractSubset001
135 * @tc.desc: Test ExtractSubset
136 * @tc.type: FUNC
137 * @tc.require: I91F9L
138 */
139 HWTEST_F(SkiaBitmapTest, ExtractSubset001, TestSize.Level1)
140 {
141 Bitmap left;
142 Rect subset = Rect(0, 0, 50, 50); // 50: right, bottom
143 SkiaBitmap skiaBitmap;
144 ASSERT_TRUE(!skiaBitmap.ExtractSubset(left, subset));
145 }
146
147 /**
148 * @tc.name: GetPixels001
149 * @tc.desc: Test GetPixels
150 * @tc.type: FUNC
151 * @tc.require: I91F9L
152 */
153 HWTEST_F(SkiaBitmapTest, GetPixels001, TestSize.Level1)
154 {
155 SkiaBitmap skiaBitmap;
156 ASSERT_TRUE(skiaBitmap.GetPixels() == nullptr);
157 }
158
159 /**
160 * @tc.name: PeekPixels001
161 * @tc.desc: Test PeekPixels
162 * @tc.type: FUNC
163 * @tc.require: I91F9L
164 */
165 HWTEST_F(SkiaBitmapTest, PeekPixels001, TestSize.Level1)
166 {
167 Pixmap pixmap;
168 SkiaBitmap skiaBitmap;
169 ASSERT_TRUE(!skiaBitmap.PeekPixels(pixmap));
170 }
171
172 /**
173 * @tc.name: ExportSkiaBitmap001
174 * @tc.desc: Test ExportSkiaBitmap
175 * @tc.type: FUNC
176 * @tc.require: I91F9L
177 */
178 HWTEST_F(SkiaBitmapTest, ExportSkiaBitmap001, TestSize.Level1)
179 {
180 SkiaBitmap skiaBitmap;
181 skiaBitmap.ExportSkiaBitmap();
182 }
183
184 /**
185 * @tc.name: IsImmutable001
186 * @tc.desc: Test IsImmutable
187 * @tc.type: FUNC
188 * @tc.require: I91F9L
189 */
190 HWTEST_F(SkiaBitmapTest, IsImmutable001, TestSize.Level1)
191 {
192 SkiaBitmap skiaBitmap;
193 ASSERT_TRUE(!skiaBitmap.IsImmutable());
194 }
195
196 /**
197 * @tc.name: SetImmutable001
198 * @tc.desc: Test SetImmutable
199 * @tc.type: FUNC
200 * @tc.require: I91F9L
201 */
202 HWTEST_F(SkiaBitmapTest, SetImmutable001, TestSize.Level1)
203 {
204 SkiaBitmap skiaBitmap;
205 skiaBitmap.SetImmutable();
206 }
207
208 /**
209 * @tc.name: ClearWithColor001
210 * @tc.desc: Test ClearWithColor
211 * @tc.type: FUNC
212 * @tc.require: I91F9L
213 */
214 HWTEST_F(SkiaBitmapTest, ClearWithColor001, TestSize.Level1)
215 {
216 SkiaBitmap skiaBitmap;
217 skiaBitmap.ClearWithColor(0xFF000000);
218 }
219
220 /**
221 * @tc.name: GetColor001
222 * @tc.desc: Test GetColor
223 * @tc.type: FUNC
224 * @tc.require: I91F9L
225 */
226 HWTEST_F(SkiaBitmapTest, GetColor001, TestSize.Level1)
227 {
228 SkiaBitmap skiaBitmap;
229 skiaBitmap.GetColor(0, 0);
230 }
231
232 /**
233 * @tc.name: Free001
234 * @tc.desc: Test Free
235 * @tc.type: FUNC
236 * @tc.require: I91F9L
237 */
238 HWTEST_F(SkiaBitmapTest, Free001, TestSize.Level1)
239 {
240 SkiaBitmap skiaBitmap;
241 skiaBitmap.Free();
242 }
243
244 /**
245 * @tc.name: IsValid001
246 * @tc.desc: Test IsValid
247 * @tc.type: FUNC
248 * @tc.require: I91F9L
249 */
250 HWTEST_F(SkiaBitmapTest, IsValid001, TestSize.Level1)
251 {
252 SkiaBitmap skiaBitmap;
253 ASSERT_TRUE(skiaBitmap.IsValid());
254 }
255
256 /**
257 * @tc.name: IsEmpty001
258 * @tc.desc: Test IsEmpty
259 * @tc.type: FUNC
260 * @tc.require: I91F9L
261 */
262 HWTEST_F(SkiaBitmapTest, IsEmpty001, TestSize.Level1)
263 {
264 SkiaBitmap skiaBitmap;
265 ASSERT_TRUE(skiaBitmap.IsEmpty());
266 }
267
268 /**
269 * @tc.name: GetPixmap001
270 * @tc.desc: Test GetPixmap
271 * @tc.type: FUNC
272 * @tc.require: I91F9L
273 */
274 HWTEST_F(SkiaBitmapTest, GetPixmap001, TestSize.Level1)
275 {
276 SkiaBitmap skiaBitmap;
277 skiaBitmap.GetPixmap();
278 }
279
280 /**
281 * @tc.name: TryAllocPixels001
282 * @tc.desc: Test TryAllocPixels
283 * @tc.type: FUNC
284 * @tc.require: I91F9L
285 */
286 HWTEST_F(SkiaBitmapTest, TryAllocPixels001, TestSize.Level1)
287 {
288 int width = 100;
289 int height = 50;
290 ImageInfo offscreenInfo = { width, height, COLORTYPE_RGBA_8888,
291 ALPHATYPE_PREMUL, nullptr};
292 SkiaBitmap skiaBitmap;
293 skiaBitmap.TryAllocPixels(offscreenInfo);
294 }
295
296 /**
297 * @tc.name: Serialize001
298 * @tc.desc: Test Serialize
299 * @tc.type: FUNC
300 * @tc.require: I91F9L
301 */
302 HWTEST_F(SkiaBitmapTest, Serialize001, TestSize.Level1)
303 {
304 SkiaBitmap skiaBitmap;
305 skiaBitmap.Serialize();
306 skiaBitmap.Deserialize(nullptr);
307 skiaBitmap.Deserialize(std::make_shared<Data>());
308
309 BitmapFormat bitmapFormat = { ColorType::COLORTYPE_BGRA_8888,
310 AlphaType::ALPHATYPE_PREMUL};
311 skiaBitmap.Build(100, 50, bitmapFormat, 0); // 100:width, 50:height
312 skiaBitmap.ClearWithColor(0xFF000000);
313 skiaBitmap.Serialize();
314 skiaBitmap.Deserialize(std::make_shared<Data>());
315 }
316 } // namespace Drawing
317 } // namespace Rosen
318 } // namespace OHOS