Skip to content

Commit a5c2e7a

Browse files
committed
Add tests for sfVertexArray
1 parent 86a7828 commit a5c2e7a

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ add_executable(test-csfml-graphics
5252
Graphics/RenderStates.test.cpp
5353
Graphics/StencilMode.test.cpp
5454
Graphics/Transform.test.cpp
55+
Graphics/VertexArray.test.cpp
5556
)
5657
target_link_libraries(test-csfml-graphics PRIVATE csfml-graphics Catch2::Catch2WithMain SFML::Graphics)
5758
set_target_warnings(test-csfml-graphics)

test/Graphics/VertexArray.test.cpp

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#include <CSFML/Graphics/VertexArray.h>
2+
3+
#include <catch2/catch_test_macros.hpp>
4+
5+
#include "CSFML/Graphics/PrimitiveType.h"
6+
7+
TEST_CASE("[Graphics] sfVertexArray")
8+
{
9+
SECTION("sfVertexArray_create")
10+
{
11+
const sfVertexArray* vertexArray = sfVertexArray_create();
12+
CHECK(sfVertexArray_getVertexCount(vertexArray) == 0);
13+
CHECK(sfVertexArray_getPrimitiveType(vertexArray) == sfPoints);
14+
const sfFloatRect bounds = sfVertexArray_getBounds(vertexArray);
15+
CHECK(bounds.position.x == 0);
16+
CHECK(bounds.position.y == 0);
17+
CHECK(bounds.size.x == 0);
18+
CHECK(bounds.size.y == 0);
19+
sfVertexArray_destroy(vertexArray);
20+
}
21+
22+
SECTION("sfVertexArray_copy")
23+
{
24+
sfVertexArray* vertexArray1 = sfVertexArray_create();
25+
sfVertexArray_resize(vertexArray1, 10);
26+
sfVertexArray_setPrimitiveType(vertexArray1, sfLines);
27+
const sfVertexArray* vertexArray2 = sfVertexArray_copy(vertexArray1);
28+
CHECK(sfVertexArray_getVertexCount(vertexArray2) == 10);
29+
CHECK(sfVertexArray_getPrimitiveType(vertexArray2) == sfLines);
30+
sfVertexArray_destroy(vertexArray2);
31+
sfVertexArray_destroy(vertexArray1);
32+
}
33+
34+
SECTION("sfVertexArray_resize")
35+
{
36+
sfVertexArray* vertexArray = sfVertexArray_create();
37+
sfVertexArray_resize(vertexArray, 42);
38+
const auto vertexCount = sfVertexArray_getVertexCount(vertexArray);
39+
CHECK(vertexCount == 42);
40+
for (std::size_t i = 0; i < vertexCount; ++i)
41+
{
42+
const auto& vertex = *sfVertexArray_getVertex(vertexArray, i);
43+
CHECK(vertex.position.x == 0);
44+
CHECK(vertex.position.y == 0);
45+
CHECK(+vertex.color.r == sfWhite.r);
46+
CHECK(+vertex.color.g == sfWhite.g);
47+
CHECK(+vertex.color.b == sfWhite.b);
48+
CHECK(+vertex.color.a == sfWhite.a);
49+
CHECK(vertex.texCoords.x == 0);
50+
CHECK(vertex.texCoords.y == 0);
51+
}
52+
sfVertexArray_destroy(vertexArray);
53+
}
54+
55+
SECTION("sfVertexArray_clear")
56+
{
57+
sfVertexArray* vertexArray = sfVertexArray_create();
58+
sfVertexArray_resize(vertexArray, 13);
59+
sfVertexArray_setPrimitiveType(vertexArray, sfLines);
60+
sfVertexArray_clear(vertexArray);
61+
CHECK(sfVertexArray_getVertexCount(vertexArray) == 0);
62+
CHECK(sfVertexArray_getPrimitiveType(vertexArray) == sfLines);
63+
sfVertexArray_destroy(vertexArray);
64+
}
65+
66+
SECTION("sfVertexArray_append")
67+
{
68+
sfVertexArray* vertexArray = sfVertexArray_create();
69+
sfVertexArray_append(vertexArray, {{1, 2}, {3, 4, 5, 6}, {7, 8}});
70+
CHECK(sfVertexArray_getVertexCount(vertexArray) == 1);
71+
const auto& vertex = *sfVertexArray_getVertex(vertexArray, 0);
72+
CHECK(vertex.position.x == 1);
73+
CHECK(vertex.position.y == 2);
74+
CHECK(+vertex.color.r == 3);
75+
CHECK(+vertex.color.g == 4);
76+
CHECK(+vertex.color.b == 5);
77+
CHECK(+vertex.color.a == 6);
78+
CHECK(vertex.texCoords.x == 7);
79+
CHECK(vertex.texCoords.y == 8);
80+
sfVertexArray_destroy(vertexArray);
81+
}
82+
83+
SECTION("sfVertexArray_getBounds")
84+
{
85+
sfVertexArray* vertexArray = sfVertexArray_create();
86+
sfVertexArray_append(vertexArray, {{1, 1}, {}, {}});
87+
sfVertexArray_append(vertexArray, {{2, 2}, {}, {}});
88+
89+
sfFloatRect bounds = sfVertexArray_getBounds(vertexArray);
90+
CHECK(bounds.position.x == 1);
91+
CHECK(bounds.position.y == 1);
92+
CHECK(bounds.size.x == 1);
93+
CHECK(bounds.size.y == 1);
94+
95+
*sfVertexArray_getVertex(vertexArray, 0) = {{0, 0}, {}, {}};
96+
bounds = sfVertexArray_getBounds(vertexArray);
97+
CHECK(bounds.position.x == 0);
98+
CHECK(bounds.position.y == 0);
99+
CHECK(bounds.size.x == 2);
100+
CHECK(bounds.size.y == 2);
101+
102+
*sfVertexArray_getVertex(vertexArray, 0) = {{5, 5}, {}, {}};
103+
bounds = sfVertexArray_getBounds(vertexArray);
104+
CHECK(bounds.position.x == 2);
105+
CHECK(bounds.position.y == 2);
106+
CHECK(bounds.size.x == 3);
107+
CHECK(bounds.size.y == 3);
108+
109+
sfVertexArray_append(vertexArray, {{10, 10}, {}, {}});
110+
bounds = sfVertexArray_getBounds(vertexArray);
111+
CHECK(bounds.position.x == 2);
112+
CHECK(bounds.position.y == 2);
113+
CHECK(bounds.size.x == 8);
114+
CHECK(bounds.size.y == 8);
115+
116+
sfVertexArray_destroy(vertexArray);
117+
}
118+
}

0 commit comments

Comments
 (0)