Repository navigation
test: add unit tests for 8 groups of lambda callbacks - #291
Conversation
Reviewer's GuideTestsAdd callback tests for the application, attribute widgets, central widget, text tool, main window, page-view menus, color picker, and title-bar actions.
Revise zoom-combo-box tests to exercise implemented constructor, menu-flat, and item-icon behavior instead of the unimplemented arrow-icon API.
Update existing tests and shared helpers to preserve clipboard state, avoid unsafe tool destruction, and clean up page and scene state reliably.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
bcb5885 to
36fe005
Compare
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
36fe005 to
9fecfb8
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析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个安全漏洞 ✅ 通过
安全漏洞详情: 建议: [] 💡 改进建议代码示例// 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 代码审查工具自动生成 |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Cover 8 groups of previously 0-coverage lambda callbacks and interfaces:
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:
Tests:
Chores: