1 /*
2  * Copyright (c) 2023-2023 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 "plugin/plugins/ffmpeg_adapter/utils/avc_config_data_parser.h"
18 
19 using namespace testing::ext;
20 
21 namespace OHOS {
22 namespace Media {
23 namespace Test {
24 using namespace Plugin::Ffmpeg;
25 
26 HWTEST(FFmpegAvcConfigDataParserTest, testParseConfigData, TestSize.Level1)
27 {
28     const uint8_t* ptr1 = nullptr;
29     auto parser1 = std::make_shared<AVCConfigDataParser>(ptr1, 0);
30     bool res1 = parser1->ParseConfigData();
31     ASSERT_FALSE(res1);
32 
33     uint8_t nums[9] = {1, 2, 4, 16, 91, 128, 160, 232, 255};
34     for (size_t i = 0; i < 9; i++) {
35         uint8_t num = nums[i];
36         const uint8_t* ptr = &num;
37         size_t size = sizeof(num);
38         auto parser = std::make_shared<AVCConfigDataParser>(ptr, size);
39         bool res = parser->ParseConfigData();
40         if (num == 232 || num == 160 || num == 128) {
41             ASSERT_FALSE(res);
42         } else {
43             ASSERT_TRUE(res);
44         }
45     }
46 }
47 
48 HWTEST(FFmpegAvcConfigDataParserTest, testIsNeedAddFrameHeader, TestSize.Level1)
49 {
50     uint8_t num = 10;
51     const uint8_t* ptr1 = &num;
52     auto parser = std::make_shared<AVCConfigDataParser>(ptr1, 1);
53     bool res = parser->IsNeedAddFrameHeader();
54     ASSERT_FALSE(res);
55 }
56 
57 HWTEST(FFmpegAvcConfigDataParserTest, testGetNewConfigData, TestSize.Level1)
58 {
59     const uint8_t* ptr1 = nullptr;
60     auto parser1 = std::make_shared<AVCConfigDataParser>(ptr1, 0);
61     std::shared_ptr<uint8_t> newCfgData;
62     size_t newCfgDataSize;
63     bool res1 = parser1->GetNewConfigData(newCfgData, newCfgDataSize);
64     ASSERT_FALSE(res1);
65 
66     uint8_t num = 160;
67     const uint8_t* ptr2 = &num;
68     auto parser2 = std::make_shared<AVCConfigDataParser>(ptr2, 3);
69     std::shared_ptr<uint8_t> data;
70     size_t size;
71     bool res2 = parser2->GetNewConfigData(data, size);
72     ASSERT_FALSE(res2);
73 }
74 
75 } // namespace Test
76 } // namespace Media
77 } // namespace OHOS