test: 补充 dde-services 单元测试与 D-Bus 测试 - #177
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 GuideIntroduces 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 testsequenceDiagram
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
Flow diagram for isolated test executionflowchart 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]
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 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>| include(GNUInstallDirs) | ||
| include(CTest) |
There was a problem hiding this comment.
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).
| include(GNUInstallDirs) | |
| include(CTest) | |
| include(GNUInstallDirs) |
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 构建
1. Enable coverage instrumentation for test targets by default 2. Add coverage target that runs ctest and generates the lcov report Log: Add coverage instrumentation and a coverage target test: 新增覆盖率插桩与 coverage 目标 1. 默认开启测试目标的覆盖率插桩 2. 新增 coverage 目标,执行 ctest 并生成 lcov 报告 Log: 新增覆盖率插桩与 coverage 目标
55aa3f1 to
499d4db
Compare
测试补充:dde-services 单元测试 + D-Bus 契约测试
为 dde-services 新增项目根
tests/目录与 7 个 ctest target(框架 Qt6::Test,门控BUILD_TESTING),覆盖此前无测试的 thememanager / wallpaperslideshow / xsettings 核心逻辑,以及 wallpaperslideshow 的 D-Bus 接口契约。新增文件
tests/CMakeLists.txtset(CMAKE_AUTOMOC ON);wallpaperslideshow-utils经 ctestXDG_CONFIG_HOME隔离写操作;dbus target 源列表接入fakeservice.h触发 AUTOMOCtests/tst_sunrisesunset.cppSunriseSunset纯算法单元测试tests/tst_wpssl_utils.cpputils静态助手单元测试tests/tst_format.cppFormatPictureMIME→类型映射单元测试tests/tst_keyfile.cppKeyFileini/.desktop 解析 + 序列化往返单元测试tests/tst_xsutils.cppUtilsXSETTINGS 字节助手单元测试tests/tst_xsdatainfo.cppXSItemInfo/XSDataInfo纯字节 marshal/unmarshal 单元测试(+23 用例)tests/fakeservice.horg.deepin.dde.WallpaperSlideshow最小实现tests/tst_wallpaperslideshow_dbus.cppCMakeLists.txtinclude(CTest)(project(dde-services)之后);末尾追加BUILD_TESTING门控接入tests/测试结果
tst-xsdatainfo覆盖xsettings/impl/xsdatainfo.cpp纯字节 marshal/unmarshal)覆盖率(测试 target 以
-fno-exceptions构建,gcov + lcov 分支覆盖)三项均达标。注:默认 flags 下分支覆盖偏低,差距来自 gcc 对 Qt6
noexcept代码生成的反向异常清理分支(不可达);测试 target 加-fno-exceptions后实际逻辑分支覆盖 93.5%。新增xsettings/impl/xsdatainfo.cpp100% 分支覆盖(52/52)为主要贡献。构建要点(已修复)
include(CTest):第二轮 squash 到 fork master 基线时丢失了根CMakeLists.txt的include(CTest),导致默认配置下BUILD_TESTING未定义、enable_testing()未调用 → 测试 target 不构建、ctest 找不到测试。本轮已恢复(project(dde-services)之后),以本地e70c5ee为准,与 upstream master 一致。PR 现开箱即用:默认配置即启用测试。add_executable(tst-wallpaperslideshow-dbus ...)源列表加入${CMAKE_CURRENT_SOURCE_DIR}/fakeservice.h,使 AUTOMOC 生成FakeWallpaperSlideshowService的 MOC,消除 vtable 链接错误。tst-xsdatainfo的 AUTOMOC 由源列表中xsdatainfo.cpp触发(其#include "xsdatainfo.h"),无需额外处理。wallpaperslideshow-utils用例经 ctestset_tests_properties(... ENVIRONMENT "XDG_CONFIG_HOME=...")重定向writeWallpaperConfig写路径,未设时QSKIP,不污染真实用户配置。org.deepin.dde.WallpaperSlideshow.Test.p<pid>在隔离 session bus 上运行,session bus 不可用时QSKIP。记录的被测代码缺陷(仅记录,未修改被测代码)
wallpaperslideshow/utils.cppisFileExists:URI 解码结果未使用,对原始filename判存在,URI 输入恒判不存在。xsettings/keyfile.cppKeyFile::deleteKey:键已移除但恒返回 false。xsettings/keyfile.cppKeyFile::getBool:section 缺失时恒返回 false(非 defaultValue)。wallpaperslideshow/background/format.cppFormatPicture::typeMap:image/gif映射为"jpeg"(疑误)。thememanager/sunrisesunset.cppSunriseSunset:极昼/极夜位置sunrise值无意义。wallpaperslideshow/utils.cppWriteStringToFile:swapFile=filename+"/.swap"经QDir.mkpath建成目录,QFile::open(WriteOnly)打开目录失败(EISDIR),非空名恒返回 false。对缺陷 #1/#2/#5/#6,测试按实际行为断言并注释标注,未掩盖。
验证指令
Related Multica issue: DDE-106 (id
6f46b926-e537-4e11-a557-252426580cc9)Summary by Sourcery
Expand dde-services with comprehensive unit and D-Bus contract testing, enabled by default through CTest and accompanied by coverage reporting.
Enhancements:
Build:
Tests:
Chores: