Files
sambu 3e10ee8488 test(S6): 补齐 app 层与 HTTP 第二组集成测试,行覆盖率 72.2%→80.3%(NFR-05 达标)
新增
- tests/integration/test_menu.c:菜单 14 项全分派、命令全集正/负例、参数解析、脚本化 stdin 主循环
- tests/integration/test_http_api.c:其余 11 个接口 + 错误路径(400/404/协议层 400)
- src/app/app_options.c:app_parse_args/app_print_usage 从 main.c 迁入静态库(app.h 声明此前无实现)
- app_clear_stop():复用主循环时清除退出标志
- tools/coverage.sh:A10 覆盖率门限自动判定;acceptance 扩到 A1~A10 共 25 项

修复(本轮集成测试暴露)
- menu_render 漏渲染首项「设备列表」(行号 0 既当标题又当表项 0)
- http_server_stop 只置标志不关套接字,导致同进程无法二次启动(聚合运行 70 项失败)
- POST /api/config 未匹配到字段时假成功(现返回 400)
- CRC/I2C 字节序、采样路数、离线设备负例等此前已在集成阶段修复

实测:CTest 19/19;聚合运行 19 套件 2450 断言 0 失败;ASan 19/19;覆盖率 80.3%
2026-09-14 22:23:17 +08:00

51 lines
2.1 KiB
C
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.
/**
* @file menu.h
* @brief 控制台菜单:渲染、选择与命令分发
*
* 教材对应:项目一(输出格式)·项目三 任务五「switch 分支——主菜单功能选择与跳转」·
* 项目四(输入校验循环)·项目七(函数指针表)
*/
#ifndef SHS_MENU_H
#define SHS_MENU_H
#include "shs/common.h"
#include "shs/errors.h"
#include "shs/system.h"
/** 菜单项:编号 + 标题 + 处理函数(项目七 函数指针) */
typedef struct {
int id; /**< 菜单编号 */
const char *label; /**< 菜单标题 */
shs_err_t (*action)(SmartHomeSystem *sys); /**< 处理函数;项目十的集成入口 */
const char *chapter; /**< 对应教材项目(知识点溯源) */
} MenuItem;
/** 主菜单项数量 */
int menu_item_count(void);
/** 取第 index 个菜单项(越界返回 NULL) */
const MenuItem *menu_item_at(int index);
/** 渲染主菜单文本 */
shs_err_t menu_render(const SmartHomeSystem *sys, char *buf, size_t buf_size);
/* * 按编号分发(switch 演示),返回处理函数的执行结果;编号越界返回 SHS_ERR_RANGE */
shs_err_t menu_dispatch(SmartHomeSystem *sys, int choice);
/** 读取一行用户选择并转成整数(项目四 do-while + 输入校验) */
int menu_read_choice(const char *prompt);
/* 各菜单项处理函数(供菜单表与测试直接调用) */
shs_err_t menu_action_list_devices(SmartHomeSystem *sys);
shs_err_t menu_action_toggle_device(SmartHomeSystem *sys);
shs_err_t menu_action_dim_light(SmartHomeSystem *sys);
shs_err_t menu_action_lock(SmartHomeSystem *sys);
shs_err_t menu_action_sensors(SmartHomeSystem *sys);
shs_err_t menu_action_ac_mode(SmartHomeSystem *sys);
shs_err_t menu_action_scene(SmartHomeSystem *sys);
shs_err_t menu_action_schedule(SmartHomeSystem *sys);
shs_err_t menu_action_report(SmartHomeSystem *sys);
shs_err_t menu_action_logs(SmartHomeSystem *sys);
shs_err_t menu_action_protocol(SmartHomeSystem *sys);
shs_err_t menu_action_save_load(SmartHomeSystem *sys);
shs_err_t menu_action_self_test(SmartHomeSystem *sys);
shs_err_t menu_action_about(SmartHomeSystem *sys);
#endif /* SHS_MENU_H */