diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 474fc274..06ce8e66 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -49,6 +49,9 @@ add_executable(test-csfml-graphics Graphics/Color.test.cpp Graphics/CoordinateType.test.cpp Graphics/Rect.test.cpp + Graphics/RenderStates.test.cpp + Graphics/StencilMode.test.cpp + Graphics/Transform.test.cpp ) target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics) set_target_warnings(test-csfml-graphics) diff --git a/test/Graphics/RenderStates.test.cpp b/test/Graphics/RenderStates.test.cpp new file mode 100644 index 00000000..6e74623e --- /dev/null +++ b/test/Graphics/RenderStates.test.cpp @@ -0,0 +1,41 @@ +#include + +#include + +#include + +#include "CSFML/Graphics/CoordinateType.h" + +TEST_CASE("[Graphics] sfRenderStates") +{ + SECTION("Construction") + { + constexpr sfRenderStates renderStates{}; + STATIC_CHECK(renderStates.blendMode.colorSrcFactor == sfBlendFactorZero); + STATIC_CHECK(renderStates.blendMode.colorDstFactor == sfBlendFactorZero); + STATIC_CHECK(renderStates.blendMode.colorEquation == sfBlendEquationAdd); + STATIC_CHECK(renderStates.blendMode.alphaSrcFactor == sfBlendFactorZero); + STATIC_CHECK(renderStates.blendMode.alphaDstFactor == sfBlendFactorZero); + STATIC_CHECK(renderStates.blendMode.alphaEquation == sfBlendEquationAdd); + STATIC_CHECK(renderStates.stencilMode.stencilComparison == sfStencilComparisonNever); + STATIC_CHECK(renderStates.stencilMode.stencilUpdateOperation == sfStencilUpdateOperationKeep); + STATIC_CHECK(renderStates.stencilMode.stencilReference.value == 0); + STATIC_CHECK(renderStates.stencilMode.stencilMask.value == 0); + STATIC_CHECK(!renderStates.stencilMode.stencilOnly); + for (const auto element : renderStates.transform.matrix) + CHECK(element == 0); + STATIC_CHECK(renderStates.coordinateType == sfCoordinateTypeNormalized); + STATIC_CHECK(renderStates.texture == nullptr); + STATIC_CHECK(renderStates.shader == nullptr); + } + + SECTION("sfRenderStates_default") + { + CHECK(sfRenderStates_default.blendMode.alphaDstFactor == sfBlendAlpha.alphaDstFactor); + CHECK(sfRenderStates_default.blendMode.colorDstFactor == sfBlendAlpha.colorDstFactor); + CHECK(sfRenderStates_default.blendMode.colorEquation == sfBlendAlpha.colorEquation); + CHECK(sfRenderStates_default.blendMode.alphaSrcFactor == sfBlendAlpha.alphaSrcFactor); + CHECK(sfRenderStates_default.blendMode.alphaDstFactor == sfBlendAlpha.alphaDstFactor); + CHECK(sfRenderStates_default.blendMode.alphaEquation == sfBlendAlpha.alphaEquation); + } +} diff --git a/test/Graphics/StencilMode.test.cpp b/test/Graphics/StencilMode.test.cpp new file mode 100644 index 00000000..72b2cf67 --- /dev/null +++ b/test/Graphics/StencilMode.test.cpp @@ -0,0 +1,55 @@ +#include + +#include + +#include + +TEST_CASE("[Graphics] sfStencilMode") +{ + SECTION("sfStencilComparison") + { + STATIC_CHECK(sfStencilComparisonNever == static_cast(sf::StencilComparison::Never)); + STATIC_CHECK(sfStencilComparisonLess == static_cast(sf::StencilComparison::Less)); + STATIC_CHECK(sfStencilComparisonLessEqual == static_cast(sf::StencilComparison::LessEqual)); + STATIC_CHECK(sfStencilComparisonGreater == static_cast(sf::StencilComparison::Greater)); + STATIC_CHECK(sfStencilComparisonGreaterEqual == static_cast(sf::StencilComparison::GreaterEqual)); + STATIC_CHECK(sfStencilComparisonEqual == static_cast(sf::StencilComparison::Equal)); + STATIC_CHECK(sfStencilComparisonNotEqual == static_cast(sf::StencilComparison::NotEqual)); + STATIC_CHECK(sfStencilComparisonAlways == static_cast(sf::StencilComparison::Always)); + } + + SECTION("sfStencilUpdateOperation") + { + STATIC_CHECK(sfStencilUpdateOperationKeep == static_cast(sf::StencilUpdateOperation::Keep)); + STATIC_CHECK(sfStencilUpdateOperationZero == static_cast(sf::StencilUpdateOperation::Zero)); + STATIC_CHECK(sfStencilUpdateOperationReplace == static_cast(sf::StencilUpdateOperation::Replace)); + STATIC_CHECK(sfStencilUpdateOperationIncrement == static_cast(sf::StencilUpdateOperation::Increment)); + STATIC_CHECK(sfStencilUpdateOperationDecrement == static_cast(sf::StencilUpdateOperation::Decrement)); + STATIC_CHECK(sfStencilUpdateOperationInvert == static_cast(sf::StencilUpdateOperation::Invert)); + } + + SECTION("sfStencilValue") + { + constexpr sfStencilValue stencilValue{}; + STATIC_CHECK(stencilValue.value == 0); + } + + SECTION("sfStencilMode") + { + constexpr sfStencilMode stencilMode{}; + STATIC_CHECK(stencilMode.stencilComparison == sfStencilComparisonNever); + STATIC_CHECK(stencilMode.stencilUpdateOperation == sfStencilUpdateOperationKeep); + STATIC_CHECK(stencilMode.stencilReference.value == 0); + STATIC_CHECK(stencilMode.stencilMask.value == 0); + STATIC_CHECK(!stencilMode.stencilOnly); + } + + SECTION("sfStencilMode_default") + { + CHECK(sfStencilMode_default.stencilComparison == sfStencilComparisonAlways); + CHECK(sfStencilMode_default.stencilUpdateOperation == sfStencilUpdateOperationKeep); + CHECK(sfStencilMode_default.stencilReference.value == 0); + CHECK(sfStencilMode_default.stencilMask.value == ~0u); + CHECK(!sfStencilMode_default.stencilOnly); + } +} diff --git a/test/Graphics/Transform.test.cpp b/test/Graphics/Transform.test.cpp new file mode 100644 index 00000000..93cb5a06 --- /dev/null +++ b/test/Graphics/Transform.test.cpp @@ -0,0 +1,128 @@ +#include + +#include + +#include + +TEST_CASE("[Graphics] sfTransform") +{ + SECTION("Construction") + { + constexpr sfTransform transform{}; + STATIC_CHECK(std::size(transform.matrix) == 9); + for (const auto element : transform.matrix) + CHECK(element == 0); + } + + SECTION("sfTransform_Identity") + { + CHECK(sfTransform_Identity.matrix[0] == 1); + CHECK(sfTransform_Identity.matrix[1] == 0); + CHECK(sfTransform_Identity.matrix[2] == 0); + CHECK(sfTransform_Identity.matrix[3] == 0); + CHECK(sfTransform_Identity.matrix[4] == 1); + CHECK(sfTransform_Identity.matrix[5] == 0); + CHECK(sfTransform_Identity.matrix[6] == 0); + CHECK(sfTransform_Identity.matrix[7] == 0); + CHECK(sfTransform_Identity.matrix[8] == 1); + } + + SECTION("sfTransform_fromMatrix") + { + const auto transform = sfTransform_fromMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9); + CHECK(transform.matrix[0] == 1); + CHECK(transform.matrix[1] == 2); + CHECK(transform.matrix[2] == 3); + CHECK(transform.matrix[3] == 4); + CHECK(transform.matrix[4] == 5); + CHECK(transform.matrix[5] == 6); + CHECK(transform.matrix[6] == 7); + CHECK(transform.matrix[7] == 8); + CHECK(transform.matrix[8] == 9); + } + + SECTION("sfTransform_getMatrix") + { + const auto transform = sfTransform_fromMatrix(1, 2, 3, 4, 5, 6, 7, 8, 9); + std::array matrix{}; + matrix.fill(std::numeric_limits::signaling_NaN()); + sfTransform_getMatrix(&transform, matrix.data()); + CHECK(matrix[0] == 1); + CHECK(matrix[1] == 4); + CHECK(matrix[2] == 0); + CHECK(matrix[3] == 7); + CHECK(matrix[4] == 2); + CHECK(matrix[5] == 5); + CHECK(matrix[6] == 0); + CHECK(matrix[7] == 8); + CHECK(matrix[8] == 0); + CHECK(matrix[9] == 0); + CHECK(matrix[10] == 1); + CHECK(matrix[11] == 0); + CHECK(matrix[12] == 3); + CHECK(matrix[13] == 6); + CHECK(matrix[14] == 0); + CHECK(matrix[15] == 9); + } + + SECTION("sfTransform_getInverse") + { + SECTION("Identity") + { + const auto inverse = sfTransform_getInverse(&sfTransform_Identity); + for (std::size_t i = 0; i < std::size(inverse.matrix); ++i) + CHECK(inverse.matrix[0] == sfTransform_Identity.matrix[0]); + } + + SECTION("Non-identity") + { + const auto transform = sfTransform_fromMatrix(1, 2, 3, 4, 5, 4, 3, 2, 1); + const auto inverse = sfTransform_getInverse(&transform); + CHECK(inverse.matrix[0] == 0.375f); + CHECK(inverse.matrix[1] == -0.5f); + CHECK(inverse.matrix[2] == 0.875f); + CHECK(inverse.matrix[3] == -1); + CHECK(inverse.matrix[4] == 1); + CHECK(inverse.matrix[5] == -1); + CHECK(inverse.matrix[6] == 0.875f); + CHECK(inverse.matrix[7] == -0.5f); + CHECK(inverse.matrix[8] == 0.375f); + } + } + + SECTION("sfTransform_transformPoint") + { + } + + SECTION("sfTransform_transformRect") + { + } + + SECTION("sfTransform_combine") + { + } + + SECTION("sfTransform_translate") + { + } + + SECTION("sfTransform_rotate") + { + } + + SECTION("sfTransform_rotateWithCenter") + { + } + + SECTION("sfTransform_scale") + { + } + + SECTION("sfTransform_scaleWithCenter") + { + } + + SECTION("sfTransform_equal") + { + } +}