diff --git a/av_transport/av_trans_control_center/test/unittest/BUILD.gn b/av_transport/av_trans_control_center/test/unittest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9096d4fc9a046a8e671adaad38a7e5b61e8fcc41 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/BUILD.gn @@ -0,0 +1,81 @@ +# Copyright (c) 2023 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( + "//foundation/distributedhardware/distributedhardware_distributed_hardware_fwk/distributedhardwarefwk.gni") + +module_out_path = "distributedhardware_distributed_hardware_fwk/av_trans_control_center_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "//third_party/json/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + "${fwk_utils_path}/include/", + "${fwk_utils_path}/include/log", + ] + + include_dirs += [ + "./inner_kits", + "./services", + "${av_center_kits_path}/include", + "${common_path}/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/decision_center/include", + "${services_path}/common/imageJpeg/include", + "${services_path}/common/screen_channel/include", + "${services_path}/common/utils/include", + "${services_path}/screentransport/screendatachannel/include", + "${services_path}/screentransport/screensinkprocessor/decoder/include", + "${services_path}/screentransport/screensinkprocessor/include", + "${services_path}/screentransport/screensinktrans/include", + "${services_path}/screentransport/screensourcetrans/include", + "${services_path}/screentransport/screensourceprocessor/include", + "${services_path}/screentransport/screensourceprocessor/encoder/include", + "${services_path}/screentransport/test/unittest/screensourcetrans/include", + "${services_path}/softbusadapter/include", + ] +} + +## UnitTest screen_callback_test +ohos_unittest("ScreenCallbackTest") { + module_out_path = module_out_path + + sources = [ "${services_path}/screentransport/test/unittest/screentranstestutils/src/screen_callback_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", + "${services_path}/screentransport/screensourcetrans:distributed_screen_sourcetrans", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "c_utils:utils", + "graphic_2d:libgraphic_utils", + "graphic_2d:surface", + "graphic_2d:sync_fence", + "ipc:ipc_core", + "player_framework:media_client", + ] +} + +group("screen_callback_test") { + testonly = true + deps = [ ":ScreenCallbackTest" ] +} + diff --git a/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_stub_test.cpp b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef653d83f51c23d001af0445c15a1223dd26d965 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_stub_test.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2023 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 "av_sync_manager_test.h" +#include "av_trans_errno.h" + +using namespace testing::ext; +namespace OHOS { +namespace DistributedHardware { +void AVTransControlCenterCallbackStubTest::SetUpTestCase(void) +{ +} + +void AVTransControlCenterCallbackStubTest::TearDownTestCase(void) +{ +} + +void AVTransControlCenterCallbackStubTest::SetUp() +{ +} + +void AVTransControlCenterCallbackStubTest::TearDown() +{ +} + +int32_t AVTransControlCenterCallbackStubTest::TestControlCenterCallbackStub::SetParameter( + AVTransTag tag, const std::string &value) +{ + (void) tag; + (void) value; + return DH_AVT_SUCCESS; +} +int32_t AVTransControlCenterCallbackStubTest::TestControlCenterCallbackStub::SetSharedMemory( + const AVTransSharedMemory &memory) +{ + (void) memory; + return DH_AVT_SUCCESS; +} +int32_t AVTransControlCenterCallbackStubTest::TestControlCenterCallbackStub::Notify( + const AVTransEvent &event) +{ + (void) event; + return DH_AVT_SUCCESS; +} + +/** + * @tc.name: set_parameter_001 + * @tc.desc: set parameter function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackStubTest, set_parameter_001, TestSize.Level0) +{ + sptr CallbackStubPtr(new TestControlCenterCallbackStub()); + AVTransControlCenterCallbackProxy callbackProxy(CallbackStubPtr); + + AVTransTag tag; + std::string value; + int32_t ret = callbackProxy.SetParameter(tag, value); + EXPECT_EQ(NO_ERROR, ret); +} + +/** + * @tc.name: set_shared_memory_001 + * @tc.desc: set shared memory function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackStubTest, set_shared_memory_001, TestSize.Level0) +{ + sptr CallbackStubPtr(new TestControlCenterCallbackStub()); + AVTransControlCenterCallbackProxy callbackProxy(CallbackStubPtr); + + AVTransSharedMemory memory; + int32_t ret = callbackProxy.SetSharedMemory(memory); + EXPECT_EQ(NO_ERROR, ret); +} + +/** + * @tc.name: notify_001 + * @tc.desc: notify function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackStubTest, notify_001, TestSize.Level0) +{ + sptr CallbackStubPtr(new TestControlCenterCallbackStub()); + AVTransControlCenterCallbackProxy callbackProxy(CallbackStubPtr); + + AVTransEvent event; + int32_t ret = callbackProxy.Notify(event); + EXPECT_EQ(NO_ERROR, ret); +} \ No newline at end of file diff --git a/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_stub_test.h b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_stub_test.h new file mode 100644 index 0000000000000000000000000000000000000000..7bbbaf0dd51ef75ce90bf2d6bfd9a5cebc26a4d4 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_stub_test.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023 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_AV_TRANS_CONTROL_CENTER_CALLBACK_STUB_TEST_H +#define OHOS_AV_TRANS_CONTROL_CENTER_CALLBACK_STUB_TEST_H + +#include +#include "av_trans_control_center_callback_stub.h" + +namespace OHOS { +namespace DistributedHardware { +class AVTransControlCenterCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + + class TestControlCenterCallbackStub : public OHOS::DistributedHardware::AVTransControlCenterCallbackStub { + public: + TestControlCenterCallbackStub() = default; + virtual ~TestControlCenterCallbackStub() = default; + int32_t SetParameter(AVTransTag tag, const std::string &value) override; + int32_t SetSharedMemory(const AVTransSharedMemory &memory) override; + int32_t Notify(const AVTransEvent &event) override; + }; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_test.cpp b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6432711687332361cb3ab7c58e9180db2f0d7def --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_test.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2023 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 "av_trans_control_center_callback_test.h" +#include "av_trans_errno.h" + +using namespace testing::ext; +namespace OHOS { +namespace DistributedHardware { +void AVTransControlCenterCallbackTest::SetUpTestCase(void) +{ +} + +void AVTransControlCenterCallbackTest::TearDownTestCase(void) +{ +} + +void AVTransControlCenterCallbackTest::SetUp() +{ + callBack_ = std::make_shared(); + std::string ownerName = "ownerName"; + std::string peerDevId = "peerDevId"; + callBack_->receiverEngine_ = std::shared_ptr(ownerName, peerDevId); + callBack_->senderEngine_ = std::shared_ptr(ownerName, peerDevId); + +void AVTransControlCenterCallbackTest::TearDown() +{ + callBack_->senderEngine_ = nullptr; + callBack_->receiverEngine_ = nullptr; + callBack_ = nullptr; +} + +/** + * @tc.name: set_parameter_001 + * @tc.desc: set parameter function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackTest, set_parameter_001, TestSize.Level0) +{ + AVTransTag tag = AVTransTag::START_AV_SYNC; + std::string value; + int32_t ret = callBack_->SetParameter(tag, value); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: set_parameter_002 + * @tc.desc: set parameter function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackTest, set_parameter_002, TestSize.Level0) +{ + AVTransTag tag = AVTransTag::STOP_AV_SYNC; + std::string value; + int32_t ret = callBack_->SetParameter(tag, value); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: set_parameter_003 + * @tc.desc: set parameter function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackTest, set_parameter_003, TestSize.Level0) +{ + AVTransTag tag = AVTransTag::TIME_SYNC_RESULT; + std::string value; + int32_t ret = callBack_->SetParameter(tag, value); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: set_shared_memory_001 + * @tc.desc: set shared memory function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackTest, set_shared_memory_001, TestSize.Level0) +{ + AVTransSharedMemory memory; + int32_t ret = callBack_->SetSharedMemory(memory); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: notify_001 + * @tc.desc: notify function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackTest, notify_001, TestSize.Level0) +{ + const AVTransEvent event; + int32_t ret = callBack_->notify(event); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: set_sender_engine_001 + * @tc.desc: set sender engine function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackTest, set_sender_engine_001, TestSize.Level0) +{ + std::string ownerName = "ownerName1"; + std::string peerDevId = "peerDevId1"; + std::shared_ptr sender = std::shared_ptr(ownerName, peerDevId); + callBack_->SetSenderEngine(sender); + EXPECT_EQ(callBack_->senderEngine_, sender); +} + +/** + * @tc.name: set_receiver_engine_001 + * @tc.desc: set receiver engine function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackTest, set_receiver_engine_001, TestSize.Level0) +{ + std::string ownerName = "ownerName1"; + std::string peerDevId = "peerDevId1"; + std::shared_ptr receiver = std::shared_ptr(ownerName, peerDevId); + callBack_->SetReceiverEngine(receiver); + EXPECT_EQ(callBack_->receiverEngine_, receiver); +} \ No newline at end of file diff --git a/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_test.h b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_test.h new file mode 100644 index 0000000000000000000000000000000000000000..9e9fa7a20199550a9ba8ee6962a0de34fb5f6348 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/inner_kits/av_trans_control_center_callback_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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_AV_TRANS_CONTROL_CENTER_CALLBACK_TEST_H +#define OHOS_AV_TRANS_CONTROL_CENTER_CALLBACK_TEST_H + +#include + +namespace OHOS { +namespace DistributedHardware { +class AVTransControlCenterCallbackTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr callBack_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/av_transport/av_trans_control_center/test/unittest/services/av_sync_manager_test.cpp b/av_transport/av_trans_control_center/test/unittest/services/av_sync_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81fa2b62d98fd343781f527dc88587bbf48ade1c --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/services/av_sync_manager_test.cpp @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2023 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 "av_sync_manager_test.h" +#include "av_trans_errno.h" + +using namespace testing::ext; +namespace OHOS { +namespace DistributedHardware { +void AVSyncManagerTest::SetUpTestCase(void) +{ +} + +void AVSyncManagerTest::TearDownTestCase(void) +{ +} + +void AVSyncManagerTest::SetUp() +{ + syncManager_ = std::make_shared(); +} + +void AVSyncManagerTest::TearDown() +{ + syncManager_ = nullptr; +} + +/** + * @tc.name: add_stream_info_001 + * @tc.desc: add stream info function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, add_stream_info_001, TestSize.Level0) +{ + AVStreamInfo stream; + syncManager_->AddStreamInfo(stream); + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: add_stream_info_002 + * @tc.desc: add stream info function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, add_stream_info_002, TestSize.Level0) +{ + AVStreamInfo streamFirst; + syncManager_->AddStreamInfo(streamFirst); + AVStreamInfo streamSecond; + syncManager_->AddStreamInfo(streamSecond); + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: remove_stream_info_001 + * @tc.desc: remove stream info function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, remove_stream_info_001, TestSize.Level0) +{ + AVStreamInfo streamFirst; + syncManager_->AddStreamInfo(streamFirst); + AVStreamInfo streamSecond; + syncManager_->AddStreamInfo(streamSecond); + + syncManager_->RemoveStreamInfo(streamSecond); + + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: enable_sender_av_sync_001 + * @tc.desc: enable sender av sync function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, enable_sender_av_sync_001, TestSize.Level0) +{ + + syncManager_->EnableSenderAVSync(); + + + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: disable_sender_av_sync_001 + * @tc.desc: disable sender av sync function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, disable_sender_av_sync_001, TestSize.Level0) +{ + + syncManager_->DisableSenderAVSync(); + + + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: handle_av_sync_message_001 + * @tc.desc: handle av sync function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, handle_av_sync_message_001, TestSize.Level0) +{ + std::shared_ptr message = nullptr; + syncManager_->HandleAvSyncMessage(message); + + + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: enable_receiver_av_sync_001 + * @tc.desc: enable receiver av sync function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, enable_receiver_av_sync_001, TestSize.Level0) +{ + std::string groupInfo; + syncManager_->EnableReceiverAVSync(groupInfo); + + + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: disable_receiver_av_sync_001 + * @tc.desc: disable receiver av sync function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, disable_receiver_av_sync_001, TestSize.Level0) +{ + std::string groupInfo; + syncManager_->DisableReceiverAVSync(groupInfo); + + + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} + +/** + * @tc.name: merge_group_info_001 + * @tc.desc: merge group info function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVSyncManagerTest, merge_group_info_001, TestSize.Level0) +{ + std::string groupInfo; + syncManager_->MergeGroupInfo(groupInfo); + + + EXPECT_NE(0, syncManager_->streamInfoList_.size()); +} \ No newline at end of file diff --git a/av_transport/av_trans_control_center/test/unittest/services/av_sync_manager_test.h b/av_transport/av_trans_control_center/test/unittest/services/av_sync_manager_test.h new file mode 100644 index 0000000000000000000000000000000000000000..e9f1206da1bf88c64418577ca7f23f1ac7009d20 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/services/av_sync_manager_test.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023 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_AV_SYNC_MANAGER_TEST_H +#define OHOS_AV_SYNC_MANAGER_TEST_H + +#include + +#include "av_sync_manager.h" + +namespace OHOS { +namespace DistributedHardware { +class AVSyncManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr syncManager_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_callback_proxy_test.cpp b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_callback_proxy_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb977d4563981fbbe04d1ec92657958a23c47e34 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_callback_proxy_test.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023 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 "av_sync_manager_test.h" + +using namespace testing::ext; +namespace OHOS { +namespace DistributedHardware { +void AVTransControlCenterCallbackProxyTest::SetUpTestCase(void) +{ +} + +void AVTransControlCenterCallbackProxyTest::TearDownTestCase(void) +{ +} + +void AVTransControlCenterCallbackProxyTest::SetUp() +{ +} + +void AVTransControlCenterCallbackProxyTest::TearDown() +{ +} + +/** + * @tc.name: av_sync_manager_test_001 + * @tc.desc: Verify the EventBus AddHandler function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterCallbackProxyTest, event_bus_test_001, TestSize.Level0) +{ + EXPECT_EQ(g_regHandler, nullptr); + + FakeEvent e(*g_sender, *g_obj); + g_regHandler = g_eventBus->AddHandler(e.GetType(), *g_listener); + + EXPECT_NE(g_regHandler, nullptr); + EXPECT_EQ(g_regHandler->GetSender(), nullptr); + EXPECT_EQ(g_regHandler->GetHandler(), (void *)g_listener); +} diff --git a/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_callback_proxy_test.h b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_callback_proxy_test.h new file mode 100644 index 0000000000000000000000000000000000000000..b8f0a3cf256f531a4fe8339796f0ef43a6ab7b2b --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_callback_proxy_test.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 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_AV_TRANS_CONTROL_CENTER_CALLBACK_PROXY_TEST_H +#define OHOS_AV_TRANS_CONTROL_CENTER_CALLBACK_PROXY_TEST_H + +#include + +namespace OHOS { +namespace DistributedHardware { +class AVTransControlCenterCallbackProxyTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_test.cpp b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..311639a507d605d7417cb430b96cf1caf66f84c3 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_test.cpp @@ -0,0 +1,471 @@ +/* + * Copyright (c) 2023 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 "av_trans_control_center_test.h" +#include "av_trans_types.h" +#include "av_sync_utils.h" +#include "av_trans_errno.h" + +using namespace testing::ext; +namespace OHOS { +namespace DistributedHardware { +void AVTransControlCenterTest::SetUpTestCase(void) +{ +} + +void AVTransControlCenterTest::TearDownTestCase(void) +{ +} + +void AVTransControlCenterTest::SetUp() +{ + center_ = std::make_shared(); +} + +void AVTransControlCenterTest::TearDown() +{ + center_ = nullptr; +} + +/** + * @tc.name: initialize_av_center_001 + * @tc.desc: initialize av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, initialize_av_center_001, TestSize.Level0) +{ + TransRole transRole = TransRole::UNKNOWN; + int32_t engineId; + int32_t ret = center_->InitializeAVCenter(transRole, engineId); + EXPECT_EQ(ERR_DH_AVT_INVALID_PARAM_VALUE, ret); +} + +/** + * @tc.name: initialize_av_center_002 + * @tc.desc: initialize av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, initialize_av_center_002, TestSize.Level0) +{ + TransRole transRole = TransRole::AV_SENDER; + int32_t engineId; + center_->initialized_= true; + int32_t ret = center_->InitializeAVCenter(transRole, engineId); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: initialize_av_center_003 + * @tc.desc: initialize av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, initialize_av_center_003, TestSize.Level0) +{ + TransRole transRole = TransRole::AV_SENDER; + int32_t engineId; + center_->initialized_= false; + int32_t ret = center_->InitializeAVCenter(transRole, engineId); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: release_av_center_001 + * @tc.desc: release av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, release_av_center_001, TestSize.Level0) +{ + int32_t engineId = INVALID_ENGINE_ID; + int32_t ret = center_->ReleaseAVCenter(engineId); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: release_av_center_002 + * @tc.desc: release av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, release_av_center_002, TestSize.Level0) +{ + int32_t engineId = 1; + int32_t engineIdSecond = 2; + center_->engine2DevIdMap_.insert(std::make_pair(engineId, "engineId")); + center_->engine2DevIdMap_.insert(std::make_pair(engineIdSecond, "engineId")); + int32_t ret = center_->ReleaseAVCenter(engineId); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: release_av_center_003 + * @tc.desc: release av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, release_av_center_003, TestSize.Level0) +{ + int32_t engineId = 1; + center_->engine2DevIdMap_.insert(std::make_pair(engineId, "engineId")); + int32_t ret = center_->ReleaseAVCenter(engineId); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: release_av_center_004 + * @tc.desc: release av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, release_av_center_004, TestSize.Level0) +{ + int32_t engineId = 1; + center_->engine2DevIdMap_.insert(std::make_pair(engineId, "engineId")); + center_->connectedDevIds_.push_back("engineId"); + int32_t ret = center_->ReleaseAVCenter(engineId); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: create_control_channel_001 + * @tc.desc: create control channel function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, create_control_channel_001, TestSize.Level0) +{ + int32_t engineId = INVALID_ENGINE_ID; + std::string peerDevId; + int32_t ret = center_->CreateControlChannel(engineId, peerDevId); + EXPECT_EQ(ERR_DH_AVT_INVALID_PARAM_VALUE, ret); +} + +/** + * @tc.name: create_control_channel_002 + * @tc.desc: create control channel function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, create_control_channel_002, TestSize.Level0) +{ + int32_t engineId = 1; + std::string peerDevId; + center_->initialized_ = false; + int32_t ret = center_->CreateControlChannel(engineId, peerDevId); + EXPECT_EQ(ERR_DH_AVT_CREATE_CHANNEL_FAILED, ret); +} + +/** + * @tc.name: create_control_channel_003 + * @tc.desc: create control channel function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, create_control_channel_003, TestSize.Level0) +{ + int32_t engineId = 1; + std::string peerDevId = "peerDevId"; + center_->initialized_ = true; + center_->connectedDevIds_.push_back("peerDevId"); + int32_t ret = center_->CreateControlChannel(engineId, peerDevId); + EXPECT_EQ(ERR_DH_AVT_CHANNEL_ALREADY_CREATED, ret); +} + +/** + * @tc.name: create_control_channel_004 + * @tc.desc: create control channel function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, create_control_channel_004, TestSize.Level0) +{ + int32_t engineId = 1; + std::string peerDevId = "peerDevId"; + center_->initialized_ = true; + int32_t ret = center_->CreateControlChannel(engineId, peerDevId); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: notify_av_center_001 + * @tc.desc: notify av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, notify_av_center_001, TestSize.Level0) +{ + int32_t engineId; + AVTransEvent event; + event.type = EventType::EVENT_ADD_STREAM; + + int32_t ret = center_->NotifyAVCenter(engineId, event); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: notify_av_center_002 + * @tc.desc: notify av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, notify_av_center_002, TestSize.Level0) +{ + int32_t engineId; + AVTransEvent event; + event.type = EventType::EVENT_REMOVE_STREAM; + + int32_t ret = center_->NotifyAVCenter(engineId, event); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: notify_av_center_003 + * @tc.desc: notify av center function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, notify_av_center_003, TestSize.Level0) +{ + int32_t engineId; + AVTransEvent event; + event.type = EventType::EVENT_CHANNEL_OPENED; + + int32_t ret = center_->NotifyAVCenter(engineId, event); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: register_ctl_center_callback_001 + * @tc.desc: register ctl center callback function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, register_ctl_center_callback_001, TestSize.Level0) +{ + int32_t engineId = INVALID_ENGINE_ID; + sptr callback = nullptr; + int32_t ret = center_->RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(ERR_DH_AVT_INVALID_PARAM_VALUE, ret); +} + +/** + * @tc.name: register_ctl_center_callback_002 + * @tc.desc: register ctl center callback function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, register_ctl_center_callback_002, TestSize.Level0) +{ + int32_t engineId = 1; + sptr callback = nullptr; + int32_t ret = center_->RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(ERR_DH_AVT_INVALID_PARAM_VALUE, ret); +} + +/** + * @tc.name: register_ctl_center_callback_003 + * @tc.desc: register ctl center callback function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, register_ctl_center_callback_003, TestSize.Level0) +{ + int32_t engineId = 1; + sptr callback = new CenterCallback(); + int32_t ret = center_->RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: on_channel_event_001 + * @tc.desc: on channel event function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, on_channel_event_001, TestSize.Level0) +{ + AVTransEvent event; + event.type = EventType::EVENT_CHANNEL_CLOSED; + center_->OnChannelEvent(event); + int32_t engineId = 1; + sptr callback = new CenterCallback(); + int32_t ret = center_->RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: on_channel_event_002 + * @tc.desc: on channel event function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, on_channel_event_002, TestSize.Level0) +{ + AVTransEvent event; + //event.content = (uint32_t)AVTransTag::START_AV_SYNC; + event.type = EventType::EVENT_DATA_RECEIVED; + center_->OnChannelEvent(event); + int32_t engineId = 1; + sptr callback = new CenterCallback(); + int32_t ret = center_->RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: on_channel_event_003 + * @tc.desc: on channel event function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, on_channel_event_003, TestSize.Level0) +{ + AVTransEvent event; + event.type = EventType::EVENT_TIME_SYNC_RESULT; + center_->sessionName_ = AV_SYNC_RECEIVER_CONTROL_SESSION_NAME; + center_->OnChannelEvent(event); + int32_t engineId = 1; + sptr callback = new CenterCallback(); + int32_t ret = center_->RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: on_channel_event_004 + * @tc.desc: on channel event function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, on_channel_event_004, TestSize.Level0) +{ + AVTransEvent event; + event.type = EventType::EVENT_REMOVE_STREAM; + center_->sessionName_ = AV_SYNC_RECEIVER_CONTROL_SESSION_NAME; + center_->OnChannelEvent(event); + + StreamData *data; + StreamData *ext; + center_->OnStreamReceived(data, ext); + int32_t engineId = 1; + sptr callback = new CenterCallback(); + int32_t ret = center_->RegisterCtlCenterCallback(engineId, callback); + EXPECT_EQ(DH_AVT_SUCCESS, ret); +} + +/** + * @tc.name: send_message_001 + * @tc.desc: send message function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, send_message_001, TestSize.Level0) +{ + std::shared_ptr message = nullptr; + int32_t ret = center_->SendMessage(message);; + EXPECT_EQ(ERR_DH_AVT_INVALID_PARAM, ret); +} + +/** + * @tc.name: send_message_002 + * @tc.desc: send message function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, send_message_002, TestSize.Level0) +{ + std::shared_ptr message = std::make_shared(); + int32_t ret = center_->SendMessage(message);; + EXPECT_EQ(ERR_DH_AVT_INVALID_PARAM, ret); +} + +/** + * @tc.name: set_param_2_engines_001 + * @tc.desc: set param2engines function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, set_param_2_engines_001, TestSize.Level0) +{ + AVTransTag tag; + std::string value = "value"; + int32_t engineId = 1; + sptr callback = new CenterCallback(); + center_->callbackMap_.insert(std::make_pair(engineId, callback)); + int32_t ret = center_->SetParam2Engines(tag, value); + EXPECT_EQ(callback->value_, value); +} + +/** + * @tc.name: set_param_2_engines_002 + * @tc.desc: set param2engines function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, set_param_2_engines_002, TestSize.Level0) +{ + AVTransSharedMemory memory; + memory.name = "memory"; + sptr callback = new CenterCallback(); + center_->SetParam2Engines(memory); + EXPECT_EQ(callback->memory_.name, memory.name); +} + +/** + * @tc.name: handle_channel_event_001 + * @tc.desc: handle channel event function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, handle_channel_event_001, TestSize.Level0) +{ + AVTransEvent event; + event.type = EventType::EVENT_CHANNEL_CLOSED; + center_->HandleChannelEvent(event); + event.type = EventType::EVENT_CHANNEL_OPEN_FAIL; + center_->HandleChannelEvent(event); + event.type = EventType::EVENT_CHANNEL_OPENED; + event.content = AV_SYNC_RECEIVER_CONTROL_SESSION_NAME; + center_->HandleChannelEvent(event); + + EXPECT_NE(0, center_->connectedDevIds_.size()); +} + +/** + * @tc.name: is_invalid_engineId_001 + * @tc.desc: is invalid engineId function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, is_invalid_engineId_001, TestSize.Level0) +{ + int32_t engineId = BASE_ENGINE_ID - 1; + bool ret = center_->IsInvalidEngineId(engineId); + EXPECT_EQ(true, ret); +} + +/** + * @tc.name: is_invalid_engineId_002 + * @tc.desc: is invalid engineId function. + * @tc.type: FUNC + * @tc.require: AR000GHSK9 + */ +HWTEST_F(AVTransControlCenterTest, is_invalid_engineId_002, TestSize.Level0) +{ + int32_t engineId = BASE_ENGINE_ID + 1; + bool ret = center_->IsInvalidEngineId(engineId); + EXPECT_EQ(true, ret); +} \ No newline at end of file diff --git a/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_test.h b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_test.h new file mode 100644 index 0000000000000000000000000000000000000000..82f781f74878a696552489baa0b525776fee80e6 --- /dev/null +++ b/av_transport/av_trans_control_center/test/unittest/services/av_trans_control_center_test.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023 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_AV_TRANS_CONTROL_CENTER_TEST_H +#define OHOS_AV_TRANS_CONTROL_CENTER_TEST_H + +#include + +namespace OHOS { +namespace DistributedHardware { +class AVTransControlCenterTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr center_ = nullptr; +}; +class CenterCallback : public IAVTransControlCenterCallback { +public: + CenterCallback() = default; + ~CenterCallback() = default; + int32_t SetParameter(AVTransTag tag, const std::string &value) override + { + value_ = value; + return DH_AVT_SUCCESS; + } + int32_t SetSharedMemory(const AVTransSharedMemory &memory) override + { + memory_ = memory; + return DH_AVT_SUCCESS; + } + int32_t Notify(const AVTransEvent &event) override + { + return DH_AVT_SUCCESS; + } +private: + std::string value_; + AVTransSharedMemory memory_; +} +} // namespace DistributedHardware +} // namespace OHOS +#endif