Repository navigation
test: 补充 dde-services 单元测试 - #177
Conversation
|
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>1ea453e to
499d4db
Compare
|
TAG Bot New tag: 1.0.44 |
499d4db to
fdab2cf
Compare
|
TAG Bot New tag: 1.0.45 |
|
TAG Bot New tag: 1.0.46 |
|
TAG Bot New tag: 1.0.47 |
mhduiy
left a comment
There was a problem hiding this comment.
这里模块各自独立的模块单元测试最好放在模块内部,目录结构看起来也好看一点,而不是放在最外层
a9c64e9 to
0895563
Compare
为 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 构建通过。
0895563 to
d839636
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无改进建议,语法逻辑层面表现优秀'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['无改进建议,代码质量层面表现优秀'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无改进建议,性能层面表现良好'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无改进建议,安全层面表现优秀'] 💡 改进建议代码示例本报告由 AI 代码审查工具自动生成 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/forcemerge |
|
This pr force merged! (status: blocked) |
测试补充: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 isolated unit and D-Bus contract testing for core plugin behavior, including optional coverage reporting.
Enhancements:
Build:
Tests: