!7981 生命周期UT分支覆盖率补充

Merge pull request !7981 from hubijie/master2
This commit is contained in:
openharmony_ci 2024-08-09 06:18:12 +00:00 committed by Gitee
commit 2cd034c94d
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 185 additions and 0 deletions

View File

@ -532,6 +532,9 @@ HWTEST_F(SceneSessionTest, IsDecorEnable01, Function | SmallTest | Level2)
property->SetDecorEnable(false);
property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
ASSERT_EQ(true, scensession_->IsDecorEnable());
scensession_->SetSessionProperty(nullptr);
ASSERT_EQ(false, scensession_->IsDecorEnable());
}
/**
@ -644,6 +647,11 @@ HWTEST_F(SceneSessionTest, SaveAspectRatio, Function | SmallTest | Level2)
scensession = new (std::nothrow) SceneSession(info, nullptr);
EXPECT_NE(scensession, nullptr);
ASSERT_EQ(true, scensession->SaveAspectRatio(0.1));
scensession->sessionInfo_.bundleName_ = "";
scensession->sessionInfo_.moduleName_ = "";
scensession->sessionInfo_.abilityName_ = "";
ASSERT_EQ(false, scensession->SaveAspectRatio(0.1));
}
/**
@ -723,6 +731,11 @@ HWTEST_F(SceneSessionTest, NotifySessionRectChange, Function | SmallTest | Level
EXPECT_NE(scensession, nullptr);
WSRect overlapRect = { 0, 0, 0, 0 };
scensession->NotifySessionRectChange(overlapRect, SizeChangeReason::ROTATION);
scensession->sessionRectChangeFunc_ = [](const WSRect& rect, const SizeChangeReason& reason) {
return;
};
scensession->NotifySessionRectChange(overlapRect, SizeChangeReason::ROTATION);
}
/**
@ -1180,6 +1193,13 @@ HWTEST_F(SceneSessionTest, GetRatioPreferenceKey, Function | SmallTest | Level2)
std::string key = info.bundleName_ + info.moduleName_ + info.abilityName_;
scensession = new (std::nothrow) SceneSession(info, specificCallback_);
ASSERT_EQ(key, scensession->GetRatioPreferenceKey());
std::string key2(30, 'a');
std::string key3(80, 'a');
scensession->sessionInfo_.bundleName_ = key2;
scensession->sessionInfo_.moduleName_ = key2;
scensession->sessionInfo_.abilityName_ = key2;
ASSERT_EQ(key3, scensession->GetRatioPreferenceKey());
}
/**
@ -1694,6 +1714,81 @@ HWTEST_F(SceneSessionTest, GetAppForceLandscapeConfig, Function | SmallTest | Le
auto result = sceneSession->GetAppForceLandscapeConfig(config);
ASSERT_EQ(result, WMError::WM_OK);
}
/**
* @tc.name: HandleCompatibleModeMoveDrag
* @tc.desc: HandleCompatibleModeMoveDrag
* @tc.type: FUNC
*/
HWTEST_F(SceneSessionTest, HandleCompatibleModeMoveDrag, Function | SmallTest | Level2)
{
SessionInfo info;
info.abilityName_ = "HandleCompatibleModeMoveDrag";
info.bundleName_ = "HandleCompatibleModeMoveDrag";
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
EXPECT_NE(sceneSession, nullptr);
WSRect rect = {1, 1, 1, 1};
WSRect rect2 = {1, 1, 2, 1};
sceneSession->winRect_ = rect2;
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, false);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
rect2 = {1, 1, 1, 2};
sceneSession->winRect_ = rect2;
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
rect = {1, 1, 2000, 1};
rect2 = {1, 1, 2, 1};
sceneSession->winRect_ = rect2;
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
rect = {1, 1, 2000, 1};
rect2 = {1, 1, 1, 2};
sceneSession->winRect_ = rect2;
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
rect = {1, 1, 500, 1};
rect2 = {1, 1, 1, 2};
sceneSession->winRect_ = rect2;
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, true);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
rect = {1, 1, 500, 1};
rect2 = {1, 1, 1, 2};
sceneSession->winRect_ = rect2;
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::HIDE, false);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::HIDE);
sceneSession->HandleCompatibleModeMoveDrag(rect, SizeChangeReason::MOVE, false);
ASSERT_EQ(sceneSession->reason_, SizeChangeReason::MOVE);
}
/**
* @tc.name: SetMoveDragCallback
* @tc.desc: SetMoveDragCallback
* @tc.type: FUNC
*/
HWTEST_F(SceneSessionTest, SetMoveDragCallback, Function | SmallTest | Level2)
{
SessionInfo info;
info.abilityName_ = "SetMoveDragCallback";
info.bundleName_ = "SetMoveDragCallback";
sptr<SceneSession::SpecificSessionCallback> specificCallback =
sptr<SceneSession::SpecificSessionCallback>::MakeSptr();
EXPECT_NE(specificCallback, nullptr);
sptr<SceneSession> sceneSession = sptr<SceneSession>::MakeSptr(info, nullptr);
EXPECT_NE(sceneSession, nullptr);
sceneSession->moveDragController_ = nullptr;
sceneSession->SetMoveDragCallback();
}
}
}
}

