mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-24 07:20:09 +00:00
[UT] new display_manager_agent_stub_test
Signed-off-by: leafly2021 <figo.yefei@huawei.com> Change-Id: Ia97adc028e46737657b9cfad78bf0d10ee2c87dd
This commit is contained in:
parent
f3a6d6f8bb
commit
9dd689101a
@ -60,6 +60,7 @@ private:
|
||||
void NotifyDisplayDestroy(DisplayId);
|
||||
void NotifyDisplayChange(sptr<DisplayInfo> displayInfo);
|
||||
bool UpdateDisplayInfoLocked(sptr<DisplayInfo>);
|
||||
void Clear();
|
||||
|
||||
std::map<DisplayId, sptr<Display>> displayMap_;
|
||||
DisplayStateCallback displayStateCallback_;
|
||||
@ -186,32 +187,39 @@ private:
|
||||
|
||||
bool DisplayManager::Impl::CheckRectValid(const Media::Rect& rect, int32_t oriHeight, int32_t oriWidth) const
|
||||
{
|
||||
if (!((rect.left >= 0) && (rect.left < oriWidth) && (rect.top >= 0) && (rect.top < oriHeight))) {
|
||||
WLOGFE("rect left or top invalid!");
|
||||
if (rect.left < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!((rect.width > 0) && (rect.width <= (oriWidth - rect.left)) &&
|
||||
(rect.height > 0) && (rect.height <= (oriHeight - rect.top)))) {
|
||||
if (!((rect.width == 0) && (rect.height == 0))) {
|
||||
WLOGFE("rect height or width invalid!");
|
||||
return false;
|
||||
}
|
||||
if (rect.top < 0) {
|
||||
return false;
|
||||
}
|
||||
if (rect.width < 0) {
|
||||
return false;
|
||||
}
|
||||
if (rect.height < 0) {
|
||||
return false;
|
||||
}
|
||||
if (rect.width + rect.left > oriWidth) {
|
||||
return false;
|
||||
}
|
||||
if (rect.height + rect.top > oriHeight) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DisplayManager::Impl::CheckSizeValid(const Media::Size& size, int32_t oriHeight, int32_t oriWidth) const
|
||||
{
|
||||
if (!((size.width > 0) && (size.height > 0))) {
|
||||
if (!((size.width == 0) && (size.height == 0))) {
|
||||
WLOGFE("width or height invalid!");
|
||||
return false;
|
||||
}
|
||||
if (size.width < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((size.width > MAX_RESOLUTION_SIZE_SCREENSHOT) or (size.height > MAX_RESOLUTION_SIZE_SCREENSHOT)) {
|
||||
WLOGFE("width or height too big!");
|
||||
if (size.height < 0) {
|
||||
return false;
|
||||
}
|
||||
if (size.width > MAX_RESOLUTION_SIZE_SCREENSHOT) {
|
||||
return false;
|
||||
}
|
||||
if (size.height > MAX_RESOLUTION_SIZE_SCREENSHOT) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -228,7 +236,7 @@ void DisplayManager::Impl::ClearDisplayStateCallback()
|
||||
}
|
||||
}
|
||||
|
||||
DisplayManager::Impl::~Impl()
|
||||
void DisplayManager::Impl::Clear()
|
||||
{
|
||||
std::lock_guard<std::recursive_mutex> lock(mutex_);
|
||||
bool res = true;
|
||||
@ -252,6 +260,11 @@ DisplayManager::Impl::~Impl()
|
||||
ClearDisplayStateCallback();
|
||||
}
|
||||
|
||||
DisplayManager::Impl::~Impl()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
DisplayManager::DisplayManager() : pImpl_(new Impl())
|
||||
{
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ group("unittest") {
|
||||
deps = [
|
||||
":dm_display_change_unit_test",
|
||||
":dm_display_manager_adapter_test",
|
||||
":dm_display_manager_agent_stub_test",
|
||||
":dm_display_manager_test",
|
||||
":dm_display_power_unit_test",
|
||||
":dm_display_test",
|
||||
@ -98,15 +99,26 @@ ohos_unittest("dm_display_manager_adapter_test") {
|
||||
ohos_unittest("dm_display_manager_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
include_dirs = [ "//foundation/window/window_manager/dm/src" ]
|
||||
|
||||
sources = [ "display_manager_test.cpp" ]
|
||||
|
||||
deps = [ ":dm_unittest_common" ]
|
||||
}
|
||||
|
||||
ohos_unittest("dm_display_manager_agent_stub_test") {
|
||||
module_out_path = module_out_path
|
||||
|
||||
sources = [ "display_manager_agent_stub_test.cpp" ]
|
||||
|
||||
deps = [ ":dm_unittest_common" ]
|
||||
}
|
||||
|
||||
## Build dm_unittest_common.a {{{
|
||||
config("dm_unittest_common_public_config") {
|
||||
include_dirs = [
|
||||
"//foundation/window/window_manager/dm/include",
|
||||
"//foundation/window/window_manager/dm/include/zidl",
|
||||
"//foundation/window/window_manager/dmserver/include",
|
||||
"//foundation/window/window_manager/snapshot",
|
||||
"//foundation/window/window_manager/test/common/mock",
|
||||
|
94
dm/test/unittest/display_manager_agent_stub_test.cpp
Normal file
94
dm/test/unittest/display_manager_agent_stub_test.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2022-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_manager_agent_stub.h"
|
||||
#include "display_manager_agent_default.h"
|
||||
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
|
||||
class DisplayManagerAgentStubTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp() override;
|
||||
void TearDown() override;
|
||||
sptr<DisplayManagerAgentStub> stub_;
|
||||
};
|
||||
|
||||
void DisplayManagerAgentStubTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayManagerAgentStubTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DisplayManagerAgentStubTest::SetUp()
|
||||
{
|
||||
stub_ = new DisplayManagerAgentDefault();
|
||||
}
|
||||
|
||||
void DisplayManagerAgentStubTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest01
|
||||
* @tc.desc: TRANS_ID_ON_DISPLAY_CONNECT
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerAgentStubTest, OnRemoteRequest01, Function | SmallTest | Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
data.WriteInterfaceToken(DisplayManagerAgentStub::GetDescriptor());
|
||||
sptr<DisplayInfo> displayInfo;
|
||||
data.WriteParcelable(displayInfo.GetRefPtr());
|
||||
uint32_t code = static_cast<uint32_t>(IDisplayManagerAgent::TRANS_ID_ON_DISPLAY_CONNECT);
|
||||
int res = stub_->OnRemoteRequest(code, data, reply, option);
|
||||
EXPECT_EQ(res, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnRemoteRequest02
|
||||
* @tc.desc: TRANS_ID_ON_DISPLAY_DISCONNECT
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerAgentStubTest, OnRemoteRequest02, Function | SmallTest | Level1)
|
||||
{
|
||||
MessageParcel data;
|
||||
MessageParcel reply;
|
||||
MessageOption option;
|
||||
|
||||
data.WriteInterfaceToken(DisplayManagerAgentStub::GetDescriptor());
|
||||
DisplayId displayId = 0;
|
||||
data.WriteUint64(displayId);
|
||||
uint32_t code = static_cast<uint32_t>(IDisplayManagerAgent::TRANS_ID_ON_DISPLAY_DISCONNECT);
|
||||
int res = stub_->OnRemoteRequest(code, data, reply, option);
|
||||
EXPECT_EQ(res, 0);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "mock_display_manager_adapter.h"
|
||||
#include "singleton_mocker.h"
|
||||
#include "display_manager.cpp"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -30,6 +31,12 @@ class DmMockScreenshotListener : public DisplayManager::IScreenshotListener {
|
||||
public:
|
||||
void OnScreenshot(const ScreenshotInfo info) override {}
|
||||
};
|
||||
class DmMockDisplayListener : public DisplayManager::IDisplayListener {
|
||||
public:
|
||||
void OnCreate(DisplayId) override {}
|
||||
void OnDestroy(DisplayId) override {}
|
||||
void OnChange(DisplayId) override {}
|
||||
};
|
||||
class DisplayManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@ -173,6 +180,142 @@ HWTEST_F(DisplayManagerTest, UnregisterScreenshotListener01, Function | SmallTes
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDisplayCreate01
|
||||
* @tc.desc: OnDisplayCreate
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, OnDisplayCreate01, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(true));
|
||||
sptr<DisplayManager::IDisplayListener> listener = new DmMockDisplayListener();
|
||||
DisplayManager::GetInstance().RegisterDisplayListener(listener);
|
||||
auto displayManagerListener = DisplayManager::GetInstance().pImpl_->displayManagerListener_;
|
||||
ASSERT_NE(displayManagerListener, nullptr);
|
||||
displayManagerListener->OnDisplayCreate(nullptr);
|
||||
sptr<DisplayInfo> displayInfo = new DisplayInfo();
|
||||
displayInfo->SetDisplayId(DISPLAY_ID_INVALID);
|
||||
displayManagerListener->OnDisplayCreate(displayInfo);
|
||||
displayInfo->SetDisplayId(0);
|
||||
displayManagerListener->OnDisplayCreate(displayInfo);
|
||||
ASSERT_NE(displayManagerListener->pImpl_, nullptr);
|
||||
displayManagerListener->pImpl_ = nullptr;
|
||||
displayManagerListener->OnDisplayCreate(displayInfo);
|
||||
DisplayManager::GetInstance().pImpl_->displayManagerListener_ = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDisplayDestroy
|
||||
* @tc.desc: OnDisplayDestroy
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, OnDisplayDestroy, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(true));
|
||||
sptr<DisplayManager::IDisplayListener> listener = new DmMockDisplayListener();
|
||||
DisplayManager::GetInstance().RegisterDisplayListener(listener);
|
||||
auto displayManagerListener = DisplayManager::GetInstance().pImpl_->displayManagerListener_;
|
||||
ASSERT_NE(displayManagerListener, nullptr);
|
||||
displayManagerListener->OnDisplayDestroy(DISPLAY_ID_INVALID);
|
||||
displayManagerListener->OnDisplayDestroy(0);
|
||||
displayManagerListener->pImpl_ = nullptr;
|
||||
displayManagerListener->OnDisplayDestroy(1);
|
||||
DisplayManager::GetInstance().pImpl_->displayManagerListener_ = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: OnDisplayChange
|
||||
* @tc.desc: OnDisplayChange
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, OnDisplayChange, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(true));
|
||||
sptr<DisplayManager::IDisplayListener> listener = new DmMockDisplayListener();
|
||||
DisplayManager::GetInstance().RegisterDisplayListener(listener);
|
||||
auto displayManagerListener = DisplayManager::GetInstance().pImpl_->displayManagerListener_;
|
||||
ASSERT_NE(displayManagerListener, nullptr);
|
||||
DisplayChangeEvent event = DisplayChangeEvent::DISPLAY_SIZE_CHANGED;
|
||||
displayManagerListener->OnDisplayChange(nullptr, event);
|
||||
sptr<DisplayInfo> displayInfo = new DisplayInfo();
|
||||
displayInfo->SetDisplayId(DISPLAY_ID_INVALID);
|
||||
displayManagerListener->OnDisplayChange(displayInfo, event);
|
||||
displayInfo->SetDisplayId(0);
|
||||
displayManagerListener->OnDisplayChange(displayInfo, event);
|
||||
ASSERT_NE(displayManagerListener->pImpl_, nullptr);
|
||||
displayManagerListener->pImpl_ = nullptr;
|
||||
displayManagerListener->OnDisplayChange(displayInfo, event);
|
||||
DisplayManager::GetInstance().pImpl_->displayManagerListener_ = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckRectValid
|
||||
* @tc.desc: CheckRectValid all
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, CheckRectValid, Function | SmallTest | Level1)
|
||||
{
|
||||
int32_t oriHeight = 500;
|
||||
int32_t oriWidth = 500;
|
||||
Media::Rect rect = {.left = 1, .top = 1, .width = 1, .height = 1};
|
||||
bool ret = DisplayManager::GetInstance().pImpl_->CheckRectValid(rect, oriHeight, oriWidth);
|
||||
ASSERT_TRUE(ret);
|
||||
rect.left = -1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckRectValid(rect, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
rect.left = 1;
|
||||
rect.top = -1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckRectValid(rect, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
rect.top = 1;
|
||||
rect.width = -1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckRectValid(rect, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
rect.width = 1;
|
||||
rect.height = -1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckRectValid(rect, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
rect.width = 500;
|
||||
rect.height = 1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckRectValid(rect, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
rect.width = 1;
|
||||
rect.height = 500;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckRectValid(rect, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckSizeValid
|
||||
* @tc.desc: CheckSizeValid all
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, CheckSizeValid, Function | SmallTest | Level1)
|
||||
{
|
||||
int32_t oriHeight = 500;
|
||||
int32_t oriWidth = 500;
|
||||
Media::Size size = {.width = 1, .height = 1};
|
||||
bool ret = DisplayManager::GetInstance().pImpl_->CheckSizeValid(size, oriHeight, oriWidth);
|
||||
ASSERT_TRUE(ret);
|
||||
size.width = -1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckSizeValid(size, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
size.width = 1;
|
||||
size.height = -1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckSizeValid(size, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
size.width = DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT + 1;
|
||||
size.height = 1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckSizeValid(size, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
size.width = DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT;
|
||||
size.height = DisplayManager::MAX_RESOLUTION_SIZE_SCREENSHOT + 1;
|
||||
ret = DisplayManager::GetInstance().pImpl_->CheckSizeValid(size, oriHeight, oriWidth);
|
||||
ASSERT_FALSE(ret);
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -81,6 +81,18 @@ HWTEST_F(DisplayTest, UpdateDisplayInfo01, Function | SmallTest | Level1)
|
||||
defaultDisplay_->UpdateDisplayInfo(nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetName
|
||||
* @tc.desc: UpdateDisplayInfo with nullptr
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: issueI5K0JP
|
||||
*/
|
||||
HWTEST_F(DisplayTest, GetName, Function | SmallTest | Level1)
|
||||
{
|
||||
defaultDisplay_->GetName();
|
||||
defaultDisplay_->GetDpi();
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetWaterfallCompression01
|
||||
* @tc.desc: Set waterfall compression related values with valid input.
|
||||
|
@ -83,6 +83,24 @@ HWTEST_F(ScreenGroupTest, UpdateScreenGroupInfo01, Function | SmallTest | Level2
|
||||
ScreenCombination comb = screenGroup->GetCombination();
|
||||
ASSERT_EQ(ScreenCombination::SCREEN_EXPAND, comb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: UpdateScreenGroupInfo03
|
||||
* @tc.desc: test InterfaceToken check success
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGroupTest, UpdateScreenGroupInfo03, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<ScreenGroupInfo> screenGroupInfo = new(std::nothrow) ScreenGroupInfo();
|
||||
sptr<ScreenGroup> screenGroup = new ScreenGroup(screenGroupInfo);
|
||||
std::vector<Point> position;
|
||||
position.emplace_back(0, 0);
|
||||
screenGroupInfo->position_ = position;
|
||||
SingletonMocker<ScreenManagerAdapter, MockScreenManagerAdapter> m;
|
||||
EXPECT_CALL(m.Mock(), GetScreenGroupInfoById(_)).Times(1).WillOnce(Return(screenGroupInfo));
|
||||
std::vector<Point> pos = screenGroup->GetChildPositions();
|
||||
ASSERT_EQ(position.size(), pos.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
#include "window.h"
|
||||
#include "window_option.h"
|
||||
#include "window_manager_hilog.h"
|
||||
#include "display_manager_agent_controller.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
@ -33,6 +34,15 @@ namespace {
|
||||
const int WAIT_FOR_SYNC_US = 1000 * 500; // 500ms
|
||||
}
|
||||
|
||||
class DisplayChangeEventListener : public DisplayManager::IDisplayListener {
|
||||
public:
|
||||
virtual void OnCreate(DisplayId displayId) {}
|
||||
|
||||
virtual void OnDestroy(DisplayId displayId) {}
|
||||
|
||||
virtual void OnChange(DisplayId displayId) {}
|
||||
};
|
||||
|
||||
class DisplayManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@ -278,5 +288,6 @@ HWTEST_F(DisplayManagerTest, HasPrivateWindowSkipSnapShot, Function | SmallTest
|
||||
window2->Destroy();
|
||||
ASSERT_TRUE(!hasPrivateWindow);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace OHOS::Rosen
|
||||
|
@ -206,6 +206,11 @@ ohos_unittest("wmserver_window_dumper_test") {
|
||||
sources = [ "window_dumper_test.cpp" ]
|
||||
|
||||
deps = [ ":wmserver_unittest_common" ]
|
||||
|
||||
external_deps = [
|
||||
"common_event_service:cesfwk_innerkits",
|
||||
"ipc:ipc_core",
|
||||
]
|
||||
}
|
||||
|
||||
## Build wmserver_unittest_common.a {{{
|
||||
|
Loading…
Reference in New Issue
Block a user