Skip to content

Commit 7bff721

Browse files
Add window manager unit test for window pinning
1 parent 07f855f commit 7bff721

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

tests/s25Main/UI/testWindowManager.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,75 @@ BOOST_FIXTURE_TEST_CASE(RightclickClosesWindow, uiHelper::Fixture)
466466
BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd2);
467467
}
468468

469+
BOOST_FIXTURE_TEST_CASE(PinnedWindows, uiHelper::Fixture)
470+
{
471+
constexpr KeyEvent evEsc{KeyType::Escape, 0, false, false, false};
472+
constexpr KeyEvent evAltW{KeyType::Char, 'w', false, false, true};
473+
474+
BOOST_TEST_CONTEXT("Pinned windows ignore escape key")
475+
{
476+
auto* wnd = &WINDOWMANAGER.Show(std::make_unique<TestIngameWnd>(CGI_HELP));
477+
478+
wnd->SetPinned();
479+
BOOST_TEST_CONTEXT("Pinned")
480+
{
481+
BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd);
482+
WINDOWMANAGER.Msg_KeyDown(evEsc);
483+
MOCK_EXPECT(wnd->Draw_).once();
484+
WINDOWMANAGER.Draw();
485+
BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd);
486+
}
487+
488+
wnd->SetPinned(false);
489+
BOOST_TEST_CONTEXT("Un-pinned")
490+
{
491+
WINDOWMANAGER.Msg_KeyDown(evEsc);
492+
WINDOWMANAGER.Draw();
493+
REQUIRE_WINDOW_DESTROYED(wnd);
494+
}
495+
}
496+
497+
BOOST_TEST_CONTEXT("Pinned windows close on Alt+W")
498+
{
499+
auto* wnd = &WINDOWMANAGER.Show(std::make_unique<TestIngameWnd>(CGI_HELP));
500+
501+
wnd->SetPinned();
502+
BOOST_TEST_CONTEXT("Pinned")
503+
{
504+
BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd);
505+
WINDOWMANAGER.Msg_KeyDown(evAltW);
506+
WINDOWMANAGER.Draw();
507+
REQUIRE_WINDOW_DESTROYED(wnd);
508+
}
509+
}
510+
511+
BOOST_TEST_CONTEXT("Pinned windows ignore right click")
512+
{
513+
auto* wnd = &WINDOWMANAGER.Show(std::make_unique<TestIngameWnd>(CGI_HELP));
514+
BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd);
515+
const MouseCoords evRDown(wnd->GetDrawPos() + Position(10, 10), false, true);
516+
517+
wnd->SetPinned();
518+
BOOST_TEST_CONTEXT("Pinned")
519+
{
520+
WINDOWMANAGER.Msg_RightDown(evRDown);
521+
MOCK_EXPECT(wnd->Draw_).once();
522+
WINDOWMANAGER.Draw();
523+
BOOST_TEST_REQUIRE(WINDOWMANAGER.GetTopMostWindow() == wnd);
524+
}
525+
526+
wnd->SetPinned(false);
527+
BOOST_TEST_CONTEXT("Un-pinned")
528+
{
529+
WINDOWMANAGER.Msg_RightDown(evRDown);
530+
WINDOWMANAGER.Draw();
531+
REQUIRE_WINDOW_DESTROYED(wnd);
532+
}
533+
}
534+
535+
mock::verify();
536+
}
537+
469538
MOCK_BASE_CLASS(MockSettingsWnd, TransmitSettingsIgwAdapter)
470539
{
471540
static int activeWnds;

0 commit comments

Comments
 (0)