Files
7iwind 1c3e48d59f
CI / host (pull_request) Successful in 2s
CI / cortex-m (pull_request) Successful in 5s
feat: 新增接收dispatch反向路由
2026-07-30 10:49:44 +08:00

91 lines
4.0 KiB
Markdown
Raw Permalink 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.
# DataRouter 单元测试用例文档
## 测试环境
| 项目 | 内容 |
|------|------|
| 语言标准 | C11 |
| 编译器 | GCC 11.4.0 |
| 测试框架 | 自定义轻量框架(宏 + goto cleanup) |
| 构建系统 | CMake ≥ 3.10 |
| 发送能力 | `sensor` / `status` |
| 接收能力 | `rtcm` / `command` |
## 运行方式
```bash
cmake -S . -B build
cmake --build build
ctest --test-dir build
./build/test_datarouter
```
## 测试用例列表
### 1. 未初始化(1 个)
| # | 测试名 | 描述 | 步骤 | 预期 |
|---|--------|------|------|------|
| 1 | `error_uninit` | 未 init 时发送 | `dr_send_sensor("d", 1)` | 返回 -1 |
### 2. 端口管理(4 个)
| # | 测试名 | 描述 | 步骤 | 预期 |
|---|--------|------|------|------|
| 2 | `port_create_basic` | 基本创建 | `dr_port_create()` | 返回 ≥ 0 |
| 3 | `port_create_max` | 满容量 64 | 循环到满 | 第 65 个 INVALID |
| 4 | `port_delete_invalid` | 删除无效 ID | `delete(-1)` + `delete(999)` | 不崩溃 |
| 5 | `port_default_state` | 默认状态 | 查 send_type / recv_type / count | 均为 -1 / 0 |
### 3. send_type / recv_type / handler(4 个)
| # | 测试名 | 描述 | 步骤 | 预期 |
|---|--------|------|------|------|
| 6 | `send_type_set_clear` | 设置并清除 send_type | set(sensor) → get → set(-1) → get | sensor → -1 |
| 7 | `recv_type_set_clear` | 设置并清除 recv_type | set(rtcm) → get → set(-1) → get | rtcm → -1 |
| 8 | `types_independent` | 收发类型独立设置 | 同时 set_send(sensor) + set_recv(command) | 各自返回正确值 |
| 9 | `handler_add_remove` | 添加后移除 handler | add(h) → count=1 → remove(h) → count=0 | 正确 |
### 4. 发送 — 自动广播(7 个)
| # | 测试名 | 描述 | 步骤 | 预期 |
|---|--------|------|------|------|
| 10 | `send_no_match_port` | 无匹配端口 | 不创建端口直接 send | 返回 -2 |
| 11 | `send_one_port_one_handler` | 单端口单 handler | send_type + add → send | 0,handler 1 次 |
| 12 | `send_multi_ports` | 两端口同类型 | p1(sensor) + p2(sensor) → send | handler 2 次 |
| 13 | `send_type_filter` | 类型过滤 | p1(sensor) + p2(status) → send_sensor | 只触发 p1 |
| 14 | `send_after_delete` | 删除端口后 send | 创建→设好→删除→send | 返回 -2 |
| 15 | `send_zero_length` | 零长度数据 | send("x", 0) | 0,handler 被调 |
| 16 | `send_null_data` | NULL 数据 | send(NULL, 0) | 0,handler 被调 |
### 5. 接收回调 + dispatch(6 个)
| # | 测试名 | 描述 | 步骤 | 预期 |
|---|--------|------|------|------|
| 17 | `recv_callback_direct` | 直接调用回调 | `dr_on_recv_rtcm()` + `dr_on_recv_command()` | 各自触发 |
| 18 | `dispatch_valid` | dispatch 自动路由 rtcm | set_recv(rtcm) → dispatch(port, data) | dr_on_recv_rtcm 触发 |
| 19 | `dispatch_command` | dispatch 自动路由 command | set_recv(command) → dispatch(port, data) | dr_on_recv_command 触发 |
| 20 | `dispatch_unset` | recv_type 未设置 | recv_type=-1 → dispatch | 无回调触发 |
| 21 | `dispatch_invalid_port` | 无效端口 dispatch | dispatch(999/-1, ...) | 无回调触发 |
| 22 | `dispatch_deleted_port` | 已删端口 dispatch | 创建→设置→删除→dispatch | 无回调触发 |
### 6. 能力元数据(2 个)
| # | 测试名 | 描述 | 步骤 | 预期 |
|---|--------|------|------|------|
| 23 | `send_cap_meta` | 发送能力元数据 | count / name / 边界 | 正确 |
| 24 | `recv_cap_meta` | 接收能力元数据 | count / name / 边界 | 正确 |
## 覆盖矩阵
| 功能模块 | 用例数 | 主要验证点 |
|----------|:------:|------------|
| 未初始化 | 1 | send → -1 |
| 端口管理 | 4 | 创建/满容量/删除/默认状态 |
| 收发类型 & handler | 4 | send_type/recv_type 独立设置、handler 增删 |
| 发送自动广播 | 7 | 单播/多播/过滤/删除后/零长/NULL |
| 接收 dispatch | 6 | 直接回调/有效路由/无效路由/未设置/无效端口/已删除 |
| 能力元数据 | 2 | 两组独立查询 |
**总计:24 个测试用例**