2016-11-28 14:33:50 +01:00
|
|
|
cmake_minimum_required(VERSION 2.6)
|
2016-11-28 23:27:21 +01:00
|
|
|
|
2017-06-05 23:08:14 +02:00
|
|
|
option(DISABLE_RCT2_TESTS "Disable tests that require RollerCoaster Tycoon 2 assets.")
|
|
|
|
|
2016-11-28 14:37:27 +01:00
|
|
|
# Bootstrap GoogleTest
|
2016-11-28 23:27:21 +01:00
|
|
|
INCLUDE(ExternalProject)
|
|
|
|
|
|
|
|
ExternalProject_Add(
|
2017-05-08 18:28:33 +02:00
|
|
|
googletest-distribution
|
|
|
|
URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz
|
|
|
|
URL_HASH SHA1=e7e646a6204638fe8e87e165292b8dd9cd4c36ed
|
|
|
|
TIMEOUT 10
|
|
|
|
CONFIGURE_COMMAND ""
|
|
|
|
BUILD_COMMAND ""
|
|
|
|
INSTALL_COMMAND ""
|
2016-11-28 23:27:21 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
# Specify include dir
|
|
|
|
ExternalProject_Get_Property(googletest-distribution SOURCE_DIR)
|
|
|
|
set(GOOGLETEST_DISTRIB_SOURCE_DIR "${SOURCE_DIR}")
|
|
|
|
|
|
|
|
ExternalProject_Add(
|
2017-05-08 18:28:33 +02:00
|
|
|
googletest
|
|
|
|
DEPENDS googletest-distribution
|
|
|
|
DOWNLOAD_COMMAND ""
|
|
|
|
SOURCE_DIR "${GOOGLETEST_DISTRIB_SOURCE_DIR}/googletest"
|
|
|
|
CMAKE_ARGS "-DCMAKE_CXX_FLAGS=${TARGET_M}"
|
|
|
|
BUILD_BYPRODUCTS "googletest-prefix/src/googletest-build/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}"
|
|
|
|
BUILD_BYPRODUCTS "googletest-prefix/src/googletest-build/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX}"
|
|
|
|
# Disable install step
|
|
|
|
INSTALL_COMMAND ""
|
|
|
|
# Wrap download, configure and build steps in a script to log output
|
|
|
|
LOG_DOWNLOAD ON
|
|
|
|
LOG_CONFIGURE ON
|
|
|
|
LOG_BUILD ON)
|
2016-11-28 23:27:21 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Specify include dir
|
|
|
|
set(GTEST_INCLUDE_DIR ${GOOGLETEST_DISTRIB_SOURCE_DIR}/googletest/include)
|
|
|
|
|
|
|
|
# Library
|
|
|
|
ExternalProject_Get_Property(googletest BINARY_DIR)
|
|
|
|
set(GOOGLETEST_BINARY_DIR "${BINARY_DIR}")
|
2016-11-29 23:57:30 +01:00
|
|
|
set(GTEST_LIBRARY_PATH ${GOOGLETEST_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX})
|
|
|
|
set(GTEST_MAIN_LIBRARY_PATH ${GOOGLETEST_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest_main${CMAKE_STATIC_LIBRARY_SUFFIX})
|
2016-11-28 23:27:21 +01:00
|
|
|
set(GTEST_LIBRARY gtest)
|
|
|
|
set(GTEST_MAIN_LIBRARY gtest_main)
|
2016-11-29 23:57:30 +01:00
|
|
|
add_library(${GTEST_LIBRARY} STATIC IMPORTED)
|
|
|
|
add_library(${GTEST_MAIN_LIBRARY} STATIC IMPORTED)
|
2016-11-28 23:27:21 +01:00
|
|
|
set_property(TARGET ${GTEST_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_LIBRARY_PATH})
|
|
|
|
set_property(TARGET ${GTEST_MAIN_LIBRARY} PROPERTY IMPORTED_LOCATION ${GTEST_MAIN_LIBRARY_PATH})
|
|
|
|
add_dependencies(${GTEST_LIBRARY} googletest)
|
|
|
|
add_dependencies(${GTEST_MAIN_LIBRARY} ${GTEST_LIBRARY})
|
|
|
|
|
2016-11-28 14:37:27 +01:00
|
|
|
include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
|
2017-05-08 18:35:15 +02:00
|
|
|
include_directories("${ROOT_DIR}/src")
|
2017-05-08 22:03:10 +02:00
|
|
|
include_directories(${SDL2_INCLUDE_DIRS})
|
2016-11-30 11:51:55 +01:00
|
|
|
|
|
|
|
set(GTEST_LIBRARIES gtest gtest_main pthread)
|
2016-11-28 14:37:27 +01:00
|
|
|
|
2017-02-24 23:04:20 +01:00
|
|
|
# Some most common files required in tests
|
|
|
|
set(COMMON_TEST_SOURCES
|
2017-05-08 18:35:15 +02:00
|
|
|
"${ROOT_DIR}/src/openrct2/core/Console.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/core/Diagnostics.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/core/Guard.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/core/String.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/diagnostic.c"
|
|
|
|
"${ROOT_DIR}/src/openrct2/localisation/format_codes.c"
|
|
|
|
"${ROOT_DIR}/src/openrct2/localisation/utf8.c"
|
|
|
|
"${ROOT_DIR}/src/openrct2/util/util.c"
|
|
|
|
"${ROOT_DIR}/src/openrct2/Version.cpp"
|
2017-05-08 18:28:33 +02:00
|
|
|
)
|
2017-02-24 23:04:20 +01:00
|
|
|
|
|
|
|
# Create a re-usable library to save some compilation time
|
|
|
|
add_library(test-common STATIC ${COMMON_TEST_SOURCES})
|
|
|
|
|
2017-06-05 23:08:14 +02:00
|
|
|
# Setup testdata. It should be fine here, as the only way to reach here is by explicitly requesting tests.
|
|
|
|
if (NOT "z$ENV{CI}" STREQUAL "z")
|
|
|
|
message("Detected CI environment. Disabling ride rating test.")
|
|
|
|
set(DISABLE_RCT2_TESTS ON)
|
|
|
|
endif ()
|
|
|
|
|
|
|
|
if (NOT DISABLE_RCT2_TESTS)
|
2017-06-05 23:09:43 +02:00
|
|
|
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_LIST_DIR}/testdata" "${CMAKE_CURRENT_BINARY_DIR}/testdata")
|
2017-06-05 23:08:14 +02:00
|
|
|
endif ()
|
|
|
|
|
2016-11-28 14:37:27 +01:00
|
|
|
# Start of our tests
|
2016-11-28 23:27:21 +01:00
|
|
|
|
2016-11-30 11:51:55 +01:00
|
|
|
# sawyercoding test
|
|
|
|
|
2016-12-28 13:39:21 +01:00
|
|
|
set(SAWYERCODING_TEST_SOURCES
|
2017-05-08 18:35:15 +02:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/sawyercoding_test.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/diagnostic.c"
|
|
|
|
"${ROOT_DIR}/src/openrct2/util/sawyercoding.c"
|
|
|
|
"${ROOT_DIR}/src/openrct2/localisation/utf8.c"
|
2017-05-08 18:28:33 +02:00
|
|
|
)
|
2016-11-28 14:33:50 +01:00
|
|
|
add_executable(test_sawyercoding ${SAWYERCODING_TEST_SOURCES})
|
2016-11-30 11:51:55 +01:00
|
|
|
target_link_libraries(test_sawyercoding ${GTEST_LIBRARIES})
|
|
|
|
add_test(NAME sawyercoding COMMAND test_sawyercoding)
|
|
|
|
|
|
|
|
# LanguagePack test
|
|
|
|
set(LANGUAGEPACK_TEST_SOURCES
|
2017-05-08 18:35:15 +02:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/LanguagePackTest.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/localisation/LanguagePack.cpp"
|
2017-05-08 18:28:33 +02:00
|
|
|
)
|
2016-11-30 11:51:55 +01:00
|
|
|
add_executable(test_languagepack ${LANGUAGEPACK_TEST_SOURCES})
|
2017-02-25 00:10:27 +01:00
|
|
|
target_link_libraries(test_languagepack ${GTEST_LIBRARIES} test-common dl z SDL2)
|
2016-12-15 17:55:17 +01:00
|
|
|
add_test(NAME languagepack COMMAND test_languagepack)
|
2017-02-23 23:26:11 +01:00
|
|
|
|
2017-02-24 23:04:20 +01:00
|
|
|
# INI test
|
2017-02-23 23:26:11 +01:00
|
|
|
set(INI_TEST_SOURCES
|
2017-05-08 18:35:15 +02:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/IniWriterTest.cpp"
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/IniReaderTest.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/config/IniReader.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/config/IniWriter.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/core/IStream.cpp"
|
|
|
|
"${ROOT_DIR}/src/openrct2/core/MemoryStream.cpp"
|
2017-05-08 18:28:33 +02:00
|
|
|
)
|
2017-02-23 23:26:11 +01:00
|
|
|
add_executable(test_ini ${INI_TEST_SOURCES})
|
2017-02-24 23:04:20 +01:00
|
|
|
target_link_libraries(test_ini ${GTEST_LIBRARIES} test-common dl z)
|
2017-02-23 23:26:11 +01:00
|
|
|
add_test(NAME ini COMMAND test_ini)
|
2017-02-24 23:04:36 +01:00
|
|
|
|
|
|
|
# String test
|
|
|
|
set(STRING_TEST_SOURCES
|
2017-05-08 18:35:15 +02:00
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/StringTest.cpp"
|
2017-05-08 18:28:33 +02:00
|
|
|
)
|
2017-02-24 23:04:36 +01:00
|
|
|
add_executable(test_string ${STRING_TEST_SOURCES})
|
|
|
|
target_link_libraries(test_string ${GTEST_LIBRARIES} test-common dl z)
|
|
|
|
add_test(NAME string COMMAND test_string)
|
2017-06-03 15:39:40 +02:00
|
|
|
|
|
|
|
# Ride ratings test
|
2017-06-05 23:08:14 +02:00
|
|
|
if (NOT DISABLE_RCT2_TESTS)
|
2017-06-05 22:51:57 +02:00
|
|
|
set(RIDE_RATINGS_TEST_SOURCES "${CMAKE_CURRENT_LIST_DIR}/RideRatings.cpp"
|
|
|
|
"${CMAKE_CURRENT_LIST_DIR}/TestData.cpp")
|
|
|
|
add_executable(test_ride_ratings ${RIDE_RATINGS_TEST_SOURCES})
|
|
|
|
target_link_libraries(test_ride_ratings ${GTEST_LIBRARIES} libopenrct2 dl z)
|
|
|
|
add_test(NAME ride_ratings COMMAND test_ride_ratings)
|
|
|
|
endif ()
|