• 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, 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 <fstream>
18 #include "buffer_source_stream.h"
19 #include "media_errors.h"
20 #include "memory.h"
21 #include "png_decoder.h"
22 #include "securec.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS::Media;
26 using namespace OHOS::ImagePlugin;
27 namespace OHOS {
28 namespace Multimedia {
29 static constexpr size_t NUMBER_ONE = 1;
30 static constexpr size_t NUMBER_TWO = 2;
31 class PngDecoderTest : public testing::Test {
32 public:
PngDecoderTest()33     PngDecoderTest() {}
~PngDecoderTest()34     ~PngDecoderTest() {}
35 };
36 
37 class MockInputDataStream : public SourceStream {
38 public:
39     MockInputDataStream() = default;
40 
UpdateData(const uint8_t * data,uint32_t size,bool isCompleted)41     uint32_t UpdateData(const uint8_t *data, uint32_t size, bool isCompleted) override
42     {
43         return ERR_IMAGE_DATA_UNSUPPORT;
44     }
Read(uint32_t desiredSize,DataStreamBuffer & outData)45     bool Read(uint32_t desiredSize, DataStreamBuffer &outData) override
46     {
47         if (streamSize == NUMBER_ONE) {
48             streamBuffer = std::make_shared<uint8_t>(streamSize);
49             outData.inputStreamBuffer = streamBuffer.get();
50         } else if (streamSize == NUMBER_TWO) {
51             outData.dataSize = streamSize;
52         }
53         return returnValue_;
54     }
55 
Read(uint32_t desiredSize,uint8_t * outBuffer,uint32_t bufferSize,uint32_t & readSize)56     bool Read(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize) override
57     {
58         return returnValue_;
59     }
60 
Peek(uint32_t desiredSize,DataStreamBuffer & outData)61     bool Peek(uint32_t desiredSize, DataStreamBuffer &outData) override
62     {
63         return returnValue_;
64     }
65 
Peek(uint32_t desiredSize,uint8_t * outBuffer,uint32_t bufferSize,uint32_t & readSize)66     bool Peek(uint32_t desiredSize, uint8_t *outBuffer, uint32_t bufferSize, uint32_t &readSize) override
67     {
68         return returnValue_;
69     }
70 
Tell()71     uint32_t Tell() override
72     {
73         return 0;
74     }
75 
Seek(uint32_t position)76     bool Seek(uint32_t position) override
77     {
78         return returnValue_;
79     }
80 
GetStreamType()81     uint32_t GetStreamType()
82     {
83         return -1;
84     }
85 
GetDataPtr()86     uint8_t *GetDataPtr()
87     {
88         return nullptr;
89     }
90 
IsStreamCompleted()91     bool IsStreamCompleted()
92     {
93         return returnValue_;
94     }
95 
GetStreamSize()96     size_t GetStreamSize()
97     {
98         return streamSize;
99     }
100 
SetReturn(bool returnValue)101     void SetReturn(bool returnValue)
102     {
103         returnValue_ = returnValue;
104     }
105 
SetStreamSize(size_t size)106     void SetStreamSize(size_t size)
107     {
108         streamSize = size;
109     }
110 
~MockInputDataStream()111     ~MockInputDataStream() {}
112 private:
113     bool returnValue_ = false;
114     size_t streamSize = 0;
115     std::shared_ptr<uint8_t> streamBuffer = nullptr;
116 };
117 
118 /**
119  * @tc.name: GetImageSizeTest001
120  * @tc.desc: Test of GetImageSize
121  * @tc.type: FUNC
122  */
123 HWTEST_F(PngDecoderTest, GetImageSizeTest001, TestSize.Level3)
124 {
125     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest001 start";
126     auto pngDecoder = std::make_shared<PngDecoder>();
127     int size = 1000;
128     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
129     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
130     ImagePlugin::PlSize plSize;
131     pngDecoder->SetSource(*streamPtr.release());
132     pngDecoder->GetImageSize(2, plSize);
133     bool result = (pngDecoder != nullptr);
134     ASSERT_EQ(result, true);
135     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest001 end";
136 }
137 
138 /**
139  * @tc.name: GetImageSizeTest002
140  * @tc.desc: Test of GetImageSize
141  * @tc.type: FUNC
142  */
143 HWTEST_F(PngDecoderTest, GetImageSizeTest002, TestSize.Level3)
144 {
145     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest002 start";
146     auto pngDecoder = std::make_shared<PngDecoder>();
147     ImagePlugin::PlSize plSize;
148     pngDecoder->GetImageSize(0, plSize);
149     int size = 1000;
150     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
151     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
152     pngDecoder->SetSource(*streamPtr.release());
153     bool result = (pngDecoder != nullptr);
154     ASSERT_EQ(result, true);
155     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest002 end";
156 }
157 
158 /**
159  * @tc.name: GetImageSizeTest003
160  * @tc.desc: Test of GetImageSize
161  * @tc.type: FUNC
162  */
163 HWTEST_F(PngDecoderTest, GetImageSizeTest003, TestSize.Level3)
164 {
165     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest003 start";
166     auto pngDecoder = std::make_shared<PngDecoder>();
167     auto mock = std::make_shared<MockInputDataStream>();
168     pngDecoder->SetSource(*mock.get());
169     ImagePlugin::PlSize plSize;
170     pngDecoder->GetImageSize(0, plSize);
171     bool result = (pngDecoder != nullptr);
172     ASSERT_EQ(result, true);
173     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest003 end";
174 }
175 
176 /**
177  * @tc.name: GetImageSizeTest004
178  * @tc.desc: Test of GetImageSize
179  * @tc.type: FUNC
180  */
181 HWTEST_F(PngDecoderTest, GetImageSizeTest004, TestSize.Level3)
182 {
183     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest004 start";
184     auto pngDecoder = std::make_shared<PngDecoder>();
185     auto mock = std::make_shared<MockInputDataStream>();
186     mock->SetReturn(true);
187     pngDecoder->SetSource(*mock.get());
188     ImagePlugin::PlSize plSize;
189     pngDecoder->GetImageSize(0, plSize);
190     bool result = (pngDecoder != nullptr);
191     ASSERT_EQ(result, true);
192     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest004 end";
193 }
194 
195 /**
196  * @tc.name: GetImageSizeTest005
197  * @tc.desc: Test of GetImageSize
198  * @tc.type: FUNC
199  */
200 HWTEST_F(PngDecoderTest, GetImageSizeTest005, TestSize.Level3)
201 {
202     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest005 start";
203     auto pngDecoder = std::make_shared<PngDecoder>();
204     auto mock = std::make_shared<MockInputDataStream>();
205     mock->SetStreamSize(1);
206     mock->SetReturn(true);
207     pngDecoder->SetSource(*mock.get());
208     ImagePlugin::PlSize plSize;
209     pngDecoder->GetImageSize(0, plSize);
210     bool result = (pngDecoder != nullptr);
211     ASSERT_EQ(result, true);
212     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest005 end";
213 }
214 
215 /**
216  * @tc.name: GetImageSizeTest006
217  * @tc.desc: Test of GetImageSize
218  * @tc.type: FUNC
219  */
220 HWTEST_F(PngDecoderTest, GetImageSizeTest006, TestSize.Level3)
221 {
222     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest006 start";
223     auto pngDecoder = std::make_shared<PngDecoder>();
224     auto mock = std::make_shared<MockInputDataStream>();
225     mock->SetStreamSize(2);
226     mock->SetReturn(true);
227     pngDecoder->SetSource(*mock.get());
228     ImagePlugin::PlSize plSize;
229     pngDecoder->GetImageSize(0, plSize);
230     bool result = (pngDecoder != nullptr);
231     ASSERT_EQ(result, true);
232     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest006 end";
233 }
234 
235 /**
236  * @tc.name: GetImageSizeTest007
237  * @tc.desc: Test of GetImageSize, cover code branch: if (state_ >= PngDecodingState::BASE_INFO_PARSED) branch: true
238  * @tc.type: FUNC
239  */
240 HWTEST_F(PngDecoderTest, GetImageSizeTest007, TestSize.Level3)
241 {
242     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest007 start";
243     auto pngDecoder = std::make_shared<PngDecoder>();
244     auto mock = std::make_shared<MockInputDataStream>();
245     mock->SetStreamSize(2);
246     mock->SetReturn(true);
247     pngDecoder->SetSource(*mock.get());
248     DecodeContext context;
249     pngDecoder->Decode(2, context);
250     ImagePlugin::PlSize plSize;
251     pngDecoder->GetImageSize(0, plSize);
252     bool result = (pngDecoder != nullptr);
253     ASSERT_EQ(result, true);
254     GTEST_LOG_(INFO) << "PngDecoderTest: GetImageSizeTest007 end";
255 }
256 
257 /**
258  * @tc.name: SetDecodeOptionsTest001
259  * @tc.desc: Test of SetDecodeOptions
260  * @tc.type: FUNC
261  */
262 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest001, TestSize.Level3)
263 {
264     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest001 start";
265     auto pngDecoder = std::make_shared<PngDecoder>();
266     int size = 1000;
267     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
268     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
269     pngDecoder->SetSource(*streamPtr.release());
270     PixelDecodeOptions opts;
271     PlImageInfo info;
272     pngDecoder->SetDecodeOptions(2, opts, info);
273     bool result = (pngDecoder != nullptr);
274     ASSERT_EQ(result, true);
275     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest001 end";
276 }
277 
278 /**
279  * @tc.name: SetDecodeOptionsTest002
280  * @tc.desc: Test of SetDecodeOptions
281  * @tc.type: FUNC
282  */
283 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest002, TestSize.Level3)
284 {
285     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest002 start";
286     auto pngDecoder = std::make_shared<PngDecoder>();
287     PixelDecodeOptions opts;
288     PlImageInfo info;
289     pngDecoder->SetDecodeOptions(0, opts, info);
290     int size = 1000;
291     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
292     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
293     pngDecoder->SetSource(*streamPtr.release());
294     bool result = (pngDecoder != nullptr);
295     ASSERT_EQ(result, true);
296     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest002 end";
297 }
298 
299 /**
300  * @tc.name: SetDecodeOptionsTest003
301  * @tc.desc: Test of SetDecodeOptions
302  * @tc.type: FUNC
303  */
304 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest003, TestSize.Level3)
305 {
306     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest003 start";
307     auto pngDecoder = std::make_shared<PngDecoder>();
308     int size = 1000;
309     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
310     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
311     pngDecoder->SetSource(*streamPtr.release());
312     PixelDecodeOptions opts;
313     opts.desiredPixelFormat = PlPixelFormat::RGB_565;
314     PlImageInfo info;
315     pngDecoder->SetDecodeOptions(0, opts, info);
316     bool result = (pngDecoder != nullptr);
317     ASSERT_EQ(result, true);
318     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest003 end";
319 }
320 
321 /**
322  * @tc.name: SetDecodeOptionsTest004
323  * @tc.desc: Test of SetDecodeOptions
324  * @tc.type: FUNC
325  */
326 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest004, TestSize.Level3)
327 {
328     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest004 start";
329     auto pngDecoder = std::make_shared<PngDecoder>();
330     auto mock = std::make_shared<MockInputDataStream>();
331     mock->SetReturn(false);
332     pngDecoder->SetSource(*mock.get());
333     PixelDecodeOptions opts;
334     PlImageInfo info;
335     pngDecoder->SetDecodeOptions(0, opts, info);
336     bool result = (pngDecoder != nullptr);
337     ASSERT_EQ(result, true);
338     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest004 end";
339 }
340 
341 /**
342  * @tc.name: SetDecodeOptionsTest005
343  * @tc.desc: Test of SetDecodeOptions
344  * @tc.type: FUNC
345  */
346 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest005, TestSize.Level3)
347 {
348     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest005 start";
349     auto pngDecoder = std::make_shared<PngDecoder>();
350     auto mock = std::make_shared<MockInputDataStream>();
351     mock->SetReturn(false);
352     pngDecoder->SetSource(*mock.get());
353     PixelDecodeOptions opts;
354     PlImageInfo info;
355     pngDecoder->SetDecodeOptions(0, opts, info);
356     bool result = (pngDecoder != nullptr);
357     ASSERT_EQ(result, true);
358     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest005 end";
359 }
360 
361 /**
362  * @tc.name: SetDecodeOptionsTest006
363  * @tc.desc: Test of SetDecodeOptions
364  * @tc.type: FUNC
365  */
366 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest006, TestSize.Level3)
367 {
368     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest006 start";
369     auto pngDecoder = std::make_shared<PngDecoder>();
370     int size = 1000;
371     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
372     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
373     pngDecoder->SetSource(*streamPtr.release());
374     PixelDecodeOptions opts;
375     opts.desiredPixelFormat = PlPixelFormat::RGB_888;
376     PlImageInfo info;
377     pngDecoder->SetDecodeOptions(0, opts, info);
378     bool result = (pngDecoder != nullptr);
379     ASSERT_EQ(result, true);
380     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest006 end";
381 }
382 
383 /**
384  * @tc.name: SetDecodeOptionsTest007
385  * @tc.desc: Test of SetDecodeOptions
386  * @tc.type: FUNC
387  */
388 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest007, TestSize.Level3)
389 {
390     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest007 start";
391     auto pngDecoder = std::make_shared<PngDecoder>();
392     int size = 1000;
393     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
394     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
395     pngDecoder->SetSource(*streamPtr.release());
396     PixelDecodeOptions opts;
397     opts.desiredPixelFormat = PlPixelFormat::RGBA_F16;
398     PlImageInfo info;
399     pngDecoder->SetDecodeOptions(0, opts, info);
400     bool result = (pngDecoder != nullptr);
401     ASSERT_EQ(result, true);
402     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest007 end";
403 }
404 
405 /**
406  * @tc.name: SetDecodeOptionsTest008
407  * @tc.desc: Test of SetDecodeOptions
408  * @tc.type: FUNC
409  */
410 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest008, TestSize.Level3)
411 {
412     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest008 start";
413     auto pngDecoder = std::make_shared<PngDecoder>();
414     int size = 1000;
415     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
416     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
417     pngDecoder->SetSource(*streamPtr.release());
418     PixelDecodeOptions opts;
419     opts.desiredPixelFormat = PlPixelFormat::BGRA_8888;
420     PlImageInfo info;
421     pngDecoder->SetDecodeOptions(0, opts, info);
422     bool result = (pngDecoder != nullptr);
423     ASSERT_EQ(result, true);
424     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest008 end";
425 }
426 
427 /**
428  * @tc.name: SetDecodeOptionsTest009
429  * @tc.desc: Test of SetDecodeOptions
430  * @tc.type: FUNC
431  */
432 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest009, TestSize.Level3)
433 {
434     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest009 start";
435     auto pngDecoder = std::make_shared<PngDecoder>();
436     int size = 1000;
437     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
438     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
439     pngDecoder->SetSource(*streamPtr.release());
440     PixelDecodeOptions opts;
441     opts.desiredPixelFormat = PlPixelFormat::ARGB_8888;
442     PlImageInfo info;
443     pngDecoder->SetDecodeOptions(0, opts, info);
444     bool result = (pngDecoder != nullptr);
445     ASSERT_EQ(result, true);
446     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest009 end";
447 }
448 
449 /**
450  * @tc.name: SetDecodeOptionsTest010
451  * @tc.desc: Test of SetDecodeOptions
452  * @tc.type: FUNC
453  */
454 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest010, TestSize.Level3)
455 {
456     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest010 start";
457     auto pngDecoder = std::make_shared<PngDecoder>();
458     int size = 1000;
459     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
460     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
461     pngDecoder->SetSource(*streamPtr.release());
462     PixelDecodeOptions opts;
463     opts.desiredSize.width = 0;
464     opts.desiredSize.height = 0;
465     PlImageInfo info;
466     pngDecoder->SetDecodeOptions(0, opts, info);
467     bool result = (pngDecoder != nullptr);
468     ASSERT_EQ(result, true);
469     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest010 end";
470 }
471 
472 /**
473  * @tc.name: SetDecodeOptionsTest011
474  * @tc.desc: Test of SetDecodeOptions
475  * @tc.type: FUNC
476  */
477 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest011, TestSize.Level3)
478 {
479     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest011 start";
480     auto pngDecoder = std::make_shared<PngDecoder>();
481     int size = 1000;
482     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
483     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
484     pngDecoder->SetSource(*streamPtr.release());
485     PixelDecodeOptions opts;
486     opts.desiredSize.width = 0;
487     opts.desiredSize.height = 1;
488     PlImageInfo info;
489     pngDecoder->SetDecodeOptions(0, opts, info);
490     bool result = (pngDecoder != nullptr);
491     ASSERT_EQ(result, true);
492     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest011 end";
493 }
494 
495 /**
496  * @tc.name: SetDecodeOptionsTest012
497  * @tc.desc: Test of SetDecodeOptions
498  * @tc.type: FUNC
499  */
500 HWTEST_F(PngDecoderTest, SetDecodeOptionsTest012, TestSize.Level3)
501 {
502     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest012 start";
503     auto pngDecoder = std::make_shared<PngDecoder>();
504     int size = 1000;
505     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
506     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
507     pngDecoder->SetSource(*streamPtr.release());
508     PixelDecodeOptions opts;
509     opts.desiredSize.width = 1;
510     PlImageInfo info;
511     pngDecoder->SetDecodeOptions(0, opts, info);
512     bool result = (pngDecoder != nullptr);
513     ASSERT_EQ(result, true);
514     GTEST_LOG_(INFO) << "PngDecoderTest: SetDecodeOptionsTest012 end";
515 }
516 
517 /**
518  * @tc.name: DecodeTest001
519  * @tc.desc: Test of Decode
520  * @tc.type: FUNC
521  */
522 HWTEST_F(PngDecoderTest, DecodeTest001, TestSize.Level3)
523 {
524     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest001 start";
525     auto pngDecoder = std::make_shared<PngDecoder>();
526     int size = 1000;
527     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
528     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
529     pngDecoder->SetSource(*streamPtr.release());
530     DecodeContext context;
531     pngDecoder->Decode(2, context);
532     bool result = (pngDecoder != nullptr);
533     ASSERT_EQ(result, true);
534     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest001 end";
535 }
536 
537 /**
538  * @tc.name: DecodeTest002
539  * @tc.desc: Test of Decode
540  * @tc.type: FUNC
541  */
542 HWTEST_F(PngDecoderTest, DecodeTest002, TestSize.Level3)
543 {
544     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest002 start";
545     auto pngDecoder = std::make_shared<PngDecoder>();
546     DecodeContext context;
547     pngDecoder->Decode(0, context);
548     int size = 1000;
549     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
550     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
551     pngDecoder->SetSource(*streamPtr.release());
552     bool result = (pngDecoder != nullptr);
553     ASSERT_EQ(result, true);
554     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest002 end";
555 }
556 
557 /**
558  * @tc.name: DecodeTest003
559  * @tc.desc: Test of Decode
560  * @tc.type: FUNC
561  */
562 HWTEST_F(PngDecoderTest, DecodeTest003, TestSize.Level3)
563 {
564     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest003 start";
565     auto pngDecoder = std::make_shared<PngDecoder>();
566     int size = 1000;
567     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
568     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
569     pngDecoder->SetSource(*streamPtr.release());
570     DecodeContext context;
571     pngDecoder->Decode(2, context);
572     pngDecoder->Decode(2, context);
573     bool result = (pngDecoder != nullptr);
574     ASSERT_EQ(result, true);
575     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest003 end";
576 }
577 
578 /**
579  * @tc.name: DecodeTest004
580  * @tc.desc: Test of Decode
581  * @tc.type: FUNC
582  */
583 HWTEST_F(PngDecoderTest, DecodeTest004, TestSize.Level3)
584 {
585     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest004 start";
586     auto pngDecoder = std::make_shared<PngDecoder>();
587     int size = 1000;
588     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
589     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
590     pngDecoder->SetSource(*streamPtr.release());
591     DecodeContext context;
592     pngDecoder->Reset();
593     pngDecoder->Decode(2, context);
594     bool result = (pngDecoder != nullptr);
595     ASSERT_EQ(result, true);
596     GTEST_LOG_(INFO) << "PngDecoderTest: DecodeTest004 end";
597 }
598 
599 /**
600  * @tc.name: HasProperty001
601  * @tc.desc: test HasProperty
602  * @tc.type: FUNC
603  */
604 HWTEST_F(PngDecoderTest, HasProperty001, TestSize.Level3)
605 {
606     GTEST_LOG_(INFO) << "PngDecoderTest: HasProperty001 start";
607     ImagePlugin::PngDecoder pngdcod;
608     std::string key = "";
609     bool haspro = pngdcod.HasProperty(key);
610     ASSERT_EQ(haspro, false);
611     GTEST_LOG_(INFO) << "PngDecoderTest: HasProperty001 end";
612 }
613 
614 /**
615  * @tc.name: PromoteIncrementalDecodeTest001
616  * @tc.desc: Test of PromoteIncrementalDecode
617  * @tc.type: FUNC
618  */
619 HWTEST_F(PngDecoderTest, PromoteIncrementalDecodeTest001, TestSize.Level3)
620 {
621     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest001 start";
622     auto pngDecoder = std::make_shared<PngDecoder>();
623     int size = 1000;
624     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
625     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
626     pngDecoder->SetSource(*streamPtr.release());
627     ProgDecodeContext context;
628     pngDecoder->PromoteIncrementalDecode(2, context);
629     bool result = (pngDecoder != nullptr);
630     ASSERT_EQ(result, true);
631     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest001 end";
632 }
633 
634 /**
635  * @tc.name: PromoteIncrementalDecodeTest002
636  * @tc.desc: Test of PromoteIncrementalDecode
637  * @tc.type: FUNC
638  */
639 HWTEST_F(PngDecoderTest, PromoteIncrementalDecodeTest002, TestSize.Level3)
640 {
641     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest002 start";
642     auto pngDecoder = std::make_shared<PngDecoder>();
643     ProgDecodeContext context;
644     pngDecoder->PromoteIncrementalDecode(0, context);
645     int size = 1000;
646     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
647     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
648     pngDecoder->SetSource(*streamPtr.release());
649     bool result = (pngDecoder != nullptr);
650     ASSERT_EQ(result, true);
651     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest002 end";
652 }
653 
654 /**
655  * @tc.name: PromoteIncrementalDecodeTest003
656  * @tc.desc: Test of PromoteIncrementalDecode
657  * @tc.type: FUNC
658  */
659 HWTEST_F(PngDecoderTest, PromoteIncrementalDecodeTest003, TestSize.Level3)
660 {
661     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest003 start";
662     auto pngDecoder = std::make_shared<PngDecoder>();
663     auto mock = std::make_shared<MockInputDataStream>();
664     mock->SetReturn(false);
665     pngDecoder->SetSource(*mock.get());
666     ProgDecodeContext context;
667     pngDecoder->PromoteIncrementalDecode(0, context);
668     bool result = (pngDecoder != nullptr);
669     ASSERT_EQ(result, true);
670     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest003 end";
671 }
672 
673 /**
674  * @tc.name: PromoteIncrementalDecodeTest004
675  * @tc.desc: Test of PromoteIncrementalDecode
676  * @tc.type: FUNC
677  */
678 HWTEST_F(PngDecoderTest, PromoteIncrementalDecodeTest004, TestSize.Level3)
679 {
680     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest004 start";
681     auto pngDecoder = std::make_shared<PngDecoder>();
682     auto mock = std::make_shared<MockInputDataStream>();
683     mock->SetReturn(false);
684     pngDecoder->SetSource(*mock.get());
685     ProgDecodeContext context;
686     context.decodeContext.allocatorType = Media::AllocatorType::SHARE_MEM_ALLOC;
687     pngDecoder->PromoteIncrementalDecode(0, context);
688     bool result = (pngDecoder != nullptr);
689     ASSERT_EQ(result, true);
690     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest004 end";
691 }
692 
693 /**
694  * @tc.name: PromoteIncrementalDecodeTest005
695  * @tc.desc: Test of PromoteIncrementalDecode
696  * @tc.type: FUNC
697  */
698 HWTEST_F(PngDecoderTest, PromoteIncrementalDecodeTest005, TestSize.Level3)
699 {
700     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest005 start";
701     auto pngDecoder = std::make_shared<PngDecoder>();
702     auto mock = std::make_shared<MockInputDataStream>();
703     mock->SetReturn(false);
704     pngDecoder->SetSource(*mock.get());
705     ProgDecodeContext context;
706     context.decodeContext.allocatorType = Media::AllocatorType::SHARE_MEM_ALLOC;
707     pngDecoder->Reset();
708     pngDecoder->PromoteIncrementalDecode(0, context);
709     bool result = (pngDecoder != nullptr);
710     ASSERT_EQ(result, true);
711     GTEST_LOG_(INFO) << "PngDecoderTest: PromoteIncrementalDecodeTest005 end";
712 }
713 } // namespace Multimedia
714 } // namespace OHOS