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