SFML/test/Window/VideoMode.test.cpp

112 lines
4.1 KiB
C++
Raw Normal View History

2021-12-24 06:21:51 +08:00
#include <SFML/Window/VideoMode.hpp>
2023-01-18 12:51:08 +08:00
#include <catch2/catch_test_macros.hpp>
2022-07-05 00:20:58 +08:00
#include <WindowUtil.hpp>
2023-09-19 10:43:13 +08:00
#include <algorithm>
#include <type_traits>
2023-09-19 10:43:13 +08:00
TEST_CASE("[Window] sf::VideoMode", runDisplayTests())
2021-12-24 06:21:51 +08:00
{
2023-01-18 12:51:08 +08:00
SECTION("Type traits")
{
STATIC_CHECK(std::is_copy_constructible_v<sf::VideoMode>);
STATIC_CHECK(std::is_copy_assignable_v<sf::VideoMode>);
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::VideoMode>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::VideoMode>);
}
SECTION("Construction")
2021-12-24 06:21:51 +08:00
{
2023-01-18 12:51:08 +08:00
SECTION("Default constructor")
2021-12-24 06:21:51 +08:00
{
2023-09-19 10:43:13 +08:00
const sf::VideoMode videoMode;
CHECK(videoMode.size == sf::Vector2u(0, 0));
2021-12-24 06:21:51 +08:00
CHECK(videoMode.bitsPerPixel == 0);
}
2023-01-18 12:51:08 +08:00
SECTION("Width, height constructor")
2021-12-24 06:21:51 +08:00
{
2023-09-19 10:43:13 +08:00
const sf::VideoMode videoMode({800, 600});
CHECK(videoMode.size == sf::Vector2u(800, 600));
2021-12-24 06:21:51 +08:00
CHECK(videoMode.bitsPerPixel == 32);
}
2023-01-18 12:51:08 +08:00
SECTION("Width, height, bit depth constructor")
2021-12-24 06:21:51 +08:00
{
2023-09-19 10:43:13 +08:00
const sf::VideoMode videoMode({800, 600}, 24);
CHECK(videoMode.size == sf::Vector2u(800, 600));
2021-12-24 06:21:51 +08:00
CHECK(videoMode.bitsPerPixel == 24);
}
}
2023-09-19 10:43:13 +08:00
SECTION("getFullscreenModes()")
{
const auto& modes = sf::VideoMode::getFullscreenModes();
CHECK(std::is_sorted(modes.begin(), modes.end(), std::greater<>()));
}
SECTION("isValid()")
{
const sf::VideoMode videoMode;
CHECK(!videoMode.isValid());
}
2023-01-18 12:51:08 +08:00
SECTION("Operators")
2021-12-24 06:21:51 +08:00
{
2023-01-18 12:51:08 +08:00
SECTION("operator==")
2021-12-24 06:21:51 +08:00
{
CHECK(sf::VideoMode() == sf::VideoMode());
CHECK(sf::VideoMode({0, 0}, 0) == sf::VideoMode({0, 0}, 0));
CHECK(sf::VideoMode({1080, 1920}, 64) == sf::VideoMode({1080, 1920}, 64));
2021-12-24 06:21:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("operator!=")
2021-12-24 06:21:51 +08:00
{
CHECK(sf::VideoMode() != sf::VideoMode({1, 0}));
CHECK(sf::VideoMode() != sf::VideoMode({0, 1}));
CHECK(sf::VideoMode() != sf::VideoMode({0, 0}, 1));
CHECK(sf::VideoMode({720, 720}) != sf::VideoMode({720, 720}, 24));
CHECK(sf::VideoMode({1080, 1920}, 16) != sf::VideoMode({400, 600}));
2021-12-24 06:21:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("operator<")
2021-12-24 06:21:51 +08:00
{
CHECK(sf::VideoMode() < sf::VideoMode({0, 0}, 1));
CHECK(sf::VideoMode({800, 800}, 24) < sf::VideoMode({1080, 1920}, 48));
CHECK(sf::VideoMode({400, 600}, 48) < sf::VideoMode({600, 400}, 48));
CHECK(sf::VideoMode({400, 400}, 48) < sf::VideoMode({400, 600}, 48));
2021-12-24 06:21:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("operator>")
2021-12-24 06:21:51 +08:00
{
CHECK(sf::VideoMode({1, 0}) > sf::VideoMode({0, 0}, 1));
CHECK(sf::VideoMode({800, 800}, 48) > sf::VideoMode({1080, 1920}, 24));
CHECK(sf::VideoMode({600, 400}, 48) > sf::VideoMode({400, 600}, 48));
CHECK(sf::VideoMode({400, 600}, 48) > sf::VideoMode({400, 400}, 48));
2021-12-24 06:21:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("operator<=")
2021-12-24 06:21:51 +08:00
{
CHECK(sf::VideoMode() <= sf::VideoMode({0, 0}, 1));
CHECK(sf::VideoMode({800, 800}, 24) <= sf::VideoMode({1080, 1920}, 48));
CHECK(sf::VideoMode({400, 600}, 48) <= sf::VideoMode({600, 400}, 48));
CHECK(sf::VideoMode({400, 400}, 48) <= sf::VideoMode({400, 600}, 48));
2021-12-24 06:21:51 +08:00
CHECK(sf::VideoMode() <= sf::VideoMode());
CHECK(sf::VideoMode({0, 0}, 0) <= sf::VideoMode({0, 0}, 0));
CHECK(sf::VideoMode({1080, 1920}, 64) <= sf::VideoMode({1080, 1920}, 64));
2021-12-24 06:21:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("operator>=")
2021-12-24 06:21:51 +08:00
{
CHECK(sf::VideoMode({1, 0}) >= sf::VideoMode({0, 0}, 1));
CHECK(sf::VideoMode({800, 800}, 48) >= sf::VideoMode({1080, 1920}, 24));
CHECK(sf::VideoMode({600, 400}, 48) >= sf::VideoMode({400, 600}, 48));
CHECK(sf::VideoMode({400, 600}, 48) >= sf::VideoMode({400, 400}, 48));
2021-12-24 06:21:51 +08:00
CHECK(sf::VideoMode() >= sf::VideoMode());
CHECK(sf::VideoMode({0, 0}, 0) >= sf::VideoMode({0, 0}, 0));
CHECK(sf::VideoMode({1080, 1920}, 64) >= sf::VideoMode({1080, 1920}, 64));
2021-12-24 06:21:51 +08:00
}
}
}