1fa7767c5Sopenharmony_ci/* 2fa7767c5Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd. 3fa7767c5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fa7767c5Sopenharmony_ci * you may not use this file except in compliance with the License. 5fa7767c5Sopenharmony_ci * You may obtain a copy of the License at 6fa7767c5Sopenharmony_ci * 7fa7767c5Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fa7767c5Sopenharmony_ci * 9fa7767c5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fa7767c5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fa7767c5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fa7767c5Sopenharmony_ci * See the License for the specific language governing permissions and 13fa7767c5Sopenharmony_ci * limitations under the License. 14fa7767c5Sopenharmony_ci */ 15fa7767c5Sopenharmony_ci 16fa7767c5Sopenharmony_ci#include "gtest/gtest.h" 17fa7767c5Sopenharmony_ci#include "plugin/plugins/ffmpeg_adapter/utils/avc_config_data_parser.h" 18fa7767c5Sopenharmony_ci 19fa7767c5Sopenharmony_ciusing namespace testing::ext; 20fa7767c5Sopenharmony_ci 21fa7767c5Sopenharmony_cinamespace OHOS { 22fa7767c5Sopenharmony_cinamespace Media { 23fa7767c5Sopenharmony_cinamespace Test { 24fa7767c5Sopenharmony_ciusing namespace Plugin::Ffmpeg; 25fa7767c5Sopenharmony_ci 26fa7767c5Sopenharmony_ciHWTEST(FFmpegAvcConfigDataParserTest, testParseConfigData, TestSize.Level1) 27fa7767c5Sopenharmony_ci{ 28fa7767c5Sopenharmony_ci const uint8_t* ptr1 = nullptr; 29fa7767c5Sopenharmony_ci auto parser1 = std::make_shared<AVCConfigDataParser>(ptr1, 0); 30fa7767c5Sopenharmony_ci bool res1 = parser1->ParseConfigData(); 31fa7767c5Sopenharmony_ci ASSERT_FALSE(res1); 32fa7767c5Sopenharmony_ci 33fa7767c5Sopenharmony_ci uint8_t nums[9] = {1, 2, 4, 16, 91, 128, 160, 232, 255}; 34fa7767c5Sopenharmony_ci for (size_t i = 0; i < 9; i++) { 35fa7767c5Sopenharmony_ci uint8_t num = nums[i]; 36fa7767c5Sopenharmony_ci const uint8_t* ptr = # 37fa7767c5Sopenharmony_ci size_t size = sizeof(num); 38fa7767c5Sopenharmony_ci auto parser = std::make_shared<AVCConfigDataParser>(ptr, size); 39fa7767c5Sopenharmony_ci bool res = parser->ParseConfigData(); 40fa7767c5Sopenharmony_ci if (num == 232 || num == 160 || num == 128) { 41fa7767c5Sopenharmony_ci ASSERT_FALSE(res); 42fa7767c5Sopenharmony_ci } else { 43fa7767c5Sopenharmony_ci ASSERT_TRUE(res); 44fa7767c5Sopenharmony_ci } 45fa7767c5Sopenharmony_ci } 46fa7767c5Sopenharmony_ci} 47fa7767c5Sopenharmony_ci 48fa7767c5Sopenharmony_ciHWTEST(FFmpegAvcConfigDataParserTest, testIsNeedAddFrameHeader, TestSize.Level1) 49fa7767c5Sopenharmony_ci{ 50fa7767c5Sopenharmony_ci uint8_t num = 10; 51fa7767c5Sopenharmony_ci const uint8_t* ptr1 = # 52fa7767c5Sopenharmony_ci auto parser = std::make_shared<AVCConfigDataParser>(ptr1, 1); 53fa7767c5Sopenharmony_ci bool res = parser->IsNeedAddFrameHeader(); 54fa7767c5Sopenharmony_ci ASSERT_FALSE(res); 55fa7767c5Sopenharmony_ci} 56fa7767c5Sopenharmony_ci 57fa7767c5Sopenharmony_ciHWTEST(FFmpegAvcConfigDataParserTest, testGetNewConfigData, TestSize.Level1) 58fa7767c5Sopenharmony_ci{ 59fa7767c5Sopenharmony_ci const uint8_t* ptr1 = nullptr; 60fa7767c5Sopenharmony_ci auto parser1 = std::make_shared<AVCConfigDataParser>(ptr1, 0); 61fa7767c5Sopenharmony_ci std::shared_ptr<uint8_t> newCfgData; 62fa7767c5Sopenharmony_ci size_t newCfgDataSize; 63fa7767c5Sopenharmony_ci bool res1 = parser1->GetNewConfigData(newCfgData, newCfgDataSize); 64fa7767c5Sopenharmony_ci ASSERT_FALSE(res1); 65fa7767c5Sopenharmony_ci 66fa7767c5Sopenharmony_ci uint8_t num = 160; 67fa7767c5Sopenharmony_ci const uint8_t* ptr2 = # 68fa7767c5Sopenharmony_ci auto parser2 = std::make_shared<AVCConfigDataParser>(ptr2, 3); 69fa7767c5Sopenharmony_ci std::shared_ptr<uint8_t> data; 70fa7767c5Sopenharmony_ci size_t size; 71fa7767c5Sopenharmony_ci bool res2 = parser2->GetNewConfigData(data, size); 72fa7767c5Sopenharmony_ci ASSERT_FALSE(res2); 73fa7767c5Sopenharmony_ci} 74fa7767c5Sopenharmony_ci 75fa7767c5Sopenharmony_ci} // namespace Test 76fa7767c5Sopenharmony_ci} // namespace Media 77fa7767c5Sopenharmony_ci} // namespace OHOS