diff --git a/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp b/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp index 2f23f02ae3a6a5a4a22f9e45e77465f95e2bfae5..5d6f27ae314a1e3e102815991baaa702f6e802fd 100644 --- a/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp +++ b/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp @@ -128,6 +128,7 @@ HWTEST_F(AudioCtrlChannelTest, OnSessionClosed_001, TestSize.Level1) ctrlChannel_->OnSessionClosed(sessionId); listener = std::make_shared(); ctrlChannel_->channelListener_ = listener; + ctrlChannel_->OnSessionClosed(sessionId); AudioEvent event; EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, ctrlChannel_->SendEvent(event)); } @@ -140,12 +141,17 @@ HWTEST_F(AudioCtrlChannelTest, OnSessionClosed_001, TestSize.Level1) */ HWTEST_F(AudioCtrlChannelTest, SendMsg_001, TestSize.Level1) { + int32_t sessionId = 1; + int32_t dataLen = 3; + uint8_t *data = new uint8_t[dataLen]; + ctrlChannel_->OnBytesReceived(sessionId, data, dataLen); std::shared_ptr listener = std::make_shared(); ctrlChannel_->channelListener_ = listener; - - int32_t sessionId = 0; - uint8_t *data = nullptr; - int32_t dataLen = 0; + ctrlChannel_->OnBytesReceived(sessionId, data, dataLen); + delete [] data; + data = nullptr; + sessionId = 0; + dataLen = 0; ctrlChannel_->OnBytesReceived(sessionId, data, dataLen); listener = nullptr; ctrlChannel_->channelListener_ = listener; @@ -159,5 +165,18 @@ HWTEST_F(AudioCtrlChannelTest, SendMsg_001, TestSize.Level1) string message = "sendMsg"; EXPECT_NE(ERR_DH_AUDIO_CTRL_CHANNEL_SEND_MSG_FAIL, ctrlChannel_->SendMsg(message)); } + +/** + * @tc.name: from_audioEventJson_001 + * @tc.desc: Verify the from_audioEventJson function. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioCtrlChannelTest, from_audioEventJson_001, TestSize.Level1) +{ + AudioEvent event; + json j; + EXPECT_NE(DH_SUCCESS, from_audioEventJson(j, event)); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn b/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn index 27a29a3bd978f0aa977205646811ec241ff68d91..8eed1d60df84c60863cc00f9f8ab421434f0ceba 100644 --- a/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn +++ b/services/audiotransport/test/unittest/audiotransportstatus/BUILD.gn @@ -49,6 +49,7 @@ ohos_unittest("TransportStatusTest") { module_out_path = module_output_path sources = [ + "src/audio_transport_context_test.cpp", "src/audio_transport_pause_status_test.cpp", "src/audio_transport_start_status_test.cpp", "src/audio_transport_stop_status_test.cpp", diff --git a/services/audiotransport/test/unittest/audiotransportstatus/include/audio_transport_context_test.h b/services/audiotransport/test/unittest/audiotransportstatus/include/audio_transport_context_test.h new file mode 100644 index 0000000000000000000000000000000000000000..20a7de6c95dc14e3a8775bd153c162c1a5821e29 --- /dev/null +++ b/services/audiotransport/test/unittest/audiotransportstatus/include/audio_transport_context_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef AUDIO_TRANSPORT_CONTEXT_TEST_H +#define AUDIO_TRANSPORT_CONTEXT_TEST_H + +#include + +#define private public +#include "audio_transport_context.h" +#undef private + +namespace OHOS { +namespace DistributedHardware { +class AudioTransportContextTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr stateContext_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // AUDIO_TRANSPORT_CONTEXT_TEST_H diff --git a/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_context_test.cpp b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_context_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..959ebf332ea10849786e9a8acbc37fd088e321b7 --- /dev/null +++ b/services/audiotransport/test/unittest/audiotransportstatus/src/audio_transport_context_test.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "audio_transport_context_test.h" + +#include "daudio_errorcode.h" +#include "daudio_log.h" +#include "daudio_util.h" + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void AudioTransportContextTest::SetUpTestCase(void) {} + +void AudioTransportContextTest::TearDownTestCase(void) {} + +void AudioTransportContextTest::SetUp(void) +{ + stateContext_ = std::make_shared(); +} + +void AudioTransportContextTest::TearDown(void) +{ + stateContext_ = nullptr; +} + +/** + * @tc.name: GetTransportStatus_001 + * @tc.desc: Verify GetTransportStatus func. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioTransportContextTest, GetTransportStatus_001, TestSize.Level1) +{ + TransportStateType type = TransportStateType::TRANSPORT_STATE_START; + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, stateContext_->GetTransportStatusType()); + stateContext_->SetTransportStatus(type); + EXPECT_EQ(TransportStateType::TRANSPORT_STATE_START, stateContext_->GetTransportStatusType()); +} + +/** + * @tc.name: Stop_001 + * @tc.desc: Verify Stop func. + * @tc.type: FUNC + * @tc.require: AR000H0E5U + */ +HWTEST_F(AudioTransportContextTest, Stop_001, TestSize.Level1) +{ + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, stateContext_->Start()); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, stateContext_->Pause()); + EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, stateContext_->Stop()); + TransportStateType type = TransportStateType::TRANSPORT_STATE_START; + stateContext_->SetTransportStatus(type); + EXPECT_EQ(DH_SUCCESS, stateContext_->Start()); + EXPECT_NE(DH_SUCCESS, stateContext_->Stop()); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp b/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp index 8153cad9f2711e01626740abea2f6a49cd954cf3..a0a702be4c3fca9b3cba1314402efff1936b5eef 100644 --- a/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp +++ b/services/audiotransport/test/unittest/decodetransport/src/decode_transport_test.cpp @@ -186,6 +186,10 @@ HWTEST_F(DecodeTransportTest, decode_transport_test_004, TestSize.Level1) decodeTrans_->OnEventReceived(event); decodeTrans_->OnStateNotify(event); decodeTrans_->OnAudioDataDone(audioData); + decodeTrans_->dataTransCallback_ = std::make_shared(); + decodeTrans_->OnSessionOpened(); + decodeTrans_->OnSessionClosed(); + decodeTrans_->OnAudioDataDone(audioData); EXPECT_EQ(DH_SUCCESS, decodeTrans_->FeedAudioData(audioData)); }