Skip to content

Commit 7708b2a

Browse files
authored
add SDL tests (#103)
* add SDL tests * add array include * change some asserts to expect * add output on failure flag to ctest * remove tests which only pass in headless or debug
1 parent 0d8cd08 commit 7708b2a

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

.github/workflows/sourcehold.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ jobs:
147147
run: |
148148
if [[ ${{ matrix.target-platform }} != 'ios-simulator' ]]; then
149149
pushd build/test
150-
ctest
150+
ctest --output-on-failure
151151
popd
152152
fi
153153

src/SDL/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ target_link_libraries(SourceholdSDL
1717
PRIVATE ProjectOptions
1818
PRIVATE System
1919
PUBLIC SDL2::SDL2
20-
PRIVATE Common
20+
PUBLIC Common
2121
)
2222

2323
add_library(Sourcehold::SDL ALIAS SourceholdSDL)

test/CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ add_test(CommonTest
2020

2121
target_link_libraries(CommonTest PRIVATE Common)
2222

23+
add_test(SDLTest
24+
SDLTest.cpp
25+
)
26+
27+
target_link_libraries(SDLTest PRIVATE Sourcehold::SDL)
28+
2329
add_test(RenderingTest
2430
ColorTest.cpp
2531
SurfaceTest.cpp
2632
)
2733

2834
target_link_libraries(RenderingTest PRIVATE Rendering)
2935

36+

test/SDLTest.cpp

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <gtest/gtest.h>
2+
#include <numeric>
3+
#include <array>
4+
#include "SDL/SDLBackend.h"
5+
using namespace Sourcehold::SDL;
6+
7+
TEST(SDLHelpers, At) {
8+
std::array<int, 100> groundtruth;
9+
std::iota(std::begin(groundtruth), std::end(groundtruth), 0);
10+
11+
for (auto y = 0; y < 10; ++y) {
12+
for (auto x = 0; x < 10; ++x) {
13+
ASSERT_EQ(At({x, y}, 10), groundtruth[At({x, y}, 10)]);
14+
}
15+
}
16+
}
17+
18+
TEST(SDLHelpers, ToSDLRectPtr) {
19+
Rect<int> rect = {1, 2, 3, 4};
20+
auto sdl_rect = ToSDLRectPtr(rect);
21+
22+
ASSERT_EQ(static_cast<void*>(sdl_rect), static_cast<void*>(&rect));
23+
ASSERT_EQ(sdl_rect->x, rect.x);
24+
ASSERT_EQ(sdl_rect->y, rect.y);
25+
ASSERT_EQ(sdl_rect->w, rect.w);
26+
ASSERT_EQ(sdl_rect->h, rect.h);
27+
}

0 commit comments

Comments
 (0)