1 /* 2 * Copyright (C) 2025 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 <string> 17 #include "gtest/gtest.h" 18 #include "avcodec_errors.h" 19 #include "native_averrors.h" 20 21 using namespace testing::ext; 22 using namespace OHOS::MediaAVCodec; 23 24 namespace { 25 constexpr int32_t INVALID_VALUE = -1; 26 const std::string UNKOWN_ERROR = "unkown error"; 27 }; 28 29 namespace OHOS::MediaAVCodec { 30 class ErrorCodeCoverageUnitTest : public testing::Test { 31 public: SetUpTestCase(void)32 static void SetUpTestCase(void) {}; TearDownTestCase(void)33 static void TearDownTestCase(void) {}; SetUp(void)34 void SetUp(void) {}; TearDown(void)35 void TearDown(void) {}; 36 AVCodecServiceErrCode codecServiceErrCode; 37 }; 38 39 /** 40 * @tc.name: OHAVErrCodeToString_Coverage_Unit_Test_001 41 * @tc.desc: input valid value 42 */ 43 HWTEST_F(ErrorCodeCoverageUnitTest, OHAVErrCodeToString_Coverage_Unit_Test_001, TestSize.Level1) 44 { 45 std::string ret = OHAVErrCodeToString(AV_ERR_OK); 46 EXPECT_NE(ret, UNKOWN_ERROR); 47 } 48 49 /** 50 * @tc.name: OHAVErrCodeToString_Coverage_Unit_Test_002 51 * @tc.desc: input invalid value 52 */ 53 HWTEST_F(ErrorCodeCoverageUnitTest, OHAVErrCodeToString_Coverage_Unit_Test_002, TestSize.Level1) 54 { 55 std::string ret = OHAVErrCodeToString(static_cast<OH_AVErrCode>(INVALID_VALUE)); 56 EXPECT_EQ(ret, UNKOWN_ERROR); 57 } 58 59 /** 60 * @tc.name: AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_001 61 * @tc.desc: error code belongs to AVCS_ERRCODE_INFOS not AVCSERRCODE_TO_OHAVCODECERRCODE 62 */ 63 HWTEST_F(ErrorCodeCoverageUnitTest, AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_001, TestSize.Level1) 64 { 65 codecServiceErrCode = AVCS_ERR_VIDEO_UNSUPPORT_COLOR_SPACE_CONVERSION; 66 std::string ret = AVCSErrorToOHAVErrCodeString(static_cast<AVCodecServiceErrCode>(codecServiceErrCode)); 67 EXPECT_NE(ret, UNKOWN_ERROR); 68 } 69 70 /** 71 * @tc.name: AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_002 72 * @tc.desc: error code belongs to AVCS_ERRCODE_INFOS and AVCSERRCODE_TO_OHAVCODECERRCODE 73 */ 74 HWTEST_F(ErrorCodeCoverageUnitTest, AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_002, TestSize.Level1) 75 { 76 codecServiceErrCode = AVCS_ERR_OK; 77 std::string ret = AVCSErrorToOHAVErrCodeString(static_cast<AVCodecServiceErrCode>(codecServiceErrCode)); 78 EXPECT_NE(ret, UNKOWN_ERROR); 79 } 80 81 /** 82 * @tc.name: AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_003 83 * @tc.desc: error code belongs to AVCSERRCODE_TO_OHAVCODECERRCODE not AVCS_ERRCODE_INFOS 84 */ 85 HWTEST_F(ErrorCodeCoverageUnitTest, AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_003, TestSize.Level1) 86 { 87 std::string ret = AVCSErrorToOHAVErrCodeString(static_cast<AVCodecServiceErrCode>(AV_ERR_NO_MEMORY)); 88 EXPECT_EQ(ret, UNKOWN_ERROR); 89 } 90 91 /** 92 * @tc.name: AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_004 93 * @tc.desc: error code not belong to AVCS_ERRCODE_INFOS and AVCSERRCODE_TO_OHAVCODECERRCODE 94 */ 95 HWTEST_F(ErrorCodeCoverageUnitTest, AVCSErrorToOHAVErrCodeString_Coverage_Unit_Test_004, TestSize.Level1) 96 { 97 std::string ret = AVCSErrorToOHAVErrCodeString(static_cast<AVCodecServiceErrCode>(INVALID_VALUE)); 98 EXPECT_EQ(ret, UNKOWN_ERROR); 99 } 100 }