View File

@ -26,6 +26,7 @@
#include "mock/mock_session_stage.h"
#include "input_event.h"
#include <pointer_event.h>
#include "ui/rs_surface_node.h"
using namespace testing;
using namespace testing::ext;
@ -240,6 +241,11 @@ HWTEST_F(SceneSessionTest2, HandleEnterWinwdowArea2, Function | SmallTest | Leve
WSError result = scensession->HandleEnterWinwdowArea(1, 1);
ASSERT_EQ(result, WSError::WS_OK);
scensession->sessionInfo_.isSystem_ = true;
result = scensession->HandleEnterWinwdowArea(1, 1);
result = scensession->HandleEnterWinwdowArea(1, 1);
ASSERT_EQ(result, WSError::WS_OK);
property = new(std::nothrow) WindowSessionProperty();
property->SetWindowType(WindowType::ABOVE_APP_SYSTEM_WINDOW_END);
property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING);
@ -342,6 +348,24 @@ HWTEST_F(SceneSessionTest2, TransferPointerEvent01, Function | SmallTest | Level
pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_),
WSError::WS_ERROR_INVALID_SESSION);
scensession->sessionInfo_.isSystem_ = true;
pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_),
WSError::WS_ERROR_NULLPTR);
pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_),
WSError::WS_ERROR_NULLPTR);
scensession->sessionInfo_.isSystem_ = false;
pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_BUTTON_DOWN);
ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_),
WSError::WS_ERROR_INVALID_SESSION);
pointerEvent_->SetPointerAction(MMI::PointerEvent::POINTER_ACTION_ENTER_WINDOW);
ASSERT_EQ(scensession->TransferPointerEvent(pointerEvent_),
WSError::WS_ERROR_INVALID_SESSION);
}
/**
@ -403,6 +427,13 @@ HWTEST_F(SceneSessionTest2, RequestSessionBack, Function | SmallTest | Level2)
WSError result = scensession->RequestSessionBack(true);
ASSERT_EQ(result, WSError::WS_OK);
struct RSSurfaceNodeConfig config;
std::shared_ptr<RSSurfaceNode> surfaceNode = RSSurfaceNode::Create(config);
EXPECT_NE(nullptr, surfaceNode);
scensession->SetLeashWinSurfaceNode(surfaceNode);
result = scensession->RequestSessionBack(true);
ASSERT_EQ(result, WSError::WS_OK);
}
/**
@ -434,6 +465,10 @@ HWTEST_F(SceneSessionTest2, SetParentPersistentId, Function | SmallTest | Level2
scensession->SetParentPersistentId(0);
result = scensession->GetParentPersistentId();
ASSERT_EQ(result, 0);
scensession->SetSessionProperty(nullptr);
scensession->SetParentPersistentId(0);
ASSERT_EQ(0, scensession->GetParentPersistentId());
}
/**
@ -943,6 +978,10 @@ HWTEST_F(SceneSessionTest2, SetFloatingScale, Function | SmallTest | Level2)
scensession->specificCallback_->onUpdateAvoidArea_ = updateAvoidAreaFun;
scensession->SetFloatingScale(3.14f);
EXPECT_EQ(3.14f, scensession->floatingScale_);
scensession->floatingScale_ = 3.0f;
scensession->SetFloatingScale(3.0f);
EXPECT_EQ(3.0f, scensession->floatingScale_);
}
/**
@ -969,6 +1008,13 @@ HWTEST_F(SceneSessionTest2, ProcessPointDownSession, Function | SmallTest | Leve
scensession->specificCallback_->onSessionTouchOutside_ = sessionTouchOutsideFun;
scensession->specificCallback_->onOutsideDownEvent_ = outsideDownEventFun;
EXPECT_EQ(WSError::WS_OK, scensession->ProcessPointDownSession(3, 4));
scensession->specificCallback_->onSessionTouchOutside_ = nullptr;
EXPECT_EQ(WSError::WS_OK, scensession->ProcessPointDownSession(3, 4));
scensession->sessionInfo_.bundleName_ = "SCBGestureBack";
scensession->specificCallback_->onOutsideDownEvent_ = nullptr;
EXPECT_EQ(WSError::WS_OK, scensession->ProcessPointDownSession(3, 4));
}
/**
@ -1598,6 +1644,8 @@ HWTEST_F(SceneSessionTest2, TransferPointerEvent03, Function | SmallTest | Level
property->SetWindowType(WindowType::WINDOW_TYPE_PIP);
property->SetWindowMode(WindowMode::WINDOW_MODE_PIP);
ASSERT_EQ(WSError::WS_OK, sceneSession->SetPipActionEvent("pointerEvent", 0));
sceneSession->FixRectByLimits(limits, rect, ratio, false, vpr);
}
/**
@ -1624,6 +1672,10 @@ HWTEST_F(SceneSessionTest2, OnMoveDragCallback, Function | SmallTest | Level2)
bool visible = true;
sceneSession->UpdateNativeVisibility(visible);
sceneSession->scenePersistence_ = new (std::nothrow) ScenePersistence(info.bundleName_, 0);
EXPECT_NE(sceneSession->scenePersistence_, nullptr);
sceneSession->GetUpdatedIconPath();
}
/**
@ -1890,6 +1942,24 @@ HWTEST_F(SceneSessionTest2, CheckGetAvoidAreaAvailable, Function | SmallTest | L
sceneSession->SetSessionProperty(property);
sceneSession->CheckGetAvoidAreaAvailable(AvoidAreaType::TYPE_SYSTEM);
}
/**
* @tc.name: IsFullScreenMovable
* @tc.desc: IsFullScreenMovable
* @tc.type: FUNC
*/
HWTEST_F(SceneSessionTest2, IsFullScreenMovable, Function | SmallTest | Level2)
{
SessionInfo info;
info.abilityName_ = "IsFullScreenMovable";
info.bundleName_ = "IsFullScreenMovable";
sptr<SceneSession> sceneSession = new (std::nothrow) SceneSession(info, nullptr);
EXPECT_NE(sceneSession, nullptr);
sceneSession->SetSessionProperty(nullptr);
auto result = sceneSession->IsFullScreenMovable();
ASSERT_EQ(false, result);
}
}
}
}

