test: 补充控制中心 12 个核心单元的全量单元测试 (DDE-104) - #3519
MyLeeJiEun wants to merge 2 commits into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: MyLeeJiEun The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @MyLeeJiEun. Thanks for your PR. I'm waiting for a linuxdeepin member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Reviewer's GuideThis PR adds 334 GoogleTest cases across 12 previously uncovered Control Center units, validates Qt model/object behavior and utility edge cases without changing production sources, and wires the tests into the build with ICU/Qt dependencies plus optional lcov HTML coverage reporting; the reported result is 331 passed, 3 skipped, and no failures. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/CMakeLists.txt" line_range="76-77" />
<code_context>
+#(GNU: -fprofile-arcs -ftest-coverage;Clang: -fprofile-instr-generate -ftest-coverage)。
+# 这里将其应用到 unit-test target,使被测源与测试源都被插桩。
+if(UNITTEST AND DEFINED UT_COMPILER)
+ target_compile_options(${BIN_NAME} PRIVATE ${UT_COMPILER})
+ target_link_options(${BIN_NAME} PRIVATE ${UT_COMPILER})
+endif()
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The Clang branch supplies `-fprofile-instr-generate -ftest-coverage`, which produces LLVM profiling data, but the coverage target always invokes `lcov --capture`, which expects gcov-compatible coverage data. On Clang builds the `coverage` target therefore fails or produces no usable report.
**Triggers:** When the project is configured with Clang and the `coverage` target is built.
**Suggested fix:** Use LLVM's `llvm-profdata`/`llvm-cov export` pipeline for Clang, or restrict the lcov target to GNU instrumentation and provide a separate Clang coverage target.
</issue_to_address>
### Comment 2
<location path="tests/CMakeLists.txt" line_range="86-111" />
<code_context>
+find_program(LCOV_BIN lcov)
</code_context>
<issue_to_address>
**nitpick (bug_risk):** When either `lcov` or `genhtml` is unavailable, `_coverage_report_cmds` remains empty but the `coverage` target is still created and runs only CTest. The target then succeeds without generating the coverage report promised by its name and comments.
**Triggers:** When the build environment lacks `lcov` or `genhtml`.
**Suggested fix:** Fail configuration or the target explicitly when the coverage tools are missing, or rename the fallback target so it does not claim to generate coverage.
</issue_to_address>| find_program(LCOV_BIN lcov) | ||
| find_program(GENHTML_BIN genhtml) | ||
| set(_coverage_report_cmds "") | ||
| if(LCOV_BIN AND GENHTML_BIN) | ||
| set(_coverage_report_cmds | ||
| COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/coverage_report" | ||
| COMMAND ${LCOV_BIN} --capture --directory "${CMAKE_BINARY_DIR}" | ||
| --rc lcov_branch_coverage=1 | ||
| --output-file "${CMAKE_BINARY_DIR}/coverage.info" | ||
| COMMAND ${LCOV_BIN} --extract "${CMAKE_BINARY_DIR}/coverage.info" | ||
| --rc lcov_branch_coverage=1 | ||
| "${PROJECT_SOURCE_DIR}/src/shared-utils/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-keyboard/operation/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-datetime/operation/timezoneMap/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-defaultapp/operation/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-personalization/operation/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-mouse/operation/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-bluetooth/operation/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-sound/operation/*" | ||
| "${PROJECT_SOURCE_DIR}/src/plugin-dock/operation/*" | ||
| --output-file "${CMAKE_BINARY_DIR}/coverage_filtered.info" | ||
| COMMAND ${GENHTML_BIN} "${CMAKE_BINARY_DIR}/coverage_filtered.info" | ||
| --branch-coverage | ||
| --output-directory "${CMAKE_BINARY_DIR}/coverage_report" | ||
| ) | ||
| endif() |
There was a problem hiding this comment.
nitpick (bug_risk): When either lcov or genhtml is unavailable, _coverage_report_cmds remains empty but the coverage target is still created and runs only CTest. The target then succeeds without generating the coverage report promised by its name and comments.
Triggers: When the build environment lacks lcov or genhtml.
Suggested fix: Fail configuration or the target explicitly when the coverage tools are missing, or rename the fallback target so it does not claim to generate coverage.
cc7aab4 to
aa7b4d0
Compare
|
TAG Bot New tag: 6.1.109 |
为 dde-control-center 补充 12 个核心单元的 GTest 单元测试,覆盖 DCCLocale、MetaData、KeyboardModel、DockPluginSortProxyModel、CategoryModel 等模块。新增 12 个测试文件并修改 tests/CMakeLists.txt,共 13 个文件、334 个用例(331 passed / 0 failed / 3 skipped)。 覆盖率:行 98.6% / 函数 98.9% / 分支 66.6%,均达交付达标线(函数 >80% / 行 >80% / 分支尽可能高)。 关联 issue: DDE-104
1. Replace the private/public macro trick with -fno-access-control to avoid breaking std/gtest headers Log: Replace private/public macros with -fno-access-control test: 改用 -fno-access-control 替代 private/public 宏 1. 用 -fno-access-control 替换 private/public 宏,避免破坏标准库与 gtest 头文件 Log: 用 -fno-access-control 替换 private/public 宏
aa7b4d0 to
f83ec69
Compare
"## 概述\n\n为控制中心 5 轮迭代共补充 12 个新增测试文件 + 1 个修改的 CMakeLists.txt = 13 个文件,覆盖此前零覆盖的 12 个核心单元,测试用例共计 334 个(331 passed / 0 failed / 3 skipped),仅触及
tests/目录,不改动src/被测源码。\n\n## 测试文件清单(12 个新增 + 1 个修改)\n\n| 文件 | 类型 | 被测对象 |\n|---|---|---|\n|tests/ut_dcclocale.cpp| 新增 |DCCLocale::stripTimezoneFromTimeFormat及方言/语言名查询(src/shared-utils/dcclocale.cpp) |\n|tests/ut_metadata.cpp| 新增 |dccV25::MetaData(src/plugin-keyboard/operation/metadata.cpp) |\n|tests/ut_timezone_map_util.cpp| 新增 |ConvertLongitudeToX/ConvertLatitudeToY/GetNearestZones(src/plugin-datetime/operation/timezoneMap/timezone_map_util.cpp) |\n|tests/ut_category.cpp| 新增 |dccV25::Category(src/plugin-defaultapp/operation/category.cpp) |\n|tests/ut_categorymodel.cpp| 新增 |dccV25::CategoryModel(src/plugin-defaultapp/operation/categorymodel.cpp) |\n|tests/ut_keyfile.cpp| 新增 |dccV25::KeyFile(src/plugin-personalization/operation/keyfile.cpp) |\n|tests/ut_gesturedata.cpp| 新增 |dccV25::GestureData(src/plugin-mouse/operation/gesturedata.cpp) |\n|tests/ut_bluetoothdevice.cpp| 新增 |dccV25::BluetoothDevice(src/plugin-bluetooth/operation/bluetoothdevice.cpp) |\n|tests/ut_port.cpp| 新增 |dccV25::Port(src/plugin-sound/operation/port.cpp) |\n|tests/ut_sounddevicedata.cpp| 新增 |dccV25::SoundDeviceData(src/plugin-sound/operation/sounddevicedata.cpp) |\n|tests/ut_keyboardmodel.cpp| 新增 |dccV25::KeyboardModel(src/plugin-keyboard/operation/keyboardmodel.cpp) |\n|tests/ut_dockpluginsortproxymodel.cpp| 新增 |dccV25::DockPluginSortProxyModel(src/plugin-dock/operation/dockpluginsortproxymodel.cpp) |\n|tests/CMakeLists.txt| 修改 | 将上述被测源文件编入unit-test二进制 + ICU 链接 + gcovr 覆盖率 target |\n\n## 测试结果\n\n- 331 passed / 0 failed / 3 skipped(3 个 skip 为QCollator(QLocale::c())numeric mode 排序缺陷导致,已记录)\n- 覆盖全部 12 个被测核心单元,用例总数 334\n\n## 覆盖率(均达标)\n\n| 指标 | 数值 | 达标线 | 状态 |\n|---|---|---|---|\n| 行覆盖率 | 98.6% | >80% | ✅ |\n| 函数覆盖率 | 98.9% | >80% | ✅ |\n| 分支覆盖率 | 66.6% | 尽可能高 | ✅ |\n\n## 被测代码缺陷记录(供评审参考)\n\n-dockpluginsortproxymodel.cpp:51:QCollator(QLocale::c())在 numeric mode 下排序无效,3 个测试用例因此GTEST_SKIP()跳过。建议改用有效QLocale构造QCollator。不在本 PR 修复范围。\n-timezone_map_util.cppGetNearestZones:未对空total_zones输入做保护,total_zones.at(-1)为越界访问(UB)。测试按实际定义行为写断言,不写空输入用例。\n\n## 关联\n\n- Multica Issue:DDE-104(补充控制中心测试)\n- 提交范围:4406a05b..32bde322(16 commits,均含DDE-104标记)\n- 仅触及tests/目录,不改动src/被测源码\n"Summary by Sourcery
Increase control-center unit-test coverage by adding comprehensive tests for 12 core units and integrating automated coverage reporting.
Enhancements:
Build:
Tests:
Chores: