SFML/test/Window/WindowBase.test.cpp

151 lines
4.9 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>
#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());
CHECK(windowBase.getSystemHandle() == sf::WindowHandle());
}
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.getSystemHandle() != sf::WindowHandle());
}
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.getSystemHandle() != sf::WindowHandle());
}
}
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.getSystemHandle() != sf::WindowHandle());
}
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.getSystemHandle() != sf::WindowHandle());
}
}
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
{
sf::WindowBase windowBase;
sf::Event event;
CHECK(!windowBase.pollEvent(event));
}
2023-01-18 12:51:08 +08:00
SECTION("waitEvent()")
2023-02-04 15:06:22 +08:00
{
sf::WindowBase windowBase;
sf::Event event;
CHECK(!windowBase.waitEvent(event));
}
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
}
}