From 8337bf76dd0fcac666fd3c4c9c6e09d5ac592514 Mon Sep 17 00:00:00 2001 From: shuangshuangliu Date: Mon, 1 Sep 2025 17:29:26 +0800 Subject: [PATCH] =?UTF-8?q?TDD=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shuangshuangliu Change-Id: I03781eb3b54fed89090c13341e9f6cfc3f8dd2b2 --- .../test/unittest/anomaly_detection_test.cpp | 17 ++++++++++---- .../test/unittest/main_session_test.cpp | 15 +++++++++--- .../test/unittest/scb_system_session_test.cpp | 15 ++++++++++-- .../unittest/scene_session_manager_test10.cpp | 1 - .../unittest/scene_session_manager_test12.cpp | 23 ++++++++++++------- .../test/unittest/scene_session_test.cpp | 16 ++----------- .../test/unittest/scene_session_test2.cpp | 4 ---- .../test/unittest/scene_session_test5.cpp | 5 ---- .../unittest/session_specific_window_test.cpp | 2 -- .../test/unittest/session_stub_test.cpp | 1 - window_scene/test/unittest/session_test.cpp | 11 ++++++++- window_scene/test/unittest/session_test3.cpp | 3 --- window_scene/test/unittest/session_test4.cpp | 12 ++++++++-- .../unittest/ssmgr_specific_window_test.cpp | 1 - .../test/unittest/system_session_test.cpp | 15 +++++------- 15 files changed, 81 insertions(+), 60 deletions(-) diff --git a/window_scene/test/unittest/anomaly_detection_test.cpp b/window_scene/test/unittest/anomaly_detection_test.cpp index b7063000c2..681dc33cb2 100644 --- a/window_scene/test/unittest/anomaly_detection_test.cpp +++ b/window_scene/test/unittest/anomaly_detection_test.cpp @@ -20,13 +20,21 @@ #include "session/host/include/session.h" #include "session/host/include/scene_session.h" #include "common/include/window_session_property.h" - +#include "window_manager_hilog.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } +} class AnomalyDetectionTest : public testing::Test { public: static void SetUpTestCase(); @@ -288,9 +296,10 @@ void WallPaperTest(sptr ssm_) HWTEST_F(AnomalyDetectionTest, SceneZOrderCheckProcess, TestSize.Level1) { GTEST_LOG_(INFO) << "AnomalyDetectionTest: SceneZOrderCheckProcess start"; - int ret = 0; + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); AnomalyDetection::SceneZOrderCheckProcess(); - + EXPECT_FALSE(g_errLog.find("ZOrderCheck err, zorder 0") != std::string::npos); SessionVisibleTest(ssm_); ZeroOrderTest(ssm_); EQOrderTest(ssm_); @@ -299,7 +308,7 @@ HWTEST_F(AnomalyDetectionTest, SceneZOrderCheckProcess, TestSize.Level1) KeyGUARDTest(ssm_); IsShowWhenLockedTest(ssm_); WallPaperTest(ssm_); - ASSERT_EQ(ret, 0); + LOG_SetCallback(nullptr); GTEST_LOG_(INFO) << "AnomalyDetectionTest: SceneZOrderCheckProcess end"; } diff --git a/window_scene/test/unittest/main_session_test.cpp b/window_scene/test/unittest/main_session_test.cpp index e7f7711a6c..0a5fc0f9be 100644 --- a/window_scene/test/unittest/main_session_test.cpp +++ b/window_scene/test/unittest/main_session_test.cpp @@ -32,6 +32,14 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } +} class MainSessionTest : public testing::Test { public: static void SetUpTestCase(); @@ -398,9 +406,11 @@ HWTEST_F(MainSessionTest, NotifyClientToUpdateInteractive, TestSize.Level1) */ HWTEST_F(MainSessionTest, SetExitSplitOnBackground, TestSize.Level1) { - bool isExitSplitOnBackground = true; + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); mainSession_->SetExitSplitOnBackground(isExitSplitOnBackground); - ASSERT_EQ(true, isExitSplitOnBackground); + EXPECT_TRUE(g_errLog.find("[NAPI]") != std::string::npos); + LOG_SetCallback(nullptr); } /** @@ -892,7 +902,6 @@ HWTEST_F(MainSessionTest, NotifySubAndDialogFollowRectChange01, TestSize.Level1) WSRect rect; subSession->isFollowParentLayout_ = false; mainSession->NotifySubAndDialogFollowRectChange(rect, false, false); - ASSERT_EQ(false, isCall); subSession->isFollowParentLayout_ = true; sptr callBack = sptr::MakeSptr(); diff --git a/window_scene/test/unittest/scb_system_session_test.cpp b/window_scene/test/unittest/scb_system_session_test.cpp index 13d787515b..f04ad5aba0 100644 --- a/window_scene/test/unittest/scb_system_session_test.cpp +++ b/window_scene/test/unittest/scb_system_session_test.cpp @@ -27,6 +27,14 @@ using namespace testing::ext; namespace OHOS { namespace Rosen { +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } +} class SCBSystemSessionTest : public testing::Test { public: static void SetUpTestCase(); @@ -237,13 +245,16 @@ HWTEST_F(SCBSystemSessionTest, PresentFocusIfPointDown02, TestSize.Level1) */ HWTEST_F(SCBSystemSessionTest, PresentFocusIfNeed, TestSize.Level1) { + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); int32_t pointerAction = 8; scbSystemSession_->PresentFocusIfNeed(pointerAction, 0); - ASSERT_EQ(pointerAction, 8); + EXPECT_FALSE(g_errLog.find("OnClick down, id:") != std::string::npos); pointerAction = 100; scbSystemSession_->PresentFocusIfNeed(pointerAction, 0); - ASSERT_EQ(pointerAction, 100); + EXPECT_FALSE(g_errLog.find("OnClick down, id:") != std::string::npos); + LOG_SetCallback(nullptr); } /** diff --git a/window_scene/test/unittest/scene_session_manager_test10.cpp b/window_scene/test/unittest/scene_session_manager_test10.cpp index 8ddd07a2e5..33fa652103 100644 --- a/window_scene/test/unittest/scene_session_manager_test10.cpp +++ b/window_scene/test/unittest/scene_session_manager_test10.cpp @@ -595,7 +595,6 @@ HWTEST_F(SceneSessionManagerTest10, ChangeWindowRectYInVirtualDisplay, TestSize. DisplayId displayId = 0; int32_t y = 100; ssm_->ChangeWindowRectYInVirtualDisplay(displayId, y); - EXPECT_EQ(displayId, 0); EXPECT_EQ(y, 100); displayId = 999; ssm_->ChangeWindowRectYInVirtualDisplay(displayId, y); diff --git a/window_scene/test/unittest/scene_session_manager_test12.cpp b/window_scene/test/unittest/scene_session_manager_test12.cpp index 3b50f371fa..5f753fc3ad 100644 --- a/window_scene/test/unittest/scene_session_manager_test12.cpp +++ b/window_scene/test/unittest/scene_session_manager_test12.cpp @@ -40,12 +40,21 @@ #include "session_manager/include/zidl/session_router_stack_listener_stub.h" #include "ui_effect_manager.h" #include "ui_effect_controller_client_proxy.h" +#include "window_manager_hilog.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { +namespace { + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } +} class KeyboardTestData; class SceneSessionManagerTest12 : public testing::Test { public: @@ -1675,7 +1684,6 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground01, TestSize.Leve bool hasFloatWindowForeground = false; WMError result = ssm_->HasFloatingWindowForeground(nullptr, hasFloatWindowForeground); EXPECT_EQ(result, WMError::WM_ERROR_NULLPTR); - EXPECT_EQ(hasFloatWindowForeground, false); } /** @@ -1708,7 +1716,7 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground02, TestSize.Leve sceneSession->SetSessionState(SessionState::STATE_ACTIVE); ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession }); - bool hasFloatWindowForeground = false; + bool hasFloatWindowForeground = true; sptr token2 = sptr::MakeSptr(); WMError result = ssm_->HasFloatingWindowForeground(token2, hasFloatWindowForeground); EXPECT_EQ(result, WMError::WM_OK); @@ -1790,12 +1798,12 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground04, TestSize.Leve ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 }); ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 }); - bool hasFloatWindowForeground = false; + bool hasFloatWindowForeground = true; WMError result = ssm_->HasFloatingWindowForeground(token1, hasFloatWindowForeground); EXPECT_EQ(result, WMError::WM_OK); EXPECT_EQ(hasFloatWindowForeground, false); - hasFloatWindowForeground = false; + hasFloatWindowForeground = true; result = ssm_->HasFloatingWindowForeground(token2, hasFloatWindowForeground); EXPECT_EQ(result, WMError::WM_OK); EXPECT_EQ(hasFloatWindowForeground, false); @@ -1821,7 +1829,7 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground05, TestSize.Leve ssm_->sceneSessionMap_.insert({ sceneSession->GetPersistentId(), sceneSession }); - bool hasFloatWindowForeground = false; + bool hasFloatWindowForeground = true; WMError result = ssm_->HasFloatingWindowForeground(token, hasFloatWindowForeground); EXPECT_EQ(result, WMError::WM_OK); EXPECT_EQ(hasFloatWindowForeground, false); @@ -1859,7 +1867,7 @@ HWTEST_F(SceneSessionManagerTest12, HasFloatingWindowForeground06, TestSize.Leve ssm_->sceneSessionMap_.insert({ sceneSession1->GetPersistentId(), sceneSession1 }); ssm_->sceneSessionMap_.insert({ sceneSession2->GetPersistentId(), sceneSession2 }); - bool hasFloatWindowForeground = false; + bool hasFloatWindowForeground = true; WMError result = ssm_->HasFloatingWindowForeground(token2, hasFloatWindowForeground); EXPECT_EQ(result, WMError::WM_OK); EXPECT_EQ(hasFloatWindowForeground, false); @@ -3011,7 +3019,7 @@ HWTEST_F(SceneSessionManagerTest12, GetPiPSettingSwitchStatus, Function | SmallT ssm_->SetPiPSettingSwitchStatus(false); ret = ssm_->GetPiPSettingSwitchStatus(switchStatus); - EXPECT_EQ(switchStatus, false); + EXPECT_NE(switchStatus, true); EXPECT_EQ(ret, WMError::WM_OK); } @@ -3064,7 +3072,6 @@ HWTEST_F(SceneSessionManagerTest12, IsFocusWindowParent, Function | SmallTest | sceneSession->SetAbilityToken(nullptr); EXPECT_EQ(WSError::WS_OK, ssm_->IsFocusWindowParent(token, isParent)); - EXPECT_EQ(false, isParent); } } // namespace } // namespace Rosen diff --git a/window_scene/test/unittest/scene_session_test.cpp b/window_scene/test/unittest/scene_session_test.cpp index b030f899e8..60d495bd4d 100644 --- a/window_scene/test/unittest/scene_session_test.cpp +++ b/window_scene/test/unittest/scene_session_test.cpp @@ -201,9 +201,6 @@ HWTEST_F(SceneSessionTest, SetZOrder01, TestSize.Level1) sceneSession->SetZOrder(zOrder); usleep(WAIT_ASYNC_US); ASSERT_EQ(zOrder, sceneSession->zOrder_); - sceneSession->SetZOrder(zOrder); - usleep(WAIT_ASYNC_US); - ASSERT_EQ(zOrder, sceneSession->zOrder_); } /** @@ -1173,9 +1170,7 @@ HWTEST_F(SceneSessionTest, GetCutoutAvoidArea, TestSize.Level1) EXPECT_NE(sceneSession, nullptr); WSRect overlapRect = { 0, 0, 0, 0 }; AvoidArea avoidArea; - int ret = 1; sceneSession->GetCutoutAvoidArea(overlapRect, avoidArea); - ASSERT_EQ(ret, 1); } /** @@ -1273,9 +1268,8 @@ HWTEST_F(SceneSessionTest, OnShowWhenLocked, TestSize.Level1) sptr sceneSession; sceneSession = sptr::MakeSptr(info, specificCallback_); EXPECT_NE(sceneSession, nullptr); - int ret = 0; - sceneSession->OnShowWhenLocked(false); - ASSERT_EQ(ret, 0); + auto res = sceneSession->OnShowWhenLocked(false); + ASSERT_EQ(res, WSError::WS_OK); } /** @@ -1492,7 +1486,6 @@ HWTEST_F(SceneSessionTest, CalculateAvoidAreaRect, TestSize.Level1) sptr sceneSession; sceneSession = sptr::MakeSptr(info, specificCallback_); EXPECT_NE(sceneSession, nullptr); - int ret = 0; WSRect overlapRect = { 0, 0, 0, 0 }; WSRect avoidRect = { 0, 0, 0, 0 }; AvoidArea avoidArea; @@ -1500,7 +1493,6 @@ HWTEST_F(SceneSessionTest, CalculateAvoidAreaRect, TestSize.Level1) WSRect overlapRect_ = { 1, 1, 1, 1 }; WSRect avoidRect_ = { 1, 1, 1, 1 }; sceneSession->CalculateAvoidAreaRect(overlapRect_, avoidRect_, avoidArea); - ASSERT_EQ(ret, 0); } /** @@ -1590,7 +1582,6 @@ HWTEST_F(SceneSessionTest, UpdateCameraWindowStatus, TestSize.Level1) sptr sysSession; sysSession = sptr::MakeSptr(info, specificCallback_); EXPECT_NE(sysSession, nullptr); - int ret = 1; specificCallback_->onCameraFloatSessionChange_ = [](uint32_t accessTokenId, bool isShowing) {}; specificCallback_->onCameraSessionChange_ = [](uint32_t accessTokenId, bool isShowing) {}; @@ -1611,7 +1602,6 @@ HWTEST_F(SceneSessionTest, UpdateCameraWindowStatus, TestSize.Level1) sysSession->SetPiPTemplateInfo(pipType); sysSession->property_ = property; sysSession->UpdateCameraWindowStatus(false); - ASSERT_EQ(ret, 1); } /** @@ -1664,7 +1654,6 @@ HWTEST_F(SceneSessionTest, NotifyPropertyWhenConnect, TestSize.Level1) sptr sceneSession; sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(sceneSession, nullptr); - int ret = 1; std::string key = info.bundleName_ + info.moduleName_ + info.abilityName_; sceneSession = sptr::MakeSptr(info, specificCallback_); sceneSession->NotifyPropertyWhenConnect(); @@ -1672,7 +1661,6 @@ HWTEST_F(SceneSessionTest, NotifyPropertyWhenConnect, TestSize.Level1) property->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); sceneSession->property_ = property; sceneSession->NotifyPropertyWhenConnect(); - ASSERT_EQ(ret, 1); } /** diff --git a/window_scene/test/unittest/scene_session_test2.cpp b/window_scene/test/unittest/scene_session_test2.cpp index 4044cac88d..fa4d39a002 100644 --- a/window_scene/test/unittest/scene_session_test2.cpp +++ b/window_scene/test/unittest/scene_session_test2.cpp @@ -169,14 +169,12 @@ HWTEST_F(SceneSessionTest2, NotifyPropertyWhenConnect1, TestSize.Level1) EXPECT_NE(specificCallback_, nullptr); sptr sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(sceneSession, nullptr); - int ret = 1; std::string key = info.bundleName_ + info.moduleName_ + info.abilityName_; sceneSession = sptr::MakeSptr(info, specificCallback_); sceneSession->NotifyPropertyWhenConnect(); sptr property = nullptr; sceneSession->NotifyPropertyWhenConnect(); - ASSERT_EQ(ret, 1); } /** @@ -506,11 +504,9 @@ HWTEST_F(SceneSessionTest2, SetScale, TestSize.Level1) sptr specificCallback_ = sptr::MakeSptr(); EXPECT_NE(specificCallback_, nullptr); - int resultValue = 0; sptr sceneSession = sptr::MakeSptr(info, nullptr); EXPECT_NE(sceneSession, nullptr); sceneSession->SetScale(1.0f, 1.0f, 0.0f, 0.0f); - ASSERT_EQ(0, resultValue); } /** diff --git a/window_scene/test/unittest/scene_session_test5.cpp b/window_scene/test/unittest/scene_session_test5.cpp index 9ded5b7c12..14f83040e5 100644 --- a/window_scene/test/unittest/scene_session_test5.cpp +++ b/window_scene/test/unittest/scene_session_test5.cpp @@ -157,12 +157,10 @@ HWTEST_F(SceneSessionTest5, HookAvoidAreaInCompatibleMode, TestSize.Level1) session->property_->SetCompatibleModeProperty(compatibleModeProperty); session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FLOATING); session->HookAvoidAreaInCompatibleMode(rect, AvoidAreaType::TYPE_SYSTEM, avoidArea); - EXPECT_TRUE(avoidArea.topRect_ == invalidRect); compatibleModeProperty->SetIsAdaptToImmersive(true); session->property_->SetCompatibleModeProperty(compatibleModeProperty); session->property_->SetWindowMode(WindowMode::WINDOW_MODE_FULLSCREEN); session->HookAvoidAreaInCompatibleMode(rect, AvoidAreaType::TYPE_SYSTEM, avoidArea); - EXPECT_TRUE(avoidArea.topRect_ == invalidRect); // test top system avoidArea session->property_->GetCompatibleModeProperty()->SetIsAdaptToImmersive(true); @@ -2166,7 +2164,6 @@ HWTEST_F(SceneSessionTest5, CompatibilityModeWindowScaleTransfer, TestSize.Level info.screenId_ = 0; sptr mainSession = sptr::MakeSptr(info, nullptr); WSRect preRect = { 100, 100, 400, 400 }; - WSRect noChangeRect = { 100, 100, 400, 400 }; WSRect resultRect = { 200, 200, 200, 200 }; float scaleX = 0.5f; float scaleY = 0.5f; @@ -2176,14 +2173,12 @@ HWTEST_F(SceneSessionTest5, CompatibilityModeWindowScaleTransfer, TestSize.Level compatibleModeProperty->SetIsAdaptToProportionalScale(false); mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty); mainSession->CompatibilityModeWindowScaleTransfer(preRect, isScale); - EXPECT_EQ(noChangeRect, preRect); compatibleModeProperty->SetIsAdaptToProportionalScale(true); mainSession->property_->SetCompatibleModeProperty(compatibleModeProperty); mainSession->CompatibilityModeWindowScaleTransfer(preRect, isScale); EXPECT_EQ(resultRect, preRect); isScale = false; mainSession->CompatibilityModeWindowScaleTransfer(preRect, isScale); - EXPECT_EQ(noChangeRect, preRect); } /** diff --git a/window_scene/test/unittest/session_specific_window_test.cpp b/window_scene/test/unittest/session_specific_window_test.cpp index d9a1eab8c1..1e7e7fd8a3 100644 --- a/window_scene/test/unittest/session_specific_window_test.cpp +++ b/window_scene/test/unittest/session_specific_window_test.cpp @@ -183,11 +183,9 @@ HWTEST_F(SessionSpecificWindowTest, ClearSpecificSessionCbMap01, TestSize.Level1 info.bundleName_ = "ClearSpecificSessionCbMap01"; sptr sceneSession = sptr::MakeSptr(info, nullptr); sptr session = sptr::MakeSptr(info); - auto result = false; sceneSession->clearCallbackMapFunc_ = nullptr; sceneSession->ClearSpecificSessionCbMap(); usleep(WAIT_SYNC_IN_NS); - ASSERT_EQ(result, false); ASSERT_NE(sceneSession, nullptr); } diff --git a/window_scene/test/unittest/session_stub_test.cpp b/window_scene/test/unittest/session_stub_test.cpp index cf565667cb..b01e22ea0f 100644 --- a/window_scene/test/unittest/session_stub_test.cpp +++ b/window_scene/test/unittest/session_stub_test.cpp @@ -1398,7 +1398,6 @@ HWTEST_F(SessionStubTest, HandleUpdateKeyFrameCloneNode, Function | SmallTest | ASSERT_EQ(result, ERR_NONE); int32_t ret = 0; ASSERT_EQ(reply.ReadInt32(ret), true); - ASSERT_EQ(ret, 0); } /** diff --git a/window_scene/test/unittest/session_test.cpp b/window_scene/test/unittest/session_test.cpp index 89768221ad..e538580d4f 100644 --- a/window_scene/test/unittest/session_test.cpp +++ b/window_scene/test/unittest/session_test.cpp @@ -40,6 +40,12 @@ namespace OHOS { namespace Rosen { namespace { const std::string UNDEFINED = "undefined"; + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } } class WindowSessionTest : public testing::Test { @@ -1667,9 +1673,12 @@ HWTEST_F(WindowSessionTest, GetAndSetSessionRequestRect, TestSize.Level1) */ HWTEST_F(WindowSessionTest, SetSessionRect01, TestSize.Level1) { + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); WSRect rect = session_->GetSessionRect(); session_->SetSessionRect(rect); - ASSERT_EQ(rect, session_->GetSessionRect()); + EXPECT_TRUE(g_errLog.find("id: %{public}d skip same rect") != std::string::npos); + LOG_SetCallback(nullptr); } /** diff --git a/window_scene/test/unittest/session_test3.cpp b/window_scene/test/unittest/session_test3.cpp index aa0ec8283b..d14d0b3195 100644 --- a/window_scene/test/unittest/session_test3.cpp +++ b/window_scene/test/unittest/session_test3.cpp @@ -645,7 +645,6 @@ HWTEST_F(WindowSessionTest3, NotifyClick, TestSize.Level1) session_->SetClickListener(func); session_->NotifyClick(false, false); EXPECT_EQ(resultValue, 1); - EXPECT_EQ(hasRequestFocus, false); EXPECT_EQ(hasIsClick, false); } @@ -1017,7 +1016,6 @@ HWTEST_F(WindowSessionTest3, NotifySessionPropertyChange01, TestSize.Level1) [&resultValue](int32_t persistentid, WindowInfoKey windowInfoKey) { resultValue = 1; }; session_->sessionPropertyChangeNotifyManagerFunc_ = nullptr; session_->NotifySessionPropertyChange(WindowInfoKey::WINDOW_RECT); - EXPECT_EQ(resultValue, 0); session_->SetSessionPropertyChangeNotifyManagerListener(func); session_->NotifySessionPropertyChange(WindowInfoKey::WINDOW_RECT); @@ -1173,7 +1171,6 @@ HWTEST_F(WindowSessionTest3, GetIsHighlighted, Function | SmallTest | Level2) ASSERT_NE(session_, nullptr); bool isHighlighted = false; ASSERT_EQ(session_->GetIsHighlighted(isHighlighted), WSError::WS_OK); - ASSERT_EQ(isHighlighted, false); } } // namespace } // namespace Rosen diff --git a/window_scene/test/unittest/session_test4.cpp b/window_scene/test/unittest/session_test4.cpp index 1ec4a6f112..12ef0f99e1 100644 --- a/window_scene/test/unittest/session_test4.cpp +++ b/window_scene/test/unittest/session_test4.cpp @@ -41,6 +41,12 @@ namespace Rosen { namespace { const std::string UNDEFINED = "undefined"; constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowSessionTest4" }; + std::string g_errLog; + void MyLogCallback(const LogType type, const LogLevel level, const unsigned int domain, const char *tag, + const char *msg) + { + g_errLog = msg; + } } // namespace namespace { std::string g_logMsg; @@ -935,16 +941,18 @@ HWTEST_F(WindowSessionTest4, ShouldCreateDetectTaskInRecent, TestSize.Level1) */ HWTEST_F(WindowSessionTest4, CreateWindowStateDetectTask, TestSize.Level1) { + g_errLog.clear(); + LOG_SetCallback(MyLogCallback); auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); }; session_->RegisterIsScreenLockedCallback(isScreenLockedCallback); session_->SetSessionState(SessionState::STATE_CONNECT); bool isAttach = true; session_->CreateWindowStateDetectTask(isAttach, WindowMode::WINDOW_MODE_UNDEFINED); - ASSERT_EQ(isAttach, true); + EXPECT_FALSE(g_errLog.find("Window attach state and session state mismatch, ") != std::string::npos); session_->handler_ = nullptr; session_->CreateWindowStateDetectTask(false, WindowMode::WINDOW_MODE_UNDEFINED); - ASSERT_EQ(session_->handler_, nullptr); + LOG_SetCallback(nullptr); } /** diff --git a/window_scene/test/unittest/ssmgr_specific_window_test.cpp b/window_scene/test/unittest/ssmgr_specific_window_test.cpp index 3f453a4a5a..ce2228d3c9 100644 --- a/window_scene/test/unittest/ssmgr_specific_window_test.cpp +++ b/window_scene/test/unittest/ssmgr_specific_window_test.cpp @@ -252,7 +252,6 @@ HWTEST_F(SSMgrSpecificWindowTest, IsKeyboardForeground, TestSize.Level1) ssm_->sceneSessionMap_.insert({ 0, sceneSession }); session->property_ = sptr::MakeSptr(); - ASSERT_NE(session->property_, nullptr); if (session->property_) { auto result1 = session->GetWindowType(); diff --git a/window_scene/test/unittest/system_session_test.cpp b/window_scene/test/unittest/system_session_test.cpp index a421e35164..5710f34387 100644 --- a/window_scene/test/unittest/system_session_test.cpp +++ b/window_scene/test/unittest/system_session_test.cpp @@ -318,15 +318,12 @@ HWTEST_F(SystemSessionTest, UpdateCameraWindowStatus01, TestSize.Level1) bool result = false; systemSession_->UpdateCameraWindowStatus(true); - ASSERT_EQ(result, false); systemSession_->specificCallback_ = specificCallback; systemSession_->UpdateCameraWindowStatus(true); - ASSERT_EQ(result, false); systemSession_->property_->SetWindowType(WindowType::WINDOW_TYPE_FLOAT_CAMERA); systemSession_->UpdateCameraWindowStatus(true); - ASSERT_EQ(result, false); systemSession_->specificCallback_->onCameraFloatSessionChange_ = [&result](uint32_t accessTokenId, bool isShowing) { result = isShowing; @@ -353,7 +350,6 @@ HWTEST_F(SystemSessionTest, UpdateCameraWindowStatus02, TestSize.Level1) sysSession->property_->SetWindowType(WindowType::WINDOW_TYPE_PIP); sysSession->property_->SetWindowMode(WindowMode::WINDOW_MODE_PIP); sysSession->UpdateCameraWindowStatus(true); - ASSERT_EQ(result, false); sysSession->specificCallback_->onCameraSessionChange_ = [&result](uint32_t accessTokenId, bool isShowing) { result = isShowing; @@ -372,7 +368,6 @@ HWTEST_F(SystemSessionTest, UpdateCameraWindowStatus02, TestSize.Level1) result = false; sysSession->pipTemplateInfo_.pipTemplateType = static_cast(PiPTemplateType::VIDEO_LIVE); sysSession->UpdateCameraWindowStatus(true); - ASSERT_EQ(result, false); } /** @@ -706,7 +701,8 @@ HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect03, TestSize.Level1) sysSession->dirtyFlags_ = 0; sysSession->isKeyboardPanelEnabled_ = true; - sysSession->Session::UpdateSizeChangeReason(SizeChangeReason::MAXIMIZE); + auto res = sysSession->Session::UpdateSizeChangeReason(SizeChangeReason::MAXIMIZE); + EXPECT_EQ(res, WSError::WS_OK); sptr specificCallback = sptr::MakeSptr(); @@ -714,17 +710,18 @@ HWTEST_F(SystemSessionTest, NotifyClientToUpdateRect03, TestSize.Level1) sysSession->specificCallback_ = specificCallback; sysSession->specificCallback_->onUpdateAvoidArea_ = nullptr; sysSession->GetLayoutController()->SetSessionRect({ 0, 0, 800, 800 }); - sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr); + res = sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr); usleep(WAIT_ASYNC_US); - EXPECT_EQ(sysSession->dirtyFlags_, 0); + EXPECT_EQ(res, WSError::WS_OK); sysSession->dirtyFlags_ = 0; sysSession->SetScbCoreEnabled(true); sysSession->Session::UpdateSizeChangeReason(SizeChangeReason::MAXIMIZE); sysSession->specificCallback_->onUpdateAvoidArea_ = [](const int32_t& persistentId) {}; - sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr); + res = sysSession->NotifyClientToUpdateRect("SystemSessionTest", nullptr); usleep(WAIT_ASYNC_US); EXPECT_EQ(sysSession->dirtyFlags_, static_cast(SessionUIDirtyFlag::AVOID_AREA)); + EXPECT_EQ(res, WSError::WS_OK); } /** -- Gitee