• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define private public
17 #define protected public
18 #include <gtest/gtest.h>
19 #include "heif_box.h"
20 #include "item_data_box.h"
21 #include "item_info_box.h"
22 #include "item_property_basic_box.h"
23 #include "item_property_box.h"
24 #include "item_property_color_box.h"
25 #include "item_property_hvcc_box.h"
26 #include "item_property_transform_box.h"
27 #include "item_ref_box.h"
28 
29 using namespace testing::ext;
30 namespace OHOS {
31 namespace ImagePlugin {
32 static constexpr size_t ERR_LENGTH = -1;
33 static constexpr size_t NORMAL_LENGTH = 1;
34 static constexpr size_t SIZE_32BITS = 0xFFFFFFFF;
35 static constexpr size_t UUID_TYPE_BYTE_NUM = 16;
36 static constexpr uint32_t NAL_LAYER_ID = 33;
37 static constexpr uint8_t SKIP_DOUBLE_DATA_PROCESS_BYTE = 2;
38 
SetUint32ToUint8Vertor(uint32_t data)39 static std::vector<uint8_t> SetUint32ToUint8Vertor(uint32_t data)
40 {
41     std::vector<uint8_t> res = {
42         static_cast<uint8_t>((data >> 24) & 0xFF),
43         static_cast<uint8_t>((data >> 16) & 0xFF),
44         static_cast<uint8_t>((data >> 8) & 0xFF),
45         static_cast<uint8_t>(data & 0xFF)
46     };
47     return res;
48 }
49 
ProcessBoxData(std::vector<uint8_t> & nalu)50 static void ProcessBoxData(std::vector<uint8_t> &nalu)
51 {
52     uint32_t naluSize = nalu.size();
53     std::vector<uint32_t> indicesToDelete;
54     for (uint32_t i = UINT16_BYTES_NUM; i < naluSize; ++i) {
55         if (nalu[i - UINT8_BYTES_NUM] == 0x00 &&
56             nalu[i - SKIP_DOUBLE_DATA_PROCESS_BYTE] == 0x00 && nalu[i] == 0x03) {
57             indicesToDelete.push_back(i);
58         }
59     }
60     for (auto it = indicesToDelete.rbegin(); it != indicesToDelete.rend(); ++it) {
61         nalu.erase(nalu.begin() + *it);
62     }
63 }
64 
65 class HeifParserBoxTest : public testing::Test {
66 public:
HeifParserBoxTest()67     HeifParserBoxTest() {}
~HeifParserBoxTest()68     ~HeifParserBoxTest() {}
69 };
70 
71 /**
72  * @tc.name: ParseContentTest001
73  * @tc.desc: HeifImirBox
74  * @tc.type: FUNC
75  */
76 HWTEST_F(HeifParserBoxTest, ParseContentTest001, TestSize.Level3)
77 {
78     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest001 start";
79     HeifImirBox heifImirBox;
80     auto stream = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
81     HeifStreamReader reader(stream, 0, 0);
82     heif_error ret = heifImirBox.ParseContent(reader);
83     ASSERT_NE(ret, heif_error_ok);
84     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest001 end";
85 }
86 
87 /**
88  * @tc.name: WriteTest001
89  * @tc.desc: HeifImirBox
90  * @tc.type: FUNC
91  */
92 HWTEST_F(HeifParserBoxTest, WriteTest001, TestSize.Level3)
93 {
94     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest001 start";
95     HeifImirBox heifImirBox;
96     heifImirBox.direction_ = HeifTransformMirrorDirection::INVALID;
97     HeifStreamWriter write;
98     heif_error ret = heifImirBox.Write(write);
99     ASSERT_EQ(ret, heif_invalid_mirror_direction);
100     heifImirBox.direction_ = HeifTransformMirrorDirection::HORIZONTAL;
101     ret = heifImirBox.Write(write);
102     ASSERT_EQ(ret, heif_error_ok);
103     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest001 end";
104 }
105 
106 /**
107  * @tc.name: WriteTest002
108  * @tc.desc: HeifNclxColorProfile
109  * @tc.type: FUNC
110  */
111 HWTEST_F(HeifParserBoxTest, WriteTest002, TestSize.Level3)
112 {
113     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest002 start";
114     HeifNclxColorProfile heifNclx(0, 0, 0, 0);
115     HeifStreamWriter write;
116     heif_error ret = heifNclx.Write(write);
117     ASSERT_EQ(ret, heif_error_ok);
118     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest002 end";
119 }
120 
121 /**
122  * @tc.name: GetPropertyTest001
123  * @tc.desc: HeifIpcoBox
124  * @tc.type: FUNC
125  */
126 HWTEST_F(HeifParserBoxTest, GetPropertyTest001, TestSize.Level3)
127 {
128     GTEST_LOG_(INFO) << "HeifParserBoxTest: GetPropertyTest001 start";
129     auto heifIpcoBox = std::make_shared<HeifIpcoBox>();
130     std::shared_ptr<HeifIpmaBox> heifIpmaBox = std::make_shared<HeifIpmaBox>();
131     heif_item_id itemId = 1;
132     uint32_t boxType = 0;
133     struct PropertyAssociation rec {
134         .essential = false,
135         .propertyIndex = 0,
136     };
137     std::vector<PropertyAssociation> proPerty;
138     proPerty.push_back(rec);
139     struct PropertyEntry ref {
140         .itemId = 0,
141         .associations = proPerty,
142     };
143     heifIpmaBox->entries_.push_back(ref);
144     EXPECT_EQ(heifIpcoBox->GetProperty(itemId, heifIpmaBox, boxType), nullptr);
145     itemId = 0;
146     EXPECT_EQ(heifIpcoBox->GetProperty(itemId, heifIpmaBox, boxType), nullptr);
147     heifIpmaBox->entries_.clear();
148     rec.propertyIndex = 1;
149     proPerty.push_back(rec);
150     ref.associations = proPerty;
151     heifIpmaBox->entries_.push_back(ref);
152     std::shared_ptr<HeifBox> heifBox = std::make_shared<HeifBox>(0);
153     heifIpcoBox->children_.push_back(heifBox);
154     heifIpcoBox->GetProperty(itemId, heifIpmaBox, boxType);
155     boxType = 1;
156     EXPECT_EQ(heifIpcoBox->GetProperty(itemId, heifIpmaBox, boxType), nullptr);
157     GTEST_LOG_(INFO) << "HeifParserBoxTest: GetPropertyTest001 end";
158 }
159 
160 /**
161  * @tc.name: GetPropertiesTest001
162  * @tc.desc: HeifIpcoBox
163  * @tc.type: FUNC
164  */
165 HWTEST_F(HeifParserBoxTest, GetPropertiesTest001, TestSize.Level3)
166 {
167     GTEST_LOG_(INFO) << "HeifParserBoxTest: GetPropertiesTest001 start";
168     auto heifIpcoBox = std::make_shared<HeifIpcoBox>();
169     uint32_t itemId = 1;
170     std::shared_ptr<HeifIpmaBox> ipma = std::make_shared<HeifIpmaBox>();
171     std::vector<std::shared_ptr<HeifBox>> outProperties;
172     struct PropertyAssociation rec {
173         .essential = false,
174         .propertyIndex = 16,
175     };
176     std::vector<PropertyAssociation> proPerty;
177     proPerty.push_back(rec);
178     struct PropertyEntry ref {
179         .itemId = 0,
180         .associations = proPerty,
181     };
182     ipma->entries_.push_back(ref);
183     EXPECT_EQ(heifIpcoBox->GetProperties(itemId, ipma, outProperties), heif_error_property_not_found);
184     itemId = 0;
185     EXPECT_EQ(heifIpcoBox->GetProperties(itemId, ipma, outProperties), heif_error_invalid_property_index);
186     GTEST_LOG_(INFO) << "HeifParserBoxTest: GetPropertiesTest001 end";
187 }
188 
189 /**
190  * @tc.name: GetPropertiesTest002
191  * @tc.desc: HeifIpmaBox
192  * @tc.type: FUNC
193  */
194 HWTEST_F(HeifParserBoxTest, GetPropertiesTest002, TestSize.Level3)
195 {
196     GTEST_LOG_(INFO) << "HeifParserBoxTest: GetPropertiesTest002 start";
197     auto heifIpmaBox = std::make_shared<HeifIpmaBox>();
198     uint32_t itemId = 1;
199     struct PropertyEntry ref {.itemId = 0};
200     heifIpmaBox->entries_.push_back(ref);
201     EXPECT_EQ(heifIpmaBox->GetProperties(itemId), nullptr);
202     GTEST_LOG_(INFO) << "HeifParserBoxTest: GetPropertiesTest002 end";
203 }
204 
205 /**
206  * @tc.name: InferFullBoxVersionTest001
207  * @tc.desc: HeifIpmaBox
208  * @tc.type: FUNC
209  */
210 HWTEST_F(HeifParserBoxTest, InferFullBoxVersionTest001, TestSize.Level3)
211 {
212     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferFullBoxVersionTest001 start";
213     auto heifIpmaBox = std::make_shared<HeifIpmaBox>();
214     struct PropertyEntry ref {.itemId = 0xFFFFFFFF};
215     heifIpmaBox->entries_.push_back(ref);
216     heifIpmaBox->InferFullBoxVersion();
217     EXPECT_EQ(heifIpmaBox->version_, HEIF_BOX_VERSION_ONE);
218     heifIpmaBox->entries_.clear();
219     struct PropertyAssociation rec {
220         .essential = false,
221         .propertyIndex = 0x8F,
222     };
223     std::vector<PropertyAssociation> proPerty;
224     proPerty.push_back(rec);
225     ref.itemId = 0xFF00;
226     ref.associations = proPerty;
227     heifIpmaBox->entries_.push_back(ref);
228     heifIpmaBox->InferFullBoxVersion();
229     EXPECT_EQ(heifIpmaBox->version_, HEIF_BOX_VERSION_ZERO);
230     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferFullBoxVersionTest001 end";
231 }
232 
233 /**
234  * @tc.name: ParseItemRefTest001
235  * @tc.desc: HeifIrefBox
236  * @tc.type: FUNC
237  */
238 HWTEST_F(HeifParserBoxTest, ParseItemRefTest001, TestSize.Level3)
239 {
240     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseItemRefTest001 start";
241     auto heifIrefBox = std::make_shared<HeifIrefBox>();
242     auto inputStream = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
243     HeifStreamReader reader(inputStream, 0, 0);
244     HeifIrefBox::Reference ref;
245     heifIrefBox->version_ = 1;
246     heifIrefBox->ParseItemRef(reader, ref);
247     ASSERT_EQ(ref.toItemIds.size(), 0);
248     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseItemRefTest001 end";
249 }
250 
251 /**
252  * @tc.name: InferFullBoxVersionTest002
253  * @tc.desc: HeifIrefBox
254  * @tc.type: FUNC
255  */
256 HWTEST_F(HeifParserBoxTest, InferFullBoxVersionTest002, TestSize.Level3)
257 {
258     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferFullBoxVersionTest002 start";
259     auto heifIrefBox = std::make_shared<HeifIrefBox>();
260     struct HeifIrefBox::Reference ref {.fromItemId = 0xFFFFFFFF};
261     heifIrefBox->references_.push_back(ref);
262     EXPECT_TRUE((0xFFFFFFFF >> TWO_BYTES_SHIFT) > 0);
263     heifIrefBox->InferFullBoxVersion();
264     heifIrefBox->references_.clear();
265     ref.fromItemId = 0x00000000;
266     ref.toItemIds.push_back(0xFFFFFFFF);
267     heifIrefBox->references_.push_back(ref);
268     EXPECT_TRUE((0x00000000 >> TWO_BYTES_SHIFT) == 0);
269     heifIrefBox->InferFullBoxVersion();
270     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferFullBoxVersionTest002 end";
271 }
272 
273 /**
274  * @tc.name: HasReferencesTest001
275  * @tc.desc: HeifIrefBox
276  * @tc.type: FUNC
277  */
278 HWTEST_F(HeifParserBoxTest, HasReferencesTest001, TestSize.Level3)
279 {
280     GTEST_LOG_(INFO) << "HeifParserBoxTest: HasReferencesTest001 start";
281     auto heifIrefBox = std::make_shared<HeifIrefBox>();
282     heif_item_id itemId = 0;
283     struct HeifIrefBox::Reference ref {.fromItemId = 0};
284     heifIrefBox->references_.push_back(ref);
285     EXPECT_EQ(heifIrefBox->HasReferences(itemId), true);
286     heifIrefBox->references_.clear();
287     ref.fromItemId = 1;
288     heifIrefBox->references_.push_back(ref);
289     EXPECT_EQ(heifIrefBox->HasReferences(itemId), false);
290     GTEST_LOG_(INFO) << "HeifParserBoxTest: HasReferencesTest001 end";
291 }
292 
293 /**
294  * @tc.name: ParseContentTest002
295  * @tc.desc: HeifIinfBox
296  * @tc.type: FUNC
297  */
298 HWTEST_F(HeifParserBoxTest, ParseContentTest002, TestSize.Level3)
299 {
300     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest002 start";
301     HeifIinfBox heifIinfBox;
302     HeifInfeBox heifInfeBox;
303     auto stream = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
304     HeifStreamReader reader(stream, 0, 0);
305     reader.hasError_ = false;
306     ASSERT_EQ(heifIinfBox.ParseContent(reader), heif_error_ok);
307     heifInfeBox.version_ = 0;
308     heifInfeBox.ParseContent(reader);
309     heifInfeBox.version_ = 3;
310     heifInfeBox.ParseContent(reader);
311     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest002 end";
312 }
313 
314 /**
315  * @tc.name: InferFullBoxVersionTest003
316  * @tc.desc: HeifInfeBox
317  * @tc.type: FUNC
318  */
319 HWTEST_F(HeifParserBoxTest, InferFullBoxVersionTest003, TestSize.Level3)
320 {
321     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferFullBoxVersionTest003 start";
322     HeifInfeBox heifInfeBox;
323     heifInfeBox.isHidden_ = false;
324     heifInfeBox.itemType_ = "";
325     ASSERT_EQ(heifInfeBox.itemType_.empty(), true);
326     heifInfeBox.itemId_ = 0xFFFFFFFF;
327     heifInfeBox.InferFullBoxVersion();
328     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferFullBoxVersionTest003 end";
329 }
330 
331 /**
332  * @tc.name: WriteTest003
333  * @tc.desc: HeifInfeBox
334  * @tc.type: FUNC
335  */
336 HWTEST_F(HeifParserBoxTest, WriteTest003, TestSize.Level3)
337 {
338     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest003 start";
339     HeifInfeBox heifInfeBox;
340     HeifStreamWriter write;
341     heifInfeBox.version_ = 0;
342     ASSERT_EQ(heifInfeBox.Write(write), heif_error_ok);
343     heifInfeBox.version_ = HEIF_BOX_VERSION_THREE;
344     heifInfeBox.itemType_ = "";
345     ASSERT_EQ(heifInfeBox.itemType_.empty(), true);
346     ASSERT_EQ(heifInfeBox.Write(write), heif_error_ok);
347     heifInfeBox.itemType_ = "uri";
348     ASSERT_EQ(heifInfeBox.Write(write), heif_error_ok);
349     HeifPtimBox heifPtimBox;
350     heifPtimBox.version_ = HEIF_BOX_VERSION_ONE;
351     ASSERT_EQ(heifPtimBox.Write(write), heif_error_ok);
352     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest003 end";
353 }
354 
355 /**
356  * @tc.name: InferHeaderSizeTest001
357  * @tc.desc: HeifBox
358  * @tc.type: FUNC
359  */
360 HWTEST_F(HeifParserBoxTest, InferHeaderSizeTest001, TestSize.Level3)
361 {
362     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferHeaderSizeTest001 start";
363     HeifBox heifBox;
364     heifBox. boxType_ = BOX_TYPE_UUID;
365     ASSERT_EQ(heifBox.InferHeaderSize(), 24);
366     GTEST_LOG_(INFO) << "HeifParserBoxTest: InferHeaderSizeTest001 end";
367 }
368 
369 /**
370  * @tc.name: AppendNalDataTest001
371  * @tc.desc: HeifHvccBox
372  * @tc.type: FUNC
373  */
374 HWTEST_F(HeifParserBoxTest, AppendNalDataTest001, TestSize.Level3)
375 {
376     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendNalDataTest001 start";
377     HeifHvccBox heifHvccBox;
378     std::vector<uint8_t> nalData = {0x01, 0x02, 0x03, 0x04};
379     heifHvccBox.AppendNalData(nalData);
380     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendNalDataTest001 end";
381 }
382 
383 /**
384  * @tc.name: AppendNalDataTest001
385  * @tc.desc: Decode HeifHvccBox to valid SPS
386  * @tc.type: FUNC
387  */
388 HWTEST_F(HeifParserBoxTest, AppendNalDataTest002, TestSize.Level3)
389 {
390     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendNalDataTest002 start";
391     HeifHvccBox heifHvccBox;
392     std::vector<uint8_t> nalData = {0X42, 0X01, 0X01, 0X03, 0X70, 0X00, 0X00, 0X03, 0X00, 0X90, 0X00,
393         0X00, 0X03, 0X00, 0X00, 0X03, 0X00, 0X5a, 0Xa0, 0X04, 0X02, 0X00, 0X80, 0X59, 0X6e, 0Xa4, 0X92,
394         0X9a, 0Xe6, 0Xc0, 0X80, 0X00, 0X00, 0X03, 0X00, 0X80, 0X00, 0X00, 0X03, 0X00, 0X84, 0x22, 0X00,
395         0X01, 0x00, 0x07};
396     heifHvccBox.ProcessBoxData(nalData);
397     heifHvccBox.ParseNalUnitAnalysisSps(nalData);
398     auto spsConfig = heifHvccBox.GetSpsConfig();
399     ASSERT_EQ(spsConfig.nalUnitType, NAL_LAYER_ID);
400     ASSERT_EQ(spsConfig.bitDepthLumaMinus8, 0);
401     ASSERT_EQ(spsConfig.bitDepthChromaMinus8, 0);
402     ASSERT_EQ(spsConfig.chromaFormatIdc, 1);
403     ASSERT_EQ(spsConfig.picWidthInLumaSamples, 512);
404     ASSERT_EQ(spsConfig.picHeightInLumaSamples, 512);
405     ASSERT_EQ(spsConfig.videoRangeFlag, 1);
406     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendNalDataTest002 end";
407 }
408 
409 /**
410  * @tc.name: AppendNalDataTest003
411  * @tc.desc: Decode HeifHvccBox to valid SPS
412  * @tc.type: FUNC
413  */
414 HWTEST_F(HeifParserBoxTest, AppendNalDataTest003, TestSize.Level3)
415 {
416     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendNalDataTest003 start";
417     HeifHvccBox heifHvccBox;
418     std::vector<uint8_t> nalData = {0x42, 0x01, 0x03, 0x01, 0x60, 0x00, 0x00, 0x03, 0x00, 0x00, 0x03, 0x00,
419         0x00, 0x03, 0x00, 0x00, 0x03, 0x00, 0x78, 0x00, 0x00, 0xa0, 0x01, 0x80, 0x20, 0x15, 0x96, 0x37, 0xfd,
420         0xc8, 0xb2, 0x6b, 0xb7, 0x35, 0x02, 0x02, 0x05, 0x00, 0x80, 0x22, 0x00, 0x01, 0x00, 0x07};
421     ProcessBoxData(nalData);
422     heifHvccBox.ParseNalUnitAnalysisSps(nalData);
423     auto spsConfig = heifHvccBox.GetSpsConfig();
424     ASSERT_EQ(spsConfig.nalUnitType, NAL_LAYER_ID);
425     ASSERT_EQ(spsConfig.bitDepthLumaMinus8, 0);
426     ASSERT_EQ(spsConfig.bitDepthChromaMinus8, 0);
427     ASSERT_EQ(spsConfig.chromaFormatIdc, 1);
428     ASSERT_EQ(spsConfig.picWidthInLumaSamples, 3072);
429     ASSERT_EQ(spsConfig.picHeightInLumaSamples, 344);
430     ASSERT_EQ(spsConfig.videoRangeFlag, 0);
431     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendNalDataTest003 end";
432 }
433 
434 /**
435  * @tc.name: ParseExtentsTest001
436  * @tc.desc: HeifIlocBox
437  * @tc.type: FUNC
438  */
439 HWTEST_F(HeifParserBoxTest, ParseExtentsTest001, TestSize.Level3)
440 {
441     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseExtentsTest001 start";
442     HeifIlocBox heifIlocBox;
443     HeifIlocBox::Item item;
444     auto stream = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
445     HeifStreamReader reader(stream, 0, 0);
446     heifIlocBox.version_ = HEIF_BOX_VERSION_ONE;
447     heifIlocBox.ParseExtents(item, reader, 4, 4, 4);
448     heifIlocBox.ParseExtents(item, reader, 8, 8, 8);
449     ASSERT_EQ(item.extents.size(), 0);
450     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseExtentsTest001 end";
451 }
452 
453 /**
454  * @tc.name: AppendDataTest001
455  * @tc.desc: HeifIlocBox
456  * @tc.type: FUNC
457  */
458 HWTEST_F(HeifParserBoxTest, AppendDataTest001, TestSize.Level3)
459 {
460     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendDataTest001 start";
461     HeifIlocBox heifIlocBox;
462     heif_item_id itemId = 0;
463     std::vector<uint8_t> data;
464     uint8_t constructionMethod = 1;
465     ASSERT_EQ(heifIlocBox.UpdateData(itemId, data, constructionMethod), heif_invalid_exif_data);
466     ASSERT_EQ(heifIlocBox.items_.size(), 0);
467     constructionMethod = 0;
468     ASSERT_EQ(heifIlocBox.UpdateData(itemId, data, constructionMethod), heif_error_item_not_found);
469     heifIlocBox.items_.resize(2);
470     ASSERT_EQ(heifIlocBox.items_.size(), 2);
471     ASSERT_EQ(heifIlocBox.UpdateData(itemId, data, constructionMethod), heif_error_ok);
472     GTEST_LOG_(INFO) << "HeifParserBoxTest: AppendDataTest001 end";
473 }
474 
475 /**
476  * @tc.name: ReadToExtentDataTest001
477  * @tc.desc: HeifIlocBox
478  * @tc.type: FUNC
479  */
480 HWTEST_F(HeifParserBoxTest, ReadToExtentDataTest001, TestSize.Level3)
481 {
482     GTEST_LOG_(INFO) << "HeifParserBoxTest: ReadToExtentDataTest001 start";
483     HeifIlocBox heifIlocBox;
484     HeifIlocBox::Item item;
485     struct HeifIlocBox::Extent ref {.offset = 1};
486     item.extents.push_back(ref);
487     item.baseOffset = 1;
488     std::shared_ptr<HeifBufferInputStream> stream = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
489     stream->length_ = 0;
490     std::shared_ptr<HeifIdatBox> idatBox = std::make_shared<HeifIdatBox>();
491     item.constructionMethod = 0;
492     ASSERT_EQ(heifIlocBox.ReadToExtentData(item, stream, idatBox), heif_error_eof);
493     GTEST_LOG_(INFO) << "HeifParserBoxTest: ReadToExtentDataTest001 end";
494 }
495 
496 /**
497  * @tc.name: WriteTest004
498  * @tc.desc: HeifIdatBox
499  * @tc.type: FUNC
500  */
501 HWTEST_F(HeifParserBoxTest, WriteTest004, TestSize.Level3)
502 {
503     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest004 start";
504     HeifIdatBox heifIdatBox;
505     HeifStreamWriter writer;
506     heifIdatBox.dataForWriting_ = {0xff};
507     ASSERT_EQ(heifIdatBox.dataForWriting_.empty(), false);
508     ASSERT_EQ(heifIdatBox.Write(writer), heif_error_ok);
509     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteTest004 end";
510 }
511 
512 /**
513  * @tc.name: ReadDataTest001
514  * @tc.desc: HeifIdatBox
515  * @tc.type: FUNC
516  */
517 HWTEST_F(HeifParserBoxTest, ReadDataTest001, TestSize.Level3)
518 {
519     GTEST_LOG_(INFO) << "HeifParserBoxTest: ReadDataTest001 start";
520     HeifIdatBox heifIdatBox;
521     std::shared_ptr<HeifInputStream> stream;
522     std::vector<uint8_t> outData;
523     heifIdatBox.startPos_ = 1;
524     ASSERT_EQ(heifIdatBox.ReadData(stream, 16, 0, outData), heif_error_eof);
525     ASSERT_EQ(heifIdatBox.ReadData(stream, 0, 16, outData), heif_error_eof);
526     GTEST_LOG_(INFO) << "HeifParserBoxTest: ReadDataTest001 end";
527 }
528 
529 /**
530  * @tc.name: ParseHeaderTest001
531  * @tc.desc: Test ParseHeader when boxType is BOX_TYPE_UUID and size is enough or not
532  * @tc.type: FUNC
533  */
534 HWTEST_F(HeifParserBoxTest, ParseHeaderTest001, TestSize.Level3)
535 {
536     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseHeaderTest001 start";
537     uint32_t boxSize = 1;
538     auto data = SetUint32ToUint8Vertor(boxSize);
539     auto type = SetUint32ToUint8Vertor(BOX_TYPE_UUID);
540     data.insert(data.end(), type.begin(), type.end());
541     auto stream = std::make_shared<HeifBufferInputStream>(data.data(), UINT64_BYTES_NUM, true);
542     ASSERT_NE(stream, nullptr);
543     HeifStreamReader reader1(stream, 0, UINT64_BYTES_NUM);
544 
545     HeifBox heifBox;
546     heif_error error = heifBox.ParseContent(reader1);
547     EXPECT_EQ(error, heif_error_ok);
548 
549     HeifStreamReader reader2(stream, 0, UUID_TYPE_BYTE_NUM);
550     error = heifBox.ParseContent(reader2);
551     EXPECT_EQ(error, heif_error_ok);
552     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseHeaderTest001 end";
553 }
554 
555 /**
556  * @tc.name: ParseContentTest003
557  * @tc.desc: Test ParseContent of HeifPixiBox when CheckSize failed
558  * @tc.type: FUNC
559  */
560 HWTEST_F(HeifParserBoxTest, ParseContentTest003, TestSize.Level3)
561 {
562     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest003 start";
563     HeifPixiBox heifPixBox;
564     auto stream = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
565     ASSERT_NE(stream, nullptr);
566     HeifStreamReader reader(stream, 0, ERR_LENGTH);
567 
568     heif_error error = heifPixBox.ParseContent(reader);
569     EXPECT_EQ(error, heif_error_eof);
570     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest003 end";
571 }
572 
573 /**
574  * @tc.name: WriteHeaderTest001
575  * @tc.desc: Test WriteHeader when boxSize over 32 bits
576  * @tc.type: FUNC
577  */
578 HWTEST_F(HeifParserBoxTest, WriteHeaderTest001, TestSize.Level3)
579 {
580     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteHeaderTest001 start";
581     HeifBox heifBox;
582     HeifStreamWriter writer;
583     size_t boxSize = SIZE_32BITS + 1;
584 
585     heif_error error = heifBox.WriteHeader(writer, boxSize);
586     EXPECT_EQ(error, heif_error_ok);
587     GTEST_LOG_(INFO) << "HeifParserBoxTest: WriteHeaderTest001 end";
588 }
589 
590 /**
591  * @tc.name: ParseContentTest004
592  * @tc.desc: Test ParseContent of HeifBox when CheckSize failed
593  * @tc.type: FUNC
594  */
595 HWTEST_F(HeifParserBoxTest, ParseContentTest004, TestSize.Level3)
596 {
597     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest004 start";
598     auto stream = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
599     ASSERT_NE(stream, nullptr);
600     HeifStreamReader reader(stream, 0, ERR_LENGTH);
601     HeifBox heifBox;
602 
603     heif_error error = heifBox.ParseContent(reader);
604     EXPECT_EQ(error, heif_error_ok);
605     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentTest004 end";
606 }
607 
608 /**
609  * @tc.name: ParseContentChildrenTest001
610  * @tc.desc: Test ParseContentChildren when CheckSize succeed or failed
611  * @tc.type: FUNC
612  */
613 HWTEST_F(HeifParserBoxTest, ParseContentChildrenTest001, TestSize.Level3)
614 {
615     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentChildrenTest001 start";
616     auto stream1 = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
617     ASSERT_NE(stream1, nullptr);
618     HeifStreamReader reader1(stream1, 0, NORMAL_LENGTH);
619     HeifBox heifBox;
620     uint32_t recursionCount = 0;
621 
622     heif_error error = heifBox.ParseContentChildren(reader1, recursionCount);
623     EXPECT_EQ(error, heif_error_ok);
624 
625     recursionCount = 0;
626     auto stream2 = std::make_shared<HeifBufferInputStream>(nullptr, 0, true);
627     ASSERT_NE(stream2, nullptr);
628     HeifStreamReader reader2(stream2, 0, ERR_LENGTH);
629     error = heifBox.ParseContentChildren(reader2, recursionCount);
630     EXPECT_EQ(error, heif_error_ok);
631     GTEST_LOG_(INFO) << "HeifParserBoxTest: ParseContentChildrenTest001 end";
632 }
633 
634 
635 /**
636  * @tc.name: MakeFromReaderTest001
637  * @tc.desc: Test MakeFromReader when reader HasError is true or boxContentSize is error
638  * @tc.type: FUNC
639  */
640 HWTEST_F(HeifParserBoxTest, MakeFromReaderTest001, TestSize.Level3)
641 {
642     GTEST_LOG_(INFO) << "HeifParserBoxTest: MakeFromReaderTest001 start";
643     uint32_t recursionCount = 0;
644     uint32_t boxSize = 1;
645     auto data = SetUint32ToUint8Vertor(boxSize);
646     auto type = SetUint32ToUint8Vertor(BOX_TYPE_FTYP);
647     data.insert(data.end(), type.begin(), type.end());
648     auto stream = std::make_shared<HeifBufferInputStream>(data.data(), UINT64_BYTES_NUM, true);
649     ASSERT_NE(stream, nullptr);
650     HeifStreamReader reader(stream, 0, UINT64_BYTES_NUM);
651     reader.hasError_ = true;
652     std::shared_ptr<HeifBox> heifBoxSptr;
653 
654     HeifBox heifBox;
655     heif_error error = heifBox.MakeFromReader(reader, &heifBoxSptr, recursionCount);
656     EXPECT_EQ(error, heif_error_eof);
657     GTEST_LOG_(INFO) << "HeifParserBoxTest: MakeFromReaderTest001 end";
658 }
659 }
660 }