• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 <gmock/gmock.h>
18 #define private public
19 #include "avcodec_video_decoder_impl.h"
20 #include "media_codec_decoder_adapter_impl.h"
21 #include "audio_cenc_info_adapter_impl.h"
22 #undef private
23 #include "avsharedmemory.h"
24 #include "avsharedmemorybase.h"
25 #include "surface/window.h"
26 #include "native_window.h"
27 #include "native_avformat.h"
28 #include "native_avbuffer.h"
29 #include "native_avbuffer_info.h"
30 #include "native_drm_base.h"
31 #include "native_mediakeysystem.h"
32 
33 using namespace testing;
34 using namespace testing::ext;
35 using namespace std;
36 using testing::ext::TestSize;
37 using namespace OHOS::MediaAVCodec;
38 
GetKeySystemName()39 static const std::string GetKeySystemName()
40 {
41     if (OH_MediaKeySystem_IsSupported("com.clearplay.drm")) {
42         return "com.clearplay.drm";
43     } else if (OH_MediaKeySystem_IsSupported("com.wiseplay.drm")) {
44         return "com.wiseplay.drm";
45     } else {
46         return "ERROR";
47     }
48 }
49 
50 namespace OHOS {
51 namespace MediaAVCodec {
52 class AVCodecVideoDecoderImplMock : public AVCodecVideoDecoderImpl {
53 public:
54     MOCK_METHOD0(Prepare, int32_t());
55 };
56 }
57 namespace NWeb {
58 class DecoderCallbackImplTest : public testing::Test {};
59 
60 class DecoderCallbackAdapterMock : public DecoderCallbackAdapter {
61 public:
62     DecoderCallbackAdapterMock() = default;
63 
64     ~DecoderCallbackAdapterMock() override = default;
65 
OnError(ErrorType errorType,int32_t errorCode)66     void OnError(ErrorType errorType, int32_t errorCode) override {}
67 
OnStreamChanged(int32_t width,int32_t height,double frameRate)68     void OnStreamChanged(int32_t width, int32_t height, double frameRate) override {}
69 
OnNeedInputData(uint32_t index,std::shared_ptr<OhosBufferAdapter> buffer)70     void OnNeedInputData(uint32_t index, std::shared_ptr<OhosBufferAdapter> buffer) override {}
71 
OnNeedOutputData(uint32_t index,std::shared_ptr<BufferInfoAdapter> info,BufferFlag flag)72     void OnNeedOutputData(uint32_t index, std::shared_ptr<BufferInfoAdapter> info, BufferFlag flag) override {}
73 };
74 
75 class DecoderFormatAdapterMock : public DecoderFormatAdapter {
76 public:
77     DecoderFormatAdapterMock() = default;
78 
GetWidth()79     int32_t GetWidth() override
80     {
81         return width;
82     }
83 
GetHeight()84     int32_t GetHeight() override
85     {
86         return height;
87     }
88 
GetFrameRate()89     double GetFrameRate() override
90     {
91         return frameRate;
92     }
93 
SetWidth(int32_t w)94     void SetWidth(int32_t w) override
95     {
96         width = w;
97     }
98 
SetHeight(int32_t h)99     void SetHeight(int32_t h) override
100     {
101         height = h;
102     }
103 
SetFrameRate(double fr)104     void SetFrameRate(double fr) override
105     {
106         frameRate = fr;
107     }
108 
109     int32_t width;
110     int32_t height;
111     double frameRate;
112 };
113 
114 class MediaCodecDecoderAdapterImplTest : public testing::Test {
115 public:
116     static void SetUpTestCase(void);
117     static void TearDownTestCase(void);
118     void SetUp();
119     void TearDown();
120     void SetCencInfoAboutKeyIdIvAlgo(std::shared_ptr<AudioCencInfoAdapter> cencInfo);
121     void SetCencInfoAboutClearHeaderAndPayLoadLens(std::shared_ptr<AudioCencInfoAdapter> cencInfo);
122 
123 protected:
124     std::shared_ptr<DecoderFormatAdapterMock> format_ = nullptr;
125     std::shared_ptr<MediaCodecDecoderAdapterImpl> mediaCodecDecoderAdapterImpl_ = nullptr;
126 };
127 
SetUpTestCase(void)128 void MediaCodecDecoderAdapterImplTest::SetUpTestCase(void) {}
129 
TearDownTestCase(void)130 void MediaCodecDecoderAdapterImplTest::TearDownTestCase(void) {}
131 
SetUp()132 void MediaCodecDecoderAdapterImplTest::SetUp()
133 {
134     constexpr int32_t testWidth = 200;
135     constexpr int32_t testHeight = 300;
136     constexpr int32_t testFrameRate = 20;
137     EXPECT_EQ(mediaCodecDecoderAdapterImpl_, nullptr);
138     mediaCodecDecoderAdapterImpl_ = std::make_unique<MediaCodecDecoderAdapterImpl>();
139     EXPECT_EQ(format_, nullptr);
140     format_ = std::make_unique<DecoderFormatAdapterMock>();
141     EXPECT_NE(format_, nullptr);
142     format_->width = testWidth;
143     format_->height = testHeight;
144     format_->frameRate = testFrameRate;
145 }
146 
TearDown(void)147 void MediaCodecDecoderAdapterImplTest::TearDown(void) {}
148 
SetCencInfoAboutKeyIdIvAlgo(std::shared_ptr<AudioCencInfoAdapter> cencInfo)149 void MediaCodecDecoderAdapterImplTest::SetCencInfoAboutKeyIdIvAlgo(
150     std::shared_ptr<AudioCencInfoAdapter> cencInfo)
151 {
152     uint8_t keyId[] = {
153         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
154         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
155     uint8_t iv[] = {
156         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
157         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01};
158     cencInfo->SetAlgo(0);
159     cencInfo->SetKeyId(keyId);
160     cencInfo->SetKeyIdLen(DRM_KEY_ID_SIZE);
161     cencInfo->SetIv(iv);
162     cencInfo->SetIvLen(DRM_KEY_ID_SIZE);
163 }
164 
SetCencInfoAboutClearHeaderAndPayLoadLens(std::shared_ptr<AudioCencInfoAdapter> cencInfo)165 void MediaCodecDecoderAdapterImplTest::SetCencInfoAboutClearHeaderAndPayLoadLens(
166     std::shared_ptr<AudioCencInfoAdapter> cencInfo)
167 {
168     const std::vector<uint32_t> clearHeaderLens = {1, 2, 3};
169     const std::vector<uint32_t> payLoadLens = {4, 5, 6};
170     const uint32_t ERR_BLOCK_COUNT = 10000;
171     cencInfo->SetClearHeaderLens(clearHeaderLens);
172     cencInfo->SetPayLoadLens(payLoadLens);
173     cencInfo->SetEncryptedBlockCount(ERR_BLOCK_COUNT);
174     cencInfo->SetSkippedBlockCount(0);
175     cencInfo->SetFirstEncryptedOffset(0);
176 }
177 
178 /**
179  * @tc.name: MediaCodecDecoderAdapterImpl_CreateVideoDecoderByName_001.
180  * @tc.desc: test of MediaCodecDecoderAdapterImpl::CreateVideoDecoderByName() CreateVideoDecoderByName()
181  * @tc.type: FUNC.
182  * @tc.require:
183  */
184 HWTEST_F(MediaCodecDecoderAdapterImplTest, MediaCodecDecoderAdapterImpl_CreateVideoDecoderByName_001, TestSize.Level1)
185 {
186     // create error decoder
187     const std::string errorMimetype = "testmimeType";
188     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(
189 	    errorMimetype), DecoderAdapterCode::DECODER_ERROR);
190     const std::string errorName = "testname";
191     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByName(errorName), DecoderAdapterCode::DECODER_ERROR);
192 
193     // create normal decoder
194     const std::string validMimetype = "video/avc";
195     DecoderAdapterCode ret = mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(validMimetype);
196     EXPECT_EQ(ret, DecoderAdapterCode::DECODER_OK);
197     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseDecoder(), DecoderAdapterCode::DECODER_OK);
198 
199     // drm dncrypt decoder
200     std::string systemName = GetKeySystemName();
201     bool isSupported = OH_MediaKeySystem_IsSupported2(systemName.c_str(), validMimetype.c_str());
202     if (isSupported) {
203         MediaKeySession session;
204         mediaCodecDecoderAdapterImpl_->SetDecryptionConfig(static_cast<void*>(&session), true);
205         ret = mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(validMimetype);
206         EXPECT_EQ(ret, DecoderAdapterCode::DECODER_ERROR);
207         EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseDecoder(), DecoderAdapterCode::DECODER_ERROR);
208         mediaCodecDecoderAdapterImpl_->SetDecryptionConfig(static_cast<void*>(&session), false);
209     }
210 }
211 
212 /**
213  * @tc.name: MediaCodecDecoderAdapterImpl_InvalidValueTest_002.
214  * @tc.desc: test of InvalidValueScene in MediaCodecDecoderAdapterImpl
215  * @tc.type: FUNC.
216  * @tc.require:
217  */
218 HWTEST_F(MediaCodecDecoderAdapterImplTest, MediaCodecDecoderAdapterImpl_InvalidValueTest_002, TestSize.Level1)
219 {
220     // not create decoder and test function
221     uint32_t index_ = 0;
222     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->QueueInputBufferDec(index_, 0, 0, 0, BufferFlag::CODEC_BUFFER_FLAG_NONE),
223         DecoderAdapterCode::DECODER_ERROR);
224     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->GetOutputFormatDec(format_), DecoderAdapterCode::DECODER_ERROR);
225     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseOutputBufferDec(index_, true), DecoderAdapterCode::DECODER_ERROR);
226     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ConfigureDecoder(format_), DecoderAdapterCode::DECODER_ERROR);
227     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetParameterDecoder(format_), DecoderAdapterCode::DECODER_ERROR);
228     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetOutputSurface(nullptr), DecoderAdapterCode::DECODER_ERROR);
229     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->PrepareDecoder(), DecoderAdapterCode::DECODER_ERROR);
230     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->StartDecoder(), DecoderAdapterCode::DECODER_ERROR);
231     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->StopDecoder(), DecoderAdapterCode::DECODER_ERROR);
232     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->FlushDecoder(), DecoderAdapterCode::DECODER_ERROR);
233     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ResetDecoder(), DecoderAdapterCode::DECODER_ERROR);
234     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseDecoder(), DecoderAdapterCode::DECODER_ERROR);
235     std::shared_ptr<DecoderCallbackAdapter> callback = std::make_shared<DecoderCallbackAdapterMock>();
236     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetCallbackDec(callback), DecoderAdapterCode::DECODER_ERROR);
237     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetDecryptionConfig(nullptr, false), DecoderAdapterCode::DECODER_OK);
238     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, nullptr), DecoderAdapterCode::DECODER_ERROR);
239 
240     // create decoder and test function in error case
241     const std::string validMimetype = "video/avc";
242     DecoderAdapterCode ret = mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(validMimetype);
243     EXPECT_EQ(ret, DecoderAdapterCode::DECODER_OK);
244     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ConfigureDecoder(nullptr), DecoderAdapterCode::DECODER_ERROR);
245     constexpr int32_t errWidth = 10000;
246     format_->width = errWidth;
247     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ConfigureDecoder(format_), DecoderAdapterCode::DECODER_ERROR);
248     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetParameterDecoder(nullptr), DecoderAdapterCode::DECODER_ERROR);
249     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetParameterDecoder(format_), DecoderAdapterCode::DECODER_ERROR);
250     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->GetOutputFormatDec(nullptr), DecoderAdapterCode::DECODER_ERROR);
251     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->QueueInputBufferDec(index_, 0, 0, 0, BufferFlag::CODEC_BUFFER_FLAG_NONE),
252         DecoderAdapterCode::DECODER_ERROR);
253     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetOutputSurface(nullptr), DecoderAdapterCode::DECODER_ERROR);
254 }
255 
256 /**
257  * @tc.name: MediaCodecDecoderAdapterImpl_NormalTest_003.
258  * @tc.desc: test of NormalScene in MediaCodecDecoderAdapterImpl
259  * @tc.type: FUNC.
260  * @tc.require:
261  */
262 HWTEST_F(MediaCodecDecoderAdapterImplTest, MediaCodecDecoderAdapterImpl_NormalTest_003, TestSize.Level1)
263 {
264     uint32_t index_ = 0;
265     const std::string validMimetype = "video/avc";
266     DecoderAdapterCode ret = mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(validMimetype);
267     EXPECT_EQ(ret, DecoderAdapterCode::DECODER_OK);
268     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ConfigureDecoder(format_), DecoderAdapterCode::DECODER_OK);
269 
270     std::shared_ptr<DecoderCallbackAdapter> callback = std::make_shared<DecoderCallbackAdapterMock>();
271     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetCallbackDec(callback), DecoderAdapterCode::DECODER_OK);
272     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->PrepareDecoder(), DecoderAdapterCode::DECODER_OK);
273     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->StartDecoder(), DecoderAdapterCode::DECODER_OK);
274 
275     constexpr int32_t MEMSIZE = 1024 * 1024;
276     OH_AVBuffer* buffer = OH_AVBuffer_Create(MEMSIZE);
277     mediaCodecDecoderAdapterImpl_->OnInputBufferAvailable(index_, buffer);
278     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->QueueInputBufferDec(index_, 0, 0, 0, BufferFlag::CODEC_BUFFER_FLAG_NONE),
279         DecoderAdapterCode::DECODER_ERROR);
280     OH_AVBuffer_Destroy(buffer);
281     buffer = nullptr;
282 
283     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->GetOutputFormatDec(format_), DecoderAdapterCode::DECODER_OK);
284     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->FlushDecoder(), DecoderAdapterCode::DECODER_OK);
285     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetParameterDecoder(format_), DecoderAdapterCode::DECODER_OK);
286     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->StopDecoder(), DecoderAdapterCode::DECODER_OK);
287     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ResetDecoder(), DecoderAdapterCode::DECODER_OK);
288     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseOutputBufferDec(index_, true), DecoderAdapterCode::DECODER_ERROR);
289     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseOutputBufferDec(index_, false), DecoderAdapterCode::DECODER_ERROR);
290     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseDecoder(), DecoderAdapterCode::DECODER_OK);
291 }
292 
293 /**
294  * @tc.name: MediaCodecDecoderAdapterImpl_SetCallbackDec_004.
295  * @tc.desc: test of MediaCodecDecoderAdapterImpl::SetCallbackDec
296  * @tc.type: FUNC.
297  * @tc.require:
298  */
299 HWTEST_F(MediaCodecDecoderAdapterImplTest, MediaCodecDecoderAdapterImpl_SetCallbackDec_004, TestSize.Level1)
300 {
301     const std::string validMimetype = "video/avc";
302     DecoderAdapterCode ret = mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(validMimetype);
303     EXPECT_EQ(ret, DecoderAdapterCode::DECODER_OK);
304 
305     std::shared_ptr<DecoderCallbackAdapter> callback = nullptr;
306     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetCallbackDec(callback), DecoderAdapterCode::DECODER_ERROR);
307     callback = std::make_shared<DecoderCallbackAdapterMock>();
308     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetCallbackDec(callback), DecoderAdapterCode::DECODER_OK);
309     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ReleaseDecoder(), DecoderAdapterCode::DECODER_OK);
310 }
311 
312 /**
313  * @tc.name: MediaCodecDecoderAdapterImpl_GetTypeOrFlag_005.
314  * @tc.desc: test of MediaCodecDecoderAdapterImpl::GetBufferFlag() GetAVBufferFlag()
315  * @tc.type: FUNC.
316  * @tc.require:
317  */
318 HWTEST_F(MediaCodecDecoderAdapterImplTest, MediaCodecDecoderAdapterImpl_GetTypeOrFlag_005, TestSize.Level1)
319 {
320     EXPECT_EQ(
321         mediaCodecDecoderAdapterImpl_->GetBufferFlag(OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS),
322         BufferFlag::CODEC_BUFFER_FLAG_EOS);
323     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->GetAVBufferFlag(BufferFlag::CODEC_BUFFER_FLAG_EOS),
324         OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_EOS);
325 
326     OH_AVCodecBufferFlags testAVCodecBufferFlag = static_cast<OH_AVCodecBufferFlags>(100);
327     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->GetBufferFlag(testAVCodecBufferFlag), BufferFlag::CODEC_BUFFER_FLAG_NONE);
328     BufferFlag testBufferFlag = static_cast<BufferFlag>(100);
329     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->GetAVBufferFlag(testBufferFlag),
330         OH_AVCodecBufferFlags::AVCODEC_BUFFER_FLAGS_NONE);
331 	const std::string codecName = "video/avc";
332     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByName(codecName), DecoderAdapterCode::DECODER_OK);
333     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->ConfigureDecoder(format_), DecoderAdapterCode::DECODER_OK);
334 }
335 
336 /**
337  * @tc.name: MediaCodecDecoderAdapterImpl_OnError_006.
338  * @tc.desc: test of MediaCodecDecoderAdapterImpl::OnError() OnOutputFormatChanged() OnInputBufferAvailable()
339  * OnOutputBufferAvailable()
340  * @tc.type: FUNC.
341  * @tc.require:
342  */
343 HWTEST_F(MediaCodecDecoderAdapterImplTest, MediaCodecDecoderAdapterImpl_OnError_006, TestSize.Level1)
344 {
345     auto mediaCodecDecoderAdapterImpl_ = std::make_unique<MediaCodecDecoderAdapterImpl>();
346     std::string mimetype_ = "video/avc";
347     DecoderAdapterCode ret = mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(mimetype_);
348     EXPECT_EQ(ret, DecoderAdapterCode::DECODER_OK);
349     std::shared_ptr<DecoderCallbackAdapter> callback = std::make_shared<DecoderCallbackAdapterMock>();
350     EXPECT_NE(callback, nullptr);
351     mediaCodecDecoderAdapterImpl_->SetCallbackDec(callback);
352 
353     mediaCodecDecoderAdapterImpl_->OnError(100);
354     mediaCodecDecoderAdapterImpl_->OnOutputFormatChanged(nullptr);
355     mediaCodecDecoderAdapterImpl_->OnInputBufferAvailable(1, nullptr);
356     mediaCodecDecoderAdapterImpl_->OnOutputBufferAvailable(1, nullptr);
357 
358     constexpr int32_t MEMSIZE = 1024 * 1024;
359     OH_AVFormat* codecFormat = OH_AVFormat_Create();
360     OH_AVBuffer* buffer = OH_AVBuffer_Create(MEMSIZE);
361     mediaCodecDecoderAdapterImpl_->OnError(1);
362     mediaCodecDecoderAdapterImpl_->OnOutputFormatChanged(codecFormat);
363     mediaCodecDecoderAdapterImpl_->OnInputBufferAvailable(1, buffer);
364     mediaCodecDecoderAdapterImpl_->OnOutputBufferAvailable(1, buffer);
365     OH_AVFormat_Destroy(codecFormat);
366     OH_AVBuffer_Destroy(buffer);
367     codecFormat = nullptr;
368     buffer = nullptr;
369 
370     mediaCodecDecoderAdapterImpl_->callback_ = nullptr;
371     mediaCodecDecoderAdapterImpl_->OnError(100);
372     mediaCodecDecoderAdapterImpl_->OnOutputFormatChanged(nullptr);
373     mediaCodecDecoderAdapterImpl_->OnInputBufferAvailable(1, nullptr);
374     mediaCodecDecoderAdapterImpl_->OnOutputBufferAvailable(1, nullptr);
375 }
376 
377 /**
378  * @tc.name: MediaCodecDecoderAdapterImpl_SetAVCencInfo_007.
379  * @tc.desc: test of MediaCodecDecoderAdapterImpl::SetAVCencInfo()
380  * OnOutputBufferAvailable()
381  * @tc.type: FUNC.
382  * @tc.require:
383  */
384 HWTEST_F(MediaCodecDecoderAdapterImplTest, MediaCodecDecoderAdapterImpl_SetAVCencInfo_007, TestSize.Level1)
385 {
386     auto mediaCodecDecoderAdapterImpl_ = std::make_unique<MediaCodecDecoderAdapterImpl>();
387     std::string mimetype_ = "video/avc";
388     DecoderAdapterCode ret = mediaCodecDecoderAdapterImpl_->CreateVideoDecoderByMime(mimetype_);
389     EXPECT_EQ(ret, DecoderAdapterCode::DECODER_OK);
390 
391     std::shared_ptr<AudioCencInfoAdapter> cencInfo = std::make_shared<AudioCencInfoAdapterImpl>();
392     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
393 
394     const uint32_t ERR_ALGO = 10000;
395     cencInfo->SetAlgo(ERR_ALGO);
396     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
397     cencInfo->SetAlgo(0);
398     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
399     SetCencInfoAboutKeyIdIvAlgo(cencInfo);
400     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
401     SetCencInfoAboutClearHeaderAndPayLoadLens(cencInfo);
402     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
403     cencInfo->SetEncryptedBlockCount(0);
404     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
405     const uint32_t ERR_MODE = 10000;
406     cencInfo->SetMode(ERR_MODE);
407     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
408     cencInfo->SetMode(0);
409     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
410     constexpr int32_t MEMSIZE = 1024 * 1024;
411     OH_AVBuffer* buffer = OH_AVBuffer_Create(MEMSIZE);
412     mediaCodecDecoderAdapterImpl_->OnInputBufferAvailable(0, buffer);
413     EXPECT_EQ(mediaCodecDecoderAdapterImpl_->SetAVCencInfo(0, cencInfo), DecoderAdapterCode::DECODER_ERROR);
414     OH_AVBuffer_Destroy(buffer);
415     buffer = nullptr;
416 }
417 }
418 } // namespace OHOS::NWeb
419