暂存文件
This commit is contained in:
180
BUILD_GUIDE.md
Normal file
180
BUILD_GUIDE.md
Normal file
@@ -0,0 +1,180 @@
|
||||
# DisplayFlow 构建指南
|
||||
|
||||
## 前置要求
|
||||
|
||||
### 通用要求
|
||||
- CMake 3.15 或更高版本
|
||||
- C++17 兼容的编译器
|
||||
- Git(用于下载依赖)
|
||||
|
||||
### Windows
|
||||
- Visual Studio 2019 或更高版本
|
||||
- Windows SDK 10.0.19041.0 或更高版本
|
||||
|
||||
### Android
|
||||
- Android NDK r21 或更高版本
|
||||
- Android Studio(可选,用于开发)
|
||||
|
||||
### Linux/macOS
|
||||
- GCC 7+ 或 Clang 8+
|
||||
- pkg-config(如果启用 VP8 编解码器)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### Windows
|
||||
|
||||
```batch
|
||||
# 使用构建脚本
|
||||
scripts\build.bat Release
|
||||
|
||||
# 或手动构建
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -G "Visual Studio 16 2019" -A x64
|
||||
cmake --build . --config Release
|
||||
```
|
||||
|
||||
### Linux/macOS
|
||||
|
||||
```bash
|
||||
# 使用构建脚本
|
||||
chmod +x scripts/build.sh
|
||||
./scripts/build.sh Release
|
||||
|
||||
# 或手动构建
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build . -j$(nproc)
|
||||
```
|
||||
|
||||
### Android
|
||||
|
||||
```bash
|
||||
# 设置 Android NDK 路径
|
||||
export ANDROID_NDK=/path/to/android-ndk
|
||||
|
||||
# 创建构建目录
|
||||
mkdir build-android
|
||||
cd build-android
|
||||
|
||||
# 配置 CMake
|
||||
cmake .. \
|
||||
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
|
||||
-DANDROID_ABI=arm64-v8a \
|
||||
-DANDROID_PLATFORM=android-21 \
|
||||
-DCMAKE_BUILD_TYPE=Release
|
||||
|
||||
# 编译
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
## 构建选项
|
||||
|
||||
### 主要选项
|
||||
|
||||
- `BUILD_TESTS`: 构建测试(默认: OFF)
|
||||
```bash
|
||||
cmake .. -DBUILD_TESTS=ON
|
||||
```
|
||||
|
||||
- `BUILD_SHARED_LIBS`: 构建共享库(默认: OFF)
|
||||
```bash
|
||||
cmake .. -DBUILD_SHARED_LIBS=ON
|
||||
```
|
||||
|
||||
- `ENABLE_VP8_CODEC`: 启用 VP8 编解码器支持(默认: OFF)
|
||||
```bash
|
||||
cmake .. -DENABLE_VP8_CODEC=ON
|
||||
```
|
||||
|
||||
- `USE_SYSTEM_FLATBUFFERS`: 使用系统安装的 FlatBuffers(默认: OFF)
|
||||
```bash
|
||||
cmake .. -DUSE_SYSTEM_FLATBUFFERS=ON
|
||||
```
|
||||
|
||||
### 依赖管理
|
||||
|
||||
项目使用 CMake FetchContent 自动下载依赖。主要依赖包括:
|
||||
|
||||
- **FlatBuffers**: 自动下载(或使用系统版本)
|
||||
- **Google Test**: 仅在 `BUILD_TESTS=ON` 时下载
|
||||
- **libvpx**: 仅在 `ENABLE_VP8_CODEC=ON` 时查找
|
||||
|
||||
### 使用 vcpkg(可选)
|
||||
|
||||
如果使用 vcpkg 管理依赖:
|
||||
|
||||
```bash
|
||||
# 安装 vcpkg
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
./bootstrap-vcpkg.sh # Linux/macOS
|
||||
# 或
|
||||
.\bootstrap-vcpkg.bat # Windows
|
||||
|
||||
# 安装依赖
|
||||
./vcpkg install flatbuffers
|
||||
|
||||
# 配置 CMake 使用 vcpkg
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=[vcpkg root]/scripts/buildsystems/vcpkg.cmake
|
||||
```
|
||||
|
||||
## 运行测试
|
||||
|
||||
```bash
|
||||
# 在构建目录中
|
||||
ctest
|
||||
|
||||
# 或运行特定测试
|
||||
ctest -R test_network_interface
|
||||
|
||||
# 详细输出
|
||||
ctest --verbose
|
||||
```
|
||||
|
||||
## 输出目录
|
||||
|
||||
构建输出位于:
|
||||
- 可执行文件: `build/bin/`
|
||||
- 库文件: `build/lib/`
|
||||
- 测试: `build/tests/`
|
||||
|
||||
## 常见问题
|
||||
|
||||
### CMake 找不到编译器
|
||||
|
||||
**Windows**: 确保 Visual Studio 已安装,并在 Visual Studio 开发者命令提示符中运行。
|
||||
|
||||
**Linux**: 安装构建工具:
|
||||
```bash
|
||||
sudo apt-get install build-essential # Ubuntu/Debian
|
||||
```
|
||||
|
||||
### Android 构建失败
|
||||
|
||||
确保设置了正确的 Android NDK 路径:
|
||||
```bash
|
||||
export ANDROID_NDK=/path/to/android-ndk
|
||||
```
|
||||
|
||||
### 依赖下载失败
|
||||
|
||||
检查网络连接,或使用代理:
|
||||
```bash
|
||||
export https_proxy=http://proxy.example.com:8080
|
||||
```
|
||||
|
||||
## 开发模式
|
||||
|
||||
对于开发,建议使用 Debug 模式:
|
||||
|
||||
```bash
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
这会启用调试符号和测试支持。
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +1,49 @@
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
project(DisplayFlow VERSION 1.0.0 LANGUAGES CXX)
|
||||
|
||||
# 设置 C++ 标准
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
# ============================================================================
|
||||
# 项目配置
|
||||
# ============================================================================
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # 生成 compile_commands.json(用于 IDE)
|
||||
|
||||
# 输出目录
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
# ============================================================================
|
||||
# 包含 CMake 模块
|
||||
# ============================================================================
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
# 编译选项
|
||||
if(MSVC)
|
||||
add_compile_options(/W4 /WX-)
|
||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||
else()
|
||||
add_compile_options(-Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
# 编译器选项
|
||||
include(CompilerOptions)
|
||||
|
||||
# 平台检测
|
||||
if(ANDROID)
|
||||
set(PLATFORM_ANDROID ON)
|
||||
include(Android)
|
||||
elseif(WIN32)
|
||||
set(PLATFORM_WINDOWS ON)
|
||||
include(Windows)
|
||||
elseif(APPLE)
|
||||
set(PLATFORM_MACOS ON)
|
||||
elseif(UNIX)
|
||||
set(PLATFORM_LINUX ON)
|
||||
endif()
|
||||
|
||||
# ============================================================================
|
||||
# 构建选项
|
||||
# ============================================================================
|
||||
option(BUILD_TESTS "Build tests" OFF)
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
|
||||
option(ENABLE_VP8_CODEC "Enable VP8 codec support" OFF)
|
||||
|
||||
# ============================================================================
|
||||
# 依赖管理
|
||||
# ============================================================================
|
||||
include(Dependencies)
|
||||
|
||||
# ============================================================================
|
||||
# 测试框架
|
||||
# ============================================================================
|
||||
include(Testing)
|
||||
|
||||
# 添加子目录
|
||||
add_subdirectory(core)
|
||||
|
||||
@@ -40,10 +54,5 @@ elseif(PLATFORM_WINDOWS)
|
||||
add_subdirectory(platforms/windows)
|
||||
endif()
|
||||
|
||||
# 添加测试(如果启用)
|
||||
option(BUILD_TESTS "Build tests" OFF)
|
||||
if(BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
# 测试已在 Testing.cmake 中配置
|
||||
|
||||
|
||||
@@ -1,81 +1,39 @@
|
||||
# DisplayFlow 构建指南
|
||||
|
||||
## 前置要求
|
||||
> **注意**: 详细的构建指南请参考 [BUILD_GUIDE.md](BUILD_GUIDE.md)
|
||||
|
||||
## 快速开始
|
||||
|
||||
### Windows
|
||||
- CMake 3.15 或更高版本
|
||||
- Visual Studio 2019 或更高版本(包含 Windows SDK 10.0.19041.0+)
|
||||
- Git
|
||||
|
||||
### Android
|
||||
- CMake 3.15 或更高版本
|
||||
- Android NDK r21 或更高版本
|
||||
- Android Studio(可选,用于开发)
|
||||
```batch
|
||||
scripts\build.bat Release
|
||||
```
|
||||
|
||||
## 构建步骤
|
||||
|
||||
### Windows
|
||||
### Linux/macOS
|
||||
|
||||
```bash
|
||||
# 创建构建目录
|
||||
mkdir build
|
||||
cd build
|
||||
|
||||
# 配置 CMake
|
||||
cmake .. -G "Visual Studio 16 2019" -A x64
|
||||
|
||||
# 编译
|
||||
cmake --build . --config Release
|
||||
chmod +x scripts/build.sh
|
||||
./scripts/build.sh Release
|
||||
```
|
||||
|
||||
### Android
|
||||
|
||||
```bash
|
||||
# 创建构建目录
|
||||
mkdir build-android
|
||||
cd build-android
|
||||
|
||||
# 配置 CMake(需要设置 ANDROID_NDK 环境变量)
|
||||
export ANDROID_NDK=/path/to/android-ndk
|
||||
mkdir build-android && cd build-android
|
||||
cmake .. \
|
||||
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
|
||||
-DANDROID_ABI=arm64-v8a \
|
||||
-DANDROID_PLATFORM=android-21
|
||||
|
||||
# 编译
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
## 依赖管理
|
||||
## 主要构建选项
|
||||
|
||||
项目依赖将通过以下方式管理:
|
||||
- `BUILD_TESTS=ON`: 启用测试
|
||||
- `ENABLE_VP8_CODEC=ON`: 启用 VP8 编解码器
|
||||
- `USE_SYSTEM_FLATBUFFERS=ON`: 使用系统 FlatBuffers
|
||||
|
||||
1. **FlatBuffers**:通过 Git Submodule 或 vcpkg 引入
|
||||
2. **编解码库**:使用平台原生 API(MediaCodec、Media Foundation)
|
||||
|
||||
## 开发环境设置
|
||||
|
||||
### 使用 vcpkg(推荐)
|
||||
|
||||
```bash
|
||||
# 安装 vcpkg
|
||||
git clone https://github.com/Microsoft/vcpkg.git
|
||||
cd vcpkg
|
||||
.\bootstrap-vcpkg.bat
|
||||
|
||||
# 安装依赖
|
||||
.\vcpkg install flatbuffers
|
||||
|
||||
# 配置 CMake 使用 vcpkg
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=[vcpkg root]/scripts/buildsystems/vcpkg.cmake
|
||||
```
|
||||
|
||||
## 测试
|
||||
|
||||
```bash
|
||||
# 启用测试
|
||||
cmake .. -DBUILD_TESTS=ON
|
||||
|
||||
# 运行测试
|
||||
ctest
|
||||
```
|
||||
详细说明请参考 [BUILD_GUIDE.md](BUILD_GUIDE.md)
|
||||
|
||||
|
||||
@@ -64,14 +64,31 @@ add_library(displayflow_core STATIC
|
||||
|
||||
# 包含目录
|
||||
target_include_directories(displayflow_core PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../third_party/flatbuffers/include
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
)
|
||||
|
||||
# 链接库(根据实际依赖调整)
|
||||
# target_link_libraries(displayflow_core
|
||||
# flatbuffers
|
||||
# )
|
||||
# 链接 FlatBuffers
|
||||
target_link_libraries(displayflow_core
|
||||
PUBLIC
|
||||
flatbuffers::flatbuffers
|
||||
)
|
||||
|
||||
# 链接 VP8 编解码器(如果启用)
|
||||
if(ENABLE_VP8_CODEC AND LIBVPX_FOUND)
|
||||
target_link_libraries(displayflow_core
|
||||
PUBLIC
|
||||
${LIBVPX_LIBRARIES}
|
||||
)
|
||||
target_include_directories(displayflow_core
|
||||
PUBLIC
|
||||
${LIBVPX_INCLUDE_DIRS}
|
||||
)
|
||||
target_compile_definitions(displayflow_core
|
||||
PUBLIC
|
||||
DISPLAYFLOW_ENABLE_VP8
|
||||
)
|
||||
endif()
|
||||
|
||||
# 编译定义
|
||||
target_compile_definitions(displayflow_core PUBLIC
|
||||
|
||||
143
docs/BUILD_SYSTEM.md
Normal file
143
docs/BUILD_SYSTEM.md
Normal file
@@ -0,0 +1,143 @@
|
||||
# DisplayFlow 构建系统说明
|
||||
|
||||
本文档详细说明 DisplayFlow 的构建系统配置。
|
||||
|
||||
## 1. 构建系统架构
|
||||
|
||||
DisplayFlow 使用 CMake 作为统一构建系统,采用模块化配置:
|
||||
|
||||
```
|
||||
cmake/
|
||||
├── Dependencies.cmake # 依赖管理
|
||||
├── CompilerOptions.cmake # 编译器选项
|
||||
├── Android.cmake # Android 平台配置
|
||||
├── Windows.cmake # Windows 平台配置
|
||||
└── Testing.cmake # 测试框架配置
|
||||
```
|
||||
|
||||
## 2. 依赖管理
|
||||
|
||||
### 2.1 自动依赖下载
|
||||
|
||||
项目使用 CMake `FetchContent` 自动下载依赖:
|
||||
|
||||
- **FlatBuffers**: 自动从 GitHub 下载
|
||||
- **Google Test**: 仅在 `BUILD_TESTS=ON` 时下载
|
||||
|
||||
### 2.2 系统依赖
|
||||
|
||||
可选使用系统已安装的依赖:
|
||||
|
||||
```bash
|
||||
cmake .. -DUSE_SYSTEM_FLATBUFFERS=ON
|
||||
```
|
||||
|
||||
### 2.3 vcpkg 支持
|
||||
|
||||
支持使用 vcpkg 管理依赖:
|
||||
|
||||
```bash
|
||||
cmake .. -DCMAKE_TOOLCHAIN_FILE=[vcpkg]/scripts/buildsystems/vcpkg.cmake
|
||||
```
|
||||
|
||||
## 3. 平台配置
|
||||
|
||||
### 3.1 Windows
|
||||
|
||||
- 自动检测 Visual Studio 版本
|
||||
- 配置 Windows SDK
|
||||
- 设置 Unicode 字符集
|
||||
- 链接 DirectX 库
|
||||
|
||||
### 3.2 Android
|
||||
|
||||
- 配置 Android NDK
|
||||
- 设置 Android API 级别
|
||||
- 配置 ABI(arm64-v8a, armeabi-v7a, x86, x86_64)
|
||||
- 链接 Android 系统库
|
||||
|
||||
## 4. 编译选项
|
||||
|
||||
### 4.1 C++ 标准
|
||||
|
||||
- 使用 C++17 标准
|
||||
- 要求严格符合标准(`CMAKE_CXX_EXTENSIONS OFF`)
|
||||
|
||||
### 4.2 警告级别
|
||||
|
||||
- **MSVC**: `/W4`(警告级别 4)
|
||||
- **GCC/Clang**: `-Wall -Wextra -Wpedantic`
|
||||
|
||||
### 4.3 优化选项
|
||||
|
||||
- **Debug**: 禁用优化,生成调试信息
|
||||
- **Release**: 最高优化级别
|
||||
|
||||
## 5. 测试框架
|
||||
|
||||
### 5.1 Google Test
|
||||
|
||||
使用 Google Test 作为单元测试框架:
|
||||
|
||||
```cpp
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(MyTest, TestCase) {
|
||||
EXPECT_EQ(1 + 1, 2);
|
||||
}
|
||||
```
|
||||
|
||||
### 5.2 运行测试
|
||||
|
||||
```bash
|
||||
# 构建测试
|
||||
cmake .. -DBUILD_TESTS=ON
|
||||
cmake --build .
|
||||
|
||||
# 运行测试
|
||||
ctest
|
||||
```
|
||||
|
||||
## 6. 构建脚本
|
||||
|
||||
项目提供了便捷的构建脚本:
|
||||
|
||||
- `scripts/build.sh` (Linux/macOS)
|
||||
- `scripts/build.bat` (Windows)
|
||||
- `scripts/setup_dependencies.sh` (Linux/macOS)
|
||||
- `scripts/setup_dependencies.bat` (Windows)
|
||||
|
||||
## 7. 输出目录结构
|
||||
|
||||
```
|
||||
build/
|
||||
├── bin/ # 可执行文件
|
||||
├── lib/ # 库文件
|
||||
└── tests/ # 测试输出
|
||||
```
|
||||
|
||||
## 8. 常见配置
|
||||
|
||||
### 开发模式
|
||||
|
||||
```bash
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
|
||||
```
|
||||
|
||||
### 发布模式
|
||||
|
||||
```bash
|
||||
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||
```
|
||||
|
||||
### 启用所有功能
|
||||
|
||||
```bash
|
||||
cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DBUILD_TESTS=ON \
|
||||
-DENABLE_VP8_CODEC=ON
|
||||
```
|
||||
|
||||
|
||||
|
||||
28
scripts/build.bat
Normal file
28
scripts/build.bat
Normal file
@@ -0,0 +1,28 @@
|
||||
@echo off
|
||||
REM 构建脚本(Windows)
|
||||
|
||||
set BUILD_TYPE=%1
|
||||
if "%BUILD_TYPE%"=="" set BUILD_TYPE=Release
|
||||
|
||||
set BUILD_DIR=build-%BUILD_TYPE%
|
||||
|
||||
echo Building DisplayFlow in %BUILD_TYPE% mode...
|
||||
|
||||
REM 创建构建目录
|
||||
if not exist "%BUILD_DIR%" mkdir "%BUILD_DIR%"
|
||||
cd "%BUILD_DIR%"
|
||||
|
||||
REM 配置 CMake
|
||||
cmake .. ^
|
||||
-G "Visual Studio 16 2019" -A x64 ^
|
||||
-DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
|
||||
-DBUILD_TESTS=ON ^
|
||||
-DENABLE_VP8_CODEC=OFF
|
||||
|
||||
REM 编译
|
||||
cmake --build . --config %BUILD_TYPE% --parallel
|
||||
|
||||
echo Build complete! Output in %BUILD_DIR%\
|
||||
|
||||
|
||||
|
||||
27
scripts/build.sh
Normal file
27
scripts/build.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
#!/bin/bash
|
||||
# 构建脚本(Linux/macOS)
|
||||
|
||||
set -e
|
||||
|
||||
BUILD_TYPE=${1:-Release}
|
||||
BUILD_DIR="build-${BUILD_TYPE,,}"
|
||||
|
||||
echo "Building DisplayFlow in $BUILD_TYPE mode..."
|
||||
|
||||
# 创建构建目录
|
||||
mkdir -p "$BUILD_DIR"
|
||||
cd "$BUILD_DIR"
|
||||
|
||||
# 配置 CMake
|
||||
cmake .. \
|
||||
-DCMAKE_BUILD_TYPE="$BUILD_TYPE" \
|
||||
-DBUILD_TESTS=ON \
|
||||
-DENABLE_VP8_CODEC=OFF
|
||||
|
||||
# 编译
|
||||
cmake --build . --config "$BUILD_TYPE" -j$(nproc)
|
||||
|
||||
echo "Build complete! Output in $BUILD_DIR/"
|
||||
|
||||
|
||||
|
||||
27
scripts/setup_dependencies.bat
Normal file
27
scripts/setup_dependencies.bat
Normal file
@@ -0,0 +1,27 @@
|
||||
@echo off
|
||||
REM 依赖安装脚本(Windows)
|
||||
|
||||
echo Setting up DisplayFlow dependencies...
|
||||
|
||||
REM 检查 CMake 版本
|
||||
cmake --version
|
||||
if errorlevel 1 (
|
||||
echo Error: CMake is not installed or not in PATH
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
REM 检查是否使用 vcpkg
|
||||
if exist "vcpkg" (
|
||||
echo Using vcpkg for dependency management
|
||||
call vcpkg\bootstrap-vcpkg.bat
|
||||
vcpkg\vcpkg.exe install flatbuffers:x64-windows
|
||||
echo Dependencies installed via vcpkg
|
||||
) else (
|
||||
echo Dependencies will be fetched via CMake FetchContent
|
||||
echo No manual installation required
|
||||
)
|
||||
|
||||
echo Dependency setup complete!
|
||||
|
||||
|
||||
|
||||
26
scripts/setup_dependencies.sh
Normal file
26
scripts/setup_dependencies.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/bin/bash
|
||||
# 依赖安装脚本(Linux/macOS)
|
||||
|
||||
set -e
|
||||
|
||||
echo "Setting up DisplayFlow dependencies..."
|
||||
|
||||
# 检查 CMake 版本
|
||||
CMAKE_VERSION=$(cmake --version | head -n1 | cut -d' ' -f3)
|
||||
echo "CMake version: $CMAKE_VERSION"
|
||||
|
||||
# 检查是否使用 vcpkg
|
||||
if [ -d "vcpkg" ]; then
|
||||
echo "Using vcpkg for dependency management"
|
||||
./vcpkg/bootstrap-vcpkg.sh
|
||||
./vcpkg/vcpkg install flatbuffers
|
||||
echo "Dependencies installed via vcpkg"
|
||||
else
|
||||
echo "Dependencies will be fetched via CMake FetchContent"
|
||||
echo "No manual installation required"
|
||||
fi
|
||||
|
||||
echo "Dependency setup complete!"
|
||||
|
||||
|
||||
|
||||
33
tests/CMakeLists.txt
Normal file
33
tests/CMakeLists.txt
Normal file
@@ -0,0 +1,33 @@
|
||||
# 测试目录 CMakeLists.txt
|
||||
|
||||
if(NOT BUILD_TESTS)
|
||||
return()
|
||||
endif()
|
||||
|
||||
message(STATUS "Configuring tests")
|
||||
|
||||
# 测试源文件目录
|
||||
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# 示例测试:网络接口测试
|
||||
add_displayflow_test(
|
||||
test_network_interface
|
||||
${TEST_SOURCE_DIR}/network/test_network_interface.cpp
|
||||
)
|
||||
|
||||
# 示例测试:会话管理测试
|
||||
add_displayflow_test(
|
||||
test_session_manager
|
||||
${TEST_SOURCE_DIR}/session/test_session_manager.cpp
|
||||
)
|
||||
|
||||
# 示例测试:文件传输测试
|
||||
add_displayflow_test(
|
||||
test_file_transfer
|
||||
${TEST_SOURCE_DIR}/file_transfer/test_file_transfer.cpp
|
||||
)
|
||||
|
||||
# 可以添加更多测试...
|
||||
|
||||
|
||||
|
||||
26
tests/file_transfer/test_file_transfer.cpp
Normal file
26
tests/file_transfer/test_file_transfer.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "displayflow/core/file_transfer/file_transfer_manager.h"
|
||||
|
||||
using namespace displayflow::core;
|
||||
|
||||
class FileTransferTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
manager_ = std::make_shared<FileTransferManager>();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
manager_.reset();
|
||||
}
|
||||
|
||||
std::shared_ptr<FileTransferManager> manager_;
|
||||
};
|
||||
|
||||
TEST_F(FileTransferTest, FileTransferManagerCreation) {
|
||||
ASSERT_NE(manager_, nullptr);
|
||||
}
|
||||
|
||||
// 添加更多测试...
|
||||
|
||||
|
||||
|
||||
34
tests/network/test_network_interface.cpp
Normal file
34
tests/network/test_network_interface.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "displayflow/core/network/network_interface.h"
|
||||
|
||||
using namespace displayflow::core;
|
||||
|
||||
class NetworkInterfaceTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
// 测试前准备
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
// 测试后清理
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(NetworkInterfaceTest, NetworkInterfaceCreation) {
|
||||
NetworkInterface interface;
|
||||
interface.type = NetworkType::WiFi;
|
||||
interface.name = "wlan0";
|
||||
interface.address = "192.168.1.100";
|
||||
interface.port = 8888;
|
||||
interface.isAvailable = true;
|
||||
|
||||
EXPECT_EQ(interface.type, NetworkType::WiFi);
|
||||
EXPECT_EQ(interface.name, "wlan0");
|
||||
EXPECT_EQ(interface.address, "192.168.1.100");
|
||||
EXPECT_TRUE(interface.isAvailable);
|
||||
}
|
||||
|
||||
// 添加更多测试...
|
||||
|
||||
|
||||
|
||||
38
tests/session/test_session_manager.cpp
Normal file
38
tests/session/test_session_manager.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "displayflow/core/session/session_manager.h"
|
||||
|
||||
using namespace displayflow::core;
|
||||
|
||||
class SessionManagerTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
manager_ = std::make_shared<SessionManager>();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
manager_.reset();
|
||||
}
|
||||
|
||||
std::shared_ptr<SessionManager> manager_;
|
||||
};
|
||||
|
||||
TEST_F(SessionManagerTest, CreateSession) {
|
||||
auto session = manager_->CreateSession(RoleType::Host);
|
||||
ASSERT_NE(session, nullptr);
|
||||
EXPECT_EQ(session->GetRole(), RoleType::Host);
|
||||
}
|
||||
|
||||
TEST_F(SessionManagerTest, GetSession) {
|
||||
auto session = manager_->CreateSession(RoleType::Client);
|
||||
ASSERT_NE(session, nullptr);
|
||||
|
||||
SessionId id = session->GetId();
|
||||
auto retrieved = manager_->GetSession(id);
|
||||
ASSERT_NE(retrieved, nullptr);
|
||||
EXPECT_EQ(retrieved->GetId(), id);
|
||||
}
|
||||
|
||||
// 添加更多测试...
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user