Apply compiler warnings to tests

This commit is contained in:
Chris Thrasher 2022-04-04 12:35:35 -06:00 committed by Lukas Dürrenberger
parent 8a4563361f
commit 2a5ce3c989
6 changed files with 59 additions and 61 deletions

View File

@ -329,6 +329,8 @@ function(sfml_add_test target SOURCES DEPENDS)
# link the target to its SFML dependencies # link the target to its SFML dependencies
target_link_libraries(${target} PRIVATE ${DEPENDS} sfml-test-main) target_link_libraries(${target} PRIVATE ${DEPENDS} sfml-test-main)
set_target_warnings(${target})
# If coverage is enabled for MSVC and we are linking statically, use /WHOLEARCHIVE # If coverage is enabled for MSVC and we are linking statically, use /WHOLEARCHIVE
# to make sure the linker doesn't discard unused code sections before coverage can be measured # to make sure the linker doesn't discard unused code sections before coverage can be measured
if (SFML_ENABLE_COVERAGE AND SFML_COMPILER_MSVC AND NOT BUILD_SHARED_LIBS) if (SFML_ENABLE_COVERAGE AND SFML_COMPILER_MSVC AND NOT BUILD_SHARED_LIBS)

View File

@ -93,9 +93,9 @@ TEST_CASE("sf::Shape class - [graphics]")
triangleShape.move({1, 1}); triangleShape.move({1, 1});
triangleShape.rotate(sf::degrees(90)); triangleShape.rotate(sf::degrees(90));
CHECK(triangleShape.getLocalBounds() == sf::FloatRect({0, 0}, {2, 3})); CHECK(triangleShape.getLocalBounds() == sf::FloatRect({0, 0}, {2, 3}));
CHECK(triangleShape.getGlobalBounds().left == Approx(-2.f)); CHECK(triangleShape.getGlobalBounds().left == Approx(-2.));
CHECK(triangleShape.getGlobalBounds().top == Approx(1.f)); CHECK(triangleShape.getGlobalBounds().top == Approx(1.));
CHECK(triangleShape.getGlobalBounds().width == Approx(3.f)); CHECK(triangleShape.getGlobalBounds().width == Approx(3.));
CHECK(triangleShape.getGlobalBounds().height == Approx(2.f)); CHECK(triangleShape.getGlobalBounds().height == Approx(2.));
} }
} }

View File

