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 #define private public
17 #define protected public
18 #include <gtest/gtest.h>
19 #include "ext_pixel_convert.h"
20 #include "ext_wstream.h"
21 #include "ext_decoder.h"
22 #include "plugin_export.h"
23 #include "ext_encoder.h"
24 #include "ext_stream.h"
25 #include "mock_data_stream.h"
26 #include "mock_skw_stream.h"
27 #include "file_source_stream.h"
28 
29 using namespace testing::ext;
30 using namespace OHOS::Media;
31 using namespace OHOS::HDI::Base;
32 using namespace OHOS::MultimediaPlugin;
33 namespace OHOS {
34 namespace ImagePlugin {
35 constexpr int32_t PIXEL_MAP_MAX_RAM_SIZE = 600 * 1024 * 1024;
36 constexpr static int32_t ZERO = 0;
37 constexpr static size_t SIZE_ZERO = 0;
38 constexpr static uint32_t NO_EXIF_TAG = 1;
39 constexpr static uint32_t OFFSET_2 = 2;
40 const static string CODEC_INITED_KEY = "CodecInited";
41 const static string ENCODED_FORMAT_KEY = "EncodedFormat";
42 const static string SUPPORT_SCALE_KEY = "SupportScale";
43 const static string SUPPORT_CROP_KEY = "SupportCrop";
44 const static string EXT_SHAREMEM_NAME = "EXT RawData";
45 class ExtDecoderTest : public testing::Test {
46 public:
ExtDecoderTest()47     ExtDecoderTest() {}
~ExtDecoderTest()48     ~ExtDecoderTest() {}
49 };
50 
51 /**
52  * @tc.name: ResetTest001
53  * @tc.desc: Test of Reset
54  * @tc.type: FUNC
55  */
56 HWTEST_F(ExtDecoderTest, ResetTest001, TestSize.Level3)
57 {
58     GTEST_LOG_(INFO) << "ExtDecoderTest: ResetTest001 start";
59     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
60     EXIFInfo exifInfo_;
61     extDecoder->Reset();
62     ASSERT_EQ(extDecoder->dstSubset_.fLeft, 0);
63     ASSERT_EQ(extDecoder->codec_, nullptr);
64     ASSERT_EQ(extDecoder->info_.isEmpty(), true);
65     GTEST_LOG_(INFO) << "ExtDecoderTest: ResetTest001 end";
66 }
67 
68 /**
69  * @tc.name: CheckCodecTest001
70  * @tc.desc: Test of CheckCodec
71  * @tc.type: FUNC
72  */
73 HWTEST_F(ExtDecoderTest, CheckCodecTest001, TestSize.Level3)
74 {
75     GTEST_LOG_(INFO) << "ExtDecoderTest: CheckCodecTest001 start";
76     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
77     EXIFInfo exifInfo_;
78     extDecoder->codec_ = nullptr;
79     bool ret = extDecoder->CheckCodec();
80     ASSERT_EQ(ret, false);
81     extDecoder->stream_ = new MockInputDataStream;
82     ret = extDecoder->CheckCodec();
83     ASSERT_EQ(ret, false);
84     GTEST_LOG_(INFO) << "ExtDecoderTest: CheckCodecTest001 end";
85 }
86 
87 /**
88  * @tc.name: GetScaledSizeTest001
89  * @tc.desc: Test of GetScaledSize
90  * @tc.type: FUNC
91  */
92 HWTEST_F(ExtDecoderTest, GetScaledSizeTest001, TestSize.Level3)
93 {
94     GTEST_LOG_(INFO) << "ExtDecoderTest: GetScaledSizeTest001 start";
95     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
96     EXIFInfo exifInfo_;
97     int dWidth = 0;
98     int dHeight = 0;
99     float scale = ZERO;
100     extDecoder->codec_ = nullptr;
101     bool ret = extDecoder->GetScaledSize(dWidth, dHeight, scale);
102     ASSERT_EQ(ret, false);
103     GTEST_LOG_(INFO) << "ExtDecoderTest: GetScaledSizeTest001 end";
104 }
105 
106 /**
107  * @tc.name: GetHardwareScaledSizeTest001
108  * @tc.desc: Test of GetHardwareScaledSize
109  * @tc.type: FUNC
110  */
111 HWTEST_F(ExtDecoderTest, GetHardwareScaledSizeTest001, TestSize.Level3)
112 {
113     GTEST_LOG_(INFO) << "ExtDecoderTest: GetHardwareScaledSizeTest001 start";
114     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
115     EXIFInfo exifInfo_;
116     int dWidth = 0;
117     int dHeight = 0;
118     float scale = ZERO;
119     extDecoder->codec_ = nullptr;
120     bool ret = extDecoder->GetHardwareScaledSize(dWidth, dHeight, scale);
121     ASSERT_EQ(ret, false);
122     GTEST_LOG_(INFO) << "ExtDecoderTest: GetHardwareScaledSizeTest001 end";
123 }
124 
125 /**
126  * @tc.name: IsSupportScaleOnDecodeTest001
127  * @tc.desc: Test of IsSupportScaleOnDecode
128  * @tc.type: FUNC
129  */
130 HWTEST_F(ExtDecoderTest, IsSupportScaleOnDecodeTest001, TestSize.Level3)
131 {
132     GTEST_LOG_(INFO) << "ExtDecoderTest: IsSupportScaleOnDecodeTest001 start";
133     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
134     EXIFInfo exifInfo_;
135     extDecoder->codec_ = nullptr;
136     bool ret = extDecoder->IsSupportScaleOnDecode();
137     ASSERT_EQ(ret, false);
138     GTEST_LOG_(INFO) << "ExtDecoderTest: IsSupportScaleOnDecodeTest001 end";
139 }
140 
141 /**
142  * @tc.name: IsSupportCropOnDecodeTest001
143  * @tc.desc: Test of IsSupportCropOnDecode
144  * @tc.type: FUNC
145  */
146 HWTEST_F(ExtDecoderTest, IsSupportCropOnDecodeTest001, TestSize.Level3)
147 {
148     GTEST_LOG_(INFO) << "ExtDecoderTest: IsSupportCropOnDecodeTest001 start";
149     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
150     EXIFInfo exifInfo_;
151     extDecoder->codec_ = nullptr;
152     bool ret = extDecoder->IsSupportCropOnDecode();
153     ASSERT_EQ(ret, false);
154     SkIRect target;
155     ret = extDecoder->IsSupportCropOnDecode(target);
156     ASSERT_EQ(ret, false);
157     GTEST_LOG_(INFO) << "ExtDecoderTest: IsSupportCropOnDecodeTest001 end";
158 }
159 
160 /**
161  * @tc.name: HasPropertyTest001
162  * @tc.desc: Test of HasProperty
163  * @tc.type: FUNC
164  */
165 HWTEST_F(ExtDecoderTest, HasPropertyTest001, TestSize.Level3)
166 {
167     GTEST_LOG_(INFO) << "ExtDecoderTest: HasPropertyTest001 start";
168     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
169     EXIFInfo exifInfo_;
170     extDecoder->codec_ = nullptr;
171     string key = CODEC_INITED_KEY;
172     bool ret = extDecoder->HasProperty(key);
173     ASSERT_EQ(ret, false);
174     key = ENCODED_FORMAT_KEY;
175     ret = extDecoder->HasProperty(key);
176     ASSERT_EQ(ret, true);
177     key = SUPPORT_SCALE_KEY;
178     ret = extDecoder->HasProperty(key);
179     ASSERT_EQ(ret, false);
180     key = SUPPORT_CROP_KEY;
181     ret = extDecoder->HasProperty(key);
182     ASSERT_EQ(ret, false);
183     key = EXT_SHAREMEM_NAME;
184     ret = extDecoder->HasProperty(key);
185     ASSERT_EQ(ret, false);
186     GTEST_LOG_(INFO) << "ExtDecoderTest: HasPropertyTest001 end";
187 }
188 
189 /**
190  * @tc.name: GetImageSizeTest001
191  * @tc.desc: Test of GetImageSize
192  * @tc.type: FUNC
193  */
194 HWTEST_F(ExtDecoderTest, GetImageSizeTest001, TestSize.Level3)
195 {
196     GTEST_LOG_(INFO) << "ExtDecoderTest: GetImageSizeTest001 start";
197     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
198     EXIFInfo exifInfo_;
199     extDecoder->codec_ = nullptr;
200     uint32_t index = 0;
201     Size size;
202     uint32_t ret = extDecoder->GetImageSize(index, size);
203     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
204     extDecoder->frameCount_ = 2;
205     index = 1;
206     ret = extDecoder->GetImageSize(index, size);
207     ASSERT_EQ(ret, ERR_IMAGE_DECODE_HEAD_ABNORMAL);
208     GTEST_LOG_(INFO) << "ExtDecoderTest: GetImageSizeTest001 end";
209 }
210 
211 /**
212  * @tc.name: CheckDecodeOptionsTest001
213  * @tc.desc: Test of CheckDecodeOptions IsValidCrop
214  * @tc.type: FUNC
215  */
216 HWTEST_F(ExtDecoderTest, CheckDecodeOptionsTest001, TestSize.Level3)
217 {
218     GTEST_LOG_(INFO) << "ExtDecoderTest: CheckDecodeOptionsTest001 start";
219     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
220     EXIFInfo exifInfo_;
221     uint32_t index = 0;
222     PixelDecodeOptions opts;
223     uint32_t ret = extDecoder->CheckDecodeOptions(index, opts);
224     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
225 
226     extDecoder->dstInfo_.fDimensions = {1, 1};
227     extDecoder->dstInfo_.fColorInfo.fColorType = SkColorType::kAlpha_8_SkColorType;
228     opts.CropRect.left = -1;
229     opts.CropRect.top = -1;
230     ret = extDecoder->CheckDecodeOptions(index, opts);
231     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
232 
233     opts.CropRect.left = 0;
234     opts.CropRect.top = 0;
235     opts.CropRect.width = 1;
236     opts.CropRect.height = 1;
237     extDecoder->info_.fDimensions = {0, 0};
238     ret = extDecoder->CheckDecodeOptions(index, opts);
239     ASSERT_EQ(ret, SUCCESS);
240     GTEST_LOG_(INFO) << "ExtDecoderTest: CheckDecodeOptionsTest001 end";
241 }
242 
243 /**
244  * @tc.name: SetDecodeOptionsTest001
245  * @tc.desc: Test of SetDecodeOptions
246  * @tc.type: FUNC
247  */
248 HWTEST_F(ExtDecoderTest, SetDecodeOptionsTest001, TestSize.Level3)
249 {
250     GTEST_LOG_(INFO) << "ExtDecoderTest: SetDecodeOptionsTest001 start";
251     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
252     EXIFInfo exifInfo_;
253     uint32_t index = ZERO;
254     PixelDecodeOptions opts;
255     PlImageInfo info;
256     extDecoder->codec_ = nullptr;
257     uint32_t ret = extDecoder->SetDecodeOptions(index, opts, info);
258     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
259     extDecoder->frameCount_ = 1;
260     opts.sampleSize = OFFSET_2;
261     ret = extDecoder->SetDecodeOptions(index, opts, info);
262     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
263     GTEST_LOG_(INFO) << "ExtDecoderTest: SetDecodeOptionsTest001 end";
264 }
265 
266 /**
267  * @tc.name: SetContextPixelsBufferTest001
268  * @tc.desc: Test of SetContextPixelsBuffer ShareMemAlloc DmaMemAlloc
269  * @tc.type: FUNC
270  */
271 HWTEST_F(ExtDecoderTest, SetContextPixelsBufferTest001, TestSize.Level3)
272 {
273     GTEST_LOG_(INFO) << "ExtDecoderTest: SetContextPixelsBufferTest001 start";
274     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
275     EXIFInfo exifInfo_;
276     uint64_t byteCount = ZERO;
277     DecodeContext context;
278     uint32_t ret = extDecoder->SetContextPixelsBuffer(byteCount, context);
279     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
280     byteCount = 128;
281     ret = extDecoder->SetContextPixelsBuffer(byteCount, context);
282     ASSERT_EQ(ret, SUCCESS);
283     context.allocatorType = Media::AllocatorType::DMA_ALLOC;
284     ret = extDecoder->SetContextPixelsBuffer(byteCount, context);
285     ASSERT_EQ(ret, ERR_DMA_NOT_EXIST);
286     context.allocatorType = Media::AllocatorType::CUSTOM_ALLOC;
287     byteCount = PIXEL_MAP_MAX_RAM_SIZE + 1;
288     ret = extDecoder->SetContextPixelsBuffer(byteCount, context);
289     ASSERT_EQ(ret, ERR_IMAGE_DATA_ABNORMAL);
290     byteCount = 128;
291     ret = extDecoder->SetContextPixelsBuffer(byteCount, context);
292     ASSERT_EQ(ret, SUCCESS);
293     GTEST_LOG_(INFO) << "ExtDecoderTest: SetContextPixelsBufferTest001 end";
294 }
295 
296 /**
297  * @tc.name: PreDecodeCheckTest001
298  * @tc.desc: Test of PreDecodeCheck
299  * @tc.type: FUNC
300  */
301 HWTEST_F(ExtDecoderTest, PreDecodeCheckTest001, TestSize.Level3)
302 {
303     GTEST_LOG_(INFO) << "ExtDecoderTest: PreDecodeCheckTest001 start";
304     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
305     EXIFInfo exifInfo_;
306     uint32_t index = 0;
307     extDecoder->codec_ = nullptr;
308     uint32_t ret = extDecoder->PreDecodeCheck(index);
309     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
310     GTEST_LOG_(INFO) << "ExtDecoderTest: PreDecodeCheckTest001 end";
311 }
312 
313 /**
314  * @tc.name: DecodeTest001
315  * @tc.desc: Test of Decode
316  * @tc.type: FUNC
317  */
318 HWTEST_F(ExtDecoderTest, DecodeTest001, TestSize.Level3)
319 {
320     GTEST_LOG_(INFO) << "ExtDecoderTest: DecodeTest001 start";
321     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
322     EXIFInfo exifInfo_;
323     uint32_t index = 0;
324     DecodeContext context;
325     const int fd = open("/data/local/tmp/image/test_hw1.jpg", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
326     std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd);
327     ASSERT_NE(streamPtr, nullptr);
328     extDecoder->SetSource(*streamPtr);
329     ASSERT_NE(extDecoder->stream_, nullptr);
330     extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_));
331     ASSERT_NE(extDecoder->codec_, nullptr);
332     uint32_t ret = extDecoder->Decode(index, context);
333     ASSERT_EQ(ret, ERR_IMAGE_DECODE_FAILED);
334     GTEST_LOG_(INFO) << "ExtDecoderTest: DecodeTest001 end";
335 }
336 
337 /**
338  * @tc.name: ReportImageTypeTest001
339  * @tc.desc: Test of ReportImageType GetFormatStr
340  * @tc.type: FUNC
341  */
342 HWTEST_F(ExtDecoderTest, ReportImageTypeTest001, TestSize.Level3)
343 {
344     GTEST_LOG_(INFO) << "ExtDecoderTest: ReportImageTypeTest001 start";
345     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
346     EXIFInfo exifInfo_;
347     SkEncodedImageFormat skEncodeFormat = SkEncodedImageFormat::kBMP;
348     extDecoder->ReportImageType(skEncodeFormat);
349     skEncodeFormat = SkEncodedImageFormat::kGIF;
350     extDecoder->ReportImageType(skEncodeFormat);
351     skEncodeFormat = SkEncodedImageFormat::kICO;
352     extDecoder->ReportImageType(skEncodeFormat);
353     skEncodeFormat = SkEncodedImageFormat::kJPEG;
354     extDecoder->ReportImageType(skEncodeFormat);
355     skEncodeFormat = SkEncodedImageFormat::kPNG;
356     extDecoder->ReportImageType(skEncodeFormat);
357     skEncodeFormat = SkEncodedImageFormat::kWBMP;
358     extDecoder->ReportImageType(skEncodeFormat);
359     skEncodeFormat = SkEncodedImageFormat::kWEBP;
360     extDecoder->ReportImageType(skEncodeFormat);
361     skEncodeFormat = SkEncodedImageFormat::kPKM;
362     extDecoder->ReportImageType(skEncodeFormat);
363     skEncodeFormat = SkEncodedImageFormat::kKTX;
364     extDecoder->ReportImageType(skEncodeFormat);
365     skEncodeFormat = SkEncodedImageFormat::kASTC;
366     extDecoder->ReportImageType(skEncodeFormat);
367     skEncodeFormat = SkEncodedImageFormat::kDNG;
368     extDecoder->ReportImageType(skEncodeFormat);
369     skEncodeFormat = SkEncodedImageFormat::kHEIF;
370     extDecoder->ReportImageType(skEncodeFormat);
371     skEncodeFormat = SkEncodedImageFormat::kAVIF;
372     extDecoder->ReportImageType(skEncodeFormat);
373     GTEST_LOG_(INFO) << "ExtDecoderTest: ReportImageTypeTest001 end";
374 }
375 
376 /**
377  * @tc.name: ConvertInfoToAlphaTypeTest001
378  * @tc.desc: Test of ConvertInfoToAlphaType
379  * @tc.type: FUNC
380  */
381 HWTEST_F(ExtDecoderTest, ConvertInfoToAlphaTypeTest001, TestSize.Level3)
382 {
383     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertInfoToAlphaTypeTest001 start";
384     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
385     EXIFInfo exifInfo_;
386     SkAlphaType alphaType;
387     AlphaType outputType;
388     bool ret = extDecoder->ConvertInfoToAlphaType(alphaType, outputType);
389     ASSERT_EQ(extDecoder->info_.isEmpty(), true);
390     ASSERT_EQ(ret, false);
391     extDecoder->info_.fDimensions = {2, 2};
392     ret = extDecoder->ConvertInfoToAlphaType(alphaType, outputType);
393     ASSERT_EQ(extDecoder->info_.isEmpty(), false);
394     ASSERT_EQ(ret, false);
395     extDecoder->info_.fColorInfo.fAlphaType = kPremul_SkAlphaType;
396     ret = extDecoder->ConvertInfoToAlphaType(alphaType, outputType);
397     ASSERT_EQ(ret, true);
398     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertInfoToAlphaTypeTest001 end";
399 }
400 
401 /**
402  * @tc.name: ConvertInfoToColorTypeTest001
403  * @tc.desc: Test of ConvertInfoToColorType
404  * @tc.type: FUNC
405  */
406 HWTEST_F(ExtDecoderTest, ConvertInfoToColorTypeTest001, TestSize.Level3)
407 {
408     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertInfoToColorTypeTest001 start";
409     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
410     EXIFInfo exifInfo_;
411     SkColorType format;
412     PixelFormat outputFormat;
413     bool ret = extDecoder->ConvertInfoToColorType(format, outputFormat);
414     ASSERT_EQ(extDecoder->info_.isEmpty(), true);
415     ASSERT_EQ(ret, false);
416     extDecoder->info_.fDimensions = {2, 2};
417     ret = extDecoder->ConvertInfoToColorType(format, outputFormat);
418     ASSERT_EQ(extDecoder->info_.isEmpty(), false);
419     ASSERT_EQ(ret, false);
420     extDecoder->info_.fColorInfo.fColorType = kRGBA_8888_SkColorType;
421     ret = extDecoder->ConvertInfoToColorType(format, outputFormat);
422     ASSERT_EQ(ret, true);
423     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertInfoToColorTypeTest001 end";
424 }
425 
426 /**
427  * @tc.name: ConvertToAlphaTypeTest001
428  * @tc.desc: Test of ConvertToAlphaType
429  * @tc.type: FUNC
430  */
431 HWTEST_F(ExtDecoderTest, ConvertToAlphaTypeTest001, TestSize.Level3)
432 {
433     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertToAlphaTypeTest001 start";
434     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
435     EXIFInfo exifInfo_;
436     AlphaType desiredType;
437     AlphaType outputType;
438     desiredType = AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
439     auto ret = extDecoder->ConvertToAlphaType(desiredType, outputType);
440     ASSERT_EQ(outputType, AlphaType::IMAGE_ALPHA_TYPE_OPAQUE);
441     ASSERT_EQ(ret, SkAlphaType::kOpaque_SkAlphaType);
442 
443     desiredType = AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
444     ret = extDecoder->ConvertToAlphaType(desiredType, outputType);
445     ASSERT_EQ(outputType, AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
446     ASSERT_EQ(ret, SkAlphaType::kPremul_SkAlphaType);
447 
448     extDecoder->info_.fDimensions = {2, 2};
449     extDecoder->info_.fColorInfo.fAlphaType = kPremul_SkAlphaType;
450     ret = extDecoder->ConvertToAlphaType(desiredType, outputType);
451     ASSERT_EQ(ret, SkAlphaType::kPremul_SkAlphaType);
452     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertToAlphaTypeTest001 end";
453 }
454 
455 /**
456  * @tc.name: ConvertToColorTypeTest001
457  * @tc.desc: Test of ConvertToColorType
458  * @tc.type: FUNC
459  */
460 HWTEST_F(ExtDecoderTest, ConvertToColorTypeTest001, TestSize.Level3)
461 {
462     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertToColorTypeTest001 start";
463     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
464     EXIFInfo exifInfo_;
465     PixelFormat format;
466     PixelFormat outputFormat;
467     format = PixelFormat::RGBA_8888;
468     auto ret = extDecoder->ConvertToColorType(format, outputFormat);
469     ASSERT_EQ(outputFormat, PixelFormat::RGBA_8888);
470     ASSERT_EQ(ret, kRGBA_8888_SkColorType);
471 
472     format = PixelFormat::UNKNOWN;
473     ret = extDecoder->ConvertToColorType(format, outputFormat);
474     ASSERT_EQ(outputFormat, PixelFormat::RGBA_8888);
475     ASSERT_EQ(ret, kRGBA_8888_SkColorType);
476 
477     extDecoder->info_.fDimensions = {2, 2};
478     extDecoder->info_.fColorInfo.fColorType = kRGBA_8888_SkColorType;
479     ret = extDecoder->ConvertToColorType(format, outputFormat);
480     ASSERT_EQ(ret, kRGBA_8888_SkColorType);
481     GTEST_LOG_(INFO) << "ExtDecoderTest: ConvertToColorTypeTest001 end";
482 }
483 
484 /**
485  * @tc.name: GetPropertyCheckTest001
486  * @tc.desc: Test of GetPropertyCheck
487  * @tc.type: FUNC
488  */
489 HWTEST_F(ExtDecoderTest, GetPropertyCheckTest001, TestSize.Level3)
490 {
491     GTEST_LOG_(INFO) << "ExtDecoderTest: GetPropertyCheckTest001 start";
492     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
493     EXIFInfo exifInfo_;
494     uint32_t index = 0;
495     std::string key = ACTUAL_IMAGE_ENCODED_FORMAT;
496     uint32_t res = 0;
497     bool ret = extDecoder->GetPropertyCheck(index, key, res);
498     ASSERT_EQ(res, Media::ERR_MEDIA_VALUE_INVALID);
499     ASSERT_EQ(ret, false);
500     key = "format";
501     extDecoder->codec_ = nullptr;
502     ret = extDecoder->GetPropertyCheck(index, key, res);
503     ASSERT_EQ(res, Media::ERR_IMAGE_DECODE_HEAD_ABNORMAL);
504     ASSERT_EQ(ret, false);
505     GTEST_LOG_(INFO) << "ExtDecoderTest: GetPropertyCheckTest001 end";
506 }
507 
508 /**
509  * @tc.name: GetImagePropertyIntTest001
510  * @tc.desc: Test of GetImagePropertyInt
511  * @tc.type: FUNC
512  */
513 HWTEST_F(ExtDecoderTest, GetImagePropertyIntTest001, TestSize.Level3)
514 {
515     GTEST_LOG_(INFO) << "ExtDecoderTest: GetImagePropertyIntTest001 start";
516     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
517     EXIFInfo exifInfo_;
518     uint32_t index = 0;
519     std::string key = ACTUAL_IMAGE_ENCODED_FORMAT;
520     int32_t value = 0;
521     uint32_t ret = extDecoder->GetImagePropertyInt(index, key, value);
522     ASSERT_EQ(ret, Media::ERR_MEDIA_VALUE_INVALID);
523     GTEST_LOG_(INFO) << "ExtDecoderTest: GetImagePropertyIntTest001 end";
524 }
525 
526 /**
527  * @tc.name: GetMakerImagePropertyStringTest001
528  * @tc.desc: Test of GetMakerImagePropertyString
529  * @tc.type: FUNC
530  */
531 HWTEST_F(ExtDecoderTest, GetMakerImagePropertyStringTest001, TestSize.Level3)
532 {
533     GTEST_LOG_(INFO) << "ExtDecoderTest: GetMakerImagePropertyStringTest001 start";
534     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
535     EXIFInfo exifInfo_;
536     std::string key = "string";
537     std::string value = "propretyString";
538     uint32_t ret = extDecoder->GetMakerImagePropertyString(key, value);
539     ASSERT_EQ(ret, Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT);
540     extDecoder->exifInfo_.makerInfoTagValueMap.insert(pair<std::string, std::string>
541         ("getMaker", "getMakerImagePropertyString"));
542     key = "getMaker";
543     ret = extDecoder->GetMakerImagePropertyString(key, value);
544     ASSERT_EQ(value, "getMakerImagePropertyString");
545     ASSERT_EQ(ret, SUCCESS);
546     GTEST_LOG_(INFO) << "ExtDecoderTest: GetMakerImagePropertyStringTest001 end";
547 }
548 
549 /**
550  * @tc.name: ModifyImagePropertyTest001
551  * @tc.desc: Test of ModifyImageProperty
552  * @tc.type: FUNC
553  */
554 HWTEST_F(ExtDecoderTest, ModifyImagePropertyTest001, TestSize.Level3)
555 {
556     GTEST_LOG_(INFO) << "ExtDecoderTest: ModifyImagePropertyTest001 start";
557     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
558     EXIFInfo exifInfo_;
559     uint32_t index = 0;
560     std::string key = "Path";
561     std::string value = "void";
562     std::string path = "void";
563     uint32_t ret = extDecoder->ModifyImageProperty(index, key, value, path);
564     ASSERT_EQ(ret, Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT);
565     int fd = 0;
566     ret = extDecoder->ModifyImageProperty(index, key, value, fd);
567     ASSERT_EQ(ret, Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT);
568     uint8_t *data = nullptr;
569     uint32_t size = 0;
570     ret = extDecoder->ModifyImageProperty(index, key, value, data, size);
571     ASSERT_EQ(ret, Media::ERR_IMAGE_DECODE_EXIF_UNSUPPORT);
572     GTEST_LOG_(INFO) << "ExtDecoderTest: ModifyImagePropertyTest001 end";
573 }
574 
575 /**
576  * @tc.name: GetFilterAreaTest001
577  * @tc.desc: Test of GetFilterArea
578  * @tc.type: FUNC
579  */
580 HWTEST_F(ExtDecoderTest, GetFilterAreaTest001, TestSize.Level3)
581 {
582     GTEST_LOG_(INFO) << "ExtDecoderTest: GetFilterAreaTest001 start";
583     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
584     EXIFInfo exifInfo_;
585     int privacyType = 0;
586     std::vector<std::pair<uint32_t, uint32_t>> ranges;
587     extDecoder->codec_ = nullptr;
588     uint32_t ret = extDecoder->GetFilterArea(privacyType, ranges);
589     ASSERT_EQ(ret, NO_EXIF_TAG);
590     GTEST_LOG_(INFO) << "ExtDecoderTest: GetFilterAreaTest001 end";
591 }
592 
593 /**
594  * @tc.name: GetTopLevelImageNumTest001
595  * @tc.desc: Test of GetTopLevelImageNum
596  * @tc.type: FUNC
597  */
598 HWTEST_F(ExtDecoderTest, GetTopLevelImageNumTest001, TestSize.Level3)
599 {
600     GTEST_LOG_(INFO) << "ExtDecoderTest: GetTopLevelImageNumTest001 start";
601     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
602     EXIFInfo exifInfo_;
603     uint32_t num = 0;
604     extDecoder->codec_ = nullptr;
605     uint32_t ret = extDecoder->GetTopLevelImageNum(num);
606     ASSERT_EQ(ret, ERR_IMAGE_DECODE_HEAD_ABNORMAL);
607     extDecoder->frameCount_ = 1;
608     ret = extDecoder->GetTopLevelImageNum(num);
609     ASSERT_EQ(num, extDecoder->frameCount_);
610     ASSERT_EQ(ret, SUCCESS);
611     GTEST_LOG_(INFO) << "ExtDecoderTest: GetTopLevelImageNumTest001 end";
612 }
613 
614 /**
615  * @tc.name: IsSupportHardwareDecodeTest001
616  * @tc.desc: Test of IsSupportHardwareDecode
617  * @tc.type: FUNC
618  */
619 HWTEST_F(ExtDecoderTest, IsSupportHardwareDecodeTest001, TestSize.Level3)
620 {
621     GTEST_LOG_(INFO) << "ExtDecoderTest: IsSupportHardwareDecodeTest001 start";
622     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
623     EXIFInfo exifInfo_;
624     extDecoder->codec_ = nullptr;
625     bool ret = extDecoder->IsSupportHardwareDecode();
626     ASSERT_EQ(extDecoder->info_.isEmpty(), true);
627     ASSERT_EQ(ret, false);
628 
629     const int fd = open("/data/local/tmp/image/test_hw1.jpg", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
630     std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd);
631     ASSERT_NE(streamPtr, nullptr);
632     extDecoder->SetSource(*streamPtr);
633     ASSERT_NE(extDecoder->stream_, nullptr);
634     extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_));
635     ASSERT_NE(extDecoder->codec_, nullptr);
636     extDecoder->info_.fDimensions = {2, 2};
637     ret = extDecoder->IsSupportHardwareDecode();
638     ASSERT_EQ(extDecoder->info_.isEmpty(), false);
639     ASSERT_EQ(ret, false);
640     GTEST_LOG_(INFO) << "ExtDecoderTest: IsSupportHardwareDecodeTest001 end";
641 }
642 
643 /**
644  * @tc.name: RGBxToRGBTest001
645  * @tc.desc: Test of RGBxToRGB
646  * @tc.type: FUNC
647  */
648 HWTEST_F(ExtDecoderTest, RGBxToRGBTest001, TestSize.Level3)
649 {
650     GTEST_LOG_(INFO) << "ExtDecoderTest: RGBxToRGBTest001 start";
651     ExtPixels src;
652     ExtPixels dst;
653     src.data = new uint8_t;
654     dst.data = new uint8_t;
655     src.byteCount = 5;
656     uint32_t ret = ExtPixelConvert::RGBxToRGB(src, dst);
657     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
658     src.byteCount = 4;
659     dst.byteCount = 2;
660     ret = ExtPixelConvert::RGBxToRGB(src, dst);
661     ASSERT_EQ(ret, ERR_IMAGE_TOO_LARGE);
662     dst.byteCount = 4;
663     ret = ExtPixelConvert::RGBxToRGB(src, dst);
664     ASSERT_EQ(ret, SUCCESS);
665     delete src.data;
666     delete dst.data;
667     GTEST_LOG_(INFO) << "ExtDecoderTest: RGBxToRGBTest001 end";
668 }
669 
670 /**
671  * @tc.name: RGBToRGBxTest001
672  * @tc.desc: Test of RGBToRGBx
673  * @tc.type: FUNC
674  */
675 HWTEST_F(ExtDecoderTest, RGBToRGBxTest001, TestSize.Level3)
676 {
677     GTEST_LOG_(INFO) << "ExtDecoderTest: RGBToRGBxTest001 start";
678     ExtPixels src;
679     ExtPixels dst;
680     src.data = new uint8_t;
681     dst.data = new uint8_t;
682     src.byteCount = 4;
683     uint32_t ret = ExtPixelConvert::RGBToRGBx(src, dst);
684     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
685     src.byteCount = 3;
686     dst.byteCount = 3;
687     ret = ExtPixelConvert::RGBToRGBx(src, dst);
688     ASSERT_EQ(ret, ERR_IMAGE_TOO_LARGE);
689     dst.byteCount = 5;
690     ret = ExtPixelConvert::RGBToRGBx(src, dst);
691     ASSERT_EQ(ret, SUCCESS);
692     delete src.data;
693     delete dst.data;
694     GTEST_LOG_(INFO) << "ExtDecoderTest: RGBToRGBxTest001 end";
695 }
696 
697 /**
698  * @tc.name: writeTest001
699  * @tc.desc: Test of write
700  * @tc.type: FUNC
701  */
702 HWTEST_F(ExtDecoderTest, writeTest001, TestSize.Level3)
703 {
704     GTEST_LOG_(INFO) << "ExtDecoderTest: writeTest001 start";
705     ExtWStream extWStream;
706     std::string str = "write";
707     void* buffer = &str;
708     size_t size = 128;
709     extWStream.stream_ = nullptr;
710     bool ret = extWStream.write(buffer, size);
711     ASSERT_EQ(extWStream.stream_, nullptr);
712     ASSERT_EQ(ret, false);
713     extWStream.stream_ = new MockOutputDataStream;
714     ret = extWStream.write(buffer, size);
715     ASSERT_NE(extWStream.stream_, nullptr);
716     ASSERT_EQ(ret, false);
717     delete extWStream.stream_;
718     GTEST_LOG_(INFO) << "ExtDecoderTest: writeTest001 end";
719 }
720 
721 /**
722  * @tc.name: flushTest001
723  * @tc.desc: Test of flush
724  * @tc.type: FUNC
725  */
726 HWTEST_F(ExtDecoderTest, flushTest001, TestSize.Level3)
727 {
728     GTEST_LOG_(INFO) << "ExtDecoderTest: flushTest001 start";
729     ExtWStream extWStream;
730     extWStream.stream_ = nullptr;
731     extWStream.flush();
732     ASSERT_EQ(extWStream.stream_, nullptr);
733     extWStream.stream_ = new MockOutputDataStream;
734     extWStream.flush();
735     ASSERT_NE(extWStream.stream_, nullptr);
736     delete extWStream.stream_;
737     GTEST_LOG_(INFO) << "ExtDecoderTest: flushTest001 end";
738 }
739 
740 /**
741  * @tc.name: bytesWrittenTest001
742  * @tc.desc: Test of bytesWritten
743  * @tc.type: FUNC
744  */
745 HWTEST_F(ExtDecoderTest, bytesWrittenTest001, TestSize.Level3)
746 {
747     GTEST_LOG_(INFO) << "ExtDecoderTest: bytesWrittenTest001 start";
748     ExtWStream extWStream;
749     extWStream.stream_ = nullptr;
750     size_t ret = extWStream.bytesWritten();
751     ASSERT_EQ(extWStream.stream_, nullptr);
752     ASSERT_EQ(ret, SIZE_ZERO);
753     extWStream.stream_ = new MockOutputDataStream;
754     ret = extWStream.bytesWritten();
755     ASSERT_NE(extWStream.stream_, nullptr);
756     ASSERT_EQ(ret, SIZE_ZERO);
757     delete extWStream.stream_;
758     GTEST_LOG_(INFO) << "ExtDecoderTest: bytesWrittenTest001 end";
759 }
760 
761 /**
762  * @tc.name: PluginExternalCreateTest001
763  * @tc.desc: Test of PluginExternalCreate
764  * @tc.type: FUNC
765  */
766 HWTEST_F(ExtDecoderTest, PluginExternalCreateTest001, TestSize.Level3)
767 {
768     GTEST_LOG_(INFO) << "ExtDecoderTest: PluginExternalCreateTest001 start";
769     string className = "ClassName";
770     auto ret = PluginExternalCreate(className);
771     ASSERT_EQ(ret, nullptr);
772     GTEST_LOG_(INFO) << "ExtDecoderTest: PluginExternalCreateTest001 end";
773 }
774 
775 /**
776  * @tc.name: FinalizeEncodeTest001
777  * @tc.desc: Test of FinalizeEncode
778  * @tc.type: FUNC
779  */
780 HWTEST_F(ExtDecoderTest, FinalizeEncodeTest001, TestSize.Level3)
781 {
782     GTEST_LOG_(INFO) << "ExtDecoderTest: FinalizeEncodeTest001 start";
783     ExtEncoder extEncoder;
784     uint32_t ret = extEncoder.FinalizeEncode();
785     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
786     extEncoder.pixelmap_ = new PixelMap;
787     extEncoder.output_ = new MockOutputDataStream;
788     extEncoder.opts_.format = "image/";
789     ret = extEncoder.FinalizeEncode();
790     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
791     extEncoder.opts_.format = "image/jpeg";
792     ret = extEncoder.FinalizeEncode();
793     ASSERT_EQ(ret, ERR_IMAGE_ENCODE_FAILED);
794     GTEST_LOG_(INFO) << "ExtDecoderTest: FinalizeEncodeTest001 end";
795 }
796 
797 /**
798  * @tc.name: readTest001
799  * @tc.desc: Test of read
800  * @tc.type: FUNC
801  */
802 HWTEST_F(ExtDecoderTest, readTest001, TestSize.Level3)
803 {
804     GTEST_LOG_(INFO) << "ExtDecoderTest: readTest001 start";
805     ExtStream extStream;
806     void *buffer = nullptr;
807     size_t size = 0;
808     extStream.stream_ = nullptr;
809     size_t ret = extStream.read(buffer, size);
810     ASSERT_EQ(ret, SIZE_ZERO);
811     extStream.stream_ = new MockInputDataStream;
812     ret = extStream.read(buffer, size);
813     ASSERT_NE(extStream.stream_, nullptr);
814     ASSERT_EQ(ret, SIZE_ZERO);
815     GTEST_LOG_(INFO) << "ExtDecoderTest: readTest001 end";
816 }
817 
818 /**
819  * @tc.name: CheckCodecTest002
820  * @tc.desc: Test of CheckCodec
821  * @tc.type: FUNC
822  */
823 HWTEST_F(ExtDecoderTest, CheckCodecTest002, TestSize.Level3)
824 {
825     GTEST_LOG_(INFO) << "ExtDecoderTest: CheckCodecTest002 start";
826     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
827     EXIFInfo exifInfo_;
828     const int fd = open("/data/local/tmp/image/test_hw1.jpg", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
829     std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd);
830     ASSERT_NE(streamPtr, nullptr);
831     extDecoder->SetSource(*streamPtr);
832     ASSERT_NE(extDecoder->stream_, nullptr);
833     extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_));
834     bool ret = extDecoder->CheckCodec();
835     ASSERT_NE(extDecoder->codec_, nullptr);
836     ASSERT_EQ(ret, true);
837     GTEST_LOG_(INFO) << "ExtDecoderTest: CheckCodecTest002 end";
838 }
839 
840 /**
841  * @tc.name: GetHardwareScaledSizeTest002
842  * @tc.desc: Test of GetHardwareScaledSize
843  * @tc.type: FUNC
844  */
845 HWTEST_F(ExtDecoderTest, GetHardwareScaledSizeTest002, TestSize.Level3)
846 {
847     GTEST_LOG_(INFO) << "ExtDecoderTest: GetHardwareScaledSizeTest002 start";
848     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
849     EXIFInfo exifInfo_;
850     extDecoder->info_.fDimensions = {20, 20};
851     ASSERT_EQ(extDecoder->info_.isEmpty(), false);
852     float scale = ZERO;
853     int dWidth = 2;
854     int dHeight = 1;
855     bool ret = extDecoder->GetHardwareScaledSize(dWidth, dHeight, scale);
856     ASSERT_EQ(ret, true);
857     dWidth = 4;
858     dHeight = 2;
859     ret = extDecoder->GetHardwareScaledSize(dWidth, dHeight, scale);
860     ASSERT_EQ(ret, true);
861     dWidth = 6;
862     dHeight = 3;
863     ret = extDecoder->GetHardwareScaledSize(dWidth, dHeight, scale);
864     ASSERT_EQ(ret, true);
865     dWidth = 20;
866     dHeight = 10;
867     ret = extDecoder->GetHardwareScaledSize(dWidth, dHeight, scale);
868     ASSERT_EQ(ret, true);
869     GTEST_LOG_(INFO) << "ExtDecoderTest: GetHardwareScaledSizeTest002 end";
870 }
871 
872 /**
873  * @tc.name: PreDecodeCheckTest002
874  * @tc.desc: Test of PreDecodeCheck
875  * @tc.type: FUNC
876  */
877 HWTEST_F(ExtDecoderTest, PreDecodeCheckTest002, TestSize.Level3)
878 {
879     GTEST_LOG_(INFO) << "ExtDecoderTest: PreDecodeCheckTest002 start";
880     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
881     EXIFInfo exifInfo_;
882     uint32_t index = 0;
883     extDecoder->codec_ = nullptr;
884     uint32_t ret = extDecoder->PreDecodeCheck(index);
885     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
886 
887     extDecoder->frameCount_ = 1;
888     ret = extDecoder->PreDecodeCheck(index);
889     ASSERT_EQ(extDecoder->codec_, nullptr);
890     ASSERT_EQ(ret, ERR_IMAGE_DECODE_FAILED);
891 
892     const int fd = open("/data/local/tmp/image/test_hw1.jpg", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
893     std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd);
894     ASSERT_NE(streamPtr, nullptr);
895     extDecoder->SetSource(*streamPtr);
896     ASSERT_NE(extDecoder->stream_, nullptr);
897     extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_));
898     ASSERT_NE(extDecoder->codec_, nullptr);
899     ret = extDecoder->PreDecodeCheck(index);
900     ASSERT_EQ(ret, ERR_IMAGE_DECODE_FAILED);
901 
902     extDecoder->dstInfo_.fDimensions = {1, 1};
903     ret = extDecoder->PreDecodeCheck(index);
904     ASSERT_EQ(extDecoder->dstInfo_.isEmpty(), false);
905     ASSERT_EQ(ret, SUCCESS);
906     GTEST_LOG_(INFO) << "ExtDecoderTest: PreDecodeCheckTest002 end";
907 }
908 
909 /**
910  * @tc.name: PreDecodeCheckYuvTest001
911  * @tc.desc: Test of PreDecodeCheckYuv
912  * @tc.type: FUNC
913  */
914 HWTEST_F(ExtDecoderTest, PreDecodeCheckYuvTest001, TestSize.Level3)
915 {
916     GTEST_LOG_(INFO) << "ExtDecoderTest: PreDecodeCheckYuvTest001 start";
917     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
918     EXIFInfo exifInfo_;
919     extDecoder->codec_ = nullptr;
920     uint32_t index = 0;
921     PixelFormat desiredFormat = PixelFormat::UNKNOWN;
922     uint32_t ret = extDecoder->PreDecodeCheckYuv(index, desiredFormat);
923     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
924 
925     extDecoder->frameCount_ = 1;
926     const int fd = open("/data/local/tmp/image/test_hw1.jpg", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
927     std::unique_ptr<FileSourceStream> streamPtr = FileSourceStream::CreateSourceStream(fd);
928     ASSERT_NE(streamPtr, nullptr);
929     extDecoder->SetSource(*streamPtr);
930     ASSERT_NE(extDecoder->stream_, nullptr);
931     extDecoder->codec_ = SkCodec::MakeFromStream(std::make_unique<ExtStream>(extDecoder->stream_));
932     ASSERT_NE(extDecoder->codec_, nullptr);
933     extDecoder->dstInfo_.fDimensions = {1, 1};
934     ASSERT_EQ(extDecoder->dstInfo_.isEmpty(), false);
935     extDecoder->stream_ = nullptr;
936     ret = extDecoder->PreDecodeCheckYuv(index, desiredFormat);
937     ASSERT_EQ(ret, ERR_IMAGE_SOURCE_DATA);
938 
939     MockInputDataStream inputDataStream;
940     extDecoder->stream_ = &inputDataStream;
941     ret = extDecoder->PreDecodeCheckYuv(index, desiredFormat);
942     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
943 
944     desiredFormat = PixelFormat::NV21;
945     ret = extDecoder->PreDecodeCheckYuv(index, desiredFormat);
946     ASSERT_EQ(ret, ERR_IMAGE_SOURCE_DATA);
947     GTEST_LOG_(INFO) << "ExtDecoderTest: PreDecodeCheckYuvTest001 end";
948 }
949 
950 /**
951  * @tc.name: ReadJpegDataTest001
952  * @tc.desc: Test of ReadJpegData
953  * @tc.type: FUNC
954  */
955 HWTEST_F(ExtDecoderTest, ReadJpegDataTest001, TestSize.Level3)
956 {
957     GTEST_LOG_(INFO) << "ExtDecoderTest: ReadJpegDataTest001 start";
958     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
959     EXIFInfo exifInfo_;
960     uint8_t *jpegBuffer = nullptr;
961     uint32_t jpegBufferSize = 0;
962     extDecoder->stream_ = nullptr;
963     uint32_t ret = extDecoder->ReadJpegData(jpegBuffer, jpegBufferSize);
964     ASSERT_EQ(ret, ERR_IMAGE_SOURCE_DATA);
965 
966     MockInputDataStream inputDataStream;
967     extDecoder->stream_ = &inputDataStream;
968     ret = extDecoder->ReadJpegData(jpegBuffer, jpegBufferSize);
969     ASSERT_EQ(ret, ERR_IMAGE_GET_DATA_ABNORMAL);
970 
971     uint8_t buffer = 16;
972     jpegBuffer = &buffer;
973     jpegBufferSize = 128;
974     ret = extDecoder->ReadJpegData(jpegBuffer, jpegBufferSize);
975     ASSERT_EQ(extDecoder->stream_->Seek(0), false);
976     ASSERT_EQ(ret, ERR_IMAGE_GET_DATA_ABNORMAL);
977 
978     inputDataStream.returnValue_ = true;
979     ASSERT_EQ(extDecoder->stream_->Seek(0), true);
980     ret = extDecoder->ReadJpegData(jpegBuffer, jpegBufferSize);
981     ASSERT_EQ(ret, ERR_IMAGE_SOURCE_DATA);
982     GTEST_LOG_(INFO) << "ExtDecoderTest: ReadJpegDataTest001 end";
983 }
984 
985 /**
986  * @tc.name: GetJpegYuvOutFmtTest001
987  * @tc.desc: Test of GetJpegYuvOutFmt
988  * @tc.type: FUNC
989  */
990 HWTEST_F(ExtDecoderTest, GetJpegYuvOutFmtTest001, TestSize.Level3)
991 {
992     GTEST_LOG_(INFO) << "ExtDecoderTest: GetJpegYuvOutFmtTest001 start";
993     std::shared_ptr<ExtDecoder> extDecoder = std::make_shared<ExtDecoder>();
994     EXIFInfo exifInfo_;
995     PixelFormat desiredFormat = PixelFormat::UNKNOWN;
996     auto ret = extDecoder->GetJpegYuvOutFmt(desiredFormat);
997     ASSERT_EQ(ret, JpegYuvFmt::OutFmt_NV12);
998     desiredFormat = PixelFormat::NV12;
999     ret = extDecoder->GetJpegYuvOutFmt(desiredFormat);
1000     ASSERT_EQ(ret, JpegYuvFmt::OutFmt_NV12);
1001     GTEST_LOG_(INFO) << "ExtDecoderTest: GetJpegYuvOutFmtTest001 end";
1002 }
1003 
1004 /**
1005 @tc.name: IsHardwareEncodeSupportedTest001
1006 @tc.desc: Test of IsHardwareEncodeSupported
1007 @tc.type: FUNC
1008 */
1009 HWTEST_F(ExtDecoderTest, IsHardwareEncodeSupportedTest001, TestSize.Level3)
1010 {
1011     GTEST_LOG_(INFO) << "ExtDecoderTest: IsHardwareEncodeSupportedTest001 start";
1012     ExtEncoder extEncoder;
1013     const PlEncodeOptions opts;
1014     Media::PixelMap* pixelMap = nullptr;
1015     bool ret = extEncoder.IsHardwareEncodeSupported(opts, pixelMap);
1016     ASSERT_EQ(ret, false);
1017     GTEST_LOG_(INFO) << "ExtDecoderTest: IsHardwareEncodeSupportedTest001 end";
1018 }
1019 
1020 /**
1021 @tc.name: DoHardWareEncodeTest001
1022 @tc.desc: Test of DoHardWareEncode
1023 @tc.type: FUNC
1024 */
1025 HWTEST_F(ExtDecoderTest, DoHardWareEncodeTest001, TestSize.Level3)
1026 {
1027     GTEST_LOG_(INFO) << "ExtDecoderTest: DoHardWareEncodeTest001 start";
1028     ExtEncoder extEncoder;
1029     MockSkWStream* skStream = nullptr;
1030     Media::PixelMap pixelMap;
1031     extEncoder.pixelmap_ = &pixelMap;
1032     uint32_t ret = extEncoder.DoHardWareEncode(skStream);
1033     ASSERT_EQ(ret, ERR_IMAGE_ENCODE_FAILED);
1034     GTEST_LOG_(INFO) << "ExtDecoderTest: DoHardWareEncodeTest001 end";
1035 }
1036 
1037 /**
1038 @tc.name: EncodeImageBySurfaceBufferTest001
1039 @tc.desc: Test of EncodeImageBySurfaceBuffer
1040 @tc.type: FUNC
1041 */
1042 HWTEST_F(ExtDecoderTest, EncodeImageBySurfaceBufferTest001, TestSize.Level3)
1043 {
1044     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeImageBySurfaceBufferTest001 start";
1045     ExtEncoder extEncoder;
1046     sptr<SurfaceBuffer> surfaceBuffer = nullptr;
1047     SkImageInfo info;
1048     bool needExif = false;
1049     MockSkWStream mockSkWStream;
1050     uint32_t ret = extEncoder.EncodeImageBySurfaceBuffer(surfaceBuffer, info, needExif, mockSkWStream);
1051     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
1052     surfaceBuffer = SurfaceBuffer::Create();
1053     ASSERT_NE(surfaceBuffer, nullptr);
1054     ret = extEncoder.EncodeImageBySurfaceBuffer(surfaceBuffer, info, needExif, mockSkWStream);
1055     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
1056     auto result = extEncoder.GetImageEncodeData(surfaceBuffer, info, needExif);
1057     ASSERT_EQ(result, nullptr);
1058     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeImageBySurfaceBufferTest001 end";
1059 }
1060 
1061 /**
1062 @tc.name: EncodeSingleVividTest001
1063 @tc.desc: Test of EncodeSingleVivid
1064 @tc.type: FUNC
1065 */
1066 HWTEST_F(ExtDecoderTest, EncodeSingleVividTest001, TestSize.Level3)
1067 {
1068     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeSingleVividTest001 start";
1069     ExtEncoder extEncoder;
1070     ExtWStream outputStream;
1071     uint32_t ret = extEncoder.EncodeSingleVivid(outputStream);
1072     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
1073     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeSingleVividTest001 end";
1074 }
1075 
1076 /**
1077 @tc.name: EncodeDualVividTest001
1078 @tc.desc: Test of EncodeDualVivid
1079 @tc.type: FUNC
1080 */
1081 HWTEST_F(ExtDecoderTest, EncodeDualVividTest001, TestSize.Level3)
1082 {
1083     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeDualVividTest001 start";
1084     ExtEncoder extEncoder;
1085     ExtWStream outputStream;
1086     Media::PixelMap pixelMap;
1087     extEncoder.pixelmap_ = &pixelMap;
1088     extEncoder.pixelmap_->imageInfo_.pixelFormat = Media::PixelFormat::UNKNOWN;
1089     uint32_t ret = extEncoder.EncodeDualVivid(outputStream);
1090     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
1091     extEncoder.pixelmap_->imageInfo_.pixelFormat = Media::PixelFormat::RGBA_1010102;
1092     extEncoder.encodeFormat_ = SkEncodedImageFormat::kJPEG;
1093     extEncoder.pixelmap_->allocatorType_ = AllocatorType::DEFAULT;
1094     ret = extEncoder.EncodeDualVivid(outputStream);
1095     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
1096     extEncoder.pixelmap_->allocatorType_ = AllocatorType::DMA_ALLOC;
1097     extEncoder.encodeFormat_ = SkEncodedImageFormat::kHEIF;
1098     ret = extEncoder.EncodeDualVivid(outputStream);
1099     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
1100     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeDualVividTest001 end";
1101 }
1102 
1103 /**
1104 @tc.name: EncodeSdrImageTest001
1105 @tc.desc: Test of EncodeSdrImage
1106 @tc.type: FUNC
1107 */
1108 HWTEST_F(ExtDecoderTest, EncodeSdrImageTest001, TestSize.Level3)
1109 {
1110     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeSdrImageTest001 start";
1111     ExtEncoder extEncoder;
1112     ExtWStream outputStream;
1113     Media::PixelMap pixelMap;
1114     extEncoder.pixelmap_ = &pixelMap;
1115     extEncoder.pixelmap_->imageInfo_.pixelFormat = Media::PixelFormat::UNKNOWN;
1116     uint32_t ret = extEncoder.EncodeSdrImage(outputStream);
1117     extEncoder.pixelmap_->imageInfo_.pixelFormat = Media::PixelFormat::RGBA_1010102;
1118     ret = extEncoder.EncodeSdrImage(outputStream);
1119     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PARAMETER);
1120     GTEST_LOG_(INFO) << "ExtDecoderTest: EncodeSdrImageTest001 end";
1121 }
1122 }
1123 }