1 /*
2  * Copyright (C) 2021 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 <fcntl.h>
19 #include "image_type.h"
20 #include "image_utils.h"
21 #include "image_source.h"
22 #include "pixel_map.h"
23 #include "image_source_util.h"
24 #include "media_errors.h"
25 #include "bmp_format_agent.h"
26 #include "gif_format_agent.h"
27 #include "heif_format_agent.h"
28 #include "jpeg_format_agent.h"
29 #include "png_format_agent.h"
30 #include "raw_format_agent.h"
31 #include "wbmp_format_agent.h"
32 #include "webp_format_agent.h"
33 
34 using namespace testing::ext;
35 using namespace OHOS::Media;
36 using namespace OHOS::ImageSourceUtil;
37 
38 namespace OHOS {
39 namespace Multimedia {
40 static const std::string IMAGE_INPUT_GIF_PATH = "/data/local/tmp/image/test.gif";
41 static const std::string IMAGE_INPUT_BMP_PATH = "/data/local/tmp/image/test.bmp";
42 static const std::string IMAGE_INPUT_JPG_PATH = "/data/local/tmp/image/test.jpg";
43 static const std::string IMAGE_INPUT_PNG_PATH = "/data/local/tmp/image/test.png";
44 static const std::string IMAGE_INPUT_WEBP_PATH = "/data/local/tmp/image/test.webp";
45 static const std::string BMP_FORMAT_TYPE = "image/bmp";
46 static const std::string GIF_FORMAT_TYPE = "image/gif";
47 static const std::string JPEG_FORMAT_TYPE = "image/jpeg";
48 static const std::string PNG_FORMAT_TYPE = "image/png";
49 static const std::string RAW_FORMAT_TYPE = "image/x-raw";
50 static const std::string WBMP_FORMAT_TYPE = "image/vnd.wap.wbmp";
51 static const std::string WEBP_FORMAT_TYPE = "image/webp";
52 static constexpr uint8_t BMP_HEADER[] = { 0x42, 0x4D };
53 static const uint8_t GIF_STAMP_LEN = 6;
54 static constexpr uint8_t JPEG_HEADER[] = { 0xFF, 0xD8, 0xFF };
55 static constexpr uint8_t PNG_HEADER[] = { 137, 80, 78, 71, 13, 10, 26, 10 };
56 static constexpr uint32_t RAW_HEADER_SIZE = 0;
57 static constexpr uint32_t WBMP_HEADER_SIZE = 32;
58 static constexpr size_t WEBP_MINIMUM_LENGTH = 14;
59 
60 class FormatAgentPluginTest : public testing::Test {
61 public:
FormatAgentPluginTest()62     FormatAgentPluginTest() {}
~FormatAgentPluginTest()63     ~FormatAgentPluginTest() {}
64 };
65 
66 /**
67  * @tc.name: BmpFormatAgentPluginTest001
68  * @tc.desc: bmp GetFormatType
69  * @tc.type: FUNC
70  */
71 HWTEST_F(FormatAgentPluginTest, BmpFormatAgentPluginTest001, TestSize.Level3)
72 {
73     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest001 start";
74     ImagePlugin::BmpFormatAgent formatAgent;
75     std::string ret = formatAgent.GetFormatType();
76     ASSERT_EQ(ret, BMP_FORMAT_TYPE);
77     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest001 end";
78 }
79 
80 /**
81  * @tc.name: BmpFormatAgentPluginTest002
82  * @tc.desc: bmp GetHeaderSize
83  * @tc.type: FUNC
84  */
85 HWTEST_F(FormatAgentPluginTest, BmpFormatAgentPluginTest002, TestSize.Level3)
86 {
87     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest002 start";
88     ImagePlugin::BmpFormatAgent formatAgent;
89     uint32_t ret = formatAgent.GetHeaderSize();
90     ASSERT_EQ(ret, sizeof(BMP_HEADER));
91     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest002 end";
92 }
93 
94 /**
95  * @tc.name: BmpFormatAgentPluginTest003
96  * @tc.desc: bmp CheckFormat
97  * @tc.type: FUNC
98  */
99 HWTEST_F(FormatAgentPluginTest, BmpFormatAgentPluginTest003, TestSize.Level3)
100 {
101     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest003 start";
102     ImagePlugin::BmpFormatAgent formatAgent;
103     uint32_t datasize = formatAgent.GetHeaderSize();
104     void *headerData = nullptr;
105     bool ret = formatAgent.CheckFormat(headerData, datasize);
106     ASSERT_EQ(ret, false);
107     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest003 end";
108 }
109 
110 /**
111  * @tc.name: BmpFormatAgentPluginTest004
112  * @tc.desc: bmp CheckFormat
113  * @tc.type: FUNC
114  */
115 HWTEST_F(FormatAgentPluginTest, BmpFormatAgentPluginTest004, TestSize.Level3)
116 {
117     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest004 start";
118     ImagePlugin::BmpFormatAgent formatAgent;
119     uint32_t datasize = formatAgent.GetHeaderSize();
120     uint32_t errorCode = 0;
121     SourceOptions opts;
122     opts.formatHint = "image/bmp";
123     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_BMP_PATH, opts, errorCode);
124     ASSERT_EQ(errorCode, SUCCESS);
125     ASSERT_NE(imageSource.get(), nullptr);
126 
127     DecodeOptions decodeOpts;
128     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
129     ASSERT_EQ(errorCode, SUCCESS);
130     ASSERT_NE(pixelMap.get(), nullptr);
131 
132     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
133     ASSERT_EQ(ret, false);
134     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest004 end";
135 }
136 
137 /**
138  * @tc.name: BmpFormatAgentPluginTest005
139  * @tc.desc: bmp CheckFormat
140  * @tc.type: FUNC
141  */
142 HWTEST_F(FormatAgentPluginTest, BmpFormatAgentPluginTest005, TestSize.Level3)
143 {
144     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest005 start";
145     ImagePlugin::BmpFormatAgent formatAgent;
146     uint32_t datasize = formatAgent.GetHeaderSize();
147     bool ret = formatAgent.CheckFormat(nullptr, datasize);
148     ASSERT_EQ(ret, false);
149     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest005 end";
150 }
151 
152 /**
153  * @tc.name: BmpFormatAgentPluginTest006
154  * @tc.desc: bmp CheckFormat
155  * @tc.type: FUNC
156  */
157 HWTEST_F(FormatAgentPluginTest, BmpFormatAgentPluginTest006, TestSize.Level3)
158 {
159     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest006 start";
160     ImagePlugin::BmpFormatAgent formatAgent;
161     uint32_t datasize = formatAgent.GetHeaderSize() - 10;
162     uint32_t errorCode = 0;
163     SourceOptions opts;
164     opts.formatHint = "image/bmp";
165     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_BMP_PATH, opts, errorCode);
166     ASSERT_EQ(errorCode, SUCCESS);
167     ASSERT_NE(imageSource.get(), nullptr);
168 
169     DecodeOptions decodeOpts;
170     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
171     ASSERT_EQ(errorCode, SUCCESS);
172     ASSERT_NE(pixelMap.get(), nullptr);
173 
174     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
175     ASSERT_EQ(ret, false);
176     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest006 end";
177 }
178 
179 /**
180  * @tc.name: GifFormatAgentPluginTest001
181  * @tc.desc: Gif GetFormatType
182  * @tc.type: FUNC
183  */
184 HWTEST_F(FormatAgentPluginTest, GifFormatAgentPluginTest001, TestSize.Level3)
185 {
186     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest001 start";
187     ImagePlugin::GifFormatAgent formatAgent;
188     std::string ret = formatAgent.GetFormatType();
189     ASSERT_EQ(ret, GIF_FORMAT_TYPE);
190     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest001 end";
191 }
192 
193 /**
194  * @tc.name: GifFormatAgentPluginTest002
195  * @tc.desc: Gif GetHeaderSize
196  * @tc.type: FUNC
197  */
198 HWTEST_F(FormatAgentPluginTest, GifFormatAgentPluginTest002, TestSize.Level3)
199 {
200     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest002 start";
201     ImagePlugin::GifFormatAgent formatAgent;
202     uint32_t ret = formatAgent.GetHeaderSize();
203     ASSERT_EQ(ret, GIF_STAMP_LEN);
204     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest002 end";
205 }
206 
207 /**
208  * @tc.name: GifFormatAgentPluginTest003
209  * @tc.desc: Gif CheckFormat
210  * @tc.type: FUNC
211  */
212 HWTEST_F(FormatAgentPluginTest, GifFormatAgentPluginTest003, TestSize.Level3)
213 {
214     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest003 start";
215     ImagePlugin::GifFormatAgent formatAgent;
216     uint32_t datasize = formatAgent.GetHeaderSize();
217     void *headerData = nullptr;
218     bool ret = formatAgent.CheckFormat(headerData, datasize);
219     ASSERT_EQ(ret, false);
220     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest003 end";
221 }
222 
223 /**
224  * @tc.name: GifFormatAgentPluginTest005
225  * @tc.desc: Gif CheckFormat
226  * @tc.type: FUNC
227  */
228 HWTEST_F(FormatAgentPluginTest, GifFormatAgentPluginTest005, TestSize.Level3)
229 {
230     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest005 start";
231     ImagePlugin::GifFormatAgent formatAgent;
232     uint32_t datasize = formatAgent.GetHeaderSize();
233     bool ret = formatAgent.CheckFormat(nullptr, datasize);
234     ASSERT_EQ(ret, false);
235     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest005 end";
236 }
237 
238 /**
239  * @tc.name: JpegFormatAgentPluginTest001
240  * @tc.desc: Jpeg GetFormatType
241  * @tc.type: FUNC
242  */
243 HWTEST_F(FormatAgentPluginTest, JpegFormatAgentPluginTest001, TestSize.Level3)
244 {
245     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest001 start";
246     ImagePlugin::JpegFormatAgent formatAgent;
247     std::string ret = formatAgent.GetFormatType();
248     ASSERT_EQ(ret, JPEG_FORMAT_TYPE);
249     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest001 end";
250 }
251 
252 /**
253  * @tc.name: JpegFormatAgentPluginTest002
254  * @tc.desc: Jpeg GetHeaderSize
255  * @tc.type: FUNC
256  */
257 HWTEST_F(FormatAgentPluginTest, JpegFormatAgentPluginTest002, TestSize.Level3)
258 {
259     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest002 start";
260     ImagePlugin::JpegFormatAgent formatAgent;
261     uint32_t ret = formatAgent.GetHeaderSize();
262     ASSERT_EQ(ret, sizeof(JPEG_HEADER));
263     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest002 end";
264 }
265 
266 /**
267  * @tc.name: JpegFormatAgentPluginTest003
268  * @tc.desc: Jpeg CheckFormat
269  * @tc.type: FUNC
270  */
271 HWTEST_F(FormatAgentPluginTest, JpegFormatAgentPluginTest003, TestSize.Level3)
272 {
273     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest003 start";
274     ImagePlugin::JpegFormatAgent formatAgent;
275     uint32_t datasize = formatAgent.GetHeaderSize();
276     void *headerData = nullptr;
277     bool ret = formatAgent.CheckFormat(headerData, datasize);
278     ASSERT_EQ(ret, false);
279     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest003 end";
280 }
281 
282 /**
283  * @tc.name: JpegFormatAgentPluginTest004
284  * @tc.desc: Jpeg CheckFormat
285  * @tc.type: FUNC
286  */
287 HWTEST_F(FormatAgentPluginTest, JpegFormatAgentPluginTest004, TestSize.Level3)
288 {
289     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest004 start";
290     ImagePlugin::JpegFormatAgent formatAgent;
291     uint32_t datasize = formatAgent.GetHeaderSize();
292     uint32_t errorCode = 0;
293     SourceOptions opts;
294     opts.formatHint = "image/jpeg";
295     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_JPG_PATH, opts, errorCode);
296     ASSERT_EQ(errorCode, SUCCESS);
297     ASSERT_NE(imageSource.get(), nullptr);
298 
299     DecodeOptions decodeOpts;
300     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
301     ASSERT_EQ(errorCode, SUCCESS);
302     ASSERT_NE(pixelMap.get(), nullptr);
303 
304     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
305     ASSERT_EQ(ret, false);
306     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest004 end";
307 }
308 
309 /**
310  * @tc.name: JpegFormatAgentPluginTest005
311  * @tc.desc: Jpeg CheckFormat
312  * @tc.type: FUNC
313  */
314 HWTEST_F(FormatAgentPluginTest, JpegFormatAgentPluginTest005, TestSize.Level3)
315 {
316     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest005 start";
317     ImagePlugin::JpegFormatAgent formatAgent;
318     uint32_t datasize = formatAgent.GetHeaderSize();
319     bool ret = formatAgent.CheckFormat(nullptr, datasize);
320     ASSERT_EQ(ret, false);
321     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest005 end";
322 }
323 
324 /**
325  * @tc.name: JpegFormatAgentPluginTest006
326  * @tc.desc: Jpeg CheckFormat
327  * @tc.type: FUNC
328  */
329 HWTEST_F(FormatAgentPluginTest, JpegFormatAgentPluginTest006, TestSize.Level3)
330 {
331     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest006 start";
332     ImagePlugin::JpegFormatAgent formatAgent;
333     uint32_t datasize = formatAgent.GetHeaderSize() - 10;
334     uint32_t errorCode = 0;
335     SourceOptions opts;
336     opts.formatHint = "image/jpeg";
337     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_JPG_PATH, opts, errorCode);
338     ASSERT_EQ(errorCode, SUCCESS);
339     ASSERT_NE(imageSource.get(), nullptr);
340 
341     DecodeOptions decodeOpts;
342     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
343     ASSERT_EQ(errorCode, SUCCESS);
344     ASSERT_NE(pixelMap.get(), nullptr);
345 
346     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
347     ASSERT_EQ(ret, false);
348     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest006 end";
349 }
350 
351 /**
352  * @tc.name: PngFormatAgentPluginTest001
353  * @tc.desc: Png GetFormatType
354  * @tc.type: FUNC
355  */
356 HWTEST_F(FormatAgentPluginTest, PngFormatAgentPluginTest001, TestSize.Level3)
357 {
358     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest001 start";
359     ImagePlugin::PngFormatAgent formatAgent;
360     std::string ret = formatAgent.GetFormatType();
361     ASSERT_EQ(ret, PNG_FORMAT_TYPE);
362     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest001 end";
363 }
364 
365 /**
366  * @tc.name: PngFormatAgentPluginTest002
367  * @tc.desc: Png GetHeaderSize
368  * @tc.type: FUNC
369  */
370 HWTEST_F(FormatAgentPluginTest, PngFormatAgentPluginTest002, TestSize.Level3)
371 {
372     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest002 start";
373     ImagePlugin::PngFormatAgent formatAgent;
374     uint32_t ret = formatAgent.GetHeaderSize();
375     ASSERT_EQ(ret, sizeof(PNG_HEADER));
376     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest002 end";
377 }
378 
379 /**
380  * @tc.name: PngFormatAgentPluginTest003
381  * @tc.desc: Png CheckFormat
382  * @tc.type: FUNC
383  */
384 HWTEST_F(FormatAgentPluginTest, PngFormatAgentPluginTest003, TestSize.Level3)
385 {
386     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest003 start";
387     ImagePlugin::PngFormatAgent formatAgent;
388     uint32_t datasize = formatAgent.GetHeaderSize();
389     void *headerData = nullptr;
390     bool ret = formatAgent.CheckFormat(headerData, datasize);
391     ASSERT_EQ(ret, false);
392     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest003 end";
393 }
394 
395 /**
396  * @tc.name: PngFormatAgentPluginTest004
397  * @tc.desc: Png CheckFormat
398  * @tc.type: FUNC
399  */
400 HWTEST_F(FormatAgentPluginTest, PngFormatAgentPluginTest004, TestSize.Level3)
401 {
402     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest004 start";
403     ImagePlugin::PngFormatAgent formatAgent;
404     uint32_t datasize = formatAgent.GetHeaderSize();
405     uint32_t errorCode = 0;
406     SourceOptions opts;
407     opts.formatHint = "image/png";
408     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_PNG_PATH, opts, errorCode);
409     ASSERT_EQ(errorCode, SUCCESS);
410     ASSERT_NE(imageSource.get(), nullptr);
411 
412     DecodeOptions decodeOpts;
413     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
414     ASSERT_EQ(errorCode, SUCCESS);
415     ASSERT_NE(pixelMap.get(), nullptr);
416 
417     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
418     ASSERT_EQ(ret, false);
419     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest004 end";
420 }
421 
422 /**
423  * @tc.name: PngFormatAgentPluginTest005
424  * @tc.desc: Png CheckFormat
425  * @tc.type: FUNC
426  */
427 HWTEST_F(FormatAgentPluginTest, PngFormatAgentPluginTest005, TestSize.Level3)
428 {
429     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest005 start";
430     ImagePlugin::PngFormatAgent formatAgent;
431     uint32_t datasize = formatAgent.GetHeaderSize();
432     bool ret = formatAgent.CheckFormat(nullptr, datasize);
433     ASSERT_EQ(ret, false);
434     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest005 end";
435 }
436 
437 /**
438  * @tc.name: PngFormatAgentPluginTest006
439  * @tc.desc: Png CheckFormat
440  * @tc.type: FUNC
441  */
442 HWTEST_F(FormatAgentPluginTest, PngFormatAgentPluginTest006, TestSize.Level3)
443 {
444     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest006 start";
445     ImagePlugin::PngFormatAgent formatAgent;
446     uint32_t datasize = formatAgent.GetHeaderSize() - 10;
447     uint32_t errorCode = 0;
448     SourceOptions opts;
449     opts.formatHint = "image/png";
450     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_PNG_PATH, opts, errorCode);
451     ASSERT_EQ(errorCode, SUCCESS);
452     ASSERT_NE(imageSource.get(), nullptr);
453 
454     DecodeOptions decodeOpts;
455     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
456     ASSERT_EQ(errorCode, SUCCESS);
457     ASSERT_NE(pixelMap.get(), nullptr);
458 
459     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
460     ASSERT_EQ(ret, false);
461     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest006 end";
462 }
463 
464 /**
465  * @tc.name: RawFormatAgentPluginTest001
466  * @tc.desc: Raw GetFormatType
467  * @tc.type: FUNC
468  */
469 HWTEST_F(FormatAgentPluginTest, RawFormatAgentPluginTest001, TestSize.Level3)
470 {
471     GTEST_LOG_(INFO) << "FormatAgentPluginTest: RawFormatAgentPluginTest001 start";
472     ImagePlugin::RawFormatAgent formatAgent;
473     std::string ret = formatAgent.GetFormatType();
474     ASSERT_EQ(ret, RAW_FORMAT_TYPE);
475     GTEST_LOG_(INFO) << "FormatAgentPluginTest: RawFormatAgentPluginTest001 end";
476 }
477 
478 /**
479  * @tc.name: RawFormatAgentPluginTest002
480  * @tc.desc: Raw GetHeaderSize
481  * @tc.type: FUNC
482  */
483 HWTEST_F(FormatAgentPluginTest, RawFormatAgentPluginTest002, TestSize.Level3)
484 {
485     GTEST_LOG_(INFO) << "FormatAgentPluginTest: RawFormatAgentPluginTest002 start";
486     ImagePlugin::RawFormatAgent formatAgent;
487     uint32_t ret = formatAgent.GetHeaderSize();
488     ASSERT_EQ(ret, RAW_HEADER_SIZE);
489     GTEST_LOG_(INFO) << "FormatAgentPluginTest: RawFormatAgentPluginTest002 end";
490 }
491 
492 /**
493  * @tc.name: RawFormatAgentPluginTest003
494  * @tc.desc: Raw CheckFormat
495  * @tc.type: FUNC
496  */
497 HWTEST_F(FormatAgentPluginTest, RawFormatAgentPluginTest003, TestSize.Level3)
498 {
499     GTEST_LOG_(INFO) << "FormatAgentPluginTest: RawFormatAgentPluginTest003 start";
500     ImagePlugin::RawFormatAgent formatAgent;
501     uint32_t datasize = formatAgent.GetHeaderSize();
502     void *headerData = nullptr;
503     bool ret = formatAgent.CheckFormat(headerData, datasize);
504     ASSERT_EQ(ret, true);
505     GTEST_LOG_(INFO) << "FormatAgentPluginTest: RawFormatAgentPluginTest003 end";
506 }
507 
508 /**
509  * @tc.name: WbmpFormatAgentPluginTest001
510  * @tc.desc: Wbmp GetFormatType
511  * @tc.type: FUNC
512  */
513 HWTEST_F(FormatAgentPluginTest, WbmpFormatAgentPluginTest001, TestSize.Level3)
514 {
515     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest001 start";
516     ImagePlugin::WbmpFormatAgent formatAgent;
517     std::string ret = formatAgent.GetFormatType();
518     ASSERT_EQ(ret, WBMP_FORMAT_TYPE);
519     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest001 end";
520 }
521 
522 /**
523  * @tc.name: WbmpFormatAgentPluginTest002
524  * @tc.desc: Wbmp GetHeaderSize
525  * @tc.type: FUNC
526  */
527 HWTEST_F(FormatAgentPluginTest, WbmpFormatAgentPluginTest002, TestSize.Level3)
528 {
529     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest002 start";
530     ImagePlugin::WbmpFormatAgent formatAgent;
531     uint32_t ret = formatAgent.GetHeaderSize();
532     ASSERT_EQ(ret, WBMP_HEADER_SIZE);
533     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest002 end";
534 }
535 
536 /**
537  * @tc.name: WbmpFormatAgentPluginTest003
538  * @tc.desc: Wbmp CheckFormat
539  * @tc.type: FUNC
540  */
541 HWTEST_F(FormatAgentPluginTest, WbmpFormatAgentPluginTest003, TestSize.Level3)
542 {
543     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest003 start";
544     ImagePlugin::WbmpFormatAgent formatAgent;
545     uint32_t datasize = formatAgent.GetHeaderSize();
546     void *headerData = nullptr;
547     bool ret = formatAgent.CheckFormat(headerData, datasize);
548     ASSERT_EQ(ret, false);
549     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest003 end";
550 }
551 
552 /**
553  * @tc.name: WbmpFormatAgentPluginTest005
554  * @tc.desc: Wbmp CheckFormat
555  * @tc.type: FUNC
556  */
557 HWTEST_F(FormatAgentPluginTest, WbmpFormatAgentPluginTest005, TestSize.Level3)
558 {
559     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest005 start";
560     ImagePlugin::WbmpFormatAgent formatAgent;
561     uint32_t datasize = formatAgent.GetHeaderSize();
562     bool ret = formatAgent.CheckFormat(nullptr, datasize);
563     ASSERT_EQ(ret, false);
564     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WbmpFormatAgentPluginTest005 end";
565 }
566 
567 /**
568  * @tc.name: WebpFormatAgentPluginTest001
569  * @tc.desc: Webp GetFormatType
570  * @tc.type: FUNC
571  */
572 HWTEST_F(FormatAgentPluginTest, WebpFormatAgentPluginTest001, TestSize.Level3)
573 {
574     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest001 start";
575     ImagePlugin::WebpFormatAgent formatAgent;
576     std::string ret = formatAgent.GetFormatType();
577     ASSERT_EQ(ret, WEBP_FORMAT_TYPE);
578     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest001 end";
579 }
580 
581 /**
582  * @tc.name: WebpFormatAgentPluginTest002
583  * @tc.desc: Webp GetHeaderSize
584  * @tc.type: FUNC
585  */
586 HWTEST_F(FormatAgentPluginTest, WebpFormatAgentPluginTest002, TestSize.Level3)
587 {
588     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest002 start";
589     ImagePlugin::WebpFormatAgent formatAgent;
590     uint32_t ret = formatAgent.GetHeaderSize();
591     ASSERT_EQ(ret, WEBP_MINIMUM_LENGTH);
592     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest002 end";
593 }
594 
595 /**
596  * @tc.name: WebpFormatAgentPluginTest003
597  * @tc.desc: Webp CheckFormat
598  * @tc.type: FUNC
599  */
600 HWTEST_F(FormatAgentPluginTest, WebpFormatAgentPluginTest003, TestSize.Level3)
601 {
602     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest003 start";
603     ImagePlugin::WebpFormatAgent formatAgent;
604     uint32_t datasize = formatAgent.GetHeaderSize();
605     void *headerData = nullptr;
606     bool ret = formatAgent.CheckFormat(headerData, datasize);
607     ASSERT_EQ(ret, false);
608     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest003 end";
609 }
610 
611 /**
612  * @tc.name: WebpFormatAgentPluginTest004
613  * @tc.desc: Webp CheckFormat
614  * @tc.type: FUNC
615  */
616 HWTEST_F(FormatAgentPluginTest, WebpFormatAgentPluginTest004, TestSize.Level3)
617 {
618     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest004 start";
619     ImagePlugin::WebpFormatAgent formatAgent;
620     uint32_t datasize = formatAgent.GetHeaderSize();
621     uint32_t errorCode = 0;
622     SourceOptions opts;
623     opts.formatHint = "image/webp";
624     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_WEBP_PATH, opts, errorCode);
625     ASSERT_EQ(errorCode, SUCCESS);
626     ASSERT_NE(imageSource.get(), nullptr);
627 
628     DecodeOptions decodeOpts;
629     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
630     ASSERT_EQ(errorCode, SUCCESS);
631     ASSERT_NE(pixelMap.get(), nullptr);
632 
633     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
634     ASSERT_EQ(ret, false);
635     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest004 end";
636 }
637 
638 /**
639  * @tc.name: WebpFormatAgentPluginTest005
640  * @tc.desc: Webp CheckFormat
641  * @tc.type: FUNC
642  */
643 HWTEST_F(FormatAgentPluginTest, WebpFormatAgentPluginTest0045, TestSize.Level3)
644 {
645     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest005 start";
646     ImagePlugin::WebpFormatAgent formatAgent;
647     uint32_t datasize = 0;
648     uint32_t errorCode = 0;
649     SourceOptions opts;
650     opts.formatHint = "image/webp";
651     std::unique_ptr<ImageSource> imageSource = ImageSource::CreateImageSource(IMAGE_INPUT_WEBP_PATH, opts, errorCode);
652     ASSERT_EQ(errorCode, SUCCESS);
653     ASSERT_NE(imageSource.get(), nullptr);
654 
655     DecodeOptions decodeOpts;
656     std::unique_ptr<PixelMap> pixelMap = imageSource->CreatePixelMap(decodeOpts, errorCode);
657     ASSERT_EQ(errorCode, SUCCESS);
658     ASSERT_NE(pixelMap.get(), nullptr);
659 
660     bool ret = formatAgent.CheckFormat(pixelMap->GetPixels(), datasize);
661     ASSERT_EQ(ret, false);
662     GTEST_LOG_(INFO) << "FormatAgentPluginTest: WebpFormatAgentPluginTest005 end";
663 }
664 
665 /**
666  * @tc.name: read_byte001
667  * @tc.desc: Webp read_byte
668  * @tc.type: FUNC
669  */
670 HWTEST_F(FormatAgentPluginTest, read_byte001, TestSize.Level3)
671 {
672     GTEST_LOG_(INFO) << "FormatAgentPluginTest: read_byte001 start";
673     auto formatAgent = std::make_shared<ImagePlugin::WbmpFormatAgent>();
674     uint8_t *stream = new uint8_t(1);
675     uint8_t value = 1;
676     uint32_t offset = 1;
677     uint32_t dataSize = 0;
678     bool ret = formatAgent->read_byte(stream, value, offset, dataSize);
679     ASSERT_EQ(ret, false);
680     ret = formatAgent->read_byte(stream, value, offset, 20);
681     ASSERT_EQ(ret, true);
682     delete stream;
683     stream = nullptr;
684     GTEST_LOG_(INFO) << "FormatAgentPluginTest: read_byte001 end";
685 }
686 
687 /**
688  * @tc.name: read_mbf001
689  * @tc.desc: Webp read_mbf
690  * @tc.type: FUNC
691  */
692 HWTEST_F(FormatAgentPluginTest, read_mbf001, TestSize.Level3)
693 {
694     GTEST_LOG_(INFO) << "FormatAgentPluginTest: read_mbf001 start";
695     ImagePlugin::WbmpFormatAgent formatAgent;
696     uint8_t *stream = new uint8_t(1);
697     uint64_t value = 1;
698     uint32_t offset = 1;
699     uint32_t dataSize = 0;
700     bool ret = formatAgent.read_mbf(stream, value, offset, dataSize);
701     ASSERT_EQ(ret, false);
702     ret = formatAgent.read_mbf(stream, value, offset, 2);
703     ASSERT_EQ(ret, true);
704     delete stream;
705     stream = nullptr;
706     GTEST_LOG_(INFO) << "FormatAgentPluginTest: read_mbf001 end";
707 }
708 
709 /**
710  * @tc.name: GifFormatAgentPluginTest004
711  * @tc.desc: Gif CheckFormat
712  * @tc.type: FUNC
713  */
714 HWTEST_F(FormatAgentPluginTest, GifFormatAgentPluginTest004, TestSize.Level3)
715 {
716     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest004 start";
717     ImagePlugin::GifFormatAgent formatAgent;
718     void *headerData = nullptr;
719     uint32_t dataSize = 1;
720     bool ret = formatAgent.CheckFormat(headerData, dataSize);
721     ASSERT_EQ(ret, false);
722 
723     uint32_t data = 0;
724     headerData = &data;
725     ASSERT_NE(headerData, nullptr);
726     ret = formatAgent.CheckFormat(headerData, dataSize);
727     ASSERT_EQ(ret, false);
728 
729     dataSize = 7;
730     ret = formatAgent.CheckFormat(headerData, dataSize);
731     ASSERT_EQ(ret, false);
732 
733     char stamp[] = "GIF87a";
734     headerData = &stamp;
735     ret = formatAgent.CheckFormat(headerData, dataSize);
736     ASSERT_EQ(ret, true);
737     GTEST_LOG_(INFO) << "FormatAgentPluginTest: GifFormatAgentPluginTest004 end";
738 }
739 
740 /**
741  * @tc.name: BmpFormatAgentPluginTest007
742  * @tc.desc: bmp CheckFormat
743  * @tc.type: FUNC
744  */
745 HWTEST_F(FormatAgentPluginTest, BmpFormatAgentPluginTest007, TestSize.Level3)
746 {
747     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest007 start";
748     ImagePlugin::BmpFormatAgent formatAgent;
749     void *headerData = nullptr;
750     uint32_t dataSize = 1;
751     bool ret = formatAgent.CheckFormat(headerData, dataSize);
752     ASSERT_EQ(ret, false);
753 
754     ASSERT_EQ(sizeof(BMP_HEADER), 2);
755     uint32_t data = 0;
756     headerData = &data;
757     ASSERT_NE(headerData, nullptr);
758     ret = formatAgent.CheckFormat(headerData, dataSize);
759     ASSERT_EQ(ret, false);
760 
761     dataSize = 3;
762     ret = formatAgent.CheckFormat(headerData, dataSize);
763     ASSERT_EQ(ret, false);
764 
765     uint8_t bmpHeader[] = { 0x42, 0x4D };
766     headerData = &bmpHeader;
767     ret = formatAgent.CheckFormat(headerData, dataSize);
768     ASSERT_EQ(ret, true);
769     GTEST_LOG_(INFO) << "FormatAgentPluginTest: BmpFormatAgentPluginTest007 end";
770 }
771 
772 /**
773  * @tc.name: PngFormatAgentPluginTest007
774  * @tc.desc: Png CheckFormat
775  * @tc.type: FUNC
776  */
777 HWTEST_F(FormatAgentPluginTest, PngFormatAgentPluginTest007, TestSize.Level3)
778 {
779     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest007 start";
780     ImagePlugin::PngFormatAgent formatAgent;
781     uint32_t data = 0;
782     void *headerData = &data;
783     ASSERT_NE(headerData, nullptr);
784     uint32_t dataSize = 1;
785     ASSERT_EQ(sizeof(PNG_HEADER), 8);
786     bool ret = formatAgent.CheckFormat(headerData, dataSize);
787     ASSERT_EQ(ret, false);
788     GTEST_LOG_(INFO) << "FormatAgentPluginTest: PngFormatAgentPluginTest007 end";
789 }
790 
791 /**
792  * @tc.name: JpegFormatAgentPluginTest007
793  * @tc.desc: Jpeg CheckFormat
794  * @tc.type: FUNC
795  */
796 HWTEST_F(FormatAgentPluginTest, JpegFormatAgentPluginTest007, TestSize.Level3)
797 {
798     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest007 start";
799     ImagePlugin::JpegFormatAgent formatAgent;
800     uint32_t data = 0;
801     void *headerData = &data;
802     ASSERT_NE(headerData, nullptr);
803     uint32_t dataSize = 2;
804     ASSERT_EQ(sizeof(JPEG_HEADER), 3);
805     bool ret = formatAgent.CheckFormat(headerData, dataSize);
806     ASSERT_EQ(ret, false);
807     GTEST_LOG_(INFO) << "FormatAgentPluginTest: JpegFormatAgentPluginTest007 end";
808 }
809 }
810 }