SFML/test/Window/WindowBase.test.cpp

199 lines
6.7 KiB
C++
Raw Normal View History

#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>
#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")
{
2023-12-27 07:31:08 +08:00
STATIC_CHECK(std::has_virtual_destructor_v<sf::WindowBase>);
2023-01-18 12:51:08 +08:00
STATIC_CHECK(!std::is_copy_constructible_v<sf::WindowBase>);
STATIC_CHECK(!std::is_copy_assignable_v<sf::WindowBase>);
2023-12-27 07:31:08 +08:00
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::WindowBase>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::WindowBase>);
2023-01-18 12:51:08 +08:00
}
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());
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));
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));
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
2023-02-04 15:06:22 +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));
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));
CHECK(windowBase.getNativeHandle() != sf::WindowHandle());
2023-02-04 15:06:22 +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(100)).toDuration());
2024-06-14 19:53:58 +08:00
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-01-18 12:51:08 +08:00
SECTION("Minimum size")
{
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")
{
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()")
{
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()")
{
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
}
}