56 lines
2.6 KiB
CMake
56 lines
2.6 KiB
CMake
# 单元测试(设计 §12)。M1 spike 阶段先放一个 gtest 冒烟用例,
|
||
# 验证 gtest 经 vcpkg 接入、ctest 可跑;随 core/data/algo 实现补充真实用例。
|
||
|
||
find_package(GTest CONFIG REQUIRED)
|
||
|
||
add_executable(geopro_tests smoke_test.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE GTest::gtest GTest::gtest_main)
|
||
|
||
include(GoogleTest)
|
||
|
||
# PROJ 运行时需要数据目录(proj.db 等)。vcpkg 把数据装在 share/proj 下。
|
||
# 通过测试环境变量 PROJ_DATA 注入,使 `ctest -R CrsTransform` 无需调用方手动 set。
|
||
file(GLOB _proj_data_dirs
|
||
"${CMAKE_BINARY_DIR}/vcpkg_installed/*/share/proj"
|
||
)
|
||
# DISCOVERY_MODE PRE_TEST:把用例枚举推迟到 ctest 运行时执行,而非构建后立即跑
|
||
# exe。因 geopro_data 链 Qt6::Core,构建期发现会因 Qt6Core.dll 尚未拷贝到 exe 旁而
|
||
# 失败(0xc0000135);推迟到运行期时 POST_BUILD 已把运行时 DLL 拷到位。
|
||
if(_proj_data_dirs)
|
||
list(GET _proj_data_dirs 0 GEOPRO_PROJ_DATA)
|
||
gtest_discover_tests(geopro_tests
|
||
DISCOVERY_MODE PRE_TEST
|
||
PROPERTIES ENVIRONMENT "PROJ_DATA=${GEOPRO_PROJ_DATA}")
|
||
else()
|
||
gtest_discover_tests(geopro_tests DISCOVERY_MODE PRE_TEST)
|
||
endif()
|
||
|
||
target_sources(geopro_tests PRIVATE core/test_local_frame.cpp)
|
||
target_sources(geopro_tests PRIVATE core/test_model.cpp)
|
||
target_sources(geopro_tests PRIVATE core/test_color_scale.cpp)
|
||
target_sources(geopro_tests PRIVATE core/test_idw.cpp)
|
||
target_sources(geopro_tests PRIVATE core/test_crs_transform.cpp)
|
||
target_sources(geopro_tests PRIVATE core/test_model_data.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE geopro_core)
|
||
|
||
target_sources(geopro_tests PRIVATE data/test_parsers.cpp)
|
||
target_sources(geopro_tests PRIVATE data/test_local_repo.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE geopro_data)
|
||
|
||
# net 层:RSA 加密器。测试需直接用 OpenSSL 生成/解密密钥,故显式 find_package
|
||
# 并链接 OpenSSL(geopro_net 的 PUBLIC 链接通常已传递,这里显式以防头文件找不到)。
|
||
find_package(OpenSSL REQUIRED)
|
||
target_sources(geopro_tests PRIVATE net/test_rsa.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE geopro_net OpenSSL::SSL OpenSSL::Crypto)
|
||
|
||
# geopro_data 链 Qt6::Core,测试 exe 运行(含 gtest 发现)需要 Qt6Core.dll 等运行时
|
||
# DLL 在旁。复用 app 同样的 TARGET_RUNTIME_DLLS POST_BUILD 拷贝。
|
||
if(WIN32)
|
||
add_custom_command(TARGET geopro_tests POST_BUILD
|
||
COMMAND ${CMAKE_COMMAND} -E copy_if_different
|
||
$<TARGET_RUNTIME_DLLS:geopro_tests> $<TARGET_FILE_DIR:geopro_tests>
|
||
COMMAND_EXPAND_LISTS)
|
||
endif()
|
||
|
||
add_subdirectory(spike) # spike S3: banded contour 渲染验证
|