@ -44,40 +44,40 @@ TEST_CASE("sf::Transformable class - [graphics]")
transform.rotate(transformable.getRotation(), transformable.getOrigin()); transform.rotate(transformable.getRotation(), transformable.getOrigin());
transform.scale(transformable.getScale(), transformable.getOrigin()); transform.scale(transformable.getScale(), transformable.getOrigin());
CHECK(transformable.getTransform().getMatrix()[0] == Approx(transform.getMatrix()[0])); CHECK(transformable.getTransform().getMatrix()[0] == Approx(static_cast<double>(transform.getMatrix()[0])));
CHECK(transformable.getTransform().getMatrix()[1] == Approx(transform.getMatrix()[1])); CHECK(transformable.getTransform().getMatrix()[1] == Approx(static_cast<double>(transform.getMatrix()[1])));
CHECK(transformable.getTransform().getMatrix()[2] == Approx(transform.getMatrix()[2])); CHECK(transformable.getTransform().getMatrix()[2] == Approx(static_cast<double>(transform.getMatrix()[2])));
CHECK(transformable.getTransform().getMatrix()[3] == Approx(transform.getMatrix()[3])); CHECK(transformable.getTransform().getMatrix()[3] == Approx(static_cast<double>(transform.getMatrix()[3])));
CHECK(transformable.getTransform().getMatrix()[4] == Approx(transform.getMatrix()[4])); CHECK(transformable.getTransform().getMatrix()[4] == Approx(static_cast<double>(transform.getMatrix()[4])));
CHECK(transformable.getTransform().getMatrix()[5] == Approx(transform.getMatrix()[5])); CHECK(transformable.getTransform().getMatrix()[5] == Approx(static_cast<double>(transform.getMatrix()[5])));
CHECK(transformable.getTransform().getMatrix()[6] == Approx(transform.getMatrix()[6])); CHECK(transformable.getTransform().getMatrix()[6] == Approx(static_cast<double>(transform.getMatrix()[6])));
CHECK(transformable.getTransform().getMatrix()[7] == Approx(transform.getMatrix()[7])); CHECK(transformable.getTransform().getMatrix()[7] == Approx(static_cast<double>(transform.getMatrix()[7])));
CHECK(transformable.getTransform().getMatrix()[8] == Approx(transform.getMatrix()[8])); CHECK(transformable.getTransform().getMatrix()[8] == Approx(static_cast<double>(transform.getMatrix()[8])));
CHECK(transformable.getTransform().getMatrix()[9] == Approx(transform.getMatrix()[9])); CHECK(transformable.getTransform().getMatrix()[9] == Approx(static_cast<double>(transform.getMatrix()[9])));
CHECK(transformable.getTransform().getMatrix()[10] == Approx(transform.getMatrix()[10])); CHECK(transformable.getTransform().getMatrix()[10] == Approx(static_cast<double>(transform.getMatrix()[10])));
CHECK(transformable.getTransform().getMatrix()[11] == Approx(transform.getMatrix()[11])); CHECK(transformable.getTransform().getMatrix()[11] == Approx(static_cast<double>(transform.getMatrix()[11])));
CHECK(transformable.getTransform().getMatrix()[12] == Approx(transform.getMatrix()[12])); CHECK(transformable.getTransform().getMatrix()[12] == Approx(static_cast<double>(transform.getMatrix()[12])));
CHECK(transformable.getTransform().getMatrix()[13] == Approx(transform.getMatrix()[13])); CHECK(transformable.getTransform().getMatrix()[13] == Approx(static_cast<double>(transform.getMatrix()[13])));
CHECK(transformable.getTransform().getMatrix()[14] == Approx(transform.getMatrix()[14])); CHECK(transformable.getTransform().getMatrix()[14] == Approx(static_cast<double>(transform.getMatrix()[14])));
CHECK(transformable.getTransform().getMatrix()[15] == Approx(transform.getMatrix()[15])); CHECK(transformable.getTransform().getMatrix()[15] == Approx(static_cast<double>(transform.getMatrix()[15])));
const sf::Transform inverse_transform = transform.getInverse(); const sf::Transform inverse_transform = transform.getInverse();
CHECK(transformable.getInverseTransform().getMatrix()[0] == Approx(inverse_transform.getMatrix()[0])); CHECK(transformable.getInverseTransform().getMatrix()[0] == Approx(static_cast<double>(inverse_transform.getMatrix()[0])));
CHECK(transformable.getInverseTransform().getMatrix()[1] == Approx(inverse_transform.getMatrix()[1])); CHECK(transformable.getInverseTransform().getMatrix()[1] == Approx(static_cast<double>(inverse_transform.getMatrix()[1])));
CHECK(transformable.getInverseTransform().getMatrix()[2] == Approx(inverse_transform.getMatrix()[2])); CHECK(transformable.getInverseTransform().getMatrix()[2] == Approx(static_cast<double>(inverse_transform.getMatrix()[2])));
CHECK(transformable.getInverseTransform().getMatrix()[3] == Approx(inverse_transform.getMatrix()[3])); CHECK(transformable.getInverseTransform().getMatrix()[3] == Approx(static_cast<double>(inverse_transform.getMatrix()[3])));
CHECK(transformable.getInverseTransform().getMatrix()[4] == Approx(inverse_transform.getMatrix()[4])); CHECK(transformable.getInverseTransform().getMatrix()[4] == Approx(static_cast<double>(inverse_transform.getMatrix()[4])));
CHECK(transformable.getInverseTransform().getMatrix()[5] == Approx(inverse_transform.getMatrix()[5])); CHECK(transformable.getInverseTransform().getMatrix()[5] == Approx(static_cast<double>(inverse_transform.getMatrix()[5])));
CHECK(transformable.getInverseTransform().getMatrix()[6] == Approx(inverse_transform.getMatrix()[6])); CHECK(transformable.getInverseTransform().getMatrix()[6] == Approx(static_cast<double>(inverse_transform.getMatrix()[6])));
CHECK(transformable.getInverseTransform().getMatrix()[7] == Approx(inverse_transform.getMatrix()[7])); CHECK(transformable.getInverseTransform().getMatrix()[7] == Approx(static_cast<double>(inverse_transform.getMatrix()[7])));
CHECK(transformable.getInverseTransform().getMatrix()[8] == Approx(inverse_transform.getMatrix()[8])); CHECK(transformable.getInverseTransform().getMatrix()[8] == Approx(static_cast<double>(inverse_transform.getMatrix()[8])));
CHECK(transformable.getInverseTransform().getMatrix()[9] == Approx(inverse_transform.getMatrix()[9])); CHECK(transformable.getInverseTransform().getMatrix()[9] == Approx(static_cast<double>(inverse_transform.getMatrix()[9])));
CHECK(transformable.getInverseTransform().getMatrix()[10] == Approx(inverse_transform.getMatrix()[10])); CHECK(transformable.getInverseTransform().getMatrix()[10] == Approx(static_cast<double>(inverse_transform.getMatrix()[10])));
CHECK(transformable.getInverseTransform().getMatrix()[11] == Approx(inverse_transform.getMatrix()[11])); CHECK(transformable.getInverseTransform().getMatrix()[11] == Approx(static_cast<double>(inverse_transform.getMatrix()[11])));
CHECK(transformable.getInverseTransform().getMatrix()[12] == Approx(inverse_transform.getMatrix()[12])); CHECK(transformable.getInverseTransform().getMatrix()[12] == Approx(static_cast<double>(inverse_transform.getMatrix()[12])));
CHECK(transformable.getInverseTransform().getMatrix()[13] == Approx(inverse_transform.getMatrix()[13])); CHECK(transformable.getInverseTransform().getMatrix()[13] == Approx(static_cast<double>(inverse_transform.getMatrix()[13])));
CHECK(transformable.getInverseTransform().getMatrix()[14] == Approx(inverse_transform.getMatrix()[14])); CHECK(transformable.getInverseTransform().getMatrix()[14] == Approx(static_cast<double>(inverse_transform.getMatrix()[14])));
CHECK(transformable.getInverseTransform().getMatrix()[15] == Approx(inverse_transform.getMatrix()[15])); CHECK(transformable.getInverseTransform().getMatrix()[15] == Approx(static_cast<double>(inverse_transform.getMatrix()[15])));
} }
SUBCASE("move()") SUBCASE("move()")

