Skip to content

test(modules): add unit tests for dbus, theme, widgets and startmanager - #506

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/ut-modules-new
Aug 3, 2026
Merged

test(modules): add unit tests for dbus, theme, widgets and startmanager#506
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:test/ut-modules-new

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Add tests for DBus interfaces, ThemeListModel, ThemeListView, ThemePanel, PathSettingWgt and StartManager lambda functions.

Log: 新增dbus、theme、widgets和startmanager模块的单元测试
Influence: 覆盖DBus接口、主题面板等未覆盖函数

Summary by Sourcery

Add unit tests to improve coverage of DBus interfaces, theme components, widget behavior, and StartManager lambdas.

Tests:

  • Introduce DBus unit tests covering Dock and DockEntry interfaces, DockRect, WindowInfo, and WindowList meta-type registration and marshalling.
  • Add tests for StartManager translation, drag state handling, file-open timers, and window close timers via lambda coverage.
  • Add ThemeListModel, ThemePanel, and ThemeListView tests to exercise theme loading, painting, layout, and animation-triggering code paths.
  • Add PathSettingWgt tests for path editing, selection mode handling, file dialog cancellation, and button group signal lambdas.

@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 @pengfeixx, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@sourcery-ai

sourcery-ai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds new GoogleTest-based unit tests covering DBus dock interfaces and related meta-types, theme model/view/panel behavior (including lambdas and animations), PathSettingWgt UI logic, and StartManager translation, drag, and QTimer-based lambdas to increase coverage of previously untested code paths.

File-Level Changes

Change Details Files
Introduce unit tests for DockRect, DBus dock interfaces, and window-related meta-types to exercise constructors, properties, methods, and DBus marshalling helpers.
  • Add ut_dbus.cpp to construct and destroy ComDeepinDdeDaemonDockInterface and ComDeepinDdeDaemonDockEntryInterface instances and assert their staticInterfaceName values
  • Invoke all major DBus properties and methods on dock and entry interfaces without asserting results, ensuring code paths and meta-type registrations are executed
  • Cover DockRect default construction, conversion to QRect, debug/DBus stream operators, and registerDockRectMetaType behavior
  • Exercise WindowInfo equality operator, debug/DBus operators, and registration helpers for WindowInfo, WindowInfoMap, and WindowList meta-types
tests/src/dbus/ut_dbus.cpp
Add tests for StartManager singletons and internal lambdas triggered by drag signals and QTimer::singleShot callbacks.
  • Introduce helper to reset StartManager::m_instance before each test to avoid dangling singleton issues across tests
  • Test StartManager::tr overloads to ensure translation behavior is exercised
  • Use QMetaObject::invokeMethod to trigger tabbar dragStarted/dragEnd lambdas in createWindow and verify m_bIsTagDragging flag updates
  • Stub StartManager and Window methods to drive openFilesInTab into its QTimer lambda path and confirm windows get created
  • Stub QDir::entryList, QString::contains, and QList<Window *>::isEmpty to drive slotCloseWindow through its singleShot lambda path
tests/src/ut_startmanager_lambdas.cpp
Extend theme module test coverage for ThemeListModel initialization, data roles, sorting, and ThemePanel painting/animation-related behavior.
  • Create temporary theme JSON files and stub QDir::entryInfoList to feed deterministic data into ThemeListModel::initThemes and its sorting lambda
  • Verify ThemeListModel frame color setters, destructor, role-based data() behavior (including default cases), and rowCount
  • Subclass ThemePanel to expose paintEvent and test painting with a synthetic QPaintEvent
  • Test ThemePanel::setBackground to switch between dark/light frame colors and setFrameColor propagation into the underlying ThemeListModel
  • Exercise ThemePanel::hide, popup, and constructor-connected requestCurrentIndex lambda without waiting on animations to avoid event-loop side effects
tests/src/thememodule/ut_themelistmodel.cpp
tests/src/thememodule/ut_themepanel.cpp
Add tests for ThemeListView scrollbar adjustment logic in both visible and non-visible states.
  • Instantiate ThemeListView without a model to cover adjustScrollbarMargins early-return path when not visible
  • Attach a ThemeListModel, show and resize the view, and call adjustScrollbarMargins to exercise layout adjustment path without using QTest::qWait
