From 3a0ea06eaaccbbdff18066a3b577fbce39bf6f6a Mon Sep 17 00:00:00 2001 From: qianlf Date: Wed, 12 Jan 2022 10:24:33 +0800 Subject: [PATCH] add window wm tests Signed-off-by: qianlf Change-Id: Ic4809bc4348ceca21ad3c176d8c9c5f4850bdc8a --- ohos.build | 1 + wm/BUILD.gn | 5 + wm/test/BUILD.gn | 20 + .../unittest => wm/test/systemtest}/BUILD.gn | 90 ++-- wm/test/systemtest/window_layout_test.cpp | 229 ++++++++++ .../systemtest/window_multi_ability_test.cpp | 153 +++++++ wm/test/systemtest/window_subwindow_test.cpp | 312 ++++++++++++++ wm/test/systemtest/window_test_utils.cpp | 107 +++++ wm/test/systemtest/window_test_utils.h | 52 +++ wm/test/unittest/BUILD.gn | 150 +++++++ .../unittest/input_transfer_station_test.cpp | 87 ++++ .../unittest/input_transfer_station_test.h | 37 ++ wm/test/unittest/mock_static_call.h | 33 ++ .../test/unittest}/mock_window_adapter.h | 12 +- .../test/unittest}/singleton_mocker.h | 6 +- wm/test/unittest/window_impl_test.cpp | 392 ++++++++++++++++++ .../test/unittest}/window_impl_test.h | 12 +- .../unittest/window_input_channel_test.cpp | 91 ++++ wm/test/unittest/window_input_channel_test.h | 36 ++ wm/test/unittest/window_option_test.cpp | 191 +++++++++ wm/test/unittest/window_option_test.h | 33 ++ wm/test/unittest/window_scene_test.cpp | 231 +++++++++++ .../test/unittest/window_scene_test.h | 80 ++-- wm/test/unittest/window_test.cpp | 138 ++++++ wm/test/unittest/window_test.h | 36 ++ wmtest/unittest/src/window_impl_test.cpp | 130 ------ 26 files changed, 2449 insertions(+), 215 deletions(-) create mode 100644 wm/test/BUILD.gn rename {wmtest/unittest => wm/test/systemtest}/BUILD.gn (41%) create mode 100644 wm/test/systemtest/window_layout_test.cpp create mode 100644 wm/test/systemtest/window_multi_ability_test.cpp create mode 100644 wm/test/systemtest/window_subwindow_test.cpp create mode 100644 wm/test/systemtest/window_test_utils.cpp create mode 100644 wm/test/systemtest/window_test_utils.h create mode 100644 wm/test/unittest/BUILD.gn create mode 100644 wm/test/unittest/input_transfer_station_test.cpp create mode 100644 wm/test/unittest/input_transfer_station_test.h create mode 100644 wm/test/unittest/mock_static_call.h rename {wmtest/unittest/include/mock => wm/test/unittest}/mock_window_adapter.h (64%) rename {wmtest/unittest/include/mock => wm/test/unittest}/singleton_mocker.h (87%) create mode 100644 wm/test/unittest/window_impl_test.cpp rename {wmtest/unittest/include => wm/test/unittest}/window_impl_test.h (69%) create mode 100644 wm/test/unittest/window_input_channel_test.cpp create mode 100644 wm/test/unittest/window_input_channel_test.h create mode 100644 wm/test/unittest/window_option_test.cpp create mode 100644 wm/test/unittest/window_option_test.h create mode 100644 wm/test/unittest/window_scene_test.cpp rename wmtest/unittest/include/test_header.h => wm/test/unittest/window_scene_test.h (37%) create mode 100644 wm/test/unittest/window_test.cpp create mode 100644 wm/test/unittest/window_test.h delete mode 100644 wmtest/unittest/src/window_impl_test.cpp diff --git a/ohos.build b/ohos.build index 0887e15a4f..7e7080fd1a 100644 --- a/ohos.build +++ b/ohos.build @@ -15,6 +15,7 @@ ], "test_list": [ + "//foundation/windowmanager/wm:test" ] } } diff --git a/wm/BUILD.gn b/wm/BUILD.gn index fa58a7a367..343ac4d539 100644 --- a/wm/BUILD.gn +++ b/wm/BUILD.gn @@ -169,3 +169,8 @@ ohos_shared_library("libwm") { part_name = "window_manager" subsystem_name = "window" } + +group("test") { + testonly = true + deps = [ "test:test" ] +} diff --git a/wm/test/BUILD.gn b/wm/test/BUILD.gn new file mode 100644 index 0000000000..db162a4768 --- /dev/null +++ b/wm/test/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2021 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. + +group("test") { + testonly = true + deps = [ + "systemtest:systemtest", + "unittest:unittest", + ] +} diff --git a/wmtest/unittest/BUILD.gn b/wm/test/systemtest/BUILD.gn similarity index 41% rename from wmtest/unittest/BUILD.gn rename to wm/test/systemtest/BUILD.gn index b034b6997b..8d04cad4d7 100644 --- a/wmtest/unittest/BUILD.gn +++ b/wm/test/systemtest/BUILD.gn @@ -9,45 +9,79 @@ # 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. +# limitations under the License. import("//build/test.gni") -module_out_path = "window_manager/" -group("unittest") { +module_out_path = "window_manager/wm" + +group("systemtest") { testonly = true - deps = [ ":ut_window_impl_test" ] + deps = [ + ":wm_window_layout_test", + ":wm_window_multi_ability_test", + ":wm_window_subwindow_test", + ] +} + +## SystemTest wm_window_layout_test {{{ +ohos_systemtest("wm_window_layout_test") { + module_out_path = module_out_path + + sources = [ "window_layout_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] +} + +## SystemTest wm_window_layout_test }}} + +## SystemTest wm_window_multi_ability_test {{{ +ohos_systemtest("wm_window_multi_ability_test") { + module_out_path = module_out_path + + sources = [ "window_multi_ability_test.cpp" ] + + deps = [ ":wm_systemtest_common" ] } -## UnitTest ut_window_impl_test {{{ -ohos_unittest("ut_window_impl_test") { +## SystemTest wm_window_multi_ability_test }}} + +## SystemTest wm_window_subwindow_test {{{ +ohos_systemtest("wm_window_subwindow_test") { module_out_path = module_out_path - sources = [ "src/window_impl_test.cpp" ] + sources = [ "window_subwindow_test.cpp" ] - deps = [ ":unittest_wmtest_common" ] + deps = [ ":wm_systemtest_common" ] } -## UnitTest ut_window_impl_test }}} +## SystemTest wm_window_subwindow_test }}} -## Build unittest_wmtest_common.a {{{ -config("unittest_wmtest_common_public_config") { +## Build wm_systemtest_common.a {{{ +config("wm_systemtest_common_public_config") { include_dirs = [ "//foundation/windowmanager/wm/include", "//foundation/windowmanager/wmserver/include", - "include", "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/utils/include", "//utils/native/base/include", "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", - "//foundation/windowmanager/utils/include", "//third_party/googletest/googlemock/include", - #RSSurface - "//foundation/graphic/standard/rosen/modules/render_service_client/core", - "//foundation/graphic/standard/rosen/modules/render_service_base/include", - "//third_party/flutter/skia", + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end ] cflags = [ @@ -59,27 +93,25 @@ config("unittest_wmtest_common_public_config") { ] } -ohos_static_library("unittest_wmtest_common") { +ohos_static_library("wm_systemtest_common") { visibility = [ ":*" ] testonly = true - public_configs = [ ":unittest_wmtest_common_public_config" ] + sources = [ "window_test_utils.cpp" ] - deps = [ + public_configs = [ ":wm_systemtest_common_public_config" ] + + public_deps = [ + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", "//foundation/windowmanager/wm:libwm", "//foundation/windowmanager/wm:libwmutil", "//foundation/windowmanager/wmserver:libwms", "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", "//utils/native/base:utils", - - # RSSurface - "//foundation/graphic/standard/rosen/modules/render_service_base:librender_service_base", - "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", ] - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - ] + external_deps = [ "aafwk_standard:ability_context_native" ] } -## Build unittest_wmtest_common.a }}} +## Build wm_systemtest_common.a }}} diff --git a/wm/test/systemtest/window_layout_test.cpp b/wm/test/systemtest/window_layout_test.cpp new file mode 100644 index 0000000000..d495bf054d --- /dev/null +++ b/wm/test/systemtest/window_layout_test.cpp @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2021 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. + */ + +// gtest +#include +#include "window_test_utils.h" +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowLayoutTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + int displayId_ = 0; + std::vector> activeWindows_; + static vector fullScreenExpecteds_; +}; + +vector WindowLayoutTest::fullScreenExpecteds_; + +void WindowLayoutTest::SetUpTestCase() +{ + auto display = DisplayManager::GetInstance().GetDisplayById(0); + if (display == nullptr) { + printf("GetDefaultDisplay: failed!\n"); + } else { + printf("GetDefaultDisplay: id %llu, w %d, h %d, fps %u\n", display->GetId(), display->GetWidth(), + display->GetHeight(), display->GetFreshRate()); + } + Rect screenRect = {0, 0, display->GetWidth(), display->GetHeight()}; + utils::InitByScreenRect(screenRect); + // calc expected rects + Rect expected = { // 0. only statusBar + 0, + utils::statusBarRect_.height_, + utils::screenRect_.width_, + utils::screenRect_.height_ - utils::statusBarRect_.height_, + }; + fullScreenExpecteds_.push_back(expected); + expected = { // 1. both statusBar and naviBar + 0, + utils::statusBarRect_.height_, + utils::screenRect_.width_, + utils::screenRect_.height_ - utils::statusBarRect_.height_ - utils::naviBarRect_.height_, + }; + fullScreenExpecteds_.push_back(expected); + expected = { // 2. only naviBar + 0, + 0, + utils::screenRect_.width_, + utils::screenRect_.height_ - utils::naviBarRect_.height_, + }; + fullScreenExpecteds_.push_back(expected); +} + +void WindowLayoutTest::TearDownTestCase() +{ +} + +void WindowLayoutTest::SetUp() +{ + activeWindows_.clear(); +} + +void WindowLayoutTest::TearDown() +{ + while (!activeWindows_.empty()) { + ASSERT_EQ(WMError::WM_OK, activeWindows_.back()->Destroy()); + activeWindows_.pop_back(); + } +} + +namespace { +/** + * @tc.name: LayoutWindow02 + * @tc.desc: One FLOATING APP Window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow02, Function | MediumTest | Level3) +{ + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + const sptr& window = utils::CreateTestWindow(info); + activeWindows_.push_back(window); + + ASSERT_EQ(WMError::WM_OK, window->Show()); + ASSERT_TRUE(utils::RectEqualTo(window, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, window->Hide()); +} + +/** + * @tc.name: LayoutWindow04 + * @tc.desc: One FLOATING APP Window & One StatusBar Window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow04, Function | MediumTest | Level3) +{ + // app window + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = true, + .parentLimit = false, + .parentName = "", + }; + sptr appWin = utils::CreateTestWindow(info); + activeWindows_.push_back(appWin); + + // statusBar window + sptr statBar = utils::CreateStatusBarWindow(); + activeWindows_.push_back(statBar); + + ASSERT_EQ(WMError::WM_OK, appWin->Show()); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_)); + ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Hide()); + ASSERT_TRUE(utils::RectEqualTo(appWin, utils::defaultAppRect_)); +} + +/** + * @tc.name: LayoutWindow06 + * @tc.desc: StatusBar Window and NaviBar & Sys Window FULLSCRENN,NOT NEEDVOID,PARENTLIMIT + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow06, Function | MediumTest | Level3) +{ + // statusBar window + sptr statBar = utils::CreateStatusBarWindow(); + activeWindows_.push_back(statBar); + + // naviBar window + sptr naviBar = utils::CreateNavigationBarWindow(); + activeWindows_.push_back(naviBar); + + // sys window + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_PANEL, + .mode = WindowMode::WINDOW_MODE_FULLSCREEN, + .needAvoid = false, + .parentLimit = true, + .parentName = "", + }; + sptr sysWin = utils::CreateTestWindow(info); + activeWindows_.push_back(sysWin); + + ASSERT_EQ(WMError::WM_OK, statBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); + ASSERT_EQ(WMError::WM_OK, sysWin->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); + ASSERT_EQ(WMError::WM_OK, naviBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Hide()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::screenRect_)); +} + +/** + * @tc.name: LayoutWindow07 + * @tc.desc: StatusBar Window and NaviBar & One Floating Sys Window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowLayoutTest, LayoutWindow07, Function | MediumTest | Level3) +{ + // statusBar window + sptr statBar = utils::CreateStatusBarWindow(); + activeWindows_.push_back(statBar); + + // naviBar window + sptr naviBar = utils::CreateNavigationBarWindow(); + activeWindows_.push_back(naviBar); + + // sys window + utils::TestWindowInfo info = { + .name = "main", + .rect = utils::defaultAppRect_, + .type = WindowType::WINDOW_TYPE_PANEL, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = true, + .parentName = "", + }; + sptr sysWin = utils::CreateTestWindow(info); + activeWindows_.push_back(sysWin); + + ASSERT_EQ(WMError::WM_OK, statBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(statBar, utils::statusBarRect_)); + ASSERT_EQ(WMError::WM_OK, sysWin->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, naviBar->Show()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_)); + ASSERT_EQ(WMError::WM_OK, statBar->Hide()); + ASSERT_TRUE(utils::RectEqualTo(sysWin, utils::defaultAppRect_)); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/systemtest/window_multi_ability_test.cpp b/wm/test/systemtest/window_multi_ability_test.cpp new file mode 100644 index 0000000000..3237e1509f --- /dev/null +++ b/wm/test/systemtest/window_multi_ability_test.cpp @@ -0,0 +1,153 @@ +/* + * Copyright (c) 2021 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. + */ + +// gtest +#include +#include +#include "window_test_utils.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using utils = WindowTestUtils; +class WindowMultiAbilityTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void WindowMultiAbilityTest::SetUpTestCase() +{ +} + +void WindowMultiAbilityTest::TearDownTestCase() +{ +} + +void WindowMultiAbilityTest::SetUp() +{ +} + +void WindowMultiAbilityTest::TearDown() +{ +} + +const int SLEEP_MS = 20; + +static void ShowHideWindowSceneCallable(int i) +{ + int sleepTimeMs = i * SLEEP_MS; + usleep(sleepTimeMs); + sptr scene = utils::CreateWindowScene(); + const int loop = 10; + int j = 0; + for (; j < loop; j++) { + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + usleep(sleepTimeMs); + } +} + +static void CreateDestroyWindowSceneCallable(int i) +{ + int sleepTimeMs = i * SLEEP_MS; + const int loop = 10; + int j = 0; + for (; j < loop; j++) { + usleep(sleepTimeMs); + sptr scene = utils::CreateWindowScene(); + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + usleep(sleepTimeMs); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + usleep(sleepTimeMs); + scene.clear(); + usleep(sleepTimeMs); + } +} + +/** + * @tc.name: MultiAbilityWindow01 + * @tc.desc: Five scene process in one thread + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow01, Function | MediumTest | Level2) +{ + sptr scene1 = utils::CreateWindowScene(); + sptr scene2 = utils::CreateWindowScene(); + sptr scene3 = utils::CreateWindowScene(); + sptr scene4 = utils::CreateWindowScene(); + sptr scene5 = utils::CreateWindowScene(); + + ASSERT_EQ(WMError::WM_OK, scene1->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene2->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene3->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene4->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene5->GoForeground()); + ASSERT_EQ(WMError::WM_OK, scene5->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene4->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene3->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene2->GoBackground()); + ASSERT_EQ(WMError::WM_OK, scene1->GoBackground()); +} + +/** + * @tc.name: MultiAbilityWindow02 + * @tc.desc: Five scene process show/hide in five threads + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow02, Function | MediumTest | Level2) +{ + std::thread th1(ShowHideWindowSceneCallable, 1); + std::thread th2(ShowHideWindowSceneCallable, 2); + std::thread th3(ShowHideWindowSceneCallable, 3); + std::thread th4(ShowHideWindowSceneCallable, 4); + std::thread th5(ShowHideWindowSceneCallable, 5); + th1.join(); + th2.join(); + th3.join(); + th4.join(); + th5.join(); +} + +/** + * @tc.name: MultiAbilityWindow03 + * @tc.desc: Five scene process create/destroy in five threads + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowMultiAbilityTest, MultiAbilityWindow03, Function | MediumTest | Level2) +{ + std::thread th1(CreateDestroyWindowSceneCallable, 1); + std::thread th2(CreateDestroyWindowSceneCallable, 2); + std::thread th3(CreateDestroyWindowSceneCallable, 3); + std::thread th4(CreateDestroyWindowSceneCallable, 4); + std::thread th5(CreateDestroyWindowSceneCallable, 5); + th1.join(); + th2.join(); + th3.join(); + th4.join(); + th5.join(); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/systemtest/window_subwindow_test.cpp b/wm/test/systemtest/window_subwindow_test.cpp new file mode 100644 index 0000000000..3aa5f96627 --- /dev/null +++ b/wm/test/systemtest/window_subwindow_test.cpp @@ -0,0 +1,312 @@ +/* + * Copyright (c) 2021 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. + */ + +// gtest +#include + +#include "window.h" +#include "window_life_cycle_interface.h" +#include "window_option.h" +#include "window_scene.h" +#include "wm_common.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +class WindowSubWindowTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; + +void WindowSubWindowTest::SetUpTestCase() +{ +} + +void WindowSubWindowTest::TearDownTestCase() +{ +} + +void WindowSubWindowTest::SetUp() +{ +} + +void WindowSubWindowTest::TearDown() +{ +} + +static sptr CreateWindowScene() +{ + sptr listener = nullptr; + std::shared_ptr abilityContext = nullptr; + + sptr scene = new WindowScene(); + scene->Init(0, abilityContext, listener); + return scene; +} + +static sptr CreateSubWindow(sptr scene, WindowType type, + WindowMode mode, struct Rect rect, uint32_t flags) +{ + sptr subOp = new WindowOption(); + subOp->SetWindowType(type); + subOp->SetWindowMode(mode); + subOp->SetWindowRect(rect); + subOp->SetWindowFlags(flags); + + static int cnt = 0; + return scene->CreateWindow("SubWindow" + std::to_string(cnt++), subOp); +} + +/** + * @tc.name: SubWindow01 + * @tc.desc: FullScreen Main Window + Floating SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow01, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = 0; + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow02 + * @tc.desc: FullScreen Main Window + Floating SubWindow & Parent Limit work + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow02, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow03 + * @tc.desc: FullScreen Main Window + Floating MediaWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow03, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 2000, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow04 + * @tc.desc: FullScreen Main Window + Floating MediaWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow04, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 2000, 3000, 2000}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow05 + * @tc.desc: FullScreen Main Window + Floating MediaWindow + Floating SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow05, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + sptr subWindow2 = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow2); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + ASSERT_EQ(WMError::WM_OK, subWindow2->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, subWindow2->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow06 + * @tc.desc: FullScreen Main Window + FullScreen SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow06, Function | MediumTest | Level3) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FULLSCREEN, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); +} + +/** + * @tc.name: SubWindow07 + * @tc.desc: FullScreen Main Window + Floating SubWindow & MainWindow Fisrt GoBackground + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow07, Function | MediumTest | Level4) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); +} + +/** + * @tc.name: SubWindow08 + * @tc.desc: FullScreen Main Window + Floating SubWindow & only show SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow08, Function | MediumTest | Level4) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, subWindow->Show()); +} + +/** + * @tc.name: SubWindow09 + * @tc.desc: FullScreen Main Window + Floating SubWindow & first destroy SubWindow, then destroy MainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow09, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Hide()); + ASSERT_EQ(WMError::WM_OK, scene->GoBackground()); + + ASSERT_EQ(WMError::WM_OK, subWindow->Destroy()); +} + +/** + * @tc.name: SubWindow10 + * @tc.desc: FullScreen Main Window + Floating SubWindow & first destroy MainWindow, then destroy SubWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSubWindowTest, SubWindow10, Function | MediumTest | Level2) +{ + sptr scene = CreateWindowScene(); + + struct Rect rect = {0, 0, 100, 200}; + uint32_t flags = static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + sptr subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_APP_SUB_WINDOW, + WindowMode::WINDOW_MODE_FLOATING, rect, flags); + ASSERT_NE(nullptr, subWindow); + + ASSERT_EQ(WMError::WM_OK, scene->GoForeground()); + ASSERT_EQ(WMError::WM_OK, subWindow->Show()); + + sptr mainWindow = scene->GetMainWindow(); + ASSERT_EQ(WMError::WM_OK, mainWindow->Destroy()); + ASSERT_EQ(WMError::WM_ERROR_DESTROYED_OBJECT, subWindow->Destroy()); +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.cpp b/wm/test/systemtest/window_test_utils.cpp new file mode 100644 index 0000000000..a761514717 --- /dev/null +++ b/wm/test/systemtest/window_test_utils.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2021 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 "window_test_utils.h" + +namespace OHOS { +namespace Rosen { +Rect WindowTestUtils::screenRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::statusBarRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::naviBarRect_ = {0, 0, 0, 0}; +Rect WindowTestUtils::defaultAppRect_ = {0, 0, 0, 0}; + +sptr WindowTestUtils::CreateTestWindow(const TestWindowInfo& info) +{ + sptr option = new WindowOption(); + option->SetWindowRect(info.rect); + option->SetWindowType(info.type); + option->SetWindowMode(info.mode); + if (info.parentName != "") { + option->SetParentName(info.parentName); + } + if (info.needAvoid) { + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + } else { + option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + } + if (info.parentLimit) { + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + } else { + option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + } + sptr window = Window::Create(info.name, option); + return window; +} + +sptr WindowTestUtils::CreateStatusBarWindow() +{ + TestWindowInfo info = { + .name = "statusBar", + .rect = statusBarRect_, + .type = WindowType::WINDOW_TYPE_STATUS_BAR, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; + return CreateTestWindow(info); +} + +sptr WindowTestUtils::CreateNavigationBarWindow() +{ + TestWindowInfo info = { + .name = "naviBar", + .rect = naviBarRect_, + .type = WindowType::WINDOW_TYPE_NAVIGATION_BAR, + .mode = WindowMode::WINDOW_MODE_FLOATING, + .needAvoid = false, + .parentLimit = false, + .parentName = "", + }; + return CreateTestWindow(info); +} + +sptr WindowTestUtils::CreateWindowScene() +{ + sptr listener = nullptr; + std::shared_ptr abilityContext = nullptr; + + sptr scene = new WindowScene(); + scene->Init(0, abilityContext, listener); + return scene; +} + +void WindowTestUtils::InitByScreenRect(const Rect& screenRect) +{ + const float barRatio = 0.07; + const float appRation = 0.4; + screenRect_ = screenRect; + statusBarRect_ = {0, 0, screenRect_.width_, screenRect_.height_ * barRatio}; + naviBarRect_ = {0, screenRect_.height_ * (1 - barRatio), screenRect_.width_, screenRect_.height_ * barRatio}; + defaultAppRect_ = {0, 0, screenRect_.width_ * appRation, screenRect_.height_ * appRation}; +} + +bool WindowTestUtils::RectEqualTo(const sptr& window, const Rect& r) +{ + Rect l = window->GetRect(); + bool res = ((l.posX_ == r.posX_) && (l.posY_ == r.posY_) && (l.width_ == r.width_) && (l.height_ == r.height_)); + if (!res) { + printf("GetLayoutRect: %d %d %d %d, Expect: %d %d %d %d\n", l.posX_, l.posY_, l.width_, l.height_, + r.posX_, r.posY_, r.width_, r.height_); + } + return res; +} +} // namespace ROSEN +} // namespace OHOS diff --git a/wm/test/systemtest/window_test_utils.h b/wm/test/systemtest/window_test_utils.h new file mode 100644 index 0000000000..a8998c6b37 --- /dev/null +++ b/wm/test/systemtest/window_test_utils.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2021 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 FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H +#define FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H + +#include "display_manager.h" +#include "window.h" +#include "window_life_cycle_interface.h" +#include "window_option.h" +#include "window_scene.h" +#include "wm_common.h" + +namespace OHOS { +namespace Rosen { +class WindowTestUtils { +public: + struct TestWindowInfo { + std::string name; + Rect rect; + WindowType type; + WindowMode mode; + bool needAvoid; + bool parentLimit; + std::string parentName; + }; + static Rect screenRect_; + static Rect statusBarRect_; + static Rect naviBarRect_; + static Rect defaultAppRect_; + static void InitByScreenRect(const Rect& screenRect); + static sptr CreateTestWindow(const TestWindowInfo& info); + static sptr CreateStatusBarWindow(); + static sptr CreateNavigationBarWindow(); + static sptr CreateWindowScene(); + static bool RectEqualTo(const sptr& window, const Rect& r); +}; +} // namespace ROSEN +} // namespace OHOS +#endif // FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H diff --git a/wm/test/unittest/BUILD.gn b/wm/test/unittest/BUILD.gn new file mode 100644 index 0000000000..144000bc2b --- /dev/null +++ b/wm/test/unittest/BUILD.gn @@ -0,0 +1,150 @@ +# Copyright (c) 2021 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") +module_out_path = "window_manager/wm" + +group("unittest") { + testonly = true + + deps = [ + ":wm_input_transfer_station_test", + ":wm_window_impl_test", + ":wm_window_input_channel_test", + ":wm_window_option_test", + ":wm_window_scene_test", + ":wm_window_test", + ] +} + +## UnitTest wm_window_impl_test {{{ +ohos_unittest("wm_window_impl_test") { + module_out_path = module_out_path + + sources = [ "window_impl_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_impl_test }}} + +## UnitTest wm_input_transfer_station_test {{{ +ohos_unittest("wm_input_transfer_station_test") { + module_out_path = module_out_path + + sources = [ "input_transfer_station_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_input_transfer_station_test }}} + +## UnitTest wm_window_input_channel_test {{{ +ohos_unittest("wm_window_input_channel_test") { + module_out_path = module_out_path + + sources = [ "window_input_channel_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_input_channel_test }}} + +## UnitTest wm_window_option_test {{{ +ohos_unittest("wm_window_option_test") { + module_out_path = module_out_path + + sources = [ "window_option_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_option_test }}} + +## UnitTest wm_window_scene_test {{{ +ohos_unittest("wm_window_scene_test") { + module_out_path = module_out_path + + sources = [ "window_scene_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_scene_test }}} + +## UnitTest wm_window_test {{{ +ohos_unittest("wm_window_test") { + module_out_path = module_out_path + + sources = [ "window_test.cpp" ] + + deps = [ ":wm_unittest_common" ] +} + +## UnitTest wm_window_test }}} + +## Build wm_unittest_common.a {{{ +config("wm_unittest_common_public_config") { + include_dirs = [ + "//foundation/windowmanager/wm/include", + "//foundation/windowmanager/wmserver/include", + "//foundation/windowmanager/interfaces/innerkits/wm", + "//foundation/windowmanager/utils/include", + "//utils/native/base/include", + "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include", + "//base/hiviewdfx/hilog/interfaces/native/innerkits/include", + "//third_party/googletest/googlemock/include", + + # for abilityContext + "//foundation/aafwk/standard/frameworks/kits/ability/ability_runtime/include", + "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_base/include", + "//foundation/appexecfwk/standard/kits/appkit/native/ability_runtime/context", + "//base/global/resmgr_standard/interfaces/innerkits/include", + "//third_party/node/deps/icu-small/source/common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", + "//foundation/aafwk/standard/interfaces/innerkits/want/include/ohos/aafwk/content", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//foundation/aafwk/standard/interfaces/innerkits/base/include", + + # abilityContext end + ] + + cflags = [ + "-Wall", + "-Werror", + "-g3", + "-Dprivate=public", + "-Dprotected=public", + ] +} + +ohos_static_library("wm_unittest_common") { + visibility = [ ":*" ] + testonly = true + + public_configs = [ ":wm_unittest_common_public_config" ] + + public_deps = [ + "//foundation/ace/ace_engine/interfaces/innerkits/ace:ace_uicontent", + "//foundation/multimodalinput/input/frameworks/proxy:libmmi-client", + "//foundation/windowmanager/wm:libwm", + "//foundation/windowmanager/wm:libwmutil", + "//foundation/windowmanager/wmserver:libwms", + "//third_party/googletest:gmock", + "//third_party/googletest:gtest_main", + "//utils/native/base:utils", + ] + + external_deps = [ "aafwk_standard:ability_context_native" ] +} +## Build wm_unittest_common.a }}} diff --git a/wm/test/unittest/input_transfer_station_test.cpp b/wm/test/unittest/input_transfer_station_test.cpp new file mode 100644 index 0000000000..a4852e37c2 --- /dev/null +++ b/wm/test/unittest/input_transfer_station_test.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 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 "input_transfer_station_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using WindowMocker = SingletonMocker; +void InputTransferStationTest::SetUpTestCase() +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName("inputwindow"); + window_ = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Create(""); +} + +void InputTransferStationTest::TearDownTestCase() +{ +} + +void InputTransferStationTest::SetUp() +{ +} + +void InputTransferStationTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: AddInputWindow + * @tc.desc: add input window in station. + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(InputTransferStationTest, AddInputWindow, Function | SmallTest | Level2) +{ + std::shared_ptr listener = std::make_shared(InputEventListener()); + MMI::InputManager::GetInstance()->SetWindowInputEventConsumer(listener); + InputTransferStation::GetInstance().AddInputWindow(window_); +} + +/** + * @tc.name: RemoveInputWindow + * @tc.desc: remove input window in station. + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(InputTransferStationTest, RemoveInputWindow, Function | SmallTest | Level2) +{ + InputTransferStation::GetInstance().RemoveInputWindow(window_); +} + +/** + * @tc.name: SetInputListener + * @tc.desc: set input listener for inner window + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(InputTransferStationTest, SetInputListener, Function | SmallTest | Level2) +{ + int32_t windowId = 1; + std::shared_ptr listener = std::make_shared(InputEventListener()); + InputTransferStation::GetInstance().SetInputListener(windowId, listener); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/input_transfer_station_test.h b/wm/test/unittest/input_transfer_station_test.h new file mode 100644 index 0000000000..3f6c7576eb --- /dev/null +++ b/wm/test/unittest/input_transfer_station_test.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2021 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 FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H +#define FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H + +#include +#include "input_manager.h" +#include "input_transfer_station.h" +#include "window_impl.h" + +namespace OHOS { +namespace Rosen { +class InputTransferStationTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static inline sptr window_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/mock_static_call.h b/wm/test/unittest/mock_static_call.h new file mode 100644 index 0000000000..fa14ff0b80 --- /dev/null +++ b/wm/test/unittest/mock_static_call.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 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 FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H +#define FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H +#include + +#include "ability_context_impl.h" +#include "static_call.h" + +namespace OHOS { +namespace Rosen { +class MockStaticCall : public StaticCall { +public: + MOCK_METHOD3(CreateWindow, sptr(const std::string& windowName, + sptr& option, std::shared_ptr abilityContext)); +}; +} +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H+ diff --git a/wmtest/unittest/include/mock/mock_window_adapter.h b/wm/test/unittest/mock_window_adapter.h similarity index 64% rename from wmtest/unittest/include/mock/mock_window_adapter.h rename to wm/test/unittest/mock_window_adapter.h index b839fe7819..fc5d523c81 100644 --- a/wmtest/unittest/include/mock/mock_window_adapter.h +++ b/wm/test/unittest/mock_window_adapter.h @@ -13,9 +13,8 @@ * limitations under the License. */ -#ifndef UNITTEST_MOCK_WINDOW_ADAPTER_H -#define UNITTEST_MOCK_WINDOW_ADAPTER_H - +#ifndef FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H +#define FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H #include #include "window_adapter.h" @@ -24,12 +23,15 @@ namespace OHOS { namespace Rosen { class MockWindowAdapter : public WindowAdapter { public: + MOCK_METHOD4(CreateWindow, WMError(sptr& window, sptr& windowProperty, + std::shared_ptr surfaceNode, uint32_t& windowId)); MOCK_METHOD1(AddWindow, WMError(sptr& windowProperty)); MOCK_METHOD1(RemoveWindow, WMError(uint32_t windowId)); MOCK_METHOD0(ClearWindowAdapter, void()); + MOCK_METHOD1(DestroyWindow, WMError(uint32_t windowId)); + MOCK_METHOD2(SaveAbilityToken, WMError(const sptr& abilityToken, uint32_t windowId)); }; } } // namespace OHOS - -#endif \ No newline at end of file +#endif // FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H \ No newline at end of file diff --git a/wmtest/unittest/include/mock/singleton_mocker.h b/wm/test/unittest/singleton_mocker.h similarity index 87% rename from wmtest/unittest/include/mock/singleton_mocker.h rename to wm/test/unittest/singleton_mocker.h index e593e5fbd1..e87b91f1ed 100644 --- a/wmtest/unittest/include/mock/singleton_mocker.h +++ b/wm/test/unittest/singleton_mocker.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef UNITTEST_MOCK_SINGLETON_MOCKER_H -#define UNITTEST_MOCK_SINGLETON_MOCKER_H +#ifndef FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H +#define FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H #include "singleton_container.h" namespace OHOS { @@ -43,4 +43,4 @@ private: } // namespace Rosen } // namespace OHOS -#endif // FRAMEWORKS_WM_TEST_UNITTEST_MOCK_SINGLETON_MOCKER_H +#endif // FRAMEWORKS_WM_TEST_UT_SINGLETON_MOCKER_H diff --git a/wm/test/unittest/window_impl_test.cpp b/wm/test/unittest/window_impl_test.cpp new file mode 100644 index 0000000000..cc4abc3be8 --- /dev/null +++ b/wm/test/unittest/window_impl_test.cpp @@ -0,0 +1,392 @@ +/* + * Copyright (c) 2021 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 "window_impl_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +void WindowImplTest::SetUpTestCase() +{ + option_ = new WindowOption(); + option_->SetWindowName("WindowImplTest"); + window_ = new WindowImpl(option_); + abilityContext_ = std::make_shared(); + + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Create(""); +} + +void WindowImplTest::TearDownTestCase() +{ + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Destroy(); +} + +void WindowImplTest::SetUp() +{ +} + +void WindowImplTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: CreateWindow01 + * @tc.desc: Create window with no parentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow01, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow01"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: CreateWindow02 + * @tc.desc: Create window with no parentName and no abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow02"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(WMError::WM_ERROR_SAMGR, window->Create("")); +} + +/** + * @tc.name: CreateWindow03 + * @tc.desc: Create window with illegal parentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow03, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow03"); + sptr window = new WindowImpl(option); + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->Create("illegal")); +} + +/** + * @tc.name: CreateWindow04 + * @tc.desc: Create window with repeated windowName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow04, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("WindowImplTest"); + sptr window = new WindowImpl(option); + + ASSERT_EQ(WMError::WM_ERROR_INVALID_PARAM, window->Create("")); +} + +/** + * @tc.name: CreateWindow05 + * @tc.desc: Create window with exist parentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow05, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow05"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("WindowImplTest")); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: CreateWindow06 + * @tc.desc: Create window with no default option, get and check Property + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow06, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow06"); + struct Rect rect = {1, 2, 3u, 4u}; + option->SetWindowRect(rect); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + ASSERT_EQ(1, window->GetRect().posX_); + ASSERT_EQ(2, window->GetRect().posY_); + ASSERT_EQ(3u, window->GetRect().width_); + ASSERT_EQ(4u, window->GetRect().height_); + ASSERT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, window->GetType()); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, window->GetMode()); + ASSERT_EQ("CreateWindow06", window->GetWindowName()); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: CreateWindow07 + * @tc.desc: Create window with no parentName and abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow07, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow07"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Create("", abilityContext_)); +} + +/** + * @tc.name: CreateWindow08 + * @tc.desc: Mock SaveAbilityToken return WM_ERROR_NULLPTR, create window with no parentName and abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, CreateWindow08, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("CreateWindow08"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_NULLPTR)); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, window->Create("", abilityContext_)); +} + +/** + * @tc.name: FindWindow01 + * @tc.desc: Find one exit window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow01, Function | SmallTest | Level2) +{ + ASSERT_NE(nullptr, WindowImpl::Find("WindowImplTest")); +} + +/** + * @tc.name: FindWindow02 + * @tc.desc: Add another window, find both two windows + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + sptr option = new WindowOption(); + option->SetWindowName("FindWindow02"); + sptr window = new WindowImpl(option); + + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + + ASSERT_EQ(WMError::WM_OK, window->Create("")); + + ASSERT_NE(nullptr, WindowImpl::Find("WindowImplTest")); + ASSERT_NE(nullptr, WindowImpl::Find("FindWindow02")); + + EXPECT_CALL(m->Mock(), DestroyWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window->Destroy()); +} + +/** + * @tc.name: FindWindow03 + * @tc.desc: Find one no exit window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow03, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow03")); +} + +/** + * @tc.name: FindWindow04 + * @tc.desc: Find window with empty name + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow04, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, WindowImpl::Find("")); +} + +/** + * @tc.name: FindWindow05 + * @tc.desc: Find one destroyed window + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, FindWindow05, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, WindowImpl::Find("FindWindow02")); +} + +/** + * @tc.name: SetWindowType01 + * @tc.desc: SetWindowType + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, SetWindowType01, Function | SmallTest | Level2) +{ + ASSERT_EQ(WMError::WM_OK, window_->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW)); +} + +/** + * @tc.name: SetWindowMode01 + * @tc.desc: SetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, SetWindowMode01, Function | SmallTest | Level2) +{ + ASSERT_EQ(WMError::WM_OK, window_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN)); +} + +/** + * @tc.name: ShowHideWindow01 + * @tc.desc: Show and hide window with add and remove window ok + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow01, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Show()); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Hide()); +} + +/** + * @tc.name: ShowHideWindow02 + * @tc.desc: Show window with add window WM_ERROR_SAMGR + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Show()); +} + +/** + * @tc.name: ShowHideWindow03 + * @tc.desc: Show window with add window WM_ERROR_IPC_FAILED + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow03, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Show()); +} + +/** + * @tc.name: ShowHideWindow04 + * @tc.desc: Show window with add window OK & Hide window with remove window WM_ERROR_SAMGR + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow04, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + + EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Show()); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(WMError::WM_ERROR_SAMGR, window_->Hide()); +} + +/** + * @tc.name: ShowHideWindow05 + * @tc.desc: Hide window with remove window WM_ERROR_IPC_FAILED + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow05, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_IPC_FAILED)); + ASSERT_EQ(WMError::WM_ERROR_IPC_FAILED, window_->Hide()); +} + +/** + * @tc.name: ShowHideWindow06 + * @tc.desc: Hide window with remove window OK + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowImplTest, ShowHideWindow06, Function | SmallTest | Level3) +{ + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_EQ(WMError::WM_OK, window_->Hide()); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wmtest/unittest/include/window_impl_test.h b/wm/test/unittest/window_impl_test.h similarity index 69% rename from wmtest/unittest/include/window_impl_test.h rename to wm/test/unittest/window_impl_test.h index f9adbf5f59..a22bd18b27 100644 --- a/wmtest/unittest/include/window_impl_test.h +++ b/wm/test/unittest/window_impl_test.h @@ -13,10 +13,11 @@ * limitations under the License. */ -#ifndef UNITTEST_WINDOW_IMPL_TEST_H -#define UNITTEST_WINDOW_IMPL_TEST_H +#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H #include +#include "ability_context_impl.h" #include "window_impl.h" namespace OHOS { @@ -28,10 +29,11 @@ public: virtual void SetUp() override; virtual void TearDown() override; - static inline sptr window_ = nullptr; - static inline sptr property_ = nullptr; + static inline sptr window_ = nullptr; + static inline sptr option_ = nullptr; + static inline std::shared_ptr abilityContext_; }; } // namespace ROSEN } // namespace OHOS -#endif // FRAMEWORKS_WM_TEST_UNITTEST_WINDOW_IMPL_TEST_H \ No newline at end of file +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/window_input_channel_test.cpp b/wm/test/unittest/window_input_channel_test.cpp new file mode 100644 index 0000000000..c22101e35b --- /dev/null +++ b/wm/test/unittest/window_input_channel_test.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2021 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 "window_input_channel_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using WindowMocker = SingletonMocker; +void WindowInputChannelTest::SetUpTestCase() +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + option->SetWindowName("window"); + window_ = new WindowImpl(option); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + window_->Create(""); +} + +void WindowInputChannelTest::TearDownTestCase() +{ +} + +void WindowInputChannelTest::SetUp() +{ +} + +void WindowInputChannelTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: HandlePointerEvent + * @tc.desc: consume pointer event when receive callback from input + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(WindowInputChannelTest, HandlePointerEvent, Function | SmallTest | Level2) +{ + auto pointerEvent = MMI::PointerEvent::Create(); + sptr inputChannel = new WindowInputChannel(window_); + window_->ConsumePointerEvent(pointerEvent); + inputChannel->HandlePointerEvent(pointerEvent); +} + +/** + * @tc.name: HandleKeyEvent + * @tc.desc: consume key event when receive callback from input + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(WindowInputChannelTest, HandleKeyEvent, Function | SmallTest | Level2) +{ + auto keyEvent = MMI::KeyEvent::Create(); + sptr inputChannel = new WindowInputChannel(window_); + window_->ConsumeKeyEvent(keyEvent); + inputChannel->HandleKeyEvent(keyEvent); +} + +/** + * @tc.name: SetInputListener + * @tc.desc: set input listener when create window + * @tc.type: FUNC + * @tc.require: AR000GGTUV + */ +HWTEST_F(WindowInputChannelTest, SetInputListener, Function | SmallTest | Level2) +{ + sptr inputChannel = new WindowInputChannel(window_); + std::shared_ptr listener = std::make_shared(InputEventListener()); + inputChannel->SetInputListener(listener); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_input_channel_test.h b/wm/test/unittest/window_input_channel_test.h new file mode 100644 index 0000000000..4f43ff2f1c --- /dev/null +++ b/wm/test/unittest/window_input_channel_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H + +#include +#include "window_impl.h" +#include "window_input_channel.h" + +namespace OHOS { +namespace Rosen { +class WindowInputChannelTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static inline sptr window_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/window_option_test.cpp b/wm/test/unittest/window_option_test.cpp new file mode 100644 index 0000000000..fcf6156014 --- /dev/null +++ b/wm/test/unittest/window_option_test.cpp @@ -0,0 +1,191 @@ +/* + * Copyright (c) 2021 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 "window_option_test.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +void WindowOptionTest::SetUpTestCase() +{ +} + +void WindowOptionTest::TearDownTestCase() +{ +} + +void WindowOptionTest::SetUp() +{ +} + +void WindowOptionTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: WindowRect01 + * @tc.desc: SetWindowRect/GetWindowRect + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowRect01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + struct Rect rect = {1, 2, 3u, 4u}; + option->SetWindowRect(rect); + + ASSERT_EQ(1, option->GetWindowRect().posX_); + ASSERT_EQ(2, option->GetWindowRect().posY_); + ASSERT_EQ(3u, option->GetWindowRect().width_); + ASSERT_EQ(4u, option->GetWindowRect().height_); +} + +/** + * @tc.name: WindowType01 + * @tc.desc: SetWindowType/GetWindowType + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowType01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowType(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW); + ASSERT_EQ(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW, option->GetWindowType()); +} + +/** + * @tc.name: WindowMode01 + * @tc.desc: SetWindowMode/GetWindowMode + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowMode01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); + ASSERT_EQ(WindowMode::WINDOW_MODE_FULLSCREEN, option->GetWindowMode()); +} + +/** + * @tc.name: Focusable01 + * @tc.desc: SetFocusable/GetFocusable + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, Focusable01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetFocusable(true); + ASSERT_EQ(true, option->GetFocusable()); +} + +/** + * @tc.name: Touchable01 + * @tc.desc: SetTouchable/GetTouchable + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, Touchable01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetTouchable(true); + ASSERT_EQ(true, option->GetTouchable()); +} + +/** + * @tc.name: DisplayId01 + * @tc.desc: SetDisplayId/GetDisplayId + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, DisplayId01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetDisplayId(1); + ASSERT_EQ(1, option->GetDisplayId()); +} + +/** + * @tc.name: ParentName01 + * @tc.desc: SetParentName/GetParentName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, ParentName01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetParentName("Main Window"); + ASSERT_EQ("Main Window", option->GetParentName()); +} + +/** + * @tc.name: WindowName01 + * @tc.desc: SetWindowName/GetWindowName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowName01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowName("Sub Window"); + ASSERT_EQ("Sub Window", option->GetWindowName()); +} + +/** + * @tc.name: WindowFlag01 + * @tc.desc: SetWindowFlags/GetWindowFlags + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowFlag01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->SetWindowFlags(1u); + ASSERT_EQ(1u, option->GetWindowFlags()); +} + +/** + * @tc.name: WindowFlag02 + * @tc.desc: AddWindowFlag/GetWindowFlags + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowFlag02, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + ASSERT_EQ(static_cast(WindowFlag::WINDOW_FLAG_NEED_AVOID), option->GetWindowFlags()); +} + +/** + * @tc.name: WindowFlag03 + * @tc.desc: AddWindowFlag/RemoveWindowFlag/GetWindowFlags + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowOptionTest, WindowFlag03, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + option->AddWindowFlag(WindowFlag::WINDOW_FLAG_PARENT_LIMIT); + option->RemoveWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID); + ASSERT_EQ(static_cast(WindowFlag::WINDOW_FLAG_PARENT_LIMIT), option->GetWindowFlags()); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_option_test.h b/wm/test/unittest/window_option_test.h new file mode 100644 index 0000000000..09c7d7b1fa --- /dev/null +++ b/wm/test/unittest/window_option_test.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2021 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 FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H + +#include +#include "window_option.h" + +namespace OHOS { +namespace Rosen { +class WindowOptionTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; +}; +} // namespace ROSEN +} // namespace OHOS +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_OPTION_TEST_H diff --git a/wm/test/unittest/window_scene_test.cpp b/wm/test/unittest/window_scene_test.cpp new file mode 100644 index 0000000000..b00ed6f9f3 --- /dev/null +++ b/wm/test/unittest/window_scene_test.cpp @@ -0,0 +1,231 @@ +/* + * Copyright (c) 2021 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 "window_scene_test.h" +#include "ability_context_impl.h" +#include "mock_static_call.h" +#include "singleton_mocker.h" +#include "window_impl.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +void WindowSceneTest::SetUpTestCase() +{ + int displayId = 0; + sptr listener = nullptr; + scene_ = new WindowScene(); + abilityContext_ = std::make_shared(); + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(option))); + ASSERT_EQ(WMError::WM_OK, scene_->Init(displayId, abilityContext_, listener)); +} + +void WindowSceneTest::TearDownTestCase() +{ +} + +void WindowSceneTest::SetUp() +{ +} + +void WindowSceneTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: Init01 + * @tc.desc: Init Scene with null abilityContext, null listener + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Init01, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest))); + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + std::shared_ptr abilityContext = nullptr; + ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext, listener)); +} + +/** + * @tc.name: Init02 + * @tc.desc: Mock window Create Static Method return nullptr, init Scene with null abilityContext, null listener + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Init02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr)); + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + std::shared_ptr abilityContext = nullptr; + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->Init(displayId, abilityContext, listener)); +} + +/** + * @tc.name: Init03 + * @tc.desc: Init Scene with abilityContext, null listener + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Init03, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest))); + int displayId = 0; + sptr listener = nullptr; + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_OK, scene->Init(displayId, abilityContext_, listener)); +} + +/** + * @tc.name: Create01 + * @tc.desc: CreateWindow without windowName + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create01, Function | SmallTest | Level2) +{ + sptr optionTest = new WindowOption(); + sptr scene = new WindowScene(); + ASSERT_EQ(nullptr, scene->CreateWindow("", optionTest)); +} + +/** + * @tc.name: Create02 + * @tc.desc: CreateWindow with windowName and without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create02, Function | SmallTest | Level2) +{ + sptr optionTest = new WindowOption(); + sptr scene = new WindowScene(); + ASSERT_EQ(nullptr, scene->CreateWindow("WindowSceneTest02", optionTest)); +} + +/** + * @tc.name: Create03 + * @tc.desc: CreateWindow with windowName and mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create03, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr optionTest = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest))); + ASSERT_NE(nullptr, scene_->CreateWindow("WindowSceneTest03", optionTest)); +} + +/** + * @tc.name: Create04 + * @tc.desc: Mock window Create Static Method return nullptr, createWindow with windowName and mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create04, Function | SmallTest | Level2) +{ + sptr optionTest = new WindowOption(); + std::unique_ptr m = std::make_unique(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr)); + ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest04", optionTest)); +} + +/** + * @tc.name: Create05 + * @tc.desc: createWindow with windowName and null option + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, Create05, Function | SmallTest | Level2) +{ + sptr optionTest = nullptr; + ASSERT_EQ(nullptr, scene_->CreateWindow("WindowSceneTest05", optionTest)); +} + +/** + * @tc.name: GetMainWindow01 + * @tc.desc: GetMainWindow without scene init + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GetMainWindow01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(nullptr, scene->GetMainWindow()); +} + +/** + * @tc.name: GetMainWindow02 + * @tc.desc: GetMainWindow01 with scene init success + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GetMainWindow02, Function | SmallTest | Level2) +{ + ASSERT_NE(nullptr, scene_->GetMainWindow()); +} + +/** + * @tc.name: GoForeground01 + * @tc.desc: GoForeground01 without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GoForeground01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoForeground()); +} + +/** + * @tc.name: GoBackground01 + * @tc.desc: GoBackground01 without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, GoBackground01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->GoBackground()); +} + +/** + * @tc.name: RequestFocus01 + * @tc.desc: RequestFocus01 without mainWindow + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowSceneTest, RequestFocus01, Function | SmallTest | Level2) +{ + sptr scene = new WindowScene(); + ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->RequestFocus()); +} +} +} // namespace Rosen +} // namespace OHOS \ No newline at end of file diff --git a/wmtest/unittest/include/test_header.h b/wm/test/unittest/window_scene_test.h similarity index 37% rename from wmtest/unittest/include/test_header.h rename to wm/test/unittest/window_scene_test.h index 31f8bfbd0a..3573507f8d 100644 --- a/wmtest/unittest/include/test_header.h +++ b/wm/test/unittest/window_scene_test.h @@ -1,43 +1,37 @@ -/* - * Copyright (c) 2021 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 UNITTEST_TEST_HEADER_H -#define UNITTEST_TEST_HEADER_H - -#include "window_manager_hilog.h" - -namespace OHOS { -namespace Rosen { -#define _WMT_CPRINTF(color, func, fmt, ...) \ - func({LOG_CORE, 0, "WM_UINTTEST"}, "\033[" #color "m" "<%{public}d>" fmt "\033[0m", __LINE__, ##__VA_ARGS__) -#define WMTLOGI(color, fmt, ...) \ - _WMT_CPRINTF(color, HiviewDFX::HiLog::Info, "%{public}s: " fmt, __func__, ##__VA_ARGS__) - -#define PART(part) WMTLOGI(33, part); if (const char *strPart = part) -#define STEP(desc) WMTLOGI(34, desc); if (const char *strDesc = desc) - -#define STEP_CONDITION(condition) strPart << ": " << strDesc << " (" << condition << ")" - -#define STEP_ASSERT_(l, r, func, opstr) ASSERT_##func(l, r) << STEP_CONDITION(#l " " opstr " " #r) - -#define STEP_ASSERT_EQ(l, r) STEP_ASSERT_(l, r, EQ, "==") -#define STEP_ASSERT_NE(l, r) STEP_ASSERT_(l, r, NE, "!=") -#define STEP_ASSERT_GE(l, r) STEP_ASSERT_(l, r, GE, ">=") -#define STEP_ASSERT_LE(l, r) STEP_ASSERT_(l, r, LE, "<=") -#define STEP_ASSERT_GT(l, r) STEP_ASSERT_(l, r, GT, ">") -#define STEP_ASSERT_LT(l, r) STEP_ASSERT_(l, r, LT, "<") -} // namespace Rosen -} // namespace OHOS -#endif // UNITTEST_TEST_HEADER_H +/* + * Copyright (c) 2021 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 FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H + +#include +#include "window_scene.h" + +namespace OHOS { +namespace Rosen { +class WindowSceneTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + + static inline sptr scene_ = nullptr; + static inline std::shared_ptr abilityContext_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H \ No newline at end of file diff --git a/wm/test/unittest/window_test.cpp b/wm/test/unittest/window_test.cpp new file mode 100644 index 0000000000..f5614b064f --- /dev/null +++ b/wm/test/unittest/window_test.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (c) 2021 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 "window_test.h" +#include "mock_window_adapter.h" +#include "singleton_mocker.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace Rosen { +using Mocker = SingletonMocker; +void WindowTest::SetUpTestCase() +{ + abilityContext_ = std::make_shared(); +} + +void WindowTest::TearDownTestCase() +{ +} + +void WindowTest::SetUp() +{ +} + +void WindowTest::TearDown() +{ +} + +namespace { +/** + * @tc.name: Create01 + * @tc.desc: Create window with no WindowName and no abilityToken + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create01, Function | SmallTest | Level2) +{ + sptr option = new WindowOption(); + ASSERT_EQ(nullptr, Window::Create("", option)); +} + +/** + * @tc.name: Create02 + * @tc.desc: Create window with WindowName and no abilityToken + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_NE(nullptr, Window::Create("WindowTest02", option)); +} + +/** + * @tc.name: Create03 + * @tc.desc: Mock CreateWindow return WM_ERROR_SAMGR, create window with WindowName and no abilityToken + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create03, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_ERROR_SAMGR)); + ASSERT_EQ(nullptr, Window::Create("WindowTest03", option)); +} + +/** + * @tc.name: Create04 + * @tc.desc: Create window with WindowName and abilityContext + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create04, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + EXPECT_CALL(m->Mock(), SaveAbilityToken(_, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_NE(nullptr, Window::Create("WindowTest04", option, abilityContext_)); +} + +/** + * @tc.name: Create06 + * @tc.desc: Create window with WindowName and no option + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Create06, Function | SmallTest | Level2) +{ + sptr option = nullptr; + ASSERT_EQ(nullptr, Window::Create("", option)); +} + +/** + * @tc.name: Find01 + * @tc.desc: Find with no name + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Find01, Function | SmallTest | Level2) +{ + ASSERT_EQ(nullptr, Window::Find("")); +} + +/** + * @tc.name: Find02 + * @tc.desc: Find with name + * @tc.type: FUNC + * @tc.require: AR000GGTVJ + */ +HWTEST_F(WindowTest, Find02, Function | SmallTest | Level2) +{ + std::unique_ptr m = std::make_unique(); + sptr option = new WindowOption(); + EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK)); + ASSERT_NE(nullptr, Window::Create("WindowTest03", option)); + ASSERT_NE(nullptr, Window::Find("WindowTest03")); +} +} +} // namespace Rosen +} // namespace OHOS diff --git a/wm/test/unittest/window_test.h b/wm/test/unittest/window_test.h new file mode 100644 index 0000000000..58ff5cc764 --- /dev/null +++ b/wm/test/unittest/window_test.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 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 FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H +#define FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H + +#include +#include "ability_context_impl.h" +#include "window.h" + +namespace OHOS { +namespace Rosen { +class WindowTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + virtual void SetUp() override; + virtual void TearDown() override; + static inline std::shared_ptr abilityContext_; +}; +} // namespace ROSEN +} // namespace OHOS + +#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H \ No newline at end of file diff --git a/wmtest/unittest/src/window_impl_test.cpp b/wmtest/unittest/src/window_impl_test.cpp deleted file mode 100644 index 3e6bd8b3a1..0000000000 --- a/wmtest/unittest/src/window_impl_test.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2021 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 "window_impl_test.h" -#include "mock/mock_window_adapter.h" -#include "mock/singleton_mocker.h" -#include "test_header.h" -#include "window_property.h" - - -namespace OHOS { -namespace Rosen { -using namespace testing; - -void WindowImplTest::SetUpTestCase() -{ - property_ = sptr(new WindowProperty()); - property_->SetWindowId(0); - window_ = sptr(new WindowImpl(property_)); -} - -void WindowImplTest::TearDownTestCase() -{ -} - -void WindowImplTest::SetUp() -{ -} - -void WindowImplTest::TearDown() -{ -} - -namespace { -/* - * Function: Show - * Type: Reliability - * Rank: Important(2) - * EnvConditions: N/A - * CaseDescription: 1. mock WindowAdapter - * 2. mock AddWindow return WM_OK - * 3. call Show to AddWindow and check return is WM_OK - * 4. call Show with isAdded_=true and check return is WM_OK - * 5. mock RemoveWindow return WM_OK - * 6. call Destroy check return is WM_OK - */ -HWTEST_F(WindowImplTest, ShowWindow01, testing::ext::TestSize.Level0) -{ - PART("CaseShow01") { -#ifdef _NEW_RENDERSERVER_ - using Mocker = SingletonMocker; - std::unique_ptr m = nullptr; - STEP("1. mock WindowAdapter") { - m = std::make_unique(); - } - - STEP("2. mock AddWindow return WM_OK") { - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - } - - STEP("3. call Show and check return is WM_OK") { - STEP_ASSERT_EQ(WMError::WM_OK, window_->Show()); - } - - STEP("4. mock RemoveWindow return WM_OK") { - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - } - - STEP("5. call Destroy check return is WM_OK") { - STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy()); - } -#endif - } -} - -/* - * Function: Show - * Type: Reliability - * Rank: Important(2) - * EnvConditions: N/A - * CaseDescription: 1. mock WindowAdapter - * 2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT - * 3. call Show to AddWindow and check return is WM_ERROR_DEATH_RECIPIENT - * 4. call Show with isAdded_=true and check return is WM_ERROR_DEATH_RECIPIENT - * 5. mock RemoveWindow return WM_OK - * 6. call Destroy check return is WM_OK - */ -HWTEST_F(WindowImplTest, ShowWindow02, testing::ext::TestSize.Level0) -{ - PART("CaseShow02") { -#ifdef _NEW_RENDERSERVER_ - using Mocker = SingletonMocker; - std::unique_ptr m = nullptr; - STEP("1. mock WindowAdapter") { - m = std::make_unique(); - } - - STEP("2. mock AddWindow return WM_ERROR_DEATH_RECIPIENT") { - EXPECT_CALL(m->Mock(), AddWindow(_)).Times(1).WillOnce(Return(WMError::WM_ERROR_DEATH_RECIPIENT)); - } - - STEP("3. call Show and check return is WM_ERROR_DEATH_RECIPIENT") { - STEP_ASSERT_EQ(WMError::WM_ERROR_DEATH_RECIPIENT, window_->Show()); - } - - STEP("4. mock RemoveWindow return WM_OK") { - EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK)); - } - - STEP("5. call Destroy check return is WM_OK") { - STEP_ASSERT_EQ(WMError::WM_OK, window_->Destroy()); - } -#endif - } -} -} -} // namespace Rosen -} // namespace OHOS \ No newline at end of file -- Gitee