diff --git a/CMakeLists.txt b/CMakeLists.txt index 250f0c6..3658f32 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,4 +26,15 @@ add_subdirectory(extern/cnpy) add_subdirectory(src) # add project source code subdirectory -add_subdirectory(app) \ No newline at end of file +add_subdirectory(app) + +# download and enable google testing +include(cmake/googletest.cmake) +fetch_googletest( + ${PROJECT_SOURCE_DIR}/cmake + ${PROJECT_BINARY_DIR}/googletest + ) + +enable_testing() +# add project tests subdirectory +add_subdirectory(test) \ No newline at end of file diff --git a/cmake/googletest-download.cmake b/cmake/googletest-download.cmake new file mode 100644 index 0000000..4926683 --- /dev/null +++ b/cmake/googletest-download.cmake @@ -0,0 +1,20 @@ +# code copied from https://crascit.com/2015/07/25/cmake-gtest/ +cmake_minimum_required(VERSION 3.5 FATAL_ERROR) + +project(googletest-download NONE) + +include(ExternalProject) + +ExternalProject_Add( + googletest + SOURCE_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-src" + BINARY_DIR "@GOOGLETEST_DOWNLOAD_ROOT@/googletest-build" + GIT_REPOSITORY + https://github.com/google/googletest.git + GIT_TAG + release-1.8.0 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + TEST_COMMAND "" + ) diff --git a/cmake/googletest.cmake b/cmake/googletest.cmake new file mode 100644 index 0000000..5ca7090 --- /dev/null +++ b/cmake/googletest.cmake @@ -0,0 +1,32 @@ +# the following code to fetch googletest +# is inspired by and adapted after https://crascit.com/2015/07/25/cmake-gtest/ +# download and unpack googletest at configure time + +macro(fetch_googletest _download_module_path _download_root) + set(GOOGLETEST_DOWNLOAD_ROOT ${_download_root}) + configure_file( + ${_download_module_path}/googletest-download.cmake + ${_download_root}/CMakeLists.txt + @ONLY + ) + unset(GOOGLETEST_DOWNLOAD_ROOT) + + execute_process( + COMMAND + "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" . + WORKING_DIRECTORY + ${_download_root} + ) + execute_process( + COMMAND + "${CMAKE_COMMAND}" --build . + WORKING_DIRECTORY + ${_download_root} + ) + + # adds the targers: gtest, gtest_main, gmock, gmock_main + add_subdirectory( + ${_download_root}/googletest-src + ${_download_root}/googletest-build + ) +endmacro() diff --git a/scripts/run_tests.sh b/scripts/run_tests.sh new file mode 100644 index 0000000..acb32fb --- /dev/null +++ b/scripts/run_tests.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +echo 'Runnin Bunny Mesh Tests...' + +./build/bin/bunny_tests \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..7ac2160 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,24 @@ +add_executable( + bunny_tests + test_Mesh.cc + test_IO.cc + ) + +target_link_libraries( + bunny_tests + bunny_mesh + gtest_main + ) + +target_include_directories( + bunny_tests + PUBLIC + ${CMAKE_HOME_DIRECTORY}/include + ) + +add_test( + NAME + unit + COMMAND + ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/unit_tests + ) diff --git a/test/test_IO.cc b/test/test_IO.cc new file mode 100644 index 0000000..c938d9b --- /dev/null +++ b/test/test_IO.cc @@ -0,0 +1,7 @@ +#include "gtest/gtest.h" +#include "bunny_mesh/data_io.h" + +TEST(IO, positive) +{ + ASSERT_TRUE(true); +} \ No newline at end of file diff --git a/test/test_Mesh.cc b/test/test_Mesh.cc new file mode 100644 index 0000000..f33d055 --- /dev/null +++ b/test/test_Mesh.cc @@ -0,0 +1,7 @@ +#include "gtest/gtest.h" +#include "bunny_mesh/Mesh.h" + +TEST(Mesh, positive) +{ + ASSERT_TRUE(true); +} \ No newline at end of file