tests/src/thememodule/ut_themelistview.cpp
Add GoogleTest fixture-based tests for PathSettingWgt text, button, and radio-box handling, including dialog cancellation and signal-connected lambdas.
  • Define a test fixture that constructs and destroys a PathSettingWgt per test
  • Verify setEditText truncates or formats long paths into the custom line edit
  • Test onBoxClicked behavior for CurFileBox, LastOptBox, CustomBox, and default branch, checking custom button enabled state
  • Stub QFileDialog::exec to simulate dialog rejection in onBtnClicked and ensure the early-return path is covered
  • Simulate clicking the custom radio button to trigger the QButtonGroup::buttonClicked lambda and verify that CustomBox is selected and the custom button is enabled
tests/src/widgets/ut_pathsettintwgt.cpp
tests/src/widgets/ut_pathsettintwgt.h

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

@pengfeixx
pengfeixx force-pushed the test/ut-modules-new branch 2 times, most recently from ad16a10 to 63af614 Compare August 3, 2026 06:00
Add tests for DBus interfaces, ThemeListModel, ThemeListView,
ThemePanel, PathSettingWgt and StartManager lambda functions.

Log: 新增dbus、theme、widgets和startmanager模块的单元测试
Influence: 覆盖DBus接口、主题面板等未覆盖函数
@pengfeixx
pengfeixx force-pushed the test/ut-modules-new branch from 63af614 to 5821ba0 Compare August 3, 2026 06:03
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:70分

■ 【总体评价】

代码实现了对DBus接口、主题模块和启动管理器的单元测试,但存在内存泄漏和资源未释放问题。
逻辑基本覆盖目标函数,但因内存泄漏和文件名拼写错误等质量问题扣30分。

■ 【详细分析】

  • 1.语法逻辑(存在错误)✕

ut_startmanager_lambdas.cppfreshStartManager() 函数中,直接将 StartManager::m_instance 置空并创建新实例,导致原实例内存泄漏;ut_themelistmodel.cppprepareTempThemes 创建临时文件后未在测试结束时清理。
潜在问题:内存泄漏导致测试进程内存持续增长;临时文件残留可能影响后续测试或占用磁盘空间。
建议:在 freshStartManager() 中释放原有实例;在 data_and_initThemes 测试用例的末尾添加临时文件清理逻辑。

  • 2.代码质量(一般)✕

文件名 ut_pathsettintwgt.cpput_pathsettintwgt.h 存在拼写错误,应为 setting 而非 settintfreshStartManager() 采用强制重置单例的 hack 方式,可维护性较差。
潜在问题:拼写错误降低代码可读性;hack 方式可能掩盖真实的单例管理缺陷。
建议:修正文件名拼写;考虑使用更安全的方式重置单例,如提供专门的测试接口或使用智能指针管理生命周期。

  • 3.代码性能(存在性能问题)✕

freshStartManager() 在每个测试用例中被调用,不断创建新实例且不释放旧实例,导致内存占用线性增长,影响测试套件的整体执行性能。
潜在问题:在大型测试套件中可能因内存耗尽导致测试崩溃。
建议:复用单例实例或在测试结束后正确释放资源。

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
测试代码主要面向内部逻辑验证,未涉及外部输入处理和敏感操作,不存在安全漏洞风险。

  • 建议:无需安全修复。

■ 【改进建议代码示例】

// 修复 ut_startmanager_lambdas.cpp 中的内存泄漏
static StartManager *freshStartManager()
{
    if (StartManager::m_instance != nullptr) {
        // 避免使用 deleteLater 导致的事件循环问题,直接 delete
        delete StartManager::m_instance;
        StartManager::m_instance = nullptr;
    }
    return StartManager::instance();
}

// 修复 ut_themelistmodel.cpp 中的临时文件清理
TEST(UT_ThemeListModel, data_and_initThemes)
{
    QStringList paths = prepareTempThemes("de_themes_ut_model");
    g_testThemesList.clear();
    g_testThemesList << QFileInfo(paths[0]) << QFileInfo(paths[1]);

    Stub s;
    s.set((QFileInfoList(QDir::*)(QDir::Filters, QDir::SortFlags) const) ADDR(QDir, entryInfoList),
          entryInfoListThemesStub);

    ThemeListModel *model = new ThemeListModel;
    // ... 原有测试逻辑 ...
    
    delete model;
    
    // 清理临时文件
    for (const QString &path : paths) {
        QFile::remove(path);
    }
    QDir().rmdir(QDir::tempPath() + "/de_themes_ut_model");
}

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, pengfeixx

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

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot
deepin-bot Bot merged commit 0097692 into linuxdeepin:master Aug 3, 2026
20 checks passed
@pengfeixx
pengfeixx deleted the test/ut-modules-new branch August 3, 2026 06:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants