From f54b9de289429202756f0815ead280bd89757273 Mon Sep 17 00:00:00 2001 From: liuxiang Date: Thu, 11 Sep 2025 18:11:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BD=95=E5=88=B6=E6=A1=86=E6=9E=B6=20NativeRe?= =?UTF-8?q?corderUnitTest=20=E5=BC=82=E5=B8=B8=E7=94=A8=E4=BE=8B=E5=A4=84?= =?UTF-8?q?=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuxiang --- .../capi/src/recorder_unit_test.cpp | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) diff --git a/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp b/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp index 62077fe86..d5df74e13 100644 --- a/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp +++ b/test/unittest/recorder_test/capi/src/recorder_unit_test.cpp @@ -99,6 +99,20 @@ static HapPolicyParams hapPolicy = { .resDeviceID = { "local" }, .grantStatus = { PermissionState::PERMISSION_GRANTED }, .grantFlags = { 1 } + }, + { + .permissionName = "ohos.permission.GET_BUNDLE_INFO", + .isGeneral = true, + .resDeviceID = { "local" }, + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .grantFlags = { 1 } + }, + { + .permissionName = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED", + .isGeneral = true, + .resDeviceID = { "local" }, + .grantStatus = { PermissionState::PERMISSION_GRANTED }, + .grantFlags = { 1 } } } }; @@ -603,6 +617,55 @@ HWTEST_F(NativeRecorderUnitTest, Recorder_Prepare_007, TestSize.Level2) MEDIA_LOGI("NativeRecorderUnitTest Recorder_Prepare_007 out."); } +/** + * @tc.name: Recorder_Prepare_008 + * @tc.desc: Test recorder preparation process success situation + * @tc.type: FUNC + */ +HWTEST_F(NativeRecorderUnitTest, Recorder_Prepare_008, TestSize.Level2) +{ + MEDIA_LOGI("NativeRecorderUnitTest Recorder_Prepare_008 in."); + + OH_AVRecorder_Config config = config_; + config.url = strdup(""); + config.metadata.genre = strdup(""); + config.metadata.videoOrientation = nullptr; + config.metadata.customInfo.key = strdup("abc"); + config.metadata.customInfo.value = strdup("123"); + config.profile.audioBitrate = 96000; + config.profile.audioChannels = 2; + config.profile.audioCodec = OH_AVRecorder_CodecMimeType::AVRECORDER_AUDIO_AAC; + config.profile.audioSampleRate = 48000; + config.profile.fileFormat = OH_AVRecorder_ContainerFormatType::AVRECORDER_CFT_MPEG_4; + config.profile.videoBitrate = 2000000; + config.profile.videoCodec = OH_AVRecorder_CodecMimeType::AVRECORDER_VIDEO_AVC; + config.profile.videoFrameWidth = 1280; + config.profile.videoFrameHeight = 720; + config.profile.videoFrameRate = 30; + config.profile.isHdr = false; + config.profile.enableTemporalScale = false; + config.audioSourceType = OH_AVRecorder_AudioSourceType::AVRECORDER_MIC; + config.videoSourceType = OH_AVRecorder_VideoSourceType::AVRECORDER_SURFACE_YUV; + config.fileGenerationMode = OH_AVRecorder_FileGenerationMode::AVRECORDER_AUTO_CREATE_CAMERA_SCENE; + + int32_t ret = AV_ERR_OK; + ret = OH_AVRecorder_Prepare(recorder_, &config); + + #ifdef SUPPORT_RECORDER_CREATE_FILE + EXPECT_EQ(ret, AV_ERR_OK); + #else + EXPECT_EQ(ret, AV_ERR_INVALID_VAL); + #endif + + free(config.url); + free(config.metadata.genre); + free(config.metadata.videoOrientation); + free(config.metadata.customInfo.key); + free(config.metadata.customInfo.value); + + MEDIA_LOGI("NativeRecorderUnitTest Recorder_Prepare_008 out."); +} + /** * @tc.name: Recorder_Prepare_009 * @tc.desc: Test recorder preparation process success situation 2 @@ -950,6 +1013,97 @@ HWTEST_F(NativeRecorderUnitTest, Recorder_UpdateRotation_002, TestSize.Level2) MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_002 out."); } +/** + * @tc.name: Recorder_UpdateRotation_003 + * @tc.desc: Test recorder UpdateRotation process 003 + * @tc.type: FUNC + */ +HWTEST_F(NativeRecorderUnitTest, Recorder_UpdateRotation_003, TestSize.Level2) +{ + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_003 in."); + + OH_AVRecorder_Config config = config_; + config.url = strdup(""); + config.metadata.genre = strdup(""); + config.metadata.videoOrientation = strdup("0"); + config.metadata.customInfo.key = strdup(""); + config.metadata.customInfo.value = strdup(""); + config.fileGenerationMode = OH_AVRecorder_FileGenerationMode::AVRECORDER_AUTO_CREATE_CAMERA_SCENE; + + int32_t rotation = 90; + + int32_t ret = AV_ERR_OK; + + ret = OH_AVRecorder_Prepare(recorder_, &config); + #ifdef SUPPORT_RECORDER_CREATE_FILE + EXPECT_EQ(ret, AV_ERR_OK); + #else + EXPECT_EQ(ret, AV_ERR_INVALID_VAL); + #endif + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + + free(config.url); + free(config.metadata.genre); + free(config.metadata.videoOrientation); + free(config.metadata.customInfo.key); + free(config.metadata.customInfo.value); + + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_003 out."); +} + +/** + * @tc.name: Recorder_UpdateRotation_004 + * @tc.desc: Test recorder UpdateRotation process 004 + * @tc.type: FUNC + */ +HWTEST_F(NativeRecorderUnitTest, Recorder_UpdateRotation_004, TestSize.Level2) +{ + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_004 in."); + + OH_AVRecorder_Config config = config_; + config.url = strdup(""); + config.metadata.genre = strdup(""); + config.metadata.videoOrientation = strdup("0"); + config.metadata.customInfo.key = strdup(""); + config.metadata.customInfo.value = strdup(""); + config.fileGenerationMode = OH_AVRecorder_FileGenerationMode::AVRECORDER_AUTO_CREATE_CAMERA_SCENE; + + int32_t ret = AV_ERR_OK; + + ret = OH_AVRecorder_Prepare(recorder_, &config); + #ifdef SUPPORT_RECORDER_CREATE_FILE + EXPECT_EQ(ret, AV_ERR_OK); + #else + EXPECT_EQ(ret, AV_ERR_INVALID_VAL); + #endif + + int32_t rotation = 0; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + rotation = 90; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + rotation = 180; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + rotation = 270; + ret = OH_AVRecorder_UpdateRotation(recorder_, rotation); + EXPECT_EQ(ret, AV_ERR_OK); + + free(config.url); + free(config.metadata.genre); + free(config.metadata.videoOrientation); + free(config.metadata.customInfo.key); + free(config.metadata.customInfo.value); + + MEDIA_LOGI("NativeRecorderUnitTest Recorder_UpdateRotation_004 out."); +} + /** * @tc.name: Recorder_Start_001 * @tc.desc: Test recorder start process 001 -- Gitee