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 #include <atomic>
16 #include <iostream>
17 #include <fstream>
18 #include <queue>
19 #include <string>
20 #include <thread>
21 #include "gtest/gtest.h"
22 #include "avcodec_audio_avbuffer_decoder_demo.h"
23
24 using namespace std;
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::MediaAVCodec;
28 using namespace OHOS::MediaAVCodec::AudioBufferDemo;
29
30 namespace {
31 class NullCheckTest : public testing::Test {
32 public:
33 static void SetUpTestCase();
34 static void TearDownTestCase();
35 void SetUp() override;
36 void TearDown() override;
37 };
38
SetUpTestCase()39 void NullCheckTest::SetUpTestCase() {}
TearDownTestCase()40 void NullCheckTest::TearDownTestCase() {}
SetUp()41 void NullCheckTest::SetUp() {}
TearDown()42 void NullCheckTest::TearDown() {}
43
44 } // namespace
45
46 /**
47 * @tc.number : NULL_CHECK_001
48 * @tc.name : CreateByMime - mime null check
49 * @tc.desc : null check test
50 */
51 HWTEST_F(NullCheckTest, NULL_CHECK_001, TestSize.Level2)
52 {
53 OH_AVCodec *codec = nullptr;
54 OH_AVErrCode result0;
55 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
56 codec = aDecBufferDemo->CreateByMime(nullptr);
57 ASSERT_EQ(codec, nullptr);
58 result0 = aDecBufferDemo->Destroy(codec);
59 ASSERT_NE(result0, AV_ERR_OK);
60 delete aDecBufferDemo;
61 }
62
63 /**
64 * @tc.number : NULL_CHECK_002
65 * @tc.name : CreateByName - mime null check
66 * @tc.desc : null check test
67 */
68 HWTEST_F(NullCheckTest, NULL_CHECK_002, TestSize.Level2)
69 {
70 OH_AVCodec *codec = nullptr;
71 OH_AVErrCode result0;
72 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
73 codec = aDecBufferDemo->CreateByName(nullptr);
74 ASSERT_EQ(codec, nullptr);
75 result0 = aDecBufferDemo->Destroy(codec);
76 ASSERT_NE(result0, AV_ERR_OK);
77 delete aDecBufferDemo;
78 }
79
80 /**
81 * @tc.number : NULL_CHECK_003
82 * @tc.name : Destroy - codec null check
83 * @tc.desc : null check test
84 */
85 HWTEST_F(NullCheckTest, NULL_CHECK_003, TestSize.Level2)
86 {
87 OH_AVCodec *codec = nullptr;
88 OH_AVErrCode result0;
89 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
90 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
91 ASSERT_NE(codec, nullptr);
92 result0 = aDecBufferDemo->Destroy(nullptr);
93 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
94 result0 = aDecBufferDemo->Destroy(codec);
95 ASSERT_EQ(result0, AV_ERR_OK);
96 delete aDecBufferDemo;
97 }
98
99 /**
100 * @tc.number : NULL_CHECK_004
101 * @tc.name : SetCallback - codec null check
102 * @tc.desc : null check test
103 */
104 HWTEST_F(NullCheckTest, NULL_CHECK_004, TestSize.Level2)
105 {
106 OH_AVCodec *codec = nullptr;
107 OH_AVErrCode result0;
108 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
109 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
110 ASSERT_NE(codec, nullptr);
111 result0 = aDecBufferDemo->SetCallback(nullptr);
112 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
113 result0 = aDecBufferDemo->Destroy(codec);
114 ASSERT_EQ(result0, AV_ERR_OK);
115 delete aDecBufferDemo;
116 }
117
118 /**
119 * @tc.number : NULL_CHECK_005
120 * @tc.name : Configure - codec null check
121 * @tc.desc : null check test
122 */
123 HWTEST_F(NullCheckTest, NULL_CHECK_005, TestSize.Level2)
124 {
125 OH_AVCodec *codec = nullptr;
126 OH_AVFormat *format = OH_AVFormat_Create();
127 int32_t channel = 1;
128 int32_t sampleRate = 8000; //8000hz
129 OH_AVErrCode result0;
130 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
131 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
132 ASSERT_NE(codec, nullptr);
133 result0 = aDecBufferDemo->SetCallback(codec);
134 ASSERT_EQ(result0, AV_ERR_OK);
135 result0 = aDecBufferDemo->Configure(nullptr, format, channel, sampleRate);
136 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
137 result0 = aDecBufferDemo->Destroy(codec);
138 ASSERT_EQ(result0, AV_ERR_OK);
139 delete aDecBufferDemo;
140 }
141
142 /**
143 * @tc.number : NULL_CHECK_006
144 * @tc.name : Configure - format null check
145 * @tc.desc : null check test
146 */
147 HWTEST_F(NullCheckTest, NULL_CHECK_006, TestSize.Level2)
148 {
149 OH_AVCodec *codec = nullptr;
150 OH_AVFormat *format = OH_AVFormat_Create();
151 int32_t channel = 1;
152 int32_t sampleRate = 8000; //8000hz
153 OH_AVErrCode result0;
154 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
155 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
156 ASSERT_NE(codec, nullptr);
157 result0 = aDecBufferDemo->SetCallback(codec);
158 ASSERT_EQ(result0, AV_ERR_OK);
159 format = nullptr;
160 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
161 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
162 result0 = aDecBufferDemo->Destroy(codec);
163 ASSERT_EQ(result0, AV_ERR_OK);
164 delete aDecBufferDemo;
165 }
166
167 /**
168 * @tc.number : NULL_CHECK_007
169 * @tc.name : Prepare - codec null check
170 * @tc.desc : null check test
171 */
172 HWTEST_F(NullCheckTest, NULL_CHECK_007, TestSize.Level2)
173 {
174 OH_AVCodec *codec = nullptr;
175 OH_AVErrCode result0;
176 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
177 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
178 ASSERT_NE(codec, nullptr);
179 result0 = aDecBufferDemo->Prepare(nullptr);
180 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
181 result0 = aDecBufferDemo->Destroy(codec);
182 ASSERT_EQ(result0, AV_ERR_OK);
183 delete aDecBufferDemo;
184 }
185
186 /**
187 * @tc.number : NULL_CHECK_008
188 * @tc.name : Start - codec null check
189 * @tc.desc : null check test
190 */
191 HWTEST_F(NullCheckTest, NULL_CHECK_008, TestSize.Level2)
192 {
193 OH_AVCodec *codec = nullptr;
194 OH_AVFormat *format = OH_AVFormat_Create();
195 int32_t channel = 1;
196 int32_t sampleRate = 8000; //8000hz
197 OH_AVErrCode result0;
198 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
199 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
200 ASSERT_NE(codec, nullptr);
201 result0 = aDecBufferDemo->SetCallback(codec);
202 ASSERT_EQ(result0, AV_ERR_OK);
203 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
204 ASSERT_EQ(result0, AV_ERR_OK);
205 result0 = aDecBufferDemo->Start(nullptr);
206 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
207 result0 = aDecBufferDemo->Destroy(codec);
208 ASSERT_EQ(result0, AV_ERR_OK);
209 delete aDecBufferDemo;
210 }
211
212 /**
213 * @tc.number : NULL_CHECK_009
214 * @tc.name : Stop - codec null check
215 * @tc.desc : null check test
216 */
217 HWTEST_F(NullCheckTest, NULL_CHECK_009, TestSize.Level2)
218 {
219 OH_AVCodec *codec = nullptr;
220 OH_AVFormat *format = OH_AVFormat_Create();
221 int32_t channel = 1;
222 int32_t sampleRate = 8000; //8000hz
223 OH_AVErrCode result0;
224 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
225 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
226 ASSERT_NE(codec, nullptr);
227 result0 = aDecBufferDemo->SetCallback(codec);
228 ASSERT_EQ(result0, AV_ERR_OK);
229 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
230 ASSERT_EQ(result0, AV_ERR_OK);
231 result0 = aDecBufferDemo->Start(codec);
232 ASSERT_EQ(result0, AV_ERR_OK);
233 result0 = aDecBufferDemo->Stop(nullptr);
234 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
235 result0 = aDecBufferDemo->Destroy(codec);
236 ASSERT_EQ(result0, AV_ERR_OK);
237 delete aDecBufferDemo;
238 }
239
240 /**
241 * @tc.number : NULL_CHECK_010
242 * @tc.name : Flush - codec null check
243 * @tc.desc : null check test
244 */
245 HWTEST_F(NullCheckTest, NULL_CHECK_010, TestSize.Level2)
246 {
247 OH_AVCodec *codec = nullptr;
248 OH_AVFormat *format = OH_AVFormat_Create();
249 int32_t channel = 1;
250 int32_t sampleRate = 8000; //8000hz
251 OH_AVErrCode result0;
252 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
253 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
254 ASSERT_NE(codec, nullptr);
255 result0 = aDecBufferDemo->SetCallback(codec);
256 ASSERT_EQ(result0, AV_ERR_OK);
257 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
258 ASSERT_EQ(result0, AV_ERR_OK);
259 result0 = aDecBufferDemo->Start(codec);
260 ASSERT_EQ(result0, AV_ERR_OK);
261 result0 = aDecBufferDemo->Flush(nullptr);
262 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
263 result0 = aDecBufferDemo->Destroy(codec);
264 ASSERT_EQ(result0, AV_ERR_OK);
265 delete aDecBufferDemo;
266 }
267
268 /**
269 * @tc.number : NULL_CHECK_011
270 * @tc.name : Reset - codec null check
271 * @tc.desc : null check test
272 */
273 HWTEST_F(NullCheckTest, NULL_CHECK_011, TestSize.Level2)
274 {
275 OH_AVCodec *codec = nullptr;
276 OH_AVErrCode result0;
277 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
278 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
279 ASSERT_NE(codec, nullptr);
280 result0 = aDecBufferDemo->Reset(nullptr);
281 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
282 result0 = aDecBufferDemo->Destroy(codec);
283 ASSERT_EQ(result0, AV_ERR_OK);
284 delete aDecBufferDemo;
285 }
286
287 /**
288 * @tc.number : NULL_CHECK_012
289 * @tc.name : GetOutputDescription - codec null check
290 * @tc.desc : null check test
291 */
292 HWTEST_F(NullCheckTest, NULL_CHECK_012, TestSize.Level2)
293 {
294 OH_AVCodec *codec = nullptr;
295 OH_AVFormat *format = OH_AVFormat_Create();
296 int32_t channel = 1;
297 int32_t sampleRate = 8000; //8000hz
298 OH_AVErrCode result0;
299 OH_AVFormat *result1;
300 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
301 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
302 ASSERT_NE(codec, nullptr);
303 result0 = aDecBufferDemo->SetCallback(codec);
304 ASSERT_EQ(result0, AV_ERR_OK);
305 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
306 ASSERT_EQ(result0, AV_ERR_OK);
307 result0 = aDecBufferDemo->Start(codec);
308 ASSERT_EQ(result0, AV_ERR_OK);
309 result1 = aDecBufferDemo->GetOutputDescription(nullptr);
310 ASSERT_EQ(result1, nullptr);
311 result0 = aDecBufferDemo->Destroy(codec);
312 ASSERT_EQ(result0, AV_ERR_OK);
313 delete aDecBufferDemo;
314 }
315
316 /**
317 * @tc.number : NULL_CHECK_013
318 * @tc.name : PushInputData - codec null check
319 * @tc.desc : null check test
320 */
321 HWTEST_F(NullCheckTest, NULL_CHECK_013, TestSize.Level2)
322 {
323 OH_AVCodec *codec = nullptr;
324 OH_AVFormat *format = OH_AVFormat_Create();
325 int32_t channel = 1;
326 int32_t sampleRate = 8000; //8000hz
327 uint32_t index;
328 OH_AVErrCode result0;
329 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
330 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
331 ASSERT_NE(codec, nullptr);
332 result0 = aDecBufferDemo->SetCallback(codec);
333 ASSERT_EQ(result0, AV_ERR_OK);
334 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
335 ASSERT_EQ(result0, AV_ERR_OK);
336 result0 = aDecBufferDemo->Start(codec);
337 ASSERT_EQ(result0, AV_ERR_OK);
338 index = aDecBufferDemo->GetInputIndex();
339 result0 = aDecBufferDemo->PushInputData(nullptr, index);
340 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
341 result0 = aDecBufferDemo->Destroy(codec);
342 ASSERT_EQ(result0, AV_ERR_OK);
343 delete aDecBufferDemo;
344 }
345
346 /**
347 * @tc.number : NULL_CHECK_014
348 * @tc.name : FreeOutputData - codec null check
349 * @tc.desc : null check test
350 */
351 HWTEST_F(NullCheckTest, NULL_CHECK_014, TestSize.Level2)
352 {
353 OH_AVCodec *codec = nullptr;
354 OH_AVFormat *format = OH_AVFormat_Create();
355 int32_t channel = 1;
356 int32_t sampleRate = 8000; //8000hz
357 uint32_t index;
358 OH_AVErrCode result0;
359 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
360 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
361 ASSERT_NE(codec, nullptr);
362 result0 = aDecBufferDemo->SetCallback(codec);
363 ASSERT_EQ(result0, AV_ERR_OK);
364 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
365 ASSERT_EQ(result0, AV_ERR_OK);
366 result0 = aDecBufferDemo->Start(codec);
367 ASSERT_EQ(result0, AV_ERR_OK);
368 index = aDecBufferDemo->GetInputIndex();
369 index = -1;
370 result0 = aDecBufferDemo->PushInputDataEOS(codec, index);
371 ASSERT_NE(result0, AV_ERR_OK);
372 index = aDecBufferDemo->GetOutputIndex();
373 result0 = aDecBufferDemo->FreeOutputData(nullptr, index);
374 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
375 result0 = aDecBufferDemo->Destroy(codec);
376 ASSERT_EQ(result0, AV_ERR_OK);
377 delete aDecBufferDemo;
378 }
379
380 /**
381 * @tc.number : NULL_CHECK_015
382 * @tc.name : IsValid - codec null check
383 * @tc.desc : null check test
384 */
385 HWTEST_F(NullCheckTest, NULL_CHECK_015, TestSize.Level2)
386 {
387 OH_AVCodec *codec = nullptr;
388 bool *isValid = nullptr;
389 OH_AVErrCode result0;
390 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
391 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
392 ASSERT_NE(codec, nullptr);
393 result0 = aDecBufferDemo->IsValid(nullptr, isValid);
394 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
395 result0 = aDecBufferDemo->Destroy(codec);
396 ASSERT_EQ(result0, AV_ERR_OK);
397 delete aDecBufferDemo;
398 }
399
400 /**
401 * @tc.number : NULL_CHECK_016
402 * @tc.name : IsValid - isValid null check
403 * @tc.desc : null check test
404 */
405 HWTEST_F(NullCheckTest, NULL_CHECK_016, TestSize.Level2)
406 {
407 OH_AVCodec *codec = nullptr;
408 bool *isValid = nullptr;
409 OH_AVErrCode result0;
410 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
411 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
412 ASSERT_NE(codec, nullptr);
413 isValid = nullptr;
414 result0 = aDecBufferDemo->IsValid(codec, isValid);
415 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
416 result0 = aDecBufferDemo->Destroy(codec);
417 ASSERT_EQ(result0, AV_ERR_OK);
418 delete aDecBufferDemo;
419 }
420
421 /**
422 * @tc.number : NULL_CHECK_017
423 * @tc.name : PushInputDataEOS - codec null check
424 * @tc.desc : null check test
425 */
426 HWTEST_F(NullCheckTest, NULL_CHECK_017, TestSize.Level2)
427 {
428 OH_AVCodec *codec = nullptr;
429 OH_AVFormat *format = OH_AVFormat_Create();
430 int32_t channel = 1;
431 int32_t sampleRate = 8000; //8000hz
432 uint32_t index;
433 OH_AVErrCode result0;
434 ADecBufferDemo *aDecBufferDemo = new ADecBufferDemo();
435 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_G711MU);
436 ASSERT_NE(codec, nullptr);
437 result0 = aDecBufferDemo->SetCallback(codec);
438 ASSERT_EQ(result0, AV_ERR_OK);
439 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
440 ASSERT_EQ(result0, AV_ERR_OK);
441 result0 = aDecBufferDemo->Start(codec);
442 ASSERT_EQ(result0, AV_ERR_OK);
443 index = aDecBufferDemo->GetInputIndex();
444 result0 = aDecBufferDemo->PushInputDataEOS(nullptr, index);
445 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
446 result0 = aDecBufferDemo->Destroy(codec);
447 ASSERT_EQ(result0, AV_ERR_OK);
448 delete aDecBufferDemo;
449 }
450
451
452 /**
453 * @tc.number : NULL_CHECK_018
454 * @tc.name : NULL_CHECK_018
455 * @tc.desc : SetIntBuffer - format null check
456 */
457 HWTEST_F(NullCheckTest, NULL_CHECK_018, TestSize.Level2)
458 {
459 std::vector<int32_t> vDepth = { 0 };
460 int32_t* trackIdsDepth = vDepth.data();
461
462 bool ret = OH_AVFormat_SetIntBuffer(nullptr, OH_MD_KEY_REFERENCE_TRACK_IDS, trackIdsDepth, vDepth.size());
463 ASSERT_EQ(ret, false);
464 }
465
466
467 /**
468 * @tc.number : NULL_CHECK_019
469 * @tc.name : NULL_CHECK_019
470 * @tc.desc : SetIntBuffer - key null check
471 */
472 HWTEST_F(NullCheckTest, NULL_CHECK_019, TestSize.Level2)
473 {
474 OH_AVFormat* format = OH_AVFormat_Create();
475 std::vector<int32_t> vDepth = { 0 };
476 int32_t* trackIdsDepth = vDepth.data();
477
478 bool ret = OH_AVFormat_SetIntBuffer(format, nullptr, trackIdsDepth, vDepth.size());
479 OH_AVFormat_Destroy(format);
480
481 ASSERT_EQ(ret, false);
482 }
483
484
485 /**
486 * @tc.number : NULL_CHECK_020
487 * @tc.name : NULL_CHECK_020
488 * @tc.desc : SetIntBuffer - addr null check
489 */
490 HWTEST_F(NullCheckTest, NULL_CHECK_020, TestSize.Level2)
491 {
492 OH_AVFormat* format = OH_AVFormat_Create();
493 std::vector<int32_t> vDepth = { 0 };
494
495 bool ret = OH_AVFormat_SetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, nullptr, vDepth.size());
496 OH_AVFormat_Destroy(format);
497
498 ASSERT_EQ(ret, false);
499 }
500
501
502 /**
503 * @tc.number : NULL_CHECK_021
504 * @tc.name : NULL_CHECK_021
505 * @tc.desc : SetIntBuffer - size is zero
506 */
507 HWTEST_F(NullCheckTest, NULL_CHECK_021, TestSize.Level2)
508 {
509 OH_AVFormat* format = OH_AVFormat_Create();
510 std::vector<int32_t> vDepth = { 0 };
511 int32_t* trackIdsDepth = vDepth.data();
512
513 bool ret = OH_AVFormat_SetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, trackIdsDepth, 0);
514 OH_AVFormat_Destroy(format);
515
516 ASSERT_EQ(ret, false);
517 }
518
519
520 /**
521 * @tc.number : NULL_CHECK_022
522 * @tc.name : NULL_CHECK_022
523 * @tc.desc : GetIntBuffer - format null check
524 */
525 HWTEST_F(NullCheckTest, NULL_CHECK_022, TestSize.Level2)
526 {
527 OH_AVFormat* format = OH_AVFormat_Create();
528 std::vector<int32_t> vDepth = { 0 };
529 int32_t* trackIdsDepth = vDepth.data();
530
531 bool ret = OH_AVFormat_SetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, trackIdsDepth, vDepth.size());
532 ASSERT_EQ(ret, true);
533
534 int32_t* getBuffer = nullptr;
535 size_t getSize = 0;
536 ret = OH_AVFormat_GetIntBuffer(nullptr, OH_MD_KEY_REFERENCE_TRACK_IDS, &getBuffer, &getSize);
537
538 OH_AVFormat_Destroy(format);
539 ASSERT_EQ(ret, false);
540 }
541
542
543 /**
544 * @tc.number : NULL_CHECK_023
545 * @tc.name : NULL_CHECK_023
546 * @tc.desc : GetIntBuffer - key null check
547 */
548 HWTEST_F(NullCheckTest, NULL_CHECK_023, TestSize.Level2)
549 {
550 OH_AVFormat* format = OH_AVFormat_Create();
551 std::vector<int32_t> vDepth = { 0 };
552 int32_t* trackIdsDepth = vDepth.data();
553
554 bool ret = OH_AVFormat_SetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, trackIdsDepth, vDepth.size());
555 ASSERT_EQ(ret, true);
556
557 int32_t* getBuffer = nullptr;
558 size_t getSize = 0;
559 ret = OH_AVFormat_GetIntBuffer(format, nullptr, &getBuffer, &getSize);
560
561 OH_AVFormat_Destroy(format);
562 ASSERT_EQ(ret, false);
563 }
564
565
566 /**
567 * @tc.number : NULL_CHECK_024
568 * @tc.name : NULL_CHECK_024
569 * @tc.desc : GetIntBuffer - addr null check
570 */
571 HWTEST_F(NullCheckTest, NULL_CHECK_024, TestSize.Level2)
572 {
573 OH_AVFormat* format = OH_AVFormat_Create();
574 std::vector<int32_t> vDepth = { 0 };
575 int32_t* trackIdsDepth = vDepth.data();
576
577 bool ret = OH_AVFormat_SetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, trackIdsDepth, vDepth.size());
578 ASSERT_EQ(ret, true);
579
580 size_t getSize = 0;
581 ret = OH_AVFormat_GetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, nullptr, &getSize);
582
583 OH_AVFormat_Destroy(format);
584 ASSERT_EQ(ret, false);
585 }
586
587
588 /**
589 * @tc.number : NULL_CHECK_025
590 * @tc.name : NULL_CHECK_025
591 * @tc.desc : GetIntBuffer - size null check
592 */
593 HWTEST_F(NullCheckTest, NULL_CHECK_025, TestSize.Level2)
594 {
595 OH_AVFormat* format = OH_AVFormat_Create();
596 std::vector<int32_t> vDepth = { 0 };
597 int32_t* trackIdsDepth = vDepth.data();
598
599 bool ret = OH_AVFormat_SetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, trackIdsDepth, vDepth.size());
600 ASSERT_EQ(ret, true);
601
602 int32_t* getBuffer = nullptr;
603 ret = OH_AVFormat_GetIntBuffer(format, OH_MD_KEY_REFERENCE_TRACK_IDS, &getBuffer, nullptr);
604
605 OH_AVFormat_Destroy(format);
606 ASSERT_EQ(ret, false);
607 }
608
609
610 /**
611 * @tc.number : NULL_CHECK_026
612 * @tc.name : NULL_CHECK_026
613 * @tc.desc : QueryInputBuffer - codec null check
614 */
615 HWTEST_F(NullCheckTest, NULL_CHECK_026, TestSize.Level2)
616 {
617 OH_AVCodec* codec = nullptr;
618 OH_AVFormat* format = OH_AVFormat_Create();
619 int32_t channel = 1;
620 int32_t sampleRate = 16000;
621 OH_AVErrCode result0;
622 ADecBufferDemo* aDecBufferDemo = new ADecBufferDemo();
623 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
624 ASSERT_NE(codec, nullptr);
625 OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
626 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
627 ASSERT_EQ(result0, AV_ERR_OK);
628 result0 = aDecBufferDemo->Start(codec);
629 ASSERT_EQ(result0, AV_ERR_OK);
630
631 uint32_t index = -1;
632 result0 = OH_AudioCodec_QueryInputBuffer(nullptr, &index, 20000);
633 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
634
635 result0 = aDecBufferDemo->Destroy(codec);
636 ASSERT_EQ(result0, AV_ERR_OK);
637 delete aDecBufferDemo;
638 }
639
640
641 /**
642 * @tc.number : NULL_CHECK_027
643 * @tc.name : NULL_CHECK_027
644 * @tc.desc : QueryInputBuffer - index null check
645 */
646 HWTEST_F(NullCheckTest, NULL_CHECK_027, TestSize.Level2)
647 {
648 OH_AVCodec* codec = nullptr;
649 OH_AVFormat* format = OH_AVFormat_Create();
650 int32_t channel = 1;
651 int32_t sampleRate = 16000;
652 OH_AVErrCode result0;
653 ADecBufferDemo* aDecBufferDemo = new ADecBufferDemo();
654 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
655 ASSERT_NE(codec, nullptr);
656 OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
657 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
658 ASSERT_EQ(result0, AV_ERR_OK);
659 result0 = aDecBufferDemo->Start(codec);
660 ASSERT_EQ(result0, AV_ERR_OK);
661
662 result0 = OH_AudioCodec_QueryInputBuffer(codec, nullptr, 20000);
663 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
664
665 result0 = aDecBufferDemo->Destroy(codec);
666 ASSERT_EQ(result0, AV_ERR_OK);
667 delete aDecBufferDemo;
668 }
669
670
671 /**
672 * @tc.number : NULL_CHECK_028
673 * @tc.name : NULL_CHECK_028
674 * @tc.desc : GetInputBuffer - codec null check
675 */
676 HWTEST_F(NullCheckTest, NULL_CHECK_028, TestSize.Level2)
677 {
678 OH_AVCodec* codec = nullptr;
679 OH_AVFormat* format = OH_AVFormat_Create();
680 int32_t channel = 1;
681 int32_t sampleRate = 16000;
682 OH_AVErrCode result0;
683 ADecBufferDemo* aDecBufferDemo = new ADecBufferDemo();
684 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
685 ASSERT_NE(codec, nullptr);
686 OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
687 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
688 ASSERT_EQ(result0, AV_ERR_OK);
689 result0 = aDecBufferDemo->Start(codec);
690 ASSERT_EQ(result0, AV_ERR_OK);
691
692 uint32_t index = -1;
693 result0 = OH_AudioCodec_QueryInputBuffer(codec, &index, 20000);
694 ASSERT_EQ(result0, AV_ERR_OK);
695
696 OH_AVBuffer* inputBuf = OH_AudioCodec_GetInputBuffer(nullptr, index);
697 ASSERT_EQ(inputBuf, nullptr);
698
699 result0 = aDecBufferDemo->Destroy(codec);
700 ASSERT_EQ(result0, AV_ERR_OK);
701 delete aDecBufferDemo;
702 }
703
704
705 /**
706 * @tc.number : NULL_CHECK_029
707 * @tc.name : NULL_CHECK_029
708 * @tc.desc : QueryOutputBuffer - codec null check
709 */
710 HWTEST_F(NullCheckTest, NULL_CHECK_029, TestSize.Level2)
711 {
712 OH_AVCodec* codec = nullptr;
713 OH_AVFormat* format = OH_AVFormat_Create();
714 int32_t channel = 1;
715 int32_t sampleRate = 16000;
716 OH_AVErrCode result0;
717 ADecBufferDemo* aDecBufferDemo = new ADecBufferDemo();
718 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
719 ASSERT_NE(codec, nullptr);
720 OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
721 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
722 ASSERT_EQ(result0, AV_ERR_OK);
723 result0 = aDecBufferDemo->Start(codec);
724 ASSERT_EQ(result0, AV_ERR_OK);
725
726 uint32_t index = -1;
727 result0 = OH_AudioCodec_QueryOutputBuffer(nullptr, &index, 20000);
728 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
729
730 result0 = aDecBufferDemo->Destroy(codec);
731 ASSERT_EQ(result0, AV_ERR_OK);
732 delete aDecBufferDemo;
733 }
734
735
736 /**
737 * @tc.number : NULL_CHECK_030
738 * @tc.name : NULL_CHECK_030
739 * @tc.desc : QueryOutputBuffer - index null check
740 */
741 HWTEST_F(NullCheckTest, NULL_CHECK_030, TestSize.Level2)
742 {
743 OH_AVCodec* codec = nullptr;
744 OH_AVFormat* format = OH_AVFormat_Create();
745 int32_t channel = 1;
746 int32_t sampleRate = 16000;
747 OH_AVErrCode result0;
748 ADecBufferDemo* aDecBufferDemo = new ADecBufferDemo();
749 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
750 ASSERT_NE(codec, nullptr);
751 OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
752 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
753 ASSERT_EQ(result0, AV_ERR_OK);
754 result0 = aDecBufferDemo->Start(codec);
755 ASSERT_EQ(result0, AV_ERR_OK);
756
757 result0 = OH_AudioCodec_QueryOutputBuffer(codec, nullptr, 20000);
758 ASSERT_EQ(result0, AV_ERR_INVALID_VAL);
759
760 result0 = aDecBufferDemo->Destroy(codec);
761 ASSERT_EQ(result0, AV_ERR_OK);
762 delete aDecBufferDemo;
763 }
764
765
766 /**
767 * @tc.number : NULL_CHECK_031
768 * @tc.name : NULL_CHECK_031
769 * @tc.desc : GetOutputBuffer - codec null check
770 */
771 HWTEST_F(NullCheckTest, NULL_CHECK_031, TestSize.Level2)
772 {
773 OH_AVCodec* codec = nullptr;
774 OH_AVFormat* format = OH_AVFormat_Create();
775 int32_t channel = 1;
776 int32_t sampleRate = 16000;
777 OH_AVErrCode result0;
778 ADecBufferDemo* aDecBufferDemo = new ADecBufferDemo();
779 codec = aDecBufferDemo->CreateByMime(OH_AVCODEC_MIMETYPE_AUDIO_AAC);
780 ASSERT_NE(codec, nullptr);
781 OH_AVFormat_SetIntValue(format, OH_MD_KEY_ENABLE_SYNC_MODE, 1);
782 result0 = aDecBufferDemo->Configure(codec, format, channel, sampleRate);
783 ASSERT_EQ(result0, AV_ERR_OK);
784 result0 = aDecBufferDemo->Start(codec);
785 ASSERT_EQ(result0, AV_ERR_OK);
786
787 uint32_t index = 0;
788 OH_AVBuffer* outputBuf = OH_AudioCodec_GetOutputBuffer(nullptr, index);
789 ASSERT_EQ(outputBuf, nullptr);
790
791 result0 = aDecBufferDemo->Destroy(codec);
792 ASSERT_EQ(result0, AV_ERR_OK);
793 delete aDecBufferDemo;
794 }