From ed38e8a3851c0c58e583a96b6e5c7f85aa05ed24 Mon Sep 17 00:00:00 2001 From: shuangshuangliu Date: Thu, 21 Aug 2025 15:25:20 +0800 Subject: [PATCH] =?UTF-8?q?TDD=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shuangshuangliu Change-Id: Iea3a5f53069c6d895edcf988200af9959228067f --- wm/test/unittest/BUILD.gn | 11 + wm/test/unittest/root_scene_new_test.cpp | 726 +++++++++++++++++++++++ 2 files changed, 737 insertions(+) create mode 100644 wm/test/unittest/root_scene_new_test.cpp diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn index 6a9fca35b8..459cddaf38 100644 --- a/wm/test/unittest/BUILD.gn +++ b/wm/test/unittest/BUILD.gn @@ -31,6 +31,7 @@ group("unittest") { ":wm_picture_in_picture_controller_test", ":wm_picture_in_picture_manager_test", ":wm_picture_in_picture_option_test", + ":wm_root_scene_new_test", ":wm_root_scene_test", ":wm_screen_scene_test", ":wm_vsync_station_test", @@ -531,6 +532,16 @@ ohos_unittest("wm_root_scene_test") { external_deps = test_external_deps } +ohos_unittest("wm_root_scene_new_test") { + module_out_path = module_out_path + + sources = [ "root_scene_new_test.cpp" ] + + deps = [ ":wm_unittest_common" ] + + external_deps = test_external_deps +} + ohos_unittest("wm_screen_scene_test") { module_out_path = module_out_path diff --git a/wm/test/unittest/root_scene_new_test.cpp b/wm/test/unittest/root_scene_new_test.cpp new file mode 100644 index 0000000000..1c8678f4b4 --- /dev/null +++ b/wm/test/unittest/root_scene_new_test.cpp @@ -0,0 +1,726 @@ +/* + * 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 +#include +#include +#include +#include "mock_uicontent.h" +#include +#include "root_scene.h" +#include "screen_scene.h" + +#include "app_mgr_client.h" +#include "mock_uicontent.h" +#include "singleton.h" +#include "singleton_container.h" + +#include "vsync_station.h" +#include "window_manager_hilog.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +const uint32_t MOCK_LEM_SUB_WIDTH = 340; +const uint32_t MOCK_LEM_SUB_HEIGHT = 340; +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } +} +class RootSceneNewTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + +private: + static constexpr uint32_t WAIT_SYNC_IN_NS = 200000; +}; + +void RootSceneNewTest::SetUpTestCase() {} + +void RootSceneNewTest::TearDownTestCase() {} + +void RootSceneNewTest::SetUp() {} + +void RootSceneNewTest::TearDown() +{ + usleep(WAIT_SYNC_IN_NS); +} + +namespace { +/** + * @tc.name: LoadContent01 + * @tc.desc: context is nullptr + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, LoadContent01, TestSize.Level1) +{ + RootScene rootScene; + rootScene.LoadContent("a", nullptr, nullptr, nullptr); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: UpdateViewportConfig01 + * @tc.desc: UpdateViewportConfig Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UpdateViewportConfig01, TestSize.Level1) +{ + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); + RootScene rootScene; + Rect rect; + + rootScene.uiContent_ = nullptr; + rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED); + EXPECT_FALSE(g_errLog.find("uiContent_ is nullptr!") != std::string::npos); + + rootScene.uiContent_ = std::make_unique(); + rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED); + + rect.width_ = MOCK_LEM_SUB_WIDTH; + rect.height_ = MOCK_LEM_SUB_HEIGHT; + rootScene.UpdateViewportConfig(rect, WindowSizeChangeReason::UNDEFINED); + EXPECT_EQ(1, rootScene.GetWindowId()); + LOG_SetCallback(nullptr); +} + +/** + * @tc.name: UpdateConfiguration + * @tc.desc: UpdateConfiguration Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UpdateConfiguration, TestSize.Level1) +{ + RootScene rootScene; + sptr staticRootScene = sptr::MakeSptr(); + wptr weakWindow(staticRootScene); + rootScene.AddRootScene(DEFAULT_DISPLAY_ID, weakWindow); + rootScene.AddRootScene(100, nullptr); + + std::shared_ptr configuration = std::make_shared(); + rootScene.uiContent_ = nullptr; + rootScene.UpdateConfiguration(configuration); + + rootScene.uiContent_ = std::make_unique(); + rootScene.UpdateConfiguration(configuration); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: UpdateConfigurationForSpecified + * @tc.desc: UpdateConfigurationForSpecified Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UpdateConfigurationForSpecified, TestSize.Level1) +{ + RootScene rootScene; + std::shared_ptr configuration; + std::shared_ptr resourceManager; + + rootScene.uiContent_ = std::make_unique(); + rootScene.UpdateConfigurationForSpecified(configuration, resourceManager); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: UpdateConfigurationForAll + * @tc.desc: UpdateConfigurationForAll Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UpdateConfigurationForAll, TestSize.Level1) +{ + RootScene rootScene; + std::shared_ptr configuration = std::make_shared(); + + auto prevStaticRootScene = RootScene::staticRootScene_; + rootScene.UpdateConfigurationForAll(configuration); + + sptr staticRootScene = sptr::MakeSptr(); + RootScene::staticRootScene_ = staticRootScene; + rootScene.UpdateConfigurationForAll(configuration); + + RootScene::staticRootScene_ = prevStaticRootScene; + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: RegisterInputEventListener01 + * @tc.desc: RegisterInputEventListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RegisterInputEventListener01, TestSize.Level1) +{ + sptr rootScene = sptr::MakeSptr(); + rootScene->RegisterInputEventListener(); + EXPECT_EQ(1, rootScene->GetWindowId()); +} + +/** + * @tc.name: RequestVsyncErr + * @tc.desc: RequestVsync Test Err + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RequestVsyncErr, TestSize.Level1) +{ + RootScene rootScene; + std::shared_ptr vsyncCallback = std::make_shared(); + rootScene.RequestVsync(vsyncCallback); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: GetVSyncPeriod + * @tc.desc: GetVSyncPeriod Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, GetVSyncPeriod, TestSize.Level1) +{ + RootScene rootScene; + rootScene.GetVSyncPeriod(); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: FlushFrameRate + * @tc.desc: FlushFrameRate Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, FlushFrameRate, TestSize.Level1) +{ + RootScene rootScene; + uint32_t rate = 120; + int32_t animatorExpectedFrameRate = -1; + rootScene.FlushFrameRate(rate, animatorExpectedFrameRate); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: SetFrameLayoutFinishCallback + * @tc.desc: SetFrameLayoutFinishCallback Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, SetFrameLayoutFinishCallback, TestSize.Level1) +{ + RootScene rootScene; + rootScene.SetFrameLayoutFinishCallback(nullptr); + ASSERT_EQ(rootScene.frameLayoutFinishCb_, nullptr); + + rootScene.uiContent_ = std::make_unique(); + rootScene.SetFrameLayoutFinishCallback(nullptr); + ASSERT_EQ(rootScene.frameLayoutFinishCb_, nullptr); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: SetUiDvsyncSwitch + * @tc.desc: SetUiDvsyncSwitch Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, SetUiDvsyncSwitchSucc, TestSize.Level1) +{ + RootScene rootScene; + rootScene.SetUiDvsyncSwitch(true); + rootScene.SetUiDvsyncSwitch(false); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: SetUiDvsyncSwitch + * @tc.desc: SetUiDvsyncSwitch Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, SetUiDvsyncSwitchErr, TestSize.Level1) +{ + RootScene rootScene; + rootScene.SetUiDvsyncSwitch(true); + rootScene.SetUiDvsyncSwitch(false); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: SetTouchEvent + * @tc.desc: SetTouchEvent Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, SetTouchEventSucc, TestSize.Level1) +{ + RootScene rootScene; + rootScene.SetTouchEvent(0); + rootScene.SetTouchEvent(1); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: SetTouchEvent + * @tc.desc: SetTouchEvent Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, SetTouchEventErr, TestSize.Level1) +{ + RootScene rootScene; + rootScene.SetTouchEvent(0); + rootScene.SetTouchEvent(1); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: IsLastFrameLayoutFinished + * @tc.desc: IsLastFrameLayoutFinished Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, IsLastFrameLayoutFinished, TestSize.Level1) +{ + RootScene rootScene; + auto ret = rootScene.IsLastFrameLayoutFinished(); + EXPECT_EQ(ret, true); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: OnFlushUIParams + * @tc.desc: OnFlushUIParams Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, OnFlushUIParams, TestSize.Level1) +{ + RootScene rootScene; + rootScene.OnFlushUIParams(); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: OnBundleUpdated + * @tc.desc: OnBundleUpdated Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, OnBundleUpdated, TestSize.Level1) +{ + RootScene rootScene; + std::string bundleName = "test"; + rootScene.OnBundleUpdated(bundleName); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: SetDisplayOrientation + * @tc.desc: SetDisplayOrientation Test01 + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, SetDisplayOrientationTest01, TestSize.Level1) +{ + RootScene rootScene; + int32_t orientation = 0; + rootScene.SetDisplayOrientation(orientation); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: SetDisplayOrientation + * @tc.desc: SetDisplayOrientation Test02 + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, SetDisplayOrientationTest02, TestSize.Level1) +{ + RootScene rootScene; + int32_t orientation = 100; + rootScene.SetDisplayOrientation(orientation); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: RegisterAvoidAreaChangeListener + * @tc.desc: RegisterAvoidAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RegisterAvoidAreaChangeListener001, TestSize.Level1) +{ + RootScene rootScene; + rootScene.updateRootSceneAvoidAreaCallback_ = [] {}; + sptr listener = sptr::MakeSptr(); + auto ret = rootScene.RegisterAvoidAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_OK, ret); +} + +/** + * @tc.name: RegisterAvoidAreaChangeListener + * @tc.desc: RegisterAvoidAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RegisterAvoidAreaChangeListener002, TestSize.Level1) +{ + RootScene rootScene; + rootScene.updateRootSceneAvoidAreaCallback_ = [] {}; + sptr listener = nullptr; + auto ret = rootScene.RegisterAvoidAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + +/** + * @tc.name: UnregisterAvoidAreaChangeListener + * @tc.desc: UnregisterAvoidAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UnregisterAvoidAreaChangeListener001, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = sptr::MakeSptr(); + auto ret = rootScene.UnregisterAvoidAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_OK, ret); +} + +/** + * @tc.name: UnregisterAvoidAreaChangeListener + * @tc.desc: UnregisterAvoidAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UnregisterAvoidAreaChangeListener002, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = nullptr; + auto ret = rootScene.UnregisterAvoidAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + +/** + * @tc.name: NotifyAvoidAreaChangeForRoot + * @tc.desc: NotifyAvoidAreaChangeForRoot Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, NotifyAvoidAreaChangeForRoot, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = sptr::MakeSptr(); + ASSERT_NE(nullptr, listener); + rootScene.avoidAreaChangeListeners_.insert(listener); + AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE; + AvoidArea avoidArea; + rootScene.NotifyAvoidAreaChangeForRoot(new AvoidArea(avoidArea), type); +} + +/** + * @tc.name: GetAvoidAreaByType + * @tc.desc: GetAvoidAreaByType Test err + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, GetAvoidAreaByType, TestSize.Level1) +{ + RootScene rootScene; + AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE; + AvoidArea avoidArea; + rootScene.getSessionAvoidAreaByTypeCallback_ = nullptr; + + auto ret = rootScene.GetAvoidAreaByType(type, avoidArea); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + +/** + * @tc.name: GetAvoidAreaByTypeTest + * @tc.desc: GetAvoidAreaByType Test err + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, GetAvoidAreaByTypeTest, TestSize.Level1) +{ + RootScene rootScene; + AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE; + AvoidArea avoidArea; + AvoidArea testAvoidArea; + testAvoidArea.topRect_ = {1, 1, 1, 1}; + GetSessionAvoidAreaByTypeCallback func = [testAvoidArea](AvoidAreaType type)->AvoidArea { + return testAvoidArea; + }; + rootScene.getSessionAvoidAreaByTypeCallback_ = func; + + auto ret = rootScene.GetAvoidAreaByType(type, avoidArea, Rect::EMPTY_RECT, 15); + EXPECT_EQ(WMError::WM_DO_NOTHING, ret); +} + +/** + * @tc.name: GetAvoidAreaByTypeTest001 + * @tc.desc: GetAvoidAreaByType Test err + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, GetAvoidAreaByTypeTest001, TestSize.Level1) +{ + RootScene rootScene; + AvoidAreaType type = AvoidAreaType::TYPE_SYSTEM_GESTURE; + AvoidArea avoidArea; + AvoidArea testAvoidArea; + testAvoidArea.topRect_ = {1, 1, 1, 1}; + GetSessionAvoidAreaByTypeCallback func = [testAvoidArea](AvoidAreaType type)->AvoidArea { + return testAvoidArea; + }; + rootScene.getSessionAvoidAreaByTypeCallback_ = func; + + constexpr int32_t API_VERSION_18 = 18; + auto ret = rootScene.GetAvoidAreaByType(type, avoidArea, Rect::EMPTY_RECT, API_VERSION_18); + EXPECT_EQ(WMError::WM_OK, ret); + EXPECT_EQ(avoidArea.topRect_, testAvoidArea.topRect_); +} + +/** + * @tc.name: UpdateConfigurationSync + * @tc.desc: UpdateConfigurationSync Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UpdateConfigurationSync, TestSize.Level1) +{ + RootScene rootScene; + sptr staticRootScene = sptr::MakeSptr(); + wptr weakWindow(staticRootScene); + rootScene.AddRootScene(DEFAULT_DISPLAY_ID, weakWindow); + rootScene.AddRootScene(100, nullptr); + std::shared_ptr configuration = std::make_shared(); + + rootScene.uiContent_ = nullptr; + rootScene.UpdateConfigurationSync(configuration); + rootScene.uiContent_ = std::make_unique(); + rootScene.UpdateConfigurationSync(configuration); + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: UpdateConfigurationSyncForAll + * @tc.desc: UpdateConfigurationSyncForAll Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UpdateConfigurationSyncForAll, TestSize.Level1) +{ + RootScene rootScene; + std::shared_ptr configuration = std::make_shared(); + + auto prevStaticRootScene = RootScene::staticRootScene_; + rootScene.UpdateConfigurationSyncForAll(configuration); + + sptr staticRootScene; + RootScene::staticRootScene_ = staticRootScene; + rootScene.UpdateConfigurationSyncForAll(configuration); + + RootScene::staticRootScene_ = prevStaticRootScene; + EXPECT_EQ(1, rootScene.GetWindowId()); +} + +/** + * @tc.name: IsSystemWindow + * @tc.desc: IsSystemWindow Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, IsSystemWindow, TestSize.Level1) +{ + RootScene rootScene; + bool res = rootScene.IsSystemWindow(); + EXPECT_EQ(true, res); +} + +/** + * @tc.name: IsAppWindow + * @tc.desc: IsAppWindow Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, IsAppWindow, TestSize.Level1) +{ + RootScene rootScene; + bool res = rootScene.IsAppWindow(); + EXPECT_EQ(false, res); +} + +/** + * @tc.name: RegisterOccupiedAreaChangeListener + * @tc.desc: RegisterOccupiedAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RegisterOccupiedAreaChangeListener, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = sptr::MakeSptr(); + auto ret = rootScene.RegisterOccupiedAreaChangeListener(listener); + ASSERT_EQ(WMError::WM_OK, ret); + listener = nullptr; + ret = rootScene.RegisterOccupiedAreaChangeListener(listener); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + +/** + * @tc.name: RegisterOccupiedAreaChangeListener + * @tc.desc: RegisterOccupiedAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RegisterOccupiedAreaChangeListener001, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = sptr::MakeSptr(); + auto ret = rootScene.RegisterOccupiedAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_OK, ret); +} + +/** + * @tc.name: RegisterOccupiedAreaChangeListener + * @tc.desc: RegisterOccupiedAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RegisterOccupiedAreaChangeListener002, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = nullptr; + auto ret = rootScene.RegisterOccupiedAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + +/** + * @tc.name: UnregisterOccupiedAreaChangeListener + * @tc.desc: UnregisterOccupiedAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UnregisterOccupiedAreaChangeListener001, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = sptr::MakeSptr(); + auto ret = rootScene.UnregisterOccupiedAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_OK, ret); +} + +/** + * @tc.name: UnregisterOccupiedAreaChangeListener + * @tc.desc: UnregisterOccupiedAreaChangeListener Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, UnregisterOccupiedAreaChangeListener002, TestSize.Level1) +{ + RootScene rootScene; + sptr listener = nullptr; + auto ret = rootScene.UnregisterOccupiedAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_ERROR_NULLPTR, ret); +} + +/** + * @tc.name: NotifyOccupiedAreaChangeForRoot + * @tc.desc: NotifyOccupiedAreaChangeForRoot Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, NotifyOccupiedAreaChangeForRoot, TestSize.Level1) +{ + auto rootScene = sptr::MakeSptr(); + sptr listener = sptr::MakeSptr(); + ASSERT_NE(nullptr, listener); + auto ret = rootScene->RegisterOccupiedAreaChangeListener(listener); + EXPECT_EQ(WMError::WM_OK, ret); + sptr info = nullptr; + rootScene->NotifyOccupiedAreaChangeForRoot(info); + info = sptr::MakeSptr(); + ASSERT_NE(nullptr, info); + rootScene->NotifyOccupiedAreaChangeForRoot(info); +} + +/** + * @tc.name: GetRSNodeByStringIDTest + * @tc.desc: For GetRSNodeByStringID Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, GetRSNodeByStringIDTest, TestSize.Level1) +{ + string stringId = "GetRSNodeByStringIDTest"; + sptr rootScene = sptr::MakeSptr(); + rootScene->uiContent_ = std::make_unique(); + rootScene->SetTopWindowBoundaryByID(stringId); + rootScene->OnBundleUpdated(stringId); + + auto res = rootScene->GetRSNodeByStringID(stringId); + EXPECT_EQ(res, nullptr); +} + +/** + * @tc.name: GetRSNodeByStringIDTest001 + * @tc.desc: For GetRSNodeByStringID Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, GetRSNodeByStringIDTest001, TestSize.Level1) +{ + string stringId = "GetRSNodeByStringIDTest"; + sptr rootScene = sptr::MakeSptr(); + rootScene->uiContent_ = nullptr; + rootScene->SetTopWindowBoundaryByID(stringId); + rootScene->OnBundleUpdated(stringId); + + auto res = rootScene->GetRSNodeByStringID(stringId); + EXPECT_EQ(res, nullptr); +} + +/** + * @tc.name: GetStatusBarHeight + * @tc.desc: GetStatusBarHeight test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, GetStatusBarHeight, TestSize.Level1) +{ + RootScene rootScene; + auto height = rootScene.GetStatusBarHeight(); + EXPECT_EQ(0, height); + rootScene.getStatusBarHeightCallback_ = []() -> uint32_t { return 100; }; + height = rootScene.GetStatusBarHeight(); + EXPECT_EQ(100, height); +} + +/** + * @tc.name: AddRootScene + * @tc.desc: For AddRootScene Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, AddRootScene, TestSize.Level1) +{ + sptr rootScene = sptr::MakeSptr(); + sptr screenScene = sptr::MakeSptr("AddRootScene"); + rootScene->uiContent_ = std::make_unique(); + wptr weakWindow(rootScene); + wptr weakWindow1(screenScene); + rootScene->AddRootScene(1, weakWindow); + rootScene->AddRootScene(12, weakWindow1); + + auto res = rootScene->GetUIContentByDisplayId(1); + EXPECT_EQ(res.second, true); + res = rootScene->GetUIContentByDisplayId(12); + EXPECT_EQ(res.second, true); +} + +/** + * @tc.name: RemoveRootScene + * @tc.desc: For RemoveRootScene Test + * @tc.type: FUNC + */ +HWTEST_F(RootSceneNewTest, RemoveRootScene, TestSize.Level1) +{ + sptr rootScene = sptr::MakeSptr(); + rootScene->uiContent_ = std::make_unique(); + wptr weakWindow(rootScene); + rootScene->AddRootScene(0, weakWindow); + + auto res = rootScene->GetUIContentByDisplayId(0); + EXPECT_EQ(res.second, true); + rootScene->RemoveRootScene(0); + res = rootScene->GetUIContentByDisplayId(0); + EXPECT_EQ(res.second, false); +} + +} // namespace +} // namespace Rosen +} // namespace OHOS \ No newline at end of file -- Gitee