Files
SimpleRemoter/test/CMakeLists.txt
T
yuanyuanxianganddeepseek-flash d8048979e3 Feature: Report activity history on Linux clients
Implement COMMAND_QUERY_ACTIVITY -> TOKEN_REPORT_ACTIVITY with two backends
picked at startup. With a desktop, a sampler thread reads the foreground
window every second and books dwell time like the Windows client: under
five seconds is dropped, five idle minutes close the window, the last 500
records stay newest first, each line being "[YYYY-MM-DD HH:MM:SS] [title]
duration". It uses its own ActivityChecker because an Xlib connection
cannot be shared with the heartbeat thread, and it is stopped before main's
locals go away.

A reachable X server is not enough: the window backend is only chosen when
the root window carries _NET_SUPPORTING_WM_CHECK, so Xvfb or a bare X
without an EWMH window manager falls back to the headless backend instead
of sampling a window id that never appears.

Without a desktop the answer is computed on demand: logins from
"last -n 100 -F" plus bash/zsh history of root and /home/*, tagged [登录] or
[命令] after a [来源] header. Both halves are merged and sorted by
timestamp; three fifths of the budget goes to logins and reboot records are
capped at ten, since a WSL or container writes one reboot per start.
activity_commands=0 drops the command half.

A single detached thread builds and sends it, only while the main link is up.

The MCP gate now admits Linux for get_activity_history and documents both
shapes. test/unit/linux covers the parsers, ordering and UTF-8 truncation;
15 cases pass.

Co-Authored-By: deepseek-flash
2026-11-08 15:22:09 +01:00

451 lines
11 KiB
CMake
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# SimpleRemoter 测试构建配置
cmake_minimum_required(VERSION 3.14)
project(SimpleRemoterTests)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# MSVC 编码设置
if(MSVC)
add_compile_options(/utf-8)
endif()
# 选项:是否构建测试
option(BUILD_TESTING "Build tests" ON)
if(NOT BUILD_TESTING)
return()
endif()
# 使用 FetchContent 获取 Google Test
include(FetchContent)
FetchContent_Declare(
googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
)
# Windows 下避免覆盖 /MT /MD 设置
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
enable_testing()
# 包含项目头文件目录
include_directories(${CMAKE_SOURCE_DIR}/..)
include_directories(${CMAKE_SOURCE_DIR}/../client)
include_directories(${CMAKE_SOURCE_DIR}/../server/2015Remote)
include_directories(${CMAKE_SOURCE_DIR}/../common)
# ============================================
# 客户端 Buffer 测试
# ============================================
add_executable(client_buffer_test
unit/client/BufferTest.cpp
)
# 测试文件内联包含了 Buffer 实现的测试版本
# 无需链接原始源文件,支持跨平台测试
target_link_libraries(client_buffer_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(client_buffer_test PRIVATE _WIN32)
endif()
# ============================================
# 服务端 Buffer 测试
# ============================================
add_executable(server_buffer_test
unit/server/BufferTest.cpp
)
# 测试文件内联包含了 Buffer 实现的测试版本
# 支持跨平台测试
target_link_libraries(server_buffer_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(server_buffer_test PRIVATE _WIN32)
endif()
# Linux 需要 pthread
if(UNIX)
find_package(Threads REQUIRED)
target_link_libraries(client_buffer_test Threads::Threads)
target_link_libraries(server_buffer_test Threads::Threads)
endif()
# ============================================
# 协议测试 (Phase 1)
# ============================================
add_executable(protocol_test
unit/protocol/PacketTest.cpp
unit/protocol/PathUtilsTest.cpp
)
target_link_libraries(protocol_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(protocol_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(protocol_test Threads::Threads)
endif()
# ============================================
# 文件传输测试 (Phase 2)
# ============================================
add_executable(file_transfer_test
unit/file/FileTransferV2Test.cpp
)
target_link_libraries(file_transfer_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(file_transfer_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(file_transfer_test Threads::Threads)
endif()
# ============================================
# 分块管理测试 (Phase 2)
# ============================================
add_executable(chunk_manager_test
unit/file/ChunkManagerTest.cpp
)
target_link_libraries(chunk_manager_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(chunk_manager_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(chunk_manager_test Threads::Threads)
endif()
# ============================================
# SHA-256 校验测试 (Phase 2)
# ============================================
add_executable(sha256_verify_test
unit/file/SHA256VerifyTest.cpp
)
target_link_libraries(sha256_verify_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(sha256_verify_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(sha256_verify_test Threads::Threads)
endif()
# ============================================
# 断点续传状态测试 (Phase 2)
# ============================================
add_executable(resume_state_test
unit/file/ResumeStateTest.cpp
)
target_link_libraries(resume_state_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(resume_state_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(resume_state_test Threads::Threads)
endif()
# ============================================
# 协议头验证测试 (Phase 3)
# ============================================
add_executable(header_test
unit/network/HeaderTest.cpp
)
target_link_libraries(header_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(header_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(header_test Threads::Threads)
endif()
# ============================================
# 粘包/分包测试 (Phase 3)
# ============================================
add_executable(packet_fragment_test
unit/network/PacketFragmentTest.cpp
)
target_link_libraries(packet_fragment_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(packet_fragment_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(packet_fragment_test Threads::Threads)
endif()
# ============================================
# HTTP 伪装测试 (Phase 3)
# ============================================
add_executable(http_mask_test
unit/network/HttpMaskTest.cpp
)
target_link_libraries(http_mask_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(http_mask_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(http_mask_test Threads::Threads)
endif()
# ============================================
# 差分算法测试 (Phase 4)
# ============================================
add_executable(diff_algorithm_test
unit/screen/DiffAlgorithmTest.cpp
)
target_link_libraries(diff_algorithm_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(diff_algorithm_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(diff_algorithm_test Threads::Threads)
endif()
# ============================================
# RGB565 压缩测试 (Phase 4)
# ============================================
add_executable(rgb565_test
unit/screen/RGB565Test.cpp
)
target_link_libraries(rgb565_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(rgb565_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(rgb565_test Threads::Threads)
endif()
# ============================================
# 滚动检测测试 (Phase 4)
# ============================================
add_executable(scroll_detector_test
unit/screen/ScrollDetectorTest.cpp
)
target_link_libraries(scroll_detector_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(scroll_detector_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(scroll_detector_test Threads::Threads)
endif()
# ============================================
# 质量自适应测试 (Phase 4)
# ============================================
add_executable(quality_adaptive_test
unit/screen/QualityAdaptiveTest.cpp
)
target_link_libraries(quality_adaptive_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(quality_adaptive_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(quality_adaptive_test Threads::Threads)
endif()
# ============================================
# 吞吐判据测试(自适应质量的双判据)
# 直接 include 真实 commands.h,不复制实现,所以需要把 common/ 加进头文件搜索路径
# ============================================
add_executable(quality_load_test
unit/screen/QualityLoadTest.cpp
)
target_include_directories(quality_load_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../common
${CMAKE_CURRENT_SOURCE_DIR}/..
)
target_link_libraries(quality_load_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(quality_load_test PRIVATE _WIN32)
endif()
if(MSVC)
# CMake 默认给所有目标加 /D_WINDOWS,commands.h 见到它就 include <afxwin.h>;
# 测试用 /MD 又没定义 _AFXDLL,于是直接编译失败(这个目标因此一直没在 Windows
# 上跑起来)。判据本身不需要 MFC,去掉它不是二选一:commands.h 会退回 windows.h。
# 只对 MSVC 生效:MinGW/GCC 不认 /U_WINDOWS。
target_compile_options(quality_load_test PRIVATE /U_WINDOWS)
endif()
if(UNIX)
target_link_libraries(quality_load_test Threads::Threads)
endif()
# ============================================
# Linux 历史活动(无头后端)解析测试
# 直接 include 真实的 linux/LinuxActivityHistory.h,不复制实现;窗口后端要 X11,不在这里测
# ============================================
add_executable(linux_activity_test
unit/linux/ActivityHistoryTest.cpp
)
target_include_directories(linux_activity_test PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../linux
)
target_link_libraries(linux_activity_test
GTest::gtest_main
)
if(UNIX)
target_link_libraries(linux_activity_test Threads::Threads)
endif()
# ============================================
# 时间验证测试 (授权模块)
# ============================================
add_executable(date_verify_test
unit/auth/DateVerifyTest.cpp
)
target_link_libraries(date_verify_test
GTest::gtest_main
)
if(WIN32)
target_compile_definitions(date_verify_test PRIVATE _WIN32)
endif()
if(UNIX)
target_link_libraries(date_verify_test Threads::Threads)
endif()
# ============================================
# IP地理位置测试 (网络API)
# ============================================
if(WIN32)
add_executable(geolocation_test
unit/network/GeoLocationTest.cpp
)
target_link_libraries(geolocation_test
GTest::gtest_main
wininet
ws2_32
)
target_compile_definitions(geolocation_test PRIVATE _WIN32)
endif()
# ============================================
# 注册表配置测试 (iniFile/binFile)
# ============================================
if(WIN32)
add_executable(registry_config_test
unit/config/RegistryConfigTest.cpp
)
target_link_libraries(registry_config_test
GTest::gtest_main
advapi32
)
target_compile_definitions(registry_config_test PRIVATE _WIN32)
endif()
# 注册测试
include(GoogleTest)
if(WIN32)
gtest_discover_tests(geolocation_test)
gtest_discover_tests(registry_config_test)
endif()
gtest_discover_tests(client_buffer_test)
gtest_discover_tests(server_buffer_test)
gtest_discover_tests(protocol_test)
gtest_discover_tests(file_transfer_test)
gtest_discover_tests(chunk_manager_test)
gtest_discover_tests(sha256_verify_test)
gtest_discover_tests(resume_state_test)
gtest_discover_tests(header_test)
gtest_discover_tests(packet_fragment_test)
gtest_discover_tests(http_mask_test)
gtest_discover_tests(diff_algorithm_test)
gtest_discover_tests(rgb565_test)
gtest_discover_tests(scroll_detector_test)
gtest_discover_tests(quality_adaptive_test)
gtest_discover_tests(quality_load_test)
gtest_discover_tests(linux_activity_test)
gtest_discover_tests(date_verify_test)
# 自定义目标:运行所有测试
add_custom_target(run_tests
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
DEPENDS client_buffer_test server_buffer_test protocol_test
file_transfer_test chunk_manager_test sha256_verify_test resume_state_test
header_test packet_fragment_test http_mask_test
diff_algorithm_test rgb565_test scroll_detector_test quality_adaptive_test
quality_load_test linux_activity_test date_verify_test
)