From 2a5ce3c989b022a82356b09c0daa6234c54ca5e7 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 4 Apr 2022 12:35:35 -0600 Subject: [PATCH] Apply compiler warnings to tests --- cmake/Macros.cmake | 2 + test/Graphics/Shape.cpp | 8 ++-- test/Graphics/Transformable.cpp | 64 +++++++++++++++---------------- test/System/Angle.cpp | 20 +++++----- test/System/Time.cpp | 22 +++++------ test/TestUtilities/SystemUtil.hpp | 4 +- 6 files changed, 59 insertions(+), 61 deletions(-) diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index 038cb973..40bc5591 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -329,6 +329,8 @@ function(sfml_add_test target SOURCES DEPENDS) # link the target to its SFML dependencies 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 # 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) diff --git a/test/Graphics/Shape.cpp b/test/Graphics/Shape.cpp index 8da42ab3..fc6ba6e5 100644 --- a/test/Graphics/Shape.cpp +++ b/test/Graphics/Shape.cpp @@ -93,9 +93,9 @@ TEST_CASE("sf::Shape class - [graphics]") triangleShape.move({1, 1}); triangleShape.rotate(sf::degrees(90)); CHECK(triangleShape.getLocalBounds() == sf::FloatRect({0, 0}, {2, 3})); - CHECK(triangleShape.getGlobalBounds().left == Approx(-2.f)); - CHECK(triangleShape.getGlobalBounds().top == Approx(1.f)); - CHECK(triangleShape.getGlobalBounds().width == Approx(3.f)); - CHECK(triangleShape.getGlobalBounds().height == Approx(2.f)); + CHECK(triangleShape.getGlobalBounds().left == Approx(-2.)); + CHECK(triangleShape.getGlobalBounds().top == Approx(1.)); + CHECK(triangleShape.getGlobalBounds().width == Approx(3.)); + CHECK(triangleShape.getGlobalBounds().height == Approx(2.)); } } diff --git a/test/Graphics/Transformable.cpp b/test/Graphics/Transformable.cpp index b4da5139..4ab7b825 100644 --- a/test/Graphics/Transformable.cpp +++ b/test/Graphics/Transformable.cpp @@ -44,40 +44,40 @@ TEST_CASE("sf::Transformable class - [graphics]") transform.rotate(transformable.getRotation(), transformable.getOrigin()); transform.scale(transformable.getScale(), transformable.getOrigin()); - CHECK(transformable.getTransform().getMatrix()[0] == Approx(transform.getMatrix()[0])); - CHECK(transformable.getTransform().getMatrix()[1] == Approx(transform.getMatrix()[1])); - CHECK(transformable.getTransform().getMatrix()[2] == Approx(transform.getMatrix()[2])); - CHECK(transformable.getTransform().getMatrix()[3] == Approx(transform.getMatrix()[3])); - CHECK(transformable.getTransform().getMatrix()[4] == Approx(transform.getMatrix()[4])); - CHECK(transformable.getTransform().getMatrix()[5] == Approx(transform.getMatrix()[5])); - CHECK(transformable.getTransform().getMatrix()[6] == Approx(transform.getMatrix()[6])); - CHECK(transformable.getTransform().getMatrix()[7] == Approx(transform.getMatrix()[7])); - CHECK(transformable.getTransform().getMatrix()[8] == Approx(transform.getMatrix()[8])); - CHECK(transformable.getTransform().getMatrix()[9] == Approx(transform.getMatrix()[9])); - CHECK(transformable.getTransform().getMatrix()[10] == Approx(transform.getMatrix()[10])); - CHECK(transformable.getTransform().getMatrix()[11] == Approx(transform.getMatrix()[11])); - CHECK(transformable.getTransform().getMatrix()[12] == Approx(transform.getMatrix()[12])); - CHECK(transformable.getTransform().getMatrix()[13] == Approx(transform.getMatrix()[13])); - CHECK(transformable.getTransform().getMatrix()[14] == Approx(transform.getMatrix()[14])); - CHECK(transformable.getTransform().getMatrix()[15] == Approx(transform.getMatrix()[15])); + CHECK(transformable.getTransform().getMatrix()[0] == Approx(static_cast(transform.getMatrix()[0]))); + CHECK(transformable.getTransform().getMatrix()[1] == Approx(static_cast(transform.getMatrix()[1]))); + CHECK(transformable.getTransform().getMatrix()[2] == Approx(static_cast(transform.getMatrix()[2]))); + CHECK(transformable.getTransform().getMatrix()[3] == Approx(static_cast(transform.getMatrix()[3]))); + CHECK(transformable.getTransform().getMatrix()[4] == Approx(static_cast(transform.getMatrix()[4]))); + CHECK(transformable.getTransform().getMatrix()[5] == Approx(static_cast(transform.getMatrix()[5]))); + CHECK(transformable.getTransform().getMatrix()[6] == Approx(static_cast(transform.getMatrix()[6]))); + CHECK(transformable.getTransform().getMatrix()[7] == Approx(static_cast(transform.getMatrix()[7]))); + CHECK(transformable.getTransform().getMatrix()[8] == Approx(static_cast(transform.getMatrix()[8]))); + CHECK(transformable.getTransform().getMatrix()[9] == Approx(static_cast(transform.getMatrix()[9]))); + CHECK(transformable.getTransform().getMatrix()[10] == Approx(static_cast(transform.getMatrix()[10]))); + CHECK(transformable.getTransform().getMatrix()[11] == Approx(static_cast(transform.getMatrix()[11]))); + CHECK(transformable.getTransform().getMatrix()[12] == Approx(static_cast(transform.getMatrix()[12]))); + CHECK(transformable.getTransform().getMatrix()[13] == Approx(static_cast(transform.getMatrix()[13]))); + CHECK(transformable.getTransform().getMatrix()[14] == Approx(static_cast(transform.getMatrix()[14]))); + CHECK(transformable.getTransform().getMatrix()[15] == Approx(static_cast(transform.getMatrix()[15]))); const sf::Transform inverse_transform = transform.getInverse(); - CHECK(transformable.getInverseTransform().getMatrix()[0] == Approx(inverse_transform.getMatrix()[0])); - CHECK(transformable.getInverseTransform().getMatrix()[1] == Approx(inverse_transform.getMatrix()[1])); - CHECK(transformable.getInverseTransform().getMatrix()[2] == Approx(inverse_transform.getMatrix()[2])); - CHECK(transformable.getInverseTransform().getMatrix()[3] == Approx(inverse_transform.getMatrix()[3])); - CHECK(transformable.getInverseTransform().getMatrix()[4] == Approx(inverse_transform.getMatrix()[4])); - CHECK(transformable.getInverseTransform().getMatrix()[5] == Approx(inverse_transform.getMatrix()[5])); - CHECK(transformable.getInverseTransform().getMatrix()[6] == Approx(inverse_transform.getMatrix()[6])); - CHECK(transformable.getInverseTransform().getMatrix()[7] == Approx(inverse_transform.getMatrix()[7])); - CHECK(transformable.getInverseTransform().getMatrix()[8] == Approx(inverse_transform.getMatrix()[8])); - CHECK(transformable.getInverseTransform().getMatrix()[9] == Approx(inverse_transform.getMatrix()[9])); - CHECK(transformable.getInverseTransform().getMatrix()[10] == Approx(inverse_transform.getMatrix()[10])); - CHECK(transformable.getInverseTransform().getMatrix()[11] == Approx(inverse_transform.getMatrix()[11])); - CHECK(transformable.getInverseTransform().getMatrix()[12] == Approx(inverse_transform.getMatrix()[12])); - CHECK(transformable.getInverseTransform().getMatrix()[13] == Approx(inverse_transform.getMatrix()[13])); - CHECK(transformable.getInverseTransform().getMatrix()[14] == Approx(inverse_transform.getMatrix()[14])); - CHECK(transformable.getInverseTransform().getMatrix()[15] == Approx(inverse_transform.getMatrix()[15])); + CHECK(transformable.getInverseTransform().getMatrix()[0] == Approx(static_cast(inverse_transform.getMatrix()[0]))); + CHECK(transformable.getInverseTransform().getMatrix()[1] == Approx(static_cast(inverse_transform.getMatrix()[1]))); + CHECK(transformable.getInverseTransform().getMatrix()[2] == Approx(static_cast(inverse_transform.getMatrix()[2]))); + CHECK(transformable.getInverseTransform().getMatrix()[3] == Approx(static_cast(inverse_transform.getMatrix()[3]))); + CHECK(transformable.getInverseTransform().getMatrix()[4] == Approx(static_cast(inverse_transform.getMatrix()[4]))); + CHECK(transformable.getInverseTransform().getMatrix()[5] == Approx(static_cast(inverse_transform.getMatrix()[5]))); + CHECK(transformable.getInverseTransform().getMatrix()[6] == Approx(static_cast(inverse_transform.getMatrix()[6]))); + CHECK(transformable.getInverseTransform().getMatrix()[7] == Approx(static_cast(inverse_transform.getMatrix()[7]))); + CHECK(transformable.getInverseTransform().getMatrix()[8] == Approx(static_cast(inverse_transform.getMatrix()[8]))); + CHECK(transformable.getInverseTransform().getMatrix()[9] == Approx(static_cast(inverse_transform.getMatrix()[9]))); + CHECK(transformable.getInverseTransform().getMatrix()[10] == Approx(static_cast(inverse_transform.getMatrix()[10]))); + CHECK(transformable.getInverseTransform().getMatrix()[11] == Approx(static_cast(inverse_transform.getMatrix()[11]))); + CHECK(transformable.getInverseTransform().getMatrix()[12] == Approx(static_cast(inverse_transform.getMatrix()[12]))); + CHECK(transformable.getInverseTransform().getMatrix()[13] == Approx(static_cast(inverse_transform.getMatrix()[13]))); + CHECK(transformable.getInverseTransform().getMatrix()[14] == Approx(static_cast(inverse_transform.getMatrix()[14]))); + CHECK(transformable.getInverseTransform().getMatrix()[15] == Approx(static_cast(inverse_transform.getMatrix()[15]))); } SUBCASE("move()") diff --git a/test/System/Angle.cpp b/test/System/Angle.cpp index f4c249cb..b9948ffa 100644 --- a/test/System/Angle.cpp +++ b/test/System/Angle.cpp @@ -52,30 +52,30 @@ TEST_CASE("sf::Angle class - [system]") { const sf::Angle 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); CHECK(bigAngle == sf::degrees(1000)); - CHECK(bigAngle.asRadians() == Approx(17.453293f)); + CHECK(bigAngle.asRadians() == Approx(17.453293)); const sf::Angle bigNegativeAngle = sf::degrees(-4321); CHECK(bigNegativeAngle == sf::degrees(-4321)); - CHECK(bigNegativeAngle.asRadians() == Approx(-75.415677f)); + CHECK(bigNegativeAngle.asRadians() == Approx(-75.415677)); } SUBCASE("radians()") { const sf::Angle angle = sf::radians(1); - CHECK(angle.asDegrees() == Approx(57.2957795f)); - CHECK(angle.asRadians() == Approx(1.0f)); + CHECK(angle.asDegrees() == Approx(57.2957795)); + CHECK(angle.asRadians() == Approx(1.0)); const sf::Angle bigAngle = sf::radians(72); - CHECK(bigAngle.asDegrees() == Approx(4125.29612f)); - CHECK(bigAngle.asRadians() == Approx(72.0f)); + CHECK(bigAngle.asDegrees() == Approx(4125.29612)); + CHECK(bigAngle.asRadians() == Approx(72.0)); const sf::Angle bigNegativeAngle = sf::radians(-200); - CHECK(bigNegativeAngle.asDegrees() == Approx(-11459.1559f)); - CHECK(bigNegativeAngle.asRadians() == Approx(-200.0f)); + CHECK(bigNegativeAngle.asDegrees() == Approx(-11459.1559)); + 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::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/=") diff --git a/test/System/Time.cpp b/test/System/Time.cpp index aaed19d9..3461affb 100644 --- a/test/System/Time.cpp +++ b/test/System/Time.cpp @@ -25,8 +25,6 @@ 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).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); @@ -35,8 +33,6 @@ 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).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); } @@ -153,11 +149,11 @@ TEST_CASE("sf::Time class - [system]") SUBCASE("operator*=") { - sf::Time time = sf::milliseconds(420); + sf::Time time = sf::milliseconds(1'000); time *= static_cast(10); - CHECK(time == sf::milliseconds(4'200)); + CHECK(time == sf::milliseconds(10'000)); time *= 0.1f; - CHECK(time.asMicroseconds() == Approx(420'000).epsilon(0.1f)); + CHECK(time.asMilliseconds() == 1'000); } SUBCASE("operator/") @@ -167,16 +163,16 @@ TEST_CASE("sf::Time class - [system]") CHECK(sf::seconds(1) / static_cast(2) == sf::seconds(0.5f)); CHECK(sf::seconds(42) / static_cast(2) == sf::seconds(21)); 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/=") { - sf::Time time = sf::milliseconds(420); - time /= static_cast(42); - CHECK(time == sf::milliseconds(10)); - time /= 10.0f; - CHECK(time.asMicroseconds() == Approx(1'000).epsilon(0.1f)); + sf::Time time = sf::milliseconds(1'000); + time /= static_cast(2); + CHECK(time == sf::milliseconds(500)); + time /= 0.5f; + CHECK(time.asMilliseconds() == 1'000); } SUBCASE("operator%") diff --git a/test/TestUtilities/SystemUtil.hpp b/test/TestUtilities/SystemUtil.hpp index f3b5c807..4d366cd6 100644 --- a/test/TestUtilities/SystemUtil.hpp +++ b/test/TestUtilities/SystemUtil.hpp @@ -54,8 +54,8 @@ struct ApproxVec // Utilities for approximate equality struct ApproxDeg { - ApproxDeg(double degrees) - : degrees(static_cast(degrees)) {} + ApproxDeg(double deg) + : degrees(static_cast(deg)) {} float degrees; };