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