2022-07-25 14:36:05 +08:00
|
|
|
#include <SFML/Window/WindowBase.hpp>
|
|
|
|
|
2023-02-04 15:06:22 +08:00
|
|
|
// Other 1st party headers
|
|
|
|
#include <SFML/Window/Event.hpp>
|
|
|
|
#include <SFML/Window/VideoMode.hpp>
|
|
|
|
|
2023-04-24 20:13:52 +08:00
|
|
|
#include <SFML/System/String.hpp>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2023-02-04 15:06:22 +08:00
|
|
|
|
|
|
|
#include <WindowUtil.hpp>
|
2024-06-14 19:53:58 +08:00
|
|
|
#include <chrono>
|
2022-07-25 14:36:05 +08:00
|
|
|
#include <type_traits>
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
TEST_CASE("[Window] sf::WindowBase", runDisplayTests())
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Type traits")
|
|
|
|
{
|
|
|
|
STATIC_CHECK(!std::is_copy_constructible_v<sf::WindowBase>);
|
|
|
|
STATIC_CHECK(!std::is_copy_assignable_v<sf::WindowBase>);
|
|
|
|
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::WindowBase>);
|
|
|
|
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::WindowBase>);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Construction")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Default constructor")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
const sf::WindowBase windowBase;
|
|
|
|
CHECK(!windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getPosition() == sf::Vector2i());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u());
|
|
|
|
CHECK(!windowBase.hasFocus());
|
2023-08-28 05:34:31 +08:00
|
|
|
CHECK(windowBase.getNativeHandle() == sf::WindowHandle());
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Mode and title constructor")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
|
|
|
CHECK(windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(360, 240));
|
2023-08-28 05:34:31 +08:00
|
|
|
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Mode, title, and style constructor")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests", sf::Style::Resize);
|
|
|
|
CHECK(windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(360, 240));
|
2023-08-28 05:34:31 +08:00
|
|
|
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
2024-01-02 06:38:14 +08:00
|
|
|
|
|
|
|
SECTION("Mode, title, style, and state constructor")
|
|
|
|
{
|
|
|
|
const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests", sf::Style::Resize, sf::State::Windowed);
|
|
|
|
CHECK(windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(360, 240));
|
|
|
|
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Mode, title, and state constructor")
|
|
|
|
{
|
|
|
|
const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests", sf::State::Windowed);
|
|
|
|
CHECK(windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(360, 240));
|
|
|
|
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
|
|
|
|
}
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("create()")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase;
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Mode and title")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests");
|
|
|
|
CHECK(windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(240, 360));
|
2023-08-28 05:34:31 +08:00
|
|
|
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Mode, title, and style")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests", sf::Style::Resize);
|
|
|
|
CHECK(windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(240, 360));
|
2023-08-28 05:34:31 +08:00
|
|
|
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
2024-01-02 06:38:14 +08:00
|
|
|
|
|
|
|
SECTION("Mode, title, style, and state")
|
|
|
|
{
|
|
|
|
windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests", sf::Style::Resize, sf::State::Windowed);
|
|
|
|
CHECK(windowBase.isOpen());
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(240, 360));
|
|
|
|
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
|
|
|
|
}
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("close()")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
|
|
|
windowBase.close();
|
|
|
|
CHECK(!windowBase.isOpen());
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("pollEvent()")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
2024-06-14 19:53:58 +08:00
|
|
|
SECTION("Uninitialized window")
|
|
|
|
{
|
|
|
|
sf::WindowBase windowBase;
|
|
|
|
CHECK(!windowBase.pollEvent());
|
|
|
|
}
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("waitEvent()")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
2024-06-14 19:53:58 +08:00
|
|
|
SECTION("Uninitialized window")
|
|
|
|
{
|
|
|
|
sf::WindowBase windowBase;
|
|
|
|
CHECK(!windowBase.waitEvent());
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Initialized window")
|
|
|
|
{
|
|
|
|
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
|
|
|
|
|
|
|
constexpr auto timeout = sf::milliseconds(100);
|
|
|
|
|
|
|
|
const auto startTime = std::chrono::steady_clock::now();
|
|
|
|
const auto event = windowBase.waitEvent(timeout);
|
|
|
|
const auto elapsed = std::chrono::steady_clock::now() - startTime;
|
|
|
|
|
|
|
|
REQUIRE(elapsed < (timeout + sf::milliseconds(50)).toDuration());
|
|
|
|
|
|
|
|
if (elapsed <= timeout.toDuration())
|
|
|
|
CHECK(event);
|
|
|
|
else
|
|
|
|
CHECK(!event);
|
|
|
|
}
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Set/get position")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase;
|
|
|
|
windowBase.setPosition({12, 34});
|
|
|
|
CHECK(windowBase.getPosition() == sf::Vector2i());
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Set/get size")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Uninitialized window")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase;
|
|
|
|
windowBase.setSize({128, 256});
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u());
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Initialized window")
|
2023-02-04 15:06:22 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
|
|
|
windowBase.setSize({128, 256});
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(128, 256));
|
|
|
|
}
|
2023-05-01 08:00:04 +08:00
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Minimum size")
|
2023-05-01 08:00:04 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
|
|
|
windowBase.setMinimumSize(sf::Vector2u(128, 256));
|
|
|
|
windowBase.setSize({100, 100});
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(128, 256));
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("Maximum size")
|
2023-05-01 08:00:04 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
|
|
|
windowBase.setMaximumSize(sf::Vector2u(128, 256));
|
|
|
|
windowBase.setSize({400, 400});
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(128, 256));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("setMinimumSize()")
|
2023-05-01 08:00:04 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase(sf::VideoMode({100, 100}), "WindowBase Tests", sf::Style::Default ^ sf::Style::Resize);
|
|
|
|
windowBase.setMinimumSize(sf::Vector2u(200, 300));
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(200, 300));
|
|
|
|
windowBase.setMaximumSize(sf::Vector2u(200, 300));
|
|
|
|
}
|
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
SECTION("setMinimumSize()")
|
2023-05-01 08:00:04 +08:00
|
|
|
{
|
|
|
|
sf::WindowBase windowBase(sf::VideoMode({400, 400}), "WindowBase Tests", sf::Style::Default ^ sf::Style::Resize);
|
|
|
|
windowBase.setMaximumSize(sf::Vector2u(200, 300));
|
|
|
|
CHECK(windowBase.getSize() == sf::Vector2u(200, 300));
|
|
|
|
windowBase.setMinimumSize(sf::Vector2u(200, 300));
|
2023-02-04 15:06:22 +08:00
|
|
|
}
|
|
|
|
}
|