From 76b4f9b2f2680716ef96eec7b8359ec618511d26 Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Tue, 10 Sep 2024 20:35:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=B1=E8=B4=A5=E7=9A=84UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 --- .../unittest/include/screen_client_test.h | 4 +- .../screen_client_window_adapter_test.h | 4 +- .../test/unittest/src/screen_client_test.cpp | 39 ++++++++++--------- .../src/screen_client_window_adapter_test.cpp | 33 +++++++++------- .../1.0/src/screenregion_test.cpp | 4 ++ .../1.0/src/screenregionmgr_test.cpp | 6 ++- .../2.0/src/screenregion_test.cpp | 19 ++++++++- 7 files changed, 71 insertions(+), 38 deletions(-) diff --git a/services/screenclient/test/unittest/include/screen_client_test.h b/services/screenclient/test/unittest/include/screen_client_test.h index 465c22db..1f21e185 100644 --- a/services/screenclient/test/unittest/include/screen_client_test.h +++ b/services/screenclient/test/unittest/include/screen_client_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -31,6 +31,8 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + + std::shared_ptr windowProperty_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/screenclient/test/unittest/include/screen_client_window_adapter_test.h b/services/screenclient/test/unittest/include/screen_client_window_adapter_test.h index db0bcc01..a4cfd2cf 100644 --- a/services/screenclient/test/unittest/include/screen_client_window_adapter_test.h +++ b/services/screenclient/test/unittest/include/screen_client_window_adapter_test.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Huawei Device Co., Ltd. + * Copyright (c) 2022-2024 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 @@ -36,6 +36,8 @@ public: static void TearDownTestCase(void); void SetUp(); void TearDown(); + + std::shared_ptr windowProperty_; }; } // namespace DistributedHardware } // namespace OHOS diff --git a/services/screenclient/test/unittest/src/screen_client_test.cpp b/services/screenclient/test/unittest/src/screen_client_test.cpp index a6903ff6..0585e0a0 100644 --- a/services/screenclient/test/unittest/src/screen_client_test.cpp +++ b/services/screenclient/test/unittest/src/screen_client_test.cpp @@ -19,13 +19,23 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { +constexpr static uint32_t VIDEO_DATA_NUM = 480; + void ScreenClientTest::SetUpTestCase(void) {} void ScreenClientTest::TearDownTestCase(void) {} -void ScreenClientTest::SetUp() {} +void ScreenClientTest::SetUp() +{ + windowProperty_ = std::make_shared(); + windowProperty_->width = VIDEO_DATA_NUM; + windowProperty_->height = VIDEO_DATA_NUM; +} -void ScreenClientTest::TearDown() {} +void ScreenClientTest::TearDown() +{ + windowProperty_ = nullptr; +} /** * @tc.name: AddWindow_001 @@ -35,8 +45,8 @@ void ScreenClientTest::TearDown() {} */ HWTEST_F(ScreenClientTest, AddWindow_001, TestSize.Level1) { - std::shared_ptr windowProperty = nullptr; - int32_t ret = ScreenClient::GetInstance().AddWindow(windowProperty); + windowProperty_ = nullptr; + int32_t ret = ScreenClient::GetInstance().AddWindow(windowProperty_); EXPECT_EQ(ERR_DH_SCREEN_SCREENCLIENT_ADD_WINDOW_ERROR, ret); } @@ -48,8 +58,7 @@ HWTEST_F(ScreenClientTest, AddWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientTest, AddWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); - int32_t expectId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t expectId = ScreenClient::GetInstance().AddWindow(windowProperty_); int32_t ret = ScreenClient::GetInstance().RemoveWindow(expectId); EXPECT_EQ(DH_SUCCESS, ret); } @@ -74,8 +83,7 @@ HWTEST_F(ScreenClientTest, ShowWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientTest, ShowWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); - int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_); int32_t ret = ScreenClient::GetInstance().ShowWindow(windowId); EXPECT_EQ(DH_SUCCESS, ret); ret = ScreenClient::GetInstance().RemoveWindow(windowId); @@ -118,8 +126,7 @@ HWTEST_F(ScreenClientTest, HideWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientTest, HideWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); - int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_); int32_t ret = ScreenClient::GetInstance().HideWindow(windowId); EXPECT_EQ(DH_SUCCESS, ret); ret = ScreenClient::GetInstance().RemoveWindow(windowId); @@ -162,8 +169,7 @@ HWTEST_F(ScreenClientTest, MoveWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientTest, MoveWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); - int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_); int32_t ret = ScreenClient::GetInstance().MoveWindow(windowId, 0, 0); EXPECT_EQ(DH_SUCCESS, ret); ret = ScreenClient::GetInstance().RemoveWindow(windowId); @@ -206,8 +212,7 @@ HWTEST_F(ScreenClientTest, RemoveWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientTest, RemoveWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); - int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_); int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId); EXPECT_EQ(DH_SUCCESS, ret); } @@ -245,8 +250,7 @@ HWTEST_F(ScreenClientTest, GetSurface_001, TestSize.Level1) */ HWTEST_F(ScreenClientTest, GetSurface_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); - int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty); + int32_t windowId = ScreenClient::GetInstance().AddWindow(windowProperty_); sptr actualSurface = ScreenClient::GetInstance().GetSurface(windowId); EXPECT_NE(nullptr, actualSurface); int32_t ret = ScreenClient::GetInstance().RemoveWindow(windowId); @@ -261,8 +265,7 @@ HWTEST_F(ScreenClientTest, GetSurface_002, TestSize.Level1) */ HWTEST_F(ScreenClientTest, DestroyAllWindow_001, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); - ScreenClient::GetInstance().AddWindow(windowProperty); + ScreenClient::GetInstance().AddWindow(windowProperty_); int32_t ret = ScreenClient::GetInstance().DestroyAllWindow(); EXPECT_EQ(DH_SUCCESS, ret); } diff --git a/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp b/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp index e1358778..d777533f 100644 --- a/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp +++ b/services/screenclient/test/unittest/src/screen_client_window_adapter_test.cpp @@ -19,13 +19,23 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { +constexpr static uint32_t VIDEO_DATA_NUM = 480; + void ScreenClientWindowAdapterTest::SetUpTestCase(void) {} void ScreenClientWindowAdapterTest::TearDownTestCase(void) {} -void ScreenClientWindowAdapterTest::SetUp() {} +void ScreenClientWindowAdapterTest::SetUp() +{ + windowProperty_ = std::make_shared(); + windowProperty_->width = VIDEO_DATA_NUM; + windowProperty_->height = VIDEO_DATA_NUM; +} -void ScreenClientWindowAdapterTest::TearDown() {} +void ScreenClientWindowAdapterTest::TearDown() +{ + windowProperty_ = nullptr; +} /** * @tc.name: CreateWindow_001 @@ -35,8 +45,8 @@ void ScreenClientWindowAdapterTest::TearDown() {} */ HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_001, TestSize.Level1) { - std::shared_ptr windowProperty = nullptr; - EXPECT_EQ(nullptr, ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, 0)); + windowProperty_ = nullptr; + EXPECT_EQ(nullptr, ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty_, 0)); } /** @@ -47,9 +57,8 @@ HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientWindowAdapterTest, CreateWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); int32_t windowId = 0; - sptr actualSurface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + sptr actualSurface = ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty_, windowId); EXPECT_NE(nullptr, actualSurface); int32_t ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); EXPECT_EQ(DH_SUCCESS, ret); @@ -75,9 +84,8 @@ HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientWindowAdapterTest, ShowWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); int32_t windowId = 100; - ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty_, windowId); int32_t ret = ScreenClientWindowAdapter::GetInstance().ShowWindow(windowId); EXPECT_EQ(DH_SUCCESS, ret); ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); @@ -119,9 +127,8 @@ HWTEST_F(ScreenClientWindowAdapterTest, HideWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientWindowAdapterTest, HideWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); int32_t windowId = 0; - ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty_, windowId); int32_t ret = ScreenClientWindowAdapter::GetInstance().HideWindow(windowId); EXPECT_EQ(DH_SUCCESS, ret); ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); @@ -164,9 +171,8 @@ HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientWindowAdapterTest, MoveWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); int32_t windowId = 0; - ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty_, windowId); int32_t ret = ScreenClientWindowAdapter::GetInstance().MoveWindow(windowId, 0, 0); EXPECT_EQ(DH_SUCCESS, ret); ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); @@ -209,9 +215,8 @@ HWTEST_F(ScreenClientWindowAdapterTest, RemoveWindow_001, TestSize.Level1) */ HWTEST_F(ScreenClientWindowAdapterTest, RemoveWindow_002, TestSize.Level1) { - std::shared_ptr windowProperty = std::make_shared(); int32_t windowId = 0; - ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty, windowId); + ScreenClientWindowAdapter::GetInstance().CreateWindow(windowProperty_, windowId); int32_t ret = ScreenClientWindowAdapter::GetInstance().RemoveWindow(windowId); EXPECT_EQ(DH_SUCCESS, ret); } diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp index 1d22cc31..79008887 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregion_test.cpp @@ -22,6 +22,8 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { namespace V1_0 { +constexpr static uint32_t VIDEO_DATA_NUM = 480; + void ScreenRegionTestV1::SetUpTestCase(void) {} void ScreenRegionTestV1::TearDownTestCase(void) {} @@ -137,6 +139,8 @@ HWTEST_F(ScreenRegionTestV1, GetVideoParam_001, TestSize.Level1) HWTEST_F(ScreenRegionTestV1, GetWindowProperty_001, TestSize.Level1) { screenRegion_->windowProperty_ = std::make_shared(); + screenRegion_->windowProperty_->width = VIDEO_DATA_NUM; + screenRegion_->windowProperty_->height = VIDEO_DATA_NUM; std::shared_ptr ret = screenRegion_->GetWindowProperty(); EXPECT_EQ(screenRegion_->windowProperty_, ret); } diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp index 2a2ff601..a42c723f 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/1.0/src/screenregionmgr_test.cpp @@ -21,6 +21,8 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { namespace V1_0 { +constexpr static uint32_t VIDEO_DATA_NUM = 480; + void ScreenRegionManagerTestV1::SetUpTestCase(void) {} void ScreenRegionManagerTestV1::TearDownTestCase(void) {} @@ -99,8 +101,8 @@ HWTEST_F(ScreenRegionManagerTestV1, ReleaseAllRegions_003, TestSize.Level1) std::shared_ptr windowProperty = std::make_shared(); windowProperty->startX = 0; windowProperty->startY = 0; - windowProperty->width = 100; - windowProperty->height = 100; + windowProperty->width = VIDEO_DATA_NUM; + windowProperty->height = VIDEO_DATA_NUM; ScreenRegionManager::GetInstance().PublishMessage(topic, screenId, remoteDevId, windowId, windowProperty); int32_t ret = ScreenRegionManager::GetInstance().ReleaseAllRegions(); diff --git a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp index e17ecea0..97701531 100644 --- a/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp +++ b/services/screenservice/test/unittest/sinkservice/screenregionmgr/2.0/src/screenregion_test.cpp @@ -25,6 +25,8 @@ using namespace testing::ext; namespace OHOS { namespace DistributedHardware { namespace V2_0 { +constexpr static uint32_t VIDEO_DATA_NUM = 480; + void ScreenRegionTestV2::SetUpTestCase(void) {} void ScreenRegionTestV2::TearDownTestCase(void) {} @@ -329,7 +331,13 @@ HWTEST_F(ScreenRegionTestV2, SetUp_001, TestSize.Level1) content = contentJson.dump(); EXPECT_EQ(ERR_DH_SCREEN_INPUT_PARAM_INVALID, screenRegion_->SetUp(content)); + ScreenRect screenRect; + screenRect.startX = 0; + screenRect.startY = 0; + screenRect.width = VIDEO_DATA_NUM; + screenRect.height = VIDEO_DATA_NUM; DScreenMapRelation dScreenMapRelation; + dScreenMapRelation.SetScreenRect(screenRect); contentJson[KEY_MAPRELATION] = dScreenMapRelation; content = contentJson.dump(); screenRegion_->receiverAdapter_ = nullptr; @@ -337,6 +345,7 @@ HWTEST_F(ScreenRegionTestV2, SetUp_001, TestSize.Level1) screenRegion_->receiverAdapter_ = std::make_shared(); EXPECT_EQ(DH_SUCCESS, screenRegion_->SetUp(content)); + screenRegion_->Release(); } /** @@ -359,10 +368,16 @@ HWTEST_F(ScreenRegionTestV2, ConfigWindow_001, TestSize.Level1) */ HWTEST_F(ScreenRegionTestV2, ConfigWindow_002, TestSize.Level1) { + ScreenRect screenRect; + screenRect.startX = 0; + screenRect.startY = 0; + screenRect.width = VIDEO_DATA_NUM; + screenRect.height = VIDEO_DATA_NUM; + DScreenMapRelation dScreenMapRelation; screenRegion_->mapRelation_ = std::make_shared(); - std::shared_ptr windowProperty = std::make_shared(); - ScreenClient::GetInstance().AddWindow(windowProperty); + screenRegion_->mapRelation_->SetScreenRect(screenRect); EXPECT_EQ(DH_SUCCESS, screenRegion_->ConfigWindow()); + screenRegion_->Release(); } /** -- Gitee