From 35e479bc2863a70ca6c418664a4e00b6083204df Mon Sep 17 00:00:00 2001 From: Hugues Delorme Date: Tue, 11 Feb 2014 11:13:15 +0100 Subject: [PATCH] Add unit tests for expected platform behavior --- CMakeLists.txt | 9 ++++---- tests/test_platform.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 tests/test_platform.c diff --git a/CMakeLists.txt b/CMakeLists.txt index c075bb3..38ca8f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,10 +182,11 @@ enable_testing() set(CMAKE_CTEST_COMMAND ctest -V) add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) -add_executable(test_internal EXCLUDE_FROM_ALL tests/test_internal.c - tests/stream_buffer.c +add_executable(test_internal EXCLUDE_FROM_ALL tests/stream_buffer.c + tests/test_internal.c src/stream.c src/internal/ascii_parse.c) +add_executable(test_platform EXCLUDE_FROM_ALL tests/test_platform.c) add_test(test_internal test_internal) -add_dependencies(check test_internal) - +add_test(test_platform test_platform) +add_dependencies(check test_internal test_platform) diff --git a/tests/test_platform.c b/tests/test_platform.c new file mode 100644 index 0000000..27c914f --- /dev/null +++ b/tests/test_platform.c @@ -0,0 +1,50 @@ +#include "utest_lib.h" + +#include "../src/global.h" +#include "../src/libstl/stl_triangle.h" + +#include + +const char* test_platform__alignment() +{ + UTEST_ASSERT(offsetof(foug_stl_coords_t, x) == 0); + UTEST_ASSERT(offsetof(foug_stl_coords_t, y) == 4); + UTEST_ASSERT(offsetof(foug_stl_coords_t, z) == 8); + UTEST_ASSERT(sizeof(foug_stl_coords_t) == FOUG_STL_COORDS_RAWSIZE); + + UTEST_ASSERT(offsetof(foug_stl_triangle_t, normal) == 0); + UTEST_ASSERT(offsetof(foug_stl_triangle_t, v1) == FOUG_STL_COORDS_RAWSIZE); + UTEST_ASSERT(offsetof(foug_stl_triangle_t, v2) == 2*FOUG_STL_COORDS_RAWSIZE); + UTEST_ASSERT(offsetof(foug_stl_triangle_t, v3) == 3*FOUG_STL_COORDS_RAWSIZE); + UTEST_ASSERT(offsetof(foug_stl_triangle_t, attribute_byte_count) == 4*FOUG_STL_COORDS_RAWSIZE); + UTEST_ASSERT(sizeof(foug_stl_triangle_t) >= FOUG_STLB_TRIANGLE_RAWSIZE); + + return NULL; +} + +const char* test_platform__global_h() +{ + UTEST_ASSERT(sizeof(int8_t) == 1); + UTEST_ASSERT(sizeof(uint8_t) == 1); + + UTEST_ASSERT(sizeof(int16_t) == 2); + UTEST_ASSERT(sizeof(uint16_t) == 2); + + UTEST_ASSERT(sizeof(int32_t) == 4); + UTEST_ASSERT(sizeof(uint32_t) == 4); + + UTEST_ASSERT(sizeof(foug_real32_t) == 4); + UTEST_ASSERT(sizeof(foug_real64_t) == 8); + + return NULL; +} + +const char* all_tests() +{ + UTEST_SUITE_START(); + UTEST_RUN(test_platform__alignment); + UTEST_RUN(test_platform__global_h); + return NULL; +} + +UTEST_MAIN(all_tests)