diff --git a/bundle.json b/bundle.json index 7c6eeb703088a421eb1bf3273489e2ac9d86e89b..6d721823c470c619558dfdb226553cbe9761ee5e 100644 --- a/bundle.json +++ b/bundle.json @@ -84,7 +84,7 @@ "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/screenservice/test/unittest/sinkservice/screenregionmgr:DscreenRegionMgrTest", "//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/services/common/test/unittest/utils/BUILD.gn b/services/common/test/unittest/utils/BUILD.gn index 559366ad6192dd0657a407105cfc321a6dad1ca6..73c301ee087347cf777214244d535d8d569fbee0 100644 --- a/services/common/test/unittest/utils/BUILD.gn +++ b/services/common/test/unittest/utils/BUILD.gn @@ -25,6 +25,7 @@ config("module_private_config") { "${fwk_common_path}/utils/include", "${fwk_common_path}/log/include", "${fwk_utils_path}/include/log", + "//foundation/distributedhardware/distributed_hardware_fwk/interfaces/inner_kits/include", ] include_dirs += [ @@ -40,6 +41,7 @@ ohos_unittest("UtilsTest") { module_out_path = module_out_path sources = [ + "${services_path}/common/test/unittest/utils/dscreen_fwkkit_test.cpp", "${services_path}/common/test/unittest/utils/dscreen_maprelation_test.cpp", "${services_path}/common/test/unittest/utils/video_param_test.cpp", ] @@ -47,6 +49,7 @@ ohos_unittest("UtilsTest") { configs = [ ":module_private_config" ] deps = [ + "${distributedhardwarefwk_path}/interfaces/inner_kits:libdhfwk_sdk", "${services_path}/screenservice/sinkservice:distributed_screen_sink", "//third_party/googletest:gmock", "//third_party/googletest:gtest_main", diff --git a/services/common/test/unittest/utils/dscreen_fwkkit_test.cpp b/services/common/test/unittest/utils/dscreen_fwkkit_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bd6c355820922255f8c9c4728daf267e0b13b07d --- /dev/null +++ b/services/common/test/unittest/utils/dscreen_fwkkit_test.cpp @@ -0,0 +1,47 @@ +/* + * 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_fwkkit_test.h" +#include "distributed_hardware_fwk_kit.h" +#include "dscreen_fwkkit.h" +#undef private + +using namespace testing::ext; + +namespace OHOS { +namespace DistributedHardware { +void DScreenFwkKitTest::SetUpTestCase(void) {} + +void DScreenFwkKitTest::TearDownTestCase(void) {} + +void DScreenFwkKitTest::SetUp(){} + +void DScreenFwkKitTest::TearDown() {} + +/** + * @tc.name: GetDHFwkKit_001 + * @tc.desc: Verify the GetDHFwkKit function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenFwkKitTest, GetDHFwkKit_001, TestSize.Level1) +{ + auto ret = DScreenFwkKit::GetInstance().GetDHFwkKit(); + + EXPECT_NE(nullptr, DScreenFwkKit::GetInstance().dhfwkKit_); +} +} // namespace DistributedHardware +} // namespace OHOS \ No newline at end of file diff --git a/services/common/test/unittest/utils/dscreen_fwkkit_test.h b/services/common/test/unittest/utils/dscreen_fwkkit_test.h new file mode 100644 index 0000000000000000000000000000000000000000..42cd54bfe652bd646ad196ff2d581ac7cce3fd26 --- /dev/null +++ b/services/common/test/unittest/utils/dscreen_fwkkit_test.h @@ -0,0 +1,32 @@ +/* + * 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_FWK_KIT_TEST_H +#define OHOS_DSCREEN_FWK_KIT_TEST_H + +#include + +namespace OHOS { +namespace DistributedHardware { +class DScreenFwkKitTest : 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/common/test/unittest/utils/dscreen_maprelation_test.cpp b/services/common/test/unittest/utils/dscreen_maprelation_test.cpp index f78fa27e846d46bd02189933b541494d11fa3bd5..d18a89cd9d29d6bf690c273a99de8afda6a9310a 100644 --- a/services/common/test/unittest/utils/dscreen_maprelation_test.cpp +++ b/services/common/test/unittest/utils/dscreen_maprelation_test.cpp @@ -93,5 +93,55 @@ HWTEST_F(DScreenMapRelationTest, GetScreenRect_001, TestSize.Level1) ScreenRect actual = dscreenMapRelation->GetScreenRect(); EXPECT_EQ(startX, actual.startX); } + +/** + * @tc.name: to_json_001 + * @tc.desc: Verify the to_json function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenMapRelationTest, to_json_001, TestSize.Level1) +{ + json j; + uint64_t displayId = 1; + uint64_t screenId = 2; + DisplayRect displayRect = {0, 0, 100, 100}; + ScreenRect screenRect = {0, 0, 200, 200}; + DScreenMapRelation dScreenMapRelation; + dScreenMapRelation.SetDisplayId(displayId); + dScreenMapRelation.SetScreenId(screenId); + dScreenMapRelation.SetDisplayRect(displayRect); + dScreenMapRelation.SetScreenRect(screenRect); + to_json(j, dScreenMapRelation); + + uint64_t jsonDisplayId = 0; + j.at(KEY_DISPLAY_ID).get_to(jsonDisplayId); + EXPECT_EQ(displayId, jsonDisplayId); +} + +/** + * @tc.name: from_json_001 + * @tc.desc: Verify the from_json function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(DScreenMapRelationTest, from_json_001, TestSize.Level1) +{ + json j; + uint64_t displayId = 1; + uint64_t screenId = 2; + DisplayRect displayRect = {0, 0, 100, 100}; + ScreenRect screenRect = {0, 0, 200, 200}; + DScreenMapRelation dScreenMapRelation; + dScreenMapRelation.SetDisplayId(displayId); + dScreenMapRelation.SetScreenId(screenId); + dScreenMapRelation.SetDisplayRect(displayRect); + dScreenMapRelation.SetScreenRect(screenRect); + to_json(j, dScreenMapRelation); + + DScreenMapRelation jsonDScreenMapRelation; + from_json(j, jsonDScreenMapRelation); + EXPECT_EQ(displayId, jsonDScreenMapRelation.GetDisplayId()); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/common/test/unittest/utils/video_param_test.cpp b/services/common/test/unittest/utils/video_param_test.cpp index 23bd135787eb17c316ad438b5c2495f97c8d9a21..2d15f4582536ce0eb267751fdc7a278c81ac32a6 100644 --- a/services/common/test/unittest/utils/video_param_test.cpp +++ b/services/common/test/unittest/utils/video_param_test.cpp @@ -131,5 +131,68 @@ HWTEST_F(VideoParamTest, GetVideoFormat_001, TestSize.Level1) uint8_t actual = videoParam_->GetVideoFormat(); EXPECT_EQ(videoFormat, actual); } + +/** + * @tc.name: to_json_001 + * @tc.desc: Verify the to_json function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(VideoParamTest, to_json_001, TestSize.Level1) +{ + json j; + uint32_t screenWidth = 100; + uint32_t screenHeight = 100; + uint32_t videoWidth = 100; + uint32_t videoHeight = 100; + uint32_t fps = 30; + uint8_t codecType = DEFAULT_CODECTYPE; + uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; + + VideoParam videoParam; + videoParam.SetScreenWidth(screenWidth); + videoParam.SetScreenHeight(screenHeight); + videoParam.SetVideoWidth(videoWidth); + videoParam.SetVideoHeight(videoHeight); + videoParam.SetFps(fps); + videoParam.SetCodecType(codecType); + videoParam.SetVideoFormat(videoFormat); + to_json(j, videoParam); + + uint32_t jsonVideoWidth = 0; + j.at(KEY_VIDEO_WIDTH).get_to(jsonVideoWidth); + EXPECT_EQ(videoWidth, jsonVideoWidth); +} + +/** + * @tc.name: from_json_001 + * @tc.desc: Verify the from_json function. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(VideoParamTest, from_json_001, TestSize.Level1) +{ + json j; + uint32_t screenWidth = 100; + uint32_t screenHeight = 100; + uint32_t videoWidth = 100; + uint32_t videoHeight = 100; + uint32_t fps = 30; + uint8_t codecType = DEFAULT_CODECTYPE; + uint8_t videoFormat = DEFAULT_VIDEO_FORMAT; + + VideoParam videoParam; + videoParam.SetScreenWidth(screenWidth); + videoParam.SetScreenHeight(screenHeight); + videoParam.SetVideoWidth(videoWidth); + videoParam.SetVideoHeight(videoHeight); + videoParam.SetFps(fps); + videoParam.SetCodecType(codecType); + videoParam.SetVideoFormat(videoFormat); + to_json(j, videoParam); + VideoParam jsonVideoParam; + from_json(j, jsonVideoParam); + EXPECT_EQ(videoWidth, jsonVideoParam.GetVideoWidth()); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn index 2abb51cbd24a44a444711c4646abb6a1c9a0f8fb..58b72f968248ad2b14469dcbaf9c9e5b83930f6a 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/BUILD.gn @@ -53,8 +53,8 @@ config("module_private_config") { ] } -## UnitTest DscreenSinkServiceTest -ohos_unittest("DscreenSinkServiceTest") { +## UnitTest DscreenRegionMgrTest +ohos_unittest("DscreenRegionMgrTest") { module_out_path = module_out_path sources = [ diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp index af269be8754d077238f6eac9d2a6c1375db6942f..5fd622c9ba34739c5f4338853880cebfee130138 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/src/screenregionmgr_test.cpp @@ -67,6 +67,27 @@ HWTEST_F(ScreenRegionManagerTest, NotifyRemoteScreenService_001, TestSize.Level1 EXPECT_EQ(ERR_DH_SCREEN_SA_GET_REMOTE_SOURCE_SERVICE_FAIL, ret); } +/** + * @tc.name: HandleNotifySetUp_001 + * @tc.desc: Verify the HandleNotifySetUp function failed. + * @tc.type: FUNC + * @tc.require: Issue Number + */ +HWTEST_F(ScreenRegionManagerTest, HandleNotifySetUp_001, TestSize.Level1) +{ + ScreenRegionManager::GetInstance().screenRegions_.clear(); + const std::string remoteDevId = "sourceDevId"; + const std::string eventContent = "{\"dhId\":\"SCREEN#0\",\"mapRelation\":{\"displayId\":0,\ + \"displayRect\":{\"height\":1280,\"startX\":0,\"startY\":0,\"width\":720},\"screenId\":2,\ + \"screenRect\":{\"height\":1280,\"startX\":0,\"startY\":0,\"width\":720}},\"screenId\":2,\ + \"videoParam\":{\"codecType\":2,\"colorFormat\":3,\"fps\":30,\"screenHeight\":1280,\ + \"screenWidth\":720,\"videoHeight\":1280,\"videoWidth\":720}}"; + ScreenRegionManager::GetInstance().HandleNotifySetUp(remoteDevId, eventContent); + + EXPECT_NE(0, ScreenRegionManager::GetInstance().screenRegions_.size()); + ScreenRegionManager::GetInstance().screenRegions_.clear(); +} + /** * @tc.name: GetDScreenSourceSA_001 * @tc.desc: Verify the GetDScreenSourceSA function failed.