Skip to content

Commit b0b4d25

Browse files
committed
Add tests for sfVertexArray
1 parent 82d0ff2 commit b0b4d25

File tree

2 files changed

+117
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)