mirror of
https://github.com/openharmony/windowmanager.git
synced 2026-07-21 04:25:28 -04:00
add window wm tests
Signed-off-by: qianlf <qianliangfang@huawei.com> Change-Id: Ic4809bc4348ceca21ad3c176d8c9c5f4850bdc8a
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
],
|
||||
|
||||
"test_list": [
|
||||
"//foundation/windowmanager/wm:test"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,3 +169,8 @@ ohos_shared_library("libwm") {
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
||||
group("test") {
|
||||
testonly = true
|
||||
deps = [ "test:test" ]
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
# 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("systemtest") {
|
||||
testonly = true
|
||||
|
||||
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" ]
|
||||
}
|
||||
|
||||
## SystemTest wm_window_multi_ability_test }}}
|
||||
|
||||
## SystemTest wm_window_subwindow_test {{{
|
||||
ohos_systemtest("wm_window_subwindow_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "window_subwindow_test.cpp" ]
|
||||
|
||||
deps = [ ":wm_systemtest_common" ]
|
||||
}
|
||||
|
||||
## SystemTest wm_window_subwindow_test }}}
|
||||
|
||||
## Build wm_systemtest_common.a {{{
|
||||
config("wm_systemtest_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_systemtest_common") {
|
||||
visibility = [ ":*" ]
|
||||
testonly = true
|
||||
|
||||
sources = [ "window_test_utils.cpp" ]
|
||||
|
||||
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",
|
||||
]
|
||||
|
||||
external_deps = [ "aafwk_standard:ability_context_native" ]
|
||||
}
|
||||
## Build wm_systemtest_common.a }}}
|
||||
@@ -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 <gtest/gtest.h>
|
||||
#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<sptr<Window>> activeWindows_;
|
||||
static vector<Rect> fullScreenExpecteds_;
|
||||
};
|
||||
|
||||
vector<Rect> 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>& 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<Window> appWin = utils::CreateTestWindow(info);
|
||||
activeWindows_.push_back(appWin);
|
||||
|
||||
// statusBar window
|
||||
sptr<Window> 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<Window> statBar = utils::CreateStatusBarWindow();
|
||||
activeWindows_.push_back(statBar);
|
||||
|
||||
// naviBar window
|
||||
sptr<Window> 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<Window> 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<Window> statBar = utils::CreateStatusBarWindow();
|
||||
activeWindows_.push_back(statBar);
|
||||
|
||||
// naviBar window
|
||||
sptr<Window> 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<Window> 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
|
||||
@@ -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 <gtest/gtest.h>
|
||||
#include <thread>
|
||||
#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<WindowScene> 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<WindowScene> 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<WindowScene> scene1 = utils::CreateWindowScene();
|
||||
sptr<WindowScene> scene2 = utils::CreateWindowScene();
|
||||
sptr<WindowScene> scene3 = utils::CreateWindowScene();
|
||||
sptr<WindowScene> scene4 = utils::CreateWindowScene();
|
||||
sptr<WindowScene> 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
|
||||
@@ -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 <gtest/gtest.h>
|
||||
|
||||
#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<WindowScene> CreateWindowScene()
|
||||
{
|
||||
sptr<IWindowLifeCycle> listener = nullptr;
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
|
||||
|
||||
sptr<WindowScene> scene = new WindowScene();
|
||||
scene->Init(0, abilityContext, listener);
|
||||
return scene;
|
||||
}
|
||||
|
||||
static sptr<Window> CreateSubWindow(sptr<WindowScene> scene, WindowType type,
|
||||
WindowMode mode, struct Rect rect, uint32_t flags)
|
||||
{
|
||||
sptr<WindowOption> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = 0;
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 2000, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 2000, 3000, 2000};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> subWindow = CreateSubWindow(scene, WindowType::WINDOW_TYPE_MEDIA,
|
||||
WindowMode::WINDOW_MODE_FLOATING, rect, flags);
|
||||
ASSERT_NE(nullptr, subWindow);
|
||||
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<WindowScene> scene = CreateWindowScene();
|
||||
|
||||
struct Rect rect = {0, 0, 100, 200};
|
||||
uint32_t flags = static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT);
|
||||
sptr<Window> 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<Window> mainWindow = scene->GetMainWindow();
|
||||
ASSERT_EQ(WMError::WM_OK, mainWindow->Destroy());
|
||||
ASSERT_EQ(WMError::WM_ERROR_DESTROYED_OBJECT, subWindow->Destroy());
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -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<Window> WindowTestUtils::CreateTestWindow(const TestWindowInfo& info)
|
||||
{
|
||||
sptr<WindowOption> 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 = Window::Create(info.name, option);
|
||||
return window;
|
||||
}
|
||||
|
||||
sptr<Window> 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<Window> 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<WindowScene> WindowTestUtils::CreateWindowScene()
|
||||
{
|
||||
sptr<IWindowLifeCycle> listener = nullptr;
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext = nullptr;
|
||||
|
||||
sptr<WindowScene> 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>& 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
|
||||
@@ -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<Window> CreateTestWindow(const TestWindowInfo& info);
|
||||
static sptr<Window> CreateStatusBarWindow();
|
||||
static sptr<Window> CreateNavigationBarWindow();
|
||||
static sptr<WindowScene> CreateWindowScene();
|
||||
static bool RectEqualTo(const sptr<Window>& window, const Rect& r);
|
||||
};
|
||||
} // namespace ROSEN
|
||||
} // namespace OHOS
|
||||
#endif // FRAMEWORKS_WM_TEST_ST_WINDOW_TEST_UTILS_H
|
||||
@@ -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 }}}
|
||||
@@ -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<WindowAdapter, MockWindowAdapter>;
|
||||
void InputTransferStationTest::SetUpTestCase()
|
||||
{
|
||||
std::unique_ptr<WindowMocker> m = std::make_unique<WindowMocker>();
|
||||
sptr<WindowOption> 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<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(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<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(InputEventListener());
|
||||
InputTransferStation::GetInstance().SetInputListener(windowId, listener);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -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 <gtest/gtest.h>
|
||||
#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<WindowImpl> window_;
|
||||
};
|
||||
} // namespace ROSEN
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_INPUT_TRANSFER_STATION_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_MOCK_STATIC_CALL_H
|
||||
#define FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H
|
||||
#include <gmock/gmock.h>
|
||||
|
||||
#include "ability_context_impl.h"
|
||||
#include "static_call.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class MockStaticCall : public StaticCall {
|
||||
public:
|
||||
MOCK_METHOD3(CreateWindow, sptr<Window>(const std::string& windowName,
|
||||
sptr<WindowOption>& option, std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext));
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_MOCK_STATIC_CALL_H+
|
||||
+7
-5
@@ -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 <gmock/gmock.h>
|
||||
|
||||
#include "window_adapter.h"
|
||||
@@ -24,12 +23,15 @@ namespace OHOS {
|
||||
namespace Rosen {
|
||||
class MockWindowAdapter : public WindowAdapter {
|
||||
public:
|
||||
MOCK_METHOD4(CreateWindow, WMError(sptr<IWindow>& window, sptr<WindowProperty>& windowProperty,
|
||||
std::shared_ptr<RSSurfaceNode> surfaceNode, uint32_t& windowId));
|
||||
MOCK_METHOD1(AddWindow, WMError(sptr<WindowProperty>& 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<IRemoteObject>& abilityToken, uint32_t windowId));
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
||||
|
||||
#endif
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_MOCK_WINDOW_ADAPTER_H
|
||||
+3
-3
@@ -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
|
||||
@@ -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<WindowAdapter, MockWindowAdapter>;
|
||||
void WindowImplTest::SetUpTestCase()
|
||||
{
|
||||
option_ = new WindowOption();
|
||||
option_->SetWindowName("WindowImplTest");
|
||||
window_ = new WindowImpl(option_);
|
||||
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
|
||||
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _, _)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
window_->Create("");
|
||||
}
|
||||
|
||||
void WindowImplTest::TearDownTestCase()
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("CreateWindow01");
|
||||
sptr<WindowImpl> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("CreateWindow02");
|
||||
sptr<WindowImpl> 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<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("CreateWindow03");
|
||||
sptr<WindowImpl> 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<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("WindowImplTest");
|
||||
sptr<WindowImpl> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("CreateWindow05");
|
||||
sptr<WindowImpl> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
sptr<WindowOption> 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<WindowImpl> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("CreateWindow07");
|
||||
sptr<WindowImpl> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("CreateWindow08");
|
||||
sptr<WindowImpl> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetWindowName("FindWindow02");
|
||||
sptr<WindowImpl> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
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<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
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<Mocker> m = std::make_unique<Mocker>();
|
||||
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<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), RemoveWindow(_)).Times(1).WillOnce(Return(WMError::WM_OK));
|
||||
ASSERT_EQ(WMError::WM_OK, window_->Hide());
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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_IMPL_TEST_H
|
||||
#define FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "ability_context_impl.h"
|
||||
#include "window_impl.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class WindowImplTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
static inline sptr<WindowImpl> window_ = nullptr;
|
||||
static inline sptr<WindowOption> option_ = nullptr;
|
||||
static inline std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
|
||||
};
|
||||
} // namespace ROSEN
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_IMPL_TEST_H
|
||||
@@ -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<WindowAdapter, MockWindowAdapter>;
|
||||
void WindowInputChannelTest::SetUpTestCase()
|
||||
{
|
||||
std::unique_ptr<WindowMocker> m = std::make_unique<WindowMocker>();
|
||||
sptr<WindowOption> 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<WindowInputChannel> 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<WindowInputChannel> 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<WindowInputChannel> inputChannel = new WindowInputChannel(window_);
|
||||
std::shared_ptr<MMI::IInputEventConsumer> listener = std::make_shared<InputEventListener>(InputEventListener());
|
||||
inputChannel->SetInputListener(listener);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
+6
-7
@@ -13,25 +13,24 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef UNITTEST_WINDOW_IMPL_TEST_H
|
||||
#define UNITTEST_WINDOW_IMPL_TEST_H
|
||||
#ifndef FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H
|
||||
#define FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "window_impl.h"
|
||||
#include "window_input_channel.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class WindowImplTest : public testing::Test {
|
||||
class WindowInputChannelTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
static inline sptr<Window> window_ = nullptr;
|
||||
static inline sptr<WindowProperty> property_ = nullptr;
|
||||
static inline sptr<WindowImpl> window_;
|
||||
};
|
||||
} // namespace ROSEN
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_WM_TEST_UNITTEST_WINDOW_IMPL_TEST_H
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_INPUT_CHANNEL_TEST_H
|
||||
@@ -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<WindowOption> 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<WindowOption> 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<WindowOption> 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<WindowOption> 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<WindowOption> 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<WindowOption> 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<WindowOption> 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<WindowOption> 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<WindowOption> 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<WindowOption> option = new WindowOption();
|
||||
option->AddWindowFlag(WindowFlag::WINDOW_FLAG_NEED_AVOID);
|
||||
ASSERT_EQ(static_cast<uint32_t>(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<WindowOption> 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<uint32_t>(WindowFlag::WINDOW_FLAG_PARENT_LIMIT), option->GetWindowFlags());
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -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 <gtest/gtest.h>
|
||||
#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
|
||||
@@ -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<StaticCall, MockStaticCall>;
|
||||
void WindowSceneTest::SetUpTestCase()
|
||||
{
|
||||
int displayId = 0;
|
||||
sptr<IWindowLifeCycle> listener = nullptr;
|
||||
scene_ = new WindowScene();
|
||||
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> optionTest = new WindowOption();
|
||||
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
|
||||
int displayId = 0;
|
||||
sptr<IWindowLifeCycle> listener = nullptr;
|
||||
sptr<WindowScene> scene = new WindowScene();
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> optionTest = new WindowOption();
|
||||
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(nullptr));
|
||||
int displayId = 0;
|
||||
sptr<IWindowLifeCycle> listener = nullptr;
|
||||
sptr<WindowScene> scene = new WindowScene();
|
||||
std::shared_ptr<AbilityRuntime::AbilityContext> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> optionTest = new WindowOption();
|
||||
EXPECT_CALL(m->Mock(), CreateWindow(_, _, _)).Times(1).WillOnce(Return(new WindowImpl(optionTest)));
|
||||
int displayId = 0;
|
||||
sptr<IWindowLifeCycle> listener = nullptr;
|
||||
sptr<WindowScene> 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<WindowOption> optionTest = new WindowOption();
|
||||
sptr<WindowScene> 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<WindowOption> optionTest = new WindowOption();
|
||||
sptr<WindowScene> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> 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<WindowOption> optionTest = new WindowOption();
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
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<WindowOption> 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<WindowScene> 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<WindowScene> 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<WindowScene> 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<WindowScene> scene = new WindowScene();
|
||||
ASSERT_EQ(WMError::WM_ERROR_NULLPTR, scene->RequestFocus());
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
@@ -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_WINDOW_SCENE_TEST_H
|
||||
#define FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#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<WindowScene> scene_ = nullptr;
|
||||
static inline std::shared_ptr<AbilityRuntime::AbilityContext> abilityContext_;
|
||||
};
|
||||
} // namespace ROSEN
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_SCENE_TEST_H
|
||||
@@ -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<WindowAdapter, MockWindowAdapter>;
|
||||
void WindowTest::SetUpTestCase()
|
||||
{
|
||||
abilityContext_ = std::make_shared<AbilityRuntime::AbilityContextImpl>();
|
||||
}
|
||||
|
||||
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<WindowOption> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> 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<WindowOption> 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<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<WindowOption> 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
|
||||
@@ -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 <gtest/gtest.h>
|
||||
#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<AbilityRuntime::AbilityContext> abilityContext_;
|
||||
};
|
||||
} // namespace ROSEN
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_WINDOW_TEST_H
|
||||
@@ -1,85 +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.
|
||||
|
||||
import("//build/test.gni")
|
||||
module_out_path = "window_manager/"
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":ut_window_impl_test" ]
|
||||
}
|
||||
|
||||
## UnitTest ut_window_impl_test {{{
|
||||
ohos_unittest("ut_window_impl_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "src/window_impl_test.cpp" ]
|
||||
|
||||
deps = [ ":unittest_wmtest_common" ]
|
||||
}
|
||||
|
||||
## UnitTest ut_window_impl_test }}}
|
||||
|
||||
## Build unittest_wmtest_common.a {{{
|
||||
config("unittest_wmtest_common_public_config") {
|
||||
include_dirs = [
|
||||
"//foundation/windowmanager/wm/include",
|
||||
"//foundation/windowmanager/wmserver/include",
|
||||
"include",
|
||||
"//foundation/windowmanager/interfaces/innerkits/wm",
|
||||
"//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",
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library("unittest_wmtest_common") {
|
||||
visibility = [ ":*" ]
|
||||
testonly = true
|
||||
|
||||
public_configs = [ ":unittest_wmtest_common_public_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/windowmanager/wm:libwm",
|
||||
"//foundation/windowmanager/wm:libwmutil",
|
||||
"//foundation/windowmanager/wmserver:libwms",
|
||||
"//third_party/googletest:gmock",
|
||||
"//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",
|
||||
]
|
||||
}
|
||||
## Build unittest_wmtest_common.a }}}
|
||||
@@ -1,43 +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.
|
||||
*/
|
||||
|
||||
#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
|
||||
@@ -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<WindowProperty>(new WindowProperty());
|
||||
property_->SetWindowId(0);
|
||||
window_ = sptr<Window>(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<WindowAdapter, MockWindowAdapter>;
|
||||
std::unique_ptr<Mocker> m = nullptr;
|
||||
STEP("1. mock WindowAdapter") {
|
||||
m = std::make_unique<Mocker>();
|
||||
}
|
||||
|
||||
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<WindowAdapter, MockWindowAdapter>;
|
||||
std::unique_ptr<Mocker> m = nullptr;
|
||||
STEP("1. mock WindowAdapter") {
|
||||
m = std::make_unique<Mocker>();
|
||||
}
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user