View File

@ -52,30 +52,30 @@ TEST_CASE("sf::Angle class - [system]")
{ {
const sf::Angle angle = sf::degrees(15); const sf::Angle angle = sf::degrees(15);
CHECK(angle == sf::degrees(15)); CHECK(angle == sf::degrees(15));
CHECK(angle.asRadians() == Approx(0.26179939f)); CHECK(angle.asRadians() == Approx(0.26179939));
const sf::Angle bigAngle = sf::degrees(1000); const sf::Angle bigAngle = sf::degrees(1000);
CHECK(bigAngle == sf::degrees(1000)); CHECK(bigAngle == sf::degrees(1000));
CHECK(bigAngle.asRadians() == Approx(17.453293f)); CHECK(bigAngle.asRadians() == Approx(17.453293));
const sf::Angle bigNegativeAngle = sf::degrees(-4321); const sf::Angle bigNegativeAngle = sf::degrees(-4321);
CHECK(bigNegativeAngle == sf::degrees(-4321)); CHECK(bigNegativeAngle == sf::degrees(-4321));
CHECK(bigNegativeAngle.asRadians() == Approx(-75.415677f)); CHECK(bigNegativeAngle.asRadians() == Approx(-75.415677));
} }
SUBCASE("radians()") SUBCASE("radians()")
{ {
const sf::Angle angle = sf::radians(1); const sf::Angle angle = sf::radians(1);
CHECK(angle.asDegrees() == Approx(57.2957795f)); CHECK(angle.asDegrees() == Approx(57.2957795));
CHECK(angle.asRadians() == Approx(1.0f)); CHECK(angle.asRadians() == Approx(1.0));
const sf::Angle bigAngle = sf::radians(72); const sf::Angle bigAngle = sf::radians(72);
CHECK(bigAngle.asDegrees() == Approx(4125.29612f)); CHECK(bigAngle.asDegrees() == Approx(4125.29612));
CHECK(bigAngle.asRadians() == Approx(72.0f)); CHECK(bigAngle.asRadians() == Approx(72.0));
const sf::Angle bigNegativeAngle = sf::radians(-200); const sf::Angle bigNegativeAngle = sf::radians(-200);
CHECK(bigNegativeAngle.asDegrees() == Approx(-11459.1559f)); CHECK(bigNegativeAngle.asDegrees() == Approx(-11459.1559));
CHECK(bigNegativeAngle.asRadians() == Approx(-200.0f)); CHECK(bigNegativeAngle.asRadians() == Approx(-200.0));
} }
} }
@ -228,7 +228,7 @@ TEST_CASE("sf::Angle class - [system]")
CHECK(sf::Angle::Zero / sf::degrees(1) == 0); CHECK(sf::Angle::Zero / sf::degrees(1) == 0);
CHECK(sf::degrees(10) / sf::degrees(10) == 1); CHECK(sf::degrees(10) / sf::degrees(10) == 1);
CHECK(sf::radians(10) / sf::radians(2) == Approx(5.0f)); CHECK(sf::radians(10) / sf::radians(2) == Approx(5.0));
} }
SUBCASE("operator/=") SUBCASE("operator/=")

