Skip to content

Commit

Permalink
Added Google Testing Support to Bunny Mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroperrusi committed Feb 7, 2019
1 parent a0a2290 commit 1b228d4
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 1 deletion.
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,15 @@ add_subdirectory(extern/cnpy)
add_subdirectory(src)

# add project source code subdirectory
add_subdirectory(app)
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)
20 changes: 20 additions & 0 deletions cmake/googletest-download.cmake
Original file line number Diff line number Diff line change
@@ -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 ""
)
32 changes: 32 additions & 0 deletions cmake/googletest.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

echo 'Runnin Bunny Mesh Tests...'

./build/bin/bunny_tests
24 changes: 24 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
7 changes: 7 additions & 0 deletions test/test_IO.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "gtest/gtest.h"
#include "bunny_mesh/data_io.h"

TEST(IO, positive)
{
ASSERT_TRUE(true);
}
7 changes: 7 additions & 0 deletions test/test_Mesh.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "gtest/gtest.h"
#include "bunny_mesh/Mesh.h"

TEST(Mesh, positive)
{
ASSERT_TRUE(true);
}

0 comments on commit 1b228d4

Please sign in to comment.