From 2af65286b71c1c9ad14372c1dda4f60bebf7a8ec Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 4 Feb 2023 00:06:22 -0700 Subject: [PATCH] Add tests for `sf::WindowBase` --- test/CMakeLists.txt | 3 + test/TestUtilities/GraphicsUtil.hpp | 6 -- test/TestUtilities/WindowUtil.hpp | 6 ++ test/Window/WindowBase.test.cpp | 106 ++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 6 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 286f7110..86a6391b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -67,6 +67,9 @@ set(WINDOW_SRC Window/WindowBase.test.cpp ) sfml_add_test(test-sfml-window "${WINDOW_SRC}" SFML::Window) +if(SFML_RUN_DISPLAY_TESTS) + target_compile_definitions(test-sfml-window PRIVATE SFML_RUN_DISPLAY_TESTS) +endif() set(GRAPHICS_SRC Graphics/BlendMode.test.cpp diff --git a/test/TestUtilities/GraphicsUtil.hpp b/test/TestUtilities/GraphicsUtil.hpp index 18da9742..4b134356 100644 --- a/test/TestUtilities/GraphicsUtil.hpp +++ b/test/TestUtilities/GraphicsUtil.hpp @@ -11,12 +11,6 @@ #include #include -#ifdef SFML_RUN_DISPLAY_TESTS -static constexpr bool skipDisplayTests = false; -#else -static constexpr bool skipDisplayTests = true; -#endif - namespace sf { struct BlendMode; diff --git a/test/TestUtilities/WindowUtil.hpp b/test/TestUtilities/WindowUtil.hpp index e0b58e09..b555c746 100644 --- a/test/TestUtilities/WindowUtil.hpp +++ b/test/TestUtilities/WindowUtil.hpp @@ -7,6 +7,12 @@ #include +#ifdef SFML_RUN_DISPLAY_TESTS +static constexpr bool skipDisplayTests = false; +#else +static constexpr bool skipDisplayTests = true; +#endif + // String conversions for doctest framework namespace sf { diff --git a/test/Window/WindowBase.test.cpp b/test/Window/WindowBase.test.cpp index 63032aa4..8038b56f 100644 --- a/test/Window/WindowBase.test.cpp +++ b/test/Window/WindowBase.test.cpp @@ -1,8 +1,114 @@ #include +// Other 1st party headers +#include +#include +#include + +#include + +#include #include static_assert(!std::is_copy_constructible_v); static_assert(!std::is_copy_assignable_v); static_assert(!std::is_nothrow_move_constructible_v); static_assert(!std::is_nothrow_move_assignable_v); + +TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests)) +{ + SUBCASE("Construction") + { + SUBCASE("Default constructor") + { + const sf::WindowBase windowBase; + CHECK(!windowBase.isOpen()); + CHECK(windowBase.getPosition() == sf::Vector2i()); + CHECK(windowBase.getSize() == sf::Vector2u()); + CHECK(!windowBase.hasFocus()); + CHECK(windowBase.getSystemHandle() == sf::WindowHandle()); + } + + SUBCASE("Mode and title constructor") + { + const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests"); + CHECK(windowBase.isOpen()); + CHECK(windowBase.getSize() == sf::Vector2u(360, 240)); + CHECK(windowBase.getSystemHandle() != sf::WindowHandle()); + } + + SUBCASE("Mode, title, and style constructor") + { + const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests", sf::Style::Resize); + CHECK(windowBase.isOpen()); + CHECK(windowBase.getSize() == sf::Vector2u(360, 240)); + CHECK(windowBase.getSystemHandle() != sf::WindowHandle()); + } + } + + SUBCASE("create()") + { + sf::WindowBase windowBase; + + SUBCASE("Mode and title") + { + windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests"); + CHECK(windowBase.isOpen()); + CHECK(windowBase.getSize() == sf::Vector2u(240, 360)); + CHECK(windowBase.getSystemHandle() != sf::WindowHandle()); + } + + SUBCASE("Mode, title, and style") + { + windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests", sf::Style::Resize); + CHECK(windowBase.isOpen()); + CHECK(windowBase.getSize() == sf::Vector2u(240, 360)); + CHECK(windowBase.getSystemHandle() != sf::WindowHandle()); + } + } + + SUBCASE("close()") + { + sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests"); + windowBase.close(); + CHECK(!windowBase.isOpen()); + } + + SUBCASE("pollEvent()") + { + sf::WindowBase windowBase; + sf::Event event; + CHECK(!windowBase.pollEvent(event)); + } + + SUBCASE("waitEvent()") + { + sf::WindowBase windowBase; + sf::Event event; + CHECK(!windowBase.waitEvent(event)); + } + + SUBCASE("Get/set position") + { + sf::WindowBase windowBase; + windowBase.setPosition({12, 34}); + CHECK(windowBase.getPosition() == sf::Vector2i()); + } + + SUBCASE("Set/get size") + { + SUBCASE("Uninitialized window") + { + sf::WindowBase windowBase; + windowBase.setSize({128, 256}); + CHECK(windowBase.getSize() == sf::Vector2u()); + } + + SUBCASE("Initialized window") + { + sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests"); + windowBase.setSize({128, 256}); + CHECK(windowBase.getSize() == sf::Vector2u(128, 256)); + } + } +}