From d7ab9208bed2f8406da13f102a477a843e3cc679 Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Fri, 1 Sep 2023 16:42:47 -0600 Subject: [PATCH] Add tests for `sf::RenderTexture` The generateMipmap test was failing because I forgot to enable MESA in the MinGW Static Standard Library job. --- .github/workflows/ci.yml | 2 +- src/SFML/Graphics/RenderTexture.cpp | 1 + test/Graphics/RenderTexture.test.cpp | 79 ++++++++++++++++++++++++++-- 3 files changed, 77 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 293e195ec..e37e49d83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,7 @@ jobs: config: { name: OpenGL ES, flags: -DSFML_USE_MESA3D=TRUE -DBUILD_SHARED_LIBS=TRUE -DSFML_OPENGL_ES=ON } type: { name: Debug, flags: -DCMAKE_BUILD_TYPE=Debug -DSFML_ENABLE_COVERAGE=TRUE } - platform: { name: Windows MinGW, os: windows-2022 } - config: { name: Static Standard Libraries, flags: -GNinja -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DSFML_USE_STATIC_STD_LIBS=TRUE } + config: { name: Static Standard Libraries, flags: -GNinja -DSFML_USE_MESA3D=TRUE -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DSFML_USE_STATIC_STD_LIBS=TRUE } - platform: { name: macOS, os: macos-12 } config: { name: Frameworks, flags: -GNinja -DSFML_BUILD_FRAMEWORKS=TRUE -DBUILD_SHARED_LIBS=TRUE } - platform: { name: Android, os: ubuntu-22.04 } diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index f38945c60..65c67185c 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -170,6 +170,7 @@ Vector2u RenderTexture::getSize() const //////////////////////////////////////////////////////////// bool RenderTexture::isSrgb() const { + assert(m_impl && "Must call RenderTexture::create first"); return m_impl->isSrgb(); } diff --git a/test/Graphics/RenderTexture.test.cpp b/test/Graphics/RenderTexture.test.cpp index 4799e0588..50d7b7917 100644 --- a/test/Graphics/RenderTexture.test.cpp +++ b/test/Graphics/RenderTexture.test.cpp @@ -1,8 +1,79 @@ #include +#include + +#include #include -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::RenderTexture", runDisplayTests()) +{ + SECTION("Type traits") + { + 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); + } + + SECTION("Construction") + { + const sf::RenderTexture renderTexture; + CHECK(!renderTexture.isSmooth()); + CHECK(!renderTexture.isRepeated()); + CHECK(renderTexture.getSize() == sf::Vector2u(0, 0)); + } + + SECTION("create()") + { + sf::RenderTexture renderTexture; + CHECK(!renderTexture.create({1'000'000, 1'000'000})); + CHECK(renderTexture.create({480, 360})); + CHECK(!renderTexture.isSmooth()); + CHECK(!renderTexture.isRepeated()); + CHECK(renderTexture.getSize() == sf::Vector2u(480, 360)); + CHECK(!renderTexture.isSrgb()); + } + + SECTION("getMaximumAntialiasingLevel()") + { + CHECK(sf::RenderTexture::getMaximumAntialiasingLevel() < 32); + } + + SECTION("Set/get smooth") + { + sf::RenderTexture renderTexture; + renderTexture.setSmooth(true); + CHECK(renderTexture.isSmooth()); + } + + SECTION("Set/get repeated") + { + sf::RenderTexture renderTexture; + renderTexture.setRepeated(true); + CHECK(renderTexture.isRepeated()); + } + + SECTION("generateMipmap()") + { + sf::RenderTexture renderTexture; + CHECK(!renderTexture.generateMipmap()); + CHECK(renderTexture.create({480, 360})); + CHECK(renderTexture.generateMipmap()); + } + + SECTION("setActive()") + { + sf::RenderTexture renderTexture; + CHECK(!renderTexture.setActive()); + CHECK(renderTexture.create({480, 360})); + CHECK(renderTexture.setActive()); + } + + SECTION("getTexture()") + { + sf::RenderTexture renderTexture; + CHECK(renderTexture.getTexture().getSize() == sf::Vector2u(0, 0)); + CHECK(renderTexture.create({480, 360})); + CHECK(renderTexture.getTexture().getSize() == sf::Vector2u(480, 360)); + } +}