Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ add_executable(test-csfml-graphics
Graphics/BlendMode.test.cpp
Graphics/Color.test.cpp
Graphics/CoordinateType.test.cpp
Graphics/PrimitiveType.test.cpp
Graphics/Rect.test.cpp
Graphics/RenderStates.test.cpp
Graphics/Shape.test.cpp
Graphics/StencilMode.test.cpp
Graphics/Transform.test.cpp
Graphics/VertexArray.test.cpp
Graphics/View.test.cpp
)
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics)
set_target_warnings(test-csfml-graphics)
Expand Down
7 changes: 0 additions & 7 deletions test/Graphics/BlendMode.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ TEST_CASE("[Graphics] sfBlendMode")

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);
Expand Down
15 changes: 15 additions & 0 deletions test/Graphics/PrimitiveType.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <CSFML/Graphics/PrimitiveType.h>

#include <SFML/Graphics/PrimitiveType.hpp>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Graphics] sfPrimitiveType")
{
STATIC_CHECK(sfPoints == static_cast<int>(sf::PrimitiveType::Points));
STATIC_CHECK(sfLines == static_cast<int>(sf::PrimitiveType::Lines));
STATIC_CHECK(sfLineStrip == static_cast<int>(sf::PrimitiveType::LineStrip));
STATIC_CHECK(sfTriangles == static_cast<int>(sf::PrimitiveType::Triangles));
STATIC_CHECK(sfTriangleStrip == static_cast<int>(sf::PrimitiveType::TriangleStrip));
STATIC_CHECK(sfTriangleFan == static_cast<int>(sf::PrimitiveType::TriangleFan));
}
107 changes: 107 additions & 0 deletions test/Graphics/Shape.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include <CSFML/Graphics/Shape.h>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Graphics] sfShape")
{
const auto getPointCount = [](void* userData) -> std::size_t
{ return static_cast<std::vector<sfVector2f>*>(userData)->size(); };
const auto getPoint = [](std::size_t index, void* userData) -> sfVector2f
{ return static_cast<std::vector<sfVector2f>*>(userData)->operator[](index); };
std::vector<sfVector2f> points = {{0, 0}, {30, 0}, {0, 30}};

SECTION("sfShape_create")
{
const sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
const sfVector2f position = sfShape_getPosition(shape);
CHECK(position.x == 0);
CHECK(position.y == 0);
CHECK(sfShape_getRotation(shape) == 0);
const sfVector2f scale = sfShape_getScale(shape);
CHECK(scale.x == 1);
CHECK(scale.y == 1);
const sfVector2f origin = sfShape_getOrigin(shape);
CHECK(origin.x == 0);
CHECK(origin.y == 0);
const sfTransform transform = sfShape_getTransform(shape);
const std::vector matrix(std::data(transform.matrix), std::data(transform.matrix) + std::size(transform.matrix));
CHECK(matrix == std::vector<float>({1, 0, 0, 0, 1, 0, 0, 0, 1}));
const sfTransform inverseTransform = sfShape_getInverseTransform(shape);
const std::vector inverseMatrix(std::data(inverseTransform.matrix),
std::data(inverseTransform.matrix) + std::size(inverseTransform.matrix));
CHECK(inverseMatrix == std::vector<float>({1, 0, 0, 0, 1, 0, 0, 0, 1}));
CHECK(sfShape_getTexture(shape) == nullptr);
const sfIntRect textureRect = sfShape_getTextureRect(shape);
CHECK(textureRect.position.x == 0);
CHECK(textureRect.position.y == 0);
CHECK(textureRect.size.x == 0);
CHECK(textureRect.size.y == 0);
const sfColor fillColor = sfShape_getFillColor(shape);
CHECK(fillColor.r == sfWhite.r);
CHECK(fillColor.g == sfWhite.g);
CHECK(fillColor.b == sfWhite.b);
CHECK(fillColor.a == sfWhite.a);
const sfColor outlineColor = sfShape_getOutlineColor(shape);
CHECK(outlineColor.r == sfWhite.r);
CHECK(outlineColor.g == sfWhite.g);
CHECK(outlineColor.b == sfWhite.b);
CHECK(outlineColor.a == sfWhite.a);
CHECK(sfShape_getOutlineThickness(shape) == 0);
CHECK(sfShape_getPointCount(shape) == 3);
const sfVector2f point = sfShape_getPoint(shape, 0);
CHECK(point.x == 0);
CHECK(point.y == 0);
const sfVector2f geometricCenter = sfShape_getGeometricCenter(shape);
CHECK(geometricCenter.x == 10);
CHECK(geometricCenter.y == 10);
const sfFloatRect localBounds = sfShape_getLocalBounds(shape);
CHECK(localBounds.position.x == 0);
CHECK(localBounds.position.y == 0);
CHECK(localBounds.size.x == 0);
CHECK(localBounds.size.y == 0);
const sfFloatRect globalBounds = sfShape_getGlobalBounds(shape);
CHECK(globalBounds.position.x == 0);
CHECK(globalBounds.position.y == 0);
CHECK(globalBounds.size.x == 0);
CHECK(globalBounds.size.y == 0);
sfShape_destroy(shape);
}

SECTION("Set/get position")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setPosition(shape, {10, 20});
const sfVector2f position = sfShape_getPosition(shape);
CHECK(position.x == 10);
CHECK(position.y == 20);
sfShape_destroy(shape);
}

