Skip to content

test: 补充 dde-services 单元测试与 D-Bus 测试 - #151

Draft
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/test-supplement
Draft

test: 补充 dde-services 单元测试与 D-Bus 测试#151
MyLeeJiEun wants to merge 1 commit into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/test-supplement

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Aug 17, 2026

Copy link
Copy Markdown

测试补充: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.txtinclude(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::typeMapimage/gif 映射为 "jpeg"(疑误)。
  5. thememanager/sunrisesunset.cpp SunriseSunset:极昼/极夜位置 sunrise 值无意义。
  6. wallpaperslideshow/utils.cpp WriteStringToFileswapFile=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)

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

Sorry @MyLeeJiEun, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@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. 😃

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

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.40
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #154

@deepin-bot

deepin-bot Bot commented Aug 18, 2026

Copy link
Copy Markdown

TAG Bot

New tag: 1.0.41
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #155

1. Add tests/ with 7 Qt6::Test ctest targets: thememanager
   sunrise, wpssl utils/format/dbus, xsettings
   keyfile/xsutils/xsdatainfo, gated by BUILD_TESTING
2. Add fakeservice.h D-Bus stub; enable AUTOMOC on the dbus target
3. Isolate wpssl-utils via ctest XDG_CONFIG_HOME; QSKIP on no bus
4. Restore include(CTest) in root CMakeLists so BUILD_TESTING
   defaults on and enable_testing() runs (lost in prior squash)
5. 134/134 cases pass; coverage (target -fno-exceptions): line
   96.9%, function 94.2%, branch 93.5%, all above the 70% bar

Influence:
1. Build with -DBUILD_TESTING=ON and run ctest for the 7 targets
2. Coverage via -fprofile-arcs -ftest-coverage + --coverage link,
   lcov branch coverage; build the test target with -fno-exceptions

test: 补充 dde-services 单元测试与 D-Bus 测试

1. 新增 tests/ 与 7 个 Qt6::Test ctest target:thememanager
   sunrise、wpssl utils/format/dbus、xsettings
   keyfile/xsutils/xsdatainfo,由 BUILD_TESTING 门控
2. 新增 fakeservice.h D-Bus 桩,dbus target 接入 AUTOMOC
3. wallpaperslideshow-utils 用 ctest XDG_CONFIG_HOME 隔离,缺
   session bus 时 QSKIP
4. 恢复根 CMakeLists 的 include(CTest),使 BUILD_TESTING 默认开启
   且 enable_testing() 生效(此前 squash 丢失该行)
5. 134/134 用例通过;覆盖率(target -fno-exceptions):行
   96.9%、函数 94.2%、分支 93.5%,三项均达 70% 门线

Influence:
1. 以 -DBUILD_TESTING=ON 构建,对 7 个 target 运行 ctest
2. 覆盖率:-fprofile-arcs -ftest-coverage + --coverage 链接,
   lcov 分支覆盖;测试 target 以 -fno-exceptions 构建
@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/test-supplement branch from 1df7e0a to cf2d7d3 Compare August 19, 2026 08:43
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