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