1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include <memory>
18 #include "tiff_parser.h"
19 #include "image_log.h"
20 
21 using namespace OHOS::Media;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace Multimedia {
26 static const std::string IMAGE_INPUT_JPEG_PATH = "/data/local/tmp/image/test_exif.jpg";
27 
28 class TiffParserTest : public testing::Test {
29 public:
TiffParserTest()30     TiffParserTest() {}
~TiffParserTest()31     ~TiffParserTest() {}
32 };
33 
34 HWTEST_F(TiffParserTest, DecodeJpegExif001, TestSize.Level3)
35 {
36     auto exifData = exif_data_new_from_file(IMAGE_INPUT_JPEG_PATH.c_str());
37     ASSERT_NE(exifData, nullptr);
38 
39     unsigned char* buf = nullptr;
40     unsigned int len = 0;
41     exif_data_save_data(exifData, &buf, &len);
42     GTEST_LOG_(INFO) << "TiffParserTest: DecodeJpegExif001" << " buffer length: " << len;
43     ASSERT_NE(len, 0);
44 
45     ExifData *exifData_ = nullptr;
46     TiffParser::DecodeJpegExif(buf, len, &exifData_);
47     ASSERT_NE(exifData_, nullptr);
48 }
49 
50 HWTEST_F(TiffParserTest, EncodeJpegExif001, TestSize.Level3)
51 {
52     TiffParser parser;
53     auto exifData = exif_data_new_from_file(IMAGE_INPUT_JPEG_PATH.c_str());
54     ASSERT_NE(exifData, nullptr);
55 
56     unsigned char* buf = nullptr;
57     unsigned int len = 0;
58     exif_data_save_data(exifData, &buf, &len);
59     ASSERT_NE(len, 0);
60 
61     ExifData *exifData_ = nullptr;
62     parser.DecodeJpegExif(buf, len, &exifData_);
63     ASSERT_NE(exifData_, nullptr);
64 
65     unsigned char *dataPtr = nullptr;
66     uint32_t size;
67     parser.EncodeJpegExif(&dataPtr, size, exifData_);
68     ASSERT_NE(dataPtr, nullptr);
69 }
70 
71 HWTEST_F(TiffParserTest, Decode001, TestSize.Level3)
72 {
73     TiffParser parser;
74     auto exifData = exif_data_new_from_file(IMAGE_INPUT_JPEG_PATH.c_str());
75     ASSERT_NE(exifData, nullptr);
76 
77     unsigned char* buf = nullptr;
78     unsigned int len = 0;
79     exif_data_save_data(exifData, &buf, &len);
80     ASSERT_NE(len, 0);
81 
82     ExifData *exifData_ = nullptr;
83     parser.Decode(buf + 6, len - 6, &exifData_);
84     ASSERT_NE(exifData_, nullptr);
85 }
86 
87 HWTEST_F(TiffParserTest, Encode001, TestSize.Level3)
88 {
89     TiffParser parser;
90     auto exifData = exif_data_new_from_file(IMAGE_INPUT_JPEG_PATH.c_str());
91     ASSERT_NE(exifData, nullptr);
92 
93     unsigned char* buf = nullptr;
94     unsigned int len = 0;
95     exif_data_save_data(exifData, &buf, &len);
96     ASSERT_NE(len, 0);
97 
98     ExifData *exifData_ = nullptr;
99     parser.Decode(buf + 6, len - 6, &exifData_);
100     ASSERT_NE(exifData_, nullptr);
101 
102     unsigned char *dataPtr = nullptr;
103     uint32_t size;
104     parser.Encode(&dataPtr, size, exifData_);
105     ASSERT_NE(dataPtr, nullptr);
106 }
107 } // namespace Multimedia
108 } // namespace OHOS
109