From 413ff4e558dabc7e1e79688e54ab3acaf1474bfc Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Thu, 9 Feb 2017 19:31:38 +0000 Subject: [PATCH] Expose private functions in grid_raytrace for unit testing. --- src/gamelib/grid_raytrace.cpp | 4 ++++ src/gamelib/grid_raytrace.hpp | 5 +++++ src/mycurry_toplevelConfig.h.in | 1 + test/unit/CMakeLists.txt | 1 + 4 files changed, 11 insertions(+) diff --git a/src/gamelib/grid_raytrace.cpp b/src/gamelib/grid_raytrace.cpp index 5fd8519..862e0db 100644 --- a/src/gamelib/grid_raytrace.cpp +++ b/src/gamelib/grid_raytrace.cpp @@ -30,7 +30,9 @@ #include namespace curry { +#if !defined(BUILD_TESTING) namespace { +#endif float inv_length (const vec2f& parVec) { return 1.0f / std::sqrt(parVec.x() * parVec.x() + parVec.y() * parVec.y()); } @@ -77,7 +79,9 @@ namespace curry { //else //return INFINITY; } +#if !defined(BUILD_TESTING) } //unnamed namespace +#endif //see: //http://stackoverflow.com/questions/24679963/precise-subpixel-line-drawing-algorithm-rasterization-algorithm diff --git a/src/gamelib/grid_raytrace.hpp b/src/gamelib/grid_raytrace.hpp index f3ab590..80b7123 100644 --- a/src/gamelib/grid_raytrace.hpp +++ b/src/gamelib/grid_raytrace.hpp @@ -20,12 +20,17 @@ #pragma once #include "vector.hpp" +#include "mycurry_toplevelConfig.h" #include namespace curry { class WorldGrid; class TileProperty; +#if defined(BUILD_TESTING) + float segment_intersection (const vec2f& parA, const vec2f& parDirA, const vec2f& parB, const vec2f& parDirB); +#endif + struct WorldTileProperty { vec2us index; const TileProperty* property; diff --git a/src/mycurry_toplevelConfig.h.in b/src/mycurry_toplevelConfig.h.in index 165dab5..ac6f3c4 100644 --- a/src/mycurry_toplevelConfig.h.in +++ b/src/mycurry_toplevelConfig.h.in @@ -20,3 +20,4 @@ #pragma once #define RESOURCES_PATH "@MYCURRY_RESOURCES_PATH@/" +#cmakedefine BUILD_TESTING diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 4134d13..4e3d6bf 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -17,6 +17,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src/gamelib PRIVATE ${CMAKE_SOURCE_DIR}/lib/vectorwrapper/include PRIVATE ${CMAKE_SOURCE_DIR}/lib/tree-2.81/src + PRIVATE ${CMAKE_BINARY_DIR} ) add_test(