diff options
author | jkoan <jkoan@gmx.de> | 2023-01-17 21:07:15 +0100 |
---|---|---|
committer | jkoan <jkoan@gmx.de> | 2023-02-04 20:21:12 +0100 |
commit | 71bc50eaac4342c79f935394beef7686d7acb870 (patch) | |
tree | 2a18de812ce730cb69f90921266855996b61ed71 | |
parent | d4509f6c64a1b4c05a50a0b16906b871367a77c8 (diff) | |
download | navit-71bc50eaac4342c79f935394beef7686d7acb870.tar.gz |
change:core:Update googletest to last cmake tutorial
-rwxr-xr-x | CMakeLists.txt | 58 | ||||
-rw-r--r-- | test/CMakeLists.txt | 23 | ||||
-rw-r--r-- | test/main.cpp | 6 | ||||
-rw-r--r-- | test/search.cpp | 2 | ||||
-rw-r--r-- | test/suntime.cpp | 24 |
5 files changed, 53 insertions, 60 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b416035e..aaac464f6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -937,53 +937,17 @@ option(ENABLE_UNIT_TESTS "Enable unit tests" ON) message(STATUS "Enable testing: ${ENABLE_UNIT_TESTS}") if(ENABLE_UNIT_TESTS) - configure_file(cmake/googletest.cmake googletest-download/CMakeLists.txt) - execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) - if(result) - message(FATAL_ERROR "CMake step for googletest failed: ${result}") - endif() - execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download ) - if(result) - message(FATAL_ERROR "Build step for googletest failed: ${result}") - endif() - - # Prevent overriding the parent project's compiler/linker - # settings on Windows + include(FetchContent) + FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip + ) + # For Windows: Prevent overriding the parent project's compiler/linker settings set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + FetchContent_MakeAvailable(googletest) - # Add googletest directly to our build. This defines - # the gtest and gtest_main targets. - add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src - ${CMAKE_CURRENT_BINARY_DIR}/googletest-build - EXCLUDE_FROM_ALL) - - # 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() - - # Now simply link against gtest or gtest_main as needed. Eg - add_executable(unit_tests "") - - target_sources( - unit_tests - PRIVATE - search.cpp - main.cpp - ) + enable_testing() + + add_subdirectory (test) - target_link_libraries( - unit_tests - PRIVATE - navit - gtest_main - ) - - add_test(unit ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/unit_tests) -endif() +endif(ENABLE_UNIT_TESTS) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index eef472b3a..6f1831040 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,10 +1,21 @@ file(GLOB TEST_FILES_SOURCES "*.cpp") -add_executable(unit_tests ${TEST_FILES_SOURCES}) +set_property(TARGET navit PROPERTY ENABLE_EXPORTS 1) -target_link_libraries(unit_tests navit) +include_directories( "${PROJECT_BINARY_DIR}") +include_directories( "${PROJECT_SOURCE_DIR}") +include_directories( "${PROJECT_BINARY_DIR}/navit") +include_directories( "${PROJECT_SOURCE_DIR}/navit") -add_test( - NAME unit - COMMAND ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}/unit_tests - ) +add_executable(unit_tests "") + +target_sources( + unit_tests + PRIVATE + ${TEST_FILES_SOURCES} +) + +target_link_libraries(unit_tests PRIVATE navit GTest::gtest_main ) + +include(GoogleTest) +gtest_discover_tests(unit_tests) diff --git a/test/main.cpp b/test/main.cpp deleted file mode 100644 index 64becff4b..000000000 --- a/test/main.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include <gtest/gtest.h> - -int main(int argc, char **argv) { - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/test/search.cpp b/test/search.cpp index a5f114e0a..e79774f3c 100644 --- a/test/search.cpp +++ b/test/search.cpp @@ -1,4 +1,4 @@ -#include "search.h" +#include "navit/search.h" #include <gtest/gtest.h> TEST(SearchTestSuite, search_fix_spaces) { diff --git a/test/suntime.cpp b/test/suntime.cpp new file mode 100644 index 000000000..cb80939ef --- /dev/null +++ b/test/suntime.cpp @@ -0,0 +1,24 @@ +extern "C"{ +#include <math.h> +#include "sunriset.h" +} +#include <gtest/gtest.h> + +TEST(SearchTestSuite, sunriset_equator) { + double rise; + double tset; + // Values from https://api.sunrise-sunset.org/json?lat=0.0&lng=0.0&date=2020-01-01 + ASSERT_EQ(__sunriset__(2020,1,1,0.0,0.0,-0.8,1,&rise,&tset), 0); + ASSERT_EQ(HOURS(rise),5); + ASSERT_EQ(HOURS(tset),18); + // TODO: Check minutes in Range? +} + +TEST(SearchTestSuite, pole) { + double rise; + double tset; + // https://api.sunrise-sunset.org/json?lat=90.0&lng=0.0&date=2020-01-01 + ASSERT_EQ(__sunriset__(2020,1,1,90.0,0.0,-0.8,1,&rise,&tset), 0); + ASSERT_EQ(HOURS(rise),12); + ASSERT_EQ(HOURS(tset),12); +} |