Skip to content

test: 新增 SheetRenderer/Logger 用例并扩充 DocTabBar/ThreadPool 测试 - #296

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:feat/extend-test-coverage
Jul 21, 2026
Merged

test: 新增 SheetRenderer/Logger 用例并扩充 DocTabBar/ThreadPool 测试#296
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:feat/extend-test-coverage

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

新增 tests/uiframe/ut_sheetrenderer.cpp

  • 覆盖 SheetRenderer 所有公共接口在空文档/无效索引场景下的行为
  • 覆盖 handleOpened 后 getPageCount/getImage/pageHasLable 路径
  • TearDown 中清空 m_pages 避免 renderer 析构时挂起关闭任务

新增 tests/ut_logger.cpp

  • 覆盖 MLogger 的 setRules/appendRules 规则合并与替换逻辑
  • 覆盖析构(含 DConfig 分支)安全退出

扩充 tests/uiframe/ut_doctabbar.cpp

  • 补充 createMimeDataFromTab/canInsertFromMimeData/insertFromMimeData*
  • 补充 onSetCurrentIndex/onTabChanged/onTabCloseRequested(含节流)
  • 补充 onTabReleased/onTabDroped(空目标/单 tab/MoveAction 分支)
  • 补充 resizeEvent

扩充 tests/sidebar/ut_readerimagethreadpoolmanager.cpp

  • 补充 ReadImageTask::run 在无 sheet 时的安全路径
  • 补充 ReaderImageThreadPoolManager 单例、getImageForDocSheet、 onDocProxyDestroyed/onReceiverDestroyed 槽函数

测试总数从 812 提升到 869,全部通过;
reader 模块函数覆盖率从 77.8% 提升到 80.3%。

Summary by Sourcery

Add new unit tests for SheetRenderer and MLogger and expand existing DocTabBar and ReaderImageThreadPoolManager coverage to validate edge cases and safe behavior in empty, invalid, and throttled scenarios.

Tests:

  • Add SheetRenderer tests covering all public APIs for empty documents, invalid indices, page label handling, and handleOpened/loadPageLable flows without real documents.
  • Add MLogger tests for rules management (setRules variations) and safe destruction behavior.
  • Extend DocTabBar tests to cover MIME data drag-and-drop flows, tab index and close handling (including throttling), tab release/drop behaviors under various conditions, and resize events.
  • Extend ReaderImageThreadPoolManager tests to cover ReadImageTask::run without sheet, singleton access, image retrieval for null sheets, and destruction-related signal handlers handling unknown objects.

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds new unit tests for SheetRenderer and MLogger and expands existing DocTabBar and ReaderImageThreadPoolManager tests to cover drag-and-drop, tab lifecycle, thread-pool behavior, and various edge cases (null/invalid inputs, empty documents), including cleanup of internal state to avoid dangling tasks and crashes.

File-Level Changes

Change Details Files
Expanded DocTabBar tests to cover MIME-based drag-and-drop, tab selection/close behavior including throttling, tab release/drop variants, and resize handling.
  • Updated createMimeDataFromTab expectations to validate custom deepin_reader MIME formats instead of absence of URLs.
  • Added tests for canInsertFromMimeData and insertFromMimeData* covering valid/invalid MIME data and drag-enter behavior and ensuring tab count invariants.
  • Added tests for onSetCurrentIndex, onTabChanged, and onTabCloseRequested including invalid indices, signal emission, and close throttling within a 100ms window.
  • Added tests for onTabReleased and onTabDroped for cases such as single tab, null target with multiple tabs (new-window behavior), and MoveAction (tab move-out) while asserting tab count and signal emission.
  • Added a resizeEvent smoke test to ensure DocTabBar handles resize events without error.
tests/uiframe/ut_doctabbar.cpp
Extended ReaderImageThreadPoolManager tests to validate ReadImageTask behavior without an associated sheet and to cover singleton semantics, null input handling, and destruction callbacks.
  • Included DocSheet, QPixmap, and QImage headers needed for new tests.
  • Added UT_ReadImageTask_runNoSheet to ensure run() is a safe no-op when no sheet is set.
  • Introduced UT_ReaderImageThreadPoolManager fixture to reuse singleton instance across tests.
  • Added tests to verify getInstance returns a non-null singleton and that multiple calls return the same instance.
  • Added getImageForDocSheet(nullptr, ...) test asserting it returns a null pixmap and smoke tests for onDocProxyDestroyed/onReceiverDestroyed with unknown QObject instances.
tests/sidebar/ut_readerimagethreadpoolmanager.cpp
Introduced SheetRenderer unit tests to exercise all public APIs under empty-document, invalid-index, and manual handleOpened scenarios, with explicit cleanup of internal pages to avoid dangling close tasks.
  • Created tests/uiframe/ut_sheetrenderer.cpp with a TestSheetRenderer fixture that constructs a DocSheet/SheetRenderer using a sample PDF and owns a DWidget parent.
  • In TearDown, explicitly clears m_tester->m_pages and deletes the parent widget to prevent the renderer destructor from queuing close tasks on deleted Page objects.
  • Added a suite of tests covering opened(), getPageCount(), getImage, getLinkAtPoint, getWords, getAnnotations, getPageSize, getText, search, and all annotation-related methods when no valid page exists, asserting safe defaults (null/empty/false).
  • Added tests for outline(), properties(), save(), saveAs(), pageLableIndex(), pageHasLable(), and pageNum2Lable in no-document or empty-label scenarios to ensure they return safe default values.
  • Added tests that bypass sigOpened connections and manually call handleOpened with constructed PDFPage instances, then assert getPageCount, pageHasLable, pageNum2Lable, and getImage behavior, while ensuring pages are cleared after use.
  • Added a direct loadPageLable() smoke test to verify it is safe when the underlying document is null.
tests/uiframe/ut_sheetrenderer.cpp
Added MLogger unit tests to cover rule setting/merging behavior and safe destruction, including interaction with QLoggingCategory.
  • Introduced tests/ut_logger.cpp with a UT_MLogger fixture that manages MLogger lifetime.
  • Added tests for initial rules() accessibility and semantics-agnostic retrieval to ensure no crashes on first use.
  • Added tests for setRules with a single rule, semicolon-separated rules (ensuring they are converted/handled as multi-line or equivalent), and empty-string rules (resulting in an empty rules set).
  • Added a destruction test that sets logging rules, deletes the MLogger instance, and asserts a clean teardown (no crash).
tests/ut_logger.cpp

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 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/ut_logger.cpp" line_range="60-37" />
<code_context>
+    EXPECT_TRUE(m_tester->rules().isEmpty());
+}
+
+TEST_F(UT_MLogger, testDestruction)
+{
+    MLogger *logger = new MLogger;
+    logger->setRules(QString("test.category=true"));
+    delete logger;
+    SUCCEED();
+}
</code_context>
<issue_to_address>
**issue (testing):** Logger tests don't cover appendRules or the DConfig-related destruction branch mentioned in the PR description.

The tests currently only cover `setRules` and a basic destruction path. To match the PR’s stated coverage, please: (1) add tests for `appendRules` that start with existing rules, append new ones, and assert the resulting rules are merged/overwritten as intended; and (2) add a test that forces the DConfig-specific destruction branch (using configuration stubs or a controlled environment) and verifies it completes without errors and performs the expected cleanup.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/ut_logger.cpp
// Just verify we can call rules() without crashing.
QString r = m_tester->rules();
Q_UNUSED(r);
SUCCEED();

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 (testing): Logger tests don't cover appendRules or the DConfig-related destruction branch mentioned in the PR description.

The tests currently only cover setRules and a basic destruction path. To match the PR’s stated coverage, please: (1) add tests for appendRules that start with existing rules, append new ones, and assert the resulting rules are merged/overwritten as intended; and (2) add a test that forces the DConfig-specific destruction branch (using configuration stubs or a controlled environment) and verifies it completes without errors and performs the expected cleanup.

@pengfeixx
pengfeixx force-pushed the feat/extend-test-coverage branch from 352dafc to d7e7dde Compare July 21, 2026 05:29
@pengfeixx

Copy link
Copy Markdown
Contributor Author

/retest

4 similar comments
@pengfeixx

Copy link
Copy Markdown
Contributor Author

/retest

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/retest

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/retest

@pengfeixx

Copy link
Copy Markdown
Contributor Author

/retest

@pengfeixx
pengfeixx force-pushed the feat/extend-test-coverage branch from d7e7dde to 69f947a Compare July 21, 2026 07:33
New tests/uiframe/ut_sheetrenderer.cpp covers SheetRenderer public
APIs under empty-document/invalid-index scenarios and handleOpened
paths for getPageCount/getImage/pageHasLable.
New tests/ut_logger.cpp covers MLogger setRules/appendRules merging
and safe destruction (including the DConfig branch).
Extended tests/uiframe/ut_doctabbar.cpp adds MIME data, tab close/
change/release/drop, throttle, and resizeEvent coverage.
Extended tests/sidebar/ut_readerimagethreadpoolmanager.cpp adds
ReadImageTask::run null-sheet path and singleton/slot coverage.

新增 ut_sheetrenderer.cpp,覆盖 SheetRenderer 公共接口在空文档与
无效索引下的行为,以及 handleOpened 后的页面查询路径。
新增 ut_logger.cpp,覆盖 MLogger setRules/appendRules 规则合并与
析构(含 DConfig 分支)安全退出。
扩充 ut_doctabbar.cpp,补充 createMimeDataFromTab、
insertFromMimeData*、onTabChanged、onTabCloseRequested 节流、
onTabReleased/onTabDroped 与 resizeEvent 等用例。
扩充 ut_readerimagethreadpoolmanager.cpp,补充 ReadImageTask::run
无 sheet 时的安全路径以及单例与槽函数用例。

Log: 新增 SheetRenderer/Logger 用例并扩充 DocTabBar/ThreadPool 测试
Influence: 单测从 812 增至 869,函数覆盖率从 77.8% 提升至 80.3%。
@pengfeixx
pengfeixx force-pushed the feat/extend-test-coverage branch from 69f947a to 3a38bde Compare July 21, 2026 07:39
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码新增和扩展了多个模块的单元测试,测试覆盖面广且考虑了边界条件,但版权声明格式存在笔误。
逻辑基本正确但因版权声明格式错误及部分断言宽松扣5分。

■ 【详细分析】

  • 1.语法逻辑(基本正确)✓

代码整体编译逻辑正确,但在 ut_readerimagethreadpoolmanager.cpp 中版权声明 2019-2026 ~ 2020 格式存在明显笔误。在 ut_logger.cpptestSetRulesReplacesSemicolon 测试中,断言条件使用 || 连接多个可能的情况,过于宽松,无法精确验证分号替换为换行符的确切逻辑。
潜在问题:版权年份格式不规范可能引起合规检查失败;宽松的断言可能导致回归问题无法被测试捕获。
建议:修正版权声明为 2019-2020 Uniontech Software Technology Co.,Ltd. 或符合项目规范的格式;收紧 testSetRulesReplacesSemicolon 的断言,明确期望的字符串格式。

  • 2.代码质量(良好)✓

测试代码结构清晰,遵循了 GTest 的 TEST_F 夹具模式,命名规范统一。新增的测试用例覆盖了空指针、无效索引等常见边界条件,并在复杂的 ut_sheetrenderer.cpp 中添加了注释说明清理资源的原因。
潜在问题:部分测试用例中存在重复的初始化代码,如多次创建 QMutexDPdfPagePDFPage
建议:可以将重复的对象创建逻辑提取到辅助函数或 SetUp 中,减少代码冗余。

  • 3.代码性能(无性能问题)✓

单元测试代码执行轻量,没有引入复杂的算法或高频轮询,资源在 TearDown 中得到了妥善释放。
建议:保持当前的资源管理方式,确保测试用例相互独立且快速执行。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次代码为单元测试代码,不涉及外部输入处理、网络通信或敏感数据操作,不存在安全风险。

  • 建议:无需额外安全修复。

■ 【改进建议代码示例】

// 修复 ut_readerimagethreadpoolmanager.cpp 版权声明
-// Copyright (C) 2019-2026 ~ 2020 Uniontech Software Technology Co.,Ltd.
+// Copyright (C) 2019-2020 Uniontech Software Technology Co.,Ltd.

// 优化 ut_logger.cpp 中的断言逻辑
 TEST_F(UT_MLogger, testSetRulesReplacesSemicolon)
 {
     m_tester->setRules(QString("a.b=true;c.d=false"));
-    EXPECT_TRUE(m_tester->rules().contains(QString("a.b=true\n c.d=false")) ||
-                m_tester->rules().contains(QString("a.b=true\nc.d=false")) ||
-                m_tester->rules().contains(QString("a.b=true")));
+    // 假设 setRules 会将 ';' 替换为 '\n'
+    EXPECT_TRUE(m_tester->rules().contains(QString("a.b=true\nc.d=false")));
 }

@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 57c4e45 into linuxdeepin:master Jul 21, 2026
12 checks passed
@pengfeixx
pengfeixx deleted the feat/extend-test-coverage branch July 21, 2026 08:08
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