View File

@ -375,6 +375,9 @@ HWTEST_F(SceneSessionTest4, GetSessionSnapshotFilePath, Function | SmallTest | L
session->Session::SetSessionState(SessionState::STATE_DISCONNECT);
session->scenePersistence_ = sptr<ScenePersistence>::MakeSptr("GetSessionSnapshotFilePath", 1);
EXPECT_EQ("GetSessionSnapshotFilePath_1.astc", session->GetSessionSnapshotFilePath());
session->SetSessionState(SessionState::STATE_BACKGROUND);
EXPECT_EQ("GetSessionSnapshotFilePath_1.astc", session->GetSessionSnapshotFilePath());
}
/**

View File

@ -728,6 +728,10 @@ HWTEST_F(SceneSessionTest5, FixRectByAspectRatio01, Function | SmallTest | Level
systemConfig.isSystemDecorEnable_ = false;
EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
systemConfig.isSystemDecorEnable_ = true;
session->SetSessionProperty(nullptr);
EXPECT_EQ(false, session->FixRectByAspectRatio(rect));
}
/**
@ -758,6 +762,19 @@ HWTEST_F(SceneSessionTest5, OnMoveDragCallback, Function | SmallTest | Level2)
reason = SizeChangeReason::DRAG_START;
session->OnMoveDragCallback(reason);
EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
session->moveDragController_ = sptr<MoveDragController>::MakeSptr(2024);
EXPECT_NE(session->moveDragController_, nullptr);
session->SetSessionProperty(nullptr);
session->OnMoveDragCallback(reason);
EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
sptr<WindowSessionProperty> property = new (std::nothrow) WindowSessionProperty();
ASSERT_NE(nullptr, property);
session->SetSessionProperty(property);
property->compatibleModeInPc_ = true;
session->OnMoveDragCallback(reason);
EXPECT_EQ(WSError::WS_OK, session->UpdateSizeChangeReason(reason));
}
/**