SFML/test/Graphics/BlendMode.test.cpp

190 lines
9.4 KiB
C++
Raw Permalink Normal View History

2022-01-12 05:40:51 +08:00
#include <SFML/Graphics/BlendMode.hpp>
2023-01-18 12:51:08 +08:00
#include <catch2/catch_test_macros.hpp>
2022-01-12 05:40:51 +08:00
2022-07-05 00:20:58 +08:00
#include <GraphicsUtil.hpp>
#include <type_traits>
TEST_CASE("[Graphics] sf::BlendMode")
2022-01-12 05:40:51 +08:00
{
2023-01-18 12:51:08 +08:00
SECTION("Type traits")
{
STATIC_CHECK(std::is_copy_constructible_v<sf::BlendMode>);
STATIC_CHECK(std::is_copy_assignable_v<sf::BlendMode>);
STATIC_CHECK(std::is_nothrow_move_constructible_v<sf::BlendMode>);
STATIC_CHECK(std::is_nothrow_move_assignable_v<sf::BlendMode>);
}
SECTION("Construction")
2022-01-12 05:40:51 +08:00
{
2023-01-18 12:51:08 +08:00
SECTION("Default constructor")
2022-01-12 05:40:51 +08:00
{
const sf::BlendMode blendMode;
CHECK(blendMode.colorSrcFactor == sf::BlendMode::SrcAlpha);
CHECK(blendMode.colorDstFactor == sf::BlendMode::OneMinusSrcAlpha);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.colorEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(blendMode.alphaSrcFactor == sf::BlendMode::One);
CHECK(blendMode.alphaDstFactor == sf::BlendMode::OneMinusSrcAlpha);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.alphaEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("Combined color and alpha constructor using default parameter")
2022-01-12 05:40:51 +08:00
{
const sf::BlendMode blendMode(sf::BlendMode::Zero, sf::BlendMode::SrcColor);
CHECK(blendMode.colorSrcFactor == sf::BlendMode::Zero);
CHECK(blendMode.colorDstFactor == sf::BlendMode::SrcColor);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.colorEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(blendMode.alphaSrcFactor == sf::BlendMode::Zero);
CHECK(blendMode.alphaDstFactor == sf::BlendMode::SrcColor);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.alphaEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("Combined color and alpha constructor")
2022-01-12 05:40:51 +08:00
{
const sf::BlendMode blendMode(sf::BlendMode::Zero, sf::BlendMode::SrcColor, sf::BlendMode::ReverseSubtract);
CHECK(blendMode.colorSrcFactor == sf::BlendMode::Zero);
CHECK(blendMode.colorDstFactor == sf::BlendMode::SrcColor);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.colorEquation == sf::BlendMode::ReverseSubtract);
2022-01-12 05:40:51 +08:00
CHECK(blendMode.alphaSrcFactor == sf::BlendMode::Zero);
CHECK(blendMode.alphaDstFactor == sf::BlendMode::SrcColor);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.alphaEquation == sf::BlendMode::ReverseSubtract);
2022-01-12 05:40:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("Separate color and alpha constructor")
2022-01-12 05:40:51 +08:00
{
2022-07-05 00:20:58 +08:00
const sf::BlendMode blendMode(sf::BlendMode::Zero,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max);
2022-01-12 05:40:51 +08:00
CHECK(blendMode.colorSrcFactor == sf::BlendMode::Zero);
CHECK(blendMode.colorDstFactor == sf::BlendMode::SrcColor);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.colorEquation == sf::BlendMode::ReverseSubtract);
2022-01-12 05:40:51 +08:00
CHECK(blendMode.alphaSrcFactor == sf::BlendMode::OneMinusDstAlpha);
CHECK(blendMode.alphaDstFactor == sf::BlendMode::DstAlpha);
2022-07-05 00:20:58 +08:00
CHECK(blendMode.alphaEquation == sf::BlendMode::Max);
2022-01-12 05:40:51 +08:00
}
}
2023-01-18 12:51:08 +08:00
SECTION("Operators")
2022-01-12 05:40:51 +08:00
{
2023-01-18 12:51:08 +08:00
SECTION("operator==")
2022-01-12 05:40:51 +08:00
{
CHECK(sf::BlendMode() == sf::BlendMode());
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One) ==
sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One));
CHECK(sf::BlendMode(sf::BlendMode::Zero,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max) ==
sf::BlendMode(sf::BlendMode::Zero,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max));
2022-01-12 05:40:51 +08:00
CHECK_FALSE(sf::BlendMode() == sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One));
2022-07-05 00:20:58 +08:00
CHECK_FALSE(sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One) ==
sf::BlendMode(sf::BlendMode::One, sf::BlendMode::Zero));
CHECK_FALSE(
sf::BlendMode(sf::BlendMode::Zero,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max) ==
sf::BlendMode(sf::BlendMode::One,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max));
2022-01-12 05:40:51 +08:00
}
2023-01-18 12:51:08 +08:00
SECTION("operator!=")
2022-01-12 05:40:51 +08:00
{
CHECK_FALSE(sf::BlendMode() != sf::BlendMode());
2022-07-05 00:20:58 +08:00
CHECK_FALSE(sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One) !=
sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One));
CHECK_FALSE(
sf::BlendMode(sf::BlendMode::Zero,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max) !=
sf::BlendMode(sf::BlendMode::Zero,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max));
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendMode() != sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One));
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMode(sf::BlendMode::Zero, sf::BlendMode::One) !=
sf::BlendMode(sf::BlendMode::One, sf::BlendMode::Zero));
CHECK(sf::BlendMode(sf::BlendMode::Zero,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max) !=
sf::BlendMode(sf::BlendMode::One,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max));
2022-01-12 05:40:51 +08:00
}
}
2023-01-18 12:51:08 +08:00
SECTION("Static constants")
2022-01-12 05:40:51 +08:00
{
CHECK(sf::BlendAlpha.colorSrcFactor == sf::BlendMode::SrcAlpha);
CHECK(sf::BlendAlpha.colorDstFactor == sf::BlendMode::OneMinusSrcAlpha);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendAlpha.colorEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendAlpha.alphaSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendAlpha.alphaDstFactor == sf::BlendMode::OneMinusSrcAlpha);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendAlpha.alphaEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendAdd.colorSrcFactor == sf::BlendMode::SrcAlpha);
CHECK(sf::BlendAdd.colorDstFactor == sf::BlendMode::One);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendAdd.colorEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendAdd.alphaSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendAdd.alphaDstFactor == sf::BlendMode::One);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendAdd.alphaEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendMultiply.colorSrcFactor == sf::BlendMode::DstColor);
CHECK(sf::BlendMultiply.colorDstFactor == sf::BlendMode::Zero);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMultiply.colorEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendMultiply.alphaSrcFactor == sf::BlendMode::DstColor);
CHECK(sf::BlendMultiply.alphaDstFactor == sf::BlendMode::Zero);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMultiply.alphaEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendMin.colorSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendMin.colorDstFactor == sf::BlendMode::One);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMin.colorEquation == sf::BlendMode::Min);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendMin.alphaSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendMin.alphaDstFactor == sf::BlendMode::One);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMin.alphaEquation == sf::BlendMode::Min);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendMax.colorSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendMax.colorDstFactor == sf::BlendMode::One);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMax.colorEquation == sf::BlendMode::Max);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendMax.alphaSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendMax.alphaDstFactor == sf::BlendMode::One);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendMax.alphaEquation == sf::BlendMode::Max);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendNone.colorSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendNone.colorDstFactor == sf::BlendMode::Zero);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendNone.colorEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
CHECK(sf::BlendNone.alphaSrcFactor == sf::BlendMode::One);
CHECK(sf::BlendNone.alphaDstFactor == sf::BlendMode::Zero);
2022-07-05 00:20:58 +08:00
CHECK(sf::BlendNone.alphaEquation == sf::BlendMode::Add);
2022-01-12 05:40:51 +08:00
}
}