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 <gtest/gtest.h>
17 #include <securec.h>
18 #include "image_source.h"
19 #include "image_type.h"
20 #include "image_utils.h"
21 #include "media_errors.h"
22 #include "pixel_map.h"
23 #include "pixel_astc.h"
24 #include "pixel_convert_adapter.h"
25
26
27 using namespace testing::ext;
28 using namespace OHOS::Media;
29 namespace OHOS {
30 namespace Multimedia {
31
32 constexpr uint8_t ASTC_MAGIC_0 = 0x13; // ASTC MAGIC ID 0x13
33 constexpr uint8_t ASTC_MAGIC_1 = 0xAB; // ASTC MAGIC ID 0xAB
34 constexpr uint8_t ASTC_MAGIC_2 = 0xA1; // ASTC MAGIC ID 0xA1
35 constexpr uint8_t ASTC_MAGIC_3 = 0x5C; // ASTC MAGIC ID 0x5C
36 constexpr uint8_t ASTC_1TH_BYTES = 8;
37 constexpr uint8_t ASTC_2TH_BYTES = 16;
38 constexpr uint8_t MASKBITS_FOR_8BIT = 255;
39 constexpr uint8_t ASTC_PER_BLOCK_BYTES = 16;
40
41 constexpr uint8_t ASTC_BLOCK4X4_FIT_SUT_ASTC_EXAMPLE0[ASTC_PER_BLOCK_BYTES] = {
42 0x43, 0x80, 0xE9, 0xE8, 0xFA, 0xFC, 0x14, 0x17, 0xFF, 0xFF, 0x81, 0x42, 0x12, 0x5A, 0xD4, 0xE9
43 };
44
45 class PixelAstcTest : public testing::Test {
46 public:
PixelAstcTest()47 PixelAstcTest() {}
~PixelAstcTest()48 ~PixelAstcTest() {}
49 };
50
GenAstcHeader(uint8_t * header,size_t blockSize,size_t width,size_t height)51 static bool GenAstcHeader(uint8_t* header, size_t blockSize, size_t width, size_t height)
52 {
53 if (header == nullptr) {
54 return false;
55 }
56 uint8_t* tmp = header;
57 *tmp++ = ASTC_MAGIC_0;
58 *tmp++ = ASTC_MAGIC_1;
59 *tmp++ = ASTC_MAGIC_2;
60 *tmp++ = ASTC_MAGIC_3;
61 *tmp++ = static_cast<uint8_t>(blockSize);
62 *tmp++ = static_cast<uint8_t>(blockSize);
63 // 1 means 3D block size
64 *tmp++ = 1;
65 *tmp++ = width & MASKBITS_FOR_8BIT;
66 *tmp++ = (width >> ASTC_1TH_BYTES) & MASKBITS_FOR_8BIT;
67 *tmp++ = (width >> ASTC_2TH_BYTES) & MASKBITS_FOR_8BIT;
68 *tmp++ = height & MASKBITS_FOR_8BIT;
69 *tmp++ = (height >> ASTC_1TH_BYTES) & MASKBITS_FOR_8BIT;
70 *tmp++ = (height >> ASTC_2TH_BYTES) & MASKBITS_FOR_8BIT;
71 // astc support 3D, for 2D,the 3D size is 1
72 *tmp++ = 1;
73 *tmp++ = 0;
74 *tmp++ = 0;
75 return true;
76 }
77
ConstructAstcBody(uint8_t * astcBody,size_t & blockNums,const uint8_t * astcBlockPart)78 static bool ConstructAstcBody(uint8_t* astcBody, size_t& blockNums, const uint8_t* astcBlockPart)
79 {
80 if (astcBody == nullptr || astcBlockPart == nullptr) {
81 return false;
82 }
83
84 uint8_t* astcBuf = astcBody;
85 for (size_t blockIdx = 0; blockIdx < blockNums; blockIdx++) {
86 if (memcpy_s(astcBuf, ASTC_PER_BLOCK_BYTES, astcBlockPart, ASTC_PER_BLOCK_BYTES) != 0) {
87 return false;
88 }
89 astcBuf += ASTC_PER_BLOCK_BYTES;
90 }
91 return true;
92 }
93
ConstructPixelAstc(std::unique_ptr<PixelMap> & pixelMap,uint8_t ** dataIn)94 static void ConstructPixelAstc(std::unique_ptr<PixelMap>& pixelMap, uint8_t** dataIn)
95 {
96 uint32_t errorCode = 0;
97 SourceOptions opts;
98 size_t width = 256; // ASTC width
99 size_t height = 256; // ASTC height
100 // 4 means ASTC compression format is 4x4
101 size_t blockNum = ((width + 4 - 1) / 4) * ((height + 4 - 1) / 4);
102 // 16 means ASTC per block bytes and header bytes
103 size_t size = blockNum * 16 + 16;
104 uint8_t* data = (uint8_t*)malloc(size);
105
106 // 4 means blockSize
107 if (!GenAstcHeader(data, 4, width, height)) {
108 GTEST_LOG_(INFO) << "GenAstcHeader failed";
109 }
110 // 16 means header bytes
111 if (!ConstructAstcBody(data + 16, blockNum, ASTC_BLOCK4X4_FIT_SUT_ASTC_EXAMPLE0)) {
112 GTEST_LOG_(INFO) << "ConstructAstcBody failed";
113 }
114
115 std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(data, size, opts, errorCode);
116 ASSERT_EQ(errorCode, SUCCESS);
117 ASSERT_NE(imageSource.get(), nullptr);
118
119 DecodeOptions decodeOpts;
120 pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
121 ASSERT_EQ(errorCode, SUCCESS);
122 *dataIn = data;
123 }
124
125 /**
126 * @tc.name: PixelAstcTest001
127 * @tc.desc: PixelAstc scale
128 * @tc.type: FUNC
129 */
130 HWTEST_F(PixelAstcTest, PixelAstcTest001, TestSize.Level3)
131 {
132 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest001 start";
133 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
134 uint8_t* data = nullptr;
135 ConstructPixelAstc(pixelAstc, &data);
136 ASSERT_NE(pixelAstc.get(), nullptr);
137 // 2.0 means scale width value
138 float xAxis = 2.0;
139 // 2.0 means scale height value
140 float yAxis = 2.0;
141 pixelAstc->scale(xAxis, yAxis);
142 TransformData transformData;
143 pixelAstc->GetTransformData(transformData);
144 ASSERT_EQ(transformData.scaleX, 2.0); // 2.0 means scale width value
145 ASSERT_EQ(transformData.scaleY, 2.0); // 2.0 means scale height value
146 if (data != nullptr) {
147 free(data);
148 }
149 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest001 end";
150 }
151
152 /**
153 * @tc.name: PixelAstcTest002
154 * @tc.desc: PixelAstc translate
155 * @tc.type: FUNC
156 */
157 HWTEST_F(PixelAstcTest, PixelAstcTest002, TestSize.Level3)
158 {
159 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest002 start";
160 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
161 uint8_t* data = nullptr;
162 ConstructPixelAstc(pixelAstc, &data);
163 ASSERT_NE(pixelAstc.get(), nullptr);
164 // 2.0 means x_coordinate value
165 float xAxis = 2.0;
166 // 2.0 means y_coordinate value
167 float yAxis = 2.0;
168 pixelAstc->translate(xAxis, yAxis);
169 TransformData transformData;
170 pixelAstc->GetTransformData(transformData);
171 ASSERT_EQ(transformData.translateX, 2.0); // 2.0 means x_coordinate value
172 ASSERT_EQ(transformData.translateY, 2.0); // 2.0 means y_coordinate value
173 if (data != nullptr) {
174 free(data);
175 }
176 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest002 end";
177 }
178
179 /**
180 * @tc.name: PixelAstcTest003
181 * @tc.desc: PixelAstc flip
182 * @tc.type: FUNC
183 */
184 HWTEST_F(PixelAstcTest, PixelAstcTest003, TestSize.Level3)
185 {
186 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest003 start";
187 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
188 uint8_t* data = nullptr;
189 ConstructPixelAstc(pixelAstc, &data);
190 ASSERT_NE(pixelAstc.get(), nullptr);
191 bool xAxis = false;
192 bool yAxis = true;
193 pixelAstc->flip(xAxis, yAxis);
194 TransformData transformData;
195 pixelAstc->GetTransformData(transformData);
196 ASSERT_EQ(transformData.flipX, false);
197 ASSERT_EQ(transformData.flipY, true);
198 if (data != nullptr) {
199 free(data);
200 }
201 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest003 end";
202 }
203
204 /**
205 * @tc.name: PixelAstcTest004
206 * @tc.desc: PixelAstc rotate
207 * @tc.type: FUNC
208 */
209 HWTEST_F(PixelAstcTest, PixelAstcTest004, TestSize.Level3)
210 {
211 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest004 start";
212 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
213 uint8_t* data = nullptr;
214 ConstructPixelAstc(pixelAstc, &data);
215 ASSERT_NE(pixelAstc.get(), nullptr);
216 // 2.0 means rotate angle value
217 float degrees = 2.0;
218 pixelAstc->rotate(degrees);
219 TransformData transformData;
220 pixelAstc->GetTransformData(transformData);
221 ASSERT_EQ(transformData.rotateD, 2.0); // 2.0 means rotate angle value
222 if (data != nullptr) {
223 free(data);
224 }
225 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest004 end";
226 }
227
228 /**
229 * @tc.name: PixelAstcTest005
230 * @tc.desc: PixelAstc crop
231 * @tc.type: FUNC
232 */
233 HWTEST_F(PixelAstcTest, PixelAstcTest005, TestSize.Level3)
234 {
235 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest005 start";
236 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
237 uint8_t* data = nullptr;
238 ConstructPixelAstc(pixelAstc, &data);
239 Rect rect;
240 // -1 means to the left of the distance rect
241 rect.left = -1;
242 rect.top = 1;
243 rect.width = 1;
244 rect.height = 1;
245 uint32_t ret = pixelAstc->crop(rect);
246 EXPECT_EQ(ERR_IMAGE_CROP, ret);
247
248 // -1 means to the top of the distance rect
249 rect.left = 1;
250 rect.top = -1;
251 ret = pixelAstc->crop(rect);
252 EXPECT_EQ(ERR_IMAGE_CROP, ret);
253
254 // -1 means width of the crop part
255 rect.top = 1;
256 rect.width = -1;
257 ret = pixelAstc->crop(rect);
258 EXPECT_EQ(ERR_IMAGE_CROP, ret);
259
260 // -1 means height of the crop part
261 rect.width = 1;
262 rect.height = -1;
263 ret = pixelAstc->crop(rect);
264 EXPECT_EQ(ERR_IMAGE_CROP, ret);
265
266 rect.height = 1;
267 ret = pixelAstc->crop(rect);
268 EXPECT_EQ(SUCCESS, ret);
269 TransformData transformData;
270 pixelAstc->GetTransformData(transformData);
271 ASSERT_EQ(transformData.cropLeft, 1);
272 ASSERT_EQ(transformData.cropTop, 1);
273 ASSERT_EQ(transformData.cropWidth, 1);
274 ASSERT_EQ(transformData.cropHeight, 1);
275 if (data != nullptr) {
276 free(data);
277 }
278 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest005 end";
279 }
280
281 /**
282 * @tc.name: PixelAstcTest006
283 * @tc.desc: PixelAstc SetAlpha
284 * @tc.type: FUNC
285 */
286 HWTEST_F(PixelAstcTest, PixelAstcTest006, TestSize.Level3)
287 {
288 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest006 start";
289 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
290 uint8_t* data = nullptr;
291 ConstructPixelAstc(pixelAstc, &data);
292 // 0.5 means transparency
293 float percent = 0.5;
294 uint32_t ret = pixelAstc->SetAlpha(percent);
295 EXPECT_EQ(ERR_IMAGE_DATA_UNSUPPORT, ret);
296 if (data != nullptr) {
297 free(data);
298 }
299 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest006 end";
300 }
301
302 /**
303 * @tc.name: PixelAstcTest008
304 * @tc.desc: PixelAstc GetARGB32ColorA
305 * @tc.type: FUNC
306 */
307 HWTEST_F(PixelAstcTest, PixelAstcTest008, TestSize.Level3)
308 {
309 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest008 start";
310 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
311 uint8_t* data = nullptr;
312 ConstructPixelAstc(pixelAstc, &data);
313 // 1 means ARGB color value
314 uint32_t color = 1;
315 uint8_t ret = pixelAstc->GetARGB32ColorA(color);
316 EXPECT_EQ(0, ret);
317 if (data != nullptr) {
318 free(data);
319 }
320 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest008 end";
321 }
322
323 /**
324 * @tc.name: PixelAstcTest009
325 * @tc.desc: PixelAstc GetARGB32ColorR
326 * @tc.type: FUNC
327 */
328 HWTEST_F(PixelAstcTest, PixelAstcTest009, TestSize.Level3)
329 {
330 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest009 start";
331 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
332 uint8_t* data = nullptr;
333 ConstructPixelAstc(pixelAstc, &data);
334 // 1 means ARGB color value
335 uint32_t color = 1;
336 uint8_t ret = pixelAstc->GetARGB32ColorR(color);
337 EXPECT_EQ(0, ret);
338 if (data != nullptr) {
339 free(data);
340 }
341 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest009 end";
342 }
343
344
345 /**
346 * @tc.name: PixelAstcTest010
347 * @tc.desc: PixelAstc GetARGB32ColorG
348 * @tc.type: FUNC
349 */
350 HWTEST_F(PixelAstcTest, PixelAstcTest010, TestSize.Level3)
351 {
352 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest010 start";
353 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
354 uint8_t* data = nullptr;
355 ConstructPixelAstc(pixelAstc, &data);
356 // 1 means ARGB color value
357 uint32_t color = 1;
358 uint8_t ret = pixelAstc->GetARGB32ColorG(color);
359 EXPECT_EQ(0, ret);
360 if (data != nullptr) {
361 free(data);
362 }
363 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest010 end";
364 }
365
366 /**
367 * @tc.name: PixelAstcTest011
368 * @tc.desc: PixelAstc GetARGB32ColorB
369 * @tc.type: FUNC
370 */
371 HWTEST_F(PixelAstcTest, PixelAstcTest011, TestSize.Level3)
372 {
373 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest011 start";
374 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
375 uint8_t* data = nullptr;
376 ConstructPixelAstc(pixelAstc, &data);
377 // 1 means ARGB color value
378 uint32_t color = 1;
379 uint8_t ret = pixelAstc->GetARGB32ColorB(color);
380 EXPECT_EQ(0, ret);
381 if (data != nullptr) {
382 free(data);
383 }
384 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest011 end";
385 }
386
387 /**
388 * @tc.name: PixelAstcTest012
389 * @tc.desc: PixelAstc IsSameImage
390 * @tc.type: FUNC
391 */
392 HWTEST_F(PixelAstcTest, PixelAstcTest012, TestSize.Level3)
393 {
394 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest012 start";
395 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
396 uint8_t* data = nullptr;
397 ConstructPixelAstc(pixelAstc, &data);
398 PixelMap pixelmap;
399 bool ret = pixelAstc->IsSameImage(pixelmap);
400 EXPECT_EQ(false, ret);
401 if (data != nullptr) {
402 free(data);
403 }
404 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest012 end";
405 }
406
407 /**
408 * @tc.name: PixelAstcTest013
409 * @tc.desc: PixelAstc IsSameImage
410 * @tc.type: FUNC
411 */
412 HWTEST_F(PixelAstcTest, PixelAstcTest013, TestSize.Level3)
413 {
414 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest013 start";
415 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
416 uint8_t* data = nullptr;
417 ConstructPixelAstc(pixelAstc, &data);
418 PixelMap pixelmap;
419 bool ret = pixelAstc->IsSameImage(pixelmap);
420 EXPECT_EQ(false, ret);
421 if (data != nullptr) {
422 free(data);
423 }
424 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest013 end";
425 }
426
427 /**
428 * @tc.name: PixelAstcTest014
429 * @tc.desc: PixelAstc ReadPixels
430 * @tc.type: FUNC
431 */
432 HWTEST_F(PixelAstcTest, PixelAstcTest014, TestSize.Level3)
433 {
434 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest014 start";
435 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
436 uint8_t* data = nullptr;
437 ConstructPixelAstc(pixelAstc, &data);
438 const uint64_t bufferSize = 0;
439 const uint32_t offset = 0;
440 const uint32_t stride = 0;
441 Rect region;
442 uint8_t dst;
443 uint32_t ret = pixelAstc->ReadPixels(bufferSize, offset, stride, region, &dst);
444 EXPECT_EQ(ERR_IMAGE_INVALID_PARAMETER, ret);
445 if (data != nullptr) {
446 free(data);
447 }
448 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest014 end";
449 }
450
451 /**
452 * @tc.name: PixelAstcTest015
453 * @tc.desc: PixelAstc ReadPixels
454 * @tc.type: FUNC
455 */
456 HWTEST_F(PixelAstcTest, PixelAstcTest015, TestSize.Level3)
457 {
458 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest015 start";
459 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
460 uint8_t* data = nullptr;
461 ConstructPixelAstc(pixelAstc, &data);
462 const uint64_t bufferSize = 0;
463 uint8_t dst;
464 uint32_t ret = pixelAstc->ReadPixels(bufferSize, &dst);
465 EXPECT_EQ(ERR_IMAGE_INVALID_PARAMETER, ret);
466 if (data != nullptr) {
467 free(data);
468 }
469 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest015 end";
470 }
471
472 /**
473 * @tc.name: PixelAstcTest016
474 * @tc.desc: PixelAstc ReadPixels
475 * @tc.type: FUNC
476 */
477 HWTEST_F(PixelAstcTest, PixelAstcTest016, TestSize.Level3)
478 {
479 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest016 start";
480 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
481 uint8_t* data = nullptr;
482 ConstructPixelAstc(pixelAstc, &data);
483 Position pos;
484 uint32_t dst;
485 uint32_t ret = pixelAstc->ReadPixel(pos, dst);
486 EXPECT_EQ(ERR_IMAGE_INVALID_PARAMETER, ret);
487 if (data != nullptr) {
488 free(data);
489 }
490 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest016 end";
491 }
492
493 /**
494 * @tc.name: PixelAstcTest017
495 * @tc.desc: PixelAstc ResetConfig
496 * @tc.type: FUNC
497 */
498 HWTEST_F(PixelAstcTest, PixelAstcTest017, TestSize.Level3)
499 {
500 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest017 start";
501 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
502 uint8_t* data = nullptr;
503 ConstructPixelAstc(pixelAstc, &data);
504 Size size;
505 PixelFormat format = PixelFormat::RGBA_8888;
506 uint32_t ret = pixelAstc->ResetConfig(size, format);
507 EXPECT_EQ(ERR_IMAGE_INVALID_PARAMETER, ret);
508 if (data != nullptr) {
509 free(data);
510 }
511 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest017 end";
512 }
513
514 /**
515 * @tc.name: PixelAstcTest018
516 * @tc.desc: PixelAstc SetAlphaType
517 * @tc.type: FUNC
518 */
519 HWTEST_F(PixelAstcTest, PixelAstcTest018, TestSize.Level3)
520 {
521 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest018 start";
522 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
523 uint8_t* data = nullptr;
524 ConstructPixelAstc(pixelAstc, &data);
525 const AlphaType alphaType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
526 bool ret = pixelAstc->SetAlphaType(alphaType);
527 EXPECT_EQ(false, ret);
528 if (data != nullptr) {
529 free(data);
530 }
531 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest018 end";
532 }
533
534 /**
535 * @tc.name: PixelAstcTest019
536 * @tc.desc: PixelAstc WritePixel
537 * @tc.type: FUNC
538 */
539 HWTEST_F(PixelAstcTest, PixelAstcTest019, TestSize.Level3)
540 {
541 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest019 start";
542 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
543 uint8_t* data = nullptr;
544 ConstructPixelAstc(pixelAstc, &data);
545 Position pos;
546 const uint32_t dst = 0;
547 uint32_t ret = pixelAstc->WritePixel(pos, dst);
548 EXPECT_EQ(ERR_IMAGE_INVALID_PARAMETER, ret);
549 if (data != nullptr) {
550 free(data);
551 }
552 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest019 end";
553 }
554
555 /**
556 * @tc.name: PixelAstcTest020
557 * @tc.desc: PixelAstc WritePixel
558 * @tc.type: FUNC
559 */
560 HWTEST_F(PixelAstcTest, PixelAstcTest020, TestSize.Level3)
561 {
562 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest020 start";
563 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
564 uint8_t* data = nullptr;
565 ConstructPixelAstc(pixelAstc, &data);
566 uint8_t *source = nullptr;
567 const uint64_t bufferSize = 0;
568 const uint32_t offset = 0;
569 const uint32_t stride = 0;
570 Rect region;
571 uint32_t ret = pixelAstc->WritePixels(source, bufferSize, offset, stride, region);
572 EXPECT_EQ(ERR_IMAGE_INVALID_PARAMETER, ret);
573 if (data != nullptr) {
574 free(data);
575 }
576 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest020 end";
577 }
578
579 /**
580 * @tc.name: PixelAstcTest021
581 * @tc.desc: PixelAstc WritePixel
582 * @tc.type: FUNC
583 */
584 HWTEST_F(PixelAstcTest, PixelAstcTest021, TestSize.Level3)
585 {
586 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest021 start";
587 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
588 uint8_t* data = nullptr;
589 ConstructPixelAstc(pixelAstc, &data);
590 const uint32_t color = 0;
591 bool ret = pixelAstc->WritePixels(color);
592 EXPECT_EQ(false, ret);
593 if (data != nullptr) {
594 free(data);
595 }
596 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest021 end";
597 }
598
599 /**
600 * @tc.name: PixelAstcTest022
601 * @tc.desc: PixelAstc WritePixel
602 * @tc.type: FUNC
603 */
604 HWTEST_F(PixelAstcTest, PixelAstcTest022, TestSize.Level3)
605 {
606 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest022 start";
607 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
608 uint8_t* data = nullptr;
609 ConstructPixelAstc(pixelAstc, &data);
610 uint8_t *source = nullptr;
611 const uint64_t bufferSize = 0;
612 uint32_t ret = pixelAstc->WritePixels(source, bufferSize);
613 EXPECT_EQ(ERR_IMAGE_INVALID_PARAMETER, ret);
614 if (data != nullptr) {
615 free(data);
616 }
617 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest022 end";
618 }
619
620 /**
621 * @tc.name: PixelAstcTest023
622 * @tc.desc: PixelAstc SetTransformered
623 * @tc.type: FUNC
624 */
625 HWTEST_F(PixelAstcTest, PixelAstcTest023, TestSize.Level3)
626 {
627 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest023 start";
628 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
629 uint8_t* data = nullptr;
630 ConstructPixelAstc(pixelAstc, &data);
631 bool isTransFormered = false;
632 pixelAstc->SetTransformered(isTransFormered);
633 bool ret = pixelAstc->IsTransformered();
634 EXPECT_EQ(false, ret);
635 if (data != nullptr) {
636 free(data);
637 }
638 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest023 end";
639 }
640
641 /**
642 * @tc.name: PixelAstcTest024
643 * @tc.desc: PixelAstc SetRowStride
644 * @tc.type: FUNC
645 */
646 HWTEST_F(PixelAstcTest, PixelAstcTest024, TestSize.Level3)
647 {
648 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest024 start";
649 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
650 uint8_t* data = nullptr;
651 ConstructPixelAstc(pixelAstc, &data);
652 int32_t ret = pixelAstc->GetRowStride();
653 EXPECT_EQ(0, ret);
654 if (data != nullptr) {
655 free(data);
656 }
657 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest024 end";
658 }
659
660 /**
661 * @tc.name: PixelAstcTest025
662 * @tc.desc: PixelAstc IsSourceAsResponse
663 * @tc.type: FUNC
664 */
665 HWTEST_F(PixelAstcTest, PixelAstcTest025, TestSize.Level3)
666 {
667 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest025 start";
668 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
669 uint8_t* data = nullptr;
670 ConstructPixelAstc(pixelAstc, &data);
671 bool ret = pixelAstc->IsSourceAsResponse();
672 EXPECT_EQ(false, ret);
673 if (data != nullptr) {
674 free(data);
675 }
676 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest025 end";
677 }
678
679 /**
680 * @tc.name: PixelAstcTest026
681 * @tc.desc: PixelAstc GetWritablePixels
682 * @tc.type: FUNC
683 */
684 HWTEST_F(PixelAstcTest, PixelAstcTest026, TestSize.Level3)
685 {
686 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest026 start";
687 std::unique_ptr<PixelMap> pixelAstc = std::unique_ptr<PixelMap>();
688 uint8_t* data = nullptr;
689 ConstructPixelAstc(pixelAstc, &data);
690 EXPECT_EQ(nullptr, pixelAstc->GetWritablePixels());
691 if (data != nullptr) {
692 free(data);
693 }
694 GTEST_LOG_(INFO) << "PixelAstcTest: PixelAstcTest026 end";
695 }
696 }
697 }