From cfbb256f3deccf116eb7ea27dbe17523407a0723 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9C=89=E5=BA=B7?= Date: Wed, 22 Jan 2025 16:12:09 +0800 Subject: [PATCH] =?UTF-8?q?TDD=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张有康 --- .../dms_unittest/screen_scene_config_test.cpp | 2 +- .../screen_session_manager_proxy_test.cpp | 128 +++++------------- ...screen_snapshot_picker_connection_test.cpp | 3 +- .../session_display_power_controller_test.cpp | 8 +- 4 files changed, 40 insertions(+), 101 deletions(-) diff --git a/window_scene/test/dms_unittest/screen_scene_config_test.cpp b/window_scene/test/dms_unittest/screen_scene_config_test.cpp index e7d8657f59..57ec2d1491 100644 --- a/window_scene/test/dms_unittest/screen_scene_config_test.cpp +++ b/window_scene/test/dms_unittest/screen_scene_config_test.cpp @@ -684,7 +684,7 @@ HWTEST_F(ScreenSceneConfigTest, GetCurvedCompressionAreaInLandscape03, Function HWTEST_F(ScreenSceneConfigTest, ReadStringListConfigInfo01, Function | SmallTest | Level3) { xmlNodePtr rootNode = nullptr; - ScreenSceneConfig::ReadStringListConfigInfo(nullptr, ""); + ScreenSceneConfig::ReadStringListConfigInfo(rootNode, ""); EXPECT_EQ(rootNode, nullptr); } diff --git a/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp b/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp index a66c72f21e..753136bd9d 100644 --- a/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_manager_proxy_test.cpp @@ -27,6 +27,7 @@ #include "display_manager_adapter.h" #include "display_manager_agent_default.h" #include "scene_board_judgement.h" +#include "screen_session_manager/include/screen_session_manager.h" using namespace testing; using namespace testing::ext; @@ -1179,16 +1180,10 @@ HWTEST_F(ScreenSessionManagerProxyTest, RemoveVirtualScreenFromGroup, Function | sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - - int resultValue = 0; std::vector screens = {1002, 1003, 1004}; - std::function func = [&]() - { - screenSessionManagerProxy->RemoveVirtualScreenFromGroup(screens); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->RemoveVirtualScreenFromGroup(screens); + auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(2000); + EXPECT_EQ(screenSession, nullptr); } /** @@ -1594,16 +1589,10 @@ HWTEST_F(ScreenSessionManagerProxyTest, ConvertScreenIdToRsScreenId, Function | sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - int resultValue = 0; ScreenId screenId = 1001; ScreenId rsScreenId = 1002; - std::function func = [&]() - { - screenSessionManagerProxy->ConvertScreenIdToRsScreenId(screenId, rsScreenId); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + auto ret = screenSessionManagerProxy->ConvertScreenIdToRsScreenId(screenId, rsScreenId); + EXPECT_EQ(ret, false); } /** @@ -1639,15 +1628,9 @@ HWTEST_F(ScreenSessionManagerProxyTest, DumpAllScreensInfo, Function | SmallTest sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - int resultValue = 0; std::string dumpInfo; - std::function func = [&]() - { - screenSessionManagerProxy->DumpAllScreensInfo(dumpInfo); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->DumpAllScreensInfo(dumpInfo); + EXPECT_NE(dumpInfo, ""); } /** @@ -1661,16 +1644,10 @@ HWTEST_F(ScreenSessionManagerProxyTest, DumpSpecialScreenInfo, Function | SmallT sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - int resultValue = 0; ScreenId id = 1001; std::string dumpInfo; - std::function func = [&]() - { - screenSessionManagerProxy->DumpSpecialScreenInfo(id, dumpInfo); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->DumpSpecialScreenInfo(id, dumpInfo); + EXPECT_NE(dumpInfo, ""); } /** @@ -1684,15 +1661,13 @@ HWTEST_F(ScreenSessionManagerProxyTest, SetFoldDisplayMode, Function | SmallTest sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - int resultValue = 0; const FoldDisplayMode displayMode {0}; - std::function func = [&]() - { - screenSessionManagerProxy->SetFoldDisplayMode(displayMode); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->SetFoldDisplayMode(displayMode); + if (screenSessionManagerProxy->IsFoldable()) { + EXPECT_NE(ScreenSessionManager::GetInstance().foldScreenController_, nullptr); + } else { + EXPECT_EQ(ScreenSessionManager::GetInstance().foldScreenController_, nullptr); + } } /** @@ -1728,15 +1703,13 @@ HWTEST_F(ScreenSessionManagerProxyTest, SetFoldStatusLocked, Function | SmallTes sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - int resultValue = 0; bool locked = true; - std::function func = [&]() - { - screenSessionManagerProxy->SetFoldStatusLocked(locked); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->SetFoldStatusLocked(locked); + if (screenSessionManagerProxy->IsFoldable()) { + EXPECT_NE(ScreenSessionManager::GetInstance().foldScreenController_, nullptr); + } else { + EXPECT_EQ(ScreenSessionManager::GetInstance().foldScreenController_, nullptr); + } } /** @@ -1786,15 +1759,9 @@ HWTEST_F(ScreenSessionManagerProxyTest, IsFoldable, Function | SmallTest | Level SingletonContainer::Get().InitDMSProxy(); sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - - int resultValue = 0; - std::function func = [&]() - { - screenSessionManagerProxy->IsFoldable(); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->IsFoldable(); + auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(2000); + EXPECT_EQ(screenSession, nullptr); } /** @@ -1807,15 +1774,8 @@ HWTEST_F(ScreenSessionManagerProxyTest, IsCaptured, Function | SmallTest | Level SingletonContainer::Get().InitDMSProxy(); sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - - int resultValue = 0; - std::function func = [&]() - { - screenSessionManagerProxy->IsCaptured(); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + auto ret = screenSessionManagerProxy->IsCaptured(); + EXPECT_EQ(ret, false); } /** @@ -1895,15 +1855,9 @@ HWTEST_F(ScreenSessionManagerProxyTest, SetClient, Function | SmallTest | Level1 sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - int resultValue = 0; const sptr client = nullptr; - std::function func = [&]() - { - screenSessionManagerProxy->SetClient(client); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->SetClient(client); + EXPECT_EQ(client, nullptr); } /** @@ -1916,15 +1870,9 @@ HWTEST_F(ScreenSessionManagerProxyTest, SwitchUser, Function | SmallTest | Level SingletonContainer::Get().InitDMSProxy(); sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - - int resultValue = 0; - std::function func = [&]() - { - screenSessionManagerProxy->SwitchUser(); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->SwitchUser(); + auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(2000); + EXPECT_EQ(screenSession, nullptr); } /** @@ -1937,16 +1885,10 @@ HWTEST_F(ScreenSessionManagerProxyTest, GetScreenProperty, Function | SmallTest SingletonContainer::Get().InitDMSProxy(); sptr impl = SingletonContainer::Get().displayManagerServiceProxy_->AsObject(); sptr screenSessionManagerProxy = new ScreenSessionManagerProxy(impl); - - int resultValue = 0; ScreenId screenId = 1001; - std::function func = [&]() - { - screenSessionManagerProxy->GetScreenProperty(screenId); - resultValue = 1; - }; - func(); - EXPECT_EQ(resultValue, 1); + screenSessionManagerProxy->GetScreenProperty(screenId); + auto screenSession = ScreenSessionManager::GetInstance().GetScreenSession(2000); + EXPECT_EQ(screenSession, nullptr); } /** diff --git a/window_scene/test/dms_unittest/screen_snapshot_picker_connection_test.cpp b/window_scene/test/dms_unittest/screen_snapshot_picker_connection_test.cpp index e94ffc1b0a..084ba5225c 100644 --- a/window_scene/test/dms_unittest/screen_snapshot_picker_connection_test.cpp +++ b/window_scene/test/dms_unittest/screen_snapshot_picker_connection_test.cpp @@ -215,9 +215,8 @@ HWTEST_F(ScreenSnapshotPickerConnectionTest, GetScreenSnapshotInfo03, Function | */ HWTEST_F(ScreenSnapshotPickerConnectionTest, SnapshotPickerDisconnectExtension01, Function | SmallTest | Level1) { - std::unique_ptr abilityConnection_ = nullptr; ScreenSnapshotPickerConnection::GetInstance().SnapshotPickerDisconnectExtension(); - EXPECT_EQ(abilityConnection_, nullptr); + EXPECT_EQ(ScreenSnapshotPickerConnection::GetInstance().abilityConnection_, nullptr); } /** diff --git a/window_scene/test/dms_unittest/session_display_power_controller_test.cpp b/window_scene/test/dms_unittest/session_display_power_controller_test.cpp index 911b66bd79..68bda56914 100644 --- a/window_scene/test/dms_unittest/session_display_power_controller_test.cpp +++ b/window_scene/test/dms_unittest/session_display_power_controller_test.cpp @@ -22,6 +22,7 @@ #include "session_manager.h" #include "session_display_power_controller.h" #include "zidl/window_manager_agent_interface.h" +#include "screen_session_manager/include/screen_session_manager.h" using namespace testing; using namespace testing::ext; @@ -166,11 +167,8 @@ HWTEST_F(SessionDisplayPowerControllerTest, SuspendBegin, Function | SmallTest | HWTEST_F(SessionDisplayPowerControllerTest, WaitScreenOffNotify, Function | SmallTest | Level1) { DisplayState state = DisplayState::ON_SUSPEND; - SessionDisplayPowerController controller([](DisplayId id, sptr info, const std::map>& infos, DisplayStateChangeType type) { - EXPECT_TRUE(true); - }); - EXPECT_EQ(state, DisplayState::ON_SUSPEND); + ScreenSessionManager::GetInstance().sessionDisplayPowerController_->WaitScreenOffNotify(state); + EXPECT_NE(state, DisplayState::UNKNOWN); } }