107 lines
5.9 KiB
CMake
107 lines
5.9 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_sources(geopro_tests PRIVATE core/test_geo_frame.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_sources(geopro_tests PRIVATE data/test_nav_dto.cpp)
|
||
target_sources(geopro_tests PRIVATE data/test_dataset_chart_dto.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE geopro_data)
|
||
|
||
# net 层:RSA 加密器。测试需直接用 OpenSSL 生成/解密密钥,故显式 find_package
|
||
# 并链接 OpenSSL(geopro_net 的 PUBLIC 链接通常已传递,这里显式以防头文件找不到)。
|
||
find_package(OpenSSL REQUIRED)
|
||
find_package(Qt6 COMPONENTS Core Network Test REQUIRED)
|
||
target_sources(geopro_tests PRIVATE net/test_rsa.cpp)
|
||
# 端到端登录连通测试(ApiClient + AuthService),需 Qt6::Core/Network 与事件循环。
|
||
target_sources(geopro_tests PRIVATE net/test_auth.cpp)
|
||
# ApiBatch 离线单测(QSignalSpy 需 Qt6::Test)。
|
||
target_sources(geopro_tests PRIVATE net/test_api_batch.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE geopro_net OpenSSL::SSL OpenSSL::Crypto Qt6::Core Qt6::Network Qt6::Test)
|
||
|
||
# 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()
|
||
|
||
# render 层:ColorLutBuilder(core ColorScale -> vtkLookupTable)。
|
||
# 需 vtkLookupTable(VTK::CommonCore);geopro_render 已 PUBLIC 传递其余 VTK 组件。
|
||
find_package(VTK REQUIRED COMPONENTS CommonCore CommonDataModel RenderingCore)
|
||
target_sources(geopro_tests PRIVATE render/test_color_lut.cpp)
|
||
target_sources(geopro_tests PRIVATE render/test_contour_bands.cpp)
|
||
# dd_voxel:buildVoxel(ScalarVolume->vtkImageData->GPU 体绘制) 构建不崩 + dims 正确。
|
||
target_sources(geopro_tests PRIVATE render/test_voxel_build.cpp)
|
||
# dd_voxel 回归:buildVoxelFromScatters(散点 projX/Y -EPSG:4547-> 世界系 + IDW) 配准+充填(需 PROJ_DATA)。
|
||
target_sources(geopro_tests PRIVATE render/test_voxel_register.cpp)
|
||
# Curtain:buildCurtain(Grid+GeoLocalFrame->vtkStructuredGrid 帘面) 非空 actor + 点数=nx*ny。
|
||
target_sources(geopro_tests PRIVATE render/test_curtain.cpp)
|
||
# Scatter(#17):buildScatter(ScatterField+ColorScale->vtkPolyData 彩色散点) 点数/verts/上色/y取负。
|
||
target_sources(geopro_tests PRIVATE render/test_scatter.cpp)
|
||
# Anomaly:buildAnomalies(markType 点/线/面 -> vtkActor) 几何/闭合/颜色/y取负/空跳过。
|
||
target_sources(geopro_tests PRIVATE render/test_anomaly.cpp)
|
||
# Electrode:buildElectrodes(剖面顶边朝下三角 ▼) 三角数/顶点位置/空安全。
|
||
target_sources(geopro_tests PRIVATE render/test_electrode.cpp)
|
||
# Terrain:buildTerrain(GDAL 读 dem/image + 重投影 → warp 面+纹理) 非空/缺文件安全(需 PROJ_DATA)。
|
||
target_sources(geopro_tests PRIVATE render/test_terrain.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE geopro_render ${VTK_LIBRARIES})
|
||
vtk_module_autoinit(TARGETS geopro_tests MODULES ${VTK_LIBRARIES})
|
||
|
||
# Qwt 集成冒烟(仅当 qwt 目标存在,即 external/qwt-src 已拉取)。
|
||
if(TARGET qwt)
|
||
target_sources(geopro_tests PRIVATE render/test_qwt_smoke.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE qwt)
|
||
endif()
|
||
|
||
target_include_directories(geopro_tests PRIVATE ${CMAKE_SOURCE_DIR}/src/app)
|
||
# tests/ 在 include 路径:net/test_api_batch.cpp 用 #include "net/FakeApiCall.hpp"。
|
||
target_include_directories(geopro_tests PRIVATE ${CMAKE_SOURCE_DIR}/tests)
|
||
target_sources(geopro_tests PRIVATE app/test_chart_strategy_registry.cpp)
|
||
# ColorMapService 测试(geopro_desktop 是可执行文件,直接把源加入测试目标)
|
||
target_sources(geopro_tests PRIVATE
|
||
app/test_colormap_service.cpp
|
||
${CMAKE_SOURCE_DIR}/src/app/panels/chart/ColorMapService.cpp
|
||
)
|
||
|
||
# controller 层:DatasetDetailController 编排集成测试(QSignalSpy 验证 chartReady/loadFailed)。
|
||
find_package(Qt6 COMPONENTS Test REQUIRED)
|
||
target_sources(geopro_tests PRIVATE controller/test_dataset_detail_controller.cpp)
|
||
target_link_libraries(geopro_tests PRIVATE geopro_controller Qt6::Test)
|
||
|
||
add_subdirectory(spike) # spike S3: banded contour 渲染验证
|