fix(storage)+test: 修复设备表校验和可被绕过,登记 5 套新单元测试

- 缺陷(由测试 agent 用例 TC-FILE-005 发现):read_device 在读取后立刻把 name 末字节置 0,
  导致文件里该字节被篡改时校验和仍能对上,完整性校验形同虚设。
  修复:先按原始字节做校验和比对,通过后再统一做字段清洗(补 NUL 结尾)。
  实测:篡改 name 末字节的设备表现在被正确判为 SHS_ERR_PARSE。
- 测试期望修正:配置名称上限 32 字节(约 10 个汉字),超长应返回 SHS_ERR_RANGE
  而不是静默截断;补充正常长度用例。
- 登记 unit.branch / unit.loop / unit.bitops / unit.errors / unit.file 五套到 runner 与 CTest。
- ctest 8/8 通过。
This commit is contained in:
sambu committed 2026-09-14 20:28:32 +08:00
1 parent 190edad1ce
commit 4b4b24ca4a
5 files changed
+830 -3

No files matched your search

+12 -2
View File
@@ -116,7 +116,12 @@ if(SHS_BUILD_TESTS)
tests/framework/test_framework.c
tests/test_runner.c
tests/unit/test_string.c
tests/unit/test_num.c)
tests/unit/test_num.c
tests/unit/test_branch.c
tests/unit/test_loop.c
tests/unit/test_bitops.c
tests/unit/test_errors.c
tests/unit/test_file.c)
add_executable(shs_tests ${SHS_TEST_SOURCES})
target_link_libraries(shs_tests PRIVATE shs_core shs_warnings)
@@ -125,7 +130,12 @@ if(SHS_BUILD_TESTS)
# 每个测试套件在 CTest 中独立注册(ctest -R unit.string)
set(SHS_TEST_SUITES
unit.string
unit.num)
unit.num
unit.branch
unit.loop
unit.bitops
unit.errors
unit.file)
foreach(suite IN LISTS SHS_TEST_SUITES)
add_test(NAME ${suite} COMMAND shs_tests --suite ${suite})
endforeach()