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:
commit
578a770737
36 files changed
+2914
No files matched your search
+79
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @file main.c
|
||||
* @brief 程序入口:智能家居控制系统(项目一 —— 第一个 C 程序 / 程序结构)
|
||||
*
|
||||
* 教材对应:项目一 任务三「第一个 C 程序」;后续里程碑将在此接入
|
||||
* CLI 交互模式(--cli)与网页模式(--web)。
|
||||
*/
|
||||
#include "shs/common.h"
|
||||
#include "shs/errors.h"
|
||||
#include "shs/string_utils.h"
|
||||
#include "shs/num_utils.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static void shs_print_banner(void)
|
||||
{
|
||||
printf("==========================================================\n");
|
||||
printf(" %s (Smart Home Control System) v%s\n", SHS_PRODUCT_NAME, SHS_VERSION_STRING);
|
||||
printf(" 《C语言程序设计项目化教程——智能家居控制系统开发实战》配套工程\n");
|
||||
printf("==========================================================\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 启动自检:检查已实现的公共模块是否工作正常
|
||||
* @return 通过的检查项数量
|
||||
*/
|
||||
static int shs_bootstrap_self_check(void)
|
||||
{
|
||||
int passed = 0;
|
||||
|
||||
/* 项目五:字符数组与字符串 */
|
||||
char name[SHS_NAME_MAX];
|
||||
if (shs_strcpy(name, sizeof(name), "客厅主灯") == SHS_OK && shs_strlen(name) > 0) {
|
||||
printf("[自检] 字符串模块 : 通过(设备名 \"%s\")\n", name);
|
||||
passed++;
|
||||
}
|
||||
|
||||
/* 项目二:运算符与类型转换 */
|
||||
char hex[SHS_FRAME_MAX * 2 + 1];
|
||||
const uint8_t sample[4] = { 0x5A, 0x01, 0x02, 0x32 };
|
||||
if (shs_bytes_to_hex(sample, sizeof(sample), hex, sizeof(hex)) == SHS_OK) {
|
||||
printf("[自检] 进制转换模块 : 通过(帧样本 %s)\n", hex);
|
||||
passed++;
|
||||
}
|
||||
|
||||
/* 项目六:递归调用 */
|
||||
if (shs_factorial(5) == 120L && shs_gcd(48, 18) == 6) {
|
||||
printf("[自检] 递归函数模块 : 通过(5! = %ld,gcd(48,18) = %d)\n",
|
||||
shs_factorial(5), shs_gcd(48, 18));
|
||||
passed++;
|
||||
}
|
||||
|
||||
/* 项目三:分支判断错误码 */
|
||||
int value = 0;
|
||||
if (shs_parse_int("42", &value) == SHS_OK && value == 42 &&
|
||||
shs_parse_int("abc", &value) == SHS_ERR_PARSE) {
|
||||
printf("[自检] 输入校验模块 : 通过(合法与非法输入均正确分支)\n");
|
||||
passed++;
|
||||
}
|
||||
|
||||
return passed;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
SHS_UNUSED(argc);
|
||||
SHS_UNUSED(argv);
|
||||
|
||||
shs_print_banner();
|
||||
|
||||
const int passed = shs_bootstrap_self_check();
|
||||
printf("----------------------------------------------------------\n");
|
||||
printf("启动自检:%d 项通过\n", passed);
|
||||
printf("当前为 M0/M1 骨架版本,CLI 菜单与网页界面在后续里程碑接入。\n");
|
||||
printf("构建/运行/测试方式见 README.md 与 docs/05-用户手册.md\n");
|
||||
printf("==========================================================\n");
|
||||
return (passed == 4) ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user