From bc86e0bcedd2e3d0d6b9a64f24f40008dda200e4 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Sat, 5 Aug 2023 18:48:57 -0600 Subject: [PATCH] Add tests for `sf::Sprite` --- test/Graphics/Sprite.test.cpp | 69 ++++++++++++++++++++++++++++++++--- 1 file changed, 64 insertions(+), 5 deletions(-) diff --git a/test/Graphics/Sprite.test.cpp b/test/Graphics/Sprite.test.cpp index f10b9f8c..73afc411 100644 --- a/test/Graphics/Sprite.test.cpp +++ b/test/Graphics/Sprite.test.cpp @@ -1,9 +1,68 @@ #include +// Other 1st party headers +#include + +#include + +#include #include -static_assert(!std::is_constructible_v); -static_assert(std::is_copy_constructible_v); -static_assert(std::is_copy_assignable_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); +TEST_CASE("[Graphics] sf::Sprite", runDisplayTests()) +{ + SECTION("Type traits") + { + STATIC_CHECK(!std::is_constructible_v); + STATIC_CHECK(std::is_copy_constructible_v); + STATIC_CHECK(std::is_copy_assignable_v); + STATIC_CHECK(std::is_nothrow_move_constructible_v); + STATIC_CHECK(std::is_nothrow_move_assignable_v); + } + + const sf::Texture texture; + + SECTION("Construction") + { + SECTION("Texture constructor") + { + const sf::Sprite sprite(texture); + CHECK(&sprite.getTexture() == &texture); + CHECK(sprite.getTextureRect() == sf::IntRect()); + CHECK(sprite.getColor() == sf::Color::White); + CHECK(sprite.getLocalBounds() == sf::FloatRect()); + CHECK(sprite.getGlobalBounds() == sf::FloatRect()); + } + + SECTION("Texture and rectangle constructor") + { + const sf::Sprite sprite(texture, {{0, 0}, {40, 60}}); + CHECK(&sprite.getTexture() == &texture); + CHECK(sprite.getTextureRect() == sf::IntRect({0, 0}, {40, 60})); + CHECK(sprite.getColor() == sf::Color::White); + CHECK(sprite.getLocalBounds() == sf::FloatRect({0, 0}, {40, 60})); + CHECK(sprite.getGlobalBounds() == sf::FloatRect({0, 0}, {40, 60})); + } + } + + SECTION("Set/get texture") + { + sf::Sprite sprite(texture); + const sf::Texture otherTexture; + sprite.setTexture(otherTexture); + CHECK(&sprite.getTexture() == &otherTexture); + } + + SECTION("Set/get texture rect") + { + sf::Sprite sprite(texture); + sprite.setTextureRect({{1, 2}, {3, 4}}); + CHECK(sprite.getTextureRect() == sf::IntRect({1, 2}, {3, 4})); + } + + SECTION("Set/get color") + { + sf::Sprite sprite(texture); + sprite.setColor(sf::Color::Red); + CHECK(sprite.getColor() == sf::Color::Red); + } +}