From ad7325592780001c93bc0b04b1383a8a12a5a637 Mon Sep 17 00:00:00 2001 From: w30042960 Date: Mon, 30 Oct 2023 11:17:27 +0800 Subject: [PATCH] modify UT Signed-off-by: w30042960 --- .../include/audio_ctrl_channel.h | 62 ----- .../src/audio_ctrl_channel.cpp | 254 ------------------ .../audioctrltransport/BUILD.gn | 71 ----- .../include/audio_ctrl_transport.h | 61 ----- .../interface/iaudio_ctrl_trans_callback.h | 31 --- .../interface/iaudio_ctrl_transport.h | 37 --- .../src/audio_ctrl_transport.cpp | 184 ------------- .../audiotransport/test/unittest/BUILD.gn | 2 - .../test/unittest/audioctrlchannel/BUILD.gn | 61 ----- .../include/audio_ctrl_channel_test.h | 42 --- .../src/audio_ctrl_channel_test.cpp | 182 ------------- .../test/unittest/audioctrltransport/BUILD.gn | 61 ----- .../include/audio_ctrl_transport_test.h | 42 --- .../src/audio_ctrl_transport_test.cpp | 201 -------------- .../include/audiotrans_test_utils.h | 9 - 15 files changed, 1300 deletions(-) delete mode 100644 services/audiotransport/audiochannel/audioctrlchannel/include/audio_ctrl_channel.h delete mode 100644 services/audiotransport/audiochannel/audioctrlchannel/src/audio_ctrl_channel.cpp delete mode 100644 services/audiotransport/audioctrltransport/BUILD.gn delete mode 100644 services/audiotransport/audioctrltransport/include/audio_ctrl_transport.h delete mode 100644 services/audiotransport/audioctrltransport/interface/iaudio_ctrl_trans_callback.h delete mode 100644 services/audiotransport/audioctrltransport/interface/iaudio_ctrl_transport.h delete mode 100644 services/audiotransport/audioctrltransport/src/audio_ctrl_transport.cpp delete mode 100644 services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn delete mode 100644 services/audiotransport/test/unittest/audioctrlchannel/include/audio_ctrl_channel_test.h delete mode 100644 services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp delete mode 100644 services/audiotransport/test/unittest/audioctrltransport/BUILD.gn delete mode 100644 services/audiotransport/test/unittest/audioctrltransport/include/audio_ctrl_transport_test.h delete mode 100644 services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp diff --git a/services/audiotransport/audiochannel/audioctrlchannel/include/audio_ctrl_channel.h b/services/audiotransport/audiochannel/audioctrlchannel/include/audio_ctrl_channel.h deleted file mode 100644 index 7e959e62..00000000 --- a/services/audiotransport/audiochannel/audioctrlchannel/include/audio_ctrl_channel.h +++ /dev/null @@ -1,62 +0,0 @@ - /* - * 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 OHOS_AUDIO_CTRL_CHANNEL_H -#define OHOS_AUDIO_CTRL_CHANNEL_H - -#include "nlohmann/json.hpp" - -#include "iaudio_channel_listener.h" -#include "iaudio_channel.h" -#include "softbus_adapter.h" - -using json = nlohmann::json; - -namespace OHOS { -namespace DistributedHardware { -class AudioCtrlChannel : public IAudioChannel, - public ISoftbusListener, - public std::enable_shared_from_this { -public: - explicit AudioCtrlChannel(const std::string &peerDevId) : peerDevId_(peerDevId) {}; - ~AudioCtrlChannel() override = default; - - int32_t CreateSession(const std::shared_ptr &listener, - const std::string &sessionName) override; - int32_t ReleaseSession() override; - int32_t OpenSession() override; - int32_t CloseSession() override; - int32_t SendData(const std::shared_ptr &audioData) override; - int32_t SendEvent(const AudioEvent &audioEvent) override; - - void OnSessionOpened(int32_t sessionId, int32_t result) override; - void OnSessionClosed(int32_t sessionId) override; - void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override; - void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo) override; - -private: - int32_t SendMsg(string &message); - const int32_t MSG_MAX_SIZE = 45 * 1024; - const std::string peerDevId_; - int32_t sessionId_ = 0; - std::string sessionName_; - std::weak_ptr channelListener_; -}; - -int32_t from_audioEventJson(const json &j, AudioEvent &audioEvent); -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_CTRL_CHANNEL_H diff --git a/services/audiotransport/audiochannel/audioctrlchannel/src/audio_ctrl_channel.cpp b/services/audiotransport/audiochannel/audioctrlchannel/src/audio_ctrl_channel.cpp deleted file mode 100644 index d80eb25a..00000000 --- a/services/audiotransport/audiochannel/audioctrlchannel/src/audio_ctrl_channel.cpp +++ /dev/null @@ -1,254 +0,0 @@ - /* - * 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_ctrl_channel.h" - -#include - -#include "daudio_hisysevent.h" -#include "daudio_hitrace.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioCtrlChannel" - -namespace OHOS { -namespace DistributedHardware { -int32_t AudioCtrlChannel::CreateSession(const std::shared_ptr &listener, - const std::string &sessionName) -{ - DHLOGI("Create session, peerDevId: %s.", GetAnonyString(peerDevId_).c_str()); - if (listener == nullptr) { - DHLOGE("Channel listener is null."); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_NULLPTR, - "daudio channel listener is null."); - return ERR_DH_AUDIO_NULLPTR; - } - - DAUDIO_SYNC_TRACE(DAUDIO_CREATE_CTRL_SESSION); - int32_t ret = - SoftbusAdapter::GetInstance().CreateSoftbusSessionServer(PKG_NAME, sessionName, peerDevId_); - if (ret != DH_SUCCESS) { - DHLOGE("Create softbus session failed ret: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio create softbus session failed."); - return ret; - } - - ret = SoftbusAdapter::GetInstance().RegisterSoftbusListener(shared_from_this(), sessionName, peerDevId_); - if (ret != DH_SUCCESS) { - DHLOGE("Register softbus adapter listener failed ret: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio register softbus adapter listener failed."); - return ret; - } - - channelListener_ = listener; - sessionName_ = sessionName; - DHLOGI("Create softbus session success."); - return DH_SUCCESS; -} - -int32_t AudioCtrlChannel::ReleaseSession() -{ - DHLOGI("Release session, peerDevId: %s", GetAnonyString(peerDevId_).c_str()); - DAUDIO_SYNC_TRACE(DAUDIO_RELEASE_CTRL_SESSION); - int32_t ret = SoftbusAdapter::GetInstance().RemoveSoftbusSessionServer(PKG_NAME, sessionName_, peerDevId_); - if (ret != DH_SUCCESS) { - DHLOGE("Release softbus session failed ret: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio release softbus session failed."); - return ret; - } - - ret = SoftbusAdapter::GetInstance().UnRegisterSoftbusListener(sessionName_, peerDevId_); - if (ret != DH_SUCCESS) { - DHLOGE("UnRegister softbus adapter listener failed ret: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio unRegister softbus adapter listener failed."); - return ret; - } - channelListener_.reset(); - - DHLOGI("Release softbus session success."); - return DH_SUCCESS; -} - -int32_t AudioCtrlChannel::OpenSession() -{ - DHLOGI("Open session, peerDevId: %s.", GetAnonyString(peerDevId_).c_str()); - DaudioStartAsyncTrace(DAUDIO_OPEN_CTRL_SESSION, DAUDIO_OPEN_CTRL_SESSION_TASKID); - int32_t sessionId = - SoftbusAdapter::GetInstance().OpenSoftbusSession(sessionName_, sessionName_, peerDevId_); - if (sessionId < 0) { - DHLOGE("Open ctrl session failed, ret: %d.", sessionId); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ERR_DH_AUDIO_TRANS_ERROR, - "daudio open ctrl session failed."); - return ERR_DH_AUDIO_TRANS_ERROR; - } - sessionId_ = sessionId; - - DHLOGI("Open ctrl session success, sessionId: %d.", sessionId_); - return DH_SUCCESS; -} - -int32_t AudioCtrlChannel::CloseSession() -{ - DHLOGI("Close session, sessionId: %d.", sessionId_); - if (sessionId_ == 0) { - DHLOGD("Session is already closed."); - return DH_SUCCESS; - } - - DAUDIO_SYNC_TRACE(DAUDIO_CLOSE_CTRL_SESSION); - int32_t ret = SoftbusAdapter::GetInstance().CloseSoftbusSession(sessionId_); - if (ret != DH_SUCCESS) { - DHLOGE("Close ctrl session failed, ret: %d.", ret); - DAudioHisysevent::GetInstance().SysEventWriteFault(DAUDIO_OPT_FAIL, ret, - "daudio close ctrl session failed."); - return ret; - } - sessionId_ = 0; - - DHLOGI("Close ctrl session success."); - return DH_SUCCESS; -} - -int32_t AudioCtrlChannel::SendData(const std::shared_ptr &data) -{ - (void) data; - - return DH_SUCCESS; -} - -int32_t AudioCtrlChannel::SendEvent(const AudioEvent &audioEvent) -{ - DHLOGD("Send event, sessionId: %d.", sessionId_); - json jAudioEvent; - jAudioEvent[KEY_TYPE] = audioEvent.type; - jAudioEvent[KEY_EVENT_CONTENT] = audioEvent.content; - std::string message = jAudioEvent.dump(); - int ret = SendMsg(message); - if (ret != DH_SUCCESS) { - DHLOGE("Send audio event failed ret: %d.", ret); - return ret; - } - - return DH_SUCCESS; -} - -int32_t AudioCtrlChannel::SendMsg(string &message) -{ - DHLOGD("Start send messages."); - return DH_SUCCESS; -} - -void AudioCtrlChannel::OnSessionOpened(int32_t sessionId, int32_t result) -{ - DHLOGI("On control session opened, sessionId: %d, result: %d.", sessionId, result); - if (result != 0) { - DHLOGE("Session open failed."); - return; - } - - auto listener = channelListener_.lock(); - if (listener == nullptr) { - DHLOGE("Channel listener is null."); - return; - } - listener->OnSessionOpened(); - DaudioFinishAsyncTrace(DAUDIO_OPEN_CTRL_SESSION, DAUDIO_OPEN_CTRL_SESSION_TASKID); - sessionId_ = sessionId; -} - -void AudioCtrlChannel::OnSessionClosed(int32_t sessionId) -{ - DHLOGI("On control session closed, sessionId: %d.", sessionId); - if (sessionId_ == 0) { - DHLOGD("Session already closed."); - return; - } - auto listener = channelListener_.lock(); - if (listener == nullptr) { - DHLOGE("Channel listener is null."); - return; - } - listener->OnSessionClosed(); - sessionId_ = 0; -} - -void AudioCtrlChannel::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) -{ - DHLOGI("On bytes received, sessionId: %d, dataLen: %d.", sessionId, dataLen); - if (sessionId < 0 || data == nullptr || dataLen == 0 || dataLen > MSG_MAX_SIZE) { - DHLOGE("Param check failed"); - return; - } - auto listener = channelListener_.lock(); - if (listener == nullptr) { - DHLOGE("Channel listener is null."); - return; - } - - uint8_t *buf = reinterpret_cast(calloc(dataLen + STR_TERM_LEN, sizeof(uint8_t))); - if (buf == nullptr) { - DHLOGE("Malloc memory failed."); - return; - } - - if (memcpy_s(buf, dataLen + STR_TERM_LEN, reinterpret_cast(data), dataLen) != EOK) { - DHLOGE("Received bytes data copy failed."); - free(buf); - return; - } - - std::string message(buf, buf + dataLen); - DHLOGI("On bytes received message: %s.", message.c_str()); - AudioEvent audioEvent; - json jParam = json::parse(message, nullptr, false); - if (from_audioEventJson(jParam, audioEvent) != DH_SUCCESS) { - DHLOGE("Get audioEvent from json failed."); - free(buf); - return; - } - free(buf); - DHLOGI("On bytes received end"); - - listener->OnEventReceived(audioEvent); -} - -void AudioCtrlChannel::OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, - const StreamFrameInfo *streamFrameInfo) -{ - (void) sessionId; - (void) data; - (void) ext; - (void) streamFrameInfo; - - DHLOGI("Ctrl channel not support yet."); -} - -int from_audioEventJson(const json &j, AudioEvent &audioEvent) -{ - if (!JsonParamCheck(j, {KEY_TYPE, KEY_EVENT_CONTENT})) { - DHLOGE("Json data is illegal."); - return ERR_DH_AUDIO_NULLPTR; - } - - j.at(KEY_TYPE).get_to(audioEvent.type); - j.at(KEY_EVENT_CONTENT).get_to(audioEvent.content); - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/audiotransport/audioctrltransport/BUILD.gn b/services/audiotransport/audioctrltransport/BUILD.gn deleted file mode 100644 index 2692c501..00000000 --- a/services/audiotransport/audioctrltransport/BUILD.gn +++ /dev/null @@ -1,71 +0,0 @@ -# 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. - -import("//build/ohos.gni") -import("//build/ohos_var.gni") -import("../../../distributedaudio.gni") - -ohos_shared_library("distributed_audio_control") { - branch_protector_ret = "pac_ret" - sanitize = { - boundary_sanitize = true - cfi = true - cfi_cross_dso = true - debug = false - integer_overflow = true - ubsan = true - } - stack_protector_ret = true - include_dirs = [ - "//third_party/json/include", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${common_path}/dfx_utils/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - "${softbusadapter_path}/include", - "${audio_transport_path}/audiochannel/interface", - "${audio_transport_path}/audioctrltransport/interface", - "${audio_transport_path}/audiochannel/audioctrlchannel/include", - ] - - sources = [ - "${audio_transport_path}/audiochannel/audioctrlchannel/src/audio_ctrl_channel.cpp", - "src/audio_ctrl_transport.cpp", - ] - - deps = [ - "${services_path}/common:distributed_audio_utils", - "${softbusadapter_path}:distributed_audio_softbus_adapter", - ] - - external_deps = [ - "c_utils:utils", - "dsoftbus:softbus_client", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", - ] - - defines = [ - "HI_LOG_ENABLE", - "LOG_DOMAIN=0xD004100", - ] - - subsystem_name = "distributedhardware" - - part_name = "distributed_audio" -} diff --git a/services/audiotransport/audioctrltransport/include/audio_ctrl_transport.h b/services/audiotransport/audioctrltransport/include/audio_ctrl_transport.h deleted file mode 100644 index 128e2aa8..00000000 --- a/services/audiotransport/audioctrltransport/include/audio_ctrl_transport.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 OHOS_AUDIO_CTRL_TRANSPORT_H -#define OHOS_AUDIO_CTRL_TRANSPORT_H - -#include - -#include "iaudio_ctrl_trans_callback.h" -#include "iaudio_ctrl_transport.h" -#include "iaudio_channel.h" - -#include "audio_event.h" -#include "audio_data.h" -#include "daudio_log.h" -#include "daudio_errorcode.h" - -namespace OHOS { -namespace DistributedHardware { -class AudioCtrlTransport : public IAudioCtrlTransport, - public IAudioChannelListener, - public std::enable_shared_from_this { -public: - explicit AudioCtrlTransport(const std::string &devId) : devId_(devId) {}; - ~AudioCtrlTransport() override = default; - - int32_t SetUp(const std::shared_ptr &callback) override; - int32_t Release() override; - int32_t Start() override; - int32_t Stop() override; - int32_t SendAudioEvent(const AudioEvent &event) override; - - void OnSessionOpened() override; - void OnSessionClosed() override; - void OnDataReceived(const std::shared_ptr &data) override; - void OnEventReceived(const AudioEvent &event) override; - -private: - int32_t InitAudioCtrlTrans(const std::string &devId); - int32_t RegisterChannelListener(); - -private: - const std::string devId_; - std::weak_ptr ctrlTransCallback_; - std::shared_ptr audioChannel_; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_CTRL_TRANSPORT_H diff --git a/services/audiotransport/audioctrltransport/interface/iaudio_ctrl_trans_callback.h b/services/audiotransport/audioctrltransport/interface/iaudio_ctrl_trans_callback.h deleted file mode 100644 index 95a457b3..00000000 --- a/services/audiotransport/audioctrltransport/interface/iaudio_ctrl_trans_callback.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * 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 OHOS_IAUDIO_CTRL_TRANS_CALLBACK_H -#define OHOS_IAUDIO_CTRL_TRANS_CALLBACK_H - -#include "audio_event.h" - -namespace OHOS { -namespace DistributedHardware { -class IAudioCtrlTransCallback { -public: - virtual ~IAudioCtrlTransCallback() = default; - virtual void OnStateChange(int32_t type) = 0; - virtual void OnEventReceived(const AudioEvent &event) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_IAUDIO_CTRL_TRANS_CALLBACK_H diff --git a/services/audiotransport/audioctrltransport/interface/iaudio_ctrl_transport.h b/services/audiotransport/audioctrltransport/interface/iaudio_ctrl_transport.h deleted file mode 100644 index 9a87302b..00000000 --- a/services/audiotransport/audioctrltransport/interface/iaudio_ctrl_transport.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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 OHOS_IAUDIO_CTRL_TRANSPORT_H -#define OHOS_IAUDIO_CTRL_TRANSPORT_H - -#include "iaudio_ctrl_trans_callback.h" - -#include "audio_param.h" - -namespace OHOS { -namespace DistributedHardware { -class IAudioCtrlTransport { -public: - virtual ~IAudioCtrlTransport() = default; - - virtual int32_t SetUp(const std::shared_ptr &callback) = 0; - virtual int32_t Release() = 0; - virtual int32_t Start() = 0; - virtual int32_t Stop() = 0; - virtual int32_t SendAudioEvent(const AudioEvent &event) = 0; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_IAUDIO_CTRL_TRANSPORT_H diff --git a/services/audiotransport/audioctrltransport/src/audio_ctrl_transport.cpp b/services/audiotransport/audioctrltransport/src/audio_ctrl_transport.cpp deleted file mode 100644 index 138e2f82..00000000 --- a/services/audiotransport/audioctrltransport/src/audio_ctrl_transport.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - * 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_ctrl_channel.h" -#include "audio_ctrl_transport.h" - -#undef DH_LOG_TAG -#define DH_LOG_TAG "AudioCtrlTransport" - -namespace OHOS { -namespace DistributedHardware { -int32_t AudioCtrlTransport::SetUp(const std::shared_ptr &callback) -{ - DHLOGI("Set up audio control transport."); - if (callback == nullptr) { - DHLOGE("callback is null."); - return ERR_DH_AUDIO_TRANS_ERROR; - } - - ctrlTransCallback_ = callback; - int32_t ret = InitAudioCtrlTrans(devId_); - if (ret != DH_SUCCESS) { - DHLOGE("Set up failed ret: %d.", ret); - return ret; - } - - DHLOGI("Set up audio control transport success."); - return DH_SUCCESS; -} - -int32_t AudioCtrlTransport::Release() -{ - DHLOGI("Release audio control transport."); - if (audioChannel_ == nullptr) { - DHLOGE("Channel is already release."); - return DH_SUCCESS; - } - - int32_t ret = audioChannel_->ReleaseSession(); - if (ret != DH_SUCCESS) { - DHLOGE("Release channel session failed ret: %d.", ret); - return ERR_DH_AUDIO_TRANS_ERROR; - } - audioChannel_ = nullptr; - - DHLOGI("Release success."); - return DH_SUCCESS; -} - -int32_t AudioCtrlTransport::Start() -{ - DHLOGI("Start audio control transport."); - if (audioChannel_ == nullptr) { - DHLOGE("Channel is null."); - return ERR_DH_AUDIO_NULLPTR; - } - - int ret = audioChannel_->OpenSession(); - if (ret != DH_SUCCESS) { - DHLOGE("Open channel session failed ret: %d.", ret); - return ret; - } - - DHLOGI("Start success."); - return DH_SUCCESS; -} - -int32_t AudioCtrlTransport::Stop() -{ - DHLOGI("Stop audio control transport."); - if (audioChannel_ == nullptr) { - DHLOGE("Channel is already release."); - return DH_SUCCESS; - } - - int32_t ret = audioChannel_->CloseSession(); - if (ret != DH_SUCCESS) { - DHLOGE("Close Session failed ret: %d.", ret); - return ERR_DH_AUDIO_TRANS_ERROR; - } - - DHLOGI("Stop success."); - return DH_SUCCESS; -} - -int32_t AudioCtrlTransport::SendAudioEvent(const AudioEvent &event) -{ - DHLOGI("Send audio event."); - if (audioChannel_ == nullptr) { - DHLOGE("Channel is null."); - return ERR_DH_AUDIO_NULLPTR; - } - - int32_t ret = audioChannel_->SendEvent(event); - if (ret != DH_SUCCESS) { - DHLOGE("Send data failed."); - } - - DHLOGI("Send Audio Event success."); - return DH_SUCCESS; -} - -void AudioCtrlTransport::OnSessionOpened() -{ - DHLOGI("On channel session opened."); - auto callback = ctrlTransCallback_.lock(); - if (callback == nullptr) { - DHLOGE("Callback is nullptr."); - return; - } - callback->OnStateChange(AudioEventType::CTRL_OPENED); -} - -void AudioCtrlTransport::OnSessionClosed() -{ - DHLOGD("On channel session closed."); - auto callback = ctrlTransCallback_.lock(); - if (callback == nullptr) { - DHLOGE("Callback is nullptr."); - return; - } - callback->OnStateChange(AudioEventType::CTRL_CLOSED); -} - -void AudioCtrlTransport::OnDataReceived(const std::shared_ptr &data) -{ - (void)data; -} - -void AudioCtrlTransport::OnEventReceived(const AudioEvent &event) -{ - DHLOGD("Audio event received."); - auto callback = ctrlTransCallback_.lock(); - if (callback == nullptr) { - DHLOGE("Callback is null."); - return; - } - callback->OnEventReceived(event); -} - -int32_t AudioCtrlTransport::InitAudioCtrlTrans(const std::string &netWordId) -{ - if (audioChannel_ == nullptr) { - audioChannel_ = std::make_shared(netWordId); - } - - int32_t ret = RegisterChannelListener(); - if (ret != DH_SUCCESS) { - DHLOGE("Register channel listener failed ret: %d.", ret); - audioChannel_ = nullptr; - return ret; - } - return DH_SUCCESS; -} - -int32_t AudioCtrlTransport::RegisterChannelListener() -{ - DHLOGI("Register channel listener."); - if (audioChannel_ == nullptr) { - DHLOGE("Channel is null."); - return ERR_DH_AUDIO_NULLPTR; - } - - int32_t ret = audioChannel_->CreateSession(shared_from_this(), CTRL_SESSION_NAME); - if (ret != DH_SUCCESS) { - DHLOGE("Create session failed ret: %d.", ret); - return ret; - } - return DH_SUCCESS; -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/audiotransport/test/unittest/BUILD.gn b/services/audiotransport/test/unittest/BUILD.gn index 4414bc04..c0c8266d 100644 --- a/services/audiotransport/test/unittest/BUILD.gn +++ b/services/audiotransport/test/unittest/BUILD.gn @@ -18,8 +18,6 @@ import("../../../../distributedaudio.gni") group("daudio_transport_test") { testonly = true deps = [ - "${audio_transport_path}/test/unittest/audioctrlchannel:audio_ctrl_channel_test", - "${audio_transport_path}/test/unittest/audioctrltransport:audio_ctrl_transport_test", "${audio_transport_path}/test/unittest/audiodatachannel:audio_data_channel_test", "${audio_transport_path}/test/unittest/audiotransportstatus:transport_status_test", "${audio_transport_path}/test/unittest/decodetransport:decode_transport_test", diff --git a/services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn b/services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn deleted file mode 100644 index 998230c2..00000000 --- a/services/audiotransport/test/unittest/audioctrlchannel/BUILD.gn +++ /dev/null @@ -1,61 +0,0 @@ -# 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. - -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -module_out_path = - "distributed_audio/services/audiotransport/audio_ctrl_channel_test" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "//third_party/json/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - "${softbusadapter_path}/include", - "${audio_transport_path}/audiochannel/interface", - "${audio_transport_path}/audiochannel/audioctrlchannel/include", - "${audio_transport_path}/audioctrltransport/interface", - "${audio_transport_path}/test/unittest/audiotranstestutils/include", - ] -} - -## UnitTest audio_ctrl_channel_test -ohos_unittest("AudioCtrlChannelTest") { - module_out_path = module_out_path - - sources = [ "src/audio_ctrl_channel_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "${audio_transport_path}/audioctrltransport:distributed_audio_control", - "${services_path}/common:distributed_audio_utils", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] -} - -group("audio_ctrl_channel_test") { - testonly = true - deps = [ ":AudioCtrlChannelTest" ] -} diff --git a/services/audiotransport/test/unittest/audioctrlchannel/include/audio_ctrl_channel_test.h b/services/audiotransport/test/unittest/audioctrlchannel/include/audio_ctrl_channel_test.h deleted file mode 100644 index cae3770a..00000000 --- a/services/audiotransport/test/unittest/audioctrlchannel/include/audio_ctrl_channel_test.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 OHOS_AUDIO_CTRL_CHANNEL_TEST_H -#define OHOS_AUDIO_CTRL_CHANNEL_TEST_H - -#include - -#include "daudio_constants.h" -#include "daudio_errorcode.h" -#include "audiotrans_test_utils.h" - -#define private public -#include "audio_ctrl_channel.h" -#undef private - -namespace OHOS { -namespace DistributedHardware { -class AudioCtrlChannelTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr ctrlChannel_ = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_CTRL_CHANNEL_TEST_H 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 deleted file mode 100644 index 2f27d654..00000000 --- a/services/audiotransport/test/unittest/audioctrlchannel/src/audio_ctrl_channel_test.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * 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_ctrl_channel_test.h" -#include -#include "daudio_log.h" -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -void AudioCtrlChannelTest::SetUpTestCase(void) {} - -void AudioCtrlChannelTest::TearDownTestCase(void) {} - -void AudioCtrlChannelTest::SetUp(void) -{ - std::string peerDevId = "peerDevId"; - ctrlChannel_ = std::make_shared(peerDevId); -} - -void AudioCtrlChannelTest::TearDown(void) -{ - ctrlChannel_ = nullptr; -} - -/** - * @tc.name: CreateSession_001 - * @tc.desc: Verify the CreateSession and ReleaseSession function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlChannelTest, CreateSession_001, TestSize.Level1) -{ - std::shared_ptr listener = nullptr; - EXPECT_NE(DH_SUCCESS, ctrlChannel_->CreateSession(listener, CTRL_SESSION_NAME)); - EXPECT_EQ(DH_SUCCESS, ctrlChannel_->ReleaseSession()); - listener = std::make_shared(); - EXPECT_NE(DH_SUCCESS, ctrlChannel_->CreateSession(listener, CTRL_SESSION_NAME)); - EXPECT_EQ(DH_SUCCESS, ctrlChannel_->ReleaseSession()); -} - -/** - * @tc.name: OpenSession_002 - * @tc.desc: Verify the OpenSession function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlChannelTest, OpenSession_002, TestSize.Level1) -{ - std::shared_ptr listener = nullptr; - ctrlChannel_->channelListener_ = listener; - int32_t sessionId = 0; - int32_t result = 0; - - ctrlChannel_->OnSessionOpened(sessionId, result); - - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, ctrlChannel_->OpenSession()); - EXPECT_EQ(DH_SUCCESS, ctrlChannel_->CloseSession()); - ctrlChannel_->sessionId_ = 1; - EXPECT_EQ(DH_SUCCESS, ctrlChannel_->CloseSession()); -} - -/** - * @tc.name: OpenSession_002 - * @tc.desc: Verify the OpenSession function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlChannelTest, SendData_002, TestSize.Level1) -{ - std::shared_ptr listener = std::make_shared(); - ctrlChannel_->channelListener_ = listener; - int32_t sessionId = -1; - int32_t result = -1; - - ctrlChannel_->OnSessionOpened(sessionId, result); - - size_t capacity = 2; - std::shared_ptr data = std::make_shared(capacity); - EXPECT_EQ(DH_SUCCESS, ctrlChannel_->SendData(data)); -} - -/** - * @tc.name: SendEvent_001 - * @tc.desc: Verify the SendEvent function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlChannelTest, SendEvent_001, TestSize.Level1) -{ - std::shared_ptr listener = std::make_shared(); - ctrlChannel_->channelListener_ = listener; - int32_t sessionId = 0; - int32_t result = 0; - - ctrlChannel_->OnSessionOpened(sessionId, result); - - AudioEvent event; - EXPECT_EQ(DH_SUCCESS, ctrlChannel_->SendEvent(event)); -} - -/** - * @tc.name: OnSessionClosed_001 - * @tc.desc: Verify the OnSessionClosed function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlChannelTest, OnSessionClosed_001, TestSize.Level1) -{ - std::shared_ptr listener = nullptr; - ctrlChannel_->channelListener_ = listener; - int32_t sessionId = 0; - - ctrlChannel_->OnSessionClosed(sessionId); - ctrlChannel_->sessionId_ = 1; - ctrlChannel_->OnSessionClosed(sessionId); - listener = std::make_shared(); - ctrlChannel_->channelListener_ = listener; - ctrlChannel_->OnSessionClosed(sessionId); - AudioEvent event; - EXPECT_EQ(DH_SUCCESS, ctrlChannel_->SendEvent(event)); -} - -/** - * @tc.name: SendMsg_001 - * @tc.desc: Verify the SendMsg function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -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; - ctrlChannel_->OnBytesReceived(sessionId, data, dataLen); - delete [] data; - data = nullptr; - sessionId = 0; - dataLen = 0; - ctrlChannel_->OnBytesReceived(sessionId, data, dataLen); - listener = nullptr; - ctrlChannel_->channelListener_ = listener; - ctrlChannel_->OnBytesReceived(sessionId, data, dataLen); - - StreamData *datas; - StreamData *ext; - StreamFrameInfo *streamFrameInfo; - ctrlChannel_->OnStreamReceived(sessionId, datas, ext, streamFrameInfo); - - string message = "sendMsg"; - EXPECT_EQ(DH_SUCCESS, 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/audioctrltransport/BUILD.gn b/services/audiotransport/test/unittest/audioctrltransport/BUILD.gn deleted file mode 100644 index 7696159c..00000000 --- a/services/audiotransport/test/unittest/audioctrltransport/BUILD.gn +++ /dev/null @@ -1,61 +0,0 @@ -# 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. - -import("//build/test.gni") -import("../../../../../distributedaudio.gni") - -module_out_path = - "distributed_audio/services/audiotransport/audio_ctrl_transport_test" - -config("module_private_config") { - visibility = [ ":*" ] - - include_dirs = [ - "//third_party/json/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/", - ] - - include_dirs += [ - "include", - "${common_path}/include", - "${services_path}/common/audioparam", - "${services_path}/common/audiodata/include", - "${services_path}/softbusadapter/include", - "${audio_transport_path}/audiochannel/interface", - "${audio_transport_path}/audiochannel/audioctrlchannel/include", - "${audio_transport_path}/audioctrltransport/include", - "${audio_transport_path}/audioctrltransport/interface", - "${audio_transport_path}/test/unittest/audiotranstestutils/include", - ] -} - -## UnitTest audio_ctrl_transport_test -ohos_unittest("AudioCtrlTransportTest") { - module_out_path = module_out_path - - sources = [ "src/audio_ctrl_transport_test.cpp" ] - - configs = [ ":module_private_config" ] - - deps = [ - "${audio_transport_path}/audioctrltransport:distributed_audio_control", - "//third_party/googletest:gmock", - "//third_party/googletest:gtest_main", - ] -} - -group("audio_ctrl_transport_test") { - testonly = true - deps = [ ":AudioCtrlTransportTest" ] -} diff --git a/services/audiotransport/test/unittest/audioctrltransport/include/audio_ctrl_transport_test.h b/services/audiotransport/test/unittest/audioctrltransport/include/audio_ctrl_transport_test.h deleted file mode 100644 index f02eacb1..00000000 --- a/services/audiotransport/test/unittest/audioctrltransport/include/audio_ctrl_transport_test.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 OHOS_AUDIO_CTRL_TRANSPORT_TEST_H -#define OHOS_AUDIO_CTRL_TRANSPORT_TEST_H - -#include - -#include "daudio_errorcode.h" -#include "daudio_log.h" -#include "audiotrans_test_utils.h" - -#define private public -#include "audio_ctrl_transport.h" -#undef private - -namespace OHOS { -namespace DistributedHardware { -class AudioCtrlTransportTest : public testing::Test { -public: - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - std::shared_ptr trans = nullptr; -}; -} // namespace DistributedHardware -} // namespace OHOS -#endif // OHOS_AUDIO_CTRL_TRANSPORT_TEST_H \ No newline at end of file diff --git a/services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp b/services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp deleted file mode 100644 index 10cbf715..00000000 --- a/services/audiotransport/test/unittest/audioctrltransport/src/audio_ctrl_transport_test.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/* - * 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_ctrl_transport_test.h" -using namespace testing::ext; - -namespace OHOS { -namespace DistributedHardware { -void AudioCtrlTransportTest::SetUpTestCase(void) {} - -void AudioCtrlTransportTest::TearDownTestCase(void) {} - -void AudioCtrlTransportTest::SetUp(void) -{ - std::string peerDevId = "peerDevId"; - trans = std::make_shared(peerDevId); -} - -void AudioCtrlTransportTest::TearDown(void) {} - -/** - * @tc.name: SetUp_001 - * @tc.desc: Verify the SetUp function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, SetUp_001, TestSize.Level1) -{ - std::shared_ptr callback = nullptr; - EXPECT_EQ(ERR_DH_AUDIO_TRANS_ERROR, trans->SetUp(callback)); -} - -/** - * @tc.name: SetUp_002 - * @tc.desc: Verify the SetUp function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, SetUp_002, TestSize.Level1) -{ - std::string peerDevId = "peerDevId"; - std::shared_ptr callback = std::make_shared(); - trans->audioChannel_ = std::make_shared(peerDevId); - EXPECT_EQ(DH_SUCCESS, trans->SetUp(callback)); -} - -/** - * @tc.name: Release_001 - * @tc.desc: Verify the Release function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, Release_001, TestSize.Level1) -{ - EXPECT_EQ(DH_SUCCESS, trans->Release()); -} - -/** - * @tc.name: Release_002 - * @tc.desc: Verify the Release function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, Release_002, TestSize.Level1) -{ - std::string peerDevId = "peerDevId"; - trans->audioChannel_ = std::make_shared(peerDevId); - EXPECT_EQ(DH_SUCCESS, trans->Release()); -} - -/** - * @tc.name: Start_001 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, Start_001, TestSize.Level1) -{ - trans->OnSessionOpened(); - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, trans->Start()); -} - -/** - * @tc.name: Start_002 - * @tc.desc: Verify the Start function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, Start_002, TestSize.Level1) -{ - std::string peerDevId = "peerDevId"; - trans->audioChannel_ = std::make_shared(peerDevId); - EXPECT_EQ(DH_SUCCESS, trans->Start()); -} - -/** - * @tc.name: Stop_001 - * @tc.desc: Verify the Stop function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, Stop_001, TestSize.Level1) -{ - AudioEvent event; - trans->OnEventReceived(event); - trans->OnSessionClosed(); - EXPECT_EQ(DH_SUCCESS, trans->Stop()); -} - -/** - * @tc.name: Stop_002 - * @tc.desc: Verify the Stop function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, Stop_002, TestSize.Level1) -{ - std::string peerDevId = "peerDevId"; - trans->audioChannel_ = std::make_shared(peerDevId); - EXPECT_EQ(DH_SUCCESS, trans->Stop()); -} - -/** - * @tc.name: SendAudioEvent_001 - * @tc.desc: Verify the SendAudioEvent function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, SendAudioEvent_001, TestSize.Level1) -{ - std::string peerDevId = "peerDevId"; - trans->audioChannel_ = std::make_shared(peerDevId); - AudioEvent event ; - EXPECT_EQ(DH_SUCCESS, trans->SendAudioEvent(event)); -} - -/** - * @tc.name: SendAudioEvent_002 - * @tc.desc: Verify the SendAudioEvent function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, SendAudioEvent_002, TestSize.Level1) -{ - AudioEvent event ; - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, trans->SendAudioEvent(event)); -} - -/** - * @tc.name: RegisterChannelListener_001 - * @tc.desc: Verify the RegisterChannelListener function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, RegisterChannelListener_001, TestSize.Level1) -{ - std::shared_ptr listener = nullptr; - EXPECT_EQ(ERR_DH_AUDIO_NULLPTR, trans->RegisterChannelListener()); -} - -/** - * @tc.name: RegisterChannelListener_002 - * @tc.desc: Verify the RegisterChannelListener function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, RegisterChannelListener_002, TestSize.Level1) -{ - std::string peerDevId = "peerDevId"; - trans->audioChannel_ = std::make_shared(peerDevId); - std::shared_ptr listener = std::make_shared(); - EXPECT_EQ(DH_SUCCESS, trans->RegisterChannelListener()); -} - -/** - * @tc.name: InitAudioCtrlTrans_002 - * @tc.desc: Verify the InitAudioCtrlTrans function. - * @tc.type: FUNC - * @tc.require: AR000H0E5U - */ -HWTEST_F(AudioCtrlTransportTest, InitAudioCtrlTrans_002, TestSize.Level1) -{ - std::string peerDevId = "peerDevId"; - const std::string netWorkId = "netWorkId"; - trans->audioChannel_ = std::make_shared(peerDevId); - EXPECT_EQ(DH_SUCCESS, trans->InitAudioCtrlTrans(netWorkId)); -} -} // namespace DistributedHardware -} // namespace OHOS diff --git a/services/audiotransport/test/unittest/audiotranstestutils/include/audiotrans_test_utils.h b/services/audiotransport/test/unittest/audiotranstestutils/include/audiotrans_test_utils.h index 865630fe..6735e631 100644 --- a/services/audiotransport/test/unittest/audiotranstestutils/include/audiotrans_test_utils.h +++ b/services/audiotransport/test/unittest/audiotranstestutils/include/audiotrans_test_utils.h @@ -17,7 +17,6 @@ #define OHOS_AUDIO_TRANS_TEST_UTILS_H #include "iaudio_channel_listener.h" -#include "iaudio_ctrl_trans_callback.h" #include "iaudio_channel.h" namespace OHOS { @@ -34,14 +33,6 @@ public: void OnEventReceived(const AudioEvent &event) override {}; }; -class MockIAudioCtrlTransCallback : public IAudioCtrlTransCallback { -public: - MockIAudioCtrlTransCallback() {} - ~MockIAudioCtrlTransCallback() {} - void OnStateChange(int32_t state) override {}; - void OnEventReceived(const AudioEvent &event) override {}; -}; - class MockAudioCtrlChannel : public IAudioChannel { public: explicit MockAudioCtrlChannel(std::string peerDevId) : peerDevId_(peerDevId) {} -- Gitee