From 800c4eb4c45612bf4673c5647501e4aa966a6bf1 Mon Sep 17 00:00:00 2001 From: Anatoly Date: Fri, 17 Jul 2020 16:18:48 +0300 Subject: [PATCH] - minor tests fixes --- src/CMakeLists.txt | 46 ++++++++++++++++++++++++++++++++++++++------- src/domaintests.cpp | 16 ++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) create mode 100644 src/domaintests.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2fb93eb..c262023 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,33 @@ +# Defines the gtest & gtest_main libraries. User tests should link +# with one of them. +function(cxx_library_with_type name type cxx_flags) + # type can be either STATIC or SHARED to denote a static or shared library. + # ARGN refers to additional arguments after 'cxx_flags'. + add_library(${name} ${type} ${ARGN}) + set_target_properties(${name} + PROPERTIES + COMPILE_FLAGS "${cxx_flags}") + if (BUILD_SHARED_LIBS OR type STREQUAL "SHARED") + set_target_properties(${name} + PROPERTIES + COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") + endif() + if (CMAKE_USE_PTHREADS_INIT) + target_link_libraries(${name} ${CMAKE_THREAD_LIBS_INIT}) + endif() +endfunction() + +######################################################################## +# +# Helper functions for creating build targets. + +function(cxx_library name cxx_flags) + cxx_library_with_type(${name} "" "${cxx_flags}" ${ARGN}) +endfunction() + + set(GROMACS_CXX_FLAGS "${GROMACS_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") -set(SOURCES - src/domains.cpp - src/domaintype.cpp - src/newfit.cpp) -set(HEADERS - src/domaintype.h - src/newfit.h) + add_executable(domains domains.cpp domaintype.cpp newfit.cpp) include_directories( ${GROMACS_INCLUDE_DIRS} @@ -13,3 +35,13 @@ include_directories( set_target_properties(domains PROPERTIES COMPILE_FLAGS "${GROMACS_CXX_FLAGS}") target_link_libraries(domains ${GROMACS_LIBRARIES} ${OpenMP_CXX_LIBRARIES}) + + +cxx_library(gtest "${cxx_strict}" gtest/src/gtest-all.cc) +add_executable(domaintests domaintests.cpp domaintype.cpp newfit.cpp) +include_directories( + ${GROMACS_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src/gtest/include + ${CMAKE_SOURCE_DIR}/src/gtest) +target_link_libraries(domaintests ${GROMACS_LIBRARIES} ${OpenMP_CXX_LIBRARIES} gtest) diff --git a/src/domaintests.cpp b/src/domaintests.cpp new file mode 100644 index 0000000..a6a51c7 --- /dev/null +++ b/src/domaintests.cpp @@ -0,0 +1,16 @@ +#include +#include "gtest/gtest.h" + +int summary (int a, int b) { + return a + b; +} + +TEST( test001, test001 ) +{ + ASSERT_EQ(15, summary(10, 5)); +} + +int main(int argc, char *argv[]) { + ::testing::InitGoogleTest( &argc, argv ); + return RUN_ALL_TESTS(); +} -- 2.22.0