mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-24 07:20:09 +00:00
commit
0cc6c19279
@ -121,9 +121,13 @@
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
"//foundation/window/window_manager/wm:test",
|
||||
"//foundation/window/window_manager/dm:test",
|
||||
"//foundation/window/window_manager/extension:test"
|
||||
"//foundation/window/window_manager/dmserver:test",
|
||||
"//foundation/window/window_manager/extension:test",
|
||||
"//foundation/window/window_manager/snapshot:test",
|
||||
"//foundation/window/window_manager/utils:test",
|
||||
"//foundation/window/window_manager/wm:test",
|
||||
"//foundation/window/window_manager/wmserver:test"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@ group("systemtest") {
|
||||
":dm_display_minimal_test",
|
||||
":dm_display_power_test",
|
||||
":dm_screen_manager_test",
|
||||
":dm_screenshot_cmd_test",
|
||||
":dm_screenshot_test",
|
||||
]
|
||||
}
|
||||
@ -70,24 +69,6 @@ ohos_systemtest("dm_screenshot_test") {
|
||||
|
||||
## SystemTest dm_screenshot_test }}}
|
||||
|
||||
## SystemTest dm_screenshot_cmd_test {{{
|
||||
ohos_systemtest("dm_screenshot_cmd_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
include_dirs = [ "//foundation/window/window_manager/snapshot" ]
|
||||
|
||||
sources = [
|
||||
"//foundation/window/window_manager/snapshot/snapshot_utils.cpp",
|
||||
"screenshot_cmd_test.cpp",
|
||||
]
|
||||
|
||||
deps = [ ":dm_systemtest_common" ]
|
||||
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
}
|
||||
|
||||
## SystemTest dm_screenshot_cmd_test }}}
|
||||
|
||||
## SystemTest dm_screen_manager_test {{{
|
||||
ohos_systemtest("dm_screen_manager_test") {
|
||||
module_out_path = module_out_path
|
||||
|
@ -24,7 +24,6 @@ group("unittest") {
|
||||
":dm_screen_manager_test",
|
||||
":dm_screen_test",
|
||||
":dm_screenshot_test",
|
||||
":dm_snapshot_utils_test",
|
||||
]
|
||||
}
|
||||
|
||||
@ -50,22 +49,6 @@ ohos_unittest("dm_display_power_unit_test") {
|
||||
|
||||
## UnitTest dm_snapshot_utils_test }}}
|
||||
|
||||
## UnitTest dm_snapshot_utils_test {{{
|
||||
ohos_unittest("dm_snapshot_utils_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [
|
||||
"//foundation/window/window_manager/snapshot/snapshot_utils.cpp",
|
||||
"snapshot_utils_test.cpp",
|
||||
]
|
||||
|
||||
deps = [ ":dm_unittest_common" ]
|
||||
|
||||
external_deps = [ "hitrace_native:hitrace_meter" ]
|
||||
}
|
||||
|
||||
## UnitTest dm_snapshot_utils_test }}}
|
||||
|
||||
## UnitTest dm_screenshot_test {{{
|
||||
ohos_unittest("dm_screenshot_test") {
|
||||
module_out_path = module_out_path
|
||||
|
@ -26,15 +26,19 @@ using Mocker = SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter>;
|
||||
|
||||
sptr<Display> ScreenTest::defaultDisplay_ = nullptr;
|
||||
ScreenId ScreenTest::defaultScreenId_ = SCREEN_ID_INVALID;
|
||||
sptr<Screen> ScreenTest::screen_ = nullptr;
|
||||
|
||||
void ScreenTest::SetUpTestCase()
|
||||
{
|
||||
defaultDisplay_ = DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
defaultScreenId_ = static_cast<ScreenId>(defaultDisplay_->GetId());
|
||||
screen_ = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
}
|
||||
|
||||
void ScreenTest::TearDownTestCase()
|
||||
{
|
||||
defaultDisplay_ = nullptr;
|
||||
screen_ = nullptr;
|
||||
}
|
||||
|
||||
void ScreenTest::SetUp()
|
||||
@ -46,6 +50,24 @@ void ScreenTest::TearDown()
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: GetBasicProperty01
|
||||
* @tc.desc: Basic property getter test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenTest, GetBasicProperty01, Function | SmallTest | Level1)
|
||||
{
|
||||
ASSERT_GT(screen_->GetName().size(), 0);
|
||||
ASSERT_GT(screen_->GetWidth(), 0);
|
||||
ASSERT_GT(screen_->GetHeight(), 0);
|
||||
ASSERT_GT(screen_->GetVirtualWidth(), 0);
|
||||
ASSERT_GT(screen_->GetVirtualHeight(), 0);
|
||||
ASSERT_GT(screen_->GetVirtualPixelRatio(), 0);
|
||||
ASSERT_EQ(screen_->GetRotation(), Rotation::ROTATION_0);
|
||||
ASSERT_EQ(screen_->IsReal(), true);
|
||||
ASSERT_NE(screen_->GetScreenInfo(), nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetScreenActiveMode01
|
||||
* @tc.desc: SetScreenActiveMode with valid modeId and return success
|
||||
@ -53,12 +75,11 @@ namespace {
|
||||
*/
|
||||
HWTEST_F(ScreenTest, SetScreenActiveMode01, Function | SmallTest | Level1)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
auto supportedModes = screen->GetSupportedModes();
|
||||
auto supportedModes = screen_->GetSupportedModes();
|
||||
ASSERT_GT(supportedModes.size(), 0);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(true));
|
||||
bool res = screen->SetScreenActiveMode(supportedModes.size() - 1);
|
||||
bool res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
|
||||
ASSERT_EQ(true, res);
|
||||
}
|
||||
|
||||
@ -69,12 +90,11 @@ HWTEST_F(ScreenTest, SetScreenActiveMode01, Function | SmallTest | Level1)
|
||||
*/
|
||||
HWTEST_F(ScreenTest, SetScreenActiveMode02, Function | SmallTest | Level1)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
auto supportedModes = screen->GetSupportedModes();
|
||||
auto supportedModes = screen_->GetSupportedModes();
|
||||
ASSERT_GT(supportedModes.size(), 0);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), SetScreenActiveMode(_, _)).Times(1).WillOnce(Return(false));
|
||||
bool res = screen->SetScreenActiveMode(supportedModes.size() - 1);
|
||||
bool res = screen_->SetScreenActiveMode(supportedModes.size() - 1);
|
||||
ASSERT_EQ(false, res);
|
||||
}
|
||||
|
||||
@ -85,11 +105,10 @@ HWTEST_F(ScreenTest, SetScreenActiveMode02, Function | SmallTest | Level1)
|
||||
*/
|
||||
HWTEST_F(ScreenTest, GetScreenSupportedColorGamuts01, Function | SmallTest | Level2)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), GetScreenSupportedColorGamuts(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
std::vector<ScreenColorGamut> colorGamuts;
|
||||
auto res = screen->GetScreenSupportedColorGamuts(colorGamuts);
|
||||
auto res = screen_->GetScreenSupportedColorGamuts(colorGamuts);
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
}
|
||||
|
||||
@ -100,11 +119,10 @@ HWTEST_F(ScreenTest, GetScreenSupportedColorGamuts01, Function | SmallTest | Lev
|
||||
*/
|
||||
HWTEST_F(ScreenTest, GetScreenColorGamut01, Function | SmallTest | Level2)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), GetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
|
||||
auto res = screen->GetScreenColorGamut(colorGamut);
|
||||
auto res = screen_->GetScreenColorGamut(colorGamut);
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
}
|
||||
|
||||
@ -115,11 +133,10 @@ HWTEST_F(ScreenTest, GetScreenColorGamut01, Function | SmallTest | Level2)
|
||||
*/
|
||||
HWTEST_F(ScreenTest, SetScreenColorGamut01, Function | SmallTest | Level2)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), SetScreenColorGamut(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
ScreenColorGamut colorGamut = ScreenColorGamut::COLOR_GAMUT_SRGB;
|
||||
auto res = screen->SetScreenColorGamut(colorGamut);
|
||||
auto res = screen_->SetScreenColorGamut(colorGamut);
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
}
|
||||
|
||||
@ -130,11 +147,10 @@ HWTEST_F(ScreenTest, SetScreenColorGamut01, Function | SmallTest | Level2)
|
||||
*/
|
||||
HWTEST_F(ScreenTest, GetScreenGamutMap01, Function | SmallTest | Level2)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), GetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
|
||||
auto res = screen->GetScreenGamutMap(gamutMap);
|
||||
auto res = screen_->GetScreenGamutMap(gamutMap);
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
}
|
||||
|
||||
@ -145,11 +161,10 @@ HWTEST_F(ScreenTest, GetScreenGamutMap01, Function | SmallTest | Level2)
|
||||
*/
|
||||
HWTEST_F(ScreenTest, SetScreenGamutMap01, Function | SmallTest | Level2)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), SetScreenGamutMap(_, _)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
ScreenGamutMap gamutMap = ScreenGamutMap::GAMUT_MAP_CONSTANT;
|
||||
auto res = screen->SetScreenGamutMap(gamutMap);
|
||||
auto res = screen_->SetScreenGamutMap(gamutMap);
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
}
|
||||
|
||||
@ -160,10 +175,9 @@ HWTEST_F(ScreenTest, SetScreenGamutMap01, Function | SmallTest | Level2)
|
||||
*/
|
||||
HWTEST_F(ScreenTest, SetScreenColorTransform01, Function | SmallTest | Level2)
|
||||
{
|
||||
auto screen = ScreenManager::GetInstance().GetScreenById(defaultScreenId_);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), SetScreenColorTransform(_)).Times(1).WillOnce(Return(DMError::DM_OK));
|
||||
auto res = screen->SetScreenColorTransform();
|
||||
auto res = screen_->SetScreenColorTransform();
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ public:
|
||||
|
||||
static sptr<Display> defaultDisplay_;
|
||||
static ScreenId defaultScreenId_;
|
||||
static sptr<Screen> screen_;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-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 "snapshot_utils_test.h"
|
||||
|
||||
#include "display_manager.h"
|
||||
#include "mock_display_manager_adapter.h"
|
||||
#include "singleton_mocker.h"
|
||||
#include "snapshot_utils.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
|
||||
void SnapshotUtilsTest::SetUpTestCase()
|
||||
{
|
||||
TestUtils::InjectTokenInfoByHapName(0, "com.ohos.systemui", 0);
|
||||
}
|
||||
|
||||
void SnapshotUtilsTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void SnapshotUtilsTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void SnapshotUtilsTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: Check01
|
||||
* @tc.desc: Check if default png is valid file names
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Check01, Function | SmallTest | Level3)
|
||||
{
|
||||
ASSERT_EQ(true, SnapShotUtils::CheckFileNameValid(defaultFile_));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Check02
|
||||
* @tc.desc: Check custom png is valid file names
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Check02, Function | SmallTest | Level3)
|
||||
{
|
||||
std::string fileName = "/data/test.png";
|
||||
ASSERT_EQ(true, SnapShotUtils::CheckFileNameValid(fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Check03
|
||||
* @tc.desc: Check random path is invalid file names
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Check03, Function | SmallTest | Level3)
|
||||
{
|
||||
std::string fileName = "/path/to/test/1.png";
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckFileNameValid(fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Write01
|
||||
* @tc.desc: Write default png using valid file names and valid PixelMap
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Write01, Function | SmallTest | Level3)
|
||||
{
|
||||
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManager::GetInstance().GetScreenshot(id);
|
||||
ASSERT_NE(nullptr, pixelMap);
|
||||
ASSERT_EQ(true, SnapShotUtils::WriteToPngWithPixelMap(defaultFile_, *pixelMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Write02
|
||||
* @tc.desc: Write default png using valid file names and valid WriteToPngParam
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Write02, Function | SmallTest | Level3)
|
||||
{
|
||||
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManager::GetInstance().GetScreenshot(id);
|
||||
ASSERT_NE(nullptr, pixelMap);
|
||||
WriteToPngParam param = {
|
||||
.width = pixelMap->GetWidth(),
|
||||
.height = pixelMap->GetHeight(),
|
||||
.data = pixelMap->GetPixels(),
|
||||
.stride = pixelMap->GetRowBytes(),
|
||||
.bitDepth = defaultBitDepth_
|
||||
};
|
||||
ASSERT_EQ(true, SnapShotUtils::WriteToPng(defaultFile_, param));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Write03
|
||||
* @tc.desc: Write custom png using valid file names and valid WriteToPngParam
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Write03, Function | SmallTest | Level3)
|
||||
{
|
||||
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManager::GetInstance().GetScreenshot(id);
|
||||
ASSERT_NE(nullptr, pixelMap);
|
||||
WriteToPngParam param = {
|
||||
.width = (pixelMap->GetWidth() / 2),
|
||||
.height = (pixelMap->GetWidth() / 2),
|
||||
.data = pixelMap->GetPixels(),
|
||||
.stride = pixelMap->GetRowBytes(),
|
||||
.bitDepth = defaultBitDepth_
|
||||
};
|
||||
ASSERT_EQ(true, SnapShotUtils::WriteToPng(defaultFile_, param));
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -77,3 +77,8 @@ ohos_shared_library("libdms") {
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
||||
group("test") {
|
||||
testonly = true
|
||||
deps = [ "test:test" ]
|
||||
}
|
||||
|
17
dmserver/test/BUILD.gn
Normal file
17
dmserver/test/BUILD.gn
Normal 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" ]
|
||||
}
|
83
dmserver/test/unittest/BUILD.gn
Normal file
83
dmserver/test/unittest/BUILD.gn
Normal file
@ -0,0 +1,83 @@
|
||||
# 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")
|
||||
|
||||
module_out_path = "window_manager/dmserver"
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
# ":dmserver_display_manager_config_test",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("dmserver_display_manager_config_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "display_manager_config_test.cpp" ]
|
||||
|
||||
deps = [ ":dmserver_unittest_common" ]
|
||||
}
|
||||
|
||||
## Build dmserver_unittest_common.a {{{
|
||||
config("dmserver_unittest_common_public_config") {
|
||||
include_dirs = [
|
||||
"//foundation/window/window_manager/dm/include",
|
||||
"//foundation/window/window_manager/dmserver/include",
|
||||
"//foundation/window/window_manager/snapshot",
|
||||
"//foundation/window/window_manager/interfaces/innerkits/dm",
|
||||
"//foundation/window/window_manager/dm/test/utils/",
|
||||
"//foundation/window/window_manager/utils/include",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client", # RSSurface
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library("dmserver_unittest_common") {
|
||||
visibility = [ ":*" ]
|
||||
testonly = true
|
||||
|
||||
public_configs = [ ":dmserver_unittest_common_public_config" ]
|
||||
|
||||
sources = [
|
||||
"../utils/test_utils.cpp",
|
||||
"screen_manager_utils.cpp",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/multimedia/image_standard/interfaces/innerkits:image_native", # PixelMap
|
||||
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//foundation/window/window_manager/dmserver:libdms",
|
||||
"//foundation/window/window_manager/snapshot:snapshot_display",
|
||||
"//foundation/window/window_manager/utils:libwmutil",
|
||||
"//foundation/window/window_manager/wm:libwm",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//third_party/libpng:libpng", # png
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
subsystem_name = "window"
|
||||
part_name = "window_manager"
|
||||
}
|
||||
## Build dmserver_unittest_common.a }}}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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
|
||||
@ -13,24 +13,49 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_DM_TEST_UT_SNAPSHOT_UTILS_TEST_H
|
||||
#define FRAMEWORKS_DM_TEST_UT_SNAPSHOT_UTILS_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "display.h"
|
||||
|
||||
#include "display_manager_config.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class SnapshotUtilsTest : public testing::Test {
|
||||
class DisplayManagerConfigTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
const std::string defaultFile_ = "/data/snapshot_display_1.png";
|
||||
const int defaultBitDepth_ = 8;
|
||||
};
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_DM_TEST_UT_SNAPSHOT_UTILS_TEST_H
|
||||
void DisplayManagerConfigTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayManagerConfigTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayManagerConfigTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayManagerConfigTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: Demo
|
||||
* @tc.desc: Demo
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerConfigTest, Demo, Function | SmallTest | Level1)
|
||||
{
|
||||
ASSERT_EQ(true, true);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -24,13 +24,12 @@ config("screen_runtime_config") {
|
||||
"//foundation/window/window_manager/interfaces/innerkits/wm",
|
||||
"//foundation/window/window_manager/wm/include",
|
||||
"//foundation/window/window_manager/utils/include",
|
||||
"//foundation/window/window_manager/snapshot",
|
||||
"//foundation/window/window_manager/snapshot/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_shared_library("screenrecorder_napi") {
|
||||
sources = [
|
||||
"//foundation/window/window_manager/snapshot/snapshot_utils.cpp",
|
||||
"napi/js_screen_recorder.cpp",
|
||||
"napi/screen_recorder.cpp",
|
||||
"napi/screen_recorder_module.cpp",
|
||||
@ -43,6 +42,7 @@ ohos_shared_library("screenrecorder_napi") {
|
||||
"${ability_runtime_path}/frameworks/native/appkit:appkit_native",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//foundation/window/window_manager/snapshot:libsnapshot_util",
|
||||
"//foundation/window/window_manager/utils:libwmutil",
|
||||
"//third_party/libpng:libpng", # png
|
||||
]
|
||||
|
@ -16,26 +16,21 @@ import("//build/ohos.gni")
|
||||
## Build snapshot {{{
|
||||
config("snapshot_config") {
|
||||
visibility = [ ":*" ]
|
||||
include_dirs = [ "include" ]
|
||||
}
|
||||
|
||||
ohos_executable("snapshot_display") {
|
||||
install_enable = true
|
||||
sources = [
|
||||
"snapshot_display.cpp",
|
||||
"snapshot_utils.cpp",
|
||||
]
|
||||
sources = [ "src/snapshot_display.cpp" ]
|
||||
|
||||
configs = [ ":snapshot_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//foundation/window/window_manager/utils:libwmutil",
|
||||
"//foundation/window/window_manager/wm:libwm",
|
||||
"//third_party/libpng:libpng", # png
|
||||
":libsnapshot_util",
|
||||
"../dm:libdm",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"hitrace_native:hitrace_meter",
|
||||
"multimedia_image_standard:image_native",
|
||||
"utils_base:utils",
|
||||
]
|
||||
@ -46,19 +41,29 @@ ohos_executable("snapshot_display") {
|
||||
|
||||
ohos_executable("snapshot_virtual_screen") {
|
||||
install_enable = false
|
||||
sources = [
|
||||
"snapshot_utils.cpp",
|
||||
"snapshot_virtual_screen.cpp",
|
||||
]
|
||||
sources = [ "src/snapshot_virtual_screen.cpp" ]
|
||||
|
||||
configs = [ ":snapshot_config" ]
|
||||
|
||||
deps = [
|
||||
":libsnapshot_util",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
]
|
||||
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
||||
ohos_shared_library("libsnapshot_util") {
|
||||
sources = [ "src/snapshot_utils.cpp" ]
|
||||
|
||||
configs = [ ":snapshot_config" ]
|
||||
|
||||
deps = [
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//foundation/window/window_manager/utils:libwmutil",
|
||||
"//foundation/window/window_manager/wm:libwm",
|
||||
"//third_party/libpng:libpng", # png
|
||||
"//third_party/libpng:libpng",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
@ -75,4 +80,5 @@ ohos_executable("snapshot_virtual_screen") {
|
||||
|
||||
group("test") {
|
||||
testonly = true
|
||||
deps = [ "test:test" ]
|
||||
}
|
||||
|
@ -20,9 +20,12 @@
|
||||
#include <pixel_map.h>
|
||||
#include <string>
|
||||
|
||||
#include "display_manager.h"
|
||||
#include "dm_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
constexpr int BPP = 4;
|
||||
|
||||
struct WriteToPngParam {
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
@ -49,13 +52,16 @@ public:
|
||||
static void PrintUsage(const std::string &cmdLine);
|
||||
static bool CheckFileNameValid(const std::string &fileName);
|
||||
static std::string GenerateFileName(int offset = 0);
|
||||
static bool CheckWidthAndHeightValid(const CmdArgments& cmdArgments);
|
||||
static bool CheckWidthAndHeightValid(int32_t w, int32_t h);
|
||||
static bool WriteToPng(const std::string &fileName, const WriteToPngParam ¶m);
|
||||
static bool WriteToPng(int fd, const WriteToPngParam ¶m);
|
||||
static bool WriteToPngWithPixelMap(const std::string &fileName, Media::PixelMap &pixelMap);
|
||||
static bool WriteToPngWithPixelMap(int fd, Media::PixelMap &pixelMap);
|
||||
static bool ProcessArgs(int argc, char * const argv[], CmdArgments& cmdArgments);
|
||||
static bool CheckWHValid(int32_t param);
|
||||
static bool CheckParamValid(const WriteToPngParam ¶m);
|
||||
private:
|
||||
static bool ProcessDisplayId(Rosen::DisplayId &displayId, bool isDisplayIdSet);
|
||||
};
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ int main(int argc, char *argv[])
|
||||
cmdArgments.height = display->GetHeight();
|
||||
std::cout << "process: reset to display's height " << cmdArgments.height << std::endl;
|
||||
}
|
||||
if (!SnapShotUtils::CheckWidthAndHeightValid(cmdArgments)) {
|
||||
if (!SnapShotUtils::CheckWidthAndHeightValid(cmdArgments.width, cmdArgments.height)) {
|
||||
std::cout << "error: width " << cmdArgments.width << " height " <<
|
||||
cmdArgments.height << " invalid!" << std::endl;
|
||||
return -1;
|
@ -31,15 +31,10 @@
|
||||
#include <string>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "display_manager.h"
|
||||
|
||||
|
||||
using namespace OHOS::Media;
|
||||
using namespace OHOS::Rosen;
|
||||
|
||||
namespace OHOS {
|
||||
constexpr int BITMAP_DEPTH = 8;
|
||||
constexpr int BPP = 4;
|
||||
constexpr int MAX_TIME_STR_LEN = 40;
|
||||
constexpr int YEAR_SINCE = 1900;
|
||||
|
||||
@ -112,28 +107,19 @@ bool SnapShotUtils::CheckFileNameValid(const std::string &fileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool CheckWHValid(int32_t param)
|
||||
bool SnapShotUtils::CheckWHValid(int32_t param)
|
||||
{
|
||||
if ((param <= 0) || (param > DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return (param > 0) && (param <= DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT);
|
||||
}
|
||||
|
||||
bool SnapShotUtils::CheckWidthAndHeightValid(const CmdArgments& cmdArgments)
|
||||
bool SnapShotUtils::CheckWidthAndHeightValid(int32_t w, int32_t h)
|
||||
{
|
||||
if (!CheckWHValid(cmdArgments.width) || !CheckWHValid(cmdArgments.height)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return CheckWHValid(w) && CheckWHValid(h);
|
||||
}
|
||||
|
||||
static bool CheckParamValid(const WriteToPngParam ¶m)
|
||||
bool SnapShotUtils::CheckParamValid(const WriteToPngParam ¶m)
|
||||
{
|
||||
if (param.width > DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT) {
|
||||
return false;
|
||||
}
|
||||
if (param.height > DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT) {
|
||||
if (!CheckWidthAndHeightValid(param.width, param.height)) {
|
||||
return false;
|
||||
}
|
||||
if (param.stride < BPP * param.width) {
|
||||
@ -249,7 +235,7 @@ bool SnapShotUtils::WriteToPng(int fd, const WriteToPngParam ¶m)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SnapShotUtils::WriteToPngWithPixelMap(const std::string &fileName, PixelMap &pixelMap)
|
||||
bool SnapShotUtils::WriteToPngWithPixelMap(const std::string &fileName, Media::PixelMap &pixelMap)
|
||||
{
|
||||
WriteToPngParam param;
|
||||
param.width = static_cast<uint32_t>(pixelMap.GetWidth());
|
||||
@ -271,7 +257,7 @@ bool SnapShotUtils::WriteToPngWithPixelMap(int fd, Media::PixelMap &pixelMap)
|
||||
return SnapShotUtils::WriteToPng(fd, param);
|
||||
}
|
||||
|
||||
static bool ProcessDisplayId(DisplayId &displayId, bool isDisplayIdSet)
|
||||
bool SnapShotUtils::ProcessDisplayId(Rosen::DisplayId &displayId, bool isDisplayIdSet)
|
||||
{
|
||||
if (!isDisplayIdSet) {
|
||||
displayId = DisplayManager::GetInstance().GetDefaultDisplayId();
|
@ -66,6 +66,10 @@ int main(int argc, char *argv[])
|
||||
ScreenManager::GetInstance().MakeMirror(mainId, mirrorIds);
|
||||
int fileIndex = 1;
|
||||
auto startTime = time(nullptr);
|
||||
if (startTime < 0) {
|
||||
std::cout << "startTime error!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
while (time(nullptr) - startTime < MAX_SNAPSHOT_COUNT) {
|
||||
int waitCount = 0;
|
||||
while (!surfaceReaderHandler->IsImageOk()) {
|
17
snapshot/test/BUILD.gn
Normal file
17
snapshot/test/BUILD.gn
Normal 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" ]
|
||||
}
|
88
snapshot/test/unittest/BUILD.gn
Normal file
88
snapshot/test/unittest/BUILD.gn
Normal file
@ -0,0 +1,88 @@
|
||||
# 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")
|
||||
|
||||
module_out_path = "window_manager/snapshot"
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
":snapshot_display_test",
|
||||
":snapshot_utils_test",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("snapshot_utils_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "snapshot_utils_test.cpp" ]
|
||||
|
||||
deps = [ ":utils_unittest_common" ]
|
||||
}
|
||||
|
||||
ohos_unittest("snapshot_display_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "snapshot_display_test.cpp" ]
|
||||
|
||||
deps = [ ":utils_unittest_common" ]
|
||||
}
|
||||
|
||||
## Build utils_unittest_common.a {{{
|
||||
config("utils_unittest_common_public_config") {
|
||||
include_dirs = [
|
||||
"//foundation/window/window_manager/dm/test/utils",
|
||||
"//foundation/window/window_manager/dmserver/include",
|
||||
"//foundation/window/window_manager/interfaces/innerkits/dm",
|
||||
"//foundation/window/window_manager/interfaces/innerkits/wm",
|
||||
"//foundation/window/window_manager/snapshot/include",
|
||||
"//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
|
||||
|
||||
sources =
|
||||
[ "//foundation/window/window_manager/dm/test/utils/test_utils.cpp" ]
|
||||
|
||||
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/dm:libdm",
|
||||
"//foundation/window/window_manager/snapshot:libsnapshot_util",
|
||||
"//foundation/window/window_manager/utils:libwmutil",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"access_token:libaccesstoken_sdk",
|
||||
"access_token:libnativetoken",
|
||||
"access_token:libtoken_setproc",
|
||||
"hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
|
||||
subsystem_name = "window"
|
||||
part_name = "window_manager"
|
||||
}
|
||||
## Build utils_unittest_common.a }}}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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
|
||||
@ -17,11 +17,11 @@
|
||||
#include <cstdlib>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "display_test_utils.h"
|
||||
#include "pixel_map.h"
|
||||
|
||||
#include "snapshot_utils.h"
|
||||
#include "test_utils.h"
|
||||
#include "window_manager_hilog.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -29,11 +29,10 @@ using namespace testing::ext;
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
namespace {
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenshotCmdTest"};
|
||||
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SnapshotDisplayTest"};
|
||||
}
|
||||
|
||||
using Utils = DisplayTestUtils;
|
||||
class ScreenshotCmdTest : public testing::Test {
|
||||
class SnapshotDisplayTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
@ -45,9 +44,9 @@ public:
|
||||
const int testTimeCount_ = 2;
|
||||
};
|
||||
|
||||
DisplayId ScreenshotCmdTest::defaultId_ = DISPLAY_ID_INVALID;
|
||||
DisplayId SnapshotDisplayTest::defaultId_ = DISPLAY_ID_INVALID;
|
||||
|
||||
void ScreenshotCmdTest::SetUpTestCase()
|
||||
void SnapshotDisplayTest::SetUpTestCase()
|
||||
{
|
||||
auto display = DisplayManager::GetInstance().GetDefaultDisplay();
|
||||
if (display == nullptr) {
|
||||
@ -62,15 +61,15 @@ void ScreenshotCmdTest::SetUpTestCase()
|
||||
TestUtils::InjectTokenInfoByHapName(0, "com.ohos.systemui", 0);
|
||||
}
|
||||
|
||||
void ScreenshotCmdTest::TearDownTestCase()
|
||||
void SnapshotDisplayTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void ScreenshotCmdTest::SetUp()
|
||||
void SnapshotDisplayTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void ScreenshotCmdTest::TearDown()
|
||||
void SnapshotDisplayTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
@ -86,13 +85,27 @@ bool CheckFileExist(const std::string& fPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TakeScreenshotBySpecifiedParam(std::string exec, std::string imgPath, std::string extraParam)
|
||||
{
|
||||
if (CheckFileExist(imgPath)) {
|
||||
remove(imgPath.c_str());
|
||||
}
|
||||
const std::string cmd = exec + " -f " + imgPath + " " + extraParam;
|
||||
(void)system(cmd.c_str());
|
||||
bool isExist = CheckFileExist(imgPath);
|
||||
if (isExist) {
|
||||
remove(imgPath.c_str());
|
||||
}
|
||||
return isExist;
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: ScreenShotCmdValid
|
||||
* @tc.desc: Call screenshot default cmd and check if it saves image in default path
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid01, Function | MediumTest | Level2)
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid01, Function | MediumTest | Level2)
|
||||
{
|
||||
std::string imgPath[testTimeCount_];
|
||||
int i;
|
||||
@ -121,7 +134,7 @@ HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid01, Function | MediumTest | Level2
|
||||
* @tc.desc: Call screenshot with default displayID and default path
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid02, Function | MediumTest | Level2)
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid02, Function | MediumTest | Level2)
|
||||
{
|
||||
std::string imgPath[testTimeCount_];
|
||||
int i;
|
||||
@ -151,19 +164,71 @@ HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid02, Function | MediumTest | Level2
|
||||
* @tc.desc: Call screenshot with default displayID and custom path
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenshotCmdTest, ScreenShotCmdValid03, Function | MediumTest | Level2)
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid03, Function | MediumTest | Level2)
|
||||
{
|
||||
const std::string imgPath = "/data/snapshot_display_test.png";
|
||||
if (CheckFileExist(imgPath)) {
|
||||
remove(imgPath.c_str());
|
||||
}
|
||||
const std::string cmd = defaultCmd_ + " -i " + std::to_string(defaultId_) + " -f " + imgPath;
|
||||
(void)system(cmd.c_str());
|
||||
bool isExist = CheckFileExist(imgPath);
|
||||
if (isExist) {
|
||||
remove(imgPath.c_str());
|
||||
}
|
||||
ASSERT_EQ(true, isExist);
|
||||
std::string extraParam = "-i " + std::to_string(defaultId_);
|
||||
ASSERT_EQ(true, TakeScreenshotBySpecifiedParam(defaultCmd_, imgPath, extraParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenShotCmdValid
|
||||
* @tc.desc: Call screenshot with valid width/height
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid04, Function | MediumTest | Level2)
|
||||
{
|
||||
const std::string imgPath = "/data/snapshot_display_test.png";
|
||||
std::string extraParam = "-i " + std::to_string(defaultId_) + " -w 100 -h 100";
|
||||
ASSERT_EQ(true, TakeScreenshotBySpecifiedParam(defaultCmd_, imgPath, extraParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenShotCmdValid
|
||||
* @tc.desc: Call screenshot with valid width
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid05, Function | MediumTest | Level2)
|
||||
{
|
||||
const std::string imgPath = "/data/snapshot_display_test.png";
|
||||
std::string extraParam = "-i " + std::to_string(defaultId_) + " -w 100";
|
||||
ASSERT_EQ(true, TakeScreenshotBySpecifiedParam(defaultCmd_, imgPath, extraParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenShotCmdValid
|
||||
* @tc.desc: Call screenshot with valid height
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid06, Function | MediumTest | Level2)
|
||||
{
|
||||
const std::string imgPath = "/data/snapshot_display_test.png";
|
||||
std::string extraParam = "-i " + std::to_string(defaultId_) + " -h 100";
|
||||
ASSERT_EQ(true, TakeScreenshotBySpecifiedParam(defaultCmd_, imgPath, extraParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenShotCmdValid
|
||||
* @tc.desc: Call screenshot with invalid width/height
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid07, Function | MediumTest | Level2)
|
||||
{
|
||||
const std::string imgPath = "/data/snapshot_display_test.png";
|
||||
std::string extraParam = "-i " + std::to_string(defaultId_) + " -w 10000 -h 10000";
|
||||
ASSERT_EQ(false, TakeScreenshotBySpecifiedParam(defaultCmd_, imgPath, extraParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ScreenShotCmdValid
|
||||
* @tc.desc: Call screenshot with -m
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotDisplayTest, ScreenShotCmdValid08, Function | MediumTest | Level2)
|
||||
{
|
||||
const std::string imgPath = "/data/snapshot_display_test.png";
|
||||
std::string extraParam = "-i " + std::to_string(defaultId_) + " -m";
|
||||
ASSERT_EQ(false, TakeScreenshotBySpecifiedParam(defaultCmd_, imgPath, extraParam));
|
||||
}
|
||||
} // namespace
|
||||
} // namespace Rosen
|
235
snapshot/test/unittest/snapshot_utils_test.cpp
Normal file
235
snapshot/test/unittest/snapshot_utils_test.cpp
Normal file
@ -0,0 +1,235 @@
|
||||
/*
|
||||
* 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.h"
|
||||
#include "display_manager.h"
|
||||
#include "snapshot_utils.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class SnapshotUtilsTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
const std::string defaultFile_ = "/data/snapshot_display_1.png";
|
||||
const int defaultBitDepth_ = 8;
|
||||
};
|
||||
|
||||
void SnapshotUtilsTest::SetUpTestCase()
|
||||
{
|
||||
TestUtils::InjectTokenInfoByHapName(0, "com.ohos.systemui", 0);
|
||||
}
|
||||
|
||||
void SnapshotUtilsTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void SnapshotUtilsTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void SnapshotUtilsTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: Check01
|
||||
* @tc.desc: Check if default png is valid file names
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Check01, Function | SmallTest | Level3)
|
||||
{
|
||||
ASSERT_EQ(true, SnapShotUtils::CheckFileNameValid(defaultFile_));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Check02
|
||||
* @tc.desc: Check custom png is valid file names
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Check02, Function | SmallTest | Level3)
|
||||
{
|
||||
std::string fileName = "/data/test.png";
|
||||
ASSERT_EQ(true, SnapShotUtils::CheckFileNameValid(fileName));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Check03
|
||||
* @tc.desc: Check random path is invalid file names
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Check03, Function | SmallTest | Level3)
|
||||
{
|
||||
std::string fileName1 = "/path/to/test/1.png";
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckFileNameValid(fileName1));
|
||||
std::string fileName2 = "";
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckFileNameValid(fileName2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Write01
|
||||
* @tc.desc: Write default png using valid file names and valid PixelMap
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Write01, Function | MediumTest | Level3)
|
||||
{
|
||||
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManager::GetInstance().GetScreenshot(id);
|
||||
ASSERT_NE(nullptr, pixelMap);
|
||||
ASSERT_EQ(true, SnapShotUtils::WriteToPngWithPixelMap(defaultFile_, *pixelMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Write02
|
||||
* @tc.desc: Write default png using valid file names and valid WriteToPngParam
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Write02, Function | MediumTest | Level3)
|
||||
{
|
||||
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManager::GetInstance().GetScreenshot(id);
|
||||
ASSERT_NE(nullptr, pixelMap);
|
||||
WriteToPngParam param = {
|
||||
.width = pixelMap->GetWidth(),
|
||||
.height = pixelMap->GetHeight(),
|
||||
.stride = pixelMap->GetRowBytes(),
|
||||
.bitDepth = defaultBitDepth_,
|
||||
.data = pixelMap->GetPixels()
|
||||
};
|
||||
ASSERT_EQ(true, SnapShotUtils::WriteToPng(defaultFile_, param));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Write03
|
||||
* @tc.desc: Write custom png using valid file names and valid WriteToPngParam
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Write03, Function | MediumTest | Level3)
|
||||
{
|
||||
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManager::GetInstance().GetScreenshot(id);
|
||||
ASSERT_NE(nullptr, pixelMap);
|
||||
WriteToPngParam param = {
|
||||
.width = (pixelMap->GetWidth() / 2),
|
||||
.height = (pixelMap->GetWidth() / 2),
|
||||
.stride = pixelMap->GetRowBytes(),
|
||||
.bitDepth = defaultBitDepth_,
|
||||
.data = pixelMap->GetPixels()
|
||||
};
|
||||
ASSERT_EQ(true, SnapShotUtils::WriteToPng(defaultFile_, param));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Write04
|
||||
* @tc.desc: Write pixel map with png, using fd
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, Write04, Function | MediumTest | Level3)
|
||||
{
|
||||
DisplayId id = DisplayManager::GetInstance().GetDefaultDisplayId();
|
||||
std::shared_ptr<Media::PixelMap> pixelMap = DisplayManager::GetInstance().GetScreenshot(id);
|
||||
ASSERT_EQ(true, SnapShotUtils::WriteToPngWithPixelMap(0, *pixelMap));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckWHValid
|
||||
* @tc.desc: Check width and height whether valid
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, CheckWHValid, Function | SmallTest | Level3)
|
||||
{
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckWHValid(0));
|
||||
ASSERT_EQ(true, SnapShotUtils::CheckWHValid(DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT));
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckWHValid(DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckParamValid01
|
||||
* @tc.desc: Check png param whether valid width
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, CheckParamValid01, Function | SmallTest | Level3)
|
||||
{
|
||||
WriteToPngParam paramInvalidWidth = {
|
||||
.width = DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT + 1,
|
||||
.height = 0,
|
||||
.stride = 0,
|
||||
.bitDepth = 0,
|
||||
.data = nullptr
|
||||
};
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckParamValid(paramInvalidWidth));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckParamValid02
|
||||
* @tc.desc: Check png param whether valid height
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, CheckParamValid02, Function | SmallTest | Level3)
|
||||
{
|
||||
WriteToPngParam paramInvalidHeight = {
|
||||
.width = DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT,
|
||||
.height = 0,
|
||||
.stride = 0,
|
||||
.bitDepth = 0,
|
||||
.data = nullptr
|
||||
};
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckParamValid(paramInvalidHeight));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckParamValid03
|
||||
* @tc.desc: Check png param whether valid stride
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, CheckParamValid03, Function | SmallTest | Level3)
|
||||
{
|
||||
WriteToPngParam paramInvalidStride = {
|
||||
.width = 256,
|
||||
.height = 256,
|
||||
.stride = 1,
|
||||
.bitDepth = 0,
|
||||
.data = nullptr
|
||||
};
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckParamValid(paramInvalidStride));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckParamValid04
|
||||
* @tc.desc: Check png param whether valid data
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(SnapshotUtilsTest, CheckParamValid04, Function | SmallTest | Level3)
|
||||
{
|
||||
WriteToPngParam paramInvalidData = {
|
||||
.width = 256,
|
||||
.height = 256,
|
||||
.stride = 256 * BPP,
|
||||
.bitDepth = 0,
|
||||
.data = nullptr
|
||||
};
|
||||
ASSERT_EQ(false, SnapShotUtils::CheckParamValid(paramInvalidData));
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -66,3 +66,8 @@ ohos_shared_library("libwmutil") {
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
||||
group("test") {
|
||||
testonly = true
|
||||
deps = []
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ namespace OHOS::Rosen {
|
||||
class DisplayInfo : public Parcelable {
|
||||
friend class AbstractDisplay;
|
||||
public:
|
||||
DisplayInfo() = default;
|
||||
~DisplayInfo() = default;
|
||||
WM_DISALLOW_COPY_AND_MOVE(DisplayInfo);
|
||||
|
||||
@ -49,9 +50,6 @@ public:
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, OffsetX, offsetX, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(int32_t, OffsetY, offsetY, 0);
|
||||
|
||||
protected:
|
||||
DisplayInfo() = default;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
#endif // FOUNDATION_DMSERVER_DISPLAY_INFO_H
|
@ -25,17 +25,17 @@ namespace OHOS::Rosen {
|
||||
class ScreenGroupInfo : public ScreenInfo {
|
||||
friend class AbstractScreenGroup;
|
||||
public:
|
||||
ScreenGroupInfo() = default;
|
||||
~ScreenGroupInfo() = default;
|
||||
WM_DISALLOW_COPY_AND_MOVE(ScreenGroupInfo);
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static ScreenGroupInfo* Unmarshalling(Parcel& parcel);
|
||||
|
||||
DEFINE_VAR_FUNC_GET(std::vector<ScreenId>, Children, children);
|
||||
DEFINE_VAR_FUNC_GET(std::vector<Point>, Position, position);
|
||||
DEFINE_VAR_FUNC_GET_SET(std::vector<ScreenId>, Children, children);
|
||||
DEFINE_VAR_FUNC_GET_SET(std::vector<Point>, Position, position);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenCombination, Combination, combination, ScreenCombination::SCREEN_ALONE);
|
||||
private:
|
||||
ScreenGroupInfo() = default;
|
||||
bool InnerUnmarshalling(Parcel& parcel);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -30,26 +30,26 @@ enum class ScreenType : uint32_t {
|
||||
class ScreenInfo : public Parcelable {
|
||||
friend class AbstractScreen;
|
||||
public:
|
||||
ScreenInfo() = default;
|
||||
~ScreenInfo() = default;
|
||||
WM_DISALLOW_COPY_AND_MOVE(ScreenInfo);
|
||||
|
||||
virtual bool Marshalling(Parcel& parcel) const override;
|
||||
static ScreenInfo* Unmarshalling(Parcel& parcel);
|
||||
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(std::string, Name, name, "");
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ScreenId, id, SCREEN_ID_INVALID);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, VirtualWidth, virtualWidth, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, VirtualHeight, virtualHeight, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(float, VirtualPixelRatio, virtualPixelRatio, 1.0f);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenId, ParentId, parent, SCREEN_ID_INVALID);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(bool, IsScreenGroup, isScreenGroup, false);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(Rotation, Rotation, rotation, Rotation::ROTATION_0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(ScreenType, Type, type, ScreenType::UNDEFINE);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET(uint32_t, ModeId, modeId, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(std::string, Name, name, "");
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(ScreenId, ScreenId, id, SCREEN_ID_INVALID);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, VirtualWidth, virtualWidth, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, VirtualHeight, virtualHeight, 0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(float, VirtualPixelRatio, virtualPixelRatio, 1.0f);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(ScreenId, ParentId, parent, SCREEN_ID_INVALID);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(bool, IsScreenGroup, isScreenGroup, false);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(Rotation, Rotation, rotation, Rotation::ROTATION_0);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(Orientation, Orientation, orientation, Orientation::UNSPECIFIED);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(ScreenType, Type, type, ScreenType::UNDEFINE);
|
||||
DEFINE_VAR_DEFAULT_FUNC_GET_SET(uint32_t, ModeId, modeId, 0);
|
||||
DEFINE_VAR_FUNC_GET(std::vector<sptr<SupportedScreenModes>>, Modes, modes);
|
||||
protected:
|
||||
ScreenInfo() = default;
|
||||
bool InnerUnmarshalling(Parcel& parcel);
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -19,7 +19,6 @@ group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [
|
||||
":avoid_area_controller_test",
|
||||
":wm_input_transfer_station_test",
|
||||
":wm_window_effect_test",
|
||||
":wm_window_impl_test",
|
||||
@ -31,17 +30,6 @@ group("unittest") {
|
||||
]
|
||||
}
|
||||
|
||||
## UnitTest avoid_area_controller_test {{{
|
||||
ohos_unittest("avoid_area_controller_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "avoid_area_controller_test.cpp" ]
|
||||
|
||||
deps = [ ":wm_unittest_common" ]
|
||||
}
|
||||
|
||||
## UnitTest avoid_area_controller_test }}}
|
||||
|
||||
## UnitTest wm_window_impl_test {{{
|
||||
ohos_unittest("wm_window_impl_test") {
|
||||
module_out_path = module_out_path
|
||||
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021-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.
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORKS_WM_TEST_UT_AVOID_AREA_CONTROLLER_TEST_H
|
||||
#define FRAMEWORKS_WM_TEST_UT_AVOID_AREA_CONTROLLER_TEST_H
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "window_node.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
class AvoidAreaControllerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
static sptr<WindowNode> statusbarWindowNode;
|
||||
static sptr<WindowNode> navigationBarWindowNode;
|
||||
static sptr<WindowNode> keyboardWindowNode;
|
||||
static Rect screenRect;
|
||||
static Rect cut_out_rect;
|
||||
};
|
||||
} // namespace ROSEN
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // FRAMEWORKS_WM_TEST_UT_AVOID_AREA_CONTROLLER_TEST_H
|
@ -286,6 +286,74 @@ HWTEST_F(WindowOptionTest, SetGetSystemBarProperty03, Function | SmallTest | Lev
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
ASSERT_EQ(SYS_BAR_PROPS_DEFAULT, option->GetSystemBarProperty());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HitOffset
|
||||
* @tc.desc: HitOffset setter/getter test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowOptionTest, HitOffset, Function | SmallTest | Level3)
|
||||
{
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetHitOffset(1, 1);
|
||||
PointInfo point = {1, 1};
|
||||
ASSERT_EQ(point.x, option->GetHitOffset().x);
|
||||
ASSERT_EQ(point.y, option->GetHitOffset().y);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: KeepScreenOn
|
||||
* @tc.desc: KeepScreenOn setter/getter test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowOptionTest, KeepScreenOn, Function | SmallTest | Level3)
|
||||
{
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetKeepScreenOn(true);
|
||||
ASSERT_EQ(true, option->IsKeepScreenOn());
|
||||
option->SetKeepScreenOn(false);
|
||||
ASSERT_EQ(false, option->IsKeepScreenOn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: TurnScreenOn
|
||||
* @tc.desc: TurnScreenOn setter/getter test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowOptionTest, TurnScreenOn, Function | SmallTest | Level3)
|
||||
{
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetTurnScreenOn(true);
|
||||
ASSERT_EQ(true, option->IsTurnScreenOn());
|
||||
option->SetTurnScreenOn(false);
|
||||
ASSERT_EQ(false, option->IsTurnScreenOn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Brightness
|
||||
* @tc.desc: Brightness setter/getter test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowOptionTest, Brightness, Function | SmallTest | Level3)
|
||||
{
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetBrightness(MINIMUM_BRIGHTNESS);
|
||||
ASSERT_EQ(MINIMUM_BRIGHTNESS, option->GetBrightness());
|
||||
option->SetBrightness(MAXIMUM_BRIGHTNESS);
|
||||
ASSERT_EQ(MAXIMUM_BRIGHTNESS, option->GetBrightness());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CallingWindow
|
||||
* @tc.desc: CallingWindow setter/getter test
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(WindowOptionTest, CallingWindow, Function | SmallTest | Level3)
|
||||
{
|
||||
sptr<WindowOption> option = new WindowOption();
|
||||
option->SetCallingWindow(1);
|
||||
ASSERT_EQ(1, option->GetCallingWindow());
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
||||
|
@ -105,3 +105,8 @@ ohos_shared_library("libwms") {
|
||||
part_name = "window_manager"
|
||||
subsystem_name = "window"
|
||||
}
|
||||
|
||||
group("test") {
|
||||
testonly = true
|
||||
deps = [ "test:test" ]
|
||||
}
|
||||
|
17
wmserver/test/BUILD.gn
Normal file
17
wmserver/test/BUILD.gn
Normal 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" ]
|
||||
}
|
98
wmserver/test/unittest/BUILD.gn
Normal file
98
wmserver/test/unittest/BUILD.gn
Normal file
@ -0,0 +1,98 @@
|
||||
# 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/wmserver"
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":wmsever_avoid_area_controller_test" ]
|
||||
}
|
||||
|
||||
ohos_unittest("wmsever_avoid_area_controller_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "avoid_area_controller_test.cpp" ]
|
||||
|
||||
deps = [ ":wmserver_unittest_common" ]
|
||||
}
|
||||
|
||||
## Build wmserver_unittest_common.a {{{
|
||||
config("wmserver_unittest_common_public_config") {
|
||||
include_dirs = [
|
||||
"//foundation/window/window_manager/wm/include",
|
||||
"//foundation/window/window_manager/wmserver/include",
|
||||
"//foundation/window/window_manager/wmserver/include/window_snapshot",
|
||||
"//foundation/window/window_manager/interfaces/innerkits/wm",
|
||||
"//foundation/window/window_manager/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
|
||||
"${ability_runtime_path}/interfaces/kits/native/ability/ability_runtime",
|
||||
"${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
|
||||
"//base/global/resource_management/interfaces/inner_api/include",
|
||||
"//third_party/node/deps/icu-small/source/common",
|
||||
"${ability_runtime_inner_api_path}/ability_manager/include",
|
||||
|
||||
# abilityContext end
|
||||
]
|
||||
|
||||
cflags = [
|
||||
"-Wall",
|
||||
"-Werror",
|
||||
"-g3",
|
||||
"-Dprivate=public",
|
||||
"-Dprotected=public",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_static_library("wmserver_unittest_common") {
|
||||
visibility = [ ":*" ]
|
||||
testonly = true
|
||||
|
||||
public_configs = [ ":wmserver_unittest_common_public_config" ]
|
||||
|
||||
public_deps = [
|
||||
"//base/powermgr/power_manager/interfaces/innerkits:powermgr_client",
|
||||
|
||||
# need delete it for abilitycontext
|
||||
"${ability_runtime_inner_api_path}/ability_manager:ability_manager",
|
||||
"//foundation/arkui/ace_engine/interfaces/inner_api/ace:ace_uicontent",
|
||||
"//foundation/arkui/napi:ace_napi",
|
||||
"//foundation/distributedschedule/safwk/interfaces/innerkits/safwk:system_ability_fwk",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/animation/window_animation:window_animation",
|
||||
"//foundation/graphic/graphic_2d/rosen/modules/render_service_client:librender_service_client",
|
||||
"//foundation/multimodalinput/input/frameworks/proxy:libmmi-client",
|
||||
"//foundation/window/window_manager/dm:libdm",
|
||||
"//foundation/window/window_manager/dmserver:libdms",
|
||||
"//foundation/window/window_manager/utils:libwmutil",
|
||||
"//foundation/window/window_manager/wm:libwm",
|
||||
"//foundation/window/window_manager/wmserver:libwms",
|
||||
"//third_party/googletest:gmock",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:want",
|
||||
"ability_runtime:ability_context_native",
|
||||
"bundle_framework:appexecfwk_base",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
## Build wmserver_unittest_common.a }}}
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021-2022 Huawei Device Co., Ltd.
|
||||
* 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
|
||||
@ -13,13 +13,14 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "avoid_area_controller_test.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "avoid_area_controller.h"
|
||||
#include "display_manager.h"
|
||||
#include "display_manager_config.h"
|
||||
#include "future.h"
|
||||
#include "singleton_mocker.h"
|
||||
#include "window_node.h"
|
||||
#include "wm_common.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -35,6 +36,20 @@ namespace {
|
||||
const AvoidArea EMPTY_AVOID_AREA = {};
|
||||
}
|
||||
|
||||
class AvoidAreaControllerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
virtual void SetUp() override;
|
||||
virtual void TearDown() override;
|
||||
|
||||
static sptr<WindowNode> statusbarWindowNode;
|
||||
static sptr<WindowNode> navigationBarWindowNode;
|
||||
static sptr<WindowNode> keyboardWindowNode;
|
||||
static Rect screenRect;
|
||||
static Rect cut_out_rect;
|
||||
};
|
||||
|
||||
sptr<WindowNode> AvoidAreaControllerTest::statusbarWindowNode = nullptr;
|
||||
sptr<WindowNode> AvoidAreaControllerTest::navigationBarWindowNode = nullptr;
|
||||
sptr<WindowNode> AvoidAreaControllerTest::keyboardWindowNode = nullptr;
|
||||
@ -141,14 +156,23 @@ void AvoidAreaControllerTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
#define CHECK_AVOID_AREA(avoidArea, topRect, leftRect, rightRect, bottomRect) \
|
||||
do { \
|
||||
ASSERT_EQ(avoidArea.topRect_, topRect); \
|
||||
ASSERT_EQ(avoidArea.bottomRect_, bottomRect); \
|
||||
ASSERT_EQ(avoidArea.leftRect_, leftRect); \
|
||||
ASSERT_EQ(avoidArea.rightRect_, rightRect); \
|
||||
} while (false)
|
||||
bool CheckSameArea(AvoidArea avoidArea, Rect t, Rect l, Rect r, Rect b)
|
||||
{
|
||||
return avoidArea.topRect_ == t && avoidArea.bottomRect_ == b
|
||||
&& avoidArea.leftRect_ == l && avoidArea.rightRect_ == r;
|
||||
}
|
||||
|
||||
sptr<WindowProperty> createWindowProperty(uint32_t windowId, const std::string& windowName,
|
||||
WindowType type, WindowMode mode, const Rect& screenRect)
|
||||
{
|
||||
sptr<WindowProperty> property = new WindowProperty();
|
||||
property->SetWindowId(windowId);
|
||||
property->SetWindowName(windowName);
|
||||
property->SetWindowType(type);
|
||||
property->SetWindowMode(mode);
|
||||
property->SetWindowRect(screenRect);
|
||||
return property;
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
@ -158,12 +182,8 @@ namespace {
|
||||
*/
|
||||
HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea01, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<WindowProperty> property = new WindowProperty();
|
||||
property->SetWindowId(110u);
|
||||
property->SetWindowName("test");
|
||||
property->SetWindowType(WindowType::APP_WINDOW_BASE);
|
||||
property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
|
||||
property->SetWindowRect(screenRect);
|
||||
sptr<WindowProperty> property = createWindowProperty(110u, "test",
|
||||
WindowType::APP_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, screenRect);
|
||||
sptr<WindowListener> listener = new WindowListener();
|
||||
sptr<WindowNode> appWindow = new WindowNode(property, listener, nullptr);
|
||||
uint32_t focusedWindow = appWindow->GetWindowId();
|
||||
@ -172,10 +192,10 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea01, Function | Smal
|
||||
avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
auto avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(),
|
||||
EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(),
|
||||
EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()));
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_CUTOUT);
|
||||
CHECK_AVOID_AREA(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// set rect
|
||||
Rect statusBarRect = statusbarWindowNode->GetWindowRect();
|
||||
@ -184,23 +204,23 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea01, Function | Smal
|
||||
static_cast<uint32_t>(navigationBarRect.posY_ - statusBarRect.height_) };
|
||||
property->SetWindowRect(windowRect);
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_CUTOUT);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// restore rect
|
||||
property->SetWindowRect(screenRect);
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(),
|
||||
EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(),
|
||||
EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()));
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_CUTOUT);
|
||||
CHECK_AVOID_AREA(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_SYSTEM);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,12 +230,8 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea01, Function | Smal
|
||||
*/
|
||||
HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea02, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<WindowProperty> property = new WindowProperty();
|
||||
property->SetWindowId(110u);
|
||||
property->SetWindowName("test");
|
||||
property->SetWindowType(WindowType::APP_WINDOW_BASE);
|
||||
property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
|
||||
property->SetWindowRect(screenRect);
|
||||
sptr<WindowProperty> property = createWindowProperty(110u, "test",
|
||||
WindowType::APP_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, screenRect);
|
||||
sptr<WindowListener> windowListener = new WindowListener();
|
||||
sptr<WindowNode> appWindow = new WindowNode(property, windowListener, nullptr);
|
||||
uint32_t focusedWindow = appWindow->GetWindowId();
|
||||
@ -227,14 +243,15 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea02, Function | Smal
|
||||
avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
auto avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(),
|
||||
EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// add navigation bar
|
||||
avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, navigationBarWindowNode->GetWindowRect()));
|
||||
|
||||
// update appWindow rect
|
||||
Rect statusBarRect = statusbarWindowNode->GetWindowRect();
|
||||
@ -245,21 +262,21 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea02, Function | Smal
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
avoidArea = windowListener->cutoutAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->cutoutAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// restore appWindow rect
|
||||
property->SetWindowRect(screenRect);
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(),
|
||||
EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(),
|
||||
EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect()));
|
||||
avoidArea = windowListener->cutoutAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->cutoutAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, cut_out_rect, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
@ -273,12 +290,8 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea02, Function | Smal
|
||||
*/
|
||||
HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea03, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<WindowProperty> property = new WindowProperty();
|
||||
property->SetWindowId(110u);
|
||||
property->SetWindowName("test");
|
||||
property->SetWindowType(WindowType::APP_WINDOW_BASE);
|
||||
property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
|
||||
property->SetWindowRect(screenRect);
|
||||
sptr<WindowProperty> property = createWindowProperty(110u, "test",
|
||||
WindowType::APP_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, screenRect);
|
||||
sptr<WindowListener> windowListener = new WindowListener();
|
||||
sptr<WindowNode> appWindow = new WindowNode(property, windowListener, nullptr);
|
||||
uint32_t focusedWindow = appWindow->GetWindowId();
|
||||
@ -290,29 +303,31 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea03, Function | Smal
|
||||
avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
auto avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// add navigation bar
|
||||
avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, navigationBarWindowNode->GetWindowRect()));
|
||||
|
||||
// remove status bar
|
||||
avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT,
|
||||
navigationBarWindowNode->GetWindowRect()));
|
||||
avoidArea = windowListener->cutoutAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->cutoutAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// remove navigation bar
|
||||
avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
}
|
||||
|
||||
@ -323,12 +338,8 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAndCutOutAvoidArea03, Function | Smal
|
||||
*/
|
||||
HWTEST_F(AvoidAreaControllerTest, SystemBarAvoidArea01, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<WindowProperty> property = new WindowProperty();
|
||||
property->SetWindowId(110u);
|
||||
property->SetWindowName("test");
|
||||
property->SetWindowType(WindowType::APP_WINDOW_BASE);
|
||||
property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
|
||||
property->SetWindowRect(screenRect);
|
||||
sptr<WindowProperty> property = createWindowProperty(110u, "test",
|
||||
WindowType::APP_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, screenRect);
|
||||
sptr<WindowListener> windowListener = new WindowListener();
|
||||
sptr<WindowNode> appWindow = new WindowNode(property, windowListener, nullptr);
|
||||
uint32_t focusedWindow = appWindow->GetWindowId();
|
||||
@ -345,7 +356,8 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAvoidArea01, Function | SmallTest | L
|
||||
[](sptr<WindowNode> windowNode) { return true; });
|
||||
auto avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT,
|
||||
navigationBarWindowNode->GetWindowRect()));
|
||||
|
||||
// update navigation bar window Rect
|
||||
Rect navigationBarWindowNodeRect = navigationBarWindowNode->GetWindowRect();
|
||||
@ -354,34 +366,36 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAvoidArea01, Function | SmallTest | L
|
||||
[](sptr<WindowNode> windowNode) { return true; });
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// restore status bar window Rect
|
||||
statusbarWindowNode->SetWindowRect(statusbarWindowNodeRect);
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
// restore navigation bar window Rect
|
||||
navigationBarWindowNode->SetWindowRect(navigationBarWindowNodeRect);
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_UPDATE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, statusbarWindowNode->GetWindowRect(), EMPTY_RECT,
|
||||
EMPTY_RECT, navigationBarWindowNode->GetWindowRect()));
|
||||
|
||||
// remove status bar
|
||||
avoidAreaController->ProcessWindowChange(statusbarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, navigationBarWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT,
|
||||
navigationBarWindowNode->GetWindowRect()));
|
||||
|
||||
// remove navigation bar
|
||||
avoidAreaController->ProcessWindowChange(navigationBarWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidArea = windowListener->statusBarAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
windowListener->statusBarAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -391,12 +405,8 @@ HWTEST_F(AvoidAreaControllerTest, SystemBarAvoidArea01, Function | SmallTest | L
|
||||
*/
|
||||
HWTEST_F(AvoidAreaControllerTest, KeyboardAvoidArea01, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<WindowProperty> property = new WindowProperty();
|
||||
property->SetWindowId(110u);
|
||||
property->SetWindowName("test");
|
||||
property->SetWindowType(WindowType::APP_WINDOW_BASE);
|
||||
property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
|
||||
property->SetWindowRect(screenRect);
|
||||
sptr<WindowProperty> property = createWindowProperty(110u, "test",
|
||||
WindowType::APP_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, screenRect);
|
||||
sptr<WindowListener> listener = new WindowListener();
|
||||
sptr<WindowNode> appWindow = new WindowNode(property, listener, nullptr);
|
||||
uint32_t focusedWindow = 0u;
|
||||
@ -410,20 +420,22 @@ HWTEST_F(AvoidAreaControllerTest, KeyboardAvoidArea01, Function | SmallTest | Le
|
||||
appWindow->SetWindowMode(static_cast<WindowMode>(i));
|
||||
avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
auto avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
|
||||
keyboardWindowNode->SetCallingWindow(appWindow->GetWindowId());
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, keyboardWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT,
|
||||
keyboardWindowNode->GetWindowRect()));
|
||||
|
||||
keyboardWindowNode->SetCallingWindow(0);
|
||||
focusedWindow = appWindow->GetWindowId();
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, keyboardWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT,
|
||||
keyboardWindowNode->GetWindowRect()));
|
||||
|
||||
avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidArea = avoidAreaController->GetAvoidAreaByType(appWindow, AvoidAreaType::TYPE_KEYBOARD);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
}
|
||||
}
|
||||
|
||||
@ -434,12 +446,8 @@ HWTEST_F(AvoidAreaControllerTest, KeyboardAvoidArea01, Function | SmallTest | Le
|
||||
*/
|
||||
HWTEST_F(AvoidAreaControllerTest, KeyboardAvoidArea02, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<WindowProperty> property = new WindowProperty();
|
||||
property->SetWindowId(110u);
|
||||
property->SetWindowName("test");
|
||||
property->SetWindowType(WindowType::APP_WINDOW_BASE);
|
||||
property->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN);
|
||||
property->SetWindowRect(screenRect);
|
||||
sptr<WindowProperty> property = createWindowProperty(110u, "test",
|
||||
WindowType::APP_WINDOW_BASE, WindowMode::WINDOW_MODE_FULLSCREEN, screenRect);
|
||||
sptr<WindowListener> listener = new WindowListener();
|
||||
sptr<WindowNode> appWindow = new WindowNode(property, listener, nullptr);
|
||||
uint32_t focusedWindow = appWindow->GetWindowId();
|
||||
@ -452,11 +460,12 @@ HWTEST_F(AvoidAreaControllerTest, KeyboardAvoidArea02, Function | SmallTest | Le
|
||||
avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_ADD, nullptr);
|
||||
auto avoidArea = listener->keyboardAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
listener->keyboardAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, keyboardWindowNode->GetWindowRect());
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT,
|
||||
keyboardWindowNode->GetWindowRect()));
|
||||
avoidAreaController->ProcessWindowChange(keyboardWindowNode, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
avoidArea = listener->keyboardAvoidAreaFuture_.GetResult(TIME_OUT);
|
||||
listener->keyboardAvoidAreaFuture_.Reset(EMPTY_AVOID_AREA);
|
||||
CHECK_AVOID_AREA(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT);
|
||||
ASSERT_EQ(true, CheckSameArea(avoidArea, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT, EMPTY_RECT));
|
||||
}
|
||||
avoidAreaController->ProcessWindowChange(appWindow, AvoidControlType::AVOID_NODE_REMOVE, nullptr);
|
||||
}
|
@ -1,38 +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 "inative_test.h"
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
void INativeTest::VisitTests(VisitTestFunc func)
|
||||
{
|
||||
auto sortFunc = [](const auto &it, const auto &jt) {
|
||||
if (it->GetDomain() == jt->GetDomain()) {
|
||||
return it->GetID() < jt->GetID();
|
||||
}
|
||||
return it->GetDomain() < jt->GetDomain();
|
||||
};
|
||||
std::sort(nativeTest_.begin(), nativeTest_.end(), sortFunc);
|
||||
|
||||
for (auto &test : nativeTest_) {
|
||||
func(test);
|
||||
}
|
||||
}
|
||||
|
||||
INativeTest::INativeTest()
|
||||
{
|
||||
nativeTest_.push_back(this);
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
@ -1,44 +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 OHOS_ROSEN_INATIVE_TEST_H
|
||||
#define OHOS_ROSEN_INATIVE_TEST_H
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace OHOS::Rosen {
|
||||
class INativeTest;
|
||||
using VisitTestFunc = std::function<void(INativeTest *)>;
|
||||
|
||||
class INativeTest {
|
||||
public:
|
||||
static constexpr uint32_t LAST_TIME_FOREVER = 999999999,
|
||||
|
||||
static void VisitTests(VisitTestFunc func);
|
||||
INativeTest();
|
||||
virtual ~INativeTest() = default;
|
||||
|
||||
virtual std::string GetDescription() const = 0;
|
||||
virtual std::string GetDomain() const = 0;
|
||||
virtual int32_t GetID() const = 0;
|
||||
virtual uint32_t GetLastTime() const = 0;
|
||||
virtual void Run(int32_t argc, const char **argv) = 0;
|
||||
private:
|
||||
static inline std::vector<INativeTest *> nativeTest_;
|
||||
};
|
||||
} // namespace OHOS::Rosen
|
||||
|
||||
#endif // OHOS_ROSEN_INATIVE_TEST_H
|
Loading…
Reference in New Issue
Block a user