SECTION("Set/get rotation")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setRotation(shape, 45);
CHECK(sfShape_getRotation(shape) == 45);
sfShape_destroy(shape);
}

SECTION("Set/get scale")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setScale(shape, {0.5f, 0.75f});
const sfVector2f scale = sfShape_getScale(shape);
CHECK(scale.x == 0.5f);
CHECK(scale.y == 0.75f);
sfShape_destroy(shape);
}

SECTION("Set/get origin")
{
sfShape* shape = sfShape_create(getPointCount, getPoint, &points);
sfShape_setOrigin(shape, {80, 90});
const sfVector2f origin = sfShape_getOrigin(shape);
CHECK(origin.x == 80);
CHECK(origin.y == 90);
sfShape_destroy(shape);
}
}
116 changes: 116 additions & 0 deletions test/Graphics/VertexArray.test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include <CSFML/Graphics/VertexArray.h>

#include <catch2/catch_test_macros.hpp>

TEST_CASE("[Graphics] sfVertexArray")
{
SECTION("sfVertexArray_create")
{
const sfVertexArray* vertexArray = sfVertexArray_create();
CHECK(sfVertexArray_getVertexCount(vertexArray) == 0);
CHECK(sfVertexArray_getPrimitiveType(vertexArray) == sfPoints);
const sfFloatRect bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 0);
CHECK(bounds.position.y == 0);
CHECK(bounds.size.x == 0);
CHECK(bounds.size.y == 0);
sfVertexArray_destroy(vertexArray);
}

SECTION("sfVertexArray_copy")
{
sfVertexArray* vertexArray1 = sfVertexArray_create();
sfVertexArray_resize(vertexArray1, 10);
sfVertexArray_setPrimitiveType(vertexArray1, sfLines);
const sfVertexArray* vertexArray2 = sfVertexArray_copy(vertexArray1);
CHECK(sfVertexArray_getVertexCount(vertexArray2) == 10);
CHECK(sfVertexArray_getPrimitiveType(vertexArray2) == sfLines);
sfVertexArray_destroy(vertexArray2);
sfVertexArray_destroy(vertexArray1);
}

SECTION("sfVertexArray_resize")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_resize(vertexArray, 42);
const auto vertexCount = sfVertexArray_getVertexCount(vertexArray);
CHECK(vertexCount == 42);
for (std::size_t i = 0; i < vertexCount; ++i)
{
const auto& vertex = *sfVertexArray_getVertex(vertexArray, i);
CHECK(vertex.position.x == 0);
CHECK(vertex.position.y == 0);
CHECK(+vertex.color.r == sfWhite.r);
CHECK(+vertex.color.g == sfWhite.g);
CHECK(+vertex.color.b == sfWhite.b);
CHECK(+vertex.color.a == sfWhite.a);
CHECK(vertex.texCoords.x == 0);
CHECK(vertex.texCoords.y == 0);
}
sfVertexArray_destroy(vertexArray);
}

SECTION("sfVertexArray_clear")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_resize(vertexArray, 13);
sfVertexArray_setPrimitiveType(vertexArray, sfLines);
sfVertexArray_clear(vertexArray);
CHECK(sfVertexArray_getVertexCount(vertexArray) == 0);
CHECK(sfVertexArray_getPrimitiveType(vertexArray) == sfLines);
sfVertexArray_destroy(vertexArray);
}

SECTION("sfVertexArray_append")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_append(vertexArray, {{1, 2}, {3, 4, 5, 6}, {7, 8}});
CHECK(sfVertexArray_getVertexCount(vertexArray) == 1);
const auto& vertex = *sfVertexArray_getVertex(vertexArray, 0);
CHECK(vertex.position.x == 1);
CHECK(vertex.position.y == 2);
CHECK(+vertex.color.r == 3);
CHECK(+vertex.color.g == 4);
CHECK(+vertex.color.b == 5);
CHECK(+vertex.color.a == 6);
CHECK(vertex.texCoords.x == 7);
CHECK(vertex.texCoords.y == 8);
sfVertexArray_destroy(vertexArray);
}

SECTION("sfVertexArray_getBounds")
{
sfVertexArray* vertexArray = sfVertexArray_create();
sfVertexArray_append(vertexArray, {{1, 1}, {}, {}});
sfVertexArray_append(vertexArray, {{2, 2}, {}, {}});

sfFloatRect bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 1);
CHECK(bounds.position.y == 1);
CHECK(bounds.size.x == 1);
CHECK(bounds.size.y == 1);

*sfVertexArray_getVertex(vertexArray, 0) = {{0, 0}, {}, {}};
bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 0);
CHECK(bounds.position.y == 0);
CHECK(bounds.size.x == 2);
CHECK(bounds.size.y == 2);

*sfVertexArray_getVertex(vertexArray, 0) = {{5, 5}, {}, {}};
bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 2);
CHECK(bounds.position.y == 2);
CHECK(bounds.size.x == 3);
CHECK(bounds.size.y == 3);

sfVertexArray_append(vertexArray, {{10, 10}, {}, {}});
bounds = sfVertexArray_getBounds(vertexArray);
CHECK(bounds.position.x == 2);
CHECK(bounds.position.y == 2);
CHECK(bounds.size.x == 8);
CHECK(bounds.size.y == 8);

sfVertexArray_destroy(vertexArray);
}
}
Loading
Loading