Skip to content

test: add unit tests for 8 groups of lambda callbacks - #291

Merged
wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/ut-bot/759de9225011
Nov 16, 2026
Merged

wyu71 merged 1 commit into
linuxdeepin:masterfrom
wyu71:agent/ut-bot/759de9225011

Conversation

@wyu71

@wyu71 wyu71 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Cover 8 groups of previously 0-coverage lambda callbacks and interfaces:

  1. CTextTool font widget lambdas (font family/weight/size)
  2. FileSelectDialog/TabBarWgt SizeMode lambdas
  3. PageView context menu, text menu, and paste lambdas
  4. TopTilte initMenu export/print/saveAs lambdas
  5. Application execDraw/destructor/waitShowThenLoad
  6. MainWindow initConnection lambdas
  7. CGroupButtonWgt/CAttriBaseOverallWgt lambdas
  8. PickColorWidget constructor lambdas

Issue: V-8281
Log: add unit tests for 8 groups of lambda callbacks and interfaces

Summary by Sourcery

Expand lambda-callback unit coverage across the application and harden queued focus handling against closed pages.

Bug Fixes:

  • Prevent queued focus restoration from dereferencing a page or view that was closed before the callback ran.

Tests:

  • Add unit coverage for font controls, file and tab widgets, page and text menus, title-bar actions, application callbacks, main-window connections, attribute widgets, and color-picker callbacks.
  • Improve test-suite isolation by cleaning up accumulated pages, restoring hidden boards, and logging Qt warnings with the active test name.

Chores:

  • Add diagnostic instrumentation for investigating page grouping and shortcut behavior in the page-scene test.

@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026

Copy link
Copy Markdown

Sorry @wyu71, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 12 minutes by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Tests

Add callback tests for the application, attribute widgets, central widget, text tool, main window, page-view menus, color picker, and title-bar actions.

  • tests/test_application_lambdas.cpp L1-292
  • tests/test_cattributeitemwidget_lambdas.cpp L1-184
  • tests/test_ccentralwidget_lambdas.cpp L1-153
  • tests/test_ctexttool_fontlambdas.cpp L1-350
  • tests/test_mainwindow_lambdas.cpp L1-216
  • tests/test_pageview_menulambdas.cpp L1-500
  • tests/test_pickcolorwidget_lambdas.cpp L1-247
  • tests/test_toptilte_menulambdas.cpp L1-201

Revise zoom-combo-box tests to exercise implemented constructor, menu-flat, and item-icon behavior instead of the unimplemented arrow-icon API.

  • tests/test_dzoommenucombobox_funcs2.cpp L5-16, L23-45, L50-83

Update existing tests and shared helpers to preserve clipboard state, avoid unsafe tool destruction, and clean up page and scene state reliably.

  • tests/test_cgraphicstextitem_edit.cpp L40-43, L49-56
  • tests/test_ctexttool_ext2.cpp L33-59, L65-77 (+12 small edits)
  • tests/test_helpers.h L12-16, L57-82
  • tests/test_mainwindow_misc.cpp L100-109
  • tests/test_pagescene.cpp L21, L209-214
  • tests/test_qtestmain.cpp L193-268
  • tests/test_zerocoverage_ext.cpp L45-53, L98-104, L255-277 (+5 small edits)

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

@wyu71
wyu71 force-pushed the agent/ut-bot/759de9225011 branch 10 times, most recently from bcb5885 to 36fe005 Compare November 16, 2026 05:22
Cover 8 groups of previously 0-coverage lambda callbacks and interfaces:
1. CTextTool font widget lambdas (font family/weight/size)
2. FileSelectDialog/TabBarWgt SizeMode lambdas
3. PageView context menu, text menu, and paste lambdas
4. TopTilte initMenu export/print/saveAs lambdas
5. Application execDraw/destructor/waitShowThenLoad
6. MainWindow initConnection lambdas
7. CGroupButtonWgt/CAttriBaseOverallWgt lambdas
8. PickColorWidget constructor lambdas

Issue: V-8281
Log: add unit tests for 8 groups of lambda callbacks and interfaces
@wyu71
wyu71 force-pushed the agent/ut-bot/759de9225011 branch from 36fe005 to 9fecfb8 Compare November 16, 2026 05:52
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 90 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 deepin-draw 项目新增 8 组 lambda 回调的单元测试,涵盖 Application、 CGroupButtonWgt、CAttriBaseOverallWgt、CTextTool、MainWindow、PageView 菜单、 PickColorWidget、TopTilte 等模块,同时对已有测试文件进行了加固(剪切板状态保存、 QStackedWidget 直接索引页面、PageJanitor 自动关闭修复等)。代码注释极为详尽, 测试策略清晰,无安全漏洞。存在少量测试隔离性(sizeMode 未保存/恢复)和代码 重复(releaseTextTool 在两个文件中重复定义)等轻微问题,但不影响整体质量。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['在 test_qtestmain.cpp 的 sendPostedEvents 调用前增加 currentPage() 非空判断,仅在有有效当前页面时才排空事件队列']


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['将 releaseTextTool 提取到 test_helpers.h 中,消除跨文件重复', '在 TabBarWgt SizeMode 测试中保存 DGuiApplicationHelper::instance()->sizeMode() 原始值并在测试结束后恢复', 'ClipBoardGuard 改用 std::unique_ptr 管理生命周期,在析构时 release() 交给 QClipboard', '在 D-Bus 相关测试前添加 sessionBus().isConnected() 检查并 GTEST_SKIP']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['将 QStackedWidget 查找逻辑提升到 while 循环之前,循环内直接使用缓存的指针']


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// test_helpers.h — 提取公共 releaseTextTool 并修复 sizeMode 保存/恢复

// 在 test_helpers.h 中添加:
#ifdef ENABLE_FSANITIZE
#include <sanitizer/lsan_interface.h>
#endif

inline void releaseTextTool(CTextTool *tool)
{
#ifdef ENABLE_FSANITIZE
    if (tool != nullptr)
        __lsan_ignore_object(tool);
#else
    Q_UNUSED(tool)
#endif
}

// test_ccentralwidget_lambdas.cpp — 保存/恢复 sizeMode:
TEST(TabBarWgtSizeModeLambdaTest, SizeModeChangedResizesAddButton)
{
    DrawBoard *board = drawApp->topMainWindow()->drawBoard();
    ASSERT_NE(board, nullptr);

    TabBarWgt bar(board);
    auto *addBtn = bar.findChild<DIconButton *>("AddButton");
    if (addBtn == nullptr) {
        GTEST_SKIP() << "DTabBar build exposes no AddButton child";
    }

    auto *helper = DGuiApplicationHelper::instance();
    const auto origMode = helper->sizeMode();  // 保存原始模式

    emit helper->sizeModeChanged(DGuiApplicationHelper::CompactMode);
    qApp->processEvents();
    EXPECT_EQ(addBtn->maximumWidth(), kAddBtnSizeCompact);
    EXPECT_EQ(addBtn->maximumHeight(), kAddBtnSizeCompact);

    emit helper->sizeModeChanged(DGuiApplicationHelper::NormalMode);
    qApp->processEvents();
    EXPECT_EQ(addBtn->maximumWidth(), kAddBtnSizeNormal);
    EXPECT_EQ(addBtn->maximumHeight(), kAddBtnSizeNormal);

    helper->setSizeMode(origMode);  // 恢复原始模式
    qApp->processEvents();
}

本报告由 AI 代码审查工具自动生成

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@wyu71
wyu71 merged commit 5b1171d into linuxdeepin:master Nov 16, 2026
14 checks passed
@wyu71
wyu71 deleted the agent/ut-bot/759de9225011 branch November 16, 2026 06:30
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