add UT of utils

Signed-off-by: realice <hanbing12@huawei.com>
Change-Id: I7384b4cf7e9c496a092c4e1ae9f42ae5a37b6252
This commit is contained in:
realice
2022-07-27 09:14:59 +08:00
parent d827dbcc22
commit 1b82a6745e
8 changed files with 625 additions and 1 deletions
+1 -1
View File
@@ -69,5 +69,5 @@ ohos_shared_library("libwmutil") {
group("test") {
testonly = true
deps = []
deps = [ "test:test" ]
}
+17
View File
@@ -0,0 +1,17 @@
# Copyright (c) 2022 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 = [ "unittest:unittest" ]
}
+107
View File
@@ -0,0 +1,107 @@
# Copyright (c) 2022 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")
import("//foundation/window/window_manager/windowmanager_aafwk.gni")
module_out_path = "window_manager/utils"
group("unittest") {
testonly = true
deps = [
":utils_display_info_test",
":utils_screen_group_info_test",
":utils_screen_info_test",
":utils_window_helper_test",
":utils_window_property_test",
]
}
ohos_unittest("utils_display_info_test") {
module_out_path = module_out_path
sources = [ "display_info_test.cpp" ]
deps = [ ":utils_unittest_common" ]
}
ohos_unittest("utils_screen_info_test") {
module_out_path = module_out_path
sources = [ "screen_info_test.cpp" ]
deps = [ ":utils_unittest_common" ]
external_deps = [ "graphic_standard:surface" ]
}
ohos_unittest("utils_screen_group_info_test") {
module_out_path = module_out_path
sources = [ "screen_group_info_test.cpp" ]
deps = [ ":utils_unittest_common" ]
external_deps = [ "graphic_standard:surface" ]
}
ohos_unittest("utils_window_property_test") {
module_out_path = module_out_path
sources = [ "window_property_test.cpp" ]
deps = [ ":utils_unittest_common" ]
}
ohos_unittest("utils_window_helper_test") {
module_out_path = module_out_path
sources = [ "window_helper_test.cpp" ]
deps = [ ":utils_unittest_common" ]
external_deps = [ "bundle_framework:appexecfwk_base" ]
}
## Build dm_unittest_common.a {{{
config("utils_unittest_common_public_config") {
include_dirs = [
"//foundation/window/window_manager/utils/include",
"//foundation/window/window_manager/dmserver/include",
"//foundation/window/window_manager/interfaces/innerkits/dm",
"//foundation/window/window_manager/interfaces/innerkits/wm",
"//foundation/window/window_manager/utils/include",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base/include",
]
}
ohos_static_library("utils_unittest_common") {
visibility = [ ":*" ]
testonly = true
public_configs = [ ":utils_unittest_common_public_config" ]
public_deps = [
"//foundation/graphic/graphic_2d/rosen/modules/2d_graphics:2d_graphics",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_base:librender_service_base",
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
"//foundation/window/window_manager/utils:libwmutil",
"//third_party/googletest:gmock",
"//third_party/googletest:gtest_main",
"//utils/native/base:utils",
]
subsystem_name = "window"
part_name = "window_manager"
}
## Build wm_unittest_common.a }}}
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include "display_info.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
class DisplayInfoTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
void DisplayInfoTest::SetUpTestCase()
{
}
void DisplayInfoTest::TearDownTestCase()
{
}
void DisplayInfoTest::SetUp()
{
}
void DisplayInfoTest::TearDown()
{
}
namespace {
/**
* @tc.name: MarshallingUnmarshalling
* @tc.desc: Marshalling Unmarshalling test
* @tc.type: FUNC
*/
HWTEST_F(DisplayInfoTest, MarshallingUnmarshalling, Function | SmallTest | Level2)
{
DisplayInfo displayInfoSrc;
displayInfoSrc.SetDisplayId(1);
Parcel parcel;
displayInfoSrc.Marshalling(parcel);
DisplayInfo* displayInfoDst = displayInfoSrc.Unmarshalling(parcel);
ASSERT_EQ(displayInfoDst->GetDisplayId(), 1);
delete displayInfoDst;
}
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include "screen_group_info.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
class ScreenGroupInfoTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
void ScreenGroupInfoTest::SetUpTestCase()
{
}
void ScreenGroupInfoTest::TearDownTestCase()
{
}
void ScreenGroupInfoTest::SetUp()
{
}
void ScreenGroupInfoTest::TearDown()
{
}
namespace {
/**
* @tc.name: MarshallingUnmarshalling
* @tc.desc: Marshalling Unmarshalling test
* @tc.type: FUNC
*/
HWTEST_F(ScreenGroupInfoTest, MarshallingUnmarshalling, Function | SmallTest | Level1)
{
std::vector<ScreenId> screenIds;
screenIds.push_back(1);
screenIds.push_back(2);
screenIds.push_back(3);
ScreenGroupInfo screenGroupInfoSrc;
screenGroupInfoSrc.SetChildren(screenIds);
Parcel parcel;
screenGroupInfoSrc.Marshalling(parcel);
ScreenGroupInfo* screenGroupInfoDst = screenGroupInfoSrc.Unmarshalling(parcel);
std::vector<ScreenId> screenIdsDst = screenGroupInfoDst->GetChildren();
ASSERT_EQ(screenIdsDst.size(), 3);
ASSERT_EQ(screenIdsDst[0], 1);
ASSERT_EQ(screenIdsDst[1], 2);
ASSERT_EQ(screenIdsDst[2], 3);
delete screenGroupInfoDst;
}
}
} // namespace Rosen
} // namespace OHOS
+69
View File
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include "screen_info.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
class ScreenInfoTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
void ScreenInfoTest::SetUpTestCase()
{
}
void ScreenInfoTest::TearDownTestCase()
{
}
void ScreenInfoTest::SetUp()
{
}
void ScreenInfoTest::TearDown()
{
}
namespace {
/**
* @tc.name: MarshallingUnmarshalling
* @tc.desc: Marshalling Unmarshalling test
* @tc.type: FUNC
*/
HWTEST_F(ScreenInfoTest, MarshallingUnmarshalling, Function | SmallTest | Level2)
{
ScreenInfo screenInfoSrc;
screenInfoSrc.SetScreenId(1);
Parcel parcel;
screenInfoSrc.Marshalling(parcel);
ScreenInfo* screenInfoDst = screenInfoSrc.Unmarshalling(parcel);
ASSERT_EQ(screenInfoDst->GetScreenId(), 1);
delete screenInfoDst;
}
}
} // namespace Rosen
} // namespace OHOS
+132
View File
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include "window_helper.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
class WindowHelperTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
void WindowHelperTest::SetUpTestCase()
{
}
void WindowHelperTest::TearDownTestCase()
{
}
void WindowHelperTest::SetUp()
{
}
void WindowHelperTest::TearDown()
{
}
namespace {
/**
* @tc.name: WindowTypeWindowMode
* @tc.desc: window type/mode test
* @tc.type: FUNC
*/
HWTEST_F(WindowHelperTest, WindowTypeWindowMode, Function | SmallTest | Level1)
{
ASSERT_EQ(true, WindowHelper::IsMainFullScreenWindow(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
WindowMode::WINDOW_MODE_FULLSCREEN));
ASSERT_EQ(false, WindowHelper::IsMainFullScreenWindow(WindowType::WINDOW_TYPE_APP_SUB_WINDOW,
WindowMode::WINDOW_MODE_FULLSCREEN));
ASSERT_EQ(false, WindowHelper::IsMainFullScreenWindow(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW,
WindowMode::WINDOW_MODE_SPLIT_PRIMARY));
ASSERT_EQ(true, WindowHelper::IsFloatingWindow(WindowMode::WINDOW_MODE_FLOATING));
ASSERT_EQ(false, WindowHelper::IsFloatingWindow(WindowMode::WINDOW_MODE_FULLSCREEN));
ASSERT_EQ(true, WindowHelper::IsFullScreenWindow(WindowMode::WINDOW_MODE_FULLSCREEN));
ASSERT_EQ(false, WindowHelper::IsFullScreenWindow(WindowMode::WINDOW_MODE_FLOATING));
}
/**
* @tc.name: WindowModeSupport
* @tc.desc: window mode supported test
* @tc.type: FUNC
*/
HWTEST_F(WindowHelperTest, WindowModeSupport, Function | SmallTest | Level1)
{
ASSERT_EQ(true, WindowHelper::IsWindowModeSupported(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL,
WindowMode::WINDOW_MODE_FULLSCREEN));
ASSERT_EQ(true, WindowHelper::IsWindowModeSupported(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL,
WindowMode::WINDOW_MODE_FLOATING));
ASSERT_EQ(true, WindowHelper::IsWindowModeSupported(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL,
WindowMode::WINDOW_MODE_SPLIT_PRIMARY));
ASSERT_EQ(true, WindowHelper::IsWindowModeSupported(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL,
WindowMode::WINDOW_MODE_SPLIT_SECONDARY));
ASSERT_EQ(true, WindowHelper::IsWindowModeSupported(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL,
WindowMode::WINDOW_MODE_PIP));
ASSERT_EQ(true, WindowHelper::IsWindowModeSupported(WindowModeSupport::WINDOW_MODE_SUPPORT_ALL,
WindowMode::WINDOW_MODE_UNDEFINED));
}
/**
* @tc.name: WindowRect
* @tc.desc: rect test
* @tc.type: FUNC
*/
HWTEST_F(WindowHelperTest, WindowRect, Function | SmallTest | Level1)
{
Rect rect0 = {0, 0, 0, 0};
ASSERT_EQ(true, WindowHelper::IsEmptyRect(rect0));
Rect rect1 = {0, 0, 1, 1};
ASSERT_EQ(false, WindowHelper::IsEmptyRect(rect1));
}
/**
* @tc.name: WindowStringUtil
* @tc.desc: string test
* @tc.type: FUNC
*/
HWTEST_F(WindowHelperTest, WindowStringUtil, Function | SmallTest | Level1)
{
ASSERT_EQ(true, WindowHelper::IsNumber("123"));
ASSERT_EQ(false, WindowHelper::IsNumber("1a3"));
ASSERT_EQ(false, WindowHelper::IsNumber(""));
ASSERT_EQ(true, WindowHelper::IsFloatingNumber("1.23"));
ASSERT_EQ(true, WindowHelper::IsFloatingNumber(".123"));
ASSERT_EQ(false, WindowHelper::IsFloatingNumber("1a3"));
ASSERT_EQ(false, WindowHelper::IsFloatingNumber("123.."));
std::vector<std::string> vec = WindowHelper::Split("123a123a123", "a");
for (size_t i = 0; i < vec.size(); i++) {
if (vec[i].compare("123")) {
ASSERT_TRUE(false);
}
}
ASSERT_TRUE(true);
}
}
} // namespace Rosen
} // namespace OHOS
@@ -0,0 +1,153 @@
/*
* Copyright (c) 2022 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 <gtest/gtest.h>
#include "window_property.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace Rosen {
class WindowPropertyTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
virtual void SetUp() override;
virtual void TearDown() override;
};
void WindowPropertyTest::SetUpTestCase()
{
}
void WindowPropertyTest::TearDownTestCase()
{
}
void WindowPropertyTest::SetUp()
{
}
void WindowPropertyTest::TearDown()
{
}
namespace {
/**
* @tc.name: MarshallingUnmarshalling
* @tc.desc: Marshalling Unmarshalling test
* @tc.type: FUNC
*/
HWTEST_F(WindowPropertyTest, MarshallingUnmarshalling, Function | SmallTest | Level2)
{
WindowProperty winPropSrc;
winPropSrc.SetPrivacyMode(true);
winPropSrc.SetTransparent(true);
winPropSrc.SetTransform(Transform::Identity());
Parcel parcel;
winPropSrc.Marshalling(parcel);
WindowProperty* winPropDst = winPropSrc.Unmarshalling(parcel);
ASSERT_EQ(winPropDst->GetPrivacyMode(), true);
ASSERT_EQ(winPropDst->GetTransparent(), true);
ASSERT_EQ(winPropDst->GetTransform(), Transform::Identity());
delete winPropDst;
}
/**
* @tc.name: CopyFrom
* @tc.desc: CopyFrom test
* @tc.type: FUNC
*/
HWTEST_F(WindowPropertyTest, CopyFrom, Function | SmallTest | Level2)
{
const sptr<WindowProperty> winPropSrc = new(std::nothrow) WindowProperty();
winPropSrc->SetPrivacyMode(true);
winPropSrc->SetTransparent(true);
winPropSrc->SetTransform(Transform::Identity());
WindowProperty winPropDst(winPropSrc); // winPropDst.CopyFrom(winPropSrc);
ASSERT_EQ(winPropSrc->GetPrivacyMode(), winPropDst.GetPrivacyMode());
ASSERT_EQ(winPropSrc->GetTransparent(), winPropDst.GetTransparent());
ASSERT_EQ(winPropSrc->GetTransform(), winPropDst.GetTransform());
}
/**
* @tc.name: Read
* @tc.desc: Read test
* @tc.type: FUNC
*/
HWTEST_F(WindowPropertyTest, Read, Function | SmallTest | Level2)
{
WindowProperty winPropSrc;
winPropSrc.SetPrivacyMode(true);
winPropSrc.SetTransparent(true);
Parcel parcel;
winPropSrc.Marshalling(parcel);
WindowProperty winPropDst;
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_RECT);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_MODE);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_FLAGS);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_FOCUSABLE);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCHABLE);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_ORIENTATION);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY);
winPropDst.Read(parcel, PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG);
ASSERT_EQ(false, winPropDst.GetPrivacyMode());
ASSERT_EQ(false, winPropDst.GetTransparent());
}
/**
* @tc.name: Write
* @tc.desc: Write test
* @tc.type: FUNC
*/
HWTEST_F(WindowPropertyTest, Write, Function | SmallTest | Level2)
{
Parcel parcel;
WindowProperty winPropDst;
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_RECT));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_MODE));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_FLAGS));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_FOCUSABLE));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCHABLE));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_ORIENTATION));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY));
ASSERT_EQ(true, winPropDst.Write(parcel, PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG));
}
}
} // namespace Rosen
} // namespace OHOS