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 #define private public
17 #include <gtest/gtest.h>
18 #include "buffer_source_stream.h"
19 #include "raw_decoder.h"
20 #include "raw_stream.h"
21 #include "mock_data_stream.h"
22 #include "mock_abs_image_decoder.h"
23 
24 using namespace testing::ext;
25 using namespace OHOS::Media;
26 using namespace OHOS::ImagePlugin;
27 namespace OHOS {
28 namespace Multimedia {
29 class RawDecoderTest : public testing::Test {
30 public:
RawDecoderTest()31     RawDecoderTest() {}
~RawDecoderTest()32     ~RawDecoderTest() {}
33 };
34 
35 /**
36  * @tc.name: GetImageSizeTest001
37  * @tc.desc: Test of GetImageSize
38  * @tc.type: FUNC
39  */
40 HWTEST_F(RawDecoderTest, GetImageSizeTest001, TestSize.Level3)
41 {
42     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest001 start";
43     auto rawDecoder = std::make_shared<RawDecoder>();
44     int size = 1000;
45     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
46     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
47     ImagePlugin::Size plSize;
48     rawDecoder->SetSource(*streamPtr.release());
49     rawDecoder->GetImageSize(2, plSize);
50     bool result = (rawDecoder != nullptr);
51     ASSERT_EQ(result, true);
52     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest001 end";
53 }
54 
55 /**
56  * @tc.name: GetImageSizeTest002
57  * @tc.desc: Test of GetImageSize
58  * @tc.type: FUNC
59  */
60 HWTEST_F(RawDecoderTest, GetImageSizeTest002, TestSize.Level3)
61 {
62     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest002 start";
63     auto rawDecoder = std::make_shared<RawDecoder>();
64     ImagePlugin::Size plSize;
65     rawDecoder->GetImageSize(0, plSize);
66     int size = 1000;
67     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
68     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
69     rawDecoder->SetSource(*streamPtr.release());
70     bool result = (rawDecoder != nullptr);
71     ASSERT_EQ(result, true);
72     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest002 end";
73 }
74 
75 /**
76  * @tc.name: GetImageSizeTest003
77  * @tc.desc: Test of GetImageSize
78  * @tc.type: FUNC
79  */
80 HWTEST_F(RawDecoderTest, GetImageSizeTest003, TestSize.Level3)
81 {
82     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest003 start";
83     auto rawDecoder = std::make_shared<RawDecoder>();
84     auto mock = std::make_shared<MockInputDataStream>();
85     rawDecoder->SetSource(*mock.get());
86     ImagePlugin::Size plSize;
87     rawDecoder->GetImageSize(0, plSize);
88     bool result = (rawDecoder != nullptr);
89     ASSERT_EQ(result, true);
90     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest003 end";
91 }
92 
93 /**
94  * @tc.name: GetImageSizeTest004
95  * @tc.desc: Test of GetImageSize
96  * @tc.type: FUNC
97  */
98 HWTEST_F(RawDecoderTest, GetImageSizeTest004, TestSize.Level3)
99 {
100     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest004 start";
101     auto rawDecoder = std::make_shared<RawDecoder>();
102     auto mock = std::make_shared<MockInputDataStream>();
103     mock->SetReturn(true);
104     rawDecoder->SetSource(*mock.get());
105     ImagePlugin::Size plSize;
106     rawDecoder->GetImageSize(0, plSize);
107     bool result = (rawDecoder != nullptr);
108     ASSERT_EQ(result, true);
109     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest004 end";
110 }
111 
112 /**
113  * @tc.name: GetImageSizeTest005
114  * @tc.desc: Test of GetImageSize
115  * @tc.type: FUNC
116  */
117 HWTEST_F(RawDecoderTest, GetImageSizeTest005, TestSize.Level3)
118 {
119     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest005 start";
120     auto rawDecoder = std::make_shared<RawDecoder>();
121     auto mock = std::make_shared<MockInputDataStream>();
122     mock->SetStreamSize(1);
123     mock->SetReturn(true);
124     rawDecoder->SetSource(*mock.get());
125     ImagePlugin::Size plSize;
126     rawDecoder->GetImageSize(0, plSize);
127     bool result = (rawDecoder != nullptr);
128     ASSERT_EQ(result, true);
129     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest005 end";
130 }
131 
132 /**
133  * @tc.name: GetImageSizeTest006
134  * @tc.desc: Test of GetImageSize
135  * @tc.type: FUNC
136  */
137 HWTEST_F(RawDecoderTest, GetImageSizeTest006, TestSize.Level3)
138 {
139     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest006 start";
140     auto rawDecoder = std::make_shared<RawDecoder>();
141     auto mock = std::make_shared<MockInputDataStream>();
142     mock->SetStreamSize(2);
143     mock->SetReturn(true);
144     rawDecoder->SetSource(*mock.get());
145     ImagePlugin::Size plSize;
146     rawDecoder->GetImageSize(0, plSize);
147     bool result = (rawDecoder != nullptr);
148     ASSERT_EQ(result, true);
149     GTEST_LOG_(INFO) << "RawDecoderTest: GetImageSizeTest006 end";
150 }
151 
152 /**
153  * @tc.name: RawDecoderTest001
154  * @tc.desc: HasProperty
155  * @tc.type: FUNC
156  */
157 HWTEST_F(RawDecoderTest, RawDecoderTest001, TestSize.Level3)
158 {
159     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest001 start";
160     auto rawDecoder = std::make_shared<RawDecoder>();
161     string key = "1";
162     bool res = rawDecoder->HasProperty(key);
163     ASSERT_EQ(res, false);
164     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest001 end";
165 }
166 
167 /**
168  * @tc.name: RawDecoderTest002
169  * @tc.desc: PromoteIncrementalDecode
170  * @tc.type: FUNC
171  */
172 HWTEST_F(RawDecoderTest, RawDecoderTest002, TestSize.Level3)
173 {
174     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest002 start";
175     auto rawDecoder = std::make_shared<RawDecoder>();
176     ProgDecodeContext progContext;
177     uint32_t index = 1;
178     uint32_t res = rawDecoder->PromoteIncrementalDecode(index, progContext);
179     ASSERT_EQ(res, ERR_IMAGE_DATA_UNSUPPORT);
180     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest002 end";
181 }
182 
183 /**
184  * @tc.name: RawDecoderTest003
185  * @tc.desc: GetTopLevelImageNum
186  * @tc.type: FUNC
187  */
188 HWTEST_F(RawDecoderTest, RawDecoderTest003, TestSize.Level3)
189 {
190     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest003 start";
191     auto rawDecoder = std::make_shared<RawDecoder>();
192     uint32_t index = 1;
193     uint32_t res = rawDecoder->GetTopLevelImageNum(index);
194     ASSERT_EQ(res, SUCCESS);
195     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest003 end";
196 }
197 
198 /**
199  * @tc.name: RawDecoderTest004
200  * @tc.desc: SetDecodeOptions
201  * @tc.type: FUNC
202  */
203 HWTEST_F(RawDecoderTest, RawDecoderTest004, TestSize.Level3)
204 {
205     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest004 start";
206     auto rawDecoder = std::make_shared<RawDecoder>();
207     uint32_t index = 1;
208     const PixelDecodeOptions opts;
209     PlImageInfo info;
210     uint32_t res = rawDecoder->SetDecodeOptions(index, opts, info);
211     ASSERT_EQ(res, ERR_IMAGE_INVALID_PARAMETER);
212     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest004 end";
213 }
214 
215 /**
216  * @tc.name: RawDecoderTest005
217  * @tc.desc: SetDecodeOptions
218  * @tc.type: FUNC
219  */
220 HWTEST_F(RawDecoderTest, RawDecoderTest005, TestSize.Level3)
221 {
222     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest005 start";
223     auto rawDecoder = std::make_shared<RawDecoder>();
224     uint32_t index = 0;
225     const PixelDecodeOptions opts;
226     PlImageInfo info;
227     uint32_t res = rawDecoder->SetDecodeOptions(index, opts, info);
228     ASSERT_EQ(res, ERR_MEDIA_INVALID_OPERATION);
229     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest005 end";
230 }
231 
232 /**
233  * @tc.name: RawDecoderTest006
234  * @tc.desc: GetImageSize
235  * @tc.type: FUNC
236  */
237 HWTEST_F(RawDecoderTest, RawDecoderTest006, TestSize.Level3)
238 {
239     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest006 start";
240     auto rawDecoder = std::make_shared<RawDecoder>();
241     uint32_t index = 0;
242     Size size;
243     size.width = 3;
244     size.height = 4;
245     uint32_t res = rawDecoder->GetImageSize(index, size);
246     ASSERT_EQ(res, ERR_MEDIA_INVALID_OPERATION);
247     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest006 end";
248 }
249 
250 /**
251  * @tc.name: RawDecoderTest007
252  * @tc.desc: Decode
253  * @tc.type: FUNC
254  */
255 HWTEST_F(RawDecoderTest, RawDecoderTest007, TestSize.Level3)
256 {
257     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest007 start";
258     auto rawDecoder = std::make_shared<RawDecoder>();
259     uint32_t index = 0;
260     DecodeContext context;
261     uint32_t res = rawDecoder->Decode(index, context);
262     ASSERT_EQ(res, ERR_MEDIA_INVALID_OPERATION);
263     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest007 end";
264 }
265 
266 /**
267  * @tc.name: RawDecoderTest008
268  * @tc.desc: Decode
269  * @tc.type: FUNC
270  */
271 HWTEST_F(RawDecoderTest, RawDecoderTest008, TestSize.Level3)
272 {
273     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest008 start";
274     auto rawDecoder = std::make_shared<RawDecoder>();
275     uint32_t index = 1;
276     DecodeContext context;
277     uint32_t res = rawDecoder->Decode(index, context);
278     ASSERT_EQ(res, ERR_IMAGE_INVALID_PARAMETER);
279     GTEST_LOG_(INFO) << "RawDecoderTest: RawDecoderTest008 end";
280 }
281 
282 /**
283  * @tc.name: SetDecodeOptionsTest001
284  * @tc.desc: Test of SetDecodeOptions
285  * @tc.type: FUNC
286  */
287 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest001, TestSize.Level3)
288 {
289     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest001 start";
290     auto rawDecoder = std::make_shared<RawDecoder>();
291     int size = 1000;
292     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
293     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
294     rawDecoder->SetSource(*streamPtr.release());
295     PixelDecodeOptions opts;
296     PlImageInfo info;
297     rawDecoder->SetDecodeOptions(2, opts, info);
298     bool result = (rawDecoder != nullptr);
299     ASSERT_EQ(result, true);
300     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest001 end";
301 }
302 
303 /**
304  * @tc.name: SetDecodeOptionsTest002
305  * @tc.desc: Test of SetDecodeOptions
306  * @tc.type: FUNC
307  */
308 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest002, TestSize.Level3)
309 {
310     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest002 start";
311     auto rawDecoder = std::make_shared<RawDecoder>();
312     PixelDecodeOptions opts;
313     PlImageInfo info;
314     rawDecoder->SetDecodeOptions(0, opts, info);
315     int size = 1000;
316     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
317     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
318     rawDecoder->SetSource(*streamPtr.release());
319     bool result = (rawDecoder != nullptr);
320     ASSERT_EQ(result, true);
321     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest002 end";
322 }
323 
324 /**
325  * @tc.name: SetDecodeOptionsTest003
326  * @tc.desc: Test of SetDecodeOptions
327  * @tc.type: FUNC
328  */
329 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest003, TestSize.Level3)
330 {
331     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest003 start";
332     auto rawDecoder = std::make_shared<RawDecoder>();
333     int size = 1000;
334     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
335     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
336     rawDecoder->SetSource(*streamPtr.release());
337     PixelDecodeOptions opts;
338     opts.desiredPixelFormat = PixelFormat::RGB_565;
339     PlImageInfo info;
340     rawDecoder->SetDecodeOptions(0, opts, info);
341     bool result = (rawDecoder != nullptr);
342     ASSERT_EQ(result, true);
343     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest003 end";
344 }
345 
346 /**
347  * @tc.name: SetDecodeOptionsTest004
348  * @tc.desc: Test of SetDecodeOptions
349  * @tc.type: FUNC
350  */
351 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest004, TestSize.Level3)
352 {
353     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest004 start";
354     auto rawDecoder = std::make_shared<RawDecoder>();
355     auto mock = std::make_shared<MockInputDataStream>();
356     mock->SetReturn(false);
357     rawDecoder->SetSource(*mock.get());
358     PixelDecodeOptions opts;
359     PlImageInfo info;
360     rawDecoder->SetDecodeOptions(0, opts, info);
361     bool result = (rawDecoder != nullptr);
362     ASSERT_EQ(result, true);
363     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest004 end";
364 }
365 
366 /**
367  * @tc.name: SetDecodeOptionsTest005
368  * @tc.desc: Test of SetDecodeOptions
369  * @tc.type: FUNC
370  */
371 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest005, TestSize.Level3)
372 {
373     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest005 start";
374     auto rawDecoder = std::make_shared<RawDecoder>();
375     auto mock = std::make_shared<MockInputDataStream>();
376     mock->SetStreamSize(1);
377     mock->SetReturn(true);
378     rawDecoder->SetSource(*mock.get());
379     PixelDecodeOptions opts;
380     PlImageInfo info;
381     rawDecoder->SetDecodeOptions(0, opts, info);
382     bool result = (rawDecoder != nullptr);
383     ASSERT_EQ(result, true);
384     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest005 end";
385 }
386 
387 /**
388  * @tc.name: SetDecodeOptionsTest006
389  * @tc.desc: Test of SetDecodeOptions
390  * @tc.type: FUNC
391  */
392 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest006, TestSize.Level3)
393 {
394     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest006 start";
395     auto rawDecoder = std::make_shared<RawDecoder>();
396     auto mock = std::make_shared<MockInputDataStream>();
397     mock->SetStreamSize(2);
398     mock->SetReturn(true);
399     rawDecoder->SetSource(*mock.get());
400     PixelDecodeOptions opts;
401     PlImageInfo info;
402     rawDecoder->SetDecodeOptions(0, opts, info);
403     bool result = (rawDecoder != nullptr);
404     ASSERT_EQ(result, true);
405     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest006 end";
406 }
407 
408 /**
409  * @tc.name: SetDecodeOptionsTest007
410  * @tc.desc: Test of SetDecodeOptions
411  * @tc.type: FUNC
412  */
413 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest007, TestSize.Level3)
414 {
415     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest007 start";
416     auto rawDecoder = std::make_shared<RawDecoder>();
417     PixelDecodeOptions opts;
418     PlImageInfo info;
419     rawDecoder->SetDecodeOptions(5, opts, info);
420     int size = 1000;
421     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
422     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
423     rawDecoder->SetSource(*streamPtr.release());
424     bool result = (rawDecoder != nullptr);
425     ASSERT_EQ(result, true);
426     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest002 end";
427 }
428 
429 /**
430  * @tc.name: SetDecodeOptionsTest008
431  * @tc.desc: Test of SetDecodeOptions
432  * @tc.type: FUNC
433  */
434 HWTEST_F(RawDecoderTest, SetDecodeOptionsTest008, TestSize.Level3)
435 {
436     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest008 start";
437     auto rawDecoder = std::make_shared<RawDecoder>();
438     auto mock = std::make_shared<MockInputDataStream>();
439     mock->SetStreamSize(0);
440     mock->SetReturn(true);
441     rawDecoder->SetSource(*mock.get());
442     PixelDecodeOptions opts;
443     PlImageInfo info;
444     rawDecoder->SetDecodeOptions(2, opts, info);
445     bool result = (rawDecoder != nullptr);
446     ASSERT_EQ(result, true);
447     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptionsTest008 end";
448 }
449 
450 /**
451  * @tc.name: DecodeTest001
452  * @tc.desc: Test of Decode
453  * @tc.type: FUNC
454  */
455 HWTEST_F(RawDecoderTest, DecodeTest001, TestSize.Level3)
456 {
457     GTEST_LOG_(INFO) << "RawDecoderTest: DecodeTest001 start";
458     auto rawDecoder = std::make_shared<RawDecoder>();
459     int size = 1000;
460     std::unique_ptr<uint8_t[]> data = std::make_unique<uint8_t[]>(size);
461     auto streamPtr = BufferSourceStream::CreateSourceStream(data.get(), size);
462     rawDecoder->SetSource(*streamPtr.release());
463     DecodeContext context;
464     rawDecoder->Decode(2, context);
465     bool result = (rawDecoder != nullptr);
466     ASSERT_EQ(result, true);
467     GTEST_LOG_(INFO) << "RawDecoderTest: DecodeTest001 end";
468 }
469 
470 /**
471  * @tc.name: DecodeTest002
472  * @tc.desc: Test of Decode
473  * @tc.type: FUNC
474  */
475 HWTEST_F(RawDecoderTest, DecodeTest002, TestSize.Level3)
476 {
477     GTEST_LOG_(INFO) << "RawDecoderTest: DecodeTest002 start";
478     auto rawDecoder = std::make_shared<RawDecoder>();
479     DecodeContext context;
480     rawDecoder->Decode(0, context);
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     rawDecoder->SetSource(*streamPtr.release());
485     bool result = (rawDecoder != nullptr);
486     ASSERT_EQ(result, true);
487     GTEST_LOG_(INFO) << "RawDecoderTest: DecodeTest002 end";
488 }
489 
490 /**
491  * @tc.name: DoDecodeHeaderByPiex001
492  * @tc.desc: Test of DoDecodeHeaderByPiex
493  * @tc.type: FUNC
494  */
495 HWTEST_F(RawDecoderTest, DoDecodeHeaderByPiex001, TestSize.Level3)
496 {
497     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex001 start";
498     std::unique_ptr<RawStream> rawStream_;
499     piex::PreviewImageData imageData;
500     piex::Error error = piex::GetPreviewImageData(rawStream_.get(), &imageData);
501     error = piex::Error::kFail;
502     auto rawDecoder = std::make_shared<RawDecoder>();
503     rawDecoder->DoDecodeHeaderByPiex();
504     imageData.preview.format = piex::Image::kJpegCompressed;
505     imageData.preview.length = 1;
506     bool result = (rawDecoder != nullptr);
507     ASSERT_EQ(result, true);
508     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex001 end";
509 }
510 
511 /**
512  * @tc.name: DoDecodeHeaderByPiex002
513  * @tc.desc: Test of DoDecodeHeaderByPiex
514  * @tc.type: FUNC
515  */
516 HWTEST_F(RawDecoderTest, DoDecodeHeaderByPiex002, TestSize.Level3)
517 {
518     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex002 start";
519     std::unique_ptr<RawStream> rawStream_;
520     piex::PreviewImageData imageData;
521     piex::Error error = piex::GetPreviewImageData(rawStream_.get(), &imageData);
522     error = piex::Error::kOk;
523     auto rawDecoder = std::make_shared<RawDecoder>();
524     imageData.preview.format = piex::Image::kJpegCompressed;
525     imageData.preview.length = 1;
526     rawDecoder->DoDecodeHeaderByPiex();
527     bool result = (rawDecoder != nullptr);
528     ASSERT_EQ(result, true);
529     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex002 end";
530 }
531 
532 /**
533  * @tc.name: DoDecodeHeaderByPiex003
534  * @tc.desc: Test of DoDecodeHeaderByPiex
535  * @tc.type: FUNC
536  */
537 HWTEST_F(RawDecoderTest, DoDecodeHeaderByPiex003, TestSize.Level3)
538 {
539     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex003 start";
540     auto rawDecoder = std::make_shared<RawDecoder>();
541     rawDecoder->DoDecodeHeaderByPiex();
542     bool result = (rawDecoder != nullptr);
543     ASSERT_EQ(result, true);
544     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex003 end";
545 }
546 
547 /**
548  * @tc.name: DoSetDecodeOptions
549  * @tc.desc: Test of DoSetDecodeOptions
550  * @tc.type: FUNC
551  */
552 HWTEST_F(RawDecoderTest, DoSetDecodeOptions, TestSize.Level3)
553 {
554     GTEST_LOG_(INFO) << "RawDecoderTest: DoSetDecodeOptions001 start";
555     uint32_t index = 1;
556     PixelDecodeOptions opts;
557     PlImageInfo info;
558     auto rawDecoder = std::make_shared<RawDecoder>();
559     rawDecoder->DoSetDecodeOptions(index, opts, info);
560     bool result = (rawDecoder != nullptr);
561     ASSERT_EQ(result, true);
562     GTEST_LOG_(INFO) << "RawDecoderTest: DoSetDecodeOptions001 end";
563 }
564 
565 /**
566  * @tc.name: DoGetImageSize
567  * @tc.desc: Test of DoGetImageSize
568  * @tc.type: FUNC
569  */
570 HWTEST_F(RawDecoderTest, DoGetImageSize, TestSize.Level3)
571 {
572     GTEST_LOG_(INFO) << "RawDecoderTest: DoGetImageSize start";
573     uint32_t index = 1;
574     Size size;
575     std::unique_ptr<AbsImageDecoder> jpegDecoder_;
576     auto rawDecoder = std::make_shared<RawDecoder>();
577     rawDecoder->DoGetImageSize(index, size);
578     bool result = (rawDecoder != nullptr);
579     ASSERT_EQ(result, true);
580     GTEST_LOG_(INFO) << "RawDecoderTest: DoGetImageSize end";
581 }
582 
583 /**
584  * @tc.name: DoDecode
585  * @tc.desc: Test of DoDecode
586  * @tc.type: FUNC
587  */
588 HWTEST_F(RawDecoderTest, DoDecode, TestSize.Level3)
589 {
590     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecode start";
591     uint32_t index = 1;
592     DecodeContext context;
593     auto rawDecoder = std::make_shared<RawDecoder>();
594     rawDecoder->DoDecode(index, context);
595     bool result = (rawDecoder != nullptr);
596     ASSERT_EQ(result, true);
597     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecode end";
598 }
599 
600 /**
601  * @tc.name: DecodeTest003
602  * @tc.desc: Test of DoDecode
603  * @tc.type: FUNC
604  */
605 HWTEST_F(RawDecoderTest, DecodeTest003, TestSize.Level3)
606 {
607     GTEST_LOG_(INFO) << "RawDecoderTest: DecodeTest003 start";
608     auto rawDecoder = std::make_shared<RawDecoder>();
609     uint32_t index = 0;
610     DecodeContext context;
611     rawDecoder->state_ = ImagePlugin::RawDecoder::RawDecodingState::IMAGE_DECODING;
612     uint32_t result = rawDecoder->DoDecode(index, context);
613     ASSERT_EQ(result, ERR_IMAGE_DATA_UNSUPPORT);
614     GTEST_LOG_(INFO) << "RawDecoderTest: DecodeTest003 end";
615 }
616 
617 /**
618  * @tc.name: SetDecodeOptions007
619  * @tc.desc: Test of SetDecodeOptions
620  * @tc.type: FUNC
621  */
622 HWTEST_F(RawDecoderTest, SetDecodeOptions007, TestSize.Level3)
623 {
624     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptions007 start";
625     auto rawDecoder = std::make_shared<RawDecoder>();
626     uint32_t index = 0;
627     PixelDecodeOptions opts;
628     PlImageInfo info;
629     rawDecoder->state_ = ImagePlugin::RawDecoder::RawDecodingState::IMAGE_DECODING;
630     rawDecoder->jpegDecoder_ = nullptr;
631     uint32_t result = rawDecoder->SetDecodeOptions(index, opts, info);
632     ASSERT_EQ(result, ERR_IMAGE_DATA_UNSUPPORT);
633     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptions007 end";
634 }
635 
636 /**
637  * @tc.name: GetImageSize007
638  * @tc.desc: Test of GetImageSize
639  * @tc.type: FUNC
640  */
641 HWTEST_F(RawDecoderTest, GetImageSize007, TestSize.Level3)
642 {
643     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptions007 start";
644     auto rawDecoder = std::make_shared<RawDecoder>();
645     uint32_t index = 0;
646     Size size;
647     rawDecoder->state_ = ImagePlugin::RawDecoder::RawDecodingState::BASE_INFO_PARSED;
648     rawDecoder->jpegDecoder_ = nullptr;
649     uint32_t result = rawDecoder->GetImageSize(index, size);
650     ASSERT_EQ(result, 0);
651     GTEST_LOG_(INFO) << "RawDecoderTest: SetDecodeOptions007 end";
652 }
653 
654 /**
655  * @tc.name: DoSetDecodeOptions001
656  * @tc.desc: Test of DoSetDecodeOptions
657  * @tc.type: FUNC
658  */
659 HWTEST_F(RawDecoderTest, DoSetDecodeOptions001, TestSize.Level3)
660 {
661     GTEST_LOG_(INFO) << "RawDecoderTest: DoSetDecodeOptions001 start";
662     auto rawDecoder = std::make_shared<RawDecoder>();
663     uint32_t index = 0;
664     PixelDecodeOptions opts;
665     PlImageInfo info;
666     rawDecoder->jpegDecoder_ = nullptr;
667     uint32_t result = rawDecoder->DoSetDecodeOptions(index, opts, info);
668     ASSERT_EQ(result, ERR_IMAGE_DATA_UNSUPPORT);
669     GTEST_LOG_(INFO) << "RawDecoderTest: DoSetDecodeOptions001 end";
670 }
671 
672 /**
673  * @tc.name: DoGetImageSize001
674  * @tc.desc: Test of DoGetImageSize
675  * @tc.type: FUNC
676  */
677 HWTEST_F(RawDecoderTest, DoGetImageSize001, TestSize.Level3)
678 {
679     GTEST_LOG_(INFO) << "RawDecoderTest: DoGetImageSize001 start";
680     auto rawDecoder = std::make_shared<RawDecoder>();
681     uint32_t index = 0;
682     Size size;
683     rawDecoder->jpegDecoder_ = nullptr;
684     uint32_t result = rawDecoder->DoGetImageSize(index, size);
685     ASSERT_EQ(result, ERR_IMAGE_DATA_UNSUPPORT);
686     GTEST_LOG_(INFO) << "RawDecoderTest: DoGetImageSize001 end";
687 }
688 
689 /**
690  * @tc.name: DoDecodeHeaderByPiex004
691  * @tc.desc: Test of DoDecodeHeaderByPiex
692  * @tc.type: FUNC
693  */
694 HWTEST_F(RawDecoderTest, DoDecodeHeaderByPiex004, TestSize.Level3)
695 {
696     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex004 start";
697     auto rawDecoder = std::make_shared<RawDecoder>();
698     rawDecoder->rawStream_ = nullptr;
699     uint32_t result = rawDecoder->DoDecodeHeaderByPiex();
700     ASSERT_EQ(result, Media::ERR_IMAGE_DATA_ABNORMAL);
701     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeHeaderByPiex004 end";
702 }
703 
704 /**
705  * @tc.name: DoSetDecodeOptionsTest002
706  * @tc.desc: Test of DoSetDecodeOptions
707  * @tc.type: FUNC
708  */
709 HWTEST_F(RawDecoderTest, DoSetDecodeOptionsTest002, TestSize.Level3)
710 {
711     GTEST_LOG_(INFO) << "RawDecoderTest: DoSetDecodeOptionsTest002 start";
712     auto rawDecoder = std::make_shared<RawDecoder>();
713     uint32_t index = 0;
714     PixelDecodeOptions opts;
715     PlImageInfo info;
716     rawDecoder->jpegDecoder_ = std::make_unique<MockAbsImageDecoder>();
717     ASSERT_NE(rawDecoder->jpegDecoder_, nullptr);
718     uint32_t result = rawDecoder->DoSetDecodeOptions(index, opts, info);
719     ASSERT_EQ(result, Media::SUCCESS);
720     GTEST_LOG_(INFO) << "RawDecoderTest: DoSetDecodeOptionsTest002 end";
721 }
722 
723 /**
724  * @tc.name: DoGetImageSizeTest002
725  * @tc.desc: Test of DoGetImageSize
726  * @tc.type: FUNC
727  */
728 HWTEST_F(RawDecoderTest, DoGetImageSizeTest002, TestSize.Level3)
729 {
730     GTEST_LOG_(INFO) << "RawDecoderTest: DoGetImageSizeTest002 start";
731     auto rawDecoder = std::make_shared<RawDecoder>();
732     uint32_t index = 0;
733     Size size;
734     rawDecoder->jpegDecoder_ = std::make_unique<MockAbsImageDecoder>();
735     ASSERT_NE(rawDecoder->jpegDecoder_, nullptr);
736     uint32_t result = rawDecoder->DoGetImageSize(index, size);
737     ASSERT_EQ(result, Media::SUCCESS);
738     GTEST_LOG_(INFO) << "RawDecoderTest: DoGetImageSizeTest002 end";
739 }
740 
741 /**
742  * @tc.name: DoDecodeTest002
743  * @tc.desc: Test of DoDecode
744  * @tc.type: FUNC
745  */
746 HWTEST_F(RawDecoderTest, DoDecodeTest002, TestSize.Level3)
747 {
748     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeTest002 start";
749     auto rawDecoder = std::make_shared<RawDecoder>();
750     uint32_t index = 0;
751     DecodeContext context;
752     rawDecoder->jpegDecoder_ = std::make_unique<MockAbsImageDecoder>();
753     ASSERT_NE(rawDecoder->jpegDecoder_, nullptr);
754     uint32_t result = rawDecoder->DoDecode(index, context);
755     ASSERT_EQ(result, Media::SUCCESS);
756     GTEST_LOG_(INFO) << "RawDecoderTest: DoDecodeTest002 end";
757 }
758 
759 /**
760  * @tc.name: GetDataTest001
761  * @tc.desc: Test of GetData
762  * @tc.type: FUNC
763  */
764 HWTEST_F(RawDecoderTest, GetDataTest001, TestSize.Level3)
765 {
766     GTEST_LOG_(INFO) << "RawStreamTest: GetDataTest001 start";
767     MockInputDataStream sourceStream;
768     auto rawStream = std::make_shared<RawStream>(sourceStream);
769     const size_t offset = 1;
770     const size_t length = 0;
771     uint8_t *data = nullptr;
772     rawStream->inputStream_ = nullptr;
773     auto result = rawStream->GetData(offset, length, data);
774     ASSERT_EQ(result, piex::kUnsupported);
775     MockInputDataStream mockInputDataStream;
776     rawStream->inputStream_ = &mockInputDataStream;
777     ASSERT_NE(rawStream->inputStream_, nullptr);
778     result = rawStream->GetData(offset, length, data);
779     ASSERT_EQ(result, piex::kFail);
780     mockInputDataStream.returnValue_ = true;
781     result = rawStream->GetData(offset, length, data);
782     ASSERT_EQ(result, piex::kFail);
783     GTEST_LOG_(INFO) << "RawStreamTest: GetDataTest001 end";
784 }
785 }
786 }