mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 04:41:05 +08:00
Replace Catch with Doctest
This commit is contained in:
parent
ade9843dd8
commit
29983aa8d4
6750
extlibs/headers/doctest.h
vendored
Normal file
6750
extlibs/headers/doctest.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -2,22 +2,10 @@ cmake_minimum_required(VERSION 3.14)
|
||||
|
||||
set(SRCROOT "${PROJECT_SOURCE_DIR}/test")
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(Catch2
|
||||
GIT_REPOSITORY "https://github.com/catchorg/Catch2.git"
|
||||
GIT_TAG v2.13.7)
|
||||
FetchContent_MakeAvailable(Catch2)
|
||||
|
||||
add_library(sfml-test-main STATIC "${SRCROOT}/CatchMain.cpp")
|
||||
target_include_directories(sfml-test-main PUBLIC "${SRCROOT}/TestUtilities")
|
||||
target_link_libraries(sfml-test-main PUBLIC Catch2::Catch2)
|
||||
add_library(sfml-test-main STATIC "${SRCROOT}/DoctestMain.cpp")
|
||||
target_include_directories(sfml-test-main PUBLIC "${PROJECT_SOURCE_DIR}/extlibs/headers" "${SRCROOT}/TestUtilities")
|
||||
target_compile_features(sfml-test-main PRIVATE cxx_std_17)
|
||||
|
||||
# Work around MinGW struggling to process a file as large as catch.hpp
|
||||
if(MINGW)
|
||||
target_compile_options(sfml-test-main PUBLIC -Wa,-mbig-obj)
|
||||
endif()
|
||||
|
||||
# System is always built
|
||||
SET(SYSTEM_SRC
|
||||
"${SRCROOT}/System/Time.cpp"
|
||||
|
@ -1,2 +0,0 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch2/catch.hpp>
|
2
test/DoctestMain.cpp
Normal file
2
test/DoctestMain.cpp
Normal file
@ -0,0 +1,2 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include <doctest.h>
|
@ -2,11 +2,11 @@
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include "GraphicsUtil.hpp"
|
||||
|
||||
TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
TEST_CASE("sf::Rect class template - [graphics]")
|
||||
{
|
||||
SECTION("Construction")
|
||||
SUBCASE("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
sf::IntRect rectangle;
|
||||
CHECK(rectangle.left == 0);
|
||||
@ -15,7 +15,7 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
CHECK(rectangle.height == 0);
|
||||
}
|
||||
|
||||
SECTION("(left, top, width, height) constructor")
|
||||
SUBCASE("(left, top, width, height) constructor")
|
||||
{
|
||||
sf::IntRect rectangle(1, 2, 3, 4);
|
||||
CHECK(rectangle.left == 1);
|
||||
@ -24,7 +24,7 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
CHECK(rectangle.height == 4);
|
||||
}
|
||||
|
||||
SECTION("(Vector2, Vector2) constructor")
|
||||
SUBCASE("(Vector2, Vector2) constructor")
|
||||
{
|
||||
sf::Vector2i position(1, 2);
|
||||
sf::Vector2i dimension(3, 4);
|
||||
@ -36,7 +36,7 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
CHECK(rectangle.height == 4);
|
||||
}
|
||||
|
||||
SECTION("Conversion constructor")
|
||||
SUBCASE("Conversion constructor")
|
||||
{
|
||||
sf::FloatRect sourceRectangle(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
sf::IntRect rectangle(sourceRectangle);
|
||||
@ -48,9 +48,9 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Containment")
|
||||
SUBCASE("Containment")
|
||||
{
|
||||
SECTION("contains(x, y)")
|
||||
SUBCASE("contains(x, y)")
|
||||
{
|
||||
sf::IntRect rectangle(0, 0, 10, 10);
|
||||
|
||||
@ -64,7 +64,7 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
CHECK(rectangle.contains(15, 15) == false);
|
||||
}
|
||||
|
||||
SECTION("contains(Vector2)")
|
||||
SUBCASE("contains(Vector2)")
|
||||
{
|
||||
sf::IntRect rectangle(0, 0, 10, 10);
|
||||
|
||||
@ -79,9 +79,9 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Intersection")
|
||||
SUBCASE("Intersection")
|
||||
{
|
||||
SECTION("intersects(Rect)")
|
||||
SUBCASE("intersects(Rect)")
|
||||
{
|
||||
sf::IntRect rectangle(0, 0, 10, 10);
|
||||
sf::IntRect intersectingRectangle(5, 5, 10, 10);
|
||||
@ -91,7 +91,7 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
CHECK(rectangle.intersects(nonIntersectingRectangle) == false);
|
||||
}
|
||||
|
||||
SECTION("intersects(Rect, Rect)")
|
||||
SUBCASE("intersects(Rect, Rect)")
|
||||
{
|
||||
sf::IntRect rectangle(0, 0, 10, 10);
|
||||
sf::IntRect intersectingRectangle(5, 5, 10, 10);
|
||||
@ -108,7 +108,7 @@ TEST_CASE("sf::Rect class template", "[graphics]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Comparison operations")
|
||||
SUBCASE("Comparison operations")
|
||||
{
|
||||
sf::IntRect firstRectangle(1, 3, 2, 5);
|
||||
sf::IntRect secondRectangle(1, 3, 2, 5);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <SFML/Network.hpp>
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <doctest.h>
|
||||
#include <limits>
|
||||
|
||||
template <typename IntegerType>
|
||||
@ -13,11 +13,11 @@ static void testPacketStreamOperators(IntegerType expected)
|
||||
CHECK(expected == received);
|
||||
}
|
||||
|
||||
TEST_CASE("sf::Packet class", "[network]")
|
||||
TEST_CASE("sf::Packet class - [network]")
|
||||
{
|
||||
SECTION("Stream operators")
|
||||
SUBCASE("Stream operators")
|
||||
{
|
||||
SECTION("Int8")
|
||||
SUBCASE("Int8")
|
||||
{
|
||||
testPacketStreamOperators(sf::Int8(0));
|
||||
testPacketStreamOperators(sf::Int8(1));
|
||||
@ -25,7 +25,7 @@ TEST_CASE("sf::Packet class", "[network]")
|
||||
testPacketStreamOperators(std::numeric_limits<sf::Int8>::max());
|
||||
}
|
||||
|
||||
SECTION("Int16")
|
||||
SUBCASE("Int16")
|
||||
{
|
||||
testPacketStreamOperators(sf::Int16(0));
|
||||
testPacketStreamOperators(sf::Int16(1));
|
||||
@ -33,7 +33,7 @@ TEST_CASE("sf::Packet class", "[network]")
|
||||
testPacketStreamOperators(std::numeric_limits<sf::Int16>::max());
|
||||
}
|
||||
|
||||
SECTION("Int32")
|
||||
SUBCASE("Int32")
|
||||
{
|
||||
testPacketStreamOperators(sf::Int32(0));
|
||||
testPacketStreamOperators(sf::Int32(1));
|
||||
@ -41,7 +41,7 @@ TEST_CASE("sf::Packet class", "[network]")
|
||||
testPacketStreamOperators(std::numeric_limits<sf::Int32>::max());
|
||||
}
|
||||
|
||||
SECTION("Int64")
|
||||
SUBCASE("Int64")
|
||||
{
|
||||
testPacketStreamOperators(sf::Int64(0));
|
||||
testPacketStreamOperators(sf::Int64(1));
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include <SFML/System/Time.hpp>
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <ostream>
|
||||
#include <doctest.h>
|
||||
|
||||
using doctest::Approx;
|
||||
|
||||
namespace sf
|
||||
{
|
||||
@ -11,11 +14,11 @@ std::ostream& operator <<(std::ostream& os, const sf::Time& time)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("sf::Time class", "[system]")
|
||||
TEST_CASE("sf::Time class - [system]")
|
||||
{
|
||||
SECTION("Construction")
|
||||
SUBCASE("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
const sf::Time time;
|
||||
CHECK(time.asSeconds() == 0.0f);
|
||||
@ -23,7 +26,7 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
CHECK(time.asMicroseconds() == 0);
|
||||
}
|
||||
|
||||
SECTION("Construct from seconds")
|
||||
SUBCASE("Construct from seconds")
|
||||
{
|
||||
const sf::Time time = sf::seconds(123);
|
||||
CHECK(time.asSeconds() == 123.0f);
|
||||
@ -31,8 +34,8 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
CHECK(time.asMicroseconds() == 123'000'000);
|
||||
|
||||
CHECK(sf::seconds(1'000.0f).asMicroseconds() == 1'000'000'000);
|
||||
CHECK(sf::seconds(0.000002f).asMicroseconds() == Approx(2).margin(1));
|
||||
CHECK(sf::seconds(0.000001f).asMicroseconds() == Approx(1).margin(1));
|
||||
CHECK(sf::seconds(0.000002f).asMicroseconds() == Approx(2).epsilon(1.f));
|
||||
CHECK(sf::seconds(0.000001f).asMicroseconds() == Approx(1).epsilon(1.f));
|
||||
CHECK(sf::seconds(0.0000009f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(0.0000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(0.00000001f).asMicroseconds() == 0);
|
||||
@ -41,12 +44,12 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
CHECK(sf::seconds(-0.00000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-0.0000001f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-0.0000009f).asMicroseconds() == 0);
|
||||
CHECK(sf::seconds(-0.000001f).asMicroseconds() == Approx(-1).margin(1));
|
||||
CHECK(sf::seconds(-0.000002f).asMicroseconds() == Approx(-2).margin(1));
|
||||
CHECK(sf::seconds(-0.000001f).asMicroseconds() == Approx(-1).epsilon(1.f));
|
||||
CHECK(sf::seconds(-0.000002f).asMicroseconds() == Approx(-2).epsilon(1.f));
|
||||
CHECK(sf::seconds(-1'000.0f).asMicroseconds() == -1'000'000'000);
|
||||
}
|
||||
|
||||
SECTION("Construct from milliseconds")
|
||||
SUBCASE("Construct from milliseconds")
|
||||
{
|
||||
const sf::Time time = sf::milliseconds(42);
|
||||
CHECK(time.asSeconds() == 0.042f);
|
||||
@ -54,7 +57,7 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
CHECK(time.asMicroseconds() == 42'000);
|
||||
}
|
||||
|
||||
SECTION("Construct from microseconds")
|
||||
SUBCASE("Construct from microseconds")
|
||||
{
|
||||
const sf::Time time = sf::microseconds(987654);
|
||||
CHECK(time.asSeconds() == 0.987654f);
|
||||
@ -63,16 +66,16 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Zero time")
|
||||
SUBCASE("Zero time")
|
||||
{
|
||||
CHECK(sf::Time::Zero.asSeconds() == 0.0f);
|
||||
CHECK(sf::Time::Zero.asMilliseconds() == 0);
|
||||
CHECK(sf::Time::Zero.asMicroseconds() == 0);
|
||||
}
|
||||
|
||||
SECTION("Operators")
|
||||
SUBCASE("Operators")
|
||||
{
|
||||
SECTION("operator==")
|
||||
SUBCASE("operator==")
|
||||
{
|
||||
CHECK(sf::Time() == sf::Time());
|
||||
CHECK(sf::seconds(1) == sf::seconds(1));
|
||||
@ -81,71 +84,71 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
CHECK(sf::seconds(0.5f) == sf::microseconds(500'000));
|
||||
}
|
||||
|
||||
SECTION("operator!=")
|
||||
SUBCASE("operator!=")
|
||||
{
|
||||
CHECK(sf::seconds(10.12f) != sf::milliseconds(10'121));
|
||||
CHECK(sf::microseconds(123'456) != sf::milliseconds(123));
|
||||
}
|
||||
|
||||
SECTION("operator<")
|
||||
SUBCASE("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));
|
||||
}
|
||||
|
||||
SECTION("operator>")
|
||||
SUBCASE("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));
|
||||
}
|
||||
|
||||
SECTION("operator<=")
|
||||
SUBCASE("operator<=")
|
||||
{
|
||||
CHECK(sf::milliseconds(100) <= sf::milliseconds(100));
|
||||
CHECK(sf::seconds(0.0012f) <= sf::microseconds(1'201));
|
||||
}
|
||||
|
||||
SECTION("operator>=")
|
||||
SUBCASE("operator>=")
|
||||
{
|
||||
CHECK(sf::milliseconds(100) >= sf::milliseconds(-100));
|
||||
CHECK(sf::microseconds(1'201) >= sf::seconds(0.0012f));
|
||||
}
|
||||
|
||||
SECTION("operator-")
|
||||
SUBCASE("operator-")
|
||||
{
|
||||
CHECK(sf::seconds(-1) == -sf::seconds(1));
|
||||
CHECK(sf::microseconds(1'234) == -sf::microseconds(-1'234));
|
||||
}
|
||||
|
||||
SECTION("operator+")
|
||||
SUBCASE("operator+")
|
||||
{
|
||||
CHECK(sf::seconds(1) + sf::seconds(1) == sf::seconds(2));
|
||||
CHECK(sf::milliseconds(400) + sf::microseconds(400) == sf::microseconds(400400));
|
||||
}
|
||||
|
||||
SECTION("operator+=")
|
||||
SUBCASE("operator+=")
|
||||
{
|
||||
sf::Time time = sf::seconds(1.5f);
|
||||
time += sf::seconds(1);
|
||||
CHECK(time == sf::seconds(2.5f));
|
||||
}
|
||||
|
||||
SECTION("operator-")
|
||||
SUBCASE("operator-")
|
||||
{
|
||||
CHECK(sf::seconds(1) - sf::seconds(1) == sf::seconds(0));
|
||||
CHECK(sf::milliseconds(400) - sf::microseconds(400) == sf::microseconds(399600));
|
||||
}
|
||||
|
||||
SECTION("operator-=")
|
||||
SUBCASE("operator-=")
|
||||
{
|
||||
sf::Time time = sf::seconds(1.5f);
|
||||
time -= sf::seconds(10);
|
||||
CHECK(time == sf::seconds(-8.5f));
|
||||
}
|
||||
|
||||
SECTION("operator*")
|
||||
SUBCASE("operator*")
|
||||
{
|
||||
CHECK(sf::seconds(1) * 2.0f == sf::seconds(2));
|
||||
CHECK(sf::seconds(12) * 0.5f == sf::seconds(6));
|
||||
@ -157,16 +160,16 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
CHECK(static_cast<sf::Int64>(2) * sf::seconds(42) == sf::seconds(84));
|
||||
}
|
||||
|
||||
SECTION("operator*=")
|
||||
SUBCASE("operator*=")
|
||||
{
|
||||
sf::Time time = sf::milliseconds(420);
|
||||
time *= static_cast<sf::Int64>(10);
|
||||
CHECK(time == sf::milliseconds(4'200));
|
||||
time *= 0.1f;
|
||||
CHECK(time.asMicroseconds() == Approx(420'000).margin(1));
|
||||
CHECK(time.asMicroseconds() == Approx(420'000).epsilon(0.1f));
|
||||
}
|
||||
|
||||
SECTION("operator/")
|
||||
SUBCASE("operator/")
|
||||
{
|
||||
CHECK(sf::seconds(1) / 2.0f == sf::seconds(0.5f));
|
||||
CHECK(sf::seconds(12) / 0.5f == sf::seconds(24));
|
||||
@ -176,22 +179,22 @@ TEST_CASE("sf::Time class", "[system]")
|
||||
CHECK(sf::milliseconds(10) / sf::microseconds(1) == Approx(10'000.0f).epsilon(1e-6f));
|
||||
}
|
||||
|
||||
SECTION("operator/=")
|
||||
SUBCASE("operator/=")
|
||||
{
|
||||
sf::Time time = sf::milliseconds(420);
|
||||
time /= static_cast<sf::Int64>(42);
|
||||
CHECK(time == sf::milliseconds(10));
|
||||
time /= 10.0f;
|
||||
CHECK(time.asMicroseconds() == Approx(1'000).margin(1));
|
||||
CHECK(time.asMicroseconds() == Approx(1'000).epsilon(0.1f));
|
||||
}
|
||||
|
||||
SECTION("operator%")
|
||||
SUBCASE("operator%")
|
||||
{
|
||||
CHECK(sf::seconds(10) % sf::seconds(3) == sf::seconds(1));
|
||||
CHECK(sf::milliseconds(100) % sf::microseconds(10) == sf::seconds(0));
|
||||
}
|
||||
|
||||
SECTION("operator%=")
|
||||
SUBCASE("operator%=")
|
||||
{
|
||||
sf::Time time = sf::milliseconds(100);
|
||||
time %= sf::milliseconds(99);
|
||||
|
@ -4,25 +4,25 @@
|
||||
|
||||
// Use sf::Vector2i for tests. Test coverage is given, as there are no template specializations.
|
||||
|
||||
TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
TEST_CASE("sf::Vector2 class template - [system]")
|
||||
{
|
||||
SECTION("Construction")
|
||||
SUBCASE("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
sf::Vector2i vector;
|
||||
CHECK(vector.x == 0);
|
||||
CHECK(vector.y == 0);
|
||||
}
|
||||
|
||||
SECTION("(x, y) coordinate constructor")
|
||||
SUBCASE("(x, y) coordinate constructor")
|
||||
{
|
||||
sf::Vector2i vector(1, 2);
|
||||
CHECK(vector.x == 1);
|
||||
CHECK(vector.y == 2);
|
||||
}
|
||||
|
||||
SECTION("Conversion constructor")
|
||||
SUBCASE("Conversion constructor")
|
||||
{
|
||||
sf::Vector2f sourceVector(1.0f, 2.0f);
|
||||
sf::Vector2i vector(sourceVector);
|
||||
@ -32,9 +32,9 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Unary operations")
|
||||
SUBCASE("Unary operations")
|
||||
{
|
||||
SECTION("-vector")
|
||||
SUBCASE("-vector")
|
||||
{
|
||||
sf::Vector2i vector(1, 2);
|
||||
sf::Vector2i negatedVector = -vector;
|
||||
@ -44,12 +44,12 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Arithmetic operations between two vectors")
|
||||
SUBCASE("Arithmetic operations between two vectors")
|
||||
{
|
||||
sf::Vector2i firstVector(2, 5);
|
||||
sf::Vector2i secondVector(8, 3);
|
||||
|
||||
SECTION("vector += vector")
|
||||
SUBCASE("vector += vector")
|
||||
{
|
||||
firstVector += secondVector;
|
||||
|
||||
@ -57,7 +57,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(firstVector.y == 8);
|
||||
}
|
||||
|
||||
SECTION("vector -= vector")
|
||||
SUBCASE("vector -= vector")
|
||||
{
|
||||
firstVector -= secondVector;
|
||||
|
||||
@ -65,7 +65,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(firstVector.y == 2);
|
||||
}
|
||||
|
||||
SECTION("vector + vector")
|
||||
SUBCASE("vector + vector")
|
||||
{
|
||||
sf::Vector2i result = firstVector + secondVector;
|
||||
|
||||
@ -73,7 +73,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(result.y == 8);
|
||||
}
|
||||
|
||||
SECTION("vector - vector")
|
||||
SUBCASE("vector - vector")
|
||||
{
|
||||
sf::Vector2i result = firstVector - secondVector;
|
||||
|
||||
@ -82,12 +82,12 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Arithmetic operations between vector and scalar value")
|
||||
SUBCASE("Arithmetic operations between vector and scalar value")
|
||||
{
|
||||
sf::Vector2i vector(26, 12);
|
||||
int scalar = 2;
|
||||
|
||||
SECTION("vector * scalar")
|
||||
SUBCASE("vector * scalar")
|
||||
{
|
||||
sf::Vector2i result = vector * scalar;
|
||||
|
||||
@ -95,7 +95,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(result.y == 24);
|
||||
}
|
||||
|
||||
SECTION("scalar * vector")
|
||||
SUBCASE("scalar * vector")
|
||||
{
|
||||
sf::Vector2i result = scalar * vector;
|
||||
|
||||
@ -103,7 +103,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(result.y == 24);
|
||||
}
|
||||
|
||||
SECTION("vector *= scalar")
|
||||
SUBCASE("vector *= scalar")
|
||||
{
|
||||
vector *= scalar;
|
||||
|
||||
@ -111,7 +111,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(vector.y == 24);
|
||||
}
|
||||
|
||||
SECTION("vector / scalar")
|
||||
SUBCASE("vector / scalar")
|
||||
{
|
||||
sf::Vector2i result = vector / scalar;
|
||||
|
||||
@ -119,7 +119,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(result.y == 6);
|
||||
}
|
||||
|
||||
SECTION("vector /= scalar")
|
||||
SUBCASE("vector /= scalar")
|
||||
{
|
||||
vector /= scalar;
|
||||
|
||||
@ -128,30 +128,30 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Comparison operations (two equal and one different vector)")
|
||||
SUBCASE("Comparison operations (two equal and one different vector)")
|
||||
{
|
||||
sf::Vector2i firstEqualVector(1, 5);
|
||||
sf::Vector2i secondEqualVector(1, 5);
|
||||
sf::Vector2i differentVector(6, 9);
|
||||
|
||||
SECTION("vector == vector")
|
||||
SUBCASE("vector == vector")
|
||||
{
|
||||
CHECK(firstEqualVector == secondEqualVector);
|
||||
CHECK_FALSE(firstEqualVector == differentVector);
|
||||
}
|
||||
|
||||
SECTION("vector != vector")
|
||||
SUBCASE("vector != vector")
|
||||
{
|
||||
CHECK(firstEqualVector != differentVector);
|
||||
CHECK_FALSE(firstEqualVector != secondEqualVector);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Structured bindings")
|
||||
SUBCASE("Structured bindings")
|
||||
{
|
||||
sf::Vector2i vector(1, 2);
|
||||
|
||||
SECTION("destructure by value")
|
||||
SUBCASE("destructure by value")
|
||||
{
|
||||
auto [x, y] = vector;
|
||||
|
||||
@ -166,7 +166,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
CHECK(vector.x == 1);
|
||||
}
|
||||
|
||||
SECTION("destructure by ref")
|
||||
SUBCASE("destructure by ref")
|
||||
{
|
||||
auto& [x, y] = vector;
|
||||
|
||||
@ -182,7 +182,7 @@ TEST_CASE("sf::Vector2 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Constexpr support")
|
||||
SUBCASE("Constexpr support")
|
||||
{
|
||||
constexpr sf::Vector2i vector(1, 2);
|
||||
static_assert(vector.x == 1);
|
||||
|
@ -4,11 +4,11 @@
|
||||
|
||||
// Use sf::Vector3i for tests. Test coverage is given, as there are no template specializations.
|
||||
|
||||
TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
TEST_CASE("sf::Vector3 class template - [system]")
|
||||
{
|
||||
SECTION("Construction")
|
||||
SUBCASE("Construction")
|
||||
{
|
||||
SECTION("Default constructor")
|
||||
SUBCASE("Default constructor")
|
||||
{
|
||||
sf::Vector3i vector;
|
||||
CHECK(vector.x == 0);
|
||||
@ -16,7 +16,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(vector.z == 0);
|
||||
}
|
||||
|
||||
SECTION("(x, y, z) coordinate constructor")
|
||||
SUBCASE("(x, y, z) coordinate constructor")
|
||||
{
|
||||
sf::Vector3i vector(1, 2, 3);
|
||||
CHECK(vector.x == 1);
|
||||
@ -24,7 +24,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(vector.z == 3);
|
||||
}
|
||||
|
||||
SECTION("Conversion constructor")
|
||||
SUBCASE("Conversion constructor")
|
||||
{
|
||||
sf::Vector3f sourceVector(1.0f, 2.0f, 3.0f);
|
||||
sf::Vector3i vector(sourceVector);
|
||||
@ -35,9 +35,9 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Unary operations")
|
||||
SUBCASE("Unary operations")
|
||||
{
|
||||
SECTION("-vector")
|
||||
SUBCASE("-vector")
|
||||
{
|
||||
sf::Vector3i vector(1, 2, 3);
|
||||
sf::Vector3i negatedVector = -vector;
|
||||
@ -48,12 +48,12 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Arithmetic operations between two vectors")
|
||||
SUBCASE("Arithmetic operations between two vectors")
|
||||
{
|
||||
sf::Vector3i firstVector(2, 5, 6);
|
||||
sf::Vector3i secondVector(8, 3, 7);
|
||||
|
||||
SECTION("vector += vector")
|
||||
SUBCASE("vector += vector")
|
||||
{
|
||||
firstVector += secondVector;
|
||||
|
||||
@ -62,7 +62,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(firstVector.z == 13);
|
||||
}
|
||||
|
||||
SECTION("vector -= vector")
|
||||
SUBCASE("vector -= vector")
|
||||
{
|
||||
firstVector -= secondVector;
|
||||
|
||||
@ -71,7 +71,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(firstVector.z == -1);
|
||||
}
|
||||
|
||||
SECTION("vector + vector")
|
||||
SUBCASE("vector + vector")
|
||||
{
|
||||
sf::Vector3i result = firstVector + secondVector;
|
||||
|
||||
@ -80,7 +80,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(result.z == 13);
|
||||
}
|
||||
|
||||
SECTION("vector - vector")
|
||||
SUBCASE("vector - vector")
|
||||
{
|
||||
sf::Vector3i result = firstVector - secondVector;
|
||||
|
||||
@ -90,12 +90,12 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Arithmetic operations between vector and scalar value")
|
||||
SUBCASE("Arithmetic operations between vector and scalar value")
|
||||
{
|
||||
sf::Vector3i vector(26, 12, 6);
|
||||
int scalar = 2;
|
||||
|
||||
SECTION("vector * scalar")
|
||||
SUBCASE("vector * scalar")
|
||||
{
|
||||
sf::Vector3i result = vector * scalar;
|
||||
|
||||
@ -104,7 +104,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(result.z == 12);
|
||||
}
|
||||
|
||||
SECTION("scalar * vector")
|
||||
SUBCASE("scalar * vector")
|
||||
{
|
||||
sf::Vector3i result = scalar * vector;
|
||||
|
||||
@ -113,7 +113,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(result.z == 12);
|
||||
}
|
||||
|
||||
SECTION("vector *= scalar")
|
||||
SUBCASE("vector *= scalar")
|
||||
{
|
||||
vector *= scalar;
|
||||
|
||||
@ -122,7 +122,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(vector.z == 12);
|
||||
}
|
||||
|
||||
SECTION("vector / scalar")
|
||||
SUBCASE("vector / scalar")
|
||||
{
|
||||
sf::Vector3i result = vector / scalar;
|
||||
|
||||
@ -131,7 +131,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(result.z == 3);
|
||||
}
|
||||
|
||||
SECTION("vector /= scalar")
|
||||
SUBCASE("vector /= scalar")
|
||||
{
|
||||
vector /= scalar;
|
||||
|
||||
@ -141,30 +141,30 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Comparison operations (two equal and one different vector)")
|
||||
SUBCASE("Comparison operations (two equal and one different vector)")
|
||||
{
|
||||
sf::Vector3i firstEqualVector(1, 5, 6);
|
||||
sf::Vector3i secondEqualVector(1, 5, 6);
|
||||
sf::Vector3i differentVector(6, 9, 7);
|
||||
|
||||
SECTION("vector == vector")
|
||||
SUBCASE("vector == vector")
|
||||
{
|
||||
CHECK(firstEqualVector == secondEqualVector);
|
||||
CHECK_FALSE(firstEqualVector == differentVector);
|
||||
}
|
||||
|
||||
SECTION("vector != vector")
|
||||
SUBCASE("vector != vector")
|
||||
{
|
||||
CHECK(firstEqualVector != differentVector);
|
||||
CHECK_FALSE(firstEqualVector != secondEqualVector);
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Structured bindings")
|
||||
SUBCASE("Structured bindings")
|
||||
{
|
||||
sf::Vector3i vector(1, 2, 3);
|
||||
|
||||
SECTION("destructure by value")
|
||||
SUBCASE("destructure by value")
|
||||
{
|
||||
auto [x, y, z] = vector;
|
||||
|
||||
@ -180,7 +180,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
CHECK(vector.x == 1);
|
||||
}
|
||||
|
||||
SECTION("destructure by ref")
|
||||
SUBCASE("destructure by ref")
|
||||
{
|
||||
auto& [x, y, z] = vector;
|
||||
|
||||
@ -197,7 +197,7 @@ TEST_CASE("sf::Vector3 class template", "[system]")
|
||||
}
|
||||
}
|
||||
|
||||
SECTION("Constexpr support")
|
||||
SUBCASE("Constexpr support")
|
||||
{
|
||||
constexpr sf::Vector3i vector(1, 2, 3);
|
||||
static_assert(vector.x == 1);
|
||||
|
@ -1,11 +1,11 @@
|
||||
// Note: No need to increase compile time by including TestUtilities/Graphics.hpp
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <sstream>
|
||||
#include <doctest.h>
|
||||
|
||||
// String conversions for Catch framework
|
||||
namespace Catch
|
||||
namespace sf
|
||||
{
|
||||
std::string toString(const sf::Color& color)
|
||||
doctest::String toString(const sf::Color& color)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "0x" << std::hex << color.toInteger() << std::dec
|
||||
@ -14,6 +14,6 @@ namespace Catch
|
||||
<< ", b=" << static_cast<int>(color.b)
|
||||
<< ", a=" << static_cast<int>(color.a) << ")";
|
||||
|
||||
return stream.str();
|
||||
return stream.str().c_str();
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,22 @@
|
||||
// Header for SFML unit tests.
|
||||
//
|
||||
// For a new graphics module test case, include this header and not <catch.hpp> directly.
|
||||
// This ensures that string conversions are visible and can be used by Catch for debug output.
|
||||
// For a new graphics module test case, include this header and not <doctest.h> directly.
|
||||
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
||||
|
||||
#ifndef SFML_TESTUTILITIES_GRAPHICS_HPP
|
||||
#define SFML_TESTUTILITIES_GRAPHICS_HPP
|
||||
|
||||
#include "WindowUtil.hpp"
|
||||
|
||||
// Forward declarations for non-template types
|
||||
namespace doctest
|
||||
{
|
||||
class String;
|
||||
}
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class Color;
|
||||
}
|
||||
|
||||
// String conversions for Catch framework
|
||||
namespace Catch
|
||||
{
|
||||
std::string toString(const sf::Color& color);
|
||||
doctest::String toString(const Color& color);
|
||||
}
|
||||
|
||||
#endif // SFML_TESTUTILITIES_GRAPHICS_HPP
|
||||
|
@ -3,18 +3,19 @@
|
||||
#include <SFML/System/Time.hpp>
|
||||
#include <sstream>
|
||||
|
||||
// String conversions for Catch framework
|
||||
namespace Catch
|
||||
#include <doctest.h>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
std::string toString(const sf::String& string)
|
||||
doctest::String toString(const sf::String& string)
|
||||
{
|
||||
return string.toAnsiString();
|
||||
return string.toAnsiString().c_str();
|
||||
}
|
||||
|
||||
std::string toString(sf::Time time)
|
||||
doctest::String toString(sf::Time time)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << time.asMicroseconds() << "us";
|
||||
return stream.str();
|
||||
return stream.str().c_str();
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +1,40 @@
|
||||
// Header for SFML unit tests.
|
||||
//
|
||||
// For a new system module test case, include this header and not <catch.hpp> directly.
|
||||
// This ensures that string conversions are visible and can be used by Catch for debug output.
|
||||
// For a new system module test case, include this header and not <doctest.h> directly.
|
||||
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
||||
|
||||
#ifndef SFML_TESTUTILITIES_SYSTEM_HPP
|
||||
#define SFML_TESTUTILITIES_SYSTEM_HPP
|
||||
|
||||
#include <catch2/catch.hpp>
|
||||
#include <doctest.h>
|
||||
|
||||
#include <SFML/System/Vector2.hpp>
|
||||
#include <SFML/System/Vector3.hpp>
|
||||
#include <sstream>
|
||||
|
||||
// Forward declarations for non-template types
|
||||
// String conversions for doctest framework
|
||||
namespace sf
|
||||
{
|
||||
class String;
|
||||
class Time;
|
||||
}
|
||||
|
||||
// String conversions for Catch framework
|
||||
namespace Catch
|
||||
{
|
||||
std::string toString(const sf::String& string);
|
||||
std::string toString(sf::Time time);
|
||||
doctest::String toString(const sf::String& string);
|
||||
doctest::String toString(sf::Time time);
|
||||
|
||||
template <typename T>
|
||||
std::string toString(const sf::Vector2<T>& vector)
|
||||
doctest::String toString(const sf::Vector2<T>& vector)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "(" << vector.x << ", " << vector.y << ")";
|
||||
return stream.str();
|
||||
return stream.str().c_str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string toString(const sf::Vector3<T>& vector)
|
||||
doctest::String toString(const sf::Vector3<T>& vector)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
|
||||
return stream.str();
|
||||
return stream.str().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,14 @@
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <sstream>
|
||||
|
||||
// String conversions for Catch framework
|
||||
namespace Catch
|
||||
#include <doctest.h>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
std::string toString(const sf::VideoMode& videoMode)
|
||||
doctest::String toString(const sf::VideoMode& videoMode)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << videoMode.width << "x" << videoMode.height << "x" << videoMode.bitsPerPixel;
|
||||
return stream.str();
|
||||
return stream.str().c_str();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Header for SFML unit tests.
|
||||
//
|
||||
// For a new window module test case, include this header and not <catch.hpp> directly.
|
||||
// This ensures that string conversions are visible and can be used by Catch for debug output.
|
||||
// For a new window module test case, include this header and not <doctest.h> directly.
|
||||
// This ensures that string conversions are visible and can be used by doctest for debug output.
|
||||
|
||||
#ifndef SFML_TESTUTILITIES_WINDOW_HPP
|
||||
#define SFML_TESTUTILITIES_WINDOW_HPP
|
||||
@ -10,23 +10,21 @@
|
||||
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
|
||||
// Forward declarations for non-template types
|
||||
#include <doctest.h>
|
||||
|
||||
// String conversions for doctest framework
|
||||
namespace sf
|
||||
{
|
||||
class VideoMode;
|
||||
}
|
||||
|
||||
// String conversions for Catch framework
|
||||
namespace Catch
|
||||
{
|
||||
std::string toString(const sf::VideoMode& videoMode);
|
||||
doctest::String toString(const sf::VideoMode& videoMode);
|
||||
|
||||
template <typename T>
|
||||
std::string toString(const sf::Rect<T>& rect)
|
||||
doctest::String toString(const sf::Rect<T>& rect)
|
||||
{
|
||||
std::ostringstream stream;
|
||||
stream << "(left=" << rect.left << ", top=" << rect.top << ", width=" << rect.width << ", height=" << rect.height << ")";
|
||||
return stream.str();
|
||||
return stream.str().c_str();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user