From 35e265af19432eed01faf91845e74e97a907dfee Mon Sep 17 00:00:00 2001 From: Bobie Date: Tue, 4 Jul 2023 20:56:17 +0800 Subject: [PATCH] fix the ut cases of audiomanager Signed-off-by: Bobie --- .../audiomanager/managersource/src/daudio_source_dev.cpp | 9 +++++---- .../unittest/sourcedevice/src/daudio_source_dev_test.cpp | 4 +++- .../test/unittest/sourcedevice/src/dmic_dev_test.cpp | 6 +++++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/services/audiomanager/managersource/src/daudio_source_dev.cpp b/services/audiomanager/managersource/src/daudio_source_dev.cpp index cd5e4f4d..f8a0a4c1 100644 --- a/services/audiomanager/managersource/src/daudio_source_dev.cpp +++ b/services/audiomanager/managersource/src/daudio_source_dev.cpp @@ -935,6 +935,7 @@ int32_t DAudioSourceDev::TaskPlayStatusChange(const std::string &args) int32_t ret = SendAudioEventToRemote(audioEvent); if (ret != DH_SUCCESS) { DHLOGE("Task Play status change failed."); + return ERR_DH_AUDIO_FAILED; } if (args == AUDIO_EVENT_RESTART) { @@ -1066,10 +1067,10 @@ int32_t DAudioSourceDev::NotifySinkDev(const AudioEventType type, const json Par } speaker_->SendMessage(static_cast(type), jParam.dump(), devId_); mic_->SendMessage(static_cast(type), jParam.dump(), devId_); - } - if (type == CLOSE_SPEAKER || type == CLOSE_MIC) { - // Close spk || Close mic do not need to wait RPC - return DH_SUCCESS; + if (type == CLOSE_SPEAKER || type == CLOSE_MIC) { + // Close spk || Close mic do not need to wait RPC + return DH_SUCCESS; + } } return WaitForRPC(static_cast(static_cast(type) + eventOffset)); } diff --git a/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp b/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp index 7b3730ef..89bbd673 100644 --- a/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp +++ b/services/audiomanager/test/unittest/sourcedevice/src/daudio_source_dev_test.cpp @@ -956,7 +956,7 @@ HWTEST_F(DAudioSourceDevTest, TaskChangeRenderState_001, TestSize.Level1) */ HWTEST_F(DAudioSourceDevTest, TaskPlayStatusChange_001, TestSize.Level1) { - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, sourceDev_->TaskPlayStatusChange(AUDIO_EVENT_PAUSE)); + EXPECT_EQ(ERR_DH_AUDIO_FAILED, sourceDev_->TaskPlayStatusChange(AUDIO_EVENT_PAUSE)); sourceDev_->audioCtrlMgr_ = std::make_shared(DEV_ID, sourceDev_); sourceDev_->speaker_ = std::make_shared(DEV_ID, nullptr); @@ -1088,6 +1088,8 @@ HWTEST_F(DAudioSourceDevTest, NotifySinkDev_001, TestSize.Level1) { json jAudioParam; EXPECT_EQ(ERR_DH_AUDIO_SA_RPC_WAIT_TIMEOUT, sourceDev_->NotifySinkDev(CLOSE_MIC, jAudioParam, DH_ID_SPK)); + sourceDev_->engineFlag_ = true; + EXPECT_EQ(ERR_DH_AUDIO_SA_RPC_WAIT_TIMEOUT, sourceDev_->NotifySinkDev(CLOSE_MIC, jAudioParam, DH_ID_SPK)); } } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp b/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp index f441e1d3..8fd711d1 100644 --- a/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp +++ b/services/audiomanager/test/unittest/sourcedevice/src/dmic_dev_test.cpp @@ -150,11 +150,14 @@ HWTEST_F(DMicDevTest, NotifyEvent_001, TestSize.Level1) */ HWTEST_F(DMicDevTest, SetUp_001, TestSize.Level1) { + mic_->engineFlag_ = true; mic_->micTrans_ = nullptr; - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, mic_->SetUp()); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, mic_->SetUp()); mic_->micTrans_ = std::make_shared(); EXPECT_EQ(DH_SUCCESS, mic_->SetUp()); + mic_->engineFlag_ = false; + EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, mic_->SetUp()); } /** @@ -190,6 +193,7 @@ HWTEST_F(DMicDevTest, Start_002, TestSize.Level1) EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, mic_->SetUp()); EXPECT_NE(DH_SUCCESS, mic_->Start()); + mic_->engineFlag_ = true; mic_->micTrans_ = std::make_shared(); EXPECT_EQ(DH_SUCCESS, mic_->SetUp()); EXPECT_EQ(ERR_DH_AUDIO_SA_MIC_CHANNEL_WAIT_TIMEOUT, mic_->Start()); -- Gitee