Skip to content

Commit 3cef104

Browse files
Add unit test for window title bar buttons
1 parent 35905a2 commit 3cef104

1 file changed

Lines changed: 128 additions & 0 deletions

File tree

tests/s25Main/UI/testIngameWindow.cpp

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,134 @@ BOOST_AUTO_TEST_CASE(SaveAndRestorePinned)
262262
}
263263
}
264264

265+
BOOST_AUTO_TEST_CASE(TitleBarButtons)
266+
{
267+
constexpr auto id = CGI_MINIMAP;
268+
auto it = SETTINGS.windows.persistentSettings.find(id);
269+
BOOST_REQUIRE(it != SETTINGS.windows.persistentSettings.end());
270+
auto& settings = it->second;
271+
272+
// Don't try to play sounds
273+
SETTINGS.sound.effectsEnabled = false;
274+
275+
BOOST_TEST_CONTEXT("Window pinning disabled")
276+
{
277+
SETTINGS.interface.enableWindowPinning = false;
278+
settings.isMinimized = false;
279+
settings.isPinned = false;
280+
BOOST_TEST_CONTEXT("Left title bar button closes window")
281+
{
282+
IngameWindow wnd(id, IngameWindow::posLastOrCenter, Extent(100, 100), "Test Window", nullptr);
283+
const MouseCoords evLDown{wnd.GetPos() + DrawPoint(4, 4), true};
284+
285+
BOOST_TEST(!wnd.ShouldBeClosed());
286+
BOOST_TEST(!wnd.IsMinimized());
287+
BOOST_TEST(!wnd.IsPinned());
288+
wnd.MouseLeftUp(evLDown);
289+
BOOST_TEST(wnd.ShouldBeClosed());
290+
BOOST_TEST(!wnd.IsMinimized());
291+
BOOST_TEST(!wnd.IsPinned());
292+
BOOST_TEST(!settings.isOpen);
293+
BOOST_TEST(!settings.isMinimized);
294+
BOOST_TEST(!settings.isPinned);
295+
}
296+
297+
BOOST_TEST_CONTEXT("Double-click on the window title has no effect")
298+
{
299+
IngameWindow wnd(id, IngameWindow::posLastOrCenter, Extent(100, 100), "Test Window", nullptr);
300+
const MouseCoords evLDblDown{wnd.GetPos() + DrawPoint(wnd.GetSize().x / 2, 4), true, false, true};
301+
302+
BOOST_TEST(!wnd.ShouldBeClosed());
303+
BOOST_TEST(!wnd.IsMinimized());
304+
BOOST_TEST(!wnd.IsPinned());
305+
wnd.MouseLeftUp(evLDblDown);
306+
BOOST_TEST(!wnd.ShouldBeClosed());
307+
BOOST_TEST(!wnd.IsMinimized());
308+
BOOST_TEST(!wnd.IsPinned());
309+
BOOST_TEST(settings.isOpen);
310+
BOOST_TEST(!settings.isMinimized);
311+
BOOST_TEST(!settings.isPinned);
312+
}
313+
314+
settings.isMinimized = false;
315+
BOOST_TEST_CONTEXT("Right title bar button minimizes window")
316+
{
317+
IngameWindow wnd(id, IngameWindow::posLastOrCenter, Extent(100, 100), "Test Window", nullptr);
318+
const MouseCoords evLDown{wnd.GetPos() + DrawPoint(wnd.GetSize().x, 0) + DrawPoint(-4, 4), true};
319+
320+
BOOST_TEST(!wnd.ShouldBeClosed());
321+
BOOST_TEST(!wnd.IsMinimized());
322+
BOOST_TEST(!wnd.IsPinned());
323+
wnd.MouseLeftUp(evLDown);
324+
BOOST_TEST(!wnd.ShouldBeClosed());
325+
BOOST_TEST(wnd.IsMinimized());
326+
BOOST_TEST(!wnd.IsPinned());
327+
BOOST_TEST(settings.isOpen);
328+
BOOST_TEST(settings.isMinimized);
329+
BOOST_TEST(!settings.isPinned);
330+
}
331+
}
332+
333+
BOOST_TEST_CONTEXT("Window pinning enabled")
334+
{
335+
SETTINGS.interface.enableWindowPinning = true;
336+
settings.isMinimized = false;
337+
settings.isPinned = false;
338+
BOOST_TEST_CONTEXT("Left title bar button closes window")
339+
{
340+
IngameWindow wnd(id, IngameWindow::posLastOrCenter, Extent(100, 100), "Test Window", nullptr);
341+
const MouseCoords evLDown{wnd.GetPos() + DrawPoint(4, 4), true};
342+
343+
BOOST_TEST(!wnd.ShouldBeClosed());
344+
BOOST_TEST(!wnd.IsMinimized());
345+
BOOST_TEST(!wnd.IsPinned());
346+
wnd.MouseLeftUp(evLDown);
347+
BOOST_TEST(wnd.ShouldBeClosed());
348+
BOOST_TEST(!wnd.IsMinimized());
349+
BOOST_TEST(!wnd.IsPinned());
350+
BOOST_TEST(!settings.isOpen);
351+
BOOST_TEST(!settings.isMinimized);
352+
BOOST_TEST(!settings.isPinned);
353+
}
354+
355+
BOOST_TEST_CONTEXT("Double-click on the window title minimizes")
356+
{
357+
IngameWindow wnd(id, IngameWindow::posLastOrCenter, Extent(100, 100), "Test Window", nullptr);
358+
const MouseCoords evLDblDown{wnd.GetPos() + DrawPoint(wnd.GetSize().x / 2, 4), true, false, true};
359+
360+
BOOST_TEST(!wnd.ShouldBeClosed());
361+
BOOST_TEST(!wnd.IsMinimized());
362+
BOOST_TEST(!wnd.IsPinned());
363+
wnd.MouseLeftUp(evLDblDown);
364+
BOOST_TEST(!wnd.ShouldBeClosed());
365+
BOOST_TEST(wnd.IsMinimized());
366+
BOOST_TEST(!wnd.IsPinned());
367+
BOOST_TEST(settings.isOpen);
368+
BOOST_TEST(settings.isMinimized);
369+
BOOST_TEST(!settings.isPinned);
370+
}
371+
372+
settings.isMinimized = false;
373+
settings.isPinned = false;
374+
BOOST_TEST_CONTEXT("Right title bar button pins window")
375+
{
376+
IngameWindow wnd(id, IngameWindow::posLastOrCenter, Extent(100, 100), "Test Window", nullptr);
377+
const MouseCoords evLDown{wnd.GetPos() + DrawPoint(wnd.GetSize().x, 0) + DrawPoint(-4, 4), true};
378+
379+
BOOST_TEST(!wnd.ShouldBeClosed());
380+
BOOST_TEST(!wnd.IsMinimized());
381+
BOOST_TEST(!wnd.IsPinned());
382+
wnd.MouseLeftUp(evLDown);
383+
BOOST_TEST(!wnd.ShouldBeClosed());
384+
BOOST_TEST(!wnd.IsMinimized());
385+
BOOST_TEST(wnd.IsPinned());
386+
BOOST_TEST(settings.isOpen);
387+
BOOST_TEST(!settings.isMinimized);
388+
BOOST_TEST(settings.isPinned);
389+
}
390+
}
391+
}
392+
265393
namespace {
266394
void WindowPositioning_testOne(IngameWindow& wnd, const char* context, const std::function<void()>& checkNormal,
267395
const std::function<void()>& checkMinimized)

0 commit comments

Comments
 (0)