mirror of
https://gitee.com/openharmony/window_window_manager
synced 2024-11-23 15:00:12 +00:00
cover functions coverage
Signed-off-by: zhangkai <zhangkai324@huawei.com> Change-Id: Ib05bfda117377acd28e6c9bbfbbc35759fb0c123
This commit is contained in:
parent
951b4b1109
commit
458aa60ad1
@ -462,18 +462,19 @@ ScreenId ScreenManager::MakeMirror(ScreenId mainScreenId, std::vector<ScreenId>
|
||||
return group;
|
||||
}
|
||||
|
||||
void ScreenManager::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
|
||||
DMError ScreenManager::RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens)
|
||||
{
|
||||
WLOGFI("screens.size=%{public}llu", (unsigned long long)screens.size());
|
||||
if (screens.empty()) {
|
||||
WLOGFW("RemoveVirtualScreenFromGroup failed. screens is empty.");
|
||||
return;
|
||||
return DMError::DM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
if (screens.size() > MAX_SCREEN_SIZE) {
|
||||
WLOGFW("RemoveVirtualScreenFromGroup failed. The screens size is bigger than %{public}u.", MAX_SCREEN_SIZE);
|
||||
return;
|
||||
return DMError::DM_ERROR_INVALID_PARAM;
|
||||
}
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().RemoveVirtualScreenFromGroup(screens);
|
||||
return DMError::DM_OK;
|
||||
}
|
||||
|
||||
ScreenId ScreenManager::CreateVirtualScreen(VirtualScreenOption option)
|
||||
@ -511,9 +512,10 @@ ScreenPowerState ScreenManager::GetScreenPower(ScreenId dmsScreenId)
|
||||
return SingletonContainer::Get<ScreenManagerAdapter>().GetScreenPower(dmsScreenId);
|
||||
}
|
||||
|
||||
void ScreenManager::SetScreenRotationLocked(bool isLocked)
|
||||
DMError ScreenManager::SetScreenRotationLocked(bool isLocked)
|
||||
{
|
||||
SingletonContainer::Get<ScreenManagerAdapter>().SetScreenRotationLocked(isLocked);
|
||||
return DMError::DM_OK;
|
||||
}
|
||||
|
||||
bool ScreenManager::IsScreenRotationLocked()
|
||||
|
@ -331,17 +331,21 @@ HWTEST_F(DisplayManagerTest, ImplGetDefaultDisplay01, Function | SmallTest | Lev
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ImplGetDefaultDisplay02
|
||||
* @tc.desc: Impl GetDefaultDisplay nullptr
|
||||
* @tc.name: GetDisplayByScreen
|
||||
* @tc.desc: for interface coverage & check GetDisplayByScreen
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DisplayManagerTest, ImplGetDefaultDisplay02, Function | SmallTest | Level1)
|
||||
HWTEST_F(DisplayManagerTest, GetDisplayByScreen, Function | SmallTest | Level1)
|
||||
{
|
||||
auto& displayManager = DisplayManager::GetInstance();
|
||||
sptr<Display> display = displayManager.GetDisplayByScreen(SCREEN_ID_INVALID);
|
||||
ASSERT_EQ(display, nullptr);
|
||||
|
||||
sptr<DisplayInfo> displayInfo = new DisplayInfo();
|
||||
displayInfo->SetDisplayId(DISPLAY_ID_INVALID);
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
EXPECT_CALL(m->Mock(), GetDefaultDisplayInfo()).Times(1).WillOnce(Return(displayInfo));
|
||||
sptr<Display> display = DisplayManager::GetInstance().pImpl_->GetDefaultDisplay();
|
||||
EXPECT_CALL(m->Mock(), GetDisplayInfoByScreenId(_)).Times(1).WillOnce(Return(displayInfo));
|
||||
display = displayManager.GetDisplayByScreen(1);
|
||||
ASSERT_EQ(display, nullptr);
|
||||
}
|
||||
}
|
||||
|
@ -101,6 +101,22 @@ HWTEST_F(ScreenGroupTest, UpdateScreenGroupInfo03, Function | SmallTest | Level2
|
||||
std::vector<Point> pos = screenGroup->GetChildPositions();
|
||||
ASSERT_EQ(position.size(), pos.size());
|
||||
}
|
||||
/**
|
||||
* @tc.name: GetChildIds
|
||||
* @tc.desc: for interface coverage & check GetChildIds
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenGroupTest, GetChildIds, Function | SmallTest | Level2)
|
||||
{
|
||||
sptr<ScreenGroupInfo> screenGroupInfo = new(std::nothrow) ScreenGroupInfo();
|
||||
sptr<ScreenGroup> screenGroup = new ScreenGroup(screenGroupInfo);
|
||||
auto result = screenGroup->GetChildIds();
|
||||
ASSERT_TRUE(result.empty());
|
||||
|
||||
screenGroupInfo->children_.emplace_back(1);
|
||||
result = screenGroup->GetChildIds();
|
||||
ASSERT_EQ(result.size(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -33,6 +33,16 @@ public:
|
||||
void OnDisconnect(ScreenId) override {}
|
||||
void OnChange(ScreenId) override {}
|
||||
};
|
||||
|
||||
class TestScreenGroupListener : public ScreenManager::IScreenGroupListener {
|
||||
public:
|
||||
void OnChange(const std::vector<ScreenId>&, ScreenGroupChangeEvent) override {};
|
||||
};
|
||||
|
||||
class TestIVirtualScreenGroupListener : public ScreenManager::IVirtualScreenGroupListener {
|
||||
public:
|
||||
void OnMirrorChange(const ChangeInfo& info) override {};
|
||||
};
|
||||
class ScreenManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@ -290,6 +300,133 @@ HWTEST_F(ScreenManagerTest, OnScreenGroupChange01, Function | SmallTest | Level1
|
||||
screenManagerListener->OnScreenGroupChange(trigger, screenInfos, groupEvent);
|
||||
ScreenManager::GetInstance().pImpl_->screenManagerListener_ = nullptr;
|
||||
}
|
||||
/**
|
||||
* @tc.name: RemoveVirtualScreenFromGroup
|
||||
* @tc.desc: for interface coverage & check func RemoveVirtualScreenFromGroup
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, RemoveVirtualScreenFromGroup, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
std::vector<ScreenId> testScreens(33, 1);
|
||||
auto result = ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(testScreens);
|
||||
ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, result);
|
||||
|
||||
testScreens.clear();
|
||||
result = ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(testScreens);
|
||||
ASSERT_EQ(DMError::DM_ERROR_INVALID_PARAM, result);
|
||||
|
||||
testScreens.emplace_back(static_cast<ScreenId>(1));
|
||||
EXPECT_CALL(m->Mock(), RemoveVirtualScreenFromGroup(_)).Times(1);
|
||||
result = ScreenManager::GetInstance().RemoveVirtualScreenFromGroup(testScreens);
|
||||
ASSERT_EQ(DMError::DM_OK, result);
|
||||
}
|
||||
/**
|
||||
* @tc.name: SetScreenRotationLocked
|
||||
* @tc.desc: for interface coverage & check SetScreenRotationLocked
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, SetScreenRotationLocked, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
EXPECT_CALL(m->Mock(), SetScreenRotationLocked(_)).Times(1);
|
||||
auto result = ScreenManager::GetInstance().SetScreenRotationLocked(true);
|
||||
ASSERT_EQ(DMError::DM_OK, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsScreenRotationLocked
|
||||
* @tc.desc: for interface coverage & check IsScreenRotationLocked
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, IsScreenRotationLocked, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
|
||||
EXPECT_CALL(m->Mock(), IsScreenRotationLocked()).Times(1).WillOnce(Return(true));
|
||||
auto result = ScreenManager::GetInstance().IsScreenRotationLocked();
|
||||
ASSERT_EQ(true, result);
|
||||
EXPECT_CALL(m->Mock(), IsScreenRotationLocked()).Times(1).WillOnce(Return(false));
|
||||
result = ScreenManager::GetInstance().IsScreenRotationLocked();
|
||||
ASSERT_EQ(false, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RegisterScreenGroupListener
|
||||
* @tc.desc: for interface coverage and
|
||||
* check RegisterScreenGroupListener & UnregisterScreenGroupListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, RegisterScreenGroupListener, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
auto& screenManager = ScreenManager::GetInstance();
|
||||
auto result = screenManager.RegisterScreenGroupListener(nullptr);
|
||||
ASSERT_EQ(false, result);
|
||||
|
||||
sptr<ScreenManager::IScreenGroupListener> listener = new (std::nothrow)TestScreenGroupListener();
|
||||
if (screenManager.pImpl_->screenManagerListener_ == nullptr) {
|
||||
EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(true));
|
||||
}
|
||||
result = screenManager.RegisterScreenGroupListener(listener);
|
||||
ASSERT_EQ(true, result);
|
||||
|
||||
result = screenManager.UnregisterScreenGroupListener(nullptr);
|
||||
ASSERT_EQ(false, result);
|
||||
|
||||
auto sizeScreen = screenManager.pImpl_->screenListeners_.size();
|
||||
auto sizeScreenGroup = screenManager.pImpl_->screenGroupListeners_.size();
|
||||
auto sizeVirtualScreen = screenManager.pImpl_->virtualScreenGroupListeners_.size();
|
||||
if (sizeScreenGroup > 1) {
|
||||
result = screenManager.UnregisterScreenGroupListener(listener);
|
||||
ASSERT_EQ(true, result);
|
||||
} else if (sizeScreenGroup == 1) {
|
||||
if (sizeScreen == 0 && sizeVirtualScreen == 0) {
|
||||
EXPECT_CALL(m->Mock(), UnregisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(true));
|
||||
}
|
||||
result = screenManager.UnregisterScreenGroupListener(listener);
|
||||
ASSERT_EQ(true, result);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @tc.name: RegisterVirtualScreenGroupListener
|
||||
* @tc.desc: for interface coverage and
|
||||
* check RegisterVirtualScreenGroupListener & UnregisterVirtualScreenGroupListener
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenManagerTest, RegisterVirtualScreenGroupListener, Function | SmallTest | Level1)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
auto& screenManager = ScreenManager::GetInstance();
|
||||
auto result = screenManager.RegisterVirtualScreenGroupListener(nullptr);
|
||||
ASSERT_EQ(false, result);
|
||||
|
||||
sptr<ScreenManager::IVirtualScreenGroupListener> listener = new (std::nothrow)TestIVirtualScreenGroupListener();
|
||||
if (screenManager.pImpl_->screenManagerListener_ == nullptr) {
|
||||
EXPECT_CALL(m->Mock(), RegisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(true));
|
||||
}
|
||||
result = screenManager.RegisterVirtualScreenGroupListener(listener);
|
||||
ASSERT_EQ(true, result);
|
||||
|
||||
result = screenManager.UnregisterVirtualScreenGroupListener(nullptr);
|
||||
ASSERT_EQ(false, result);
|
||||
|
||||
auto sizeScreen = screenManager.pImpl_->screenListeners_.size();
|
||||
auto sizeScreenGroup = screenManager.pImpl_->screenGroupListeners_.size();
|
||||
auto sizeVirtualScreen = screenManager.pImpl_->virtualScreenGroupListeners_.size();
|
||||
|
||||
if (sizeVirtualScreen > 1) {
|
||||
result = screenManager.UnregisterVirtualScreenGroupListener(listener);
|
||||
ASSERT_EQ(true, result);
|
||||
} else if (sizeVirtualScreen == 1) {
|
||||
if (sizeScreen == 0 && sizeScreenGroup == 0) {
|
||||
EXPECT_CALL(m->Mock(), UnregisterDisplayManagerAgent(_, _)).Times(1).WillOnce(Return(true));
|
||||
}
|
||||
result = screenManager.UnregisterVirtualScreenGroupListener(listener);
|
||||
ASSERT_EQ(true, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -194,6 +194,40 @@ HWTEST_F(ScreenTest, SetScreenColorTransform01, Function | SmallTest | Level2)
|
||||
auto res = screen_->SetScreenColorTransform();
|
||||
ASSERT_EQ(DMError::DM_OK, res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: IsGroup
|
||||
* @tc.desc: for interface coverage and check IsGroup
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenTest, IsGroup, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
|
||||
screenInfo->SetIsScreenGroup(true);
|
||||
EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
|
||||
ASSERT_EQ(true, screen_->IsGroup());
|
||||
screenInfo->SetIsScreenGroup(false);
|
||||
EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
|
||||
ASSERT_EQ(false, screen_->IsGroup());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetParentId
|
||||
* @tc.desc: for interface coverage and check GetParentId
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ScreenTest, GetParentId, Function | SmallTest | Level2)
|
||||
{
|
||||
std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
|
||||
sptr<ScreenInfo> screenInfo = screen_->GetScreenInfo();
|
||||
screenInfo->SetParentId(0);
|
||||
EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
|
||||
ASSERT_EQ(0, screen_->GetParentId());
|
||||
screenInfo->SetParentId(SCREEN_ID_INVALID);
|
||||
EXPECT_CALL(m->Mock(), GetScreenInfo(_)).Times(1).WillOnce(Return(screenInfo));
|
||||
ASSERT_EQ(SCREEN_ID_INVALID, screen_->GetParentId());
|
||||
}
|
||||
}
|
||||
} // namespace Rosen
|
||||
} // namespace OHOS
|
@ -56,13 +56,13 @@ public:
|
||||
|
||||
ScreenId MakeExpand(const std::vector<ExpandOption>& options);
|
||||
ScreenId MakeMirror(ScreenId mainScreenId, std::vector<ScreenId> mirrorScreenId);
|
||||
void RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens);
|
||||
DMError RemoveVirtualScreenFromGroup(std::vector<ScreenId> screens);
|
||||
ScreenId CreateVirtualScreen(VirtualScreenOption option);
|
||||
DMError DestroyVirtualScreen(ScreenId screenId);
|
||||
DMError SetVirtualScreenSurface(ScreenId screenId, sptr<Surface> surface);
|
||||
bool SetScreenPowerForAll(ScreenPowerState state, PowerStateChangeReason reason);
|
||||
ScreenPowerState GetScreenPower(ScreenId screenId);
|
||||
void SetScreenRotationLocked(bool isLocked);
|
||||
DMError SetScreenRotationLocked(bool isLocked);
|
||||
bool IsScreenRotationLocked();
|
||||
|
||||
bool RegisterScreenListener(sptr<IScreenListener> listener);
|
||||
|
@ -70,6 +70,10 @@ public:
|
||||
MOCK_METHOD2(GetScreenGamutMap, DMError(ScreenId screenId, ScreenGamutMap& gamutMap));
|
||||
MOCK_METHOD2(SetScreenGamutMap, DMError(ScreenId screenId, ScreenGamutMap gamutMap));
|
||||
MOCK_METHOD1(SetScreenColorTransform, DMError(ScreenId screenId));
|
||||
|
||||
MOCK_METHOD1(RemoveVirtualScreenFromGroup, void(std::vector<ScreenId> screens));
|
||||
MOCK_METHOD1(SetScreenRotationLocked, void(bool isLocked));
|
||||
MOCK_METHOD0(IsScreenRotationLocked, bool());
|
||||
};
|
||||
}
|
||||
} // namespace OHOS
|
||||
|
Loading…
Reference in New Issue
Block a user