View File

@ -25,8 +25,6 @@ TEST_CASE("sf::Time class - [system]")
CHECK(time.asMicroseconds() == 123'000'000); CHECK(time.asMicroseconds() == 123'000'000);
CHECK(sf::seconds(1'000.0f).asMicroseconds() == 1'000'000'000); CHECK(sf::seconds(1'000.0f).asMicroseconds() == 1'000'000'000);
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.0000009f).asMicroseconds() == 0);
CHECK(sf::seconds(0.0000001f).asMicroseconds() == 0); CHECK(sf::seconds(0.0000001f).asMicroseconds() == 0);
CHECK(sf::seconds(0.00000001f).asMicroseconds() == 0); CHECK(sf::seconds(0.00000001f).asMicroseconds() == 0);
@ -35,8 +33,6 @@ TEST_CASE("sf::Time class - [system]")
CHECK(sf::seconds(-0.00000001f).asMicroseconds() == 0); CHECK(sf::seconds(-0.00000001f).asMicroseconds() == 0);
CHECK(sf::seconds(-0.0000001f).asMicroseconds() == 0); CHECK(sf::seconds(-0.0000001f).asMicroseconds() == 0);
CHECK(sf::seconds(-0.0000009f).asMicroseconds() == 0); CHECK(sf::seconds(-0.0000009f).asMicroseconds() == 0);
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); CHECK(sf::seconds(-1'000.0f).asMicroseconds() == -1'000'000'000);
} }
@ -153,11 +149,11 @@ TEST_CASE("sf::Time class - [system]")
SUBCASE("operator*=") SUBCASE("operator*=")
{ {
sf::Time time = sf::milliseconds(420); sf::Time time = sf::milliseconds(1'000);
time *= static_cast<sf::Int64>(10); time *= static_cast<sf::Int64>(10);
CHECK(time == sf::milliseconds(4'200)); CHECK(time == sf::milliseconds(10'000));
time *= 0.1f; time *= 0.1f;
CHECK(time.asMicroseconds() == Approx(420'000).epsilon(0.1f)); CHECK(time.asMilliseconds() == 1'000);
} }
SUBCASE("operator/") SUBCASE("operator/")
@ -167,16 +163,16 @@ TEST_CASE("sf::Time class - [system]")
CHECK(sf::seconds(1) / static_cast<sf::Int64>(2) == sf::seconds(0.5f)); CHECK(sf::seconds(1) / static_cast<sf::Int64>(2) == sf::seconds(0.5f));
CHECK(sf::seconds(42) / static_cast<sf::Int64>(2) == sf::seconds(21)); CHECK(sf::seconds(42) / static_cast<sf::Int64>(2) == sf::seconds(21));
CHECK(sf::seconds(1) / sf::seconds(1) == 1.0f); CHECK(sf::seconds(1) / sf::seconds(1) == 1.0f);
CHECK(sf::milliseconds(10) / sf::microseconds(1) == Approx(10'000.0f).epsilon(1e-6f)); CHECK(sf::milliseconds(10) / sf::microseconds(1) == Approx(10'000.0).epsilon(1e-6));
} }
SUBCASE("operator/=") SUBCASE("operator/=")
{ {
sf::Time time = sf::milliseconds(420); sf::Time time = sf::milliseconds(1'000);
time /= static_cast<sf::Int64>(42); time /= static_cast<sf::Int64>(2);
CHECK(time == sf::milliseconds(10)); CHECK(time == sf::milliseconds(500));
time /= 10.0f; time /= 0.5f;
CHECK(time.asMicroseconds() == Approx(1'000).epsilon(0.1f)); CHECK(time.asMilliseconds() == 1'000);
} }
SUBCASE("operator%") SUBCASE("operator%")

View File

@ -54,8 +54,8 @@ struct ApproxVec
// Utilities for approximate equality // Utilities for approximate equality
struct ApproxDeg struct ApproxDeg
{ {
ApproxDeg(double degrees) ApproxDeg(double deg)
: degrees(static_cast<float>(degrees)) {} : degrees(static_cast<float>(deg)) {}
float degrees; float degrees;
}; };