chore(M0): 建立 CLion/CMake 工程骨架与测试框架

- CMake 多目标工程:shs_core 静态库 + smart_home 可执行 + shs_tests 测试
- CMakePresets.json:debug/release/asan/coverage 四个预设(debug 告警即错误)
- 自研零依赖测试框架 tests/framework/test_framework.h + 运行器(套件过滤、CTest 集成)
- 工具:tools/header_check.sh 头文件独立编译检查(接口冻结门)
- 已实现公共层:errors / string_utils / num_utils,main 启动自检
- 实测:debug 预设 0 告警、ctest 3/3 通过(45 项断言)
This commit is contained in:
sambu committed 2026-09-14 19:34:18 +08:00
commit 578a770737
36 files changed
+2914

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
/**
* @file common.h
* @brief 全局常量、平台宏与通用工具宏
*
* 教材对应:项目一(程序结构)·项目二(数据类型)·项目九(位运算基础宏)
*/
#ifndef SHS_COMMON_H
#define SHS_COMMON_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
/* ---------------------------------------------------------------- 版本信息 */
#define SHS_VERSION_MAJOR 1
#define SHS_VERSION_MINOR 0
#define SHS_VERSION_PATCH 0
#define SHS_VERSION_STRING "1.0.0"
#define SHS_PRODUCT_NAME "智能家居控制系统"
/* ---------------------------------------------------------------- 容量上限 */
#define SHS_NAME_MAX 32 /**< 名称字段长度(含结尾 '\0') */
#define SHS_TAG_MAX 16 /**< 日志标签长度 */
#define SHS_MSG_MAX 96 /**< 日志正文长度 */
#define SHS_LINE_MAX 160 /**< 单行文本缓冲 */
#define SHS_CMD_MAX 64 /**< 指令串长度 */
#define SHS_MAX_DEVICES 32 /**< 设备数量上限(一维数组) */
#define SHS_MAX_ROOMS 8 /**< 房间数量上限 */
#define SHS_MAX_ZONES 16 /**< 区域节点上限(区域树) */
#define SHS_MAX_SAMPLES 16 /**< 采样点数量上限 */
#define SHS_DAYS 7 /**< 定时矩阵:一周 7 天(二维数组第一维) */
#define SHS_HOURS 24 /**< 定时矩阵:一天 24 小时(二维数组第二维) */
#define SHS_LOG_RING_MAX 64 /**< 内存日志环形缓冲条目数 */
#define SHS_JSON_BUF_MAX 8192 /**< JSON 输出缓冲 */
#define SHS_HTTP_BUF_MAX 4096 /**< HTTP 响应体缓冲 */
#define SHS_HTTP_PATH_MAX 128 /**< HTTP 请求路径长度 */
#define SHS_HTTP_BODY_MAX 512 /**< HTTP 请求体长度 */
#define SHS_FRAME_MAX 16 /**< 通信帧最大字节数 */
/* ---------------------------------------------------------------- 通用宏 */
#define SHS_ARRAY_LEN(arr) ((int)(sizeof(arr) / sizeof((arr)[0])))
#define SHS_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define SHS_MAX(a, b) (((a) > (b)) ? (a) : (b))
#define SHS_BIT(n) (1u << (n)) /**< 第 n 位置 1(位运算) */
#define SHS_UNUSED(x) ((void)(x)) /**< 显式忽略未使用参数 */
#define SHS_STRINGIFY(x) #x
#define SHS_CONCAT(a, b) a##b
#define SHS_IS_POWER_OF_TWO(x) (((x) > 0) && (((x) & ((x) - 1)) == 0)) /**< 位运算技巧 */
#define SHS_CLAMP(v, lo, hi) (((v) < (lo)) ? (lo) : (((v) > (hi)) ? (hi) : (v)))
#ifdef _WIN32
# define SHS_PATH_SEP '\\'
#else
# define SHS_PATH_SEP '/'
#endif
#endif /* SHS_COMMON_H */