SFML/test/Graphics/RenderStates.test.cpp

96 lines
3.8 KiB
C++
Raw Permalink Normal View History

2022-05-26 02:36:06 +08:00
#include <SFML/Graphics/RenderStates.hpp>
2022-07-18 06:18:40 +08:00
#include <doctest/doctest.h>
2022-05-26 02:36:06 +08:00
2022-07-05 00:20:58 +08:00
#include <GraphicsUtil.hpp>
#include <type_traits>
static_assert(std::is_copy_constructible_v<sf::RenderStates>);
static_assert(std::is_copy_assignable_v<sf::RenderStates>);
static_assert(std::is_nothrow_move_constructible_v<sf::RenderStates>);
static_assert(std::is_nothrow_move_assignable_v<sf::RenderStates>);
2022-07-05 00:20:58 +08:00
TEST_CASE("[Graphics] sf::RenderStates")
2022-05-26 02:36:06 +08:00
{
SUBCASE("Construction")
{
SUBCASE("Default constructor")
{
const sf::RenderStates renderStates;
CHECK(renderStates.blendMode == sf::BlendMode());
CHECK(renderStates.transform == sf::Transform());
CHECK(renderStates.texture == nullptr);
CHECK(renderStates.shader == nullptr);
}
SUBCASE("BlendMode constructor")
{
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-05-26 02:36:06 +08:00
const sf::RenderStates renderStates(blendMode);
CHECK(renderStates.blendMode == blendMode);
CHECK(renderStates.transform == sf::Transform());
CHECK(renderStates.texture == nullptr);
CHECK(renderStates.shader == nullptr);
}
SUBCASE("Transform constructor")
{
2022-07-05 00:20:58 +08:00
const sf::Transform transform(10, 9, 8, 7, 6, 5, 4, 3, 2);
2022-05-26 02:36:06 +08:00
const sf::RenderStates renderStates(transform);
CHECK(renderStates.blendMode == sf::BlendMode());
CHECK(renderStates.transform == transform);
CHECK(renderStates.texture == nullptr);
CHECK(renderStates.shader == nullptr);
}
SUBCASE("Texture constructor")
{
2022-07-05 00:20:58 +08:00
const sf::Texture* texture = nullptr;
2022-05-26 02:36:06 +08:00
const sf::RenderStates renderStates(texture);
CHECK(renderStates.blendMode == sf::BlendMode());
CHECK(renderStates.transform == sf::Transform());
CHECK(renderStates.texture == texture);
CHECK(renderStates.shader == nullptr);
}
SUBCASE("Shader constructor")
{
2022-07-05 00:20:58 +08:00
const sf::Shader* shader = nullptr;
2022-05-26 02:36:06 +08:00
const sf::RenderStates renderStates(shader);
CHECK(renderStates.blendMode == sf::BlendMode());
CHECK(renderStates.transform == sf::Transform());
CHECK(renderStates.texture == nullptr);
CHECK(renderStates.shader == shader);
}
SUBCASE("Verbose constructor")
{
2022-07-05 00:20:58 +08:00
const sf::BlendMode blendMode(sf::BlendMode::One,
sf::BlendMode::SrcColor,
sf::BlendMode::ReverseSubtract,
sf::BlendMode::OneMinusDstAlpha,
sf::BlendMode::DstAlpha,
sf::BlendMode::Max);
const sf::Transform transform(10, 2, 3, 4, 50, 40, 30, 20, 10);
2022-05-26 02:36:06 +08:00
const sf::RenderStates renderStates(blendMode, transform, nullptr, nullptr);
CHECK(renderStates.blendMode == blendMode);
CHECK(renderStates.transform == transform);
CHECK(renderStates.texture == nullptr);
CHECK(renderStates.shader == nullptr);
}
}
SUBCASE("Default constant")
{
CHECK(sf::RenderStates::Default.blendMode == sf::BlendMode());
CHECK(sf::RenderStates::Default.transform == sf::Transform());
CHECK(sf::RenderStates::Default.texture == nullptr);
2022-06-24 07:09:22 +08:00
CHECK(sf::RenderStates::Default.shader == nullptr);
2022-05-26 02:36:06 +08:00
}
}