Skip to content

test: 补充控制中心 12 个核心单元的全量单元测试 (DDE-104) - #3519

Merged
MyLeeJiEun merged 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/6420f370
Oct 27, 2026
Merged

MyLeeJiEun merged 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/6420f370

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

"## 概述\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.cpp GetNearestZones:未对空 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

Expand unit-test coverage across twelve previously untested Control Center core components and provide aggregate execution and coverage reporting.

Enhancements:

  • Add module-level GoogleTest targets for core Control Center components and consolidate them under aggregate test and coverage targets.

Build:

  • Rework CMake test registration to support tests within individual modules, shared test instrumentation, ICU/DBus dependencies, and compiler-compatible coverage generation.

Tests:

  • Add comprehensive unit tests covering locale utilities, keyboard metadata and models, timezone calculations, default-application categories and models, personalization key files, mouse gestures, Bluetooth devices, sound ports and device data, and dock plugin sorting.
  • Preserve the existing pinyin-search test while moving it into the keyboard module test suite.

@deepin-ci-robot

Copy link
Copy Markdown

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@sourcery-ai

sourcery-ai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Reviewer's Guide

This 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

Change Details Files
Added broad GoogleTest coverage for 12 previously untested Control Center units, including value objects, locale/timezone utilities, device and sound data, and Qt models.
  • Covered default state, getters/setters, transformations, parsing, equality/order behavior, and boundary cases.
  • Verified Qt signal emission and suppression on unchanged values with QSignalSpy.
  • Exercised model roles, indexes, sorting, category updates, and request signals.
  • Used temporary files and deterministic fixtures for KeyFile and timezone behavior.
tests/ut_dcclocale.cpp
tests/ut_metadata.cpp
tests/ut_timezone_map_util.cpp
tests/ut_category.cpp
tests/ut_categorymodel.cpp
tests/ut_keyfile.cpp
tests/ut_gesturedata.cpp
tests/ut_bluetoothdevice.cpp
tests/ut_port.cpp
tests/ut_sounddevicedata.cpp
tests/ut_keyboardmodel.cpp
tests/ut_dockpluginsortproxymodel.cpp
Integrated the new tests and their production translation units into the unit-test build with required dependencies and access configuration.
  • Added all test and source pairs to the unit-test executable.
  • Added module include paths, Qt Test/DBus, and ICU i18n/uc linkage.
  • Applied per-file -fno-access-control for tests of selected non-public model methods.
tests/CMakeLists.txt
Added an optional instrumentation and coverage-reporting workflow for the expanded unit-test target.
  • Applied the project’s UT_COMPILER flags to compile and link unit tests when enabled.
  • Added a coverage target that runs CTest, captures and filters lcov data to the covered source directories, and renders an HTML report with genhtml.
tests/CMakeLists.txt
Documented known production defects and isolated unsupported assertions without modifying src code.
  • Skipped three numeric-ordering tests because QCollator(QLocale::c()) does not provide working numeric mode in the current environment.
  • Asserted observed behavior for known defects such as App::operator!=, dangling getAppById storage, uninitialized fields, missing SoundDeviceData port implementation, and empty-zone fallback UB.
  • Reported 331 passing, 3 skipped tests with 98.6% line and 98.9% function coverage.
tests/ut_dockpluginsortproxymodel.cpp
tests/ut_category.cpp
tests/ut_categorymodel.cpp
tests/ut_sounddevicedata.cpp
tests/ut_gesturedata.cpp
tests/ut_timezone_map_util.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/CMakeLists.txt Resolved
Comment thread tests/CMakeLists.txt
Comment on lines +86 to +111
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()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/6420f370 branch 3 times, most recently from cc7aab4 to aa7b4d0 Compare September 21, 2026 02:13
@deepin-bot

deepin-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.109
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3545

@deepin-bot

deepin-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.110
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3567

@deepin-bot

deepin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.111
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3573

@deepin-bot

deepin-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.112
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3578

@deepin-bot

deepin-bot Bot commented Oct 21, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 6.1.113
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #3581

@MyLeeJiEun
MyLeeJiEun requested a review from mhduiy October 23, 2026 03:47
caixr23
caixr23 previously approved these changes Oct 23, 2026
1. 为 keyboard、defaultapp、sound、datetime、personalization、mouse、
   bluetooth、dock 及 shared-utils 补充 12 组单元测试,共 334 个用例
2. 测试按归属放到 src/<module>/tests/,由各模块 CMakeLists 在 UNITTEST 时注册,
   顶层 tests/ 只保留框架级测试与聚合 target
3. 新增 dcc_add_unit_test 统一创建测试 target(GTest/Qt、gcov 插桩、用例发现)
4. 新增 unit-tests / run-tests / coverage 聚合 target,coverage 排除 */tests/*
5. debian/rules 增加 -DBUILD_TESTING=ON,打包时编译并运行测试
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为纯测试代码补全,为 dde-control-center 控制中心 12 个核心模块新增全量单元测试。CMake 构建系统新增 dcc_add_unit_test 公共函数和 enable_testing 前置调整,debian/rules 启用 BUILD_TESTING。测试代码结构清晰、覆盖全面、注释详尽,正确使用 GTest/QSignalSpy 验证信号发射与边界条件,并以文档化方式记录了被测源码中已知的缺陷(如 operator!= 逻辑错误、GetNearestZones 空输入 UB、QCollator numeric mode 失效等)。四维度均无扣分项,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

无需修复。本次提交为高质量测试代码,测试覆盖全面、注释详尽、构建系统集成规范。

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mhduiy, MyLeeJiEun

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@MyLeeJiEun
MyLeeJiEun merged commit 8102b25 into linuxdeepin:master Oct 27, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants