Skip to content

test: 补充 dde-services 单元测试 - #177

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/test-supplement
Oct 27, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/test-supplement

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

测试补充:dde-services 单元测试 + D-Bus 契约测试

为 dde-services 新增项目根 tests/ 目录与 7 个 ctest target(框架 Qt6::Test,门控 BUILD_TESTING),覆盖此前无测试的 thememanager / wallpaperslideshow / xsettings 核心逻辑,以及 wallpaperslideshow 的 D-Bus 接口契约。

新增文件

路径 说明
tests/CMakeLists.txt 7 个 ctest target 注册;set(CMAKE_AUTOMOC ON);wallpaperslideshow-utils 经 ctest XDG_CONFIG_HOME 隔离写操作;dbus target 源列表接入 fakeservice.h 触发 AUTOMOC
tests/tst_sunrisesunset.cpp thememanager SunriseSunset 纯算法单元测试
tests/tst_wpssl_utils.cpp wallpaperslideshow utils 静态助手单元测试
tests/tst_format.cpp wallpaperslideshow FormatPicture MIME→类型映射单元测试
tests/tst_keyfile.cpp xsettings KeyFile ini/.desktop 解析 + 序列化往返单元测试
tests/tst_xsutils.cpp xsettings Utils XSETTINGS 字节助手单元测试
tests/tst_xsdatainfo.cpp xsettings XSItemInfo/XSDataInfo 纯字节 marshal/unmarshal 单元测试(+23 用例)
tests/fakeservice.h D-Bus 测试用 org.deepin.dde.WallpaperSlideshow 最小实现
tests/tst_wallpaperslideshow_dbus.cpp wallpaperslideshow D-Bus 接口契约测试
CMakeLists.txt 恢复 include(CTest)(project(dde-services) 之后);末尾追加 BUILD_TESTING 门控接入 tests/

测试结果

  • 用例数:134/134 通过,0 failed,0 skipped
    • thememanager-sunrisesunset 14 / wallpaperslideshow-utils 31 / wallpaperslideshow-format 8 / xsettings-keyfile 25 / xsettings-xsutils 25 / xsettings-xsdatainfo 25 / wallpaperslideshow-dbus 6
  • 第一轮 77 → 第二轮 +33(109)→ 第三轮 +25(134,新增 tst-xsdatainfo 覆盖 xsettings/impl/xsdatainfo.cpp 纯字节 marshal/unmarshal)

覆盖率(测试 target 以 -fno-exceptions 构建,gcov + lcov 分支覆盖)

指标 覆盖率 门线 70%
行覆盖率 96.9% ✅
函数覆盖率 94.2% ✅
分支覆盖率 93.5% ✅

三项均达标。注:默认 flags 下分支覆盖偏低,差距来自 gcc 对 Qt6 noexcept 代码生成的反向异常清理分支(不可达);测试 target 加 -fno-exceptions 后实际逻辑分支覆盖 93.5%。新增 xsettings/impl/xsdatainfo.cpp 100% 分支覆盖(52/52)为主要贡献。

构建要点(已修复)

  • 恢复 include(CTest):第二轮 squash 到 fork master 基线时丢失了根 CMakeLists.txt 的 include(CTest),导致默认配置下 BUILD_TESTING 未定义、enable_testing() 未调用 → 测试 target 不构建、ctest 找不到测试。本轮已恢复(project(dde-services) 之后),以本地 e70c5ee 为准,与 upstream master 一致。PR 现开箱即用:默认配置即启用测试。
  • AUTOMOC 修复合入:add_executable(tst-wallpaperslideshow-dbus ...) 源列表加入 ${CMAKE_CURRENT_SOURCE_DIR}/fakeservice.h,使 AUTOMOC 生成 FakeWallpaperSlideshowService 的 MOC,消除 vtable 链接错误。tst-xsdatainfo 的 AUTOMOC 由源列表中 xsdatainfo.cpp 触发(其 #include "xsdatainfo.h"),无需额外处理。
  • XDG_CONFIG_HOME 隔离:wallpaperslideshow-utils 用例经 ctest set_tests_properties(... ENVIRONMENT "XDG_CONFIG_HOME=...") 重定向 writeWallpaperConfig 写路径,未设时 QSKIP,不污染真实用户配置。
  • D-Bus 用例用唯一服务名 org.deepin.dde.WallpaperSlideshow.Test.p<pid> 在隔离 session bus 上运行,session bus 不可用时 QSKIP。

记录的被测代码缺陷(仅记录,未修改被测代码)

  1. wallpaperslideshow/utils.cpp isFileExists:URI 解码结果未使用,对原始 filename 判存在,URI 输入恒判不存在。
  2. xsettings/keyfile.cpp KeyFile::deleteKey:键已移除但恒返回 false。
  3. xsettings/keyfile.cpp KeyFile::getBool:section 缺失时恒返回 false(非 defaultValue)。
  4. wallpaperslideshow/background/format.cpp FormatPicture::typeMap:image/gif 映射为 "jpeg"(疑误)。
  5. thememanager/sunrisesunset.cpp SunriseSunset:极昼/极夜位置 sunrise 值无意义。
  6. wallpaperslideshow/utils.cpp WriteStringToFile:swapFile=filename+"/.swap" 经 QDir.mkpath 建成目录,QFile::open(WriteOnly) 打开目录失败(EISDIR),非空名恒返回 false。

对缺陷 #1/#2/#5/#6,测试按实际行为断言并注释标注,未掩盖。

验证指令

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug   # BUILD_TESTING 默认 ON(include(CTest))
cmake --build build --target tst-sunrisesunset tst-wpssl-utils tst-format \
                              tst-keyfile tst-xsutils tst-xsdatainfo \
                              tst-wallpaperslideshow-dbus -j"$(nproc)"
cd build && ctest --output-on-failure

Related Multica issue: DDE-106 (id 6f46b926-e537-4e11-a557-252426580cc9)

Summary by Sourcery

Expand dde-services with isolated unit and D-Bus contract testing for core plugin behavior, including optional coverage reporting.

Enhancements:

  • Add comprehensive Qt unit and D-Bus contract coverage for thememanager, wallpaperslideshow, and xsettings core logic.
  • Add an optional coverage target that runs the test suite and generates filtered lcov reports.
  • Isolate filesystem and session-bus test side effects from user configuration and production services.

Build:

  • Integrate module test suites with CTest under BUILD_TESTING and restore default test discovery configuration.

Tests:

  • Add seven CTest targets covering sunrise/sunset calculations, wallpaper slideshow utilities and format detection, xsettings parsing and byte serialization, and the WallpaperSlideshow D-Bus interface.

@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

Introduces seven Qt6/CTest targets covering thememanager, wallpaperslideshow, and xsettings core logic plus the WallpaperSlideshow D-Bus contract. The suite is enabled through restored CTest integration, uses AUTOMOC and isolated filesystem/session-bus execution, includes optional coverage reporting, and records several pre-existing implementation defects through explicit behavior-based tests.

Sequence diagram for the isolated WallpaperSlideshow D-Bus contract test

sequenceDiagram
    participant Test as D-Bus test
    participant Bus as Session D-Bus
    participant Fake as FakeWallpaperSlideshowService
    participant Impl as WallpaperSlideshow implementation
    Test->>Bus: register unique test service name
    Test->>Fake: start service on isolated session bus
    Test->>Impl: invoke WallpaperSlideshow D-Bus contract
    Impl-->>Test: return D-Bus response
    Test->>Test: verify contract behavior
    Test->>Bus: release test service
Loading

Flow diagram for isolated test execution

flowchart TD
    Build[Build Qt test targets with AUTOMOC] --> CTest[Run CTest]
    CTest --> Utils[wallpaperslideshow-utils]
    Utils --> Config[Isolated XDG_CONFIG_HOME]
    CTest --> DBus[wallpaperslideshow-dbus]
    DBus --> Bus[Isolated session bus]
    Config --> Results[Behavior-based test results]
    Bus --> Results
    Results --> Coverage[Optional gcov lcov coverage report]
Loading

File-Level Changes

Change Details Files
Added seven BUILD_TESTING-gated Qt6 test executables and registered them with CTest.
  • Restored root CTest integration and added the tests subdirectory behind BUILD_TESTING.
  • Configured AUTOMOC, optional gcov/lcov coverage instrumentation, and a coverage aggregate target.
  • Built each target with only the production sources required by the corresponding test to avoid plugin GLOB/linkage issues.
CMakeLists.txt
tests/CMakeLists.txt
Added unit coverage for thememanager and wallpaperslideshow core helpers, including behavior-based assertions for known defects.
  • Tested sunrise/sunset calculations across normal, polar, geographic, and timezone cases.
  • Covered URI handling, filesystem helpers, config writing, directory paths, and environment-dependent utilities.
  • Verified MIME-to-picture-type mapping, including the existing GIF-to-JPEG behavior.
tests/tst_sunrisesunset.cpp
tests/tst_wpssl_utils.cpp
tests/tst_format.cpp
Added comprehensive xsettings parser and wire-format serialization tests.
  • Covered KeyFile parsing, defaults, sections, separators, mutation, deletion, and serialization round trips.
  • Tested XSETTINGS byte helpers for endian conversion, padding, strings, skips, truncation, and variant handling.
  • Exercised XSItemInfo and XSDataInfo marshal/unmarshal paths for integer, string, color, mismatch, unknown-type, collection, and serial cases.
tests/tst_keyfile.cpp
tests/tst_xsutils.cpp
tests/tst_xsdatainfo.cpp
Added an isolated D-Bus contract test for the WallpaperSlideshow interface.
  • Implemented a minimal QObject fake service and generated its adaptor from the production introspection XML.
  • Validated introspection, per-monitor method round trips, independent monitor state, and read/write property access over the session bus.
  • Used a per-process service name and skipped gracefully when no session bus is available.
tests/fakeservice.h
tests/tst_wallpaperslideshow_dbus.cpp
tests/CMakeLists.txt
Isolated test side effects and documented existing production-code defects without changing production behavior.
  • Redirected XDG_CONFIG_HOME for the config-writing test and used temporary filesystem fixtures.
  • Asserted documented defects according to current behavior so they remain visible during review.
  • Reported 134 passing cases and coverage instrumentation/reporting for the tested plugin sources.
tests/CMakeLists.txt
tests/tst_wpssl_utils.cpp
tests/tst_keyfile.cpp
tests/tst_format.cpp
tests/tst_sunrisesunset.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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="CMakeLists.txt" line_range="16-17" />
<code_context>

 project(dde-services)

+include(CTest)
+
 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
</code_context>
<issue_to_address>
**nitpick:** `CTest` is included twice in the root file, redundantly reprocessing the module and obscuring which inclusion is intended to define `BUILD_TESTING` and enable testing.

**Suggested fix:** Remove the duplicate `include(CTest)` and keep the one immediately after `project(dde-services)`.

```suggestion
include(GNUInstallDirs)
```
</issue_to_address>

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

Comment thread CMakeLists.txt Outdated
@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/test-supplement branch 3 times, most recently from 1ea453e to 499d4db Compare September 21, 2026 02:05
@deepin-bot

deepin-bot Bot commented Sep 22, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.44
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #184

@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/test-supplement branch from 499d4db to fdab2cf Compare September 24, 2026 02:19
@deepin-bot

deepin-bot Bot commented Oct 12, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.45
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #189

@deepin-bot

deepin-bot Bot commented Oct 15, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.46
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #198

@deepin-bot

deepin-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.47
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #202

@mhduiy mhduiy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里模块各自独立的模块单元测试最好放在模块内部,目录结构看起来也好看一点,而不是放在最外层

@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/test-supplement branch 2 times, most recently from a9c64e9 to 0895563 Compare October 23, 2026 06:14
@MyLeeJiEun
MyLeeJiEun requested a review from mhduiy October 23, 2026 06:14
为 thememanager / wallpaperslideshow / xsettings 补充 7 个 ctest target,
共 134 条用例,覆盖此前无测试的核心逻辑及 wallpaperslideshow 的 D-Bus
接口契约。

- 测试放在各模块自己的 tests/ 目录下(thememanager、wallpaperslideshow、
  xsettings),由插件 CMakeLists 在 BUILD_TESTING 门控下接入;插件的
  GLOB_RECURSE 排除 /tests/,避免测试源被编进生产 MODULE
- 测试框架 Qt6::Test;D-Bus 用例用独立服务名在 session bus 上验证接口契约,
  无 session bus 时 QSKIP;utils 用例通过 XDG_CONFIG_HOME 隔离写操作
- 根 CMakeLists 保留聚合 coverage target(lcov/genhtml),ctest 只跑本套件
  的 7 个测试,避免依赖未构建的其它测试目标;去掉重复的 include(CTest)

验证:默认配置下 7/7 target、134/134 用例通过;coverage target 可生成报告;
BUILD_TESTING=OFF 构建通过。
@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/test-supplement branch from 0895563 to d839636 Compare October 23, 2026 06:36
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 dde-services 项目三个插件模块(thememanager、wallpaperslideshow、xsettings)补充了完整的单元测试与 D-Bus 契约测试, 共新增 15 个文件、2019 行代码。代码语法正确、逻辑清晰,测试结构规范、注释详尽,无安全漏洞,性能无瓶颈。 测试覆盖了纯函数、序列化/反序列化、文件解析、D-Bus 接口契约等多个层面,并妥善记录了已知的代码缺陷(Defect #1-#6), 通过断言实际行为而非期望行为来保证测试可靠性。整体质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: ['无改进建议,语法逻辑层面表现优秀']


2. 代码质量 ✅

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

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

建议: ['无改进建议,代码质量层面表现优秀']


3. 代码性能 ✅

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

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

建议: ['无改进建议,性能层面表现良好']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['无改进建议,安全层面表现优秀']


💡 改进建议代码示例


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

@MyLeeJiEun MyLeeJiEun changed the title test: 补充 dde-services 单元测试与 D-Bus 测试 test: 补充 dde-services 单元测试 Oct 23, 2026
@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

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit eafef28 into linuxdeepin:master Oct 27, 2026
6 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.

3 participants