From d672b3504ec80c78fbabc93f563a283f2eae5d85 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sun, 29 Oct 2023 22:41:59 -0600 Subject: [PATCH] Add more tests for `sf::Shape` --- test/Graphics/Shape.test.cpp | 41 ++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/test/Graphics/Shape.test.cpp b/test/Graphics/Shape.test.cpp index 9df449ee3..49a051ef0 100644 --- a/test/Graphics/Shape.test.cpp +++ b/test/Graphics/Shape.test.cpp @@ -1,5 +1,8 @@ #include +// Other 1st party headers +#include + #include #include @@ -36,7 +39,7 @@ private: sf::Vector2f m_size; }; -TEST_CASE("[Graphics] sf::Shape") +TEST_CASE("[Graphics] sf::Shape", runDisplayTests()) { SECTION("Type traits") { @@ -60,6 +63,14 @@ TEST_CASE("[Graphics] sf::Shape") CHECK(triangleShape.getGlobalBounds() == sf::FloatRect()); } + SECTION("Set/get texture") + { + const sf::Texture texture; + TriangleShape triangleShape({}); + triangleShape.setTexture(&texture, true); + CHECK(triangleShape.getTexture() == &texture); + } + SECTION("Set/get texture rect") { TriangleShape triangleShape({}); @@ -100,15 +111,23 @@ TEST_CASE("[Graphics] sf::Shape") SECTION("Get bounds") { - TriangleShape triangleShape({2, 3}); - CHECK(triangleShape.getLocalBounds() == sf::FloatRect({0, 0}, {2, 3})); - CHECK(triangleShape.getGlobalBounds() == sf::FloatRect({0, 0}, {2, 3})); - 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)); + TriangleShape triangleShape({30, 40}); + CHECK(triangleShape.getLocalBounds() == sf::FloatRect({0, 0}, {30, 40})); + CHECK(triangleShape.getGlobalBounds() == sf::FloatRect({0, 0}, {30, 40})); + + SECTION("Move and rotate") + { + triangleShape.move({1, 1}); + triangleShape.rotate(sf::degrees(90)); + CHECK(triangleShape.getLocalBounds() == sf::FloatRect({0, 0}, {30, 40})); + CHECK(triangleShape.getGlobalBounds() == Approx(sf::FloatRect({-39, 1}, {40, 30}))); + } + + SECTION("Add outline") + { + triangleShape.setOutlineThickness(5); + CHECK(triangleShape.getLocalBounds() == Approx(sf::FloatRect({-7.2150f, -14.2400f}, {44.4300f, 59.2400f}))); + CHECK(triangleShape.getGlobalBounds() == Approx(sf::FloatRect({-7.2150f, -14.2400f}, {44.4300f, 59.2400f}))); + } } }