Skip to content

test(dconfig): add unit tests for dconfig-center - #161

Merged
deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/138c30fc68d7
Sep 20, 2026
Merged

deepin-bot[bot] merged 2 commits into
linuxdeepin:masterfrom
MyLeeJiEun:agent/dde/138c30fc68d7

Conversation

@MyLeeJiEun

@MyLeeJiEun MyLeeJiEun commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

补充 dde-app-services dconfig-center 单元测试代码,提升测试覆盖率。

Multica Issue: DDE-207

Changes

  • 新增 ut_dconfig_global.cpp — 全局工具函数测试(formatDBusObjectPath / getUserNameByUid 等)
  • 新增 ut_helper.cpp — 缓存管理器及辅助函数测试(ConfigSyncRequestCache / RefManager 等)
  • 扩展 ut_dconfigconn.cpp — 新增 8 个测试用例,修复 save 断言路径匹配问题
  • 扩展 ut_dconfigserver.cpp — 新增 9 个测试用例,修复 reload_withFileChange 路径解析
  • 改进 test_helper.hpp — 新增 MetaFileGuard RAII,EnvGuard 改用 rmpath 递归清理
  • 更新 CMakeLists.txt — ENABLE_COVERAGE 选项条件控制覆盖率,新增测试源文件

Test Results

  • 202 passed / 0 failed / 6 skipped
  • Coverage: 行 86.3% / 函数 96.9%(均 > 80%)

License

文件头版权声明年份已更新为 2026。

Summary by Sourcery

Increase dconfig-center test coverage and make the test suite independently runnable with integrated CTest and coverage support.

Enhancements:

  • Expand dconfig-center unit-test coverage across global utilities, helpers, connections, resources, and server behavior.

Build:

  • Make test builds conditional on BUILD_TESTING, add GoogleTest discovery, and provide configurable coverage-report generation.

Tests:

  • Add comprehensive tests for configuration path handling, caching, resource lifecycle, value and signal behavior, reparsing, synchronization, permissions, and server operations.
  • Improve test isolation and cleanup with temporary per-process directories, environment restoration, file backups, and writable test fixtures.

Chores:

  • Update test file copyright years through 2026.

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/tests/test_helper.hpp": {
            "b": [
                "            qunsetenv(m_name);"
            ]
        },
        "dconfig-center/tests/ut_dconfigconn.cpp": {
            "b": [
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "// Branch: isDefaultValue() returns true for unset key (default)"
            ]
        },
        "dconfig-center/tests/ut_helper.cpp": {
            "b": [
                "        qunsetenv(\"DSG_CONFIG_CONNECTION_DISABLE_DBUS\");"
            ]
        }
    }
}

@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 substantially expands dconfig-center unit coverage by adding global/helper tests and many connection, resource, and server edge-case tests, while improving fixture isolation with RAII guards and temporary paths. It also makes tests discoverable through CTest and adds optional lcov reporting controlled by CMake options; the reported result is 202 passed, 0 failed, 6 skipped, with 86.3% line and 96.9% function coverage.

File-Level Changes

Change Details Files
Expanded unit-test coverage across dconfig-center’s global utilities and helper functions.
  • Added tests for DBus/resource/connection key formatting, configure-ID parsing, process/user lookup, object pooling, filesystem discovery, QVariant/JSON conversion, validation, translation, and user-info helpers.
  • Added edge-case and invalid-input coverage, while explicitly skipping known source-defect scenarios.
dconfig-center/tests/ut_dconfig_global.cpp
dconfig-center/tests/ut_helper.cpp
Added broader connection and resource behavior tests with isolated temporary state.
  • Covered connection accessors, permissions, signals, defaults, value/reset branches, cache synchronization, resource lifecycle, save behavior, reparsing, metadata changes, and cache queries.
  • Made fixture files writable and redirected state/cache paths to PID-specific temporary directories for order-independent execution.
  • Added RAII restoration for modified metadata and environment-backed test directories.
dconfig-center/tests/ut_dconfigconn.cpp
dconfig-center/tests/test_helper.hpp
Expanded server tests for lifecycle, reload, synchronization, path handling, and edge cases.
  • Tested user-data removal, exit behavior, release handling, initialization signatures, update/sync/reload paths, configure-path parsing, cache synchronization, invalid inputs, and resource cleanup.
  • Added deterministic metadata mutation and restoration for reload/reparse scenarios.
dconfig-center/tests/ut_dconfigserver.cpp
Improved test build integration and optional coverage reporting.
  • Enabled CTest and conditionally includes the test directory through BUILD_TESTING.
  • Added GTest discovery, private-member test compilation support, and the new test sources.
  • Added configurable ENABLE_COVERAGE instrumentation plus a coverage target that runs CTest and optionally captures, filters, and renders lcov reports.
CMakeLists.txt
dconfig-center/CMakeLists.txt
dconfig-center/tests/CMakeLists.txt

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="dconfig-center/tests/CMakeLists.txt" line_range="14" />
<code_context>
 set(AUTOMOC_COMPILER_PREDEFINES ON)

-set(DTK_HAS_UNIT_TEST ON)
+option(ENABLE_COVERAGE "Enable coverage instrumentation" ON)
 # for coverage
-if (DTK_HAS_UNIT_TEST)
</code_context>
<issue_to_address>
**issue:** ENABLE_COVERAGE defaults to ON, so configuring with the default options instruments and links the test binary for coverage instead of leaving coverage disabled by default as the change description specifies.

**Triggers:** When the project is configured without explicitly setting ENABLE_COVERAGE.

**Suggested fix:** Change the option default to OFF.

```suggestion
option(ENABLE_COVERAGE "Enable coverage instrumentation" OFF)
```
</issue_to_address>

### Comment 2
<location path="dconfig-center/tests/test_helper.hpp" line_range="17" />
<code_context>
+        if (m_name)
+            restore();
+        if (!m_createdDir.isEmpty())
+            QDir().rmpath(m_createdDir);
+    }
     void set(const char *name, const QByteArray &value)
</code_context>
<issue_to_address>
**issue (bug_risk):** EnvGuard calls QDir::rmpath() rather than recursively removing the directory contents, so files created below an environment-provided directory prevent cleanup and leave test artifacts behind.

**Triggers:** When a guarded environment path is newly created and a test writes files or subdirectories beneath it.

**Suggested fix:** Use `QDir(m_createdDir).removeRecursively()` for the directory created by the guard.

```suggestion
            QDir(m_createdDir).removeRecursively();
```
</issue_to_address>

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

set(AUTOMOC_COMPILER_PREDEFINES ON)

set(DTK_HAS_UNIT_TEST ON)
option(ENABLE_COVERAGE "Enable coverage instrumentation" ON)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue: ENABLE_COVERAGE defaults to ON, so configuring with the default options instruments and links the test binary for coverage instead of leaving coverage disabled by default as the change description specifies.

Triggers: When the project is configured without explicitly setting ENABLE_COVERAGE.

Suggested fix: Change the option default to OFF.

Suggested change
option(ENABLE_COVERAGE "Enable coverage instrumentation" ON)
option(ENABLE_COVERAGE "Enable coverage instrumentation" OFF)

Comment thread dconfig-center/tests/test_helper.hpp Outdated
if (m_name)
restore();
if (!m_createdDir.isEmpty())
QDir().rmpath(m_createdDir);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): EnvGuard calls QDir::rmpath() rather than recursively removing the directory contents, so files created below an environment-provided directory prevent cleanup and leave test artifacts behind.

Triggers: When a guarded environment path is newly created and a test writes files or subdirectories beneath it.

Suggested fix: Use QDir(m_createdDir).removeRecursively() for the directory created by the guard.

Suggested change
QDir().rmpath(m_createdDir);
QDir(m_createdDir).removeRecursively();

Comment thread dconfig-center/tests/ut_dconfigserver.cpp Outdated
#include "dconfig_global.h"
#include "test_helper.hpp"

static const QString LocalPrefix = QDir::tempPath() + "/dde-app-services-test-" +

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.

QDir::tempPath(),已经不会再重复了吧,是不是不需要Pid这一级去重,

@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/138c30fc68d7 branch from 02839bc to 43442f4 Compare September 17, 2026 08:10
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/tests/test_helper.hpp": {
            "b": [
                "            qunsetenv(m_name);"
            ]
        },
        "dconfig-center/tests/ut_dconfigconn.cpp": {
            "b": [
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "// Branch: isDefaultValue() returns true for unset key (default)"
            ]
        },
        "dconfig-center/tests/ut_helper.cpp": {
            "b": [
                "        qunsetenv(\"DSG_CONFIG_CONNECTION_DISABLE_DBUS\");"
            ]
        }
    }
}

@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/138c30fc68d7 branch from 43442f4 to 94b9030 Compare September 17, 2026 08:41
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/tests/test_helper.hpp": {
            "b": [
                "            qunsetenv(m_name);"
            ]
        },
        "dconfig-center/tests/ut_dconfigconn.cpp": {
            "b": [
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "// Branch: isDefaultValue() returns true for unset key (default)"
            ]
        },
        "dconfig-center/tests/ut_helper.cpp": {
            "b": [
                "        qunsetenv(\"DSG_CONFIG_CONNECTION_DISABLE_DBUS\");"
            ]
        }
    }
}

@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/138c30fc68d7 branch from 94b9030 to 97fd978 Compare September 17, 2026 09:16
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/tests/test_helper.hpp": {
            "b": [
                "            qunsetenv(m_name);"
            ]
        },
        "dconfig-center/tests/ut_dconfigconn.cpp": {
            "b": [
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "// Branch: isDefaultValue() returns true for unset key (default)"
            ]
        },
        "dconfig-center/tests/ut_helper.cpp": {
            "b": [
                "        qunsetenv(\"DSG_CONFIG_CONNECTION_DISABLE_DBUS\");"
            ]
        }
    }
}

@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/138c30fc68d7 branch from 97fd978 to 02b6e89 Compare September 20, 2026 08:23
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/tests/test_helper.hpp": {
            "b": [
                "            qunsetenv(m_name);"
            ]
        },
        "dconfig-center/tests/ut_dconfigconn.cpp": {
            "b": [
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "// Branch: isDefaultValue() returns true for unset key (default)"
            ]
        },
        "dconfig-center/tests/ut_helper.cpp": {
            "b": [
                "        qunsetenv(\"DSG_CONFIG_CONNECTION_DISABLE_DBUS\");"
            ]
        }
    }
}

1. Add ut_dconfig_global.cpp for global utility function tests
2. Add ut_helper.cpp for cache manager and helper function tests
3. Expand ut_dconfigconn.cpp with 8 new test cases
4. Expand ut_dconfigserver.cpp with 9 new test cases
5. Fix reload_withFileChange test path resolution in ut_dconfigserver
6. Add MetaFileGuard RAII and improve EnvGuard cleanup in test_helper
7. Update CMakeLists.txt with ENABLE_COVERAGE option and new sources

Influence:
1. Verify all 202 test cases pass with 0 failures
2. Check coverage meets line 86.3% and function 96.9% thresholds
3. Validate ENABLE_COVERAGE option defaults to OFF
4. Test reload_withFileChange with correct path resolution

test(dconfig): 补充 dconfig-center 单元测试

1. 新增 ut_dconfig_global.cpp 全局工具函数测试
2. 新增 ut_helper.cpp 缓存管理器及辅助函数测试
3. 扩展 ut_dconfigconn.cpp 新增 8 个测试用例
4. 扩展 ut_dconfigserver.cpp 新增 9 个测试用例
5. 修复 ut_dconfigserver 中 reload_withFileChange 测试路径解析问题
6. 新增 MetaFileGuard RAII 并改进 EnvGuard 清理逻辑
7. 更新 CMakeLists.txt 增加 ENABLE_COVERAGE 选项及新测试源文件

Influence:
1. 验证全部 202 个测试用例通过且无失败
2. 检查覆盖率达标(行 86.3%,函数 96.9%)
3. 验证 ENABLE_COVERAGE 选项默认关闭
4. 测试 reload_withFileChange 路径解析正确性
…target

1. Gate the dconfig-center tests behind BUILD_TESTING via include(CTest)
2. Register the dconfigtest executable with ctest
3. Add coverage target that runs tests and generates the lcov report

Log: Gate dconfig-center tests with BUILD_TESTING and add a coverage target

test(dconfig-center): 以 BUILD_TESTING 门控测试并新增 coverage 目标

1. 通过 include(CTest) 将 dconfig-center 测试纳入 BUILD_TESTING 门控
2. 将 dconfigtest 可执行文件注册到 ctest
3. 新增 coverage 目标,执行测试并生成 lcov 报告

Log: 以 BUILD_TESTING 门控 dconfig-center 测试,并新增 coverage 目标
@MyLeeJiEun
MyLeeJiEun force-pushed the agent/dde/138c30fc68d7 branch from 02b6e89 to b3b4532 Compare September 20, 2026 09:30
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词unset变动
详情
    {
    "unset": {
        "dconfig-center/tests/test_helper.hpp": {
            "b": [
                "            qunsetenv(m_name);"
            ]
        },
        "dconfig-center/tests/ut_dconfigconn.cpp": {
            "b": [
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "        qunsetenv(\"STATE_DIRECTORY\");",
                "// Branch: isDefaultValue() returns true for unset key (default)"
            ]
        },
        "dconfig-center/tests/ut_helper.cpp": {
            "b": [
                "        qunsetenv(\"DSG_CONFIG_CONNECTION_DISABLE_DBUS\");"
            ]
        }
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, 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 Sep 20, 2026

Copy link
Copy Markdown
Contributor

This pr force merged! (status: unstable)

@deepin-bot
deepin-bot Bot merged commit 437ec3a into linuxdeepin:master Sep 20, 2026
14 of 16 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