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 "gtest/gtest.h" 17 #define private public 18 #include "audio_cenc_info_adapter_impl.h" 19 #undef private 20 21 using namespace testing; 22 using namespace testing::ext; 23 using namespace OHOS::NWeb; 24 25 class AudioCencInfoAdapterImplTest : public ::testing::Test { 26 protected: SetUp()27 void SetUp() override {} TearDown()28 void TearDown() override {} 29 }; 30 31 /** 32 * @tc.name: GetKeyID_ShouldReturnKeyId_WhenCalled 33 * @tc.number: AudioCencInfoAdapterImplTest_001 34 * @tc.desc: Test GetKeyId method of AudioCencInfoAdapterImpl class 35 */ 36 HWTEST_F(AudioCencInfoAdapterImplTest, GetKeyID_ShouldReturnKeyId_WhenCalled, TestSize.Level0) 37 { 38 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 39 uint8_t* keyId = (uint8_t*)"keyId"; 40 audioCencInfoAdapterImpl.SetKeyId(keyId); 41 EXPECT_EQ(audioCencInfoAdapterImpl.GetKeyId(), keyId); 42 } 43 44 /** 45 * @tc.name: GetKeyIDLen_ShouldReturnKeyIdLen_WhenCalled 46 * @tc.number: AudioCencInfoAdapterImplTest_002 47 * @tc.desc: Test GetKeyIdLen method of AudioCencInfoAdapterImpl class 48 */ 49 HWTEST_F(AudioCencInfoAdapterImplTest, GetKeyIDLen_ShouldReturnKeyIdLen_WhenCalled, TestSize.Level0) 50 { 51 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 52 uint32_t keyIdLen = 16; 53 audioCencInfoAdapterImpl.SetKeyIdLen(keyIdLen); 54 EXPECT_EQ(audioCencInfoAdapterImpl.GetKeyIdLen(), keyIdLen); 55 } 56 57 /** 58 * @tc.name: GetIv_ShouldReturnIv_WhenCalled 59 * @tc.number: AudioCencInfoAdapterImplTest_003 60 * @tc.desc: Test GetIv method of AudioCencInfoAdapterImpl class 61 */ 62 HWTEST_F(AudioCencInfoAdapterImplTest, GetIv_ShouldReturnIv_WhenCalled, TestSize.Level0) 63 { 64 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 65 uint8_t* iv = (uint8_t*)"iv"; 66 audioCencInfoAdapterImpl.SetIv(iv); 67 EXPECT_EQ(audioCencInfoAdapterImpl.GetIv(), iv); 68 } 69 70 /** 71 * @tc.name: GetIvLen_ShouldReturnIvLen_WhenCalled 72 * @tc.number: AudioCencInfoAdapterImplTest_004 73 * @tc.desc: Test GetIvLen method of AudioCencInfoAdapterImpl class 74 */ 75 HWTEST_F(AudioCencInfoAdapterImplTest, GetIvLen_ShouldReturnIvLen_WhenCalled, TestSize.Level0) 76 { 77 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 78 uint32_t ivLen = 16; 79 audioCencInfoAdapterImpl.SetIvLen(ivLen); 80 EXPECT_EQ(audioCencInfoAdapterImpl.GetIvLen(), ivLen); 81 } 82 83 /** 84 * @tc.name: GetAlgo_ShouldReturnAlgo_WhenCalled 85 * @tc.number: AudioCencInfoAdapterImplTest_005 86 * @tc.desc: Test GetAlgo method of AudioCencInfoAdapterImpl class 87 */ 88 HWTEST_F(AudioCencInfoAdapterImplTest, GetAlgo_ShouldReturnAlgo_WhenCalled, TestSize.Level0) 89 { 90 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 91 uint32_t algo = 1; 92 audioCencInfoAdapterImpl.SetAlgo(algo); 93 EXPECT_EQ(audioCencInfoAdapterImpl.GetAlgo(), algo); 94 } 95 96 /** 97 * @tc.name: GetEncryptedBlockCount_ShouldReturnEncryptedBlockCount_WhenCalled 98 * @tc.number: AudioCencInfoAdapterImplTest_006 99 * @tc.desc: Test GetEncryptedBlockCount method of AudioCencInfoAdapterImpl class 100 */ 101 HWTEST_F(AudioCencInfoAdapterImplTest, 102 GetEncryptedBlockCount_ShouldReturnEncryptedBlockCount_WhenCalled, TestSize.Level0) 103 { 104 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 105 uint32_t encryptedBlockCount = 10; 106 audioCencInfoAdapterImpl.SetEncryptedBlockCount(encryptedBlockCount); 107 EXPECT_EQ(audioCencInfoAdapterImpl.GetEncryptedBlockCount(), encryptedBlockCount); 108 } 109 110 /** 111 * @tc.name: GetSkippedBlockCount_ShouldReturnSkippedBlockCount_WhenCalled 112 * @tc.number: AudioCencInfoAdapterImplTest_007 113 * @tc.desc: Test GetSkippedBlockCount method of AudioCencInfoAdapterImpl class 114 */ 115 HWTEST_F(AudioCencInfoAdapterImplTest, 116 GetSkippedBlockCount_ShouldReturnSkippedBlockCount_WhenCalled, TestSize.Level0) 117 { 118 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 119 uint32_t skippedBlockCount = 5; 120 audioCencInfoAdapterImpl.SetSkippedBlockCount(skippedBlockCount); 121 EXPECT_EQ(audioCencInfoAdapterImpl.GetSkippedBlockCount(), skippedBlockCount); 122 } 123 124 /** 125 * @tc.name: GetFirstEncryptedOffset_ShouldReturnFirstEncryptedOffset_WhenCalled 126 * @tc.number: AudioCencInfoAdapterImplTest_008 127 * @tc.desc: Test GetFirstEncryptedOffset method of AudioCencInfoAdapterImpl class 128 */ 129 HWTEST_F(AudioCencInfoAdapterImplTest, 130 GetFirstEncryptedOffset_ShouldReturnFirstEncryptedOffset_WhenCalled, TestSize.Level0) 131 { 132 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 133 uint32_t firstEncryptedOffset = 5; 134 audioCencInfoAdapterImpl.SetFirstEncryptedOffset(firstEncryptedOffset); 135 EXPECT_EQ(audioCencInfoAdapterImpl.GetFirstEncryptedOffset(), firstEncryptedOffset); 136 } 137 138 /** 139 * @tc.name: GetClearHeaderLens_ShouldReturnClearHeaderLens_WhenCalled 140 * @tc.number: AudioCencInfoAdapterImplTest_009 141 * @tc.desc: Test GetClearHeaderLens method of AudioCencInfoAdapterImpl class 142 */ 143 HWTEST_F(AudioCencInfoAdapterImplTest, 144 GetClearHeaderLens_ShouldReturnClearHeaderLens_WhenCalled, TestSize.Level0) 145 { 146 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 147 std::vector<uint32_t> clearHeaderLens = {1, 2, 3}; 148 audioCencInfoAdapterImpl.SetClearHeaderLens(clearHeaderLens); 149 EXPECT_EQ(audioCencInfoAdapterImpl.GetClearHeaderLens(), clearHeaderLens); 150 } 151 152 /** 153 * @tc.name: GetPayLoadLens_ShouldReturnPayLoadLens_WhenCalled 154 * @tc.number: AudioCencInfoAdapterImplTest_010 155 * @tc.desc: Test GetPayLoadLens method of AudioCencInfoAdapterImpl class 156 */ 157 HWTEST_F(AudioCencInfoAdapterImplTest, 158 GetPayLoadLens_ShouldReturnPayLoadLens_WhenCalled, TestSize.Level0) 159 { 160 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 161 std::vector<uint32_t> payLoadLens = {4, 5, 6}; 162 audioCencInfoAdapterImpl.SetPayLoadLens(payLoadLens); 163 EXPECT_EQ(audioCencInfoAdapterImpl.GetPayLoadLens(), payLoadLens); 164 } 165 166 /** 167 * @tc.name: GetMode_ShouldReturnMode_WhenCalled 168 * @tc.number: AudioCencInfoAdapterImplTest_011 169 * @tc.desc: Test GetMode method of AudioCencInfoAdapterImpl class 170 */ 171 HWTEST_F(AudioCencInfoAdapterImplTest, 172 GetMode_ShouldReturnMode_WhenCalled, TestSize.Level0) 173 { 174 AudioCencInfoAdapterImpl audioCencInfoAdapterImpl; 175 uint32_t mode = 1; 176 audioCencInfoAdapterImpl.SetMode(mode); 177 EXPECT_EQ(audioCencInfoAdapterImpl.GetMode(), mode); 178 }