Skip to content

Commit

Permalink
Add tests for sfBlendMode
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Dec 22, 2024
1 parent e46663c commit b3e6e23
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ set_target_warnings(test-csfml-window)
catch_discover_tests(test-csfml-window)

add_executable(test-csfml-graphics
Graphics/BlendMode.test.cpp
Graphics/Rect.test.cpp
)
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain)
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics)
set_target_warnings(test-csfml-graphics)
catch_discover_tests(test-csfml-graphics)

Expand Down
112 changes: 112 additions & 0 deletions test/Graphics/BlendMode.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include <CSFML/Graphics/BlendMode.h>

#include <SFML/Graphics/BlendMode.hpp>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Graphics] sfBlendMode")
{
SECTION("sfBlendFactor")
{
STATIC_CHECK(sfBlendFactorZero == static_cast<int>(sf::BlendMode::Factor::Zero));
STATIC_CHECK(sfBlendFactorOne == static_cast<int>(sf::BlendMode::Factor::One));
STATIC_CHECK(sfBlendFactorSrcColor == static_cast<int>(sf::BlendMode::Factor::SrcColor));
STATIC_CHECK(sfBlendFactorOneMinusSrcColor == static_cast<int>(sf::BlendMode::Factor::OneMinusSrcColor));
STATIC_CHECK(sfBlendFactorDstColor == static_cast<int>(sf::BlendMode::Factor::DstColor));
STATIC_CHECK(sfBlendFactorOneMinusDstColor == static_cast<int>(sf::BlendMode::Factor::OneMinusDstColor));
STATIC_CHECK(sfBlendFactorSrcAlpha == static_cast<int>(sf::BlendMode::Factor::SrcAlpha));
STATIC_CHECK(sfBlendFactorOneMinusSrcAlpha == static_cast<int>(sf::BlendMode::Factor::OneMinusSrcAlpha));
STATIC_CHECK(sfBlendFactorDstAlpha == static_cast<int>(sf::BlendMode::Factor::DstAlpha));
STATIC_CHECK(sfBlendFactorOneMinusDstAlpha == static_cast<int>(sf::BlendMode::Factor::OneMinusDstAlpha));
}

SECTION("sfBlendEquation")
{
STATIC_CHECK(sfBlendEquationAdd == static_cast<int>(sf::BlendMode::Equation::Add));
STATIC_CHECK(sfBlendEquationSubtract == static_cast<int>(sf::BlendMode::Equation::Subtract));
STATIC_CHECK(sfBlendEquationReverseSubtract == static_cast<int>(sf::BlendMode::Equation::ReverseSubtract));
STATIC_CHECK(sfBlendEquationMin == static_cast<int>(sf::BlendMode::Equation::Min));
STATIC_CHECK(sfBlendEquationMax == static_cast<int>(sf::BlendMode::Equation::Max));
}

SECTION("Construction")
{
// sfBlendFactor colorSrcFactor; ///< Source blending factor for the color channels
// sfBlendFactor colorDstFactor; ///< Destination blending factor for the color channels
// sfBlendEquation colorEquation; ///< Blending equation for the color channels
// sfBlendFactor alphaSrcFactor; ///< Source blending factor for the alpha channel
// sfBlendFactor alphaDstFactor; ///< Destination blending factor for the alpha channel
// sfBlendEquation alphaEquation; ///< Blending equation for the alpha channel

constexpr sfBlendMode blendMode{};
STATIC_CHECK(blendMode.colorSrcFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.colorDstFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.colorEquation == sfBlendEquationAdd);
STATIC_CHECK(blendMode.alphaSrcFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.alphaDstFactor == sfBlendFactorZero);
STATIC_CHECK(blendMode.alphaEquation == sfBlendEquationAdd);
}

SECTION("Constants")
{
SECTION("sfBlendAlpha")
{
CHECK(sfBlendAlpha.colorSrcFactor == sfBlendFactorSrcAlpha);
CHECK(sfBlendAlpha.colorDstFactor == sfBlendFactorOneMinusSrcAlpha);
CHECK(sfBlendAlpha.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendAlpha.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendAlpha.alphaDstFactor == sfBlendFactorOneMinusSrcAlpha);
CHECK(sfBlendAlpha.alphaEquation == sfBlendEquationAdd);
}

SECTION("sfBlendAdd")
{
CHECK(sfBlendAdd.colorSrcFactor == sfBlendFactorSrcAlpha);
CHECK(sfBlendAdd.colorDstFactor == sfBlendFactorOne);
CHECK(sfBlendAdd.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendAdd.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendAdd.alphaDstFactor == sfBlendFactorOne);
CHECK(sfBlendAdd.alphaEquation == sfBlendEquationAdd);
}

SECTION("sfBlendMultiply")
{
CHECK(sfBlendMultiply.colorSrcFactor == sfBlendFactorDstColor);
CHECK(sfBlendMultiply.colorDstFactor == sfBlendFactorZero);
CHECK(sfBlendMultiply.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendMultiply.alphaSrcFactor == sfBlendFactorDstColor);
CHECK(sfBlendMultiply.alphaDstFactor == sfBlendFactorZero);
CHECK(sfBlendMultiply.alphaEquation == sfBlendEquationAdd);
}

SECTION("sfBlendMin")
{
CHECK(sfBlendMin.colorSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMin.colorDstFactor == sfBlendFactorOne);
CHECK(sfBlendMin.colorEquation == sfBlendEquationMin);
CHECK(sfBlendMin.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMin.alphaDstFactor == sfBlendFactorOne);
CHECK(sfBlendMin.alphaEquation == sfBlendEquationMin);
}

SECTION("sfBlendMax")
{
CHECK(sfBlendMax.colorSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMax.colorDstFactor == sfBlendFactorOne);
CHECK(sfBlendMax.colorEquation == sfBlendEquationMax);
CHECK(sfBlendMax.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendMax.alphaDstFactor == sfBlendFactorOne);
CHECK(sfBlendMax.alphaEquation == sfBlendEquationMax);
}

SECTION("sfBlendNone")
{
CHECK(sfBlendNone.colorSrcFactor == sfBlendFactorOne);
CHECK(sfBlendNone.colorDstFactor == sfBlendFactorZero);
CHECK(sfBlendNone.colorEquation == sfBlendEquationAdd);
CHECK(sfBlendNone.alphaSrcFactor == sfBlendFactorOne);
CHECK(sfBlendNone.alphaDstFactor == sfBlendFactorZero);
CHECK(sfBlendNone.alphaEquation == sfBlendEquationAdd);
}
}
}

0 comments on commit b3e6e23

Please sign in to comment.