From 23ed1151eda8d939fcdd85dceb39773b12ac17f3 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Sat, 5 Aug 2017 11:06:06 +0100 Subject: Adding googletest for test bench --- .dir-locals.el | 9 +++++--- .gitmodules | 4 ++++ CMakeLists.txt | 35 +++++++++++++++++-------------- README.md | 4 ++-- googletest | 1 + test/matrixtest.cpp | 60 +++++++++++++++++++++++------------------------------ 6 files changed, 59 insertions(+), 54 deletions(-) create mode 100644 .gitmodules create mode 160000 googletest diff --git a/.dir-locals.el b/.dir-locals.el index 4afe10c5..7f49a89d 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -2,15 +2,18 @@ "-I../../include/YAGE/" "-I../../../include/YAGE/" "-I/usr/include/" - "-I/usr/include/SDL2/")) + "-I/usr/include/SDL2/" + "-I../googletest/googletest/include/")) (company-c-headers-path-user . ("../include/YAGE/" "../../include/YAGE/" "../../../include/YAGE/" "/usr/include/" - "/usr/include/SDL2/")) + "/usr/include/SDL2/" + "../googletest/googletest/include/")) (flycheck-clang-include-path . ("../include/YAGE/" "../../include/YAGE/" "../../../include/YAGE/" "/usr/include/" - "/usr/include/SDL2/"))))) + "/usr/include/SDL2/" + "../googletest/googletest/include"))))) diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..e07c3b23 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "googletest"] + path = googletest + url = https://github.com/google/googletest.git + branch = master diff --git a/CMakeLists.txt b/CMakeLists.txt index 23efffdb..77de0782 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,21 @@ set(YAGE_SOURCES ${PROJECT_SOURCE_DIR}/src/texturecache.cpp ${PROJECT_SOURCE_DIR}/src/window.cpp) +# Initializing google test +# prevents overriding the parent project's compiler/linter settings on windows +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# Add googletest directly to our build. This defines +# the gtest and gtest_main targets. +add_subdirectory(${PROJECT_SOURCE_DIR}/googletest) + +# The gtest/gtest_main targets carry header search path +# dependencies automatically when using CMake 2.8.11 or +# later. Otherwise we have to add them here ourselves. +if (CMAKE_VERSION VERSION_LESS 2.8.11) + include_directories("${gtest_SOURCE_DIR}/include") +endif() + # find libraries find_package(OpenGL REQUIRED) find_package(GLEW REQUIRED) @@ -54,23 +69,13 @@ include_directories(${YAGE_INCLUDE_DIR} # make it a static library add_library(${PROJECT_NAME} ${YAGE_SOURCES}) -# add tests -add_executable(rigidbodytest - ${YAGE_TEST_DIR}/rigidbodytest.cpp) -target_link_libraries(rigidbodytest - ${YAGE_LIBRARIES} - ${OPENGL_LIBRARIES} - ${GLEW_LIBRARIES}) - -add_executable(matrixtest - ${YAGE_TEST_DIR}/matrixtest.cpp - ${YAGE_TEST_DIR}/testbench.cpp) -target_link_libraries(matrixtest - ${YAGE_LIBRARIES} +set(YAGE_LIB_DEP_L yage ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES}) # enable tests enable_testing() -add_test(RigidBodyTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/rigidbodytest) -add_test(MatrixTest ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/matrixtest) + +add_executable(matrixtest ${YAGE_TEST_DIR}/matrixtest.cpp) +target_link_libraries(matrixtest gtest_main ${YAGE_LIB_DEP_L}) +add_test(NAME matrixtest COMMAND matrixtest) diff --git a/README.md b/README.md index 52432bbc..d31829a2 100644 --- a/README.md +++ b/README.md @@ -6,5 +6,5 @@ YAGE stands for Yet Another Game Engine. License ------- -Copyright (c) 2017 Yann Herklotz Grave -- MIT License, -see file LICENSE for more details. +Copyright (c) 2017 Yann Herklotz Grave -- MIT License, +see file [LICENSE](/LICENSE) for more details. diff --git a/googletest b/googletest new file mode 160000 index 00000000..ca102b1f --- /dev/null +++ b/googletest @@ -0,0 +1 @@ +Subproject commit ca102b1f9d1f4c8a8c6f7a87b3e80d0af4b8789f diff --git a/test/matrixtest.cpp b/test/matrixtest.cpp index c84118df..aecf4c87 100644 --- a/test/matrixtest.cpp +++ b/test/matrixtest.cpp @@ -8,37 +8,25 @@ #include "Math/math.hpp" -#include "testbench.hpp" +#include "gtest/gtest.h" -void test(TestBench &tb, const std::string &test_name, bool result) -{ - tb.startTest(test_name); - tb.endTest(result); - if(!result) - { - throw std::runtime_error(test_name+" failed..."); - } -} - -bool matrixAssign() +int matrixAssign(int number) { yage::Matrix<4, 5, int> m; - m[2][3]=5; + m[2][3]=number; - return m[2][3]==5; + return m[2][3]; } -bool matrixAddition() +int matrixAddition(int num1, int num2) { yage::Matrix<4, 4, int> m1, m2; - m1[1][1]=293; - m2[1][1]=583; + m1[1][1]=num1; + m2[1][1]=num2; yage::Matrix<4, 4, int> m3=m1+m2; - std::cout<