Switch to Catch2
This commit is contained in:
parent
b14d0b47e6
commit
f6dfc04938
@ -112,7 +112,7 @@ IncludeCategories:
|
||||
- Priority: 8
|
||||
Regex: '^<SFML\/System'
|
||||
- Priority: 9
|
||||
Regex: '^<(glad|gl|X11|jni|android|stb_|GLES2|vorbis|doctest)'
|
||||
Regex: '^<(glad|gl|X11|jni|android|stb_|GLES2|vorbis|catch2)'
|
||||
- Priority: 10
|
||||
Regex: '^<([^c](.+)|coroutine|charconv|chrono|complex|concepts|condition_variable)>$'
|
||||
- Priority: 11
|
||||
|
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -139,13 +139,13 @@ jobs:
|
||||
if [ "${{ runner.os }}" == "Windows" ]; then
|
||||
# Make use of a test to print OpenGL vendor/renderer/version info to the console
|
||||
# We have to convert the backslashes in $GITHUB_WORKSPACE to (forward) slashes so bash doesn't try to escape them in the sh command
|
||||
find $(echo $GITHUB_WORKSPACE | sed 's/\\\\/\\//g')/build/bin -name test-sfml-window.exe -exec sh -c "{} --test-case=\"[Window] sf::Context\" --subcase=\"Version String\" | grep OpenGL" \;
|
||||
find $(echo $GITHUB_WORKSPACE | sed 's/\\\\/\\//g')/build/bin -name test-sfml-window.exe -exec sh -c "{} *sf::Context* --section=\"Version String\" --success | grep OpenGL" \;
|
||||
# Run the tests
|
||||
cmake --build $GITHUB_WORKSPACE/build --target runtests --config ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }}
|
||||
# Coverage is already generated on Windows when running tests.
|
||||
else
|
||||
# Make use of a test to print OpenGL vendor/renderer/version info to the console
|
||||
find $GITHUB_WORKSPACE/build/bin -name test-sfml-window -exec sh -c "{} --test-case=\"[Window] sf::Context\" --subcase=\"Version String\" | grep OpenGL" \;
|
||||
find $GITHUB_WORKSPACE/build/bin -name test-sfml-window -exec sh -c "{} *sf::Context* --section=\"Version String\" --success | grep OpenGL" \;
|
||||
# Run the tests
|
||||
ctest --test-dir $GITHUB_WORKSPACE/build --output-on-failure -C ${{ matrix.type.name == 'Debug' && 'Debug' || 'Release' }}
|
||||
# Run gcovr to extract coverage information from the test run
|
||||
|
@ -376,7 +376,7 @@ function(sfml_add_test target SOURCES DEPENDS)
|
||||
endif()
|
||||
|
||||
# Add the test
|
||||
doctest_discover_tests(${target})
|
||||
catch_discover_tests(${target})
|
||||
endfunction()
|
||||
|
||||
# Find the requested package and make an INTERFACE library from it
|
||||
|
@ -1,21 +1,24 @@
|
||||
include(FetchContent)
|
||||
|
||||
set(DOCTEST_NO_INSTALL ON)
|
||||
FetchContent_Declare(doctest
|
||||
GIT_REPOSITORY https://github.com/doctest/doctest.git
|
||||
GIT_TAG v2.4.9
|
||||
)
|
||||
FetchContent_MakeAvailable(doctest)
|
||||
include(${doctest_SOURCE_DIR}/scripts/cmake/doctest.cmake)
|
||||
|
||||
# Ensure that doctest sources and headers are not analyzed by any tools
|
||||
set_target_properties(doctest_with_main PROPERTIES COMPILE_OPTIONS "" EXPORT_COMPILE_COMMANDS OFF)
|
||||
get_target_property(DOCTEST_INCLUDE_DIRS doctest INTERFACE_INCLUDE_DIRECTORIES)
|
||||
target_include_directories(doctest SYSTEM INTERFACE ${DOCTEST_INCLUDE_DIRS})
|
||||
|
||||
add_subdirectory(install)
|
||||
set_target_warnings(test-sfml-install)
|
||||
|
||||
set(CATCH_CONFIG_FAST_COMPILE ON)
|
||||
FetchContent_Declare(Catch2
|
||||
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
|
||||
GIT_TAG v3.3.2)
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
include(Catch)
|
||||
|
||||
# Build Catch2 in C++17 mode to enable C++17 features
|
||||
target_compile_features(Catch2 PRIVATE cxx_std_17)
|
||||
|
||||
# Ensure that Catch2 sources and headers are not analyzed by any tools
|
||||
set_target_properties(Catch2 PROPERTIES COMPILE_OPTIONS "" EXPORT_COMPILE_COMMANDS OFF)
|
||||
set_target_properties(Catch2WithMain PROPERTIES EXPORT_COMPILE_COMMANDS OFF)
|
||||
get_target_property(CATCH2_INCLUDE_DIRS Catch2 INTERFACE_INCLUDE_DIRECTORIES)
|
||||
target_include_directories(Catch2 SYSTEM INTERFACE ${CATCH2_INCLUDE_DIRS})
|
||||
|
||||
add_library(sfml-test-main STATIC
|
||||
TestUtilities/SystemUtil.hpp
|
||||
TestUtilities/SystemUtil.cpp
|
||||
@ -25,10 +28,14 @@ add_library(sfml-test-main STATIC
|
||||
TestUtilities/GraphicsUtil.cpp
|
||||
)
|
||||
target_include_directories(sfml-test-main PUBLIC TestUtilities)
|
||||
target_compile_definitions(sfml-test-main PUBLIC DOCTEST_CONFIG_REQUIRE_STRINGIFICATION_FOR_ALL_USED_TYPES)
|
||||
target_link_libraries(sfml-test-main PUBLIC SFML::System doctest::doctest_with_main)
|
||||
target_link_libraries(sfml-test-main PUBLIC SFML::System Catch2::Catch2WithMain)
|
||||
set_target_warnings(sfml-test-main)
|
||||
|
||||
sfml_set_option(SFML_RUN_DISPLAY_TESTS ON BOOL "TRUE to run tests that require a display, FALSE to ignore it")
|
||||
if(SFML_RUN_DISPLAY_TESTS)
|
||||
target_compile_definitions(sfml-test-main PRIVATE SFML_RUN_DISPLAY_TESTS)
|
||||
endif()
|
||||
|
||||
set(SYSTEM_SRC
|
||||
System/Angle.test.cpp
|
||||
System/Clock.test.cpp
|
||||
@ -50,8 +57,6 @@ target_compile_definitions(test-sfml-system PRIVATE
|
||||
EXPECTED_SFML_VERSION_IS_RELEASE=$<IF:$<BOOL:${VERSION_IS_RELEASE}>,true,false>
|
||||
)
|
||||
|
||||
sfml_set_option(SFML_RUN_DISPLAY_TESTS ON BOOL "TRUE to run tests that require a display, FALSE to ignore it")
|
||||
|
||||
set(WINDOW_SRC
|
||||
Window/Context.test.cpp
|
||||
Window/ContextSettings.test.cpp
|
||||
@ -62,9 +67,6 @@ 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
|
||||
|
@ -1,20 +1,23 @@
|
||||
#include <SFML/Graphics/BlendMode.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::BlendMode>);
|
||||
static_assert(std::is_copy_assignable_v<sf::BlendMode>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::BlendMode>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::BlendMode>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::BlendMode")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::BlendMode>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::BlendMode>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::BlendMode>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::BlendMode>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::BlendMode blendMode;
|
||||
CHECK(blendMode.colorSrcFactor == sf::BlendMode::SrcAlpha);
|
||||
@ -25,7 +28,7 @@ TEST_CASE("[Graphics] sf::BlendMode")
|
||||
CHECK(blendMode.alphaEquation == sf::BlendMode::Add);
|
||||
}
|
||||
|
||||
SUBCASE("Combined color and alpha constructor using default parameter")
|
||||
SECTION("Combined color and alpha constructor using default parameter")
|
||||
{
|
||||
const sf::BlendMode blendMode(sf::BlendMode::Zero, sf::BlendMode::SrcColor);
|
||||
CHECK(blendMode.colorSrcFactor == sf::BlendMode::Zero);
|
||||
@ -36,7 +39,7 @@ TEST_CASE("[Graphics] sf::BlendMode")
|
||||
CHECK(blendMode.alphaEquation == sf::BlendMode::Add);
|
||||
}
|
||||
|
||||
SUBCASE("Combined color and alpha constructor")
|
||||
SECTION("Combined color and alpha constructor")
|
||||
{
|
||||
const sf::BlendMode blendMode(sf::BlendMode::Zero, sf::BlendMode::SrcColor, sf::BlendMode::ReverseSubtract);
|
||||
CHECK(blendMode.colorSrcFactor == sf::BlendMode::Zero);
|
||||
@ -47,7 +50,7 @@ TEST_CASE("[Graphics] sf::BlendMode")
|
||||
CHECK(blendMode.alphaEquation == sf::BlendMode::ReverseSubtract);
|
||||
}
|
||||
|
||||
SUBCASE("Separate color and alpha constructor")
|
||||
SECTION("Separate color and alpha constructor")
|
||||
{
|
||||
const sf::BlendMode blendMode(sf::BlendMode::Zero,
|
||||
sf::BlendMode::SrcColor,
|
||||
@ -64,9 +67,9 @@ TEST_CASE("[Graphics] sf::BlendMode")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("Operators")
|
||||
{
|
||||
SUBCASE("operator==")
|
||||
SECTION("operator==")
|
||||
{
|
||||
CHECK(sf::BlendMode() == sf::BlendMode());
|
||||
CHECK(sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One) ==
|
||||
@ -102,7 +105,7 @@ TEST_CASE("[Graphics] sf::BlendMode")
|
||||
sf::BlendMode::Max));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
CHECK_FALSE(sf::BlendMode() != sf::BlendMode());
|
||||
CHECK_FALSE(sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One) !=
|
||||
@ -139,7 +142,7 @@ TEST_CASE("[Graphics] sf::BlendMode")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Static constants")
|
||||
SECTION("Static constants")
|
||||
{
|
||||
CHECK(sf::BlendAlpha.colorSrcFactor == sf::BlendMode::SrcAlpha);
|
||||
CHECK(sf::BlendAlpha.colorDstFactor == sf::BlendMode::OneMinusSrcAlpha);
|
||||
|
@ -1,18 +1,21 @@
|
||||
#include <SFML/Graphics/CircleShape.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::CircleShape>);
|
||||
static_assert(std::is_copy_assignable_v<sf::CircleShape>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::CircleShape>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::CircleShape>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::CircleShape")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::CircleShape>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::CircleShape>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::CircleShape>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::CircleShape>);
|
||||
}
|
||||
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::CircleShape circle;
|
||||
CHECK(circle.getRadius() == 0.f);
|
||||
@ -21,7 +24,7 @@ TEST_CASE("[Graphics] sf::CircleShape")
|
||||
CHECK(circle.getPoint(i) == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("Radius constructor")
|
||||
SECTION("Radius constructor")
|
||||
{
|
||||
const sf::CircleShape circle(15.f);
|
||||
CHECK(circle.getRadius() == 15.f);
|
||||
@ -58,7 +61,7 @@ TEST_CASE("[Graphics] sf::CircleShape")
|
||||
CHECK(circle.getPoint(29) == Approx(sf::Vector2f(11.881320953f, 0.327786446f)));
|
||||
}
|
||||
|
||||
SUBCASE("Radius and point count constructor")
|
||||
SECTION("Radius and point count constructor")
|
||||
{
|
||||
const sf::CircleShape circle(5.f, 8);
|
||||
CHECK(circle.getRadius() == 5.f);
|
||||
@ -73,7 +76,7 @@ TEST_CASE("[Graphics] sf::CircleShape")
|
||||
CHECK(circle.getPoint(7) == Approx(sf::Vector2f(1.464465857f, 1.464466572f)));
|
||||
}
|
||||
|
||||
SUBCASE("Set radius")
|
||||
SECTION("Set radius")
|
||||
{
|
||||
sf::CircleShape circle(1.f, 6);
|
||||
circle.setRadius(10.f);
|
||||
@ -87,7 +90,7 @@ TEST_CASE("[Graphics] sf::CircleShape")
|
||||
CHECK(circle.getPoint(5) == Approx(sf::Vector2f(1.339745522f, 5.000000000f)));
|
||||
}
|
||||
|
||||
SUBCASE("Set point count")
|
||||
SECTION("Set point count")
|
||||
{
|
||||
sf::CircleShape circle(4.f, 10);
|
||||
circle.setPointCount(4);
|
||||
@ -99,7 +102,7 @@ TEST_CASE("[Graphics] sf::CircleShape")
|
||||
CHECK(circle.getPoint(3) == Approx(sf::Vector2f(0.000000000f, 3.999999762f)));
|
||||
}
|
||||
|
||||
SUBCASE("Equilateral triangle")
|
||||
SECTION("Equilateral triangle")
|
||||
{
|
||||
const sf::CircleShape triangle(2.f, 3);
|
||||
CHECK(triangle.getRadius() == 2.f);
|
||||
|
@ -1,112 +1,115 @@
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Color>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Color>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Color>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Color>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Color")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::Color color;
|
||||
CHECK(color.r == 0);
|
||||
CHECK(color.g == 0);
|
||||
CHECK(color.b == 0);
|
||||
CHECK(color.a == 255);
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Color>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Color>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Color>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Color>);
|
||||
}
|
||||
|
||||
SUBCASE("(r, g, b) constructor")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Color color(1, 2, 3);
|
||||
CHECK(color.r == 1);
|
||||
CHECK(color.g == 2);
|
||||
CHECK(color.b == 3);
|
||||
CHECK(color.a == 255);
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
constexpr sf::Color color;
|
||||
STATIC_CHECK(color.r == 0);
|
||||
STATIC_CHECK(color.g == 0);
|
||||
STATIC_CHECK(color.b == 0);
|
||||
STATIC_CHECK(color.a == 255);
|
||||
}
|
||||
|
||||
SUBCASE("(r, g, b, a) constructor")
|
||||
SECTION("(r, g, b) constructor")
|
||||
{
|
||||
const sf::Color color(1, 2, 3, 4);
|
||||
CHECK(color.r == 1);
|
||||
CHECK(color.g == 2);
|
||||
CHECK(color.b == 3);
|
||||
CHECK(color.a == 4);
|
||||
constexpr sf::Color color(1, 2, 3);
|
||||
STATIC_CHECK(color.r == 1);
|
||||
STATIC_CHECK(color.g == 2);
|
||||
STATIC_CHECK(color.b == 3);
|
||||
STATIC_CHECK(color.a == 255);
|
||||
}
|
||||
|
||||
SUBCASE("std::int32_t constructor")
|
||||
SECTION("(r, g, b, a) constructor")
|
||||
{
|
||||
CHECK(sf::Color(0x00000000) == sf::Color(0, 0, 0, 0));
|
||||
CHECK(sf::Color(0x01020304) == sf::Color(1, 2, 3, 4));
|
||||
CHECK(sf::Color(0xFFFFFFFF) == sf::Color(255, 255, 255, 255));
|
||||
constexpr sf::Color color(1, 2, 3, 4);
|
||||
STATIC_CHECK(color.r == 1);
|
||||
STATIC_CHECK(color.g == 2);
|
||||
STATIC_CHECK(color.b == 3);
|
||||
STATIC_CHECK(color.a == 4);
|
||||
}
|
||||
|
||||
SECTION("std::int32_t constructor")
|
||||
{
|
||||
STATIC_CHECK(sf::Color(0x00000000) == sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Color(0x01020304) == sf::Color(1, 2, 3, 4));
|
||||
STATIC_CHECK(sf::Color(0xFFFFFFFF) == sf::Color(255, 255, 255, 255));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("toInteger()")
|
||||
SECTION("toInteger()")
|
||||
{
|
||||
CHECK(sf::Color(0, 0, 0, 0).toInteger() == 0x00000000);
|
||||
CHECK(sf::Color(1, 2, 3, 4).toInteger() == 0x01020304);
|
||||
CHECK(sf::Color(255, 255, 255, 255).toInteger() == 0xFFFFFFFF);
|
||||
STATIC_CHECK(sf::Color(0, 0, 0, 0).toInteger() == 0x00000000);
|
||||
STATIC_CHECK(sf::Color(1, 2, 3, 4).toInteger() == 0x01020304);
|
||||
STATIC_CHECK(sf::Color(255, 255, 255, 255).toInteger() == 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
SUBCASE("Operations")
|
||||
SECTION("Operations")
|
||||
{
|
||||
SUBCASE("operator==")
|
||||
SECTION("operator==")
|
||||
{
|
||||
CHECK(sf::Color() == sf::Color());
|
||||
CHECK(sf::Color(1, 2, 3, 4) == sf::Color(1, 2, 3, 4));
|
||||
STATIC_CHECK(sf::Color() == sf::Color());
|
||||
STATIC_CHECK(sf::Color(1, 2, 3, 4) == sf::Color(1, 2, 3, 4));
|
||||
|
||||
CHECK_FALSE(sf::Color(1, 0, 0, 0) == sf::Color(0, 0, 0, 0));
|
||||
CHECK_FALSE(sf::Color(0, 1, 0, 0) == sf::Color(0, 0, 0, 0));
|
||||
CHECK_FALSE(sf::Color(0, 0, 1, 0) == sf::Color(0, 0, 0, 0));
|
||||
CHECK_FALSE(sf::Color(0, 0, 0, 1) == sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK_FALSE(sf::Color(1, 0, 0, 0) == sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK_FALSE(sf::Color(0, 1, 0, 0) == sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK_FALSE(sf::Color(0, 0, 1, 0) == sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK_FALSE(sf::Color(0, 0, 0, 1) == sf::Color(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
CHECK(sf::Color(1, 0, 0, 0) != sf::Color(0, 0, 0, 0));
|
||||
CHECK(sf::Color(0, 1, 0, 0) != sf::Color(0, 0, 0, 0));
|
||||
CHECK(sf::Color(0, 0, 1, 0) != sf::Color(0, 0, 0, 0));
|
||||
CHECK(sf::Color(0, 0, 0, 1) != sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Color(1, 0, 0, 0) != sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Color(0, 1, 0, 0) != sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Color(0, 0, 1, 0) != sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Color(0, 0, 0, 1) != sf::Color(0, 0, 0, 0));
|
||||
|
||||
CHECK_FALSE(sf::Color() != sf::Color());
|
||||
CHECK_FALSE(sf::Color(1, 2, 3, 4) != sf::Color(1, 2, 3, 4));
|
||||
STATIC_CHECK_FALSE(sf::Color() != sf::Color());
|
||||
STATIC_CHECK_FALSE(sf::Color(1, 2, 3, 4) != sf::Color(1, 2, 3, 4));
|
||||
}
|
||||
|
||||
SUBCASE("operator+")
|
||||
SECTION("operator+")
|
||||
{
|
||||
CHECK(sf::Color(0, 0, 0, 0) + sf::Color(0, 0, 0, 0) == sf::Color(0, 0, 0, 0));
|
||||
CHECK(sf::Color(50, 50, 50, 50) + sf::Color(50, 50, 50, 50) == sf::Color(100, 100, 100, 100));
|
||||
CHECK(sf::Color(100, 100, 100, 100) + sf::Color(100, 100, 100, 100) == sf::Color(200, 200, 200, 200));
|
||||
CHECK(sf::Color(150, 150, 150, 150) + sf::Color(150, 150, 150, 150) == sf::Color(255, 255, 255, 255));
|
||||
CHECK(sf::Color(255, 255, 255, 255) + sf::Color(255, 255, 255, 255) == sf::Color(255, 255, 255, 255));
|
||||
STATIC_CHECK(sf::Color(0, 0, 0, 0) + sf::Color(0, 0, 0, 0) == sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Color(50, 50, 50, 50) + sf::Color(50, 50, 50, 50) == sf::Color(100, 100, 100, 100));
|
||||
STATIC_CHECK(sf::Color(100, 100, 100, 100) + sf::Color(100, 100, 100, 100) == sf::Color(200, 200, 200, 200));
|
||||
STATIC_CHECK(sf::Color(150, 150, 150, 150) + sf::Color(150, 150, 150, 150) == sf::Color(255, 255, 255, 255));
|
||||
STATIC_CHECK(sf::Color(255, 255, 255, 255) + sf::Color(255, 255, 255, 255) == sf::Color(255, 255, 255, 255));
|
||||
}
|
||||
|
||||
SUBCASE("operator-")
|
||||
SECTION("operator-")
|
||||
{
|
||||
const sf::Color c(50, 50, 50, 50);
|
||||
const sf::Color c2(150, 150, 150, 150);
|
||||
CHECK(c2 - c == sf::Color(100, 100, 100, 100));
|
||||
CHECK(c - c2 == sf::Color(0, 0, 0, 0));
|
||||
constexpr sf::Color c(50, 50, 50, 50);
|
||||
constexpr sf::Color c2(150, 150, 150, 150);
|
||||
STATIC_CHECK(c2 - c == sf::Color(100, 100, 100, 100));
|
||||
STATIC_CHECK(c - c2 == sf::Color(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("operator*")
|
||||
SECTION("operator*")
|
||||
{
|
||||
const sf::Color c(255, 255, 255, 255);
|
||||
const sf::Color c2(2, 2, 2, 2);
|
||||
CHECK(c * c2 == sf::Color(2, 2, 2, 2));
|
||||
CHECK(c2 * c == sf::Color(2, 2, 2, 2));
|
||||
constexpr sf::Color c(255, 255, 255, 255);
|
||||
constexpr sf::Color c2(2, 2, 2, 2);
|
||||
STATIC_CHECK(c * c2 == sf::Color(2, 2, 2, 2));
|
||||
STATIC_CHECK(c2 * c == sf::Color(2, 2, 2, 2));
|
||||
}
|
||||
|
||||
SUBCASE("operator+=")
|
||||
SECTION("operator+=")
|
||||
{
|
||||
sf::Color color(42, 42, 42, 42);
|
||||
color += sf::Color(1, 1, 1, 1);
|
||||
@ -115,7 +118,7 @@ TEST_CASE("[Graphics] sf::Color")
|
||||
CHECK(color == sf::Color(255, 255, 255, 255));
|
||||
}
|
||||
|
||||
SUBCASE("operator-=")
|
||||
SECTION("operator-=")
|
||||
{
|
||||
sf::Color color(248, 248, 248, 248);
|
||||
color -= sf::Color(1, 1, 1, 1);
|
||||
@ -124,7 +127,7 @@ TEST_CASE("[Graphics] sf::Color")
|
||||
CHECK(color == sf::Color(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("operator*=")
|
||||
SECTION("operator*=")
|
||||
{
|
||||
sf::Color color(50, 50, 50, 50);
|
||||
color *= sf::Color(20, 20, 20, 20);
|
||||
@ -134,36 +137,23 @@ TEST_CASE("[Graphics] sf::Color")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Constants")
|
||||
SECTION("Constants")
|
||||
{
|
||||
CHECK(sf::Color::Black == sf::Color(0, 0, 0));
|
||||
CHECK(sf::Color::White == sf::Color(255, 255, 255));
|
||||
CHECK(sf::Color::Red == sf::Color(255, 0, 0));
|
||||
CHECK(sf::Color::Green == sf::Color(0, 255, 0));
|
||||
CHECK(sf::Color::Blue == sf::Color(0, 0, 255));
|
||||
CHECK(sf::Color::Yellow == sf::Color(255, 255, 0));
|
||||
CHECK(sf::Color::Magenta == sf::Color(255, 0, 255));
|
||||
CHECK(sf::Color::Cyan == sf::Color(0, 255, 255));
|
||||
CHECK(sf::Color::Transparent == sf::Color(0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Color::Black == sf::Color(0, 0, 0));
|
||||
STATIC_CHECK(sf::Color::White == sf::Color(255, 255, 255));
|
||||
STATIC_CHECK(sf::Color::Red == sf::Color(255, 0, 0));
|
||||
STATIC_CHECK(sf::Color::Green == sf::Color(0, 255, 0));
|
||||
STATIC_CHECK(sf::Color::Blue == sf::Color(0, 0, 255));
|
||||
STATIC_CHECK(sf::Color::Yellow == sf::Color(255, 255, 0));
|
||||
STATIC_CHECK(sf::Color::Magenta == sf::Color(255, 0, 255));
|
||||
STATIC_CHECK(sf::Color::Cyan == sf::Color(0, 255, 255));
|
||||
STATIC_CHECK(sf::Color::Transparent == sf::Color(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("Constexpr support")
|
||||
SECTION("Reinterpret as std::uint8_t*")
|
||||
{
|
||||
constexpr sf::Color color(1, 2, 3, 4);
|
||||
static_assert(color.r == 1);
|
||||
static_assert(color.g == 2);
|
||||
static_assert(color.b == 3);
|
||||
static_assert(color.a == 4);
|
||||
|
||||
static_assert(color + color == sf::Color(2, 4, 6, 8));
|
||||
|
||||
static_assert(sf::Color::Black == sf::Color(0, 0, 0, 255));
|
||||
}
|
||||
|
||||
SUBCASE("Reinterpret as std::uint8_t*")
|
||||
{
|
||||
static_assert(sizeof(sf::Color) == 4);
|
||||
static_assert(alignof(sf::Color) == 1);
|
||||
STATIC_CHECK(sizeof(sf::Color) == 4);
|
||||
STATIC_CHECK(alignof(sf::Color) == 1);
|
||||
|
||||
const std::vector<sf::Color> pixels = {{10, 11, 12, 13}, {14, 15, 16, 17}, {18, 19, 20, 21}};
|
||||
const auto* begin = reinterpret_cast<const std::uint8_t*>(pixels.data());
|
||||
|
@ -1,24 +1,27 @@
|
||||
#include <SFML/Graphics/ConvexShape.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::ConvexShape>);
|
||||
static_assert(std::is_copy_assignable_v<sf::ConvexShape>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::ConvexShape>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::ConvexShape>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::ConvexShape")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::ConvexShape>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::ConvexShape>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::ConvexShape>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::ConvexShape>);
|
||||
}
|
||||
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::ConvexShape convex;
|
||||
CHECK(convex.getPointCount() == 0);
|
||||
}
|
||||
|
||||
SUBCASE("Point count constructor")
|
||||
SECTION("Point count constructor")
|
||||
{
|
||||
const sf::ConvexShape convex(15);
|
||||
CHECK(convex.getPointCount() == 15);
|
||||
@ -26,7 +29,7 @@ TEST_CASE("[Graphics] sf::ConvexShape")
|
||||
CHECK(convex.getPoint(i) == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("Set point count")
|
||||
SECTION("Set point count")
|
||||
{
|
||||
sf::ConvexShape convex;
|
||||
convex.setPointCount(42);
|
||||
@ -35,7 +38,7 @@ TEST_CASE("[Graphics] sf::ConvexShape")
|
||||
CHECK(convex.getPoint(i) == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("Set point")
|
||||
SECTION("Set point")
|
||||
{
|
||||
sf::ConvexShape convex;
|
||||
convex.setPointCount(1);
|
||||
|
@ -1,19 +1,11 @@
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/RenderTexture.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_constructible_v<sf::Drawable>);
|
||||
static_assert(!std::is_copy_constructible_v<sf::Drawable>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Drawable>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::Drawable>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Drawable>);
|
||||
static_assert(std::is_abstract_v<sf::Drawable>);
|
||||
static_assert(std::has_virtual_destructor_v<sf::Drawable>);
|
||||
|
||||
class DrawableTest : public sf::Drawable
|
||||
{
|
||||
public:
|
||||
@ -31,15 +23,26 @@ private:
|
||||
mutable int m_callCount{};
|
||||
};
|
||||
|
||||
TEST_CASE("[Graphics] sf::Drawable" * doctest::skip(skipDisplayTests))
|
||||
TEST_CASE("[Graphics] sf::Drawable", runDisplayTests())
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_constructible_v<sf::Drawable>);
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::Drawable>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Drawable>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::Drawable>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Drawable>);
|
||||
STATIC_CHECK(std::is_abstract_v<sf::Drawable>);
|
||||
STATIC_CHECK(std::has_virtual_destructor_v<sf::Drawable>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const DrawableTest drawableTest;
|
||||
CHECK(drawableTest.callCount() == 0);
|
||||
}
|
||||
|
||||
SUBCASE("draw()")
|
||||
SECTION("draw()")
|
||||
{
|
||||
const DrawableTest drawableTest;
|
||||
sf::RenderTexture renderTexture;
|
||||
|
@ -1,18 +1,21 @@
|
||||
#include <SFML/Graphics/Glyph.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Glyph>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Glyph>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Glyph>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Glyph>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Glyph")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Glyph>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Glyph>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Glyph>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Glyph>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Glyph glyph;
|
||||
CHECK(glyph.advance == 0.f);
|
||||
|
@ -1,28 +1,31 @@
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Image>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Image>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Image>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Image>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Image")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Image>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Image>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Image>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Image>);
|
||||
}
|
||||
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::Image image;
|
||||
CHECK(image.getSize() == sf::Vector2u());
|
||||
CHECK(image.getPixelsPtr() == nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Create")
|
||||
SECTION("Create")
|
||||
{
|
||||
SUBCASE("create(Vector2)")
|
||||
SECTION("create(Vector2)")
|
||||
{
|
||||
sf::Image image;
|
||||
image.create(sf::Vector2u(10, 10));
|
||||
@ -38,7 +41,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("create(Vector2, Color)")
|
||||
SECTION("create(Vector2, Color)")
|
||||
{
|
||||
sf::Image image;
|
||||
image.create(sf::Vector2u(10, 10), sf::Color::Red);
|
||||
@ -55,7 +58,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("create(Vector2, std::uint8_t*)")
|
||||
SECTION("create(Vector2, std::uint8_t*)")
|
||||
{
|
||||
// 10 x 10, with 4 colour channels array
|
||||
std::array<std::uint8_t, 400> pixels;
|
||||
@ -83,7 +86,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Set/get pixel")
|
||||
SECTION("Set/get pixel")
|
||||
{
|
||||
sf::Image image;
|
||||
|
||||
@ -94,9 +97,9 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
CHECK(image.getPixel(sf::Vector2u(2, 2)) == sf::Color::Blue);
|
||||
}
|
||||
|
||||
SUBCASE("Copy from Image")
|
||||
SECTION("Copy from Image")
|
||||
{
|
||||
SUBCASE("Copy (Image, Vector2u)")
|
||||
SECTION("Copy (Image, Vector2u)")
|
||||
{
|
||||
sf::Image image1;
|
||||
image1.create(sf::Vector2u(10, 10), sf::Color::Blue);
|
||||
@ -114,7 +117,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Copy (Image, Vector2u, IntRect)")
|
||||
SECTION("Copy (Image, Vector2u, IntRect)")
|
||||
{
|
||||
sf::Image image1;
|
||||
image1.create(sf::Vector2u(5, 5), sf::Color::Blue);
|
||||
@ -135,7 +138,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Copy (Image, Vector2u, IntRect, bool)")
|
||||
SECTION("Copy (Image, Vector2u, IntRect, bool)")
|
||||
{
|
||||
const sf::Color dest(255, 0, 0, 255);
|
||||
const sf::Color source(5, 255, 78, 232);
|
||||
@ -166,7 +169,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Copy (Empty image)")
|
||||
SECTION("Copy (Empty image)")
|
||||
{
|
||||
const sf::Image image1;
|
||||
sf::Image image2;
|
||||
@ -183,7 +186,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Copy (Out of bounds sourceRect)")
|
||||
SECTION("Copy (Out of bounds sourceRect)")
|
||||
{
|
||||
sf::Image image1;
|
||||
image1.create(sf::Vector2u(5, 5), sf::Color::Blue);
|
||||
@ -203,9 +206,9 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Create mask from color")
|
||||
SECTION("Create mask from color")
|
||||
{
|
||||
SUBCASE("createMaskFromColor(Color)")
|
||||
SECTION("createMaskFromColor(Color)")
|
||||
{
|
||||
sf::Image image;
|
||||
image.create(sf::Vector2u(10, 10), sf::Color::Blue);
|
||||
@ -220,7 +223,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("createMaskFromColor(Color, std::uint8_t)")
|
||||
SECTION("createMaskFromColor(Color, std::uint8_t)")
|
||||
{
|
||||
sf::Image image;
|
||||
image.create(sf::Vector2u(10, 10), sf::Color::Blue);
|
||||
@ -236,7 +239,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Flip horizontally")
|
||||
SECTION("Flip horizontally")
|
||||
{
|
||||
sf::Image image;
|
||||
image.create(sf::Vector2u(10, 10), sf::Color::Red);
|
||||
@ -246,7 +249,7 @@ TEST_CASE("[Graphics] sf::Image")
|
||||
CHECK(image.getPixel(sf::Vector2u(9, 0)) == sf::Color::Green);
|
||||
}
|
||||
|
||||
SUBCASE("Flip vertically")
|
||||
SECTION("Flip vertically")
|
||||
{
|
||||
sf::Image image;
|
||||
image.create(sf::Vector2u(10, 10), sf::Color::Red);
|
||||
|
@ -2,126 +2,129 @@
|
||||
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::IntRect>);
|
||||
static_assert(std::is_copy_assignable_v<sf::IntRect>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::IntRect>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::IntRect>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Rect")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::IntRect>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::IntRect>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::IntRect>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::IntRect>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::IntRect rectangle;
|
||||
CHECK(rectangle.left == 0);
|
||||
CHECK(rectangle.top == 0);
|
||||
CHECK(rectangle.width == 0);
|
||||
CHECK(rectangle.height == 0);
|
||||
}
|
||||
|
||||
SUBCASE("(left, top, width, height) constructor")
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::IntRect rectangle({1, 2}, {3, 4});
|
||||
CHECK(rectangle.left == 1);
|
||||
CHECK(rectangle.top == 2);
|
||||
CHECK(rectangle.width == 3);
|
||||
CHECK(rectangle.height == 4);
|
||||
constexpr sf::IntRect rectangle;
|
||||
STATIC_CHECK(rectangle.left == 0);
|
||||
STATIC_CHECK(rectangle.top == 0);
|
||||
STATIC_CHECK(rectangle.width == 0);
|
||||
STATIC_CHECK(rectangle.height == 0);
|
||||
}
|
||||
|
||||
SUBCASE("(Vector2, Vector2) constructor")
|
||||
SECTION("(left, top, width, height) constructor")
|
||||
{
|
||||
const sf::Vector2i position(1, 2);
|
||||
const sf::Vector2i dimension(3, 4);
|
||||
const sf::IntRect rectangle(position, dimension);
|
||||
|
||||
CHECK(rectangle.left == 1);
|
||||
CHECK(rectangle.top == 2);
|
||||
CHECK(rectangle.width == 3);
|
||||
CHECK(rectangle.height == 4);
|
||||
constexpr sf::IntRect rectangle({1, 2}, {3, 4});
|
||||
STATIC_CHECK(rectangle.left == 1);
|
||||
STATIC_CHECK(rectangle.top == 2);
|
||||
STATIC_CHECK(rectangle.width == 3);
|
||||
STATIC_CHECK(rectangle.height == 4);
|
||||
}
|
||||
|
||||
SUBCASE("Conversion constructor")
|
||||
SECTION("(Vector2, Vector2) constructor")
|
||||
{
|
||||
const sf::FloatRect sourceRectangle({1.0f, 2.0f}, {3.0f, 4.0f});
|
||||
const sf::IntRect rectangle(sourceRectangle);
|
||||
constexpr sf::Vector2i position(1, 2);
|
||||
constexpr sf::Vector2i dimension(3, 4);
|
||||
constexpr sf::IntRect rectangle(position, dimension);
|
||||
|
||||
CHECK(rectangle.left == static_cast<int>(sourceRectangle.left));
|
||||
CHECK(rectangle.top == static_cast<int>(sourceRectangle.top));
|
||||
CHECK(rectangle.width == static_cast<int>(sourceRectangle.width));
|
||||
CHECK(rectangle.height == static_cast<int>(sourceRectangle.height));
|
||||
}
|
||||
STATIC_CHECK(rectangle.left == 1);
|
||||
STATIC_CHECK(rectangle.top == 2);
|
||||
STATIC_CHECK(rectangle.width == 3);
|
||||
STATIC_CHECK(rectangle.height == 4);
|
||||
}
|
||||
|
||||
SUBCASE("contains(Vector2)")
|
||||
SECTION("Conversion constructor")
|
||||
{
|
||||
const sf::IntRect rectangle({0, 0}, {10, 10});
|
||||
constexpr sf::FloatRect sourceRectangle({1.0f, 2.0f}, {3.0f, 4.0f});
|
||||
constexpr sf::IntRect rectangle(sourceRectangle);
|
||||
|
||||
CHECK(rectangle.contains(sf::Vector2i(0, 0)) == true);
|
||||
CHECK(rectangle.contains(sf::Vector2i(9, 0)) == true);
|
||||
CHECK(rectangle.contains(sf::Vector2i(0, 9)) == true);
|
||||
CHECK(rectangle.contains(sf::Vector2i(9, 9)) == true);
|
||||
CHECK(rectangle.contains(sf::Vector2i(9, 10)) == false);
|
||||
CHECK(rectangle.contains(sf::Vector2i(10, 9)) == false);
|
||||
CHECK(rectangle.contains(sf::Vector2i(10, 10)) == false);
|
||||
CHECK(rectangle.contains(sf::Vector2i(15, 15)) == false);
|
||||
STATIC_CHECK(rectangle.left == static_cast<int>(sourceRectangle.left));
|
||||
STATIC_CHECK(rectangle.top == static_cast<int>(sourceRectangle.top));
|
||||
STATIC_CHECK(rectangle.width == static_cast<int>(sourceRectangle.width));
|
||||
STATIC_CHECK(rectangle.height == static_cast<int>(sourceRectangle.height));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("findIntersection()")
|
||||
SECTION("contains(Vector2)")
|
||||
{
|
||||
const sf::IntRect rectangle({0, 0}, {10, 10});
|
||||
const sf::IntRect intersectingRectangle({5, 5}, {10, 10});
|
||||
constexpr sf::IntRect rectangle({0, 0}, {10, 10});
|
||||
|
||||
const auto intersectionResult = rectangle.findIntersection(intersectingRectangle);
|
||||
REQUIRE(intersectionResult.has_value());
|
||||
CHECK(intersectionResult->top == 5);
|
||||
CHECK(intersectionResult->left == 5);
|
||||
CHECK(intersectionResult->width == 5);
|
||||
CHECK(intersectionResult->height == 5);
|
||||
|
||||
const sf::IntRect nonIntersectingRectangle({-5, -5}, {5, 5});
|
||||
CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value());
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(0, 0)) == true);
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(9, 0)) == true);
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(0, 9)) == true);
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(9, 9)) == true);
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(9, 10)) == false);
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(10, 9)) == false);
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(10, 10)) == false);
|
||||
STATIC_CHECK(rectangle.contains(sf::Vector2i(15, 15)) == false);
|
||||
}
|
||||
|
||||
SUBCASE("getPosition()")
|
||||
SECTION("findIntersection()")
|
||||
{
|
||||
CHECK(sf::IntRect({}, {}).getPosition() == sf::Vector2i());
|
||||
CHECK(sf::IntRect({1, 2}, {3, 4}).getPosition() == sf::Vector2i(1, 2));
|
||||
constexpr sf::IntRect rectangle({0, 0}, {10, 10});
|
||||
constexpr sf::IntRect intersectingRectangle({5, 5}, {10, 10});
|
||||
|
||||
constexpr auto intersectionResult = rectangle.findIntersection(intersectingRectangle);
|
||||
STATIC_REQUIRE(intersectionResult.has_value());
|
||||
STATIC_CHECK(intersectionResult->top == 5);
|
||||
STATIC_CHECK(intersectionResult->left == 5);
|
||||
STATIC_CHECK(intersectionResult->width == 5);
|
||||
STATIC_CHECK(intersectionResult->height == 5);
|
||||
|
||||
constexpr sf::IntRect nonIntersectingRectangle({-5, -5}, {5, 5});
|
||||
STATIC_CHECK_FALSE(rectangle.findIntersection(nonIntersectingRectangle).has_value());
|
||||
}
|
||||
|
||||
SUBCASE("getSize()")
|
||||
SECTION("getPosition()")
|
||||
{
|
||||
CHECK(sf::IntRect({}, {}).getSize() == sf::Vector2i());
|
||||
CHECK(sf::IntRect({1, 2}, {3, 4}).getSize() == sf::Vector2i(3, 4));
|
||||
STATIC_CHECK(sf::IntRect({}, {}).getPosition() == sf::Vector2i());
|
||||
STATIC_CHECK(sf::IntRect({1, 2}, {3, 4}).getPosition() == sf::Vector2i(1, 2));
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("getSize()")
|
||||
{
|
||||
SUBCASE("operator==")
|
||||
STATIC_CHECK(sf::IntRect({}, {}).getSize() == sf::Vector2i());
|
||||
STATIC_CHECK(sf::IntRect({1, 2}, {3, 4}).getSize() == sf::Vector2i(3, 4));
|
||||
}
|
||||
|
||||
SECTION("Operators")
|
||||
{
|
||||
CHECK(sf::IntRect() == sf::IntRect());
|
||||
CHECK(sf::IntRect({1, 3}, {2, 5}) == sf::IntRect({1, 3}, {2, 5}));
|
||||
|
||||
CHECK_FALSE(sf::IntRect({1, 0}, {0, 0}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
CHECK_FALSE(sf::IntRect({0, 1}, {0, 0}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
CHECK_FALSE(sf::IntRect({0, 0}, {1, 0}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
CHECK_FALSE(sf::IntRect({0, 0}, {0, 1}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator==")
|
||||
{
|
||||
CHECK(sf::IntRect({1, 0}, {0, 0}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
CHECK(sf::IntRect({0, 1}, {0, 0}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
CHECK(sf::IntRect({0, 0}, {1, 0}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
CHECK(sf::IntRect({0, 0}, {0, 1}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
STATIC_CHECK(sf::IntRect() == sf::IntRect());
|
||||
STATIC_CHECK(sf::IntRect({1, 3}, {2, 5}) == sf::IntRect({1, 3}, {2, 5}));
|
||||
|
||||
CHECK_FALSE(sf::IntRect() != sf::IntRect());
|
||||
CHECK_FALSE(sf::IntRect({1, 3}, {2, 5}) != sf::IntRect({1, 3}, {2, 5}));
|
||||
STATIC_CHECK_FALSE(sf::IntRect({1, 0}, {0, 0}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
STATIC_CHECK_FALSE(sf::IntRect({0, 1}, {0, 0}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
STATIC_CHECK_FALSE(sf::IntRect({0, 0}, {1, 0}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
STATIC_CHECK_FALSE(sf::IntRect({0, 0}, {0, 1}) == sf::IntRect({0, 0}, {0, 0}));
|
||||
}
|
||||
|
||||
SECTION("operator!=")
|
||||
{
|
||||
STATIC_CHECK(sf::IntRect({1, 0}, {0, 0}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
STATIC_CHECK(sf::IntRect({0, 1}, {0, 0}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
STATIC_CHECK(sf::IntRect({0, 0}, {1, 0}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
STATIC_CHECK(sf::IntRect({0, 0}, {0, 1}) != sf::IntRect({0, 0}, {0, 0}));
|
||||
|
||||
STATIC_CHECK_FALSE(sf::IntRect() != sf::IntRect());
|
||||
STATIC_CHECK_FALSE(sf::IntRect({1, 3}, {2, 5}) != sf::IntRect({1, 3}, {2, 5}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::RectangleShape>);
|
||||
static_assert(std::is_copy_assignable_v<sf::RectangleShape>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::RectangleShape>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::RectangleShape>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::RectangleShape")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::RectangleShape>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::RectangleShape>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::RectangleShape>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RectangleShape>);
|
||||
}
|
||||
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::RectangleShape rectangle;
|
||||
CHECK(rectangle.getSize() == sf::Vector2f(0, 0));
|
||||
@ -23,7 +26,7 @@ TEST_CASE("[Graphics] sf::RectangleShape")
|
||||
CHECK(rectangle.getPoint(3) == sf::Vector2f(0, 0));
|
||||
}
|
||||
|
||||
SUBCASE("Size constructor")
|
||||
SECTION("Size constructor")
|
||||
{
|
||||
const sf::RectangleShape rectangle({9, 8});
|
||||
CHECK(rectangle.getSize() == sf::Vector2f(9, 8));
|
||||
@ -34,7 +37,7 @@ TEST_CASE("[Graphics] sf::RectangleShape")
|
||||
CHECK(rectangle.getPoint(3) == sf::Vector2f(0, 8));
|
||||
}
|
||||
|
||||
SUBCASE("Set size")
|
||||
SECTION("Set size")
|
||||
{
|
||||
sf::RectangleShape rectangle({7, 6});
|
||||
rectangle.setSize({5, 4});
|
||||
|
@ -1,20 +1,23 @@
|
||||
#include <SFML/Graphics/RenderStates.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::RenderStates>);
|
||||
static_assert(std::is_copy_assignable_v<sf::RenderStates>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::RenderStates>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::RenderStates>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::RenderStates")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::RenderStates>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::RenderStates>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::RenderStates>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::RenderStates>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::RenderStates renderStates;
|
||||
CHECK(renderStates.blendMode == sf::BlendMode());
|
||||
@ -23,7 +26,7 @@ TEST_CASE("[Graphics] sf::RenderStates")
|
||||
CHECK(renderStates.shader == nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("BlendMode constructor")
|
||||
SECTION("BlendMode constructor")
|
||||
{
|
||||
const sf::BlendMode blendMode(sf::BlendMode::Zero,
|
||||
sf::BlendMode::SrcColor,
|
||||
@ -38,7 +41,7 @@ TEST_CASE("[Graphics] sf::RenderStates")
|
||||
CHECK(renderStates.shader == nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Transform constructor")
|
||||
SECTION("Transform constructor")
|
||||
{
|
||||
const sf::Transform transform(10, 9, 8, 7, 6, 5, 4, 3, 2);
|
||||
const sf::RenderStates renderStates(transform);
|
||||
@ -48,7 +51,7 @@ TEST_CASE("[Graphics] sf::RenderStates")
|
||||
CHECK(renderStates.shader == nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Texture constructor")
|
||||
SECTION("Texture constructor")
|
||||
{
|
||||
const sf::Texture* texture = nullptr;
|
||||
const sf::RenderStates renderStates(texture);
|
||||
@ -58,7 +61,7 @@ TEST_CASE("[Graphics] sf::RenderStates")
|
||||
CHECK(renderStates.shader == nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Shader constructor")
|
||||
SECTION("Shader constructor")
|
||||
{
|
||||
const sf::Shader* shader = nullptr;
|
||||
const sf::RenderStates renderStates(shader);
|
||||
@ -68,7 +71,7 @@ TEST_CASE("[Graphics] sf::RenderStates")
|
||||
CHECK(renderStates.shader == shader);
|
||||
}
|
||||
|
||||
SUBCASE("Verbose constructor")
|
||||
SECTION("Verbose constructor")
|
||||
{
|
||||
const sf::BlendMode blendMode(sf::BlendMode::One,
|
||||
sf::BlendMode::SrcColor,
|
||||
@ -85,7 +88,7 @@ TEST_CASE("[Graphics] sf::RenderStates")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Default constant")
|
||||
SECTION("Default constant")
|
||||
{
|
||||
CHECK(sf::RenderStates::Default.blendMode == sf::BlendMode());
|
||||
CHECK(sf::RenderStates::Default.transform == sf::Transform());
|
||||
|
@ -8,19 +8,22 @@
|
||||
|
||||
#include <SFML/System/String.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_copy_constructible_v<sf::RenderWindow>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::RenderWindow>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::RenderWindow>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::RenderWindow>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::RenderWindow" * doctest::skip(skipDisplayTests))
|
||||
TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests())
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::RenderWindow>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::RenderWindow>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::RenderWindow>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::RenderWindow>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::RenderWindow window(sf::VideoMode(sf::Vector2u(256, 256), 24),
|
||||
"Window Title",
|
||||
@ -29,7 +32,7 @@ TEST_CASE("[Graphics] sf::RenderWindow" * doctest::skip(skipDisplayTests))
|
||||
CHECK(window.getSize() == sf::Vector2u(256, 256));
|
||||
}
|
||||
|
||||
SUBCASE("Clear")
|
||||
SECTION("Clear")
|
||||
{
|
||||
sf::RenderWindow window(sf::VideoMode(sf::Vector2u(256, 256), 24),
|
||||
"Window Title",
|
||||
|
@ -1,14 +1,9 @@
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_copy_constructible_v<sf::Shader>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::Shader>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Shader>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Shader>);
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto vertexSource = R"(
|
||||
@ -117,17 +112,37 @@ constexpr bool skipShaderDummyTest = true;
|
||||
constexpr bool skipShaderFullTest = true;
|
||||
#endif
|
||||
|
||||
std::string skipShaderDummyTests()
|
||||
{
|
||||
if constexpr (skipShaderDummyTest)
|
||||
// https://github.com/catchorg/Catch2/blob/devel/docs/test-cases-and-sections.md#special-tags
|
||||
// This tag tells Catch2 to not run a given TEST_CASE
|
||||
return "[.shaderDummy]";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string skipShaderFullTests()
|
||||
{
|
||||
if constexpr (skipShaderFullTest)
|
||||
// https://github.com/catchorg/Catch2/blob/devel/docs/test-cases-and-sections.md#special-tags
|
||||
// This tag tells Catch2 to not run a given TEST_CASE
|
||||
return "[.shaderFull]";
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("[Graphics] sf::Shader (Dummy Implementation)" * doctest::skip(skipShaderDummyTest))
|
||||
TEST_CASE("[Graphics] sf::Shader (Dummy Implementation)", skipShaderDummyTests())
|
||||
{
|
||||
SUBCASE("Available")
|
||||
SECTION("Available")
|
||||
{
|
||||
CHECK_FALSE(sf::Shader::isAvailable());
|
||||
CHECK_FALSE(sf::Shader::isGeometryAvailable());
|
||||
}
|
||||
|
||||
SUBCASE("Load")
|
||||
SECTION("Load")
|
||||
{
|
||||
sf::Shader shader;
|
||||
CHECK_FALSE(shader.loadFromMemory(vertexSource, sf::Shader::Type::Vertex));
|
||||
@ -138,12 +153,20 @@ TEST_CASE("[Graphics] sf::Shader (Dummy Implementation)" * doctest::skip(skipSha
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Graphics] sf::Shader" * doctest::skip(skipShaderFullTest))
|
||||
TEST_CASE("[Graphics] sf::Shader", skipShaderFullTests())
|
||||
{
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::Shader>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::Shader>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Shader>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Shader>);
|
||||
}
|
||||
|
||||
if (!sf::Shader::isAvailable())
|
||||
return;
|
||||
|
||||
SUBCASE("Load")
|
||||
SECTION("Load")
|
||||
{
|
||||
sf::Shader shader;
|
||||
CHECK(shader.loadFromMemory(vertexSource, sf::Shader::Type::Vertex));
|
||||
|
@ -1,17 +1,10 @@
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_constructible_v<sf::Shape>);
|
||||
static_assert(!std::is_copy_constructible_v<sf::Shape>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Shape>);
|
||||
static_assert(!std::is_move_constructible_v<sf::Shape>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Shape>);
|
||||
static_assert(std::has_virtual_destructor_v<sf::Shape>);
|
||||
|
||||
class TriangleShape : public sf::Shape
|
||||
{
|
||||
public:
|
||||
@ -45,7 +38,17 @@ private:
|
||||
|
||||
TEST_CASE("[Graphics] sf::Shape")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_constructible_v<sf::Shape>);
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::Shape>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Shape>);
|
||||
STATIC_CHECK(!std::is_move_constructible_v<sf::Shape>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Shape>);
|
||||
STATIC_CHECK(std::has_virtual_destructor_v<sf::Shape>);
|
||||
}
|
||||
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const TriangleShape triangleShape({0, 0});
|
||||
CHECK(triangleShape.getTexture() == nullptr);
|
||||
@ -57,35 +60,35 @@ TEST_CASE("[Graphics] sf::Shape")
|
||||
CHECK(triangleShape.getGlobalBounds() == sf::FloatRect());
|
||||
}
|
||||
|
||||
SUBCASE("Set/get texture rect")
|
||||
SECTION("Set/get texture rect")
|
||||
{
|
||||
TriangleShape triangleShape({});
|
||||
triangleShape.setTextureRect({{4, 5}, {6, 7}});
|
||||
CHECK(triangleShape.getTextureRect() == sf::IntRect({4, 5}, {6, 7}));
|
||||
}
|
||||
|
||||
SUBCASE("Set/get fill color")
|
||||
SECTION("Set/get fill color")
|
||||
{
|
||||
TriangleShape triangleShape({});
|
||||
triangleShape.setFillColor(sf::Color::Cyan);
|
||||
CHECK(triangleShape.getFillColor() == sf::Color::Cyan);
|
||||
}
|
||||
|
||||
SUBCASE("Set/get outline color")
|
||||
SECTION("Set/get outline color")
|
||||
{
|
||||
TriangleShape triangleShape({});
|
||||
triangleShape.setOutlineColor(sf::Color::Magenta);
|
||||
CHECK(triangleShape.getOutlineColor() == sf::Color::Magenta);
|
||||
}
|
||||
|
||||
SUBCASE("Set/get outline thickness")
|
||||
SECTION("Set/get outline thickness")
|
||||
{
|
||||
TriangleShape triangleShape({});
|
||||
triangleShape.setOutlineThickness(3.14f);
|
||||
CHECK(triangleShape.getOutlineThickness() == 3.14f);
|
||||
}
|
||||
|
||||
SUBCASE("Virtual functions: getPoint, getPointCount")
|
||||
SECTION("Virtual functions: getPoint, getPointCount")
|
||||
{
|
||||
const TriangleShape triangleShape({2, 2});
|
||||
CHECK(triangleShape.getPointCount() == 3);
|
||||
@ -94,7 +97,7 @@ TEST_CASE("[Graphics] sf::Shape")
|
||||
CHECK(triangleShape.getPoint(2) == sf::Vector2f(2, 2));
|
||||
}
|
||||
|
||||
SUBCASE("Get bounds")
|
||||
SECTION("Get bounds")
|
||||
{
|
||||
TriangleShape triangleShape({2, 3});
|
||||
CHECK(triangleShape.getLocalBounds() == sf::FloatRect({0, 0}, {2, 3}));
|
||||
|
@ -3,20 +3,25 @@
|
||||
// Other 1st party headers
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Texture>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Texture>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Texture>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Texture>);
|
||||
static_assert(std::is_nothrow_swappable_v<sf::Texture>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
TEST_CASE("[Graphics] sf::Texture", runDisplayTests())
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Texture>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Texture>);
|
||||
STATIC_CHECK(std::is_move_constructible_v<sf::Texture>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Texture>);
|
||||
STATIC_CHECK(std::is_move_assignable_v<sf::Texture>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Texture>);
|
||||
STATIC_CHECK(std::is_nothrow_swappable_v<sf::Texture>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Texture texture;
|
||||
CHECK(texture.getSize() == sf::Vector2u());
|
||||
@ -26,32 +31,32 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(texture.getNativeHandle() == 0);
|
||||
}
|
||||
|
||||
SUBCASE("create()")
|
||||
SECTION("create()")
|
||||
{
|
||||
sf::Texture texture;
|
||||
|
||||
SUBCASE("At least one zero dimension")
|
||||
SECTION("At least one zero dimension")
|
||||
{
|
||||
CHECK(!texture.create({}));
|
||||
CHECK(!texture.create({0, 1}));
|
||||
CHECK(!texture.create({1, 0}));
|
||||
}
|
||||
|
||||
SUBCASE("Valid size")
|
||||
SECTION("Valid size")
|
||||
{
|
||||
CHECK(texture.create({100, 100}));
|
||||
CHECK(texture.getSize() == sf::Vector2u(100, 100));
|
||||
CHECK(texture.getNativeHandle() != 0);
|
||||
}
|
||||
|
||||
SUBCASE("Too large")
|
||||
SECTION("Too large")
|
||||
{
|
||||
CHECK(!texture.create({100'000, 100'000}));
|
||||
CHECK(!texture.create({1'000'000, 1'000'000}));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Copy semantics")
|
||||
SECTION("Copy semantics")
|
||||
{
|
||||
constexpr std::uint8_t red[] = {0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF};
|
||||
|
||||
@ -59,14 +64,14 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
REQUIRE(texture.create(sf::Vector2u(1, 2)));
|
||||
texture.update(red);
|
||||
|
||||
SUBCASE("Construction")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Texture textureCopy(texture); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
REQUIRE(textureCopy.getSize() == sf::Vector2u(1, 2));
|
||||
CHECK(textureCopy.copyToImage().getPixel(sf::Vector2u(0, 1)) == sf::Color::Red);
|
||||
}
|
||||
|
||||
SUBCASE("Assignment")
|
||||
SECTION("Assignment")
|
||||
{
|
||||
sf::Texture textureCopy;
|
||||
textureCopy = texture;
|
||||
@ -75,21 +80,21 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("update()")
|
||||
SECTION("update()")
|
||||
{
|
||||
constexpr std::uint8_t yellow[] = {0xFF, 0xFF, 0x00, 0xFF};
|
||||
constexpr std::uint8_t cyan[] = {0x00, 0xFF, 0xFF, 0xFF};
|
||||
|
||||
sf::Texture texture;
|
||||
|
||||
SUBCASE("Pixels")
|
||||
SECTION("Pixels")
|
||||
{
|
||||
REQUIRE(texture.create(sf::Vector2u(1, 1)));
|
||||
texture.update(yellow);
|
||||
CHECK(texture.copyToImage().getPixel(sf::Vector2u(0, 0)) == sf::Color::Yellow);
|
||||
}
|
||||
|
||||
SUBCASE("Pixels, size and destination")
|
||||
SECTION("Pixels, size and destination")
|
||||
{
|
||||
REQUIRE(texture.create(sf::Vector2u(2, 1)));
|
||||
texture.update(yellow, sf::Vector2u(1, 1), sf::Vector2u(0, 0));
|
||||
@ -98,7 +103,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(texture.copyToImage().getPixel(sf::Vector2u(1, 0)) == sf::Color::Cyan);
|
||||
}
|
||||
|
||||
SUBCASE("Another texture")
|
||||
SECTION("Another texture")
|
||||
{
|
||||
sf::Texture otherTexture;
|
||||
REQUIRE(otherTexture.create(sf::Vector2u(1, 1)));
|
||||
@ -108,7 +113,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(texture.copyToImage().getPixel(sf::Vector2u(0, 0)) == sf::Color::Cyan);
|
||||
}
|
||||
|
||||
SUBCASE("Another texture and destination")
|
||||
SECTION("Another texture and destination")
|
||||
{
|
||||
REQUIRE(texture.create(sf::Vector2u(2, 1)));
|
||||
sf::Texture otherTexture1;
|
||||
@ -123,7 +128,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(texture.copyToImage().getPixel(sf::Vector2u(1, 0)) == sf::Color::Yellow);
|
||||
}
|
||||
|
||||
SUBCASE("Image")
|
||||
SECTION("Image")
|
||||
{
|
||||
REQUIRE(texture.create(sf::Vector2u(16, 32)));
|
||||
sf::Image image;
|
||||
@ -132,7 +137,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(texture.copyToImage().getPixel(sf::Vector2u(7, 15)) == sf::Color::Red);
|
||||
}
|
||||
|
||||
SUBCASE("Image and destination")
|
||||
SECTION("Image and destination")
|
||||
{
|
||||
REQUIRE(texture.create(sf::Vector2u(16, 32)));
|
||||
sf::Image image1;
|
||||
@ -147,7 +152,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Set/get smooth")
|
||||
SECTION("Set/get smooth")
|
||||
{
|
||||
sf::Texture texture;
|
||||
CHECK(!texture.isSmooth());
|
||||
@ -157,7 +162,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(!texture.isSmooth());
|
||||
}
|
||||
|
||||
SUBCASE("Set/get srgb")
|
||||
SECTION("Set/get srgb")
|
||||
{
|
||||
sf::Texture texture;
|
||||
CHECK(!texture.isSrgb());
|
||||
@ -167,7 +172,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(!texture.isSrgb());
|
||||
}
|
||||
|
||||
SUBCASE("Set/get repeated")
|
||||
SECTION("Set/get repeated")
|
||||
{
|
||||
sf::Texture texture;
|
||||
CHECK(!texture.isRepeated());
|
||||
@ -177,7 +182,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(!texture.isRepeated());
|
||||
}
|
||||
|
||||
SUBCASE("swap()")
|
||||
SECTION("swap()")
|
||||
{
|
||||
constexpr std::uint8_t blue[] = {0x00, 0x00, 0xFF, 0xFF};
|
||||
constexpr std::uint8_t green[] = {0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF};
|
||||
@ -212,7 +217,7 @@ TEST_CASE("[Graphics] sf::Texture" * doctest::skip(skipDisplayTests))
|
||||
CHECK(image2.getPixel(sf::Vector2u(0, 0)) == sf::Color::Blue);
|
||||
}
|
||||
|
||||
SUBCASE("Get Maximum Size")
|
||||
SECTION("Get Maximum Size")
|
||||
{
|
||||
CHECK(sf::Texture::getMaximumSize() > 0);
|
||||
}
|
||||
|
@ -2,106 +2,91 @@
|
||||
|
||||
#include <SFML/System/Angle.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <sstream>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Transform>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Transform>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Transform>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Transform>);
|
||||
|
||||
// Specialize StringMaker for std::vector<float>
|
||||
// https://github.com/doctest/doctest/blob/master/doc/markdown/stringification.md#docteststringmakert-specialisation
|
||||
namespace doctest
|
||||
{
|
||||
template <>
|
||||
struct StringMaker<std::vector<float>>
|
||||
{
|
||||
static String convert(const std::vector<float>& vector)
|
||||
{
|
||||
assert(!vector.empty());
|
||||
doctest::String out = "{ ";
|
||||
for (std::size_t i = 0; i + 1 < vector.size(); ++i)
|
||||
out += toString(vector[i]) + ", ";
|
||||
out += toString(vector.back()) + " }";
|
||||
return out;
|
||||
}
|
||||
};
|
||||
} // namespace doctest
|
||||
|
||||
TEST_CASE("[Graphics] sf::Transform")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
CHECK(sf::Transform() == sf::Transform::Identity);
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Transform>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Transform>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Transform>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Transform>);
|
||||
}
|
||||
|
||||
SUBCASE("3x3 matrix constructor")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Transform transform(10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f);
|
||||
const std::vector<float> matrix(transform.getMatrix(), transform.getMatrix() + 16);
|
||||
CHECK(
|
||||
matrix ==
|
||||
std::vector<float>{10.0f, 13.0f, 0.0f, 16.0f, 11.0f, 14.0f, 0.0f, 17.0f, 0.0f, 0.0f, 1.0f, 0.0f, 12.0f, 15.0f, 0.0f, 18.0f});
|
||||
}
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
STATIC_CHECK(sf::Transform() == sf::Transform::Identity);
|
||||
}
|
||||
|
||||
SUBCASE("Identity matrix")
|
||||
SECTION("3x3 matrix constructor")
|
||||
{
|
||||
const std::vector<float> matrix(sf::Transform::Identity.getMatrix(), sf::Transform::Identity.getMatrix() + 16);
|
||||
constexpr sf::Transform transform(10.0f, 11.0f, 12.0f, 13.0f, 14.0f, 15.0f, 16.0f, 17.0f, 18.0f);
|
||||
const std::vector matrix(transform.getMatrix(), transform.getMatrix() + 16);
|
||||
CHECK(matrix ==
|
||||
std::vector<float>{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f});
|
||||
std::vector{10.0f, 13.0f, 0.0f, 16.0f, 11.0f, 14.0f, 0.0f, 17.0f, 0.0f, 0.0f, 1.0f, 0.0f, 12.0f, 15.0f, 0.0f, 18.0f});
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("getInverse()")
|
||||
SECTION("Identity matrix")
|
||||
{
|
||||
CHECK(sf::Transform::Identity.getInverse() == sf::Transform::Identity);
|
||||
CHECK(sf::Transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f).getInverse() == sf::Transform::Identity);
|
||||
CHECK(sf::Transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f).getInverse() ==
|
||||
const std::vector matrix(sf::Transform::Identity.getMatrix(), sf::Transform::Identity.getMatrix() + 16);
|
||||
CHECK(matrix ==
|
||||
std::vector{1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f});
|
||||
}
|
||||
|
||||
SECTION("getInverse()")
|
||||
{
|
||||
STATIC_CHECK(sf::Transform::Identity.getInverse() == sf::Transform::Identity);
|
||||
STATIC_CHECK(sf::Transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f).getInverse() ==
|
||||
sf::Transform::Identity);
|
||||
STATIC_CHECK(sf::Transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f).getInverse() ==
|
||||
sf::Transform(0.375f, -0.5f, 0.875f, -1.0f, 1.0f, -1.0f, 0.875f, -0.5f, 0.375f));
|
||||
}
|
||||
|
||||
SUBCASE("transformPoint()")
|
||||
SECTION("transformPoint()")
|
||||
{
|
||||
CHECK(sf::Transform::Identity.transformPoint({-10.0f, -10.0f}) == sf::Vector2f(-10.0f, -10.0f));
|
||||
CHECK(sf::Transform::Identity.transformPoint({-1.0f, -1.0f}) == sf::Vector2f(-1.0f, -1.0f));
|
||||
CHECK(sf::Transform::Identity.transformPoint({-1.0f, 0.0f}) == sf::Vector2f(-1.0f, 0.0f));
|
||||
CHECK(sf::Transform::Identity.transformPoint({0.0f, 0.0f}) == sf::Vector2f(0.0f, 0.0f));
|
||||
CHECK(sf::Transform::Identity.transformPoint({0.0f, 1.0f}) == sf::Vector2f(0.0f, 1.0f));
|
||||
CHECK(sf::Transform::Identity.transformPoint({1.0f, 1.0f}) == sf::Vector2f(1.0f, 1.0f));
|
||||
CHECK(sf::Transform::Identity.transformPoint({10.0f, 10.0f}) == sf::Vector2f(10.0f, 10.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity.transformPoint({-10.0f, -10.0f}) == sf::Vector2f(-10.0f, -10.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity.transformPoint({-1.0f, -1.0f}) == sf::Vector2f(-1.0f, -1.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity.transformPoint({-1.0f, 0.0f}) == sf::Vector2f(-1.0f, 0.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity.transformPoint({0.0f, 0.0f}) == sf::Vector2f(0.0f, 0.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity.transformPoint({0.0f, 1.0f}) == sf::Vector2f(0.0f, 1.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity.transformPoint({1.0f, 1.0f}) == sf::Vector2f(1.0f, 1.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity.transformPoint({10.0f, 10.0f}) == sf::Vector2f(10.0f, 10.0f));
|
||||
|
||||
const sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
CHECK(transform.transformPoint({-1.0f, -1.0f}) == sf::Vector2f(0.0f, -5.0f));
|
||||
CHECK(transform.transformPoint({0.0f, 0.0f}) == sf::Vector2f(3.0f, 4.0f));
|
||||
CHECK(transform.transformPoint({1.0f, 1.0f}) == sf::Vector2f(6.0f, 13.0f));
|
||||
constexpr sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
STATIC_CHECK(transform.transformPoint({-1.0f, -1.0f}) == sf::Vector2f(0.0f, -5.0f));
|
||||
STATIC_CHECK(transform.transformPoint({0.0f, 0.0f}) == sf::Vector2f(3.0f, 4.0f));
|
||||
STATIC_CHECK(transform.transformPoint({1.0f, 1.0f}) == sf::Vector2f(6.0f, 13.0f));
|
||||
}
|
||||
|
||||
SUBCASE("transformRect()")
|
||||
SECTION("transformRect()")
|
||||
{
|
||||
CHECK(sf::Transform::Identity.transformRect({{-200.0f, -200.0f}, {-100.0f, -100.0f}}) ==
|
||||
STATIC_CHECK(sf::Transform::Identity.transformRect({{-200.0f, -200.0f}, {-100.0f, -100.0f}}) ==
|
||||
sf::FloatRect({-300.0f, -300.0f}, {100.0f, 100.0f}));
|
||||
CHECK(sf::Transform::Identity.transformRect({{0.0f, 0.0f}, {0.0f, 0.0f}}) ==
|
||||
STATIC_CHECK(sf::Transform::Identity.transformRect({{0.0f, 0.0f}, {0.0f, 0.0f}}) ==
|
||||
sf::FloatRect({0.0f, 0.0f}, {0.0f, 0.0f}));
|
||||
CHECK(sf::Transform::Identity.transformRect({{100.0f, 100.0f}, {200.0f, 200.0f}}) ==
|
||||
STATIC_CHECK(sf::Transform::Identity.transformRect({{100.0f, 100.0f}, {200.0f, 200.0f}}) ==
|
||||
sf::FloatRect({100.0f, 100.0f}, {200.0f, 200.0f}));
|
||||
|
||||
const sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
CHECK(transform.transformRect({{-100.0f, -100.0f}, {200.0f, 200.0f}}) ==
|
||||
constexpr sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
STATIC_CHECK(transform.transformRect({{-100.0f, -100.0f}, {200.0f, 200.0f}}) ==
|
||||
sf::FloatRect({-297.0f, -896.0f}, {600.0f, 1800.0f}));
|
||||
CHECK(transform.transformRect({{0.0f, 0.0f}, {0.0f, 0.0f}}) == sf::FloatRect({3.0f, 4.0f}, {0.0f, 0.0f}));
|
||||
CHECK(transform.transformRect({{100.0f, 100.0f}, {200.0f, 200.0f}}) ==
|
||||
STATIC_CHECK(transform.transformRect({{0.0f, 0.0f}, {0.0f, 0.0f}}) == sf::FloatRect({3.0f, 4.0f}, {0.0f, 0.0f}));
|
||||
STATIC_CHECK(transform.transformRect({{100.0f, 100.0f}, {200.0f, 200.0f}}) ==
|
||||
sf::FloatRect({303.0f, 904.0f}, {600.0f, 1800.0f}));
|
||||
}
|
||||
|
||||
SUBCASE("combine()")
|
||||
SECTION("combine()")
|
||||
{
|
||||
auto identity = sf::Transform::Identity;
|
||||
CHECK(identity.combine(sf::Transform::Identity) == sf::Transform::Identity);
|
||||
@ -115,23 +100,23 @@ TEST_CASE("[Graphics] sf::Transform")
|
||||
sf::Transform(672.0f, 1216.0f, 914.0f, 1604.0f, 2842.0f, 2108.0f, 752.0f, 1288.0f, 942.0f));
|
||||
}
|
||||
|
||||
SUBCASE("translate()")
|
||||
SECTION("translate()")
|
||||
{
|
||||
sf::Transform transform(9, 8, 7, 6, 5, 4, 3, 2, 1);
|
||||
CHECK(transform.translate({10.0f, 20.0f}) == sf::Transform(9, 8, 257, 6, 5, 164, 3, 2, 71));
|
||||
CHECK(transform.translate({10.0f, 20.0f}) == sf::Transform(9, 8, 507, 6, 5, 324, 3, 2, 141));
|
||||
}
|
||||
|
||||
SUBCASE("rotate()")
|
||||
SECTION("rotate()")
|
||||
{
|
||||
SUBCASE("Around origin")
|
||||
SECTION("Around origin")
|
||||
{
|
||||
sf::Transform transform;
|
||||
transform.rotate(sf::degrees(90));
|
||||
CHECK(transform == Approx(sf::Transform(0, -1, 0, 1, 0, 0, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("Around custom point")
|
||||
SECTION("Around custom point")
|
||||
{
|
||||
sf::Transform transform;
|
||||
transform.rotate(sf::degrees(90), {1.0f, 0.0f});
|
||||
@ -139,9 +124,9 @@ TEST_CASE("[Graphics] sf::Transform")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("scale()")
|
||||
SECTION("scale()")
|
||||
{
|
||||
SUBCASE("About origin")
|
||||
SECTION("About origin")
|
||||
{
|
||||
sf::Transform transform(1, 2, 3, 4, 5, 4, 3, 2, 1);
|
||||
CHECK(transform.scale({2.0f, 4.0f}) == sf::Transform(2, 8, 3, 8, 20, 4, 6, 8, 1));
|
||||
@ -149,7 +134,7 @@ TEST_CASE("[Graphics] sf::Transform")
|
||||
CHECK(transform.scale({10.0f, 10.0f}) == sf::Transform(0, 0, 3, 0, 0, 4, 0, 0, 1));
|
||||
}
|
||||
|
||||
SUBCASE("About custom point")
|
||||
SECTION("About custom point")
|
||||
{
|
||||
sf::Transform transform(1, 2, 3, 4, 5, 4, 3, 2, 1);
|
||||
CHECK(transform.scale({1.0f, 2.0f}, {1.0f, 0.0f}) == sf::Transform(1, 4, 3, 4, 10, 4, 3, 4, 1));
|
||||
@ -157,22 +142,24 @@ TEST_CASE("[Graphics] sf::Transform")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("Operators")
|
||||
{
|
||||
SUBCASE("operator*")
|
||||
SECTION("operator*")
|
||||
{
|
||||
CHECK(sf::Transform::Identity * sf::Transform::Identity == sf::Transform::Identity);
|
||||
CHECK(sf::Transform::Identity * sf::Transform::Identity * sf::Transform::Identity == sf::Transform::Identity);
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Transform::Identity == sf::Transform::Identity);
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Transform::Identity * sf::Transform::Identity ==
|
||||
sf::Transform::Identity);
|
||||
|
||||
const sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
CHECK(sf::Transform::Identity * transform == transform);
|
||||
CHECK(transform * sf::Transform::Identity == transform);
|
||||
CHECK(transform * transform == sf::Transform(18.0f, 18.0f, 14.0f, 36.0f, 41.0f, 36.0f, 14.0f, 18.0f, 18.0f));
|
||||
CHECK(transform * sf::Transform(10.0f, 2.0f, 3.0f, 4.0f, 50.0f, 40.0f, 30.0f, 20.0f, 10.0f) ==
|
||||
constexpr sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
STATIC_CHECK(sf::Transform::Identity * transform == transform);
|
||||
STATIC_CHECK(transform * sf::Transform::Identity == transform);
|
||||
STATIC_CHECK(transform * transform ==
|
||||
sf::Transform(18.0f, 18.0f, 14.0f, 36.0f, 41.0f, 36.0f, 14.0f, 18.0f, 18.0f));
|
||||
STATIC_CHECK(transform * sf::Transform(10.0f, 2.0f, 3.0f, 4.0f, 50.0f, 40.0f, 30.0f, 20.0f, 10.0f) ==
|
||||
sf::Transform(108.0f, 162.0f, 113.0f, 180.0f, 338.0f, 252.0f, 68.0f, 126.0f, 99.0f));
|
||||
}
|
||||
|
||||
SUBCASE("operator*=")
|
||||
SECTION("operator*=")
|
||||
{
|
||||
sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
transform *= sf::Transform::Identity;
|
||||
@ -183,52 +170,54 @@ TEST_CASE("[Graphics] sf::Transform")
|
||||
CHECK(transform == sf::Transform(672.0f, 1216.0f, 914.0f, 1604.0f, 2842.0f, 2108.0f, 752.0f, 1288.0f, 942.0f));
|
||||
}
|
||||
|
||||
SUBCASE("operator* with vector")
|
||||
SECTION("operator* with vector")
|
||||
{
|
||||
CHECK(sf::Transform::Identity * sf::Vector2f(-10.0f, -10.0f) == sf::Vector2f(-10.0f, -10.0f));
|
||||
CHECK(sf::Transform::Identity * sf::Vector2f(-1.0f, -1.0f) == sf::Vector2f(-1.0f, -1.0f));
|
||||
CHECK(sf::Transform::Identity * sf::Vector2f(-1.0f, 0.0f) == sf::Vector2f(-1.0f, 0.0f));
|
||||
CHECK(sf::Transform::Identity * sf::Vector2f(0.0f, 0.0f) == sf::Vector2f(0.0f, 0.0f));
|
||||
CHECK(sf::Transform::Identity * sf::Vector2f(0.0f, 1.0f) == sf::Vector2f(0.0f, 1.0f));
|
||||
CHECK(sf::Transform::Identity * sf::Vector2f(1.0f, 1.0f) == sf::Vector2f(1.0f, 1.0f));
|
||||
CHECK(sf::Transform::Identity * sf::Vector2f(10.0f, 10.0f) == sf::Vector2f(10.0f, 10.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Vector2f(-10.0f, -10.0f) == sf::Vector2f(-10.0f, -10.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Vector2f(-1.0f, -1.0f) == sf::Vector2f(-1.0f, -1.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Vector2f(-1.0f, 0.0f) == sf::Vector2f(-1.0f, 0.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Vector2f(0.0f, 0.0f) == sf::Vector2f(0.0f, 0.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Vector2f(0.0f, 1.0f) == sf::Vector2f(0.0f, 1.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Vector2f(1.0f, 1.0f) == sf::Vector2f(1.0f, 1.0f));
|
||||
STATIC_CHECK(sf::Transform::Identity * sf::Vector2f(10.0f, 10.0f) == sf::Vector2f(10.0f, 10.0f));
|
||||
|
||||
const sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
CHECK(transform * sf::Vector2f(-1.0f, -1.0f) == sf::Vector2f(0.0f, -5.0f));
|
||||
CHECK(transform * sf::Vector2f(0.0f, 0.0f) == sf::Vector2f(3.0f, 4.0f));
|
||||
CHECK(transform * sf::Vector2f(1.0f, 1.0f) == sf::Vector2f(6.0f, 13.0f));
|
||||
constexpr sf::Transform transform(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f);
|
||||
STATIC_CHECK(transform * sf::Vector2f(-1.0f, -1.0f) == sf::Vector2f(0.0f, -5.0f));
|
||||
STATIC_CHECK(transform * sf::Vector2f(0.0f, 0.0f) == sf::Vector2f(3.0f, 4.0f));
|
||||
STATIC_CHECK(transform * sf::Vector2f(1.0f, 1.0f) == sf::Vector2f(6.0f, 13.0f));
|
||||
}
|
||||
|
||||
SUBCASE("operator==")
|
||||
SECTION("operator==")
|
||||
{
|
||||
CHECK(sf::Transform::Identity == sf::Transform::Identity);
|
||||
CHECK(sf::Transform() == sf::Transform());
|
||||
CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0) == sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f) ==
|
||||
STATIC_CHECK(sf::Transform::Identity == sf::Transform::Identity);
|
||||
STATIC_CHECK(sf::Transform() == sf::Transform());
|
||||
STATIC_CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0) == sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f) ==
|
||||
sf::Transform(0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f));
|
||||
CHECK(sf::Transform(1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f) ==
|
||||
STATIC_CHECK(sf::Transform(1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f) ==
|
||||
sf::Transform(1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
CHECK_FALSE(sf::Transform::Identity != sf::Transform::Identity);
|
||||
CHECK_FALSE(sf::Transform() != sf::Transform());
|
||||
CHECK_FALSE(sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK_FALSE(sf::Transform(0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f) !=
|
||||
STATIC_CHECK_FALSE(sf::Transform::Identity != sf::Transform::Identity);
|
||||
STATIC_CHECK_FALSE(sf::Transform() != sf::Transform());
|
||||
STATIC_CHECK_FALSE(sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK_FALSE(
|
||||
sf::Transform(0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f) !=
|
||||
sf::Transform(0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f, 0.0001f));
|
||||
CHECK_FALSE(sf::Transform(1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f) !=
|
||||
STATIC_CHECK_FALSE(
|
||||
sf::Transform(1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f) !=
|
||||
sf::Transform(1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f, 1000.0f));
|
||||
|
||||
CHECK(sf::Transform(1, 0, 0, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 1, 0, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 0, 1, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 0, 0, 1, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 0, 0, 0, 1, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 0, 0, 0, 0, 1, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 1, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 0, 1, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 1) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(1, 0, 0, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 1, 0, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 0, 1, 0, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 0, 0, 1, 0, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 0, 0, 0, 1, 0, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 0, 0, 0, 0, 1, 0, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 1, 0, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 0, 1, 0) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
STATIC_CHECK(sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 1) != sf::Transform(0, 0, 0, 0, 0, 0, 0, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
#include <SFML/Graphics/Transformable.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Transformable>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Transformable>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Transformable>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Transformable>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Transformable")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Transformable>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Transformable>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Transformable>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Transformable>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Transformable transformable;
|
||||
CHECK(transformable.getPosition() == sf::Vector2f(0, 0));
|
||||
@ -23,7 +26,7 @@ TEST_CASE("[Graphics] sf::Transformable")
|
||||
CHECK(transformable.getInverseTransform() == sf::Transform());
|
||||
}
|
||||
|
||||
SUBCASE("Setters and getters")
|
||||
SECTION("Setters and getters")
|
||||
{
|
||||
sf::Transformable transformable;
|
||||
|
||||
@ -84,7 +87,7 @@ TEST_CASE("[Graphics] sf::Transformable")
|
||||
CHECK(transformable.getInverseTransform().getMatrix()[15] == Approx(inverseTransform.getMatrix()[15]));
|
||||
}
|
||||
|
||||
SUBCASE("move()")
|
||||
SECTION("move()")
|
||||
{
|
||||
sf::Transformable transformable;
|
||||
CHECK(transformable.getPosition() == sf::Vector2f(0, 0));
|
||||
@ -94,7 +97,7 @@ TEST_CASE("[Graphics] sf::Transformable")
|
||||
CHECK(transformable.getPosition() == sf::Vector2f(-6, 12));
|
||||
}
|
||||
|
||||
SUBCASE("rotate()")
|
||||
SECTION("rotate()")
|
||||
{
|
||||
sf::Transformable transformable;
|
||||
CHECK(transformable.getRotation() == sf::Angle::Zero);
|
||||
@ -110,7 +113,7 @@ TEST_CASE("[Graphics] sf::Transformable")
|
||||
CHECK(transformable.getRotation() == sf::degrees(340));
|
||||
}
|
||||
|
||||
SUBCASE("scale()")
|
||||
SECTION("scale()")
|
||||
{
|
||||
sf::Transformable transformable;
|
||||
CHECK(transformable.getScale() == sf::Vector2f(1, 1));
|
||||
|
@ -1,65 +1,60 @@
|
||||
#include <SFML/Graphics/Vertex.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Vertex>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Vertex>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Vertex>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Vertex>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::Vertex")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::Vertex vertex;
|
||||
CHECK(vertex.position == sf::Vector2f(0.0f, 0.0f));
|
||||
CHECK(vertex.color == sf::Color(255, 255, 255));
|
||||
CHECK(vertex.texCoords == sf::Vector2f(0.0f, 0.0f));
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Vertex>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Vertex>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Vertex>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Vertex>);
|
||||
}
|
||||
|
||||
SUBCASE("Position constructor")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Vertex vertex({1, 2});
|
||||
CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
CHECK(vertex.color == sf::Color(255, 255, 255));
|
||||
CHECK(vertex.texCoords == sf::Vector2f(0.0f, 0.0f));
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
constexpr sf::Vertex vertex;
|
||||
STATIC_CHECK(vertex.position == sf::Vector2f(0.0f, 0.0f));
|
||||
STATIC_CHECK(vertex.color == sf::Color(255, 255, 255));
|
||||
STATIC_CHECK(vertex.texCoords == sf::Vector2f(0.0f, 0.0f));
|
||||
}
|
||||
|
||||
SUBCASE("Position and color constructor")
|
||||
SECTION("Position constructor")
|
||||
{
|
||||
const sf::Vertex vertex({1, 2}, {3, 4, 5, 6});
|
||||
CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
CHECK(vertex.color == sf::Color(3, 4, 5, 6));
|
||||
CHECK(vertex.texCoords == sf::Vector2f(0.0f, 0.0f));
|
||||
constexpr sf::Vertex vertex({1, 2});
|
||||
STATIC_CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
STATIC_CHECK(vertex.color == sf::Color(255, 255, 255));
|
||||
STATIC_CHECK(vertex.texCoords == sf::Vector2f(0.0f, 0.0f));
|
||||
}
|
||||
|
||||
SUBCASE("Position and coords constructor")
|
||||
SECTION("Position and color constructor")
|
||||
{
|
||||
const sf::Vertex vertex({1, 2}, {3, 4});
|
||||
CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
CHECK(vertex.color == sf::Color(255, 255, 255));
|
||||
CHECK(vertex.texCoords == sf::Vector2f(3.0f, 4.0f));
|
||||
constexpr sf::Vertex vertex({1, 2}, {3, 4, 5, 6});
|
||||
STATIC_CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
STATIC_CHECK(vertex.color == sf::Color(3, 4, 5, 6));
|
||||
STATIC_CHECK(vertex.texCoords == sf::Vector2f(0.0f, 0.0f));
|
||||
}
|
||||
|
||||
SUBCASE("Position, color, and coords constructor")
|
||||
SECTION("Position and coords constructor")
|
||||
{
|
||||
const sf::Vertex vertex({1, 2}, {3, 4, 5, 6}, {7, 8});
|
||||
CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
CHECK(vertex.color == sf::Color(3, 4, 5, 6));
|
||||
CHECK(vertex.texCoords == sf::Vector2f(7.0f, 8.0f));
|
||||
}
|
||||
constexpr sf::Vertex vertex({1, 2}, {3, 4});
|
||||
STATIC_CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
STATIC_CHECK(vertex.color == sf::Color(255, 255, 255));
|
||||
STATIC_CHECK(vertex.texCoords == sf::Vector2f(3.0f, 4.0f));
|
||||
}
|
||||
|
||||
SUBCASE("Constexpr support")
|
||||
SECTION("Position, color, and coords constructor")
|
||||
{
|
||||
constexpr sf::Vertex vertex({1, 2}, {3, 4, 5, 6}, {7, 8});
|
||||
static_assert(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
static_assert(vertex.color == sf::Color(3, 4, 5, 6));
|
||||
static_assert(vertex.texCoords == sf::Vector2f(7.0f, 8.0f));
|
||||
STATIC_CHECK(vertex.position == sf::Vector2f(1.0f, 2.0f));
|
||||
STATIC_CHECK(vertex.color == sf::Color(3, 4, 5, 6));
|
||||
STATIC_CHECK(vertex.texCoords == sf::Vector2f(7.0f, 8.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,23 @@
|
||||
#include <SFML/Graphics/VertexArray.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::VertexArray>);
|
||||
static_assert(std::is_copy_assignable_v<sf::VertexArray>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::VertexArray>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::VertexArray>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::VertexArray")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::VertexArray>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::VertexArray>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::VertexArray>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::VertexArray>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::VertexArray vertexArray;
|
||||
CHECK(vertexArray.getVertexCount() == 0);
|
||||
@ -22,7 +25,7 @@ TEST_CASE("[Graphics] sf::VertexArray")
|
||||
CHECK(vertexArray.getBounds() == sf::FloatRect({0, 0}, {0, 0}));
|
||||
}
|
||||
|
||||
SUBCASE("Explicit constructor with default argument")
|
||||
SECTION("Explicit constructor with default argument")
|
||||
{
|
||||
const sf::VertexArray vertexArray(sf::PrimitiveType::Lines);
|
||||
CHECK(vertexArray.getVertexCount() == 0);
|
||||
@ -30,7 +33,7 @@ TEST_CASE("[Graphics] sf::VertexArray")
|
||||
CHECK(vertexArray.getBounds() == sf::FloatRect({0, 0}, {0, 0}));
|
||||
}
|
||||
|
||||
SUBCASE("Explicit constructor")
|
||||
SECTION("Explicit constructor")
|
||||
{
|
||||
const sf::VertexArray vertexArray(sf::PrimitiveType::Lines, 10);
|
||||
CHECK(vertexArray.getVertexCount() == 10);
|
||||
@ -45,7 +48,7 @@ TEST_CASE("[Graphics] sf::VertexArray")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Resize array")
|
||||
SECTION("Resize array")
|
||||
{
|
||||
sf::VertexArray vertexArray;
|
||||
vertexArray.resize(42);
|
||||
@ -58,7 +61,7 @@ TEST_CASE("[Graphics] sf::VertexArray")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Clear array")
|
||||
SECTION("Clear array")
|
||||
{
|
||||
sf::VertexArray vertexArray;
|
||||
vertexArray.append({});
|
||||
@ -66,7 +69,7 @@ TEST_CASE("[Graphics] sf::VertexArray")
|
||||
CHECK(vertexArray.getVertexCount() == 0);
|
||||
}
|
||||
|
||||
SUBCASE("Append to array")
|
||||
SECTION("Append to array")
|
||||
{
|
||||
sf::VertexArray vertexArray;
|
||||
const sf::Vertex vertex({1, 2}, {3, 4, 5, 6}, {7, 8});
|
||||
@ -77,7 +80,7 @@ TEST_CASE("[Graphics] sf::VertexArray")
|
||||
CHECK(vertexArray[0].texCoords == vertex.texCoords);
|
||||
}
|
||||
|
||||
SUBCASE("Write to array")
|
||||
SECTION("Write to array")
|
||||
{
|
||||
sf::VertexArray vertexArray;
|
||||
vertexArray.resize(10);
|
||||
@ -88,14 +91,14 @@ TEST_CASE("[Graphics] sf::VertexArray")
|
||||
CHECK(vertexArray[9].texCoords == otherVertex.texCoords);
|
||||
}
|
||||
|
||||
SUBCASE("Set primitive type")
|
||||
SECTION("Set primitive type")
|
||||
{
|
||||
sf::VertexArray vertexArray;
|
||||
vertexArray.setPrimitiveType(sf::PrimitiveType::TriangleStrip);
|
||||
CHECK(vertexArray.getPrimitiveType() == sf::PrimitiveType::TriangleStrip);
|
||||
}
|
||||
|
||||
SUBCASE("Get bounds")
|
||||
SECTION("Get bounds")
|
||||
{
|
||||
sf::VertexArray vertexArray;
|
||||
vertexArray.append(sf::Vertex({1, 1}));
|
||||
|
@ -3,30 +3,33 @@
|
||||
// Other first party headers
|
||||
#include <SFML/Graphics/Vertex.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::VertexBuffer>);
|
||||
static_assert(std::is_copy_assignable_v<sf::VertexBuffer>);
|
||||
static_assert(std::is_move_constructible_v<sf::VertexBuffer>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::VertexBuffer>);
|
||||
static_assert(std::is_move_assignable_v<sf::VertexBuffer>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::VertexBuffer>);
|
||||
static_assert(std::is_nothrow_swappable_v<sf::VertexBuffer>);
|
||||
|
||||
// Skip these tests because they produce flakey failures in CI when using xvfb-run
|
||||
TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
// Skip these tests with [.display] because they produce flakey failures in CI when using xvfb-run
|
||||
TEST_CASE("[Graphics] sf::VertexBuffer", "[.display]")
|
||||
{
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::VertexBuffer>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::VertexBuffer>);
|
||||
STATIC_CHECK(std::is_move_constructible_v<sf::VertexBuffer>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::VertexBuffer>);
|
||||
STATIC_CHECK(std::is_move_assignable_v<sf::VertexBuffer>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::VertexBuffer>);
|
||||
STATIC_CHECK(std::is_nothrow_swappable_v<sf::VertexBuffer>);
|
||||
}
|
||||
|
||||
// Skip tests if vertex buffers aren't available
|
||||
if (!sf::VertexBuffer::isAvailable())
|
||||
return;
|
||||
|
||||
SUBCASE("Construction")
|
||||
SECTION("Construction")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::VertexBuffer vertexBuffer;
|
||||
CHECK(vertexBuffer.getVertexCount() == 0);
|
||||
@ -35,7 +38,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Stream);
|
||||
}
|
||||
|
||||
SUBCASE("Primitive type constructor")
|
||||
SECTION("Primitive type constructor")
|
||||
{
|
||||
const sf::VertexBuffer vertexBuffer(sf::PrimitiveType::Triangles);
|
||||
CHECK(vertexBuffer.getVertexCount() == 0);
|
||||
@ -44,7 +47,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Stream);
|
||||
}
|
||||
|
||||
SUBCASE("Usage constructor")
|
||||
SECTION("Usage constructor")
|
||||
{
|
||||
const sf::VertexBuffer vertexBuffer(sf::VertexBuffer::Static);
|
||||
CHECK(vertexBuffer.getVertexCount() == 0);
|
||||
@ -53,7 +56,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
CHECK(vertexBuffer.getUsage() == sf::VertexBuffer::Static);
|
||||
}
|
||||
|
||||
SUBCASE("Primitive type and usage constructor")
|
||||
SECTION("Primitive type and usage constructor")
|
||||
{
|
||||
const sf::VertexBuffer vertexBuffer(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Dynamic);
|
||||
CHECK(vertexBuffer.getVertexCount() == 0);
|
||||
@ -63,11 +66,11 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Copy semantics")
|
||||
SECTION("Copy semantics")
|
||||
{
|
||||
const sf::VertexBuffer vertexBuffer(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Dynamic);
|
||||
|
||||
SUBCASE("Construction")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::VertexBuffer vertexBufferCopy(vertexBuffer); // NOLINT(performance-unnecessary-copy-initialization)
|
||||
CHECK(vertexBufferCopy.getVertexCount() == 0);
|
||||
@ -76,7 +79,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
CHECK(vertexBufferCopy.getUsage() == sf::VertexBuffer::Dynamic);
|
||||
}
|
||||
|
||||
SUBCASE("Assignment")
|
||||
SECTION("Assignment")
|
||||
{
|
||||
sf::VertexBuffer vertexBufferCopy;
|
||||
vertexBufferCopy = vertexBuffer;
|
||||
@ -87,28 +90,28 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("create()")
|
||||
SECTION("create()")
|
||||
{
|
||||
sf::VertexBuffer vertexBuffer;
|
||||
CHECK(vertexBuffer.create(100));
|
||||
CHECK(vertexBuffer.getVertexCount() == 100);
|
||||
}
|
||||
|
||||
SUBCASE("update()")
|
||||
SECTION("update()")
|
||||
{
|
||||
sf::VertexBuffer vertexBuffer;
|
||||
std::array<sf::Vertex, 128> vertices{};
|
||||
|
||||
SUBCASE("Vertices")
|
||||
SECTION("Vertices")
|
||||
{
|
||||
SUBCASE("Uninitialized buffer")
|
||||
SECTION("Uninitialized buffer")
|
||||
{
|
||||
CHECK(!vertexBuffer.update(vertices.data()));
|
||||
}
|
||||
|
||||
CHECK(vertexBuffer.create(128));
|
||||
|
||||
SUBCASE("Null vertices")
|
||||
SECTION("Null vertices")
|
||||
{
|
||||
CHECK(!vertexBuffer.update(nullptr));
|
||||
}
|
||||
@ -118,11 +121,11 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
CHECK(vertexBuffer.getNativeHandle() != 0);
|
||||
}
|
||||
|
||||
SUBCASE("Vertices, count, and offset")
|
||||
SECTION("Vertices, count, and offset")
|
||||
{
|
||||
CHECK(vertexBuffer.create(128));
|
||||
|
||||
SUBCASE("Count + offset too large")
|
||||
SECTION("Count + offset too large")
|
||||
{
|
||||
CHECK(!vertexBuffer.update(vertices.data(), 100, 100));
|
||||
}
|
||||
@ -131,7 +134,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
CHECK(vertexBuffer.getVertexCount() == 128);
|
||||
}
|
||||
|
||||
SUBCASE("Another buffer")
|
||||
SECTION("Another buffer")
|
||||
{
|
||||
sf::VertexBuffer otherVertexBuffer;
|
||||
|
||||
@ -141,7 +144,7 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("swap()")
|
||||
SECTION("swap()")
|
||||
{
|
||||
sf::VertexBuffer vertexBuffer1(sf::PrimitiveType::LineStrip, sf::VertexBuffer::Dynamic);
|
||||
CHECK(vertexBuffer1.create(50));
|
||||
@ -162,14 +165,14 @@ TEST_CASE("[Graphics] sf::VertexBuffer" * doctest::skip(true))
|
||||
CHECK(vertexBuffer2.getUsage() == sf::VertexBuffer::Dynamic);
|
||||
}
|
||||
|
||||
SUBCASE("Set/get primitive type")
|
||||
SECTION("Set/get primitive type")
|
||||
{
|
||||
sf::VertexBuffer vertexBuffer;
|
||||
vertexBuffer.setPrimitiveType(sf::PrimitiveType::TriangleFan);
|
||||
CHECK(vertexBuffer.getPrimitiveType() == sf::PrimitiveType::TriangleFan);
|
||||
}
|
||||
|
||||
SUBCASE("Set/get usage")
|
||||
SECTION("Set/get usage")
|
||||
{
|
||||
sf::VertexBuffer vertexBuffer;
|
||||
vertexBuffer.setUsage(sf::VertexBuffer::Dynamic);
|
||||
|
@ -1,20 +1,23 @@
|
||||
#include <SFML/Graphics/View.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::View>);
|
||||
static_assert(std::is_copy_assignable_v<sf::View>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::View>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::View>);
|
||||
|
||||
TEST_CASE("[Graphics] sf::View")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::View>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::View>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::View>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::View>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::View view;
|
||||
CHECK(view.getCenter() == sf::Vector2f(500, 500));
|
||||
@ -25,7 +28,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(500, 0, 500, 0, -500, 500, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("Rectangle constructor")
|
||||
SECTION("Rectangle constructor")
|
||||
{
|
||||
const sf::View view(sf::FloatRect({10, 20}, {400, 600}));
|
||||
CHECK(view.getCenter() == sf::Vector2f(210, 320));
|
||||
@ -36,7 +39,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(200, 0, 210, 0, -300, 320, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("Center + size constructor")
|
||||
SECTION("Center + size constructor")
|
||||
{
|
||||
const sf::View view({520, 960}, {1080, 1920});
|
||||
CHECK(view.getCenter() == sf::Vector2f(520, 960));
|
||||
@ -48,7 +51,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Set/get center")
|
||||
SECTION("Set/get center")
|
||||
{
|
||||
sf::View view;
|
||||
view.setCenter({3.14f, 4.2f});
|
||||
@ -57,7 +60,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(500, 0, 3.14f, 0, -500, 4.2f, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("Set/get size")
|
||||
SECTION("Set/get size")
|
||||
{
|
||||
sf::View view;
|
||||
view.setSize({600, 900});
|
||||
@ -66,7 +69,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(300, 0, 500, 0, -450, 500, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("Set/get rotation")
|
||||
SECTION("Set/get rotation")
|
||||
{
|
||||
sf::View view;
|
||||
view.setRotation(sf::degrees(-345));
|
||||
@ -83,7 +86,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
Approx(sf::Transform(383.022f, 321.394f, 500, 321.394f, -383.022f, 500, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("Set/get viewport")
|
||||
SECTION("Set/get viewport")
|
||||
{
|
||||
sf::View view;
|
||||
view.setViewport({{150, 250}, {500, 750}});
|
||||
@ -92,7 +95,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(500, 0, 500, 0, -500, 500, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("reset()")
|
||||
SECTION("reset()")
|
||||
{
|
||||
sf::View view;
|
||||
view.setCenter({3.14f, 4.2f});
|
||||
@ -108,7 +111,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(1.5f, 0, 2.5f, 0, -2, 4, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("move()")
|
||||
SECTION("move()")
|
||||
{
|
||||
sf::View view;
|
||||
view.setCenter({25, 25});
|
||||
@ -118,7 +121,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(500, 0, 40, 0, -500, 50, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("rotate()")
|
||||
SECTION("rotate()")
|
||||
{
|
||||
sf::View view;
|
||||
view.setRotation(sf::degrees(45));
|
||||
@ -129,7 +132,7 @@ TEST_CASE("[Graphics] sf::View")
|
||||
CHECK(view.getInverseTransform() == Approx(sf::Transform(433.013f, 250, 500, 250, -433.013f, 500, 0, 0, 1)));
|
||||
}
|
||||
|
||||
SUBCASE("zoom()")
|
||||
SECTION("zoom()")
|
||||
{
|
||||
sf::View view;
|
||||
view.setSize({25, 25});
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <SFML/Network/IpAddress.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <sstream>
|
||||
#include <string_view>
|
||||
@ -9,16 +9,19 @@
|
||||
using namespace std::string_literals;
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::IpAddress>);
|
||||
static_assert(std::is_copy_assignable_v<sf::IpAddress>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::IpAddress>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::IpAddress>);
|
||||
|
||||
TEST_CASE("[Network] sf::IpAddress")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("static 'create' function")
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::IpAddress>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::IpAddress>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::IpAddress>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::IpAddress>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
SECTION("static 'create' function")
|
||||
{
|
||||
const auto ipAddress = sf::IpAddress::resolve("203.0.113.2"sv);
|
||||
REQUIRE(ipAddress.has_value());
|
||||
@ -50,14 +53,14 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(!sf::IpAddress::resolve("").has_value());
|
||||
}
|
||||
|
||||
SUBCASE("Byte constructor")
|
||||
SECTION("Byte constructor")
|
||||
{
|
||||
const sf::IpAddress ipAddress(198, 51, 100, 234);
|
||||
CHECK(ipAddress.toString() == "198.51.100.234"s);
|
||||
CHECK(ipAddress.toInteger() == 0xC63364EA);
|
||||
}
|
||||
|
||||
SUBCASE("std::uint32_t constructor")
|
||||
SECTION("std::uint32_t constructor")
|
||||
{
|
||||
const sf::IpAddress ipAddress(0xCB00719A);
|
||||
CHECK(ipAddress.toString() == "203.0.113.154"s);
|
||||
@ -65,9 +68,9 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Static functions")
|
||||
SECTION("Static functions")
|
||||
{
|
||||
SUBCASE("getLocalAddress")
|
||||
SECTION("getLocalAddress")
|
||||
{
|
||||
const std::optional<sf::IpAddress> ipAddress = sf::IpAddress::getLocalAddress();
|
||||
REQUIRE(ipAddress.has_value());
|
||||
@ -75,7 +78,7 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(ipAddress->toInteger() != 0);
|
||||
}
|
||||
|
||||
SUBCASE("getPublicAddress")
|
||||
SECTION("getPublicAddress")
|
||||
{
|
||||
const std::optional<sf::IpAddress> ipAddress = sf::IpAddress::getPublicAddress(sf::seconds(1));
|
||||
if (ipAddress.has_value())
|
||||
@ -86,7 +89,7 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Static constants")
|
||||
SECTION("Static constants")
|
||||
{
|
||||
CHECK(sf::IpAddress::Any.toString() == "0.0.0.0"s);
|
||||
CHECK(sf::IpAddress::Any.toInteger() == 0);
|
||||
@ -98,21 +101,21 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(sf::IpAddress::Broadcast.toInteger() == 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("Operators")
|
||||
{
|
||||
SUBCASE("operator==")
|
||||
SECTION("operator==")
|
||||
{
|
||||
CHECK(sf::IpAddress(0xC6, 0x33, 0x64, 0x7B) == sf::IpAddress(0xC633647B));
|
||||
CHECK(sf::IpAddress(0xCB0071D2) == sf::IpAddress(203, 0, 113, 210));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
CHECK(sf::IpAddress(0x12344321) != sf::IpAddress(1234));
|
||||
CHECK(sf::IpAddress(198, 51, 100, 1) != sf::IpAddress(198, 51, 100, 11));
|
||||
}
|
||||
|
||||
SUBCASE("operator<")
|
||||
SECTION("operator<")
|
||||
{
|
||||
CHECK(sf::IpAddress(1) < sf::IpAddress(2));
|
||||
CHECK(sf::IpAddress(0, 0, 0, 0) < sf::IpAddress(1, 0, 0, 0));
|
||||
@ -122,7 +125,7 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(sf::IpAddress(0, 0, 0, 1) < sf::IpAddress(1, 0, 0, 1));
|
||||
}
|
||||
|
||||
SUBCASE("operator>")
|
||||
SECTION("operator>")
|
||||
{
|
||||
CHECK(sf::IpAddress(2) > sf::IpAddress(1));
|
||||
CHECK(sf::IpAddress(1, 0, 0, 0) > sf::IpAddress(0, 0, 0, 0));
|
||||
@ -132,7 +135,7 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(sf::IpAddress(1, 0, 0, 1) > sf::IpAddress(0, 0, 0, 1));
|
||||
}
|
||||
|
||||
SUBCASE("operator<=")
|
||||
SECTION("operator<=")
|
||||
{
|
||||
CHECK(sf::IpAddress(1) <= sf::IpAddress(2));
|
||||
CHECK(sf::IpAddress(0, 0, 0, 0) <= sf::IpAddress(1, 0, 0, 0));
|
||||
@ -145,7 +148,7 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(sf::IpAddress(0xCB0071D2) <= sf::IpAddress(203, 0, 113, 210));
|
||||
}
|
||||
|
||||
SUBCASE("operator>=")
|
||||
SECTION("operator>=")
|
||||
{
|
||||
CHECK(sf::IpAddress(2) >= sf::IpAddress(1));
|
||||
CHECK(sf::IpAddress(1, 0, 0, 0) >= sf::IpAddress(0, 0, 0, 0));
|
||||
@ -158,7 +161,7 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(sf::IpAddress(0xCB0071D2) >= sf::IpAddress(203, 0, 113, 210));
|
||||
}
|
||||
|
||||
SUBCASE("operator>>")
|
||||
SECTION("operator>>")
|
||||
{
|
||||
std::optional<sf::IpAddress> ipAddress;
|
||||
std::istringstream("198.51.100.4") >> ipAddress;
|
||||
@ -175,7 +178,7 @@ TEST_CASE("[Network] sf::IpAddress")
|
||||
CHECK(!ipAddress.has_value());
|
||||
}
|
||||
|
||||
SUBCASE("operator<<")
|
||||
SECTION("operator<<")
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << sf::IpAddress(192, 0, 2, 10);
|
||||
|
@ -1,16 +1,11 @@
|
||||
#include <SFML/Network/Packet.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <array>
|
||||
#include <limits>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Packet>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Packet>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Packet>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Packet>);
|
||||
|
||||
#define CHECK_PACKET_STREAM_OPERATORS(expected) \
|
||||
do \
|
||||
{ \
|
||||
@ -34,7 +29,15 @@ static_assert(std::is_nothrow_move_assignable_v<sf::Packet>);
|
||||
|
||||
TEST_CASE("[Network] sf::Packet")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Packet>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Packet>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Packet>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Packet>);
|
||||
}
|
||||
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::Packet packet;
|
||||
CHECK(packet.getReadPosition() == 0);
|
||||
@ -44,7 +47,7 @@ TEST_CASE("[Network] sf::Packet")
|
||||
CHECK(static_cast<bool>(packet));
|
||||
}
|
||||
|
||||
SUBCASE("Append and clear")
|
||||
SECTION("Append and clear")
|
||||
{
|
||||
constexpr std::array data = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
@ -64,9 +67,9 @@ TEST_CASE("[Network] sf::Packet")
|
||||
CHECK(static_cast<bool>(packet));
|
||||
}
|
||||
|
||||
SUBCASE("Stream operators")
|
||||
SECTION("Stream operators")
|
||||
{
|
||||
SUBCASE("std::int8_t")
|
||||
SECTION("std::int8_t")
|
||||
{
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int8_t(0));
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int8_t(1));
|
||||
@ -74,7 +77,7 @@ TEST_CASE("[Network] sf::Packet")
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::numeric_limits<std::int8_t>::max());
|
||||
}
|
||||
|
||||
SUBCASE("std::int16_t")
|
||||
SECTION("std::int16_t")
|
||||
{
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int16_t(0));
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int16_t(1));
|
||||
@ -82,7 +85,7 @@ TEST_CASE("[Network] sf::Packet")
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::numeric_limits<std::int16_t>::max());
|
||||
}
|
||||
|
||||
SUBCASE("std::int32_t")
|
||||
SECTION("std::int32_t")
|
||||
{
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int32_t(0));
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int32_t(1));
|
||||
@ -90,7 +93,7 @@ TEST_CASE("[Network] sf::Packet")
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::numeric_limits<std::int32_t>::max());
|
||||
}
|
||||
|
||||
SUBCASE("std::int64_t")
|
||||
SECTION("std::int64_t")
|
||||
{
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int64_t(0));
|
||||
CHECK_PACKET_STREAM_OPERATORS(std::int64_t(1));
|
||||
|
@ -1,187 +1,187 @@
|
||||
#include <SFML/System/Angle.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Angle>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Angle>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Angle>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Angle>);
|
||||
|
||||
TEST_CASE("[System] sf::Angle")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::Angle angle;
|
||||
CHECK(angle.asDegrees() == 0.f);
|
||||
CHECK(angle.asRadians() == 0.f);
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Angle>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Angle>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Angle>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Angle>);
|
||||
}
|
||||
|
||||
SUBCASE("wrapSigned()")
|
||||
SECTION("Construction")
|
||||
{
|
||||
CHECK(sf::Angle::Zero.wrapSigned() == sf::Angle::Zero);
|
||||
CHECK(sf::degrees(0).wrapSigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(1).wrapSigned() == sf::degrees(1));
|
||||
CHECK(sf::degrees(-1).wrapSigned() == sf::degrees(-1));
|
||||
CHECK(sf::degrees(90).wrapSigned() == sf::degrees(90));
|
||||
CHECK(sf::degrees(-90).wrapSigned() == sf::degrees(-90));
|
||||
CHECK(sf::degrees(180).wrapSigned() == sf::degrees(-180));
|
||||
CHECK(sf::degrees(-180).wrapSigned() == sf::degrees(-180));
|
||||
CHECK(sf::degrees(360).wrapSigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(-360).wrapSigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(720).wrapSigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(-720).wrapSigned() == sf::degrees(0));
|
||||
constexpr sf::Angle angle;
|
||||
STATIC_CHECK(angle.asDegrees() == 0.f);
|
||||
STATIC_CHECK(angle.asRadians() == 0.f);
|
||||
}
|
||||
|
||||
SUBCASE("wrapUnsigned()")
|
||||
SECTION("wrapSigned()")
|
||||
{
|
||||
CHECK(sf::Angle::Zero.wrapUnsigned() == sf::Angle::Zero);
|
||||
CHECK(sf::degrees(0).wrapUnsigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(1).wrapUnsigned() == sf::degrees(1));
|
||||
CHECK(sf::degrees(-1).wrapUnsigned() == sf::degrees(359));
|
||||
CHECK(sf::degrees(90).wrapUnsigned() == sf::degrees(90));
|
||||
CHECK(sf::degrees(-90).wrapUnsigned() == sf::degrees(270));
|
||||
CHECK(sf::degrees(180).wrapUnsigned() == sf::degrees(180));
|
||||
CHECK(sf::degrees(-180).wrapUnsigned() == sf::degrees(180));
|
||||
CHECK(sf::degrees(360).wrapUnsigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(-360).wrapUnsigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(720).wrapUnsigned() == sf::degrees(0));
|
||||
CHECK(sf::degrees(-720).wrapUnsigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::Angle::Zero.wrapSigned() == sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::degrees(0).wrapSigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(1).wrapSigned() == sf::degrees(1));
|
||||
STATIC_CHECK(sf::degrees(-1).wrapSigned() == sf::degrees(-1));
|
||||
STATIC_CHECK(sf::degrees(90).wrapSigned() == sf::degrees(90));
|
||||
STATIC_CHECK(sf::degrees(-90).wrapSigned() == sf::degrees(-90));
|
||||
STATIC_CHECK(sf::degrees(180).wrapSigned() == sf::degrees(-180));
|
||||
STATIC_CHECK(sf::degrees(-180).wrapSigned() == sf::degrees(-180));
|
||||
STATIC_CHECK(sf::degrees(360).wrapSigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(-360).wrapSigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(720).wrapSigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(-720).wrapSigned() == sf::degrees(0));
|
||||
}
|
||||
|
||||
SUBCASE("degrees()")
|
||||
SECTION("wrapUnsigned()")
|
||||
{
|
||||
const sf::Angle angle = sf::degrees(15);
|
||||
CHECK(angle == sf::degrees(15));
|
||||
STATIC_CHECK(sf::Angle::Zero.wrapUnsigned() == sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::degrees(0).wrapUnsigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(1).wrapUnsigned() == sf::degrees(1));
|
||||
STATIC_CHECK(sf::degrees(-1).wrapUnsigned() == sf::degrees(359));
|
||||
STATIC_CHECK(sf::degrees(90).wrapUnsigned() == sf::degrees(90));
|
||||
STATIC_CHECK(sf::degrees(-90).wrapUnsigned() == sf::degrees(270));
|
||||
STATIC_CHECK(sf::degrees(180).wrapUnsigned() == sf::degrees(180));
|
||||
STATIC_CHECK(sf::degrees(-180).wrapUnsigned() == sf::degrees(180));
|
||||
STATIC_CHECK(sf::degrees(360).wrapUnsigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(-360).wrapUnsigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(720).wrapUnsigned() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(-720).wrapUnsigned() == sf::degrees(0));
|
||||
}
|
||||
|
||||
SECTION("degrees()")
|
||||
{
|
||||
constexpr sf::Angle angle = sf::degrees(15);
|
||||
STATIC_CHECK(angle == sf::degrees(15));
|
||||
CHECK(angle.asRadians() == Approx(0.26179939f));
|
||||
|
||||
const sf::Angle bigAngle = sf::degrees(1000);
|
||||
CHECK(bigAngle == sf::degrees(1000));
|
||||
constexpr sf::Angle bigAngle = sf::degrees(1000);
|
||||
STATIC_CHECK(bigAngle == sf::degrees(1000));
|
||||
CHECK(bigAngle.asRadians() == Approx(17.453293f));
|
||||
|
||||
const sf::Angle bigNegativeAngle = sf::degrees(-4321);
|
||||
CHECK(bigNegativeAngle == sf::degrees(-4321));
|
||||
constexpr sf::Angle bigNegativeAngle = sf::degrees(-4321);
|
||||
STATIC_CHECK(bigNegativeAngle == sf::degrees(-4321));
|
||||
CHECK(bigNegativeAngle.asRadians() == Approx(-75.415677f));
|
||||
}
|
||||
|
||||
SUBCASE("radians()")
|
||||
SECTION("radians()")
|
||||
{
|
||||
const sf::Angle angle = sf::radians(1);
|
||||
constexpr sf::Angle angle = sf::radians(1);
|
||||
CHECK(angle.asDegrees() == Approx(57.2957795f));
|
||||
CHECK(angle.asRadians() == Approx(1.f));
|
||||
|
||||
const sf::Angle bigAngle = sf::radians(72);
|
||||
constexpr sf::Angle bigAngle = sf::radians(72);
|
||||
CHECK(bigAngle.asDegrees() == Approx(4125.29612f));
|
||||
CHECK(bigAngle.asRadians() == Approx(72.f));
|
||||
|
||||
const sf::Angle bigNegativeAngle = sf::radians(-200);
|
||||
constexpr sf::Angle bigNegativeAngle = sf::radians(-200);
|
||||
CHECK(bigNegativeAngle.asDegrees() == Approx(-11459.1559f));
|
||||
CHECK(bigNegativeAngle.asRadians() == Approx(-200.f));
|
||||
}
|
||||
|
||||
SECTION("Constants")
|
||||
{
|
||||
STATIC_CHECK(sf::Angle::Zero.asDegrees() == 0.f);
|
||||
STATIC_CHECK(sf::Angle::Zero.asRadians() == 0.f);
|
||||
}
|
||||
|
||||
SUBCASE("Constants")
|
||||
SECTION("Operators")
|
||||
{
|
||||
CHECK(sf::Angle::Zero.asDegrees() == 0.f);
|
||||
CHECK(sf::Angle::Zero.asRadians() == 0.f);
|
||||
SECTION("operator==")
|
||||
{
|
||||
STATIC_CHECK(sf::Angle() == sf::Angle());
|
||||
STATIC_CHECK(sf::Angle() == sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::Angle() == sf::degrees(0));
|
||||
STATIC_CHECK(sf::Angle() == sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(0) == sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(15) == sf::degrees(15));
|
||||
STATIC_CHECK(sf::radians(1) == sf::radians(1));
|
||||
STATIC_CHECK(sf::degrees(360) == sf::degrees(360));
|
||||
STATIC_CHECK(sf::degrees(720) == sf::degrees(720));
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
SUBCASE("operator==")
|
||||
{
|
||||
CHECK(sf::Angle() == sf::Angle());
|
||||
CHECK(sf::Angle() == sf::Angle::Zero);
|
||||
CHECK(sf::Angle() == sf::degrees(0));
|
||||
CHECK(sf::Angle() == sf::radians(0));
|
||||
CHECK(sf::degrees(0) == sf::radians(0));
|
||||
CHECK(sf::degrees(15) == sf::degrees(15));
|
||||
CHECK(sf::radians(1) == sf::radians(1));
|
||||
CHECK(sf::degrees(360) == sf::degrees(360));
|
||||
CHECK(sf::degrees(720) == sf::degrees(720));
|
||||
STATIC_CHECK(sf::Angle() != sf::radians(2));
|
||||
STATIC_CHECK(sf::degrees(1) != sf::radians(1));
|
||||
STATIC_CHECK(sf::radians(0) != sf::radians(0.1f));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator<")
|
||||
{
|
||||
CHECK(sf::Angle() != sf::radians(2));
|
||||
CHECK(sf::degrees(1) != sf::radians(1));
|
||||
CHECK(sf::radians(0) != sf::radians(0.1f));
|
||||
STATIC_CHECK(sf::radians(0) < sf::degrees(0.1f));
|
||||
STATIC_CHECK(sf::degrees(0) < sf::radians(0.1f));
|
||||
STATIC_CHECK(sf::radians(-0.1f) < sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(-0.1f) < sf::degrees(0));
|
||||
}
|
||||
|
||||
SUBCASE("operator<")
|
||||
SECTION("operator>")
|
||||
{
|
||||
CHECK(sf::radians(0) < sf::degrees(0.1f));
|
||||
CHECK(sf::degrees(0) < sf::radians(0.1f));
|
||||
CHECK(sf::radians(-0.1f) < sf::radians(0));
|
||||
CHECK(sf::degrees(-0.1f) < sf::degrees(0));
|
||||
STATIC_CHECK(sf::radians(0.1f) > sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(0.1f) > sf::radians(0));
|
||||
STATIC_CHECK(sf::radians(0) > sf::radians(-0.1f));
|
||||
STATIC_CHECK(sf::degrees(0) > sf::degrees(-0.1f));
|
||||
}
|
||||
|
||||
SUBCASE("operator>")
|
||||
SECTION("operator<=")
|
||||
{
|
||||
CHECK(sf::radians(0.1f) > sf::degrees(0));
|
||||
CHECK(sf::degrees(0.1f) > sf::radians(0));
|
||||
CHECK(sf::radians(0) > sf::radians(-0.1f));
|
||||
CHECK(sf::degrees(0) > sf::degrees(-0.1f));
|
||||
STATIC_CHECK(sf::radians(0) <= sf::degrees(0.1f));
|
||||
STATIC_CHECK(sf::degrees(0) <= sf::radians(0.1f));
|
||||
STATIC_CHECK(sf::radians(-0.1f) <= sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(-0.1f) <= sf::degrees(0));
|
||||
|
||||
STATIC_CHECK(sf::Angle() <= sf::Angle());
|
||||
STATIC_CHECK(sf::Angle() <= sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::Angle() <= sf::degrees(0));
|
||||
STATIC_CHECK(sf::Angle() <= sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(0) <= sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(15) <= sf::degrees(15));
|
||||
STATIC_CHECK(sf::radians(1) <= sf::radians(1));
|
||||
STATIC_CHECK(sf::degrees(360) <= sf::degrees(360));
|
||||
STATIC_CHECK(sf::degrees(720) <= sf::degrees(720));
|
||||
}
|
||||
|
||||
SUBCASE("operator<=")
|
||||
SECTION("operator>=")
|
||||
{
|
||||
CHECK(sf::radians(0) <= sf::degrees(0.1f));
|
||||
CHECK(sf::degrees(0) <= sf::radians(0.1f));
|
||||
CHECK(sf::radians(-0.1f) <= sf::radians(0));
|
||||
CHECK(sf::degrees(-0.1f) <= sf::degrees(0));
|
||||
STATIC_CHECK(sf::radians(0.1f) >= sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(0.1f) >= sf::radians(0));
|
||||
STATIC_CHECK(sf::radians(0) >= sf::radians(-0.1f));
|
||||
STATIC_CHECK(sf::degrees(0) >= sf::degrees(-0.1f));
|
||||
|
||||
CHECK(sf::Angle() <= sf::Angle());
|
||||
CHECK(sf::Angle() <= sf::Angle::Zero);
|
||||
CHECK(sf::Angle() <= sf::degrees(0));
|
||||
CHECK(sf::Angle() <= sf::radians(0));
|
||||
CHECK(sf::degrees(0) <= sf::radians(0));
|
||||
CHECK(sf::degrees(15) <= sf::degrees(15));
|
||||
CHECK(sf::radians(1) <= sf::radians(1));
|
||||
CHECK(sf::degrees(360) <= sf::degrees(360));
|
||||
CHECK(sf::degrees(720) <= sf::degrees(720));
|
||||
STATIC_CHECK(sf::Angle() >= sf::Angle());
|
||||
STATIC_CHECK(sf::Angle() >= sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::Angle() >= sf::degrees(0));
|
||||
STATIC_CHECK(sf::Angle() >= sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(0) >= sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(15) >= sf::degrees(15));
|
||||
STATIC_CHECK(sf::radians(1) >= sf::radians(1));
|
||||
STATIC_CHECK(sf::degrees(360) >= sf::degrees(360));
|
||||
STATIC_CHECK(sf::degrees(720) >= sf::degrees(720));
|
||||
}
|
||||
|
||||
SUBCASE("operator>=")
|
||||
SECTION("Unary operator-")
|
||||
{
|
||||
CHECK(sf::radians(0.1f) >= sf::degrees(0));
|
||||
CHECK(sf::degrees(0.1f) >= sf::radians(0));
|
||||
CHECK(sf::radians(0) >= sf::radians(-0.1f));
|
||||
CHECK(sf::degrees(0) >= sf::degrees(-0.1f));
|
||||
|
||||
CHECK(sf::Angle() >= sf::Angle());
|
||||
CHECK(sf::Angle() >= sf::Angle::Zero);
|
||||
CHECK(sf::Angle() >= sf::degrees(0));
|
||||
CHECK(sf::Angle() >= sf::radians(0));
|
||||
CHECK(sf::degrees(0) >= sf::radians(0));
|
||||
CHECK(sf::degrees(15) >= sf::degrees(15));
|
||||
CHECK(sf::radians(1) >= sf::radians(1));
|
||||
CHECK(sf::degrees(360) >= sf::degrees(360));
|
||||
CHECK(sf::degrees(720) >= sf::degrees(720));
|
||||
STATIC_CHECK(-sf::Angle() == sf::Angle());
|
||||
STATIC_CHECK(-sf::radians(-1) == sf::radians(1));
|
||||
STATIC_CHECK(-sf::degrees(15) == sf::degrees(-15));
|
||||
STATIC_CHECK(-sf::radians(1) == sf::radians(-1));
|
||||
}
|
||||
|
||||
SUBCASE("Unary operator-")
|
||||
SECTION("operator+")
|
||||
{
|
||||
CHECK(-sf::Angle() == sf::Angle());
|
||||
CHECK(-sf::radians(-1) == sf::radians(1));
|
||||
CHECK(-sf::degrees(15) == sf::degrees(-15));
|
||||
CHECK(-sf::radians(1) == sf::radians(-1));
|
||||
STATIC_CHECK(sf::Angle() + sf::Angle() == sf::Angle());
|
||||
STATIC_CHECK(sf::Angle::Zero + sf::radians(0.5f) == sf::radians(0.5f));
|
||||
STATIC_CHECK(sf::radians(6) + sf::radians(0.5f) == sf::radians(6.5f));
|
||||
STATIC_CHECK(sf::radians(10) + sf::radians(0.5f) == sf::radians(10.5f));
|
||||
STATIC_CHECK(sf::degrees(360) + sf::degrees(360) == sf::degrees(720));
|
||||
}
|
||||
|
||||
SUBCASE("operator+")
|
||||
{
|
||||
CHECK(sf::Angle() + sf::Angle() == sf::Angle());
|
||||
CHECK(sf::Angle::Zero + sf::radians(0.5f) == sf::radians(0.5f));
|
||||
CHECK(sf::radians(6) + sf::radians(0.5f) == sf::radians(6.5f));
|
||||
CHECK(sf::radians(10) + sf::radians(0.5f) == sf::radians(10.5f));
|
||||
CHECK(sf::degrees(360) + sf::degrees(360) == sf::degrees(720));
|
||||
}
|
||||
|
||||
SUBCASE("operator+=")
|
||||
SECTION("operator+=")
|
||||
{
|
||||
sf::Angle angle = sf::degrees(-15);
|
||||
angle += sf::degrees(15);
|
||||
@ -190,15 +190,15 @@ TEST_CASE("[System] sf::Angle")
|
||||
CHECK(angle == sf::radians(10));
|
||||
}
|
||||
|
||||
SUBCASE("operator-")
|
||||
SECTION("operator-")
|
||||
{
|
||||
CHECK(sf::Angle() - sf::Angle() == sf::Angle());
|
||||
CHECK(sf::radians(1) - sf::radians(0.5f) == sf::radians(0.5f));
|
||||
CHECK(sf::Angle::Zero - sf::radians(0.5f) == sf::radians(-0.5f));
|
||||
CHECK(sf::degrees(900) - sf::degrees(1) == sf::degrees(899));
|
||||
STATIC_CHECK(sf::Angle() - sf::Angle() == sf::Angle());
|
||||
STATIC_CHECK(sf::radians(1) - sf::radians(0.5f) == sf::radians(0.5f));
|
||||
STATIC_CHECK(sf::Angle::Zero - sf::radians(0.5f) == sf::radians(-0.5f));
|
||||
STATIC_CHECK(sf::degrees(900) - sf::degrees(1) == sf::degrees(899));
|
||||
}
|
||||
|
||||
SUBCASE("operator-=")
|
||||
SECTION("operator-=")
|
||||
{
|
||||
sf::Angle angle = sf::degrees(15);
|
||||
angle -= sf::degrees(15);
|
||||
@ -207,101 +207,89 @@ TEST_CASE("[System] sf::Angle")
|
||||
CHECK(angle == sf::radians(-10));
|
||||
}
|
||||
|
||||
SUBCASE("operator*")
|
||||
SECTION("operator*")
|
||||
{
|
||||
CHECK(sf::radians(0) * 10 == sf::Angle::Zero);
|
||||
CHECK(sf::degrees(10) * 2.5f == sf::degrees(25));
|
||||
CHECK(sf::degrees(100) * 10.0f == sf::degrees(1000));
|
||||
STATIC_CHECK(sf::radians(0) * 10 == sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::degrees(10) * 2.5f == sf::degrees(25));
|
||||
STATIC_CHECK(sf::degrees(100) * 10.0f == sf::degrees(1000));
|
||||
|
||||
CHECK(10 * sf::radians(0) == sf::Angle::Zero);
|
||||
CHECK(2.5f * sf::degrees(10) == sf::degrees(25));
|
||||
CHECK(10.0f * sf::degrees(100) == sf::degrees(1000));
|
||||
STATIC_CHECK(10 * sf::radians(0) == sf::Angle::Zero);
|
||||
STATIC_CHECK(2.5f * sf::degrees(10) == sf::degrees(25));
|
||||
STATIC_CHECK(10.0f * sf::degrees(100) == sf::degrees(1000));
|
||||
}
|
||||
|
||||
SUBCASE("operator*=")
|
||||
SECTION("operator*=")
|
||||
{
|
||||
sf::Angle angle = sf::degrees(1);
|
||||
angle *= 10;
|
||||
CHECK(angle == sf::degrees(10));
|
||||
}
|
||||
|
||||
SUBCASE("operator/")
|
||||
SECTION("operator/")
|
||||
{
|
||||
CHECK(sf::Angle::Zero / 10 == sf::Angle::Zero);
|
||||
CHECK(sf::degrees(10) / 2.5f == sf::degrees(4));
|
||||
CHECK(sf::radians(12) / 3 == sf::radians(4));
|
||||
STATIC_CHECK(sf::Angle::Zero / 10 == sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::degrees(10) / 2.5f == sf::degrees(4));
|
||||
STATIC_CHECK(sf::radians(12) / 3 == sf::radians(4));
|
||||
|
||||
CHECK(sf::Angle::Zero / sf::degrees(1) == 0.f);
|
||||
CHECK(sf::degrees(10) / sf::degrees(10) == 1.f);
|
||||
STATIC_CHECK(sf::Angle::Zero / sf::degrees(1) == 0.f);
|
||||
STATIC_CHECK(sf::degrees(10) / sf::degrees(10) == 1.f);
|
||||
CHECK(sf::radians(10) / sf::radians(2) == Approx(5.f));
|
||||
}
|
||||
|
||||
SUBCASE("operator/=")
|
||||
SECTION("operator/=")
|
||||
{
|
||||
sf::Angle angle = sf::degrees(60);
|
||||
angle /= 5;
|
||||
CHECK(angle == sf::degrees(12));
|
||||
}
|
||||
|
||||
SUBCASE("operator%")
|
||||
SECTION("operator%")
|
||||
{
|
||||
CHECK(sf::Angle::Zero % sf::radians(0.5f) == sf::Angle::Zero);
|
||||
CHECK(sf::radians(10) % sf::radians(1) == sf::radians(0));
|
||||
CHECK(sf::degrees(90) % sf::degrees(30) == sf::degrees(0));
|
||||
CHECK(sf::degrees(90) % sf::degrees(40) == sf::degrees(10));
|
||||
CHECK(sf::degrees(-90) % sf::degrees(30) == sf::degrees(0));
|
||||
CHECK(sf::degrees(-90) % sf::degrees(40) == sf::degrees(30));
|
||||
STATIC_CHECK(sf::Angle::Zero % sf::radians(0.5f) == sf::Angle::Zero);
|
||||
STATIC_CHECK(sf::radians(10) % sf::radians(1) == sf::radians(0));
|
||||
STATIC_CHECK(sf::degrees(90) % sf::degrees(30) == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(90) % sf::degrees(40) == sf::degrees(10));
|
||||
STATIC_CHECK(sf::degrees(-90) % sf::degrees(30) == sf::degrees(0));
|
||||
STATIC_CHECK(sf::degrees(-90) % sf::degrees(40) == sf::degrees(30));
|
||||
}
|
||||
|
||||
SUBCASE("operator%=")
|
||||
SECTION("operator%=")
|
||||
{
|
||||
sf::Angle angle = sf::degrees(59);
|
||||
angle %= sf::degrees(10);
|
||||
CHECK(angle == sf::degrees(9));
|
||||
}
|
||||
|
||||
SUBCASE("operator _deg")
|
||||
SECTION("operator _deg")
|
||||
{
|
||||
using namespace sf::Literals;
|
||||
CHECK(0.0_deg == sf::Angle::Zero);
|
||||
CHECK(1.0_deg == sf::degrees(1));
|
||||
CHECK(-1.0_deg == sf::degrees(-1));
|
||||
CHECK(3.14_deg == sf::degrees(3.14f));
|
||||
CHECK(-3.14_deg == sf::degrees(-3.14f));
|
||||
STATIC_CHECK(0.0_deg == sf::Angle::Zero);
|
||||
STATIC_CHECK(1.0_deg == sf::degrees(1));
|
||||
STATIC_CHECK(-1.0_deg == sf::degrees(-1));
|
||||
STATIC_CHECK(3.14_deg == sf::degrees(3.14f));
|
||||
STATIC_CHECK(-3.14_deg == sf::degrees(-3.14f));
|
||||
|
||||
CHECK(0_deg == sf::Angle::Zero);
|
||||
CHECK(1_deg == sf::degrees(1));
|
||||
CHECK(-1_deg == sf::degrees(-1));
|
||||
CHECK(100_deg == sf::degrees(100));
|
||||
CHECK(-100_deg == sf::degrees(-100));
|
||||
STATIC_CHECK(0_deg == sf::Angle::Zero);
|
||||
STATIC_CHECK(1_deg == sf::degrees(1));
|
||||
STATIC_CHECK(-1_deg == sf::degrees(-1));
|
||||
STATIC_CHECK(100_deg == sf::degrees(100));
|
||||
STATIC_CHECK(-100_deg == sf::degrees(-100));
|
||||
}
|
||||
|
||||
SUBCASE("operator _rad")
|
||||
SECTION("operator _rad")
|
||||
{
|
||||
using namespace sf::Literals;
|
||||
CHECK(0.0_rad == sf::Angle::Zero);
|
||||
CHECK(1.0_rad == sf::radians(1));
|
||||
CHECK(-1.0_rad == sf::radians(-1));
|
||||
CHECK(3.14_rad == sf::radians(3.14f));
|
||||
CHECK(-3.14_rad == sf::radians(-3.14f));
|
||||
STATIC_CHECK(0.0_rad == sf::Angle::Zero);
|
||||
STATIC_CHECK(1.0_rad == sf::radians(1));
|
||||
STATIC_CHECK(-1.0_rad == sf::radians(-1));
|
||||
STATIC_CHECK(3.14_rad == sf::radians(3.14f));
|
||||
STATIC_CHECK(-3.14_rad == sf::radians(-3.14f));
|
||||
|
||||
CHECK(0_rad == sf::Angle::Zero);
|
||||
CHECK(1_rad == sf::radians(1));
|
||||
CHECK(-1_rad == sf::radians(-1));
|
||||
CHECK(100_rad == sf::radians(100));
|
||||
CHECK(-100_rad == sf::radians(-100));
|
||||
STATIC_CHECK(0_rad == sf::Angle::Zero);
|
||||
STATIC_CHECK(1_rad == sf::radians(1));
|
||||
STATIC_CHECK(-1_rad == sf::radians(-1));
|
||||
STATIC_CHECK(100_rad == sf::radians(100));
|
||||
STATIC_CHECK(-100_rad == sf::radians(-100));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Constexpr support")
|
||||
{
|
||||
constexpr auto result = []
|
||||
{
|
||||
sf::Angle angle = sf::degrees(9);
|
||||
angle %= sf::degrees(2);
|
||||
return angle;
|
||||
}();
|
||||
|
||||
static_assert(result == sf::degrees(1));
|
||||
}
|
||||
}
|
||||
|
@ -1,20 +1,23 @@
|
||||
#include <SFML/System/Clock.hpp>
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Clock>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Clock>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Clock>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Clock>);
|
||||
|
||||
TEST_CASE("[System] sf::Clock")
|
||||
{
|
||||
SUBCASE("getElapsedTime()")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Clock>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Clock>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Clock>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Clock>);
|
||||
}
|
||||
|
||||
SECTION("getElapsedTime()")
|
||||
{
|
||||
const sf::Clock clock;
|
||||
CHECK(clock.getElapsedTime() >= sf::microseconds(0));
|
||||
@ -23,7 +26,7 @@ TEST_CASE("[System] sf::Clock")
|
||||
CHECK(clock.getElapsedTime() > elapsed);
|
||||
}
|
||||
|
||||
SUBCASE("restart()")
|
||||
SECTION("restart()")
|
||||
{
|
||||
sf::Clock clock;
|
||||
CHECK(clock.restart() >= sf::microseconds(0));
|
||||
|
@ -1,14 +1,14 @@
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
TEST_CASE("[System] SFML/Config.hpp")
|
||||
{
|
||||
SUBCASE("Version macros")
|
||||
SECTION("Version macros")
|
||||
{
|
||||
CHECK(SFML_VERSION_MAJOR == EXPECTED_SFML_VERSION_MAJOR);
|
||||
CHECK(SFML_VERSION_MINOR == EXPECTED_SFML_VERSION_MINOR);
|
||||
CHECK(SFML_VERSION_PATCH == EXPECTED_SFML_VERSION_PATCH);
|
||||
CHECK(SFML_VERSION_IS_RELEASE == EXPECTED_SFML_VERSION_IS_RELEASE);
|
||||
STATIC_CHECK(SFML_VERSION_MAJOR == EXPECTED_SFML_VERSION_MAJOR);
|
||||
STATIC_CHECK(SFML_VERSION_MINOR == EXPECTED_SFML_VERSION_MINOR);
|
||||
STATIC_CHECK(SFML_VERSION_PATCH == EXPECTED_SFML_VERSION_PATCH);
|
||||
STATIC_CHECK(SFML_VERSION_IS_RELEASE == EXPECTED_SFML_VERSION_IS_RELEASE);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
#include <SFML/System/Err.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
TEST_CASE("[System] sf::err")
|
||||
{
|
||||
SUBCASE("Overflow default buffer")
|
||||
SECTION("Overflow default buffer")
|
||||
{
|
||||
// No assertion macros in this subcase since nothing about this can be directly observed.
|
||||
// No assertion macros in this section since nothing about this can be directly observed.
|
||||
// Intention is to ensure DefaultErrStreamBuf::overflow gets called.
|
||||
sf::err() << "SFML is a simple, fast, cross-platform and object-oriented multimedia API."
|
||||
"It provides access to windowing, graphics, audio and network."
|
||||
"It is written in C++, and has bindings for various languages such as C, .Net, Ruby, Python.";
|
||||
}
|
||||
|
||||
SUBCASE("Redirect buffer to observe contents")
|
||||
SECTION("Redirect buffer to observe contents")
|
||||
{
|
||||
sf::err() << "We'll never be able to observe this" << std::endl; // Ensure buffer is flushed
|
||||
auto* const defaultStreamBuffer = sf::err().rdbuf();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <SFML/System/FileInputStream.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
@ -10,11 +10,6 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
static_assert(!std::is_copy_constructible_v<sf::FileInputStream>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::FileInputStream>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::FileInputStream>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::FileInputStream>);
|
||||
|
||||
namespace
|
||||
{
|
||||
std::string getTemporaryFilePath()
|
||||
@ -70,7 +65,15 @@ public:
|
||||
|
||||
TEST_CASE("[System] sf::FileInputStream")
|
||||
{
|
||||
SUBCASE("Empty stream")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::FileInputStream>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::FileInputStream>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::FileInputStream>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::FileInputStream>);
|
||||
}
|
||||
|
||||
SECTION("Empty stream")
|
||||
{
|
||||
sf::FileInputStream fis;
|
||||
|
||||
@ -79,7 +82,7 @@ TEST_CASE("[System] sf::FileInputStream")
|
||||
CHECK(fis.tell() == -1);
|
||||
}
|
||||
|
||||
SUBCASE("Temporary file stream")
|
||||
SECTION("Temporary file stream")
|
||||
{
|
||||
const std::string fileContents = "hello world";
|
||||
|
||||
@ -93,7 +96,7 @@ TEST_CASE("[System] sf::FileInputStream")
|
||||
CHECK(fis.read(buffer, 5) == 5);
|
||||
CHECK(std::string_view(buffer, 5) == std::string_view(fileContents.c_str(), 5));
|
||||
|
||||
SUBCASE("Move semantics")
|
||||
SECTION("Move semantics")
|
||||
{
|
||||
sf::FileInputStream fis2 = std::move(fis);
|
||||
|
||||
|
@ -1,13 +1,21 @@
|
||||
#include <SFML/System/MemoryInputStream.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <ostream>
|
||||
#include <string_view>
|
||||
|
||||
TEST_CASE("[System] sf::MemoryInputStream")
|
||||
{
|
||||
SUBCASE("Empty stream")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::MemoryInputStream>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::MemoryInputStream>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::MemoryInputStream>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::MemoryInputStream>);
|
||||
}
|
||||
|
||||
SECTION("Empty stream")
|
||||
{
|
||||
sf::MemoryInputStream mis;
|
||||
|
||||
@ -17,7 +25,7 @@ TEST_CASE("[System] sf::MemoryInputStream")
|
||||
CHECK(mis.getSize() == -1);
|
||||
}
|
||||
|
||||
SUBCASE("Open memory stream")
|
||||
SECTION("Open memory stream")
|
||||
{
|
||||
using namespace std::literals::string_view_literals;
|
||||
constexpr auto memoryContents = "hello world"sv;
|
||||
|
@ -3,26 +3,12 @@
|
||||
// Other 1st party headers
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Specialize StringMaker for std::chrono::duration specializations
|
||||
// https://github.com/doctest/doctest/blob/master/doc/markdown/stringification.md#docteststringmakert-specialisation
|
||||
namespace doctest
|
||||
{
|
||||
template <typename Rep, typename Period>
|
||||
struct StringMaker<std::chrono::duration<Rep, Period>>
|
||||
{
|
||||
static String convert(const std::chrono::duration<Rep, Period>& duration)
|
||||
{
|
||||
return toString(std::chrono::nanoseconds(duration).count()) + "ns";
|
||||
}
|
||||
};
|
||||
} // namespace doctest
|
||||
|
||||
#define CHECK_SLEEP_DURATION(duration) \
|
||||
do \
|
||||
{ \
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <SFML/System/String.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <GraphicsUtil.hpp>
|
||||
#include <array>
|
||||
@ -10,11 +10,6 @@
|
||||
|
||||
#include <cassert>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::String>);
|
||||
static_assert(std::is_copy_assignable_v<sf::String>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::String>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::String>);
|
||||
|
||||
namespace
|
||||
{
|
||||
// Return either argument depending on whether wchar_t is 16 or 32 bits
|
||||
@ -42,58 +37,57 @@ auto toHex(const CharT character)
|
||||
|
||||
// Specialize StringMaker for alternative std::basic_string<T> specializations
|
||||
// std::string's string conversion cannot be specialized but all other string types get special treatment
|
||||
// https://github.com/doctest/doctest/blob/master/doc/markdown/stringification.md#docteststringmakert-specialisation
|
||||
namespace doctest
|
||||
// https://github.com/catchorg/Catch2/blob/devel/docs/tostring.md#catchstringmaker-specialisation
|
||||
namespace Catch
|
||||
{
|
||||
template <typename CharT>
|
||||
struct StringMaker<std::basic_string<CharT>>
|
||||
template <>
|
||||
struct StringMaker<std::basic_string<std::uint8_t>>
|
||||
{
|
||||
static String convert(const std::basic_string<CharT>& string)
|
||||
static std::string convert(const std::basic_string<std::uint8_t>& string)
|
||||
{
|
||||
doctest::String output;
|
||||
std::ostringstream output;
|
||||
for (const auto character : string)
|
||||
{
|
||||
if (character >= 32 && character < 127)
|
||||
output += std::string(1, static_cast<char>(character)).c_str();
|
||||
output << std::string(1, static_cast<char>(character));
|
||||
else
|
||||
output += toHex(character).c_str();
|
||||
output << toHex(character);
|
||||
}
|
||||
return output;
|
||||
return output.str();
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct StringMaker<char32_t>
|
||||
{
|
||||
static String convert(const char32_t character)
|
||||
{
|
||||
return toHex(character).c_str();
|
||||
}
|
||||
};
|
||||
} // namespace doctest
|
||||
} // namespace Catch
|
||||
|
||||
TEST_CASE("[System] sf::String")
|
||||
{
|
||||
using namespace std::string_literals;
|
||||
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::String>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::String>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::String>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::String>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::String string;
|
||||
CHECK(std::string(string) == ""s);
|
||||
CHECK(std::wstring(string) == L""s);
|
||||
CHECK(string.toAnsiString() == ""s);
|
||||
CHECK(string.toWideString() == L""s);
|
||||
CHECK(string.toUtf8() == std::basic_string<std::uint8_t>());
|
||||
CHECK(string.toUtf16() == u""s);
|
||||
CHECK(string.toUtf32() == U""s);
|
||||
CHECK(string.toUtf8().empty());
|
||||
CHECK(string.toUtf16().empty());
|
||||
CHECK(string.toUtf32().empty());
|
||||
CHECK(string.getSize() == 0);
|
||||
CHECK(string.isEmpty());
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("ANSI character constructor")
|
||||
SECTION("ANSI character constructor")
|
||||
{
|
||||
const sf::String string = 'a';
|
||||
CHECK(std::string(string) == "a"s);
|
||||
@ -108,7 +102,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("ANSI C string constructor")
|
||||
SECTION("ANSI C string constructor")
|
||||
{
|
||||
const sf::String string = "def";
|
||||
CHECK(std::string(string) == "def"s);
|
||||
@ -123,7 +117,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("ANSI string constructor")
|
||||
SECTION("ANSI string constructor")
|
||||
{
|
||||
const sf::String string = "ghi"s;
|
||||
CHECK(std::string(string) == "ghi"s);
|
||||
@ -138,7 +132,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Wide character constructor")
|
||||
SECTION("Wide character constructor")
|
||||
{
|
||||
const sf::String string = L'\xFA';
|
||||
CHECK(std::string(string) == select("\xFA"s, "\0"s));
|
||||
@ -153,7 +147,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Wide C string constructor")
|
||||
SECTION("Wide C string constructor")
|
||||
{
|
||||
const sf::String string = L"j\xFAl";
|
||||
CHECK(std::string(string) == select("j\xFAl"s, "j\0l"s));
|
||||
@ -168,7 +162,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Wide string constructor")
|
||||
SECTION("Wide string constructor")
|
||||
{
|
||||
const sf::String string = L"mno\xFA"s;
|
||||
CHECK(std::string(string) == select("mno\xFA"s, "mno\0"s));
|
||||
@ -183,7 +177,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("UTF-32 character constructor")
|
||||
SECTION("UTF-32 character constructor")
|
||||
{
|
||||
const sf::String string = U'\U0010AFAF';
|
||||
CHECK(std::string(string) == "\0"s);
|
||||
@ -198,7 +192,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("UTF-32 C string constructor")
|
||||
SECTION("UTF-32 C string constructor")
|
||||
{
|
||||
const sf::String string = U"\U0010ABCDrs";
|
||||
CHECK(std::string(string) == "\0rs"s);
|
||||
@ -213,7 +207,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("UTF-32 string constructor")
|
||||
SECTION("UTF-32 string constructor")
|
||||
{
|
||||
const sf::String string = U"tuv\U00104321"s;
|
||||
CHECK(std::string(string) == "tuv\0"s);
|
||||
@ -229,9 +223,9 @@ TEST_CASE("[System] sf::String")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("fromUtf8()")
|
||||
SECTION("fromUtf8()")
|
||||
{
|
||||
SUBCASE("Nominal")
|
||||
SECTION("Nominal")
|
||||
{
|
||||
constexpr std::array<std::uint8_t, 4> characters{'w', 'x', 'y', 'z'};
|
||||
const sf::String string = sf::String::fromUtf8(characters.begin(), characters.end());
|
||||
@ -247,7 +241,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("Insufficient input")
|
||||
SECTION("Insufficient input")
|
||||
{
|
||||
constexpr std::array<std::uint8_t, 1> characters{251};
|
||||
const sf::String string = sf::String::fromUtf8(characters.begin(), characters.end());
|
||||
@ -257,7 +251,7 @@ TEST_CASE("[System] sf::String")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("fromUtf16()")
|
||||
SECTION("fromUtf16()")
|
||||
{
|
||||
constexpr std::array<std::uint16_t, 4> characters{0xF1, 'x', 'y', 'z'};
|
||||
const sf::String string = sf::String::fromUtf16(characters.begin(), characters.end());
|
||||
@ -273,7 +267,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("fromUtf32()")
|
||||
SECTION("fromUtf32()")
|
||||
{
|
||||
constexpr std::array<std::uint32_t, 4> characters{'w', 0x104321, 'y', 'z'};
|
||||
const sf::String string = sf::String::fromUtf32(characters.begin(), characters.end());
|
||||
@ -289,7 +283,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getData() != nullptr);
|
||||
}
|
||||
|
||||
SUBCASE("clear()")
|
||||
SECTION("clear()")
|
||||
{
|
||||
sf::String string("you'll never guess what happens when you call clear()");
|
||||
string.clear();
|
||||
@ -297,7 +291,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getSize() == 0);
|
||||
}
|
||||
|
||||
SUBCASE("erase()")
|
||||
SECTION("erase()")
|
||||
{
|
||||
sf::String string("what if i want a shorter string?");
|
||||
string.erase(0, 8);
|
||||
@ -306,7 +300,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getSize() == 23);
|
||||
}
|
||||
|
||||
SUBCASE("insert()")
|
||||
SECTION("insert()")
|
||||
{
|
||||
sf::String string("please insert text");
|
||||
string.insert(7, "don't ");
|
||||
@ -314,7 +308,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.getSize() == 24);
|
||||
}
|
||||
|
||||
SUBCASE("find()")
|
||||
SECTION("find()")
|
||||
{
|
||||
const sf::String string("a little bit of this and a little bit of that");
|
||||
CHECK(string.find("a little bit") == 0);
|
||||
@ -323,7 +317,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string.find("no way you find this") == sf::String::InvalidPos);
|
||||
}
|
||||
|
||||
SUBCASE("replace()")
|
||||
SECTION("replace()")
|
||||
{
|
||||
sf::String string("sfml is the worst");
|
||||
string.replace(12, 5, "best!");
|
||||
@ -332,7 +326,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string == "sfml is THE best!");
|
||||
}
|
||||
|
||||
SUBCASE("substring()")
|
||||
SECTION("substring()")
|
||||
{
|
||||
const sf::String string("let's get some substrings");
|
||||
CHECK(string.substring(0) == "let's get some substrings");
|
||||
@ -342,7 +336,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK_THROWS_AS((void)string.substring(420, 69), std::out_of_range);
|
||||
}
|
||||
|
||||
SUBCASE("begin() and end() const")
|
||||
SECTION("begin() and end() const")
|
||||
{
|
||||
const sf::String string("let's test the const iterators");
|
||||
CHECK(*string.begin() == 'l');
|
||||
@ -351,7 +345,7 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(character != 0);
|
||||
}
|
||||
|
||||
SUBCASE("begin() and end()")
|
||||
SECTION("begin() and end()")
|
||||
{
|
||||
sf::String string("let's test the iterators");
|
||||
CHECK(*string.begin() == 'l');
|
||||
@ -361,23 +355,23 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string == "xxxxxxxxxxxxxxxxxxxxxxxx");
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("Operators")
|
||||
{
|
||||
SUBCASE("operator+=")
|
||||
SECTION("operator+=")
|
||||
{
|
||||
sf::String string;
|
||||
string += sf::String("xyz");
|
||||
CHECK(string.toAnsiString() == "xyz"s);
|
||||
}
|
||||
|
||||
SUBCASE("operator[] const")
|
||||
SECTION("operator[] const")
|
||||
{
|
||||
const sf::String string("the quick brown fox");
|
||||
CHECK(string[0] == 't');
|
||||
CHECK(string[10] == 'b');
|
||||
}
|
||||
|
||||
SUBCASE("operator[]")
|
||||
SECTION("operator[]")
|
||||
{
|
||||
sf::String string("the quick brown fox");
|
||||
CHECK(string[0] == 't');
|
||||
@ -385,43 +379,43 @@ TEST_CASE("[System] sf::String")
|
||||
CHECK(string[1] == 'x');
|
||||
}
|
||||
|
||||
SUBCASE("operator==")
|
||||
SECTION("operator==")
|
||||
{
|
||||
CHECK(sf::String() == sf::String());
|
||||
CHECK_FALSE(sf::String() == sf::String(' '));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
CHECK(sf::String() != sf::String(' '));
|
||||
CHECK_FALSE(sf::String() != sf::String());
|
||||
}
|
||||
|
||||
SUBCASE("operator<")
|
||||
SECTION("operator<")
|
||||
{
|
||||
CHECK(sf::String('a') < sf::String('b'));
|
||||
CHECK_FALSE(sf::String() < sf::String());
|
||||
}
|
||||
|
||||
SUBCASE("operator>")
|
||||
SECTION("operator>")
|
||||
{
|
||||
CHECK(sf::String('b') > sf::String('a'));
|
||||
CHECK_FALSE(sf::String() > sf::String());
|
||||
}
|
||||
|
||||
SUBCASE("operator<=")
|
||||
SECTION("operator<=")
|
||||
{
|
||||
CHECK(sf::String() <= sf::String());
|
||||
CHECK(sf::String('a') <= sf::String('b'));
|
||||
}
|
||||
|
||||
SUBCASE("operator>=")
|
||||
SECTION("operator>=")
|
||||
{
|
||||
CHECK(sf::String() >= sf::String());
|
||||
CHECK(sf::String('b') >= sf::String('a'));
|
||||
}
|
||||
|
||||
SUBCASE("operator+")
|
||||
SECTION("operator+")
|
||||
{
|
||||
CHECK(sf::String() + sf::String() == sf::String());
|
||||
CHECK(sf::String("abc") + sf::String("def") == sf::String("abcdef"));
|
||||
|
@ -1,257 +1,246 @@
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Time>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Time>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Time>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Time>);
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Specialize StringMaker for std::chrono::duration specializations
|
||||
// https://github.com/doctest/doctest/blob/master/doc/markdown/stringification.md#docteststringmakert-specialisation
|
||||
namespace doctest
|
||||
{
|
||||
template <typename Rep, typename Period>
|
||||
struct StringMaker<std::chrono::duration<Rep, Period>>
|
||||
{
|
||||
static String convert(const std::chrono::duration<Rep, Period>& duration)
|
||||
{
|
||||
return toString(std::chrono::microseconds(duration).count()) + "us";
|
||||
}
|
||||
};
|
||||
} // namespace doctest
|
||||
|
||||
TEST_CASE("[System] sf::Time")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::Time time;
|
||||
CHECK(time.asSeconds() == 0.0f);
|
||||
CHECK(time.asMilliseconds() == 0);
|
||||
CHECK(time.asMicroseconds() == 0);
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Time>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Time>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Time>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Time>);
|
||||
}
|
||||
|
||||
SUBCASE("Construct from seconds")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Time time = sf::seconds(123);
|
||||
CHECK(time.asSeconds() == 123.0f);
|
||||
CHECK(time.asMilliseconds() == 123'000);
|
||||
CHECK(time.asMicroseconds() == 123'000'000);
|
||||
|
||||
CHECK(sf::seconds(1'000.0f).asMicroseconds() == 1'000'000'000);
|
||||
CHECK(sf::seconds(0.0000009f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(0.0000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(0.00000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(0.000000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-0.000000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-0.00000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-0.0000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-0.0000009f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-1'000.0f).asMicroseconds() == -1'000'000'000);
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
constexpr sf::Time time;
|
||||
STATIC_CHECK(time.asSeconds() == 0.0f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 0);
|
||||
STATIC_CHECK(time.asMicroseconds() == 0);
|
||||
}
|
||||
|
||||
SUBCASE("Construct from milliseconds")
|
||||
SECTION("Construct from seconds")
|
||||
{
|
||||
const sf::Time time = sf::milliseconds(42);
|
||||
CHECK(time.asSeconds() == 0.042f);
|
||||
CHECK(time.asMilliseconds() == 42);
|
||||
CHECK(time.asMicroseconds() == 42'000);
|
||||
constexpr sf::Time time = sf::seconds(123);
|
||||
STATIC_CHECK(time.asSeconds() == 123.0f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 123'000);
|
||||
STATIC_CHECK(time.asMicroseconds() == 123'000'000);
|
||||
|
||||
STATIC_CHECK(sf::seconds(1'000.0f).asMicroseconds() == 1'000'000'000);
|
||||
STATIC_CHECK(sf::seconds(0.0000009f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(0.0000001f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(0.00000001f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(0.000000001f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(-0.000000001f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(-0.00000001f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(-0.0000001f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(-0.0000009f).asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::seconds(-1'000.0f).asMicroseconds() == -1'000'000'000);
|
||||
}
|
||||
|
||||
SUBCASE("Construct from microseconds")
|
||||
SECTION("Construct from milliseconds")
|
||||
{
|
||||
const sf::Time time = sf::microseconds(987654);
|
||||
CHECK(time.asSeconds() == 0.987654f);
|
||||
CHECK(time.asMilliseconds() == 987);
|
||||
CHECK(time.asMicroseconds() == 987'654);
|
||||
constexpr sf::Time time = sf::milliseconds(42);
|
||||
STATIC_CHECK(time.asSeconds() == 0.042f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 42);
|
||||
STATIC_CHECK(time.asMicroseconds() == 42'000);
|
||||
}
|
||||
|
||||
SUBCASE("Convert from chrono duration")
|
||||
SECTION("Construct from microseconds")
|
||||
{
|
||||
constexpr sf::Time time = sf::microseconds(987654);
|
||||
STATIC_CHECK(time.asSeconds() == 0.987654f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 987);
|
||||
STATIC_CHECK(time.asMicroseconds() == 987'654);
|
||||
}
|
||||
|
||||
SECTION("Convert from chrono duration")
|
||||
{
|
||||
{
|
||||
const sf::Time time = 3min;
|
||||
CHECK(time.asSeconds() == 180.f);
|
||||
CHECK(time.asMilliseconds() == 180'000);
|
||||
CHECK(time.asMicroseconds() == 180'000'000);
|
||||
constexpr sf::Time time = 3min;
|
||||
STATIC_CHECK(time.asSeconds() == 180.f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 180'000);
|
||||
STATIC_CHECK(time.asMicroseconds() == 180'000'000);
|
||||
}
|
||||
{
|
||||
const sf::Time time = 1s;
|
||||
CHECK(time.asSeconds() == 1.f);
|
||||
CHECK(time.asMilliseconds() == 1'000);
|
||||
CHECK(time.asMicroseconds() == 1'000'000);
|
||||
constexpr sf::Time time = 1s;
|
||||
STATIC_CHECK(time.asSeconds() == 1.f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 1'000);
|
||||
STATIC_CHECK(time.asMicroseconds() == 1'000'000);
|
||||
}
|
||||
{
|
||||
const sf::Time time = 10ms;
|
||||
CHECK(time.asSeconds() == 0.01f);
|
||||
CHECK(time.asMilliseconds() == 10);
|
||||
CHECK(time.asMicroseconds() == 10'000);
|
||||
constexpr sf::Time time = 10ms;
|
||||
STATIC_CHECK(time.asSeconds() == 0.01f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 10);
|
||||
STATIC_CHECK(time.asMicroseconds() == 10'000);
|
||||
}
|
||||
{
|
||||
const sf::Time time = 2048us;
|
||||
CHECK(time.asSeconds() == 0.002048f);
|
||||
CHECK(time.asMilliseconds() == 2);
|
||||
CHECK(time.asMicroseconds() == 2048);
|
||||
constexpr sf::Time time = 2048us;
|
||||
STATIC_CHECK(time.asSeconds() == 0.002048f);
|
||||
STATIC_CHECK(time.asMilliseconds() == 2);
|
||||
STATIC_CHECK(time.asMicroseconds() == 2048);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("toDuration()")
|
||||
SECTION("toDuration()")
|
||||
{
|
||||
CHECK(sf::seconds(0).toDuration() == 0s);
|
||||
CHECK(sf::milliseconds(0).toDuration() == 0ms);
|
||||
CHECK(sf::microseconds(0).toDuration() == 0us);
|
||||
STATIC_CHECK(sf::seconds(0).toDuration() == 0s);
|
||||
STATIC_CHECK(sf::milliseconds(0).toDuration() == 0ms);
|
||||
STATIC_CHECK(sf::microseconds(0).toDuration() == 0us);
|
||||
|
||||
CHECK(sf::seconds(-1).toDuration() == -1s);
|
||||
CHECK(sf::milliseconds(-1).toDuration() == -1ms);
|
||||
CHECK(sf::microseconds(-1).toDuration() == -1us);
|
||||
STATIC_CHECK(sf::seconds(-1).toDuration() == -1s);
|
||||
STATIC_CHECK(sf::milliseconds(-1).toDuration() == -1ms);
|
||||
STATIC_CHECK(sf::microseconds(-1).toDuration() == -1us);
|
||||
|
||||
CHECK(sf::seconds(1).toDuration() == 1s);
|
||||
CHECK(sf::milliseconds(1).toDuration() == 1ms);
|
||||
CHECK(sf::microseconds(1).toDuration() == 1us);
|
||||
STATIC_CHECK(sf::seconds(1).toDuration() == 1s);
|
||||
STATIC_CHECK(sf::milliseconds(1).toDuration() == 1ms);
|
||||
STATIC_CHECK(sf::microseconds(1).toDuration() == 1us);
|
||||
|
||||
CHECK(sf::seconds(-10).toDuration() == -10s);
|
||||
CHECK(sf::milliseconds(-10).toDuration() == -10ms);
|
||||
CHECK(sf::microseconds(-10).toDuration() == -10us);
|
||||
STATIC_CHECK(sf::seconds(-10).toDuration() == -10s);
|
||||
STATIC_CHECK(sf::milliseconds(-10).toDuration() == -10ms);
|
||||
STATIC_CHECK(sf::microseconds(-10).toDuration() == -10us);
|
||||
|
||||
CHECK(sf::seconds(10).toDuration() == 10s);
|
||||
CHECK(sf::milliseconds(10).toDuration() == 10ms);
|
||||
CHECK(sf::microseconds(10).toDuration() == 10us);
|
||||
STATIC_CHECK(sf::seconds(10).toDuration() == 10s);
|
||||
STATIC_CHECK(sf::milliseconds(10).toDuration() == 10ms);
|
||||
STATIC_CHECK(sf::microseconds(10).toDuration() == 10us);
|
||||
|
||||
CHECK(sf::Time(1s).toDuration() == 1s);
|
||||
CHECK(sf::Time(1ms).toDuration() == 1ms);
|
||||
CHECK(sf::Time(1us).toDuration() == 1us);
|
||||
STATIC_CHECK(sf::Time(1s).toDuration() == 1s);
|
||||
STATIC_CHECK(sf::Time(1ms).toDuration() == 1ms);
|
||||
STATIC_CHECK(sf::Time(1us).toDuration() == 1us);
|
||||
}
|
||||
|
||||
SUBCASE("Implicit conversion to duration")
|
||||
SECTION("Implicit conversion to duration")
|
||||
{
|
||||
const auto toDuration = [](const std::chrono::microseconds& duration) { return duration; };
|
||||
CHECK(toDuration(sf::seconds(0)) == 0s);
|
||||
CHECK(toDuration(sf::milliseconds(0)) == 0ms);
|
||||
CHECK(toDuration(sf::microseconds(0)) == 0us);
|
||||
STATIC_CHECK(toDuration(sf::seconds(0)) == 0s);
|
||||
STATIC_CHECK(toDuration(sf::milliseconds(0)) == 0ms);
|
||||
STATIC_CHECK(toDuration(sf::microseconds(0)) == 0us);
|
||||
|
||||
CHECK(toDuration(sf::seconds(-1)) == -1s);
|
||||
CHECK(toDuration(sf::milliseconds(-1)) == -1ms);
|
||||
CHECK(toDuration(sf::microseconds(-1)) == -1us);
|
||||
STATIC_CHECK(toDuration(sf::seconds(-1)) == -1s);
|
||||
STATIC_CHECK(toDuration(sf::milliseconds(-1)) == -1ms);
|
||||
STATIC_CHECK(toDuration(sf::microseconds(-1)) == -1us);
|
||||
|
||||
CHECK(toDuration(sf::seconds(1)) == 1s);
|
||||
CHECK(toDuration(sf::milliseconds(1)) == 1ms);
|
||||
CHECK(toDuration(sf::microseconds(1)) == 1us);
|
||||
STATIC_CHECK(toDuration(sf::seconds(1)) == 1s);
|
||||
STATIC_CHECK(toDuration(sf::milliseconds(1)) == 1ms);
|
||||
STATIC_CHECK(toDuration(sf::microseconds(1)) == 1us);
|
||||
|
||||
CHECK(toDuration(sf::seconds(-10)) == -10s);
|
||||
CHECK(toDuration(sf::milliseconds(-10)) == -10ms);
|
||||
CHECK(toDuration(sf::microseconds(-10)) == -10us);
|
||||
STATIC_CHECK(toDuration(sf::seconds(-10)) == -10s);
|
||||
STATIC_CHECK(toDuration(sf::milliseconds(-10)) == -10ms);
|
||||
STATIC_CHECK(toDuration(sf::microseconds(-10)) == -10us);
|
||||
|
||||
CHECK(toDuration(sf::seconds(10)) == 10s);
|
||||
CHECK(toDuration(sf::milliseconds(10)) == 10ms);
|
||||
CHECK(toDuration(sf::microseconds(10)) == 10us);
|
||||
STATIC_CHECK(toDuration(sf::seconds(10)) == 10s);
|
||||
STATIC_CHECK(toDuration(sf::milliseconds(10)) == 10ms);
|
||||
STATIC_CHECK(toDuration(sf::microseconds(10)) == 10us);
|
||||
|
||||
CHECK(toDuration(sf::Time(1s)) == 1s);
|
||||
CHECK(toDuration(sf::Time(1ms)) == 1ms);
|
||||
CHECK(toDuration(sf::Time(1us)) == 1us);
|
||||
STATIC_CHECK(toDuration(sf::Time(1s)) == 1s);
|
||||
STATIC_CHECK(toDuration(sf::Time(1ms)) == 1ms);
|
||||
STATIC_CHECK(toDuration(sf::Time(1us)) == 1us);
|
||||
}
|
||||
|
||||
SUBCASE("Zero time")
|
||||
SECTION("Zero time")
|
||||
{
|
||||
CHECK(sf::Time::Zero.asSeconds() == 0.0f);
|
||||
CHECK(sf::Time::Zero.asMilliseconds() == 0);
|
||||
CHECK(sf::Time::Zero.asMicroseconds() == 0);
|
||||
STATIC_CHECK(sf::Time::Zero.asSeconds() == 0.0f);
|
||||
STATIC_CHECK(sf::Time::Zero.asMilliseconds() == 0);
|
||||
STATIC_CHECK(sf::Time::Zero.asMicroseconds() == 0);
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("Operators")
|
||||
{
|
||||
SUBCASE("operator==")
|
||||
SECTION("operator==")
|
||||
{
|
||||
CHECK(sf::Time() == sf::Time());
|
||||
CHECK(sf::seconds(1) == sf::seconds(1));
|
||||
CHECK(sf::seconds(10) == sf::milliseconds(10'000));
|
||||
CHECK(sf::milliseconds(450'450) == sf::microseconds(450'450'000));
|
||||
CHECK(sf::seconds(0.5f) == sf::microseconds(500'000));
|
||||
STATIC_CHECK(sf::Time() == sf::Time());
|
||||
STATIC_CHECK(sf::seconds(1) == sf::seconds(1));
|
||||
STATIC_CHECK(sf::seconds(10) == sf::milliseconds(10'000));
|
||||
STATIC_CHECK(sf::milliseconds(450'450) == sf::microseconds(450'450'000));
|
||||
STATIC_CHECK(sf::seconds(0.5f) == sf::microseconds(500'000));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
CHECK(sf::seconds(10.12f) != sf::milliseconds(10'121));
|
||||
CHECK(sf::microseconds(123'456) != sf::milliseconds(123));
|
||||
STATIC_CHECK(sf::seconds(10.12f) != sf::milliseconds(10'121));
|
||||
STATIC_CHECK(sf::microseconds(123'456) != sf::milliseconds(123));
|
||||
}
|
||||
|
||||
SUBCASE("operator<")
|
||||
SECTION("operator<")
|
||||
{
|
||||
CHECK(sf::seconds(54.999f) < sf::seconds(55));
|
||||
CHECK(sf::microseconds(10) < sf::milliseconds(10));
|
||||
CHECK(sf::milliseconds(1'000) < sf::microseconds(1'000'001));
|
||||
STATIC_CHECK(sf::seconds(54.999f) < sf::seconds(55));
|
||||
STATIC_CHECK(sf::microseconds(10) < sf::milliseconds(10));
|
||||
STATIC_CHECK(sf::milliseconds(1'000) < sf::microseconds(1'000'001));
|
||||
}
|
||||
|
||||
SUBCASE("operator>")
|
||||
SECTION("operator>")
|
||||
{
|
||||
CHECK(sf::seconds(55.001f) > sf::seconds(55));
|
||||
CHECK(sf::microseconds(1) > sf::seconds(0.0000001f));
|
||||
CHECK(sf::microseconds(1'000'001) > sf::milliseconds(1'000));
|
||||
STATIC_CHECK(sf::seconds(55.001f) > sf::seconds(55));
|
||||
STATIC_CHECK(sf::microseconds(1) > sf::seconds(0.0000001f));
|
||||
STATIC_CHECK(sf::microseconds(1'000'001) > sf::milliseconds(1'000));
|
||||
}
|
||||
|
||||
SUBCASE("operator<=")
|
||||
SECTION("operator<=")
|
||||
{
|
||||
CHECK(sf::milliseconds(100) <= sf::milliseconds(100));
|
||||
CHECK(sf::seconds(0.0012f) <= sf::microseconds(1'201));
|
||||
STATIC_CHECK(sf::milliseconds(100) <= sf::milliseconds(100));
|
||||
STATIC_CHECK(sf::seconds(0.0012f) <= sf::microseconds(1'201));
|
||||
}
|
||||
|
||||
SUBCASE("operator>=")
|
||||
SECTION("operator>=")
|
||||
{
|
||||
CHECK(sf::milliseconds(100) >= sf::milliseconds(-100));
|
||||
CHECK(sf::microseconds(1'201) >= sf::seconds(0.0012f));
|
||||
STATIC_CHECK(sf::milliseconds(100) >= sf::milliseconds(-100));
|
||||
STATIC_CHECK(sf::microseconds(1'201) >= sf::seconds(0.0012f));
|
||||
}
|
||||
|
||||
SUBCASE("operator-")
|
||||
SECTION("operator-")
|
||||
{
|
||||
CHECK(sf::seconds(-1) == -sf::seconds(1));
|
||||
CHECK(sf::microseconds(1'234) == -sf::microseconds(-1'234));
|
||||
STATIC_CHECK(sf::seconds(-1) == -sf::seconds(1));
|
||||
STATIC_CHECK(sf::microseconds(1'234) == -sf::microseconds(-1'234));
|
||||
}
|
||||
|
||||
SUBCASE("operator+")
|
||||
SECTION("operator+")
|
||||
{
|
||||
CHECK(sf::seconds(1) + sf::seconds(1) == sf::seconds(2));
|
||||
CHECK(sf::milliseconds(400) + sf::microseconds(400) == sf::microseconds(400400));
|
||||
STATIC_CHECK(sf::seconds(1) + sf::seconds(1) == sf::seconds(2));
|
||||
STATIC_CHECK(sf::milliseconds(400) + sf::microseconds(400) == sf::microseconds(400400));
|
||||
}
|
||||
|
||||
SUBCASE("operator+=")
|
||||
SECTION("operator+=")
|
||||
{
|
||||
sf::Time time = sf::seconds(1.5f);
|
||||
time += sf::seconds(1);
|
||||
CHECK(time == sf::seconds(2.5f));
|
||||
}
|
||||
|
||||
SUBCASE("operator-")
|
||||
SECTION("operator-")
|
||||
{
|
||||
CHECK(sf::seconds(1) - sf::seconds(1) == sf::seconds(0));
|
||||
CHECK(sf::milliseconds(400) - sf::microseconds(400) == sf::microseconds(399600));
|
||||
STATIC_CHECK(sf::seconds(1) - sf::seconds(1) == sf::seconds(0));
|
||||
STATIC_CHECK(sf::milliseconds(400) - sf::microseconds(400) == sf::microseconds(399600));
|
||||
}
|
||||
|
||||
SUBCASE("operator-=")
|
||||
SECTION("operator-=")
|
||||
{
|
||||
sf::Time time = sf::seconds(1.5f);
|
||||
time -= sf::seconds(10);
|
||||
CHECK(time == sf::seconds(-8.5f));
|
||||
}
|
||||
|
||||
SUBCASE("operator*")
|
||||
SECTION("operator*")
|
||||
{
|
||||
CHECK(sf::seconds(1) * 2.0f == sf::seconds(2));
|
||||
CHECK(sf::seconds(12) * 0.5f == sf::seconds(6));
|
||||
CHECK(sf::seconds(1) * static_cast<std::int64_t>(2) == sf::seconds(2));
|
||||
CHECK(sf::seconds(42) * static_cast<std::int64_t>(2) == sf::seconds(84));
|
||||
CHECK(2.0f * sf::seconds(1) == sf::seconds(2));
|
||||
CHECK(0.5f * sf::seconds(12) == sf::seconds(6));
|
||||
CHECK(static_cast<std::int64_t>(2) * sf::seconds(1) == sf::seconds(2));
|
||||
CHECK(static_cast<std::int64_t>(2) * sf::seconds(42) == sf::seconds(84));
|
||||
STATIC_CHECK(sf::seconds(1) * 2.0f == sf::seconds(2));
|
||||
STATIC_CHECK(sf::seconds(12) * 0.5f == sf::seconds(6));
|
||||
STATIC_CHECK(sf::seconds(1) * std::int64_t{2} == sf::seconds(2));
|
||||
STATIC_CHECK(sf::seconds(42) * std::int64_t{2} == sf::seconds(84));
|
||||
STATIC_CHECK(2.0f * sf::seconds(1) == sf::seconds(2));
|
||||
STATIC_CHECK(0.5f * sf::seconds(12) == sf::seconds(6));
|
||||
STATIC_CHECK(std::int64_t{2} * sf::seconds(1) == sf::seconds(2));
|
||||
STATIC_CHECK(std::int64_t{2} * sf::seconds(42) == sf::seconds(84));
|
||||
}
|
||||
|
||||
SUBCASE("operator*=")
|
||||
SECTION("operator*=")
|
||||
{
|
||||
sf::Time time = sf::milliseconds(1'000);
|
||||
time *= static_cast<std::int64_t>(10);
|
||||
@ -260,17 +249,17 @@ TEST_CASE("[System] sf::Time")
|
||||
CHECK(time.asMilliseconds() == 1'000);
|
||||
}
|
||||
|
||||
SUBCASE("operator/")
|
||||
SECTION("operator/")
|
||||
{
|
||||
CHECK(sf::seconds(1) / 2.0f == sf::seconds(0.5f));
|
||||
CHECK(sf::seconds(12) / 0.5f == sf::seconds(24));
|
||||
CHECK(sf::seconds(1) / static_cast<std::int64_t>(2) == sf::seconds(0.5f));
|
||||
CHECK(sf::seconds(42) / static_cast<std::int64_t>(2) == sf::seconds(21));
|
||||
CHECK(sf::seconds(1) / sf::seconds(1) == 1.0f);
|
||||
STATIC_CHECK(sf::seconds(1) / 2.0f == sf::seconds(0.5f));
|
||||
STATIC_CHECK(sf::seconds(12) / 0.5f == sf::seconds(24));
|
||||
STATIC_CHECK(sf::seconds(1) / std::int64_t{2} == sf::seconds(0.5f));
|
||||
STATIC_CHECK(sf::seconds(42) / std::int64_t{2} == sf::seconds(21));
|
||||
STATIC_CHECK(sf::seconds(1) / sf::seconds(1) == 1.0f);
|
||||
CHECK(sf::milliseconds(10) / sf::microseconds(1) == Approx(10'000.f));
|
||||
}
|
||||
|
||||
SUBCASE("operator/=")
|
||||
SECTION("operator/=")
|
||||
{
|
||||
sf::Time time = sf::milliseconds(1'000);
|
||||
time /= static_cast<std::int64_t>(2);
|
||||
@ -279,13 +268,13 @@ TEST_CASE("[System] sf::Time")
|
||||
CHECK(time.asMilliseconds() == 1'000);
|
||||
}
|
||||
|
||||
SUBCASE("operator%")
|
||||
SECTION("operator%")
|
||||
{
|
||||
CHECK(sf::seconds(10) % sf::seconds(3) == sf::seconds(1));
|
||||
CHECK(sf::milliseconds(100) % sf::microseconds(10) == sf::seconds(0));
|
||||
STATIC_CHECK(sf::seconds(10) % sf::seconds(3) == sf::seconds(1));
|
||||
STATIC_CHECK(sf::milliseconds(100) % sf::microseconds(10) == sf::seconds(0));
|
||||
}
|
||||
|
||||
SUBCASE("operator%=")
|
||||
SECTION("operator%=")
|
||||
{
|
||||
sf::Time time = sf::milliseconds(100);
|
||||
time %= sf::milliseconds(99);
|
||||
@ -293,7 +282,7 @@ TEST_CASE("[System] sf::Time")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Constexpr support")
|
||||
SECTION("Constexpr support")
|
||||
{
|
||||
constexpr auto result = []
|
||||
{
|
||||
@ -302,6 +291,6 @@ TEST_CASE("[System] sf::Time")
|
||||
return time;
|
||||
}();
|
||||
|
||||
static_assert(result == sf::milliseconds(1));
|
||||
STATIC_CHECK(result == sf::milliseconds(1));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <type_traits>
|
||||
@ -12,39 +12,42 @@ using namespace sf::Literals;
|
||||
// Use sf::Vector2i for tests (except for float vector algebra).
|
||||
// Test coverage is given, as there are no template specializations.
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Vector2i>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Vector2i>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Vector2i>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Vector2i>);
|
||||
|
||||
TEST_CASE("[System] sf::Vector2")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::Vector2i vector;
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Vector2i>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Vector2i>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Vector2i>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Vector2i>);
|
||||
}
|
||||
|
||||
SUBCASE("(x, y) coordinate constructor")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Vector2i vector(1, 2);
|
||||
CHECK(vector.x == 1);
|
||||
CHECK(vector.y == 2);
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
constexpr sf::Vector2i vector;
|
||||
STATIC_CHECK(vector.x == 0);
|
||||
STATIC_CHECK(vector.y == 0);
|
||||
}
|
||||
|
||||
SUBCASE("Conversion constructor")
|
||||
SECTION("(x, y) coordinate constructor")
|
||||
{
|
||||
const sf::Vector2f sourceVector(1.0f, 2.0f);
|
||||
const sf::Vector2i vector(sourceVector);
|
||||
|
||||
CHECK(vector.x == static_cast<int>(sourceVector.x));
|
||||
CHECK(vector.y == static_cast<int>(sourceVector.y));
|
||||
constexpr sf::Vector2i vector(1, 2);
|
||||
STATIC_CHECK(vector.x == 1);
|
||||
STATIC_CHECK(vector.y == 2);
|
||||
}
|
||||
|
||||
SUBCASE("Length and angle constructor")
|
||||
SECTION("Conversion constructor")
|
||||
{
|
||||
constexpr sf::Vector2f sourceVector(1.0f, 2.0f);
|
||||
constexpr sf::Vector2i vector(sourceVector);
|
||||
|
||||
STATIC_CHECK(vector.x == static_cast<int>(sourceVector.x));
|
||||
STATIC_CHECK(vector.y == static_cast<int>(sourceVector.y));
|
||||
}
|
||||
|
||||
SECTION("Length and angle constructor")
|
||||
{
|
||||
CHECK(sf::Vector2f(0, 0_deg) == sf::Vector2f(0, 0));
|
||||
CHECK(sf::Vector2f(0, 45_deg) == sf::Vector2f(0, 0));
|
||||
@ -98,24 +101,24 @@ TEST_CASE("[System] sf::Vector2")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Unary operations")
|
||||
SECTION("Unary operations")
|
||||
{
|
||||
SUBCASE("-vector")
|
||||
SECTION("-vector")
|
||||
{
|
||||
const sf::Vector2i vector(1, 2);
|
||||
const sf::Vector2i negatedVector = -vector;
|
||||
constexpr sf::Vector2i vector(1, 2);
|
||||
constexpr sf::Vector2i negatedVector = -vector;
|
||||
|
||||
CHECK(negatedVector.x == -1);
|
||||
CHECK(negatedVector.y == -2);
|
||||
STATIC_CHECK(negatedVector.x == -1);
|
||||
STATIC_CHECK(negatedVector.y == -2);
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Arithmetic operations between two vectors")
|
||||
SECTION("Arithmetic operations between two vectors")
|
||||
{
|
||||
sf::Vector2i firstVector(2, 5);
|
||||
const sf::Vector2i secondVector(8, 3);
|
||||
constexpr sf::Vector2i secondVector(8, 3);
|
||||
|
||||
SUBCASE("vector += vector")
|
||||
SECTION("vector += vector")
|
||||
{
|
||||
firstVector += secondVector;
|
||||
|
||||
@ -123,7 +126,7 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(firstVector.y == 8);
|
||||
}
|
||||
|
||||
SUBCASE("vector -= vector")
|
||||
SECTION("vector -= vector")
|
||||
{
|
||||
firstVector -= secondVector;
|
||||
|
||||
@ -131,7 +134,7 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(firstVector.y == 2);
|
||||
}
|
||||
|
||||
SUBCASE("vector + vector")
|
||||
SECTION("vector + vector")
|
||||
{
|
||||
const sf::Vector2i result = firstVector + secondVector;
|
||||
|
||||
@ -139,7 +142,7 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(result.y == 8);
|
||||
}
|
||||
|
||||
SUBCASE("vector - vector")
|
||||
SECTION("vector - vector")
|
||||
{
|
||||
const sf::Vector2i result = firstVector - secondVector;
|
||||
|
||||
@ -148,12 +151,12 @@ TEST_CASE("[System] sf::Vector2")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Arithmetic operations between vector and scalar value")
|
||||
SECTION("Arithmetic operations between vector and scalar value")
|
||||
{
|
||||
sf::Vector2i vector(26, 12);
|
||||
const int scalar = 2;
|
||||
|
||||
SUBCASE("vector * scalar")
|
||||
SECTION("vector * scalar")
|
||||
{
|
||||
const sf::Vector2i result = vector * scalar;
|
||||
|
||||
@ -161,7 +164,7 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(result.y == 24);
|
||||
}
|
||||
|
||||
SUBCASE("scalar * vector")
|
||||
SECTION("scalar * vector")
|
||||
{
|
||||
const sf::Vector2i result = scalar * vector;
|
||||
|
||||
@ -169,7 +172,7 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(result.y == 24);
|
||||
}
|
||||
|
||||
SUBCASE("vector *= scalar")
|
||||
SECTION("vector *= scalar")
|
||||
{
|
||||
vector *= scalar;
|
||||
|
||||
@ -177,7 +180,7 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(vector.y == 24);
|
||||
}
|
||||
|
||||
SUBCASE("vector / scalar")
|
||||
SECTION("vector / scalar")
|
||||
{
|
||||
const sf::Vector2i result = vector / scalar;
|
||||
|
||||
@ -185,7 +188,7 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(result.y == 6);
|
||||
}
|
||||
|
||||
SUBCASE("vector /= scalar")
|
||||
SECTION("vector /= scalar")
|
||||
{
|
||||
vector /= scalar;
|
||||
|
||||
@ -194,37 +197,37 @@ TEST_CASE("[System] sf::Vector2")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Comparison operations (two equal and one different vector)")
|
||||
SECTION("Comparison operations (two equal and one different vector)")
|
||||
{
|
||||
const sf::Vector2i firstEqualVector(1, 5);
|
||||
const sf::Vector2i secondEqualVector(1, 5);
|
||||
const sf::Vector2i differentVector(6, 9);
|
||||
constexpr sf::Vector2i firstEqualVector(1, 5);
|
||||
constexpr sf::Vector2i secondEqualVector(1, 5);
|
||||
constexpr sf::Vector2i differentVector(6, 9);
|
||||
|
||||
SUBCASE("vector == vector")
|
||||
SECTION("vector == vector")
|
||||
{
|
||||
CHECK(firstEqualVector == secondEqualVector);
|
||||
CHECK_FALSE(firstEqualVector == differentVector);
|
||||
STATIC_CHECK(firstEqualVector == secondEqualVector);
|
||||
STATIC_CHECK_FALSE(firstEqualVector == differentVector);
|
||||
}
|
||||
|
||||
SUBCASE("vector != vector")
|
||||
SECTION("vector != vector")
|
||||
{
|
||||
CHECK(firstEqualVector != differentVector);
|
||||
CHECK_FALSE(firstEqualVector != secondEqualVector);
|
||||
STATIC_CHECK(firstEqualVector != differentVector);
|
||||
STATIC_CHECK_FALSE(firstEqualVector != secondEqualVector);
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Structured bindings")
|
||||
SECTION("Structured bindings")
|
||||
{
|
||||
sf::Vector2i vector(1, 2);
|
||||
sf::Vector2i vector(1, 2); // NOLINT(misc-const-correctness)
|
||||
|
||||
SUBCASE("destructure by value")
|
||||
SECTION("destructure by value")
|
||||
{
|
||||
auto [x, y] = vector;
|
||||
|
||||
CHECK(x == 1);
|
||||
CHECK(y == 2);
|
||||
|
||||
static_assert(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
STATIC_CHECK(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
|
||||
x = 3;
|
||||
|
||||
@ -232,14 +235,14 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(vector.x == 1);
|
||||
}
|
||||
|
||||
SUBCASE("destructure by ref")
|
||||
SECTION("destructure by ref")
|
||||
{
|
||||
auto& [x, y] = vector;
|
||||
|
||||
CHECK(x == 1);
|
||||
CHECK(y == 2);
|
||||
|
||||
static_assert(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
STATIC_CHECK(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
|
||||
x = 3;
|
||||
|
||||
@ -248,30 +251,30 @@ TEST_CASE("[System] sf::Vector2")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Length and normalization")
|
||||
SECTION("Length and normalization")
|
||||
{
|
||||
const sf::Vector2f v(2.4f, 3.0f);
|
||||
constexpr sf::Vector2f v(2.4f, 3.0f);
|
||||
|
||||
CHECK(v.length() == Approx(3.84187f));
|
||||
CHECK(v.lengthSq() == Approx(14.7599650969f));
|
||||
CHECK(v.normalized() == Approx(sf::Vector2f(0.624695f, 0.780869f)));
|
||||
|
||||
const sf::Vector2f w(-0.7f, -2.2f);
|
||||
constexpr sf::Vector2f w(-0.7f, -2.2f);
|
||||
|
||||
CHECK(w.length() == Approx(2.30868f));
|
||||
CHECK(w.lengthSq() == Approx(5.3300033f));
|
||||
CHECK(w.normalized() == Approx(sf::Vector2f(-0.303204f, -0.952926f)));
|
||||
}
|
||||
|
||||
SUBCASE("Rotations and angles")
|
||||
SECTION("Rotations and angles")
|
||||
{
|
||||
const sf::Vector2f v(2.4f, 3.0f);
|
||||
constexpr sf::Vector2f v(2.4f, 3.0f);
|
||||
|
||||
CHECK(v.angle() == Approx(51.3402_deg));
|
||||
CHECK(sf::Vector2f::UnitX.angleTo(v) == Approx(51.3402_deg));
|
||||
CHECK(sf::Vector2f::UnitY.angleTo(v) == Approx(-38.6598_deg));
|
||||
|
||||
const sf::Vector2f w(-0.7f, -2.2f);
|
||||
constexpr sf::Vector2f w(-0.7f, -2.2f);
|
||||
|
||||
CHECK(w.angle() == Approx(-107.65_deg));
|
||||
CHECK(sf::Vector2f::UnitX.angleTo(w) == Approx(-107.65_deg));
|
||||
@ -284,18 +287,18 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(v.rotatedBy(-158.9902_deg) * ratio == Approx(w));
|
||||
CHECK(w.rotatedBy(158.9902_deg) / ratio == Approx(v));
|
||||
|
||||
CHECK(v.perpendicular() == sf::Vector2f(-3.0f, 2.4f));
|
||||
CHECK(v.perpendicular().perpendicular().perpendicular().perpendicular() == v);
|
||||
STATIC_CHECK(v.perpendicular() == sf::Vector2f(-3.0f, 2.4f));
|
||||
STATIC_CHECK(v.perpendicular().perpendicular().perpendicular().perpendicular() == v);
|
||||
|
||||
CHECK(v.rotatedBy(90_deg) == Approx(sf::Vector2f(-3.0f, 2.4f)));
|
||||
CHECK(v.rotatedBy(27.14_deg) == Approx(sf::Vector2f(0.767248f, 3.76448f)));
|
||||
CHECK(v.rotatedBy(-36.11_deg) == Approx(sf::Vector2f(3.70694f, 1.00925f)));
|
||||
}
|
||||
|
||||
SUBCASE("Products and quotients")
|
||||
SECTION("Products and quotients")
|
||||
{
|
||||
const sf::Vector2f v(2.4f, 3.0f);
|
||||
const sf::Vector2f w(-0.7f, -2.2f);
|
||||
constexpr sf::Vector2f v(2.4f, 3.0f);
|
||||
constexpr sf::Vector2f w(-0.7f, -2.2f);
|
||||
|
||||
CHECK(v.dot(w) == Approx(-8.28f));
|
||||
CHECK(w.dot(v) == Approx(-8.28f));
|
||||
@ -309,36 +312,36 @@ TEST_CASE("[System] sf::Vector2")
|
||||
CHECK(w.cwiseDiv(v) == Approx(sf::Vector2f(-0.291666f, -0.733333f)));
|
||||
}
|
||||
|
||||
SUBCASE("Projection")
|
||||
SECTION("Projection")
|
||||
{
|
||||
const sf::Vector2f v(2.4f, 3.0f);
|
||||
const sf::Vector2f w(-0.7f, -2.2f);
|
||||
constexpr sf::Vector2f v(2.4f, 3.0f);
|
||||
constexpr sf::Vector2f w(-0.7f, -2.2f);
|
||||
|
||||
CHECK(v.projectedOnto(w) == Approx(sf::Vector2f(1.087430f, 3.417636f)));
|
||||
CHECK(v.projectedOnto(w) == Approx(sf::Vector2f(-1.55347f * w)));
|
||||
CHECK(v.projectedOnto(w) == Approx(-1.55347f * w));
|
||||
|
||||
CHECK(w.projectedOnto(v) == Approx(sf::Vector2f(-1.346342f, -1.682927f)));
|
||||
CHECK(w.projectedOnto(v) == Approx(sf::Vector2f(-0.560976f * v)));
|
||||
CHECK(w.projectedOnto(v) == Approx(-0.560976f * v));
|
||||
|
||||
CHECK(v.projectedOnto(sf::Vector2f::UnitX) == Approx(sf::Vector2f(2.4f, 0.0f)));
|
||||
CHECK(v.projectedOnto(sf::Vector2f::UnitY) == Approx(sf::Vector2f(0.0f, 3.0f)));
|
||||
}
|
||||
|
||||
SUBCASE("Constexpr support")
|
||||
SECTION("Constexpr support")
|
||||
{
|
||||
constexpr sf::Vector2i v(1, 2);
|
||||
constexpr sf::Vector2i w(2, -3);
|
||||
|
||||
static_assert(v.x == 1);
|
||||
static_assert(v.y == 2);
|
||||
static_assert(v + w == sf::Vector2i(3, -1));
|
||||
STATIC_CHECK(v.x == 1);
|
||||
STATIC_CHECK(v.y == 2);
|
||||
STATIC_CHECK(v + w == sf::Vector2i(3, -1));
|
||||
|
||||
static_assert(v.lengthSq() == 5);
|
||||
static_assert(v.perpendicular() == sf::Vector2i(-2, 1));
|
||||
STATIC_CHECK(v.lengthSq() == 5);
|
||||
STATIC_CHECK(v.perpendicular() == sf::Vector2i(-2, 1));
|
||||
|
||||
static_assert(v.dot(w) == -4);
|
||||
static_assert(v.cross(w) == -7);
|
||||
static_assert(v.cwiseMul(w) == sf::Vector2i(2, -6));
|
||||
static_assert(w.cwiseDiv(v) == sf::Vector2i(2, -1));
|
||||
STATIC_CHECK(v.dot(w) == -4);
|
||||
STATIC_CHECK(v.cross(w) == -7);
|
||||
STATIC_CHECK(v.cwiseMul(w) == sf::Vector2i(2, -6));
|
||||
STATIC_CHECK(w.cwiseDiv(v) == sf::Vector2i(2, -1));
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <type_traits>
|
||||
@ -8,61 +8,64 @@
|
||||
// Use sf::Vector3i for tests (except for float vector algebra).
|
||||
// Test coverage is given, as there are no template specializations.
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::Vector3i>);
|
||||
static_assert(std::is_copy_assignable_v<sf::Vector3i>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Vector3i>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Vector3i>);
|
||||
|
||||
TEST_CASE("[System] sf::Vector3")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::Vector3i vector;
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
CHECK(vector.z == 0);
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::Vector3i>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::Vector3i>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Vector3i>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Vector3i>);
|
||||
}
|
||||
|
||||
SUBCASE("(x, y, z) coordinate constructor")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Vector3i vector(1, 2, 3);
|
||||
CHECK(vector.x == 1);
|
||||
CHECK(vector.y == 2);
|
||||
CHECK(vector.z == 3);
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
constexpr sf::Vector3i vector;
|
||||
STATIC_CHECK(vector.x == 0);
|
||||
STATIC_CHECK(vector.y == 0);
|
||||
STATIC_CHECK(vector.z == 0);
|
||||
}
|
||||
|
||||
SUBCASE("Conversion constructor")
|
||||
SECTION("(x, y, z) coordinate constructor")
|
||||
{
|
||||
const sf::Vector3f sourceVector(1.0f, 2.0f, 3.0f);
|
||||
const sf::Vector3i vector(sourceVector);
|
||||
constexpr sf::Vector3i vector(1, 2, 3);
|
||||
STATIC_CHECK(vector.x == 1);
|
||||
STATIC_CHECK(vector.y == 2);
|
||||
STATIC_CHECK(vector.z == 3);
|
||||
}
|
||||
|
||||
CHECK(vector.x == static_cast<int>(sourceVector.x));
|
||||
CHECK(vector.y == static_cast<int>(sourceVector.y));
|
||||
CHECK(vector.z == static_cast<int>(sourceVector.z));
|
||||
SECTION("Conversion constructor")
|
||||
{
|
||||
constexpr sf::Vector3f sourceVector(1.0f, 2.0f, 3.0f);
|
||||
constexpr sf::Vector3i vector(sourceVector);
|
||||
|
||||
STATIC_CHECK(vector.x == static_cast<int>(sourceVector.x));
|
||||
STATIC_CHECK(vector.y == static_cast<int>(sourceVector.y));
|
||||
STATIC_CHECK(vector.z == static_cast<int>(sourceVector.z));
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Unary operations")
|
||||
SECTION("Unary operations")
|
||||
{
|
||||
SUBCASE("-vector")
|
||||
SECTION("-vector")
|
||||
{
|
||||
const sf::Vector3i vector(1, 2, 3);
|
||||
const sf::Vector3i negatedVector = -vector;
|
||||
constexpr sf::Vector3i vector(1, 2, 3);
|
||||
constexpr sf::Vector3i negatedVector = -vector;
|
||||
|
||||
CHECK(negatedVector.x == -1);
|
||||
CHECK(negatedVector.y == -2);
|
||||
CHECK(negatedVector.z == -3);
|
||||
STATIC_CHECK(negatedVector.x == -1);
|
||||
STATIC_CHECK(negatedVector.y == -2);
|
||||
STATIC_CHECK(negatedVector.z == -3);
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Arithmetic operations between two vectors")
|
||||
SECTION("Arithmetic operations between two vectors")
|
||||
{
|
||||
sf::Vector3i firstVector(2, 5, 6);
|
||||
const sf::Vector3i secondVector(8, 3, 7);
|
||||
constexpr sf::Vector3i secondVector(8, 3, 7);
|
||||
|
||||
SUBCASE("vector += vector")
|
||||
SECTION("vector += vector")
|
||||
{
|
||||
firstVector += secondVector;
|
||||
|
||||
@ -71,7 +74,7 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(firstVector.z == 13);
|
||||
}
|
||||
|
||||
SUBCASE("vector -= vector")
|
||||
SECTION("vector -= vector")
|
||||
{
|
||||
firstVector -= secondVector;
|
||||
|
||||
@ -80,7 +83,7 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(firstVector.z == -1);
|
||||
}
|
||||
|
||||
SUBCASE("vector + vector")
|
||||
SECTION("vector + vector")
|
||||
{
|
||||
const sf::Vector3i result = firstVector + secondVector;
|
||||
|
||||
@ -89,7 +92,7 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(result.z == 13);
|
||||
}
|
||||
|
||||
SUBCASE("vector - vector")
|
||||
SECTION("vector - vector")
|
||||
{
|
||||
const sf::Vector3i result = firstVector - secondVector;
|
||||
|
||||
@ -99,30 +102,30 @@ TEST_CASE("[System] sf::Vector3")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Arithmetic operations between vector and scalar value")
|
||||
SECTION("Arithmetic operations between vector and scalar value")
|
||||
{
|
||||
sf::Vector3i vector(26, 12, 6);
|
||||
const int scalar = 2;
|
||||
constexpr int scalar = 2;
|
||||
|
||||
SUBCASE("vector * scalar")
|
||||
SECTION("vector * scalar")
|
||||
{
|
||||
sf::Vector3i result = vector * scalar;
|
||||
const sf::Vector3i result = vector * scalar;
|
||||
|
||||
CHECK(result.x == 52);
|
||||
CHECK(result.y == 24);
|
||||
CHECK(result.z == 12);
|
||||
}
|
||||
|
||||
SUBCASE("scalar * vector")
|
||||
SECTION("scalar * vector")
|
||||
{
|
||||
sf::Vector3i result = scalar * vector;
|
||||
const sf::Vector3i result = scalar * vector;
|
||||
|
||||
CHECK(result.x == 52);
|
||||
CHECK(result.y == 24);
|
||||
CHECK(result.z == 12);
|
||||
}
|
||||
|
||||
SUBCASE("vector *= scalar")
|
||||
SECTION("vector *= scalar")
|
||||
{
|
||||
vector *= scalar;
|
||||
|
||||
@ -131,16 +134,16 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(vector.z == 12);
|
||||
}
|
||||
|
||||
SUBCASE("vector / scalar")
|
||||
SECTION("vector / scalar")
|
||||
{
|
||||
sf::Vector3i result = vector / scalar;
|
||||
const sf::Vector3i result = vector / scalar;
|
||||
|
||||
CHECK(result.x == 13);
|
||||
CHECK(result.y == 6);
|
||||
CHECK(result.z == 3);
|
||||
}
|
||||
|
||||
SUBCASE("vector /= scalar")
|
||||
SECTION("vector /= scalar")
|
||||
{
|
||||
vector /= scalar;
|
||||
|
||||
@ -150,30 +153,30 @@ TEST_CASE("[System] sf::Vector3")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Comparison operations (two equal and one different vector)")
|
||||
SECTION("Comparison operations (two equal and one different vector)")
|
||||
{
|
||||
const sf::Vector3i firstEqualVector(1, 5, 6);
|
||||
const sf::Vector3i secondEqualVector(1, 5, 6);
|
||||
const sf::Vector3i differentVector(6, 9, 7);
|
||||
constexpr sf::Vector3i firstEqualVector(1, 5, 6);
|
||||
constexpr sf::Vector3i secondEqualVector(1, 5, 6);
|
||||
constexpr sf::Vector3i differentVector(6, 9, 7);
|
||||
|
||||
SUBCASE("vector == vector")
|
||||
SECTION("vector == vector")
|
||||
{
|
||||
CHECK(firstEqualVector == secondEqualVector);
|
||||
CHECK_FALSE(firstEqualVector == differentVector);
|
||||
STATIC_CHECK(firstEqualVector == secondEqualVector);
|
||||
STATIC_CHECK_FALSE(firstEqualVector == differentVector);
|
||||
}
|
||||
|
||||
SUBCASE("vector != vector")
|
||||
SECTION("vector != vector")
|
||||
{
|
||||
CHECK(firstEqualVector != differentVector);
|
||||
CHECK_FALSE(firstEqualVector != secondEqualVector);
|
||||
STATIC_CHECK(firstEqualVector != differentVector);
|
||||
STATIC_CHECK_FALSE(firstEqualVector != secondEqualVector);
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Structured bindings")
|
||||
SECTION("Structured bindings")
|
||||
{
|
||||
sf::Vector3i vector(1, 2, 3);
|
||||
sf::Vector3i vector(1, 2, 3); // NOLINT(misc-const-correctness)
|
||||
|
||||
SUBCASE("destructure by value")
|
||||
SECTION("destructure by value")
|
||||
{
|
||||
auto [x, y, z] = vector;
|
||||
|
||||
@ -181,7 +184,7 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(y == 2);
|
||||
CHECK(z == 3);
|
||||
|
||||
static_assert(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
STATIC_CHECK(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
|
||||
x = 3;
|
||||
|
||||
@ -189,7 +192,7 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(vector.x == 1);
|
||||
}
|
||||
|
||||
SUBCASE("destructure by ref")
|
||||
SECTION("destructure by ref")
|
||||
{
|
||||
auto& [x, y, z] = vector;
|
||||
|
||||
@ -197,7 +200,7 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(y == 2);
|
||||
CHECK(z == 3);
|
||||
|
||||
static_assert(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
STATIC_CHECK(std::is_same_v<decltype(x), decltype(vector.x)>);
|
||||
|
||||
x = 3;
|
||||
|
||||
@ -206,19 +209,19 @@ TEST_CASE("[System] sf::Vector3")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Length and normalization")
|
||||
SECTION("Length and normalization")
|
||||
{
|
||||
const sf::Vector3f v(2.4f, 3.0f, 5.2f);
|
||||
constexpr sf::Vector3f v(2.4f, 3.0f, 5.2f);
|
||||
|
||||
CHECK(v.length() == Approx(6.46529f));
|
||||
CHECK(v.lengthSq() == Approx(41.79997f));
|
||||
CHECK(v.normalized() == Approx(sf::Vector3f(0.37121f, 0.46401f, 0.80429f)));
|
||||
}
|
||||
|
||||
SUBCASE("Products and quotients")
|
||||
SECTION("Products and quotients")
|
||||
{
|
||||
const sf::Vector3f v(2.4f, 3.0f, 5.2f);
|
||||
const sf::Vector3f w(-0.7f, -2.2f, -4.8f);
|
||||
constexpr sf::Vector3f v(2.4f, 3.0f, 5.2f);
|
||||
constexpr sf::Vector3f w(-0.7f, -2.2f, -4.8f);
|
||||
|
||||
CHECK(v.dot(w) == Approx(-33.24f));
|
||||
CHECK(w.dot(v) == Approx(-33.24f));
|
||||
@ -231,13 +234,4 @@ TEST_CASE("[System] sf::Vector3")
|
||||
CHECK(v.cwiseDiv(w) == Approx(sf::Vector3f(-3.428571f, -1.363636f, -1.0833333f)));
|
||||
CHECK(w.cwiseDiv(v) == Approx(sf::Vector3f(-0.291666f, -0.733333f, -0.9230769f)));
|
||||
}
|
||||
|
||||
SUBCASE("Constexpr support")
|
||||
{
|
||||
constexpr sf::Vector3i vector(1, 2, 3);
|
||||
static_assert(vector.x == 1);
|
||||
static_assert(vector.y == 2);
|
||||
static_assert(vector.z == 3);
|
||||
static_assert(vector + sf::Vector3i(3, 2, 1) == sf::Vector3i(4, 4, 4));
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Header for SFML unit tests.
|
||||
//
|
||||
// For a new graphics module test case, include this header.
|
||||
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
||||
// This ensures that string conversions are visible and can be used by Catch2 for debug output.
|
||||
|
||||
#pragma once
|
||||
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_approx.hpp>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <iomanip>
|
||||
@ -58,7 +59,7 @@ template std::ostream& operator<<(std::ostream&, const Vector3<float>&);
|
||||
|
||||
bool operator==(const float& lhs, const Approx<float>& rhs)
|
||||
{
|
||||
return static_cast<double>(lhs) == doctest::Approx(static_cast<double>(rhs.value));
|
||||
return static_cast<double>(lhs) == Catch::Approx(static_cast<double>(rhs.value)).margin(1e-5);
|
||||
}
|
||||
|
||||
bool operator==(const sf::Vector2f& lhs, const Approx<sf::Vector2f>& rhs)
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Header for SFML unit tests.
|
||||
//
|
||||
// For a new system module test case, include this header.
|
||||
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
||||
// This ensures that string conversions are visible and can be used by Catch2 for debug output.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iosfwd>
|
||||
|
||||
// String conversions for doctest framework
|
||||
// String conversions for Catch2
|
||||
namespace sf
|
||||
{
|
||||
class Angle;
|
||||
|
@ -3,6 +3,17 @@
|
||||
|
||||
#include <ostream>
|
||||
|
||||
std::string runDisplayTests()
|
||||
{
|
||||
#ifdef SFML_RUN_DISPLAY_TESTS
|
||||
return "";
|
||||
#else
|
||||
// https://github.com/catchorg/Catch2/blob/devel/docs/test-cases-and-sections.md#special-tags
|
||||
// This tag tells Catch2 to not run a given TEST_CASE
|
||||
return "[.display]";
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
std::ostream& operator<<(std::ostream& os, const VideoMode& videoMode)
|
||||
|
@ -1,19 +1,18 @@
|
||||
// Header for SFML unit tests.
|
||||
//
|
||||
// For a new window module test case, include this header.
|
||||
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
||||
// This ensures that string conversions are visible and can be used by Catch2 for debug output.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SystemUtil.hpp>
|
||||
#include <string>
|
||||
|
||||
#ifdef SFML_RUN_DISPLAY_TESTS
|
||||
static constexpr bool skipDisplayTests = false;
|
||||
#else
|
||||
static constexpr bool skipDisplayTests = true;
|
||||
#endif
|
||||
// Required because WindowUtil.cpp doesn't include WindowUtil.hpp
|
||||
// NOLINTNEXTLINE(readability-redundant-declaration)
|
||||
std::string runDisplayTests();
|
||||
|
||||
// String conversions for doctest framework
|
||||
// String conversions for Catch2
|
||||
namespace sf
|
||||
{
|
||||
class VideoMode;
|
||||
|
@ -3,7 +3,7 @@
|
||||
// Other 1st party headers
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <WindowUtil.hpp>
|
||||
#include <string>
|
||||
@ -15,21 +15,24 @@
|
||||
#define GLAPI
|
||||
#endif
|
||||
|
||||
static_assert(!std::is_copy_constructible_v<sf::Context>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::Context>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::Context>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::Context>);
|
||||
|
||||
TEST_CASE("[Window] sf::Context" * doctest::skip(skipDisplayTests))
|
||||
TEST_CASE("[Window] sf::Context", runDisplayTests())
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::Context>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::Context>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::Context>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::Context>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Context context;
|
||||
|
||||
CHECK(context.getSettings().majorVersion > 0);
|
||||
}
|
||||
|
||||
SUBCASE("Version String")
|
||||
SECTION("Version String")
|
||||
{
|
||||
sf::Context context;
|
||||
|
||||
@ -39,7 +42,7 @@ TEST_CASE("[Window] sf::Context" * doctest::skip(skipDisplayTests))
|
||||
|
||||
auto glGetStringFunc = reinterpret_cast<glGetStringFuncType>(sf::Context::getFunction("glGetString"));
|
||||
|
||||
REQUIRE_UNARY(!!glGetStringFunc);
|
||||
REQUIRE(glGetStringFunc);
|
||||
|
||||
constexpr unsigned int glVendor = 0x1F00;
|
||||
constexpr unsigned int glRenderer = 0x1F01;
|
||||
@ -53,11 +56,8 @@ TEST_CASE("[Window] sf::Context" * doctest::skip(skipDisplayTests))
|
||||
REQUIRE(renderer != nullptr);
|
||||
REQUIRE(version != nullptr);
|
||||
|
||||
MESSAGE("\nOpenGL vendor: ",
|
||||
std::string(vendor),
|
||||
"\nOpenGL renderer: ",
|
||||
std::string(renderer),
|
||||
"\nOpenGL version: ",
|
||||
std::string(version));
|
||||
SUCCEED(std::string("OpenGL vendor: ") + vendor);
|
||||
SUCCEED(std::string("OpenGL renderer: ") + renderer);
|
||||
SUCCEED(std::string("OpenGL version: ") + version);
|
||||
}
|
||||
}
|
||||
|
@ -1,40 +1,43 @@
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::ContextSettings>);
|
||||
static_assert(std::is_copy_assignable_v<sf::ContextSettings>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::ContextSettings>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::ContextSettings>);
|
||||
|
||||
TEST_CASE("[Window] sf::ContextSettings")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::ContextSettings contextSettings;
|
||||
CHECK(contextSettings.depthBits == 0);
|
||||
CHECK(contextSettings.stencilBits == 0);
|
||||
CHECK(contextSettings.antialiasingLevel == 0);
|
||||
CHECK(contextSettings.majorVersion == 1);
|
||||
CHECK(contextSettings.minorVersion == 1);
|
||||
CHECK(contextSettings.attributeFlags == sf::ContextSettings::Default);
|
||||
CHECK(contextSettings.sRgbCapable == false);
|
||||
STATIC_CHECK(std::is_copy_constructible_v<sf::ContextSettings>);
|
||||
STATIC_CHECK(std::is_copy_assignable_v<sf::ContextSettings>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::ContextSettings>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::ContextSettings>);
|
||||
}
|
||||
|
||||
SUBCASE("Verbose constructor")
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::ContextSettings contextSettings(1, 1, 2, 3, 5, sf::ContextSettings::Core, true);
|
||||
CHECK(contextSettings.depthBits == 1);
|
||||
CHECK(contextSettings.stencilBits == 1);
|
||||
CHECK(contextSettings.antialiasingLevel == 2);
|
||||
CHECK(contextSettings.majorVersion == 3);
|
||||
CHECK(contextSettings.minorVersion == 5);
|
||||
CHECK(contextSettings.attributeFlags == sf::ContextSettings::Core);
|
||||
CHECK(contextSettings.sRgbCapable == true);
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
constexpr sf::ContextSettings contextSettings;
|
||||
STATIC_CHECK(contextSettings.depthBits == 0);
|
||||
STATIC_CHECK(contextSettings.stencilBits == 0);
|
||||
STATIC_CHECK(contextSettings.antialiasingLevel == 0);
|
||||
STATIC_CHECK(contextSettings.majorVersion == 1);
|
||||
STATIC_CHECK(contextSettings.minorVersion == 1);
|
||||
STATIC_CHECK(contextSettings.attributeFlags == sf::ContextSettings::Default);
|
||||
STATIC_CHECK(contextSettings.sRgbCapable == false);
|
||||
}
|
||||
|
||||
SECTION("Verbose constructor")
|
||||
{
|
||||
constexpr sf::ContextSettings contextSettings(1, 1, 2, 3, 5, sf::ContextSettings::Core, true);
|
||||
STATIC_CHECK(contextSettings.depthBits == 1);
|
||||
STATIC_CHECK(contextSettings.stencilBits == 1);
|
||||
STATIC_CHECK(contextSettings.antialiasingLevel == 2);
|
||||
STATIC_CHECK(contextSettings.majorVersion == 3);
|
||||
STATIC_CHECK(contextSettings.minorVersion == 5);
|
||||
STATIC_CHECK(contextSettings.attributeFlags == sf::ContextSettings::Core);
|
||||
STATIC_CHECK(contextSettings.sRgbCapable == true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,36 @@
|
||||
#include <SFML/Window/Cursor.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <WindowUtil.hpp>
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_copy_constructible_v<sf::Cursor>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::Cursor>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::Cursor>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::Cursor>);
|
||||
|
||||
// Skip these tests because they fail when using DRM which hasn't implemented sf::Cursor
|
||||
TEST_CASE("[Window] sf::Cursor" * doctest::skip(true))
|
||||
// Skip these tests with [.display] because they fail when using DRM which hasn't implemented sf::Cursor
|
||||
TEST_CASE("[Window] sf::Cursor", "[.display]")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::Cursor>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::Cursor>);
|
||||
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::Cursor>);
|
||||
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::Cursor>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Cursor cursor;
|
||||
}
|
||||
|
||||
SUBCASE("Move semantics")
|
||||
SECTION("Move semantics")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Construction")
|
||||
{
|
||||
sf::Cursor movedCursor;
|
||||
const sf::Cursor cursor(std::move(movedCursor));
|
||||
}
|
||||
|
||||
SUBCASE("Assignment")
|
||||
SECTION("Assignment")
|
||||
{
|
||||
sf::Cursor movedCursor;
|
||||
sf::Cursor cursor;
|
||||
@ -35,7 +38,7 @@ TEST_CASE("[Window] sf::Cursor" * doctest::skip(true))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("loadFromPixels()")
|
||||
SECTION("loadFromPixels()")
|
||||
{
|
||||
sf::Cursor cursor;
|
||||
std::array<std::uint8_t, 4> pixels{};
|
||||
@ -46,7 +49,7 @@ TEST_CASE("[Window] sf::Cursor" * doctest::skip(true))
|
||||
CHECK(cursor.loadFromPixels(pixels.data(), {1, 1}, {}));
|
||||
}
|
||||
|
||||
SUBCASE("loadFromSystem()")
|
||||
SECTION("loadFromSystem()")
|
||||
{
|
||||
sf::Cursor cursor;
|
||||
CHECK(cursor.loadFromSystem(sf::Cursor::Hand));
|
||||
|
@ -1,34 +1,37 @@
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <WindowUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(std::is_copy_constructible_v<sf::VideoMode>);
|
||||
static_assert(std::is_copy_assignable_v<sf::VideoMode>);
|
||||
static_assert(std::is_nothrow_move_constructible_v<sf::VideoMode>);
|
||||
static_assert(std::is_nothrow_move_assignable_v<sf::VideoMode>);
|
||||
|
||||
TEST_CASE("[Window] sf::VideoMode")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
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")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
sf::VideoMode videoMode;
|
||||
CHECK(videoMode.size == sf::Vector2u(0, 0));
|
||||
CHECK(videoMode.bitsPerPixel == 0);
|
||||
}
|
||||
|
||||
SUBCASE("Width, height constructor")
|
||||
SECTION("Width, height constructor")
|
||||
{
|
||||
sf::VideoMode videoMode({800, 600});
|
||||
CHECK(videoMode.size == sf::Vector2u(800, 600));
|
||||
CHECK(videoMode.bitsPerPixel == 32);
|
||||
}
|
||||
|
||||
SUBCASE("Width, height, bit depth constructor")
|
||||
SECTION("Width, height, bit depth constructor")
|
||||
{
|
||||
sf::VideoMode videoMode({800, 600}, 24);
|
||||
CHECK(videoMode.size == sf::Vector2u(800, 600));
|
||||
@ -36,16 +39,16 @@ TEST_CASE("[Window] sf::VideoMode")
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("Operators")
|
||||
SECTION("Operators")
|
||||
{
|
||||
SUBCASE("operator==")
|
||||
SECTION("operator==")
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
SUBCASE("operator!=")
|
||||
SECTION("operator!=")
|
||||
{
|
||||
CHECK(sf::VideoMode() != sf::VideoMode({1, 0}));
|
||||
CHECK(sf::VideoMode() != sf::VideoMode({0, 1}));
|
||||
@ -54,7 +57,7 @@ TEST_CASE("[Window] sf::VideoMode")
|
||||
CHECK(sf::VideoMode({1080, 1920}, 16) != sf::VideoMode({400, 600}));
|
||||
}
|
||||
|
||||
SUBCASE("operator<")
|
||||
SECTION("operator<")
|
||||
{
|
||||
CHECK(sf::VideoMode() < sf::VideoMode({0, 0}, 1));
|
||||
CHECK(sf::VideoMode({800, 800}, 24) < sf::VideoMode({1080, 1920}, 48));
|
||||
@ -62,7 +65,7 @@ TEST_CASE("[Window] sf::VideoMode")
|
||||
CHECK(sf::VideoMode({400, 400}, 48) < sf::VideoMode({400, 600}, 48));
|
||||
}
|
||||
|
||||
SUBCASE("operator>")
|
||||
SECTION("operator>")
|
||||
{
|
||||
CHECK(sf::VideoMode({1, 0}) > sf::VideoMode({0, 0}, 1));
|
||||
CHECK(sf::VideoMode({800, 800}, 48) > sf::VideoMode({1080, 1920}, 24));
|
||||
@ -70,7 +73,7 @@ TEST_CASE("[Window] sf::VideoMode")
|
||||
CHECK(sf::VideoMode({400, 600}, 48) > sf::VideoMode({400, 400}, 48));
|
||||
}
|
||||
|
||||
SUBCASE("operator<=")
|
||||
SECTION("operator<=")
|
||||
{
|
||||
CHECK(sf::VideoMode() <= sf::VideoMode({0, 0}, 1));
|
||||
CHECK(sf::VideoMode({800, 800}, 24) <= sf::VideoMode({1080, 1920}, 48));
|
||||
@ -81,7 +84,7 @@ TEST_CASE("[Window] sf::VideoMode")
|
||||
CHECK(sf::VideoMode({1080, 1920}, 64) <= sf::VideoMode({1080, 1920}, 64));
|
||||
}
|
||||
|
||||
SUBCASE("operator>=")
|
||||
SECTION("operator>=")
|
||||
{
|
||||
CHECK(sf::VideoMode({1, 0}) >= sf::VideoMode({0, 0}, 1));
|
||||
CHECK(sf::VideoMode({800, 800}, 48) >= sf::VideoMode({1080, 1920}, 24));
|
||||
|
@ -5,19 +5,22 @@
|
||||
|
||||
#include <SFML/System/String.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <WindowUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_copy_constructible_v<sf::Window>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::Window>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::Window>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::Window>);
|
||||
|
||||
TEST_CASE("[Window] sf::Window" * doctest::skip(skipDisplayTests))
|
||||
TEST_CASE("[Window] sf::Window", runDisplayTests())
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
SECTION("Type traits")
|
||||
{
|
||||
STATIC_CHECK(!std::is_copy_constructible_v<sf::Window>);
|
||||
STATIC_CHECK(!std::is_copy_assignable_v<sf::Window>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_constructible_v<sf::Window>);
|
||||
STATIC_CHECK(!std::is_nothrow_move_assignable_v<sf::Window>);
|
||||
}
|
||||
|
||||
SECTION("Construction")
|
||||
{
|
||||
const sf::Window window(sf::VideoMode(sf::Vector2u(256, 256), 32),
|
||||
"Window Title",
|
||||
|
@ -6,21 +6,24 @@
|
||||
|
||||
#include <SFML/System/String.hpp>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include <WindowUtil.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
static_assert(!std::is_copy_constructible_v<sf::WindowBase>);
|
||||
static_assert(!std::is_copy_assignable_v<sf::WindowBase>);
|
||||
static_assert(!std::is_nothrow_move_constructible_v<sf::WindowBase>);
|
||||
static_assert(!std::is_nothrow_move_assignable_v<sf::WindowBase>);
|
||||
TEST_CASE("[Window] sf::WindowBase", runDisplayTests())
|
||||
{
|
||||
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>);
|
||||
}
|
||||
|
||||
TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
SECTION("Construction")
|
||||
{
|
||||
SUBCASE("Construction")
|
||||
{
|
||||
SUBCASE("Default constructor")
|
||||
SECTION("Default constructor")
|
||||
{
|
||||
const sf::WindowBase windowBase;
|
||||
CHECK(!windowBase.isOpen());
|
||||
@ -30,7 +33,7 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
CHECK(windowBase.getSystemHandle() == sf::WindowHandle());
|
||||
}
|
||||
|
||||
SUBCASE("Mode and title constructor")
|
||||
SECTION("Mode and title constructor")
|
||||
{
|
||||
const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
||||
CHECK(windowBase.isOpen());
|
||||
@ -38,7 +41,7 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
CHECK(windowBase.getSystemHandle() != sf::WindowHandle());
|
||||
}
|
||||
|
||||
SUBCASE("Mode, title, and style constructor")
|
||||
SECTION("Mode, title, and style constructor")
|
||||
{
|
||||
const sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests", sf::Style::Resize);
|
||||
CHECK(windowBase.isOpen());
|
||||
@ -47,11 +50,11 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("create()")
|
||||
SECTION("create()")
|
||||
{
|
||||
sf::WindowBase windowBase;
|
||||
|
||||
SUBCASE("Mode and title")
|
||||
SECTION("Mode and title")
|
||||
{
|
||||
windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests");
|
||||
CHECK(windowBase.isOpen());
|
||||
@ -59,7 +62,7 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
CHECK(windowBase.getSystemHandle() != sf::WindowHandle());
|
||||
}
|
||||
|
||||
SUBCASE("Mode, title, and style")
|
||||
SECTION("Mode, title, and style")
|
||||
{
|
||||
windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests", sf::Style::Resize);
|
||||
CHECK(windowBase.isOpen());
|
||||
@ -68,51 +71,51 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("close()")
|
||||
SECTION("close()")
|
||||
{
|
||||
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
||||
windowBase.close();
|
||||
CHECK(!windowBase.isOpen());
|
||||
}
|
||||
|
||||
SUBCASE("pollEvent()")
|
||||
SECTION("pollEvent()")
|
||||
{
|
||||
sf::WindowBase windowBase;
|
||||
sf::Event event;
|
||||
CHECK(!windowBase.pollEvent(event));
|
||||
}
|
||||
|
||||
SUBCASE("waitEvent()")
|
||||
SECTION("waitEvent()")
|
||||
{
|
||||
sf::WindowBase windowBase;
|
||||
sf::Event event;
|
||||
CHECK(!windowBase.waitEvent(event));
|
||||
}
|
||||
|
||||
SUBCASE("Set/get position")
|
||||
SECTION("Set/get position")
|
||||
{
|
||||
sf::WindowBase windowBase;
|
||||
windowBase.setPosition({12, 34});
|
||||
CHECK(windowBase.getPosition() == sf::Vector2i());
|
||||
}
|
||||
|
||||
SUBCASE("Set/get size")
|
||||
SECTION("Set/get size")
|
||||
{
|
||||
SUBCASE("Uninitialized window")
|
||||
SECTION("Uninitialized window")
|
||||
{
|
||||
sf::WindowBase windowBase;
|
||||
windowBase.setSize({128, 256});
|
||||
CHECK(windowBase.getSize() == sf::Vector2u());
|
||||
}
|
||||
|
||||
SUBCASE("Initialized window")
|
||||
SECTION("Initialized window")
|
||||
{
|
||||
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
||||
windowBase.setSize({128, 256});
|
||||
CHECK(windowBase.getSize() == sf::Vector2u(128, 256));
|
||||
}
|
||||
|
||||
SUBCASE("Minimum size")
|
||||
SECTION("Minimum size")
|
||||
{
|
||||
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
||||
windowBase.setMinimumSize(sf::Vector2u(128, 256));
|
||||
@ -120,7 +123,7 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
CHECK(windowBase.getSize() == sf::Vector2u(128, 256));
|
||||
}
|
||||
|
||||
SUBCASE("Maximum size")
|
||||
SECTION("Maximum size")
|
||||
{
|
||||
sf::WindowBase windowBase(sf::VideoMode({360, 240}), "WindowBase Tests");
|
||||
windowBase.setMaximumSize(sf::Vector2u(128, 256));
|
||||
@ -129,7 +132,7 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
}
|
||||
}
|
||||
|
||||
SUBCASE("setMinimumSize()")
|
||||
SECTION("setMinimumSize()")
|
||||
{
|
||||
sf::WindowBase windowBase(sf::VideoMode({100, 100}), "WindowBase Tests", sf::Style::Default ^ sf::Style::Resize);
|
||||
windowBase.setMinimumSize(sf::Vector2u(200, 300));
|
||||
@ -137,7 +140,7 @@ TEST_CASE("[Window] sf::WindowBase" * doctest::skip(skipDisplayTests))
|
||||
windowBase.setMaximumSize(sf::Vector2u(200, 300));
|
||||
}
|
||||
|
||||
SUBCASE("setMinimumSize()")
|
||||
SECTION("setMinimumSize()")
|
||||
{
|
||||
sf::WindowBase windowBase(sf::VideoMode({400, 400}), "WindowBase Tests", sf::Style::Default ^ sf::Style::Resize);
|
||||
windowBase.setMaximumSize(sf::Vector2u(200, 300));
|
||||
|
Loading…
Reference in New Issue
Block a user