1 /* 2 * Copyright (C) 2022 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 "AudioDecoderDemoCommon.h" 19 20 using namespace std; 21 using namespace testing::ext; 22 using namespace OHOS; 23 using namespace OHOS::MediaAVCodec; 24 25 namespace { 26 class NativeNullCheckTest : public testing::Test { 27 public: 28 static void SetUpTestCase(); 29 static void TearDownTestCase(); 30 void SetUp() override; 31 void TearDown() override; 32 }; 33 SetUpTestCase()34 void NativeNullCheckTest::SetUpTestCase() {} TearDownTestCase()35 void NativeNullCheckTest::TearDownTestCase() {} SetUp()36 void NativeNullCheckTest::SetUp() {} TearDown()37 void NativeNullCheckTest::TearDown() {} 38 } 39 40 41 /** 42 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_001 43 * @tc.name : OH_AudioDecoder_CreateByMime - mime check 44 * @tc.desc : null check test 45 */ 46 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_001, TestSize.Level2) 47 { 48 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 49 OH_AVCodec* handle = decoderDemo->NativeCreateByMime(nullptr); 50 ASSERT_EQ(nullptr, handle); 51 52 delete decoderDemo; 53 } 54 55 56 /** 57 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_002 58 * @tc.name : OH_AudioDecoder_CreateByName - name check 59 * @tc.desc : null check test 60 */ 61 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_002, TestSize.Level2) 62 { 63 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 64 OH_AVCodec* handle = decoderDemo->NativeCreateByName(nullptr); 65 ASSERT_EQ(nullptr, handle); 66 67 delete decoderDemo; 68 } 69 70 71 /** 72 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_003 73 * @tc.name : OH_AudioDecoder_Destory - codec check 74 * @tc.desc : null check test 75 */ 76 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_003, TestSize.Level2) 77 { 78 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 79 OH_AVErrCode ret = decoderDemo->NativeDestroy(nullptr); 80 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 81 82 delete decoderDemo; 83 } 84 85 86 /** 87 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_004 88 * @tc.name : OH_AudioDecoder_SetCallback - codec check 89 * @tc.desc : null check test 90 */ 91 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_004, TestSize.Level2) 92 { 93 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 94 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 95 ASSERT_NE(nullptr, handle); 96 97 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 98 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 99 OH_AVErrCode ret = decoderDemo->NativeSetCallback(nullptr, cb); 100 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 101 102 decoderDemo->NativeDestroy(handle); 103 delete decoderDemo; 104 } 105 106 107 /** 108 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_005 109 * @tc.name : OH_AudioDecoder_SetCallback - callback check 110 * @tc.desc : null check test 111 */ 112 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_005, TestSize.Level2) 113 { 114 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 115 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 116 ASSERT_NE(nullptr, handle); 117 118 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 119 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 120 OH_AVErrCode ret; 121 122 cb.onError = nullptr; 123 ret = decoderDemo->NativeSetCallback(handle, cb); 124 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 125 126 cb.onStreamChanged = nullptr; 127 ret = decoderDemo->NativeSetCallback(handle, cb); 128 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 129 130 cb.onNeedInputData = nullptr; 131 ret = decoderDemo->NativeSetCallback(handle, cb); 132 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 133 134 cb.onNeedOutputData = nullptr; 135 ret = decoderDemo->NativeSetCallback(handle, cb); 136 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 137 138 decoderDemo->NativeDestroy(handle); 139 delete decoderDemo; 140 } 141 142 143 /** 144 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_006 145 * @tc.name : OH_AudioDecoder_Configure - codec check 146 * @tc.desc : null check test 147 */ 148 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_006, TestSize.Level2) 149 { 150 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 151 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 152 ASSERT_NE(nullptr, handle); 153 154 OH_AVFormat* format = OH_AVFormat_Create(); 155 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 156 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 157 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 158 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 159 160 OH_AVErrCode ret = decoderDemo->NativeConfigure(nullptr, format); 161 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 162 163 OH_AVFormat_Destroy(format); 164 decoderDemo->NativeDestroy(handle); 165 delete decoderDemo; 166 } 167 168 169 /** 170 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_007 171 * @tc.name : OH_AudioDecoder_Configure - format check 172 * @tc.desc : null check test 173 */ 174 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_007, TestSize.Level2) 175 { 176 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 177 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 178 ASSERT_NE(nullptr, handle); 179 180 OH_AVErrCode ret = decoderDemo->NativeConfigure(handle, nullptr); 181 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 182 183 decoderDemo->NativeDestroy(handle); 184 delete decoderDemo; 185 } 186 187 188 /** 189 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_008 190 * @tc.name : OH_AudioDecoder_Prepare - codec check 191 * @tc.desc : null check test 192 */ 193 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_008, TestSize.Level2) 194 { 195 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 196 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 197 ASSERT_NE(nullptr, handle); 198 199 OH_AVFormat* format = OH_AVFormat_Create(); 200 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 201 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 202 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 203 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 204 205 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 206 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 207 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 208 ASSERT_EQ(AV_ERR_OK, ret); 209 210 ret = decoderDemo->NativeConfigure(handle, format); 211 ASSERT_EQ(AV_ERR_OK, ret); 212 213 ret = decoderDemo->NativePrepare(nullptr); 214 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 215 216 OH_AVFormat_Destroy(format); 217 decoderDemo->NativeDestroy(handle); 218 delete decoderDemo; 219 } 220 221 222 /** 223 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_009 224 * @tc.name : OH_AudioDecoder_Start - codec check 225 * @tc.desc : null check test 226 */ 227 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_009, TestSize.Level2) 228 { 229 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 230 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 231 ASSERT_NE(nullptr, handle); 232 233 OH_AVFormat* format = OH_AVFormat_Create(); 234 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 235 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 236 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 237 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 238 239 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 240 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 241 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 242 ASSERT_EQ(AV_ERR_OK, ret); 243 244 ret = decoderDemo->NativeConfigure(handle, format); 245 ASSERT_EQ(AV_ERR_OK, ret); 246 247 ret = decoderDemo->NativePrepare(handle); 248 ASSERT_EQ(AV_ERR_OK, ret); 249 250 ret = decoderDemo->NativeStart(nullptr); 251 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 252 253 OH_AVFormat_Destroy(format); 254 decoderDemo->NativeDestroy(handle); 255 delete decoderDemo; 256 } 257 258 259 /** 260 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_010 261 * @tc.name : OH_AudioDecoder_Stop - codec check 262 * @tc.desc : null check test 263 */ 264 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_010, TestSize.Level2) 265 { 266 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 267 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 268 ASSERT_NE(nullptr, handle); 269 270 OH_AVFormat* format = OH_AVFormat_Create(); 271 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 272 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 273 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 274 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 275 276 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 277 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 278 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 279 ASSERT_EQ(AV_ERR_OK, ret); 280 281 ret = decoderDemo->NativeConfigure(handle, format); 282 ASSERT_EQ(AV_ERR_OK, ret); 283 284 ret = decoderDemo->NativePrepare(handle); 285 ASSERT_EQ(AV_ERR_OK, ret); 286 287 ret = decoderDemo->NativeStart(handle); 288 ASSERT_EQ(AV_ERR_OK, ret); 289 290 ret = decoderDemo->NativeStop(nullptr); 291 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 292 293 OH_AVFormat_Destroy(format); 294 decoderDemo->NativeDestroy(handle); 295 delete decoderDemo; 296 } 297 298 299 /** 300 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_011 301 * @tc.name : OH_AudioDecoder_Flush - codec check 302 * @tc.desc : null check test 303 */ 304 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_011, TestSize.Level2) 305 { 306 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 307 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 308 ASSERT_NE(nullptr, handle); 309 310 OH_AVFormat* format = OH_AVFormat_Create(); 311 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 312 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 313 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 314 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 315 316 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 317 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 318 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 319 ASSERT_EQ(AV_ERR_OK, ret); 320 321 ret = decoderDemo->NativeConfigure(handle, format); 322 ASSERT_EQ(AV_ERR_OK, ret); 323 324 ret = decoderDemo->NativePrepare(handle); 325 ASSERT_EQ(AV_ERR_OK, ret); 326 327 ret = decoderDemo->NativeStart(handle); 328 ASSERT_EQ(AV_ERR_OK, ret); 329 330 ret = decoderDemo->NativeFlush(nullptr); 331 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 332 333 OH_AVFormat_Destroy(format); 334 decoderDemo->NativeDestroy(handle); 335 delete decoderDemo; 336 } 337 338 339 /** 340 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_012 341 * @tc.name : OH_AudioDecoder_Reset - codec check 342 * @tc.desc : null check test 343 */ 344 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_012, TestSize.Level2) 345 { 346 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 347 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 348 ASSERT_NE(nullptr, handle); 349 350 OH_AVErrCode ret = decoderDemo->NativeReset(nullptr); 351 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 352 353 decoderDemo->NativeDestroy(handle); 354 delete decoderDemo; 355 } 356 357 358 /** 359 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_013 360 * @tc.name : OH_AudioDecoder_GetOutputDescription - codec check 361 * @tc.desc : null check test 362 */ 363 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_013, TestSize.Level2) 364 { 365 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 366 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 367 ASSERT_NE(nullptr, handle); 368 369 OH_AVFormat* format = OH_AVFormat_Create(); 370 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 371 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 372 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 373 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 374 375 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 376 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 377 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 378 ASSERT_EQ(AV_ERR_OK, ret); 379 380 ret = decoderDemo->NativeConfigure(handle, format); 381 ASSERT_EQ(AV_ERR_OK, ret); 382 383 ret = decoderDemo->NativePrepare(handle); 384 ASSERT_EQ(AV_ERR_OK, ret); 385 386 ret = decoderDemo->NativeStart(handle); 387 ASSERT_EQ(AV_ERR_OK, ret); 388 389 OH_AVFormat* formatRet = decoderDemo->NativeGetOutputDescription(nullptr); 390 ASSERT_EQ(nullptr, formatRet); 391 392 OH_AVFormat_Destroy(format); 393 decoderDemo->NativeDestroy(handle); 394 delete decoderDemo; 395 } 396 397 398 /** 399 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_014 400 * @tc.name : OH_AudioDecoder_SetParameter - codec check 401 * @tc.desc : null check test 402 */ 403 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_014, TestSize.Level2) 404 { 405 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 406 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 407 ASSERT_NE(nullptr, handle); 408 409 OH_AVFormat* format = OH_AVFormat_Create(); 410 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 411 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 412 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 413 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 414 415 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 416 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 417 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 418 ASSERT_EQ(AV_ERR_OK, ret); 419 420 ret = decoderDemo->NativeConfigure(handle, format); 421 ASSERT_EQ(AV_ERR_OK, ret); 422 423 ret = decoderDemo->NativePrepare(handle); 424 ASSERT_EQ(AV_ERR_OK, ret); 425 426 ret = decoderDemo->NativeStart(handle); 427 ASSERT_EQ(AV_ERR_OK, ret); 428 429 ret = decoderDemo->NativeSetParameter(nullptr, format); 430 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 431 432 OH_AVFormat_Destroy(format); 433 decoderDemo->NativeDestroy(handle); 434 delete decoderDemo; 435 } 436 437 438 /** 439 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_015 440 * @tc.name : OH_AudioDecoder_SetParameter - format check 441 * @tc.desc : null check test 442 */ 443 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_015, TestSize.Level2) 444 { 445 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 446 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 447 ASSERT_NE(nullptr, handle); 448 449 OH_AVFormat* format = OH_AVFormat_Create(); 450 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 451 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 452 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 453 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 454 455 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 456 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 457 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 458 ASSERT_EQ(AV_ERR_OK, ret); 459 460 ret = decoderDemo->NativeConfigure(handle, format); 461 ASSERT_EQ(AV_ERR_OK, ret); 462 463 ret = decoderDemo->NativePrepare(handle); 464 ASSERT_EQ(AV_ERR_OK, ret); 465 466 ret = decoderDemo->NativeStart(handle); 467 ASSERT_EQ(AV_ERR_OK, ret); 468 469 ret = decoderDemo->NativeSetParameter(handle, nullptr); 470 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 471 472 OH_AVFormat_Destroy(format); 473 decoderDemo->NativeDestroy(handle); 474 delete decoderDemo; 475 } 476 477 478 /** 479 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_016 480 * @tc.name : OH_AudioDecoder_PushInputData - codec check 481 * @tc.desc : null check test 482 */ 483 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_016, TestSize.Level2) 484 { 485 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 486 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 487 ASSERT_NE(nullptr, handle); 488 489 OH_AVFormat* format = OH_AVFormat_Create(); 490 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 491 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 492 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 493 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 494 495 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 496 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 497 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 498 ASSERT_EQ(AV_ERR_OK, ret); 499 500 ret = decoderDemo->NativeConfigure(handle, format); 501 ASSERT_EQ(AV_ERR_OK, ret); 502 503 ret = decoderDemo->NativePrepare(handle); 504 ASSERT_EQ(AV_ERR_OK, ret); 505 506 ret = decoderDemo->NativeStart(handle); 507 ASSERT_EQ(AV_ERR_OK, ret); 508 509 OH_AVCodecBufferAttr info; 510 info.size = 100; 511 info.offset = 0; 512 info.pts = 0; 513 info.flags = AVCODEC_BUFFER_FLAGS_NONE; 514 uint32_t index = decoderDemo->NativeGetInputIndex(); 515 ret = decoderDemo->NativePushInputData(nullptr, index, info); 516 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 517 518 OH_AVFormat_Destroy(format); 519 decoderDemo->NativeDestroy(handle); 520 delete decoderDemo; 521 } 522 523 524 /** 525 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_017 526 * @tc.name : OH_AudioDecoder_FreeOutputData - codec check 527 * @tc.desc : null check test 528 */ 529 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_017, TestSize.Level2) 530 { 531 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 532 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 533 ASSERT_NE(nullptr, handle); 534 535 OH_AVFormat* format = OH_AVFormat_Create(); 536 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 537 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 538 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 539 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 540 541 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 542 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 543 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 544 ASSERT_EQ(AV_ERR_OK, ret); 545 546 ret = decoderDemo->NativeConfigure(handle, format); 547 ASSERT_EQ(AV_ERR_OK, ret); 548 549 ret = decoderDemo->NativePrepare(handle); 550 ASSERT_EQ(AV_ERR_OK, ret); 551 552 ret = decoderDemo->NativeStart(handle); 553 ASSERT_EQ(AV_ERR_OK, ret); 554 555 uint32_t index = 0; 556 ret = decoderDemo->NativeFreeOutputData(nullptr, index); 557 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 558 559 OH_AVFormat_Destroy(format); 560 decoderDemo->NativeDestroy(handle); 561 delete decoderDemo; 562 } 563 564 565 /** 566 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_018 567 * @tc.name : OH_AudioDecoder_IsValid - codec check 568 * @tc.desc : null check test 569 */ 570 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_018, TestSize.Level2) 571 { 572 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 573 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 574 ASSERT_NE(nullptr, handle); 575 576 OH_AVFormat* format = OH_AVFormat_Create(); 577 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 578 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 579 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 580 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 581 582 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 583 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 584 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 585 ASSERT_EQ(AV_ERR_OK, ret); 586 587 ret = decoderDemo->NativeConfigure(handle, format); 588 ASSERT_EQ(AV_ERR_OK, ret); 589 590 ret = decoderDemo->NativePrepare(handle); 591 ASSERT_EQ(AV_ERR_OK, ret); 592 593 ret = decoderDemo->NativeStart(handle); 594 ASSERT_EQ(AV_ERR_OK, ret); 595 596 bool isVaild; 597 ret = decoderDemo->NativeIsValid(nullptr, &isVaild); 598 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 599 600 OH_AVFormat_Destroy(format); 601 decoderDemo->NativeDestroy(handle); 602 delete decoderDemo; 603 } 604 605 606 /** 607 * @tc.number : SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_019 608 * @tc.name : OH_AudioDecoder_IsValid - codec check 609 * @tc.desc : null check test 610 */ 611 HWTEST_F(NativeNullCheckTest, SUB_MULTIMEDIA_AUDIO_DECODER_NULL_CHECK_019, TestSize.Level2) 612 { 613 AudioDecoderDemo* decoderDemo = new AudioDecoderDemo(); 614 OH_AVCodec* handle = decoderDemo->NativeCreateByName("OH.Media.Codec.Decoder.Audio.Mpeg"); 615 ASSERT_NE(nullptr, handle); 616 617 OH_AVFormat* format = OH_AVFormat_Create(); 618 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_CHANNEL_COUNT, 2); 619 OH_AVFormat_SetIntValue(format, OH_MD_KEY_AUD_SAMPLE_RATE, 44100); 620 OH_AVFormat_SetIntValue(format, OH_MD_KEY_BITS_PER_CODED_SAMPLE, 4); 621 OH_AVFormat_SetLongValue(format, OH_MD_KEY_BITRATE, 169000); 622 623 struct OH_AVCodecAsyncCallback cb = { &OnError, &OnOutputFormatChanged, 624 &OnInputBufferAvailable, &OnOutputBufferAvailable }; 625 OH_AVErrCode ret = decoderDemo->NativeSetCallback(handle, cb); 626 ASSERT_EQ(AV_ERR_OK, ret); 627 628 ret = decoderDemo->NativeConfigure(handle, format); 629 ASSERT_EQ(AV_ERR_OK, ret); 630 631 ret = decoderDemo->NativePrepare(handle); 632 ASSERT_EQ(AV_ERR_OK, ret); 633 634 ret = decoderDemo->NativeStart(handle); 635 ASSERT_EQ(AV_ERR_OK, ret); 636 637 ret = decoderDemo->NativeIsValid(handle, nullptr); 638 ASSERT_EQ(AV_ERR_INVALID_VAL, ret); 639 640 OH_AVFormat_Destroy(format); 641 decoderDemo->NativeDestroy(handle); 642 delete decoderDemo; 643 }