Skip to content

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

Open
MyLeeJiEun wants to merge 2 commits into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/6420f370
Open

MyLeeJiEun wants to merge 2 commits 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

Increase control-center unit-test coverage by adding comprehensive tests for 12 core units and integrating automated coverage reporting.

Enhancements:

  • Expand unit-test coverage across 12 previously untested control-center core components, including locale utilities, metadata, timezone mapping, application categories and models, keyboard and gesture data, Bluetooth, sound, and dock models.
  • Add ICU and Qt test dependencies and expose a reusable coverage target that runs the test suite and generates filtered lcov reports for the covered modules.

Build:

  • Update the unit-test build to compile the 12 additional test/source pairs and link the required Qt, ICU, and coverage libraries.

Tests:

  • Add comprehensive GoogleTest coverage for core data objects, models, utility functions, signal behavior, sorting, persistence, and boundary cases.

Chores:

  • Document known source-level defects and skip affected assertions without modifying production code.

@deepin-ci-robot

Copy link
Copy Markdown

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

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

@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 Outdated
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

为 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 宏

This branch has not been deployed

No deployments
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.

2 participants