From 23262bc753f75e2563bdbab1fb8202ea86f272a9 Mon Sep 17 00:00:00 2001 From: gaoqiang_strong Date: Wed, 21 Sep 2022 19:26:23 +0800 Subject: [PATCH] add ut test Signed-off-by: gaoqiang_strong --- bundle.json | 2 + .../src/dscreen_source_handler_test.cpp | 65 ++++- .../test/unittest/screenhandler/BUILD.gn | 71 ++++++ .../include/dscreen_handler_test.h | 56 ++++ .../src/dscreen_handler_test.cpp | 61 +++++ services/screendemo/test.cpp | 1 + .../sinkservice/screenregionmgr/BUILD.gn | 75 ++++++ .../include/screenregion_test.h | 40 +++ .../include/screenregionmgr_test.h | 38 +++ .../screenregionmgr/src/screenregion_test.cpp | 140 ++++++++++ .../src/screenregionmgr_test.cpp | 83 ++++++ .../src/screen_source_trans_test.cpp | 240 +++++++++++++++++- .../include/screentrans_test_utils.h | 27 ++ 13 files changed, 890 insertions(+), 9 deletions(-) create mode 100644 screenhandler/test/unittest/screenhandler/BUILD.gn create mode 100644 screenhandler/test/unittest/screenhandler/include/dscreen_handler_test.h create mode 100644 screenhandler/test/unittest/screenhandler/src/dscreen_handler_test.cpp create mode 100644 services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn create mode 100644 services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregion_test.h create mode 100644 services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregionmgr_test.h create mode 100644 services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregion_test.cpp create mode 100644 services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp diff --git a/bundle.json b/bundle.json index 9dc1a648..7c6eeb70 100644 --- a/bundle.json +++ b/bundle.json @@ -83,6 +83,8 @@ ], "test":[ "//foundation/distributedhardware/distributed_screen/services/screendemo:distributedScreenTest", + "//foundation/distributedhardware/distributed_screen/screenhandler/test/unittest/screenhandler:DscreenHandlerTest", + "//foundation/distributedhardware/distributed_screen/services/screenservice/test/unittest/sinkservice/screenregionmgr:DscreenSinkServiceTest", "//foundation/distributedhardware/distributed_screen/services/screentransport/test/unittest:screen_transport_test", "//foundation/distributedhardware/distributed_screen/services/softbusadapter/test/unittest:SoftBusAdapterTest", "//foundation/distributedhardware/distributed_screen/services/common/test/unittest:service_common_test", diff --git a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp index 66a4c38a..39c90383 100644 --- a/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp +++ b/interfaces/innerkits/native_cpp/test/unittest/screensourcetest/src/dscreen_source_handler_test.cpp @@ -22,20 +22,20 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { -void DScreenSourceHandlerTest::SetUpTestCase(void) +void DScreenSourceHandlerTest::SetUpTestCase(void) {} + +void DScreenSourceHandlerTest::TearDownTestCase(void) {} + +void DScreenSourceHandlerTest::SetUp(void) { DScreenSourceHandler::GetInstance().InitSource("DScreenSourceHandlerTest"); } -void DScreenSourceHandlerTest::TearDownTestCase(void) +void DScreenSourceHandlerTest::TearDown(void) { DScreenSourceHandler::GetInstance().ReleaseSource(); } -void DScreenSourceHandlerTest::SetUp(void) {} - -void DScreenSourceHandlerTest::TearDown(void) {} - /** * @tc.name: RegisterDistributedHardware_001 * @tc.desc: Verify the RegisterDistributedHardware function. @@ -69,8 +69,61 @@ HWTEST_F(DScreenSourceHandlerTest, RegisterDistributedHardware_002, TestSize.Lev param.attrs = "attrs"; std::shared_ptr callback = std::make_shared(); DScreenSourceHandler::GetInstance().dScreenSourceCallback_ = nullptr; + int32_t ret = DScreenSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback); EXPECT_EQ(ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT, ret); } + +/** + * @tc.name: UnregisterDistributedHardware_001 + * @tc.desc: Verify the UnregisterDistributedHardware function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSourceHandlerTest, UnregisterDistributedHardware_001, TestSize.Level1) +{ + const std::string devId = "devId"; + const std::string dhId = "dhId"; + std::shared_ptr callback = std::make_shared(); + if (DScreenSourceHandler::GetInstance().dScreenSourceCallback_ == nullptr) { + DScreenSourceHandler::GetInstance().dScreenSourceCallback_ = new (std::nothrow) DScreenSourceCallback();; + } + int32_t ret = DScreenSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); + EXPECT_EQ(ERR_DH_SCREEN_SA_DISABLE_FAILED, ret); +} + +/** + * @tc.name: UnregisterDistributedHardware_002 + * @tc.desc: Verify the UnregisterDistributedHardware function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSourceHandlerTest, UnregisterDistributedHardware_002, TestSize.Level1) +{ + const std::string devId = "devId"; + const std::string dhId = "dhId"; + std::shared_ptr callback = std::make_shared(); + DScreenSourceHandler::GetInstance().dScreenSourceCallback_ = nullptr; + + int32_t ret = DScreenSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, callback); + EXPECT_EQ(ERR_DH_SCREEN_SA_SOURCEPCALLBACK_NOT_INIT, ret); +} + +/** + * @tc.name: ConfigDistributedHardware_001 + * @tc.desc: Verify the ConfigDistributedHardware function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenSourceHandlerTest, ConfigDistributedHardware_001, TestSize.Level1) +{ + const std::string devId = "devId"; + const std::string dhId = "dhId"; + const std::string key = "key"; + const std::string value = "value"; + + int32_t ret = DScreenSourceHandler::GetInstance().ConfigDistributedHardware(devId, dhId, key, value); + EXPECT_EQ(DH_SUCCESS, ret); +} } } \ No newline at end of file diff --git a/screenhandler/test/unittest/screenhandler/BUILD.gn b/screenhandler/test/unittest/screenhandler/BUILD.gn new file mode 100644 index 00000000..5b10c785 --- /dev/null +++ b/screenhandler/test/unittest/screenhandler/BUILD.gn @@ -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. + +import("//build/test.gni") +import( + "//foundation/distributedhardware/distributed_screen/distributedscreen.gni") + +module_out_path = "distributed_screen/dscreen_handler_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "//third_party/json/include", + "${windowmanager_path}/interfaces/innerkits/dm", + "${graphicstandard_path}/interfaces/innerkits/surface", + "${mediastandard_path}/interfaces/inner_api/native", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "./include", + "${common_path}/include", + "//foundation/distributedhardware/distributed_screen/screenhandler/include", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_base/include", + "//drivers/peripheral/display/interfaces/include", + "//drivers/peripheral/base", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//foundation/graphic/graphic_2d/utils/buffer_handle/export", + ] +} + +## UnitTest dscreen_handler_test +ohos_unittest("DscreenHandlerTest") { + module_out_path = module_out_path + + sources = [ "//foundation/distributedhardware/distributed_screen/screenhandler/test/unittest/screenhandler/src/dscreen_handler_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${windowmanager_path}/dm:libdm", + "//foundation/distributedhardware/distributed_screen/screenhandler:distributed_screen_handler", + "//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenHandlerTest\"", + "LOG_DOMAIN=0xD004100", + ] + + cflags = [ + "-frtti", + "-fexceptions", + ] + cflags_cc = cflags +} diff --git a/screenhandler/test/unittest/screenhandler/include/dscreen_handler_test.h b/screenhandler/test/unittest/screenhandler/include/dscreen_handler_test.h new file mode 100644 index 00000000..0533fcd0 --- /dev/null +++ b/screenhandler/test/unittest/screenhandler/include/dscreen_handler_test.h @@ -0,0 +1,56 @@ +/* + * 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_DSCREEN_HANDLER_TEST_H +#define OHOS_DSCREEN_HANDLER_TEST_H + +#include +#include + +#define private public +#include "dscreen_handler.h" +#include "dscreen_errcode.h" +#include "ihardware_handler.h" +#undef private + +namespace OHOS { +namespace DistributedHardware { +class DScreenHandlerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +class MockPluginListener : public PluginListener { +public: + MockPluginListener() = default; + virtual ~MockPluginListener() = default; + void PluginHardware(const std::string &dhId, const std::string &attrs) override + { + (void) dhId; + (void) attrs; + return; + } + void UnPluginHardware(const std::string &dhId) override + { + (void) dhId; + return; + } +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/screenhandler/test/unittest/screenhandler/src/dscreen_handler_test.cpp b/screenhandler/test/unittest/screenhandler/src/dscreen_handler_test.cpp new file mode 100644 index 00000000..98252864 --- /dev/null +++ b/screenhandler/test/unittest/screenhandler/src/dscreen_handler_test.cpp @@ -0,0 +1,61 @@ +/* + * 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. + */ + +#define private public +#include "dscreen_handler_test.h" +#undef private + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void DScreenHandlerTest::SetUpTestCase(void) {} + +void DScreenHandlerTest::TearDownTestCase(void) {} + +void DScreenHandlerTest::SetUp(void) {} + +void DScreenHandlerTest::TearDown(void) {} + +/** + * @tc.name: Initialize_001 + * @tc.desc: Verify the Initialize function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenHandlerTest, Initialize_001, TestSize.Level1) +{ + int32_t ret = DScreenHandler::GetInstance().Initialize(); + + EXPECT_EQ(DH_SUCCESS, ret); +} + +/** + * @tc.name: RegisterPluginListener_001 + * @tc.desc: Verify the RegisterPluginListener function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenHandlerTest, RegisterPluginListener_001, TestSize.Level1) +{ + std::shared_ptr listener = std::make_shared(); + DScreenHandler::GetInstance().RegisterPluginListener(listener); + + EXPECT_EQ(listener, DScreenHandler::GetInstance().listener_); +} + +} +} \ No newline at end of file diff --git a/services/screendemo/test.cpp b/services/screendemo/test.cpp index 9cfd52ee..957f0fc4 100644 --- a/services/screendemo/test.cpp +++ b/services/screendemo/test.cpp @@ -324,6 +324,7 @@ static void CreateWindow() << ", width: " << windowWidth << ", height: " << windowHeight << endl; ScreenClient::GetInstance().RemoveWindow(windowId); + _Exit(0); } int main() diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn new file mode 100644 index 00000000..2abb51cb --- /dev/null +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn @@ -0,0 +1,75 @@ +# 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( + "//foundation/distributedhardware/distributed_screen/distributedscreen.gni") + +module_out_path = "distributed_screen/dscreen_sink_service_test" + +config("module_private_config") { + visibility = [ ":*" ] + include_dirs = [ + "//base/hiviewdfx/hisysevent/interfaces/native/innerkits/hisysevent/include", + "//third_party/json/include", + "//commonlibrary/c_utils/base/include", + "//utils/system/safwk/native/include", + "//foundation/graphic/graphic_2d/interfaces/inner_api/surface", + "//foundation/graphic/graphic_2d/interfaces/inner_api/common", + "//foundation/graphic/graphic_2d/utils/buffer_handle/export", + "${windowmanager_path}/interfaces/innerkits/dm", + "${fwk_common_path}/utils/include", + "${distributedhardwarefwk_path}/interfaces/inner_kits/include", + ] + + include_dirs += [ + "./include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${common_path}/include", + "${services_path}/common/utils/include", + "${services_path}/common/databuffer/include", + "${services_path}/common/screen_channel/include", + "${services_path}/screentransport/screensinktrans/include", + "${services_path}/screentransport/screensinkprocessor/include", + "${services_path}/screentransport/screensinkprocessor/decoder/include", + "${services_path}/screenclient/include/", + "${services_path}/screenservice/sinkservice/screenregionmgr/include", + "//foundation/multimedia/image_framework/interfaces/innerkits/include", + "//drivers/peripheral/display/interfaces/include", + "//drivers/peripheral/base", + ] +} + +## UnitTest DscreenSinkServiceTest +ohos_unittest("DscreenSinkServiceTest") { + module_out_path = module_out_path + + sources = [ + "${services_path}/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregion_test.cpp", + "${services_path}/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${services_path}/screenservice/sinkservice:distributed_screen_sink", + "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ "c_utils:utils" ] +} diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregion_test.h b/services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregion_test.h new file mode 100644 index 00000000..25db650a --- /dev/null +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregion_test.h @@ -0,0 +1,40 @@ +/* + * 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_SCREEN_REGION_TEST_H +#define OHOS_SCREEN_REGION_TEST_H + +#include +#include + +#define private public +#include "dscreen_errcode.h" +#include "screen_sink_trans.h" +#include "screenregion.h" +#undef private + +namespace OHOS { +namespace DistributedHardware { +class ScreenRegionTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + std::shared_ptr screenRegion_ = nullptr; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregionmgr_test.h b/services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregionmgr_test.h new file mode 100644 index 00000000..1d9df844 --- /dev/null +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/include/screenregionmgr_test.h @@ -0,0 +1,38 @@ +/* + * 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_SCREEN_REGION_MANAGER_TEST_H +#define OHOS_SCREEN_REGION_MANAGER_TEST_H + +#include +#include + +#define private public +#include "dscreen_errcode.h" +#include "screenregionmgr.h" +#undef private + +namespace OHOS { +namespace DistributedHardware { +class ScreenRegionManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregion_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregion_test.cpp new file mode 100644 index 00000000..9f6eed48 --- /dev/null +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregion_test.cpp @@ -0,0 +1,140 @@ +/* + * 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 "screenregion_test.h" +#include "dscreen_constants.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void ScreenRegionTest::SetUpTestCase(void) {} + +void ScreenRegionTest::TearDownTestCase(void) {} + +void ScreenRegionTest::SetUp(void) +{ + const std::string remoteDevId = "sourceDevId"; + uint64_t screenId = 0; + uint64_t displayId = 0; + screenRegion_ = std::make_shared(remoteDevId, screenId, displayId); +} + +void ScreenRegionTest::TearDown(void) +{ + sleep(1); +} + +/** + * @tc.name: SetUp_001 + * @tc.desc: Verify the SetUp function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTest, SetUp_001, TestSize.Level1) +{ + screenRegion_->mapRelation_ = std::make_shared(); + ScreenRect screenRect; + screenRect.startX = 0; + screenRect.startY = 0; + screenRect.width = 256; + screenRect.height = 256; + screenRegion_->mapRelation_->SetScreenRect(screenRect); + std::shared_ptr videoParam = std::make_shared(); + videoParam->screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + videoParam->screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + videoParam->videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + videoParam->videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + videoParam->codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + videoParam->videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + videoParam->fps_ = 30; + screenRegion_->SetVideoParam(videoParam); + int32_t ret = screenRegion_->SetUp(); + + EXPECT_EQ(ERR_DH_SCREEN_SA_DSCREEN_SCREENGION_SETUP_FAILED, ret); +} + +/** + * @tc.name: Start_001 + * @tc.desc: Verify the Start function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTest, Start_001, TestSize.Level1) +{ + int32_t ret = screenRegion_->Start(); + + EXPECT_EQ(ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT, ret); +} + +/** + * @tc.name: Start_002 + * @tc.desc: Verify the Start function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTest, Start_002, TestSize.Level1) +{ + screenRegion_->sinkTrans_ = std::make_shared(); + int32_t ret = screenRegion_->Start(); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret); +} + +/** + * @tc.name: Stop_001 + * @tc.desc: Verify the Stop function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTest, Stop_001, TestSize.Level1) +{ + screenRegion_->isRunning = false; + int32_t ret = screenRegion_->Stop(); + + EXPECT_EQ(DH_SUCCESS, ret); +} + +/** + * @tc.name: Stop_002 + * @tc.desc: Verify the Stop function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTest, Stop_002, TestSize.Level1) +{ + screenRegion_->isRunning = true; + int32_t ret = screenRegion_->Stop(); + + EXPECT_EQ(ERR_DH_SCREEN_SA_SINKTRANS_NOT_INIT, ret); +} + +/** + * @tc.name: Stop_003 + * @tc.desc: Verify the Stop function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionTest, Stop_003, TestSize.Level1) +{ + screenRegion_->isRunning = true; + screenRegion_->sinkTrans_ = std::make_shared(); + int32_t ret = screenRegion_->Stop(); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, ret); +} +} +} \ No newline at end of file diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp new file mode 100644 index 00000000..e514eae6 --- /dev/null +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp @@ -0,0 +1,83 @@ +/* + * 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 "screenregionmgr_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void ScreenRegionManagerTest::SetUpTestCase(void) {} + +void ScreenRegionManagerTest::TearDownTestCase(void) {} + +void ScreenRegionManagerTest::SetUp(void) {} + +void ScreenRegionManagerTest::TearDown(void) +{ + sleep(1); +} + +/** + * @tc.name: ReleaseAllRegions_001 + * @tc.desc: Verify the ReleaseAllRegions function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTest, ReleaseAllRegions_001, TestSize.Level1) +{ + const std::string remoteDevId = "sourceDevId"; + uint64_t screenId = 0; + uint64_t displayId = 0; + std::shared_ptr screenRegion = std::make_shared(remoteDevId, screenId, displayId); + ScreenRegionManager::GetInstance().screenRegions_[remoteDevId] = screenRegion; + int32_t ret = ScreenRegionManager::GetInstance().ReleaseAllRegions(); + + EXPECT_EQ(DH_SUCCESS, ret); +} + +/** + * @tc.name: NotifyRemoteScreenService_001 + * @tc.desc: Verify the NotifyRemoteScreenService function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTest, NotifyRemoteScreenService_001, TestSize.Level1) +{ + const std::string remoteDevId = "sourceDevId"; + const std::string dhId = "sinkDhId"; + int32_t eventCode = 0; + const std::string eventContent = "sourceEvent"; + int32_t ret = ScreenRegionManager::GetInstance().NotifyRemoteScreenService(remoteDevId, dhId, eventCode, eventContent); + + EXPECT_EQ(ERR_DH_SCREEN_SA_GET_REMOTE_SOURCE_SERVICE_FAIL, ret); +} + +/** + * @tc.name: GetDScreenSourceSA_001 + * @tc.desc: Verify the GetDScreenSourceSA function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTest, GetDScreenSourceSA_001, TestSize.Level1) +{ + const std::string remoteDevId = "sourceDevId"; + sptr ret = ScreenRegionManager::GetInstance().GetDScreenSourceSA(remoteDevId); + + EXPECT_EQ(nullptr, ret); +} +} +} \ No newline at end of file diff --git a/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp b/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp index b697883f..344bc5c7 100644 --- a/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp +++ b/services/screentransport/test/unittest/screensourcetrans/src/screen_source_trans_test.cpp @@ -48,6 +48,23 @@ HWTEST_F(ScreenSourceTransTest, SetUp_001, TestSize.Level1) EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual); } +/** + * @tc.name: InitScreenTrans_001 + * @tc.desc: Verify the InitScreenTrans function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, InitScreenTrans_001, TestSize.Level1) +{ + VideoParam localParam; + VideoParam remoteParam; + std::string peerDevId = "sinkDevId"; + trans->screenChannel_ = std::make_shared(); + int32_t actual = trans->InitScreenTrans(localParam, remoteParam, peerDevId); + + EXPECT_EQ(-1, actual); +} + /** * @tc.name: Release_001 * @tc.desc: Verify the Release function. @@ -70,7 +87,7 @@ HWTEST_F(ScreenSourceTransTest, Release_001, TestSize.Level1) HWTEST_F(ScreenSourceTransTest, Release_002, TestSize.Level1) { trans->imageProcessor_ = std::make_shared(); - std::string peerDevId = "hello"; + std::string peerDevId = "sinkDevId"; trans->screenChannel_ = std::make_shared(peerDevId); int32_t actual = trans->Release(); @@ -99,13 +116,73 @@ HWTEST_F(ScreenSourceTransTest, Start_001, TestSize.Level1) HWTEST_F(ScreenSourceTransTest, Start_002, TestSize.Level1) { trans->imageProcessor_ = std::make_shared(); - std::string peerDevId = "hello"; + std::string peerDevId = "sinkDevId"; trans->screenChannel_ = std::make_shared(peerDevId); int32_t actual = trans->Start(); EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual); } +/** + * @tc.name: Start_003 + * @tc.desc: Verify the Start function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, Start_003, TestSize.Level1) +{ + trans->imageProcessor_ = std::make_shared(); + std::string peerDevId = "sinkDevId"; + trans->screenChannel_ = std::make_shared(); + int32_t actual = trans->Start(); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_TIMEOUT, actual); +} + +/** + * @tc.name: Stop_001 + * @tc.desc: Verify the Stop function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, Stop_001, TestSize.Level1) +{ + int32_t actual = trans->Stop(); + EXPECT_EQ(ERR_DH_SCREEN_TRANS_NULL_VALUE, actual); +} + +/** + * @tc.name: Stop_002 + * @tc.desc: Verify the Stop function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, Stop_002, TestSize.Level1) +{ + trans->imageProcessor_ = std::make_shared(); + std::string peerDevId = "sinkDevId"; + trans->screenChannel_ = std::make_shared(); + int32_t actual = trans->Stop(); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual); +} + +/** + * @tc.name: Stop_003 + * @tc.desc: Verify the Stop function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, Stop_003, TestSize.Level1) +{ + trans->imageProcessor_ = std::make_shared(); + std::string peerDevId = "sinkDevId"; + trans->screenChannel_ = std::make_shared(peerDevId); + int32_t actual = trans->Stop(); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_ERROR, actual); +} + /** * @tc.name: RegisterStateCallback_001 * @tc.desc: Verify the RegisterStateCallback function. @@ -135,6 +212,39 @@ HWTEST_F(ScreenSourceTransTest, RegisterStateCallback_002, TestSize.Level1) EXPECT_EQ(DH_SUCCESS, actual); } +/** + * @tc.name: CheckVideoParam_001 + * @tc.desc: Verify the CheckVideoParam function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, CheckVideoParam_001, TestSize.Level1) +{ + VideoParam localParam; + localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_MPEG4 + 1; + int32_t actual = trans->CheckVideoParam(localParam); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual); +} + +/** + * @tc.name: CheckVideoParam + * @tc.desc: Verify the CheckVideoParam function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, CheckVideoParam_002, TestSize.Level1) +{ + VideoParam localParam; + localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + localParam.videoFormat_ = VIDEO_DATA_FORMAT_RGBA8888 + 1; + VideoParam remoteParam; + std::string peerDevId; + int32_t actual = trans->CheckVideoParam(localParam); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual); +} + /** * @tc.name: CheckTransParam_001 * @tc.desc: Verify the CheckTransParam function. @@ -144,7 +254,18 @@ HWTEST_F(ScreenSourceTransTest, RegisterStateCallback_002, TestSize.Level1) HWTEST_F(ScreenSourceTransTest, CheckTransParam_001, TestSize.Level1) { VideoParam localParam; + localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; VideoParam remoteParam; + remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; std::string peerDevId; int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId); @@ -158,6 +279,60 @@ HWTEST_F(ScreenSourceTransTest, CheckTransParam_001, TestSize.Level1) * @tc.require: Issue Number */ HWTEST_F(ScreenSourceTransTest, CheckTransParam_002, TestSize.Level1) +{ + VideoParam localParam; + localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH + 1; + localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + VideoParam remoteParam; + remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + std::string peerDevId = "sinkDevId"; + int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual); +} + +/** + * @tc.name: CheckTransParam_003 + * @tc.desc: Verify the CheckTransParam function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, CheckTransParam_003, TestSize.Level1) +{ + VideoParam localParam; + localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + VideoParam remoteParam; + remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH + 1; + remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + std::string peerDevId = "sinkDevId"; + int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId); + + EXPECT_EQ(ERR_DH_SCREEN_TRANS_ILLEGAL_PARAM, actual); +} + +/** + * @tc.name: CheckTransParam_004 + * @tc.desc: Verify the CheckTransParam function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, CheckTransParam_004, TestSize.Level1) { VideoParam localParam; localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; @@ -173,12 +348,41 @@ HWTEST_F(ScreenSourceTransTest, CheckTransParam_002, TestSize.Level1) remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; - std::string peerDevId = "hello"; + std::string peerDevId = "sinkDevId"; int32_t actual = trans->CheckTransParam(localParam, remoteParam, peerDevId); EXPECT_EQ(DH_SUCCESS, actual); } +/** + * @tc.name: GetImageSurface_001 + * @tc.desc: Verify the GetImageSurface function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, GetImageSurface_001, TestSize.Level1) +{ + VideoParam localParam; + localParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + localParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + localParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + localParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + localParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + localParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + VideoParam remoteParam; + remoteParam.codecType_ = VIDEO_CODEC_TYPE_VIDEO_H264; + remoteParam.videoFormat_ = VIDEO_DATA_FORMAT_YUVI420; + remoteParam.videoWidth_ = DSCREEN_MAX_VIDEO_DATA_WIDTH; + remoteParam.videoHeight_ = DSCREEN_MAX_VIDEO_DATA_HEIGHT; + remoteParam.screenWidth_ = DSCREEN_MAX_SCREEN_DATA_WIDTH; + remoteParam.screenHeight_ = DSCREEN_MAX_SCREEN_DATA_HEIGHT; + trans->imageProcessor_ = std::make_shared(); + trans->RegisterProcessorListener(localParam, remoteParam); + sptr encoderSurface = trans->GetImageSurface(); + + EXPECT_NE(nullptr, encoderSurface); +} + /** * @tc.name: OnSessionOpened_001 * @tc.desc: Verify the OnSessionOpened function. @@ -193,5 +397,35 @@ HWTEST_F(ScreenSourceTransTest, OnSessionOpened_001, TestSize.Level1) EXPECT_EQ(false, trans->isChannelReady_); } + +/** + * @tc.name: OnSessionClosed_001 + * @tc.desc: Verify the OnSessionClosed function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, OnSessionClosed_001, TestSize.Level1) +{ + trans->transCallback_ = std::make_shared(); + + trans->OnSessionClosed(); + + EXPECT_EQ(false, trans->isChannelReady_); +} + +/** + * @tc.name: OnImageProcessDone_001 + * @tc.desc: Verify the OnImageProcessDone function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenSourceTransTest, OnImageProcessDone_001, TestSize.Level1) +{ + std::shared_ptr data = nullptr; + int32_t queueSize = trans->dataQueue_.size(); + trans->OnImageProcessDone(data); + + EXPECT_NE(queueSize, trans->dataQueue_.size()); +} } } diff --git a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h index c62e6269..29ee222c 100644 --- a/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h +++ b/services/screentransport/test/unittest/screentranstestutils/include/screentrans_test_utils.h @@ -24,6 +24,7 @@ #include "iscreen_sink_trans_callback.h" #include "iscreen_source_trans_callback.h" #include "iscreen_channel_listener.h" +#include "iscreen_channel.h" namespace OHOS { namespace DistributedHardware { @@ -78,6 +79,32 @@ public: void OnSessionClosed() override {} void OnDataReceived(const std::shared_ptr &data) override {} }; + +class MockScreenDataChannelImpl :public IScreenChannel { +public: + int32_t CreateSession(const std::shared_ptr &listener) override + { + return DH_SUCCESS; + } + int32_t ReleaseSession() override + { + return DH_SUCCESS; + } + int32_t OpenSession() override + { + return DH_SUCCESS; + } + int32_t CloseSession() override + { + return ERR_DH_SCREEN_TRANS_SESSION_NOT_OPEN; + } + int32_t SendData(const std::shared_ptr &data) override + { + (void) data; + return DH_SUCCESS; + } +}; + } // namespace DistributedHardware } // namespace OHOS #endif \ No newline at end of file -- Gitee