test: add XPS adapter and TitleMenu/Application test cases#299
Conversation
|
Warning
详情 {
"export": {
"tests/document/ut_xpsmodel.cpp": {
"b": [
" QString target = tmpDir.path() + \"/export.pdf\";"
]
}
}
} |
Reviewer's GuideAdds 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
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- The updated copyright headers like
2019-2026 ~ 2020look 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
/tmppaths for invalid files; to avoid platform-specific assumptions, consider usingQDir::tempPath()orQTemporaryDireven 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| { | ||
| EXPECT_NE(dApp, nullptr); | ||
| dApp->emitSheetChanged(); | ||
| SUCCEED(); |
There was a problem hiding this comment.
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.
| TEST_F(TestTitleMenu, testOnActionTriggeredNoSender) | ||
| { | ||
| m_tester->onActionTriggered(); | ||
| SUCCEED(); |
There was a problem hiding this comment.
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%。
a92dbaf to
51948a4
Compare
|
Warning
详情 {
"export": {
"tests/document/ut_xpsmodel.cpp": {
"b": [
" QString target = tmpDir.path() + \"/export.pdf\";"
]
}
}
} |
deepin pr auto review★ 总体评分:95分■ 【总体评价】
■ 【详细分析】
■ 【改进建议代码示例】 // 修正 ut_xpsmodel.cpp 和 ut_titlemenu.cpp 中的版权声明
- // Copyright (C) 2026 ~ 2020 UnionTech Software Technology Co.,Ltd.
+ // Copyright (C) 2019-2026 UnionTech Software Technology Co.,Ltd. |
|
Warning
详情 {
"export": {
"tests/document/ut_xpsmodel.cpp": {
"b": [
" QString target = tmpDir.path() + \"/export.pdf\";"
]
}
}
} |
2 similar comments
|
Warning
详情 {
"export": {
"tests/document/ut_xpsmodel.cpp": {
"b": [
" QString target = tmpDir.path() + \"/export.pdf\";"
]
}
}
} |
|
Warning
详情 {
"export": {
"tests/document/ut_xpsmodel.cpp": {
"b": [
" QString target = tmpDir.path() + \"/export.pdf\";"
]
}
}
} |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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:
Enhancements:
Tests: