Skip to content

test: add XPS adapter and TitleMenu/Application test cases#299

Merged
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:feat/improve-coverage-2
Jul 21, 2026
Merged

test: add XPS adapter and TitleMenu/Application test cases#299
pengfeixx merged 1 commit into
linuxdeepin:masterfrom
pengfeixx:feat/improve-coverage-2

Conversation

@pengfeixx

@pengfeixx pengfeixx commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

New tests/document/ut_xpsmodel.cpp loads the real TUNAS-XPS.xps sample and exercises XpsDocumentAdapter load/page/render/saveAs (xps+pdf), outline/properties, and XpsTextExtractor words/runs. New tests/uiframe/ut_titlemenu.cpp covers disableAllAction, onCurSheetChanged(null), and onActionTriggered signal path. Expanded tests/ut_application.cpp (previously empty) to cover Application::notify for KeyPress(Return/Enter/other), FocusIn, ZOrderChange, WindowActivate, and other events.

New tests/files/normal.xps is the real XPS sample registered in files.qrc. SearchResDelegate header bumped to 2019-2026.

新增 ut_xpsmodel.cpp,基于真实 XPS 样本文件覆盖
XpsDocumentAdapter 加载/分页/渲染/另存(XPS+PDF)、大纲、属性,
以及 XpsTextExtractor 文字与文本段提取。
新增 ut_titlemenu.cpp,覆盖 disableAllAction、
onCurSheetChanged(nullptr)、onActionTriggered 信号链路。 扩充 ut_application.cpp(原为空),覆盖 Application::notify 在 Return/Enter/普通按键、FocusIn、ZOrderChange、WindowActivate 等 事件下的处理路径。

Log: 新增 XPS 适配器与 TitleMenu/Application 用例
Influence: 单测从 869 增至 911,函数覆盖率从 80.3% 提升至 88.5%。

Summary by Sourcery

Add unit tests for XPS document handling, TitleMenu interactions, and Application event notification to improve coverage of document rendering and UI behaviors.

New Features:

  • Introduce XPS adapter tests covering document loading, page access, rendering, save-as behavior, outlines, properties, and text extraction.
  • Add TitleMenu tests validating action disabling, behavior when the current sheet is null, and action-trigger signal emission.

Enhancements:

  • Expand Application tests to cover notify() behavior for key, focus, z-order, window activation, and other events.
  • Register a real XPS sample file in the test resources for exercising XPS-related functionality.
  • Update SearchResDelegate test copyright years to 2019-2026.

Tests:

  • Add comprehensive tests for XpsDocumentAdapter, XpsTextExtractor, and DocumentFactory XPS handling.
  • Add unit tests for TitleMenu signals and action state management.
  • Extend Application unit tests to cover key press, focus, window, and miscellaneous event handling paths.

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "tests/document/ut_xpsmodel.cpp": {
            "b": [
                "    QString target = tmpDir.path() + \"/export.pdf\";"
            ]
        }
    }
}

@sourcery-ai

sourcery-ai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds new unit tests for the XPS document adapter and text extractor, TitleMenu behavior, and Application::notify event handling, introduces a real XPS sample into the test resources, and updates a copyright header year range.

File-Level Changes

Change Details Files
Add comprehensive tests for XpsDocumentAdapter, XpsTextExtractor, and XPS handling via DocumentFactory using a real XPS sample file.
  • Introduce helper functions to resolve the normal.xps path via UTSOURCEDIR or application directory and detect its presence.
  • Add TestXpsDocumentAdapter fixture to load an XPS document once per test and validate pageCount, page retrieval, save/saveAs behavior for XPS/PDF, outline and properties access, pageSize and renderPage variants, and page adapter APIs (sizeF, render, text, search, words, annotations).
  • Add negative-path tests for XpsDocumentAdapter::loadDocument with empty and non-existent paths.
  • Add TestXpsTextExtractor fixture and tests to exercise extractWords/extractTextRuns for valid, invalid page indices and invalid files.
  • Add DocumentFactory XPS tests to ensure correct document creation and error reporting for existing and non-existent XPS paths.
tests/document/ut_xpsmodel.cpp
tests/files.qrc
tests/files/normal.xps
Add TitleMenu unit tests to cover action disabling, current sheet changes with null, and action-triggered signal emission.
  • Create TestTitleMenu fixture to allocate and cleanup a TitleMenu instance per test and disconnect existing signals.
  • Add tests verifying disableAllAction and onCurSheetChanged(nullptr) disable specific actions (Save, Save as, Display in file manager, Magnifer, Search, Print) discovered via findChildren().
  • Add tests to exercise onActionTriggered when there is no sender and when a valid QAction (New window) is triggered, asserting sigActionTriggered(QString) is emitted with the action name.
tests/uiframe/ut_titlemenu.cpp
Expand Application unit tests to exercise emitSheetChanged and notify() handling for various Qt events.
  • Include Application, DocSheet, and MainWindow headers plus necessary Qt event headers for testing.
  • Add tests that call emitSheetChanged safely on the global application instance.
  • Add notify() tests for KeyPress events (Return, Enter, other key) validating acceptance for Return/Enter and basic invocation for others.
  • Add notify() tests for FocusIn, ZOrderChange, WindowActivate, and a generic None event on QWidget/QObject instances to cover different event paths.
tests/ut_application.cpp
Update copyright year range in SearchResDelegate unit test header.
  • Adjust the copyright comment from 2019 ~ 2020 to 2019-2026 ~ 2020 while preserving existing SPDX metadata.
tests/sidebar/ut_searchresdelegate.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 2 issues, and left some high level feedback:

  • The updated copyright headers like 2019-2026 ~ 2020 look malformed; please double-check and normalize the year ranges to match the project’s standard format.
  • The TitleMenu tests rely on hardcoded QAction objectName strings (e.g., "Save", "New window"), which makes them brittle to UI text changes; consider deriving these from existing constants or verifying their existence before assertions to avoid silent breakage.
  • In the XpsDocumentAdapter and XpsTextExtractor tests you hardcode /tmp paths for invalid files; to avoid platform-specific assumptions, consider using QDir::tempPath() or QTemporaryDir even for negative cases.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The updated copyright headers like `2019-2026 ~ 2020` look malformed; please double-check and normalize the year ranges to match the project’s standard format.
- The TitleMenu tests rely on hardcoded QAction objectName strings (e.g., "Save", "New window"), which makes them brittle to UI text changes; consider deriving these from existing constants or verifying their existence before assertions to avoid silent breakage.
- In the XpsDocumentAdapter and XpsTextExtractor tests you hardcode `/tmp` paths for invalid files; to avoid platform-specific assumptions, consider using `QDir::tempPath()` or `QTemporaryDir` even for negative cases.

## Individual Comments

### Comment 1
<location path="tests/ut_application.cpp" line_range="39-20" />
<code_context>
+    EXPECT_TRUE(event.isAccepted());
+}
+
+TEST(UT_Application, UT_Application_notifyKeyPressOther)
+{
+    QPushButton btn;
+    QKeyEvent event(QEvent::KeyPress, Qt::Key_A, Qt::NoModifier);
+    dApp->notify(&btn, &event);
+    SUCCEED();
+}
+
</code_context>
<issue_to_address>
**question (testing):** Clarify and assert the expected behavior for non-Return/Enter key presses

For other keys, this test only calls `notify` and `SUCCEED()` and never checks `event.isAccepted()`. Please assert the expected behavior (e.g. `EXPECT_FALSE(event.isAccepted())` if non-special keys should not be handled, or `EXPECT_TRUE` if they should) so the test clearly documents and enforces that contract.
</issue_to_address>

### Comment 2
<location path="tests/uiframe/ut_titlemenu.cpp" line_range="72-75" />
<code_context>
+    }
+}
+
+TEST_F(TestTitleMenu, testOnActionTriggeredNoSender)
+{
+    m_tester->onActionTriggered();
+    SUCCEED();
+}
+
</code_context>
<issue_to_address>
**suggestion (testing):** Consider asserting that no signal is emitted when onActionTriggered is called without a sender

`testOnActionTriggeredNoSender` currently only calls `onActionTriggered()` and `SUCCEED()`. To verify the expected behavior, add a `QSignalSpy` on `sigActionTriggered` and assert that its count stays at zero when there is no `QAction` sender. This makes the edge-case behavior explicit and protects against future regressions.

Suggested implementation:

```cpp
#include "TitleMenu.h"
#include "DocSheet.h"
#include "HandleMenu.h"
#include "ut_defines.h"
#include "stub.h"

#include <DMenu>
#include <DWidget>
#include <QSignalSpy>

#include <gtest/gtest.h>

```

```cpp
TEST_F(TestTitleMenu, testOnActionTriggeredNoSender)
{
    QSignalSpy spy(m_tester, &TitleMenu::sigActionTriggered);

    m_tester->onActionTriggered();

    EXPECT_EQ(spy.count(), 0);
}

```
</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_application.cpp
{
EXPECT_NE(dApp, nullptr);
dApp->emitSheetChanged();
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.

question (testing): Clarify and assert the expected behavior for non-Return/Enter key presses

For other keys, this test only calls notify and SUCCEED() and never checks event.isAccepted(). Please assert the expected behavior (e.g. EXPECT_FALSE(event.isAccepted()) if non-special keys should not be handled, or EXPECT_TRUE if they should) so the test clearly documents and enforces that contract.

Comment on lines +72 to +75
TEST_F(TestTitleMenu, testOnActionTriggeredNoSender)
{
m_tester->onActionTriggered();
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.

suggestion (testing): Consider asserting that no signal is emitted when onActionTriggered is called without a sender

testOnActionTriggeredNoSender currently only calls onActionTriggered() and SUCCEED(). To verify the expected behavior, add a QSignalSpy on sigActionTriggered and assert that its count stays at zero when there is no QAction sender. This makes the edge-case behavior explicit and protects against future regressions.

Suggested implementation:

#include "TitleMenu.h"
#include "DocSheet.h"
#include "HandleMenu.h"
#include "ut_defines.h"
#include "stub.h"

#include <DMenu>
#include <DWidget>
#include <QSignalSpy>

#include <gtest/gtest.h>
TEST_F(TestTitleMenu, testOnActionTriggeredNoSender)
{
    QSignalSpy spy(m_tester, &TitleMenu::sigActionTriggered);

    m_tester->onActionTriggered();

    EXPECT_EQ(spy.count(), 0);
}

New tests/document/ut_xpsmodel.cpp loads the real TUNAS-XPS.xps
sample and exercises XpsDocumentAdapter load/page/render/saveAs
(xps+pdf), outline/properties, and XpsTextExtractor words/runs.
New tests/uiframe/ut_titlemenu.cpp covers disableAllAction,
onCurSheetChanged(null), and onActionTriggered signal path.
Expanded tests/ut_application.cpp (previously empty) to cover
Application::notify for KeyPress(Return/Enter/other), FocusIn,
ZOrderChange, WindowActivate, and other events.

New tests/files/normal.xps is the real XPS sample registered in
files.qrc. SearchResDelegate header bumped to 2019-2026.

新增 ut_xpsmodel.cpp,基于真实 XPS 样本文件覆盖
XpsDocumentAdapter 加载/分页/渲染/另存(XPS+PDF)、大纲、属性,
以及 XpsTextExtractor 文字与文本段提取。
新增 ut_titlemenu.cpp,覆盖 disableAllAction、
onCurSheetChanged(nullptr)、onActionTriggered 信号链路。
扩充 ut_application.cpp(原为空),覆盖 Application::notify 在
Return/Enter/普通按键、FocusIn、ZOrderChange、WindowActivate 等
事件下的处理路径。

Log: 新增 XPS 适配器与 TitleMenu/Application 用例
Influence: 单测从 869 增至 911,函数覆盖率从 80.3% 提升至 88.5%。
@pengfeixx
pengfeixx force-pushed the feat/improve-coverage-2 branch from a92dbaf to 51948a4 Compare July 21, 2026 09:07
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "tests/document/ut_xpsmodel.cpp": {
            "b": [
                "    QString target = tmpDir.path() + \"/export.pdf\";"
            ]
        }
    }
}

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码新增了针对XPS文档适配器、标题菜单和应用通知机制的单元测试,覆盖了核心接口与边界场景
测试逻辑完整且规范,无安全漏洞,仅在个别测试用例的断言强度及版权声明格式上可进一步优化

■ 【详细分析】

  • 1.语法逻辑(完全正确)✓

代码使用GTest框架编写,测试夹具SetUp/TearDown逻辑正确,智能指针管理对象生命周期无内存泄漏。ut_xpsmodel.cpp中对越界索引和空路径的测试断言准确,ut_application.cpp中对各种事件类型的分发测试覆盖全面。
潜在问题:ut_xpsmodel.cpp中部分测试如pageAdapterTextpageAdapterWordsAndAnnotations仅调用了接口并使用SUCCEED(),未对返回值进行实质断言。
建议:对于可能为空的返回值,若接口契约明确,可增加对特定状态的断言;若确实无法确定,保持现状亦可。

  • 2.代码质量(优秀)✓

测试命名清晰,遵循了统一的命名规范。ut_xpsmodel.cpp中提供了文件不存在的跳过机制(GTEST_SKIP),保证了CI环境下的稳定性,代码注释清晰易懂。
潜在问题:新增文件的版权声明年份格式存在逻辑倒置,如2026 ~ 2020
建议:修正版权声明中的年份范围,统一改为2019-2026 UnionTech格式。

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

单元测试代码不涉及复杂算法或高频调用,资源占用低,QTemporaryDir的使用确保了测试文件的自动清理。
潜在问题:无
建议:无需优化。

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

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次新增的测试代码仅调用内部接口并验证返回值,无外部输入处理、无敏感信息泄露、无网络通信,不存在安全风险。

  • 建议:保持现有安全编码规范。

■ 【改进建议代码示例】

// 修正 ut_xpsmodel.cpp 和 ut_titlemenu.cpp 中的版权声明
- // Copyright (C) 2026 ~ 2020 UnionTech Software Technology Co.,Ltd.
+ // Copyright (C) 2019-2026 UnionTech Software Technology Co.,Ltd.

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "tests/document/ut_xpsmodel.cpp": {
            "b": [
                "    QString target = tmpDir.path() + \"/export.pdf\";"
            ]
        }
    }
}

2 similar comments
@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "tests/document/ut_xpsmodel.cpp": {
            "b": [
                "    QString target = tmpDir.path() + \"/export.pdf\";"
            ]
        }
    }
}

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "tests/document/ut_xpsmodel.cpp": {
            "b": [
                "    QString target = tmpDir.path() + \"/export.pdf\";"
            ]
        }
    }
}

@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
pengfeixx merged commit b2df4e3 into linuxdeepin:master Jul 21, 2026
11 of 15 checks passed
@pengfeixx
pengfeixx deleted the feat/improve-coverage-2 branch July 21, 2026 09:37
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