Repository navigation
test: add unit tests for 0-coverage - #297
Conversation
Reviewer's GuideTestsAdd wheel-event tests for CSpinBox focus and value behavior.
Exercise isRunning lock behavior, including contention created by a forked child.
Add tool lifecycle and destructor coverage for DrawToolManager and IDrawTool.
Add destructor-path tests for service objects and their QObject parent ownership.
Exercise graphics-item, page, and frame cleanup paths, including the harness-owned MainWindow.
Test that invalid plugin paths cause loadToolPlugin to return null.
Trigger showDirChoseDialog and close its modal dialog with a timer to check it does not crash.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 8 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="tests/test_main_isrunning.cpp" line_range="51" />
<code_context>
+ * (~/.cache/deepin/deepin-draw/single) is always freshly creatable.
+ * Restores the original HOME on destruction.
+ */
+class ScopedTempHome
+{
+public:
</code_context>
<issue_to_address>
**Conflicting test helper definitions**
`ScopedTempHome` is also defined in `tests/test_main_funcs.cpp` with a different constructor body, so the test executable violates the C++ one-definition rule; runtime behavior of the combined tests is undefined.
Give the helper a unique name in one file or move a single identical definition into a shared test header.
</issue_to_address>
### Comment 2
<location path="tests/test_frame_dtors.cpp" line_range="63" />
<code_context>
+{
+ // MainWindow::~MainWindow calls CUndoRedoCommand::clearCommand().
+ // Verify calling it does not crash when the command stack is empty.
+ CUndoRedoCommand::clearCommand();
+ SUCCEED();
+}
</code_context>
<issue_to_address>
**Shared undo history is erased**
When earlier tests or harness activity have left commands in the shared recorded-command list, `CUndoRedoCommand::clearCommand()` processes and deletes the recorded commands and clears the shared history, changing command state and leaving later tests without undo history.
Run the empty-stack check with an isolated or known-empty command list so it cannot process commands left by other tests.
</issue_to_address>
### Comment 3
<location path="tests/test_cexportimagedialog_showdir.cpp" line_range="67" />
<code_context>
+
+ // Trigger showDirChoseDialog by setting the save path combo to "Other".
+ // The enum value for Other is the last entry (7).
+ dlg->slotOnSavePathChange(CExportImageDialog::Other);
+
+ closeTimer.stop();
</code_context>
<issue_to_address>
**Dialog route stays untested**
When the save-path combo is set to `Other`, `slotOnSavePathChange(CExportImageDialog::Other)` only copies the combo text into `m_savePath` and does not call `showDirChoseDialog()`; the dialog stays closed, so the combo-to-dialog route is not tested.
Select the `UsrSelect` entry and verify that it opens the dialog.
</issue_to_address>
### Comment 4
<location path="tests/test_frame_dtors.cpp" line_range="104" />
<code_context>
+
+ // Enable device-coordinate cache so _cachePixmap may be allocated
+ // during paint; the destructor must handle cleanup safely.
+ item->setCacheMode(QGraphicsItem::DeviceCoordinateCache);
+
+ delete item; // should clean up _cachePixmap without crash
</code_context>
<issue_to_address>
**Custom cache cleanup stays untested**
When the destructor test deletes the item without rendering it, `setCacheMode(QGraphicsItem::DeviceCoordinateCache)` enables Qt's cache, not `CGraphicsItem`'s `_cachePixmap`, so `_cachePixmap` remains null and the destructor skips its custom cache-deletion branch.
Enable `CGraphicsItem`'s custom cache and render the item before deleting it.
Also at `tests/test_frame_dtors.cpp:105`.
</issue_to_address>
### Comment 5
<location path="tests/test_service_dtors.cpp" line_range="58" />
<code_context>
+ // Exercise basic identity before destruction.
+ // No error() method available; just verify construction succeeded
+
+ delete fh;
+ SUCCEED();
+}
</code_context>
<issue_to_address>
**Parent cleanup stays untested**
When the child is manually deleted before the parent, the tests destroy the child directly while its parent is still alive, so parent destruction never performs the cleanup and the tests pass even if it stops deleting the child.
Destroy the parent without manually deleting the child and verify that the parent destroys it.
Also at `tests/test_service_dtors.cpp:102-108`.
</issue_to_address>
### Comment 6
<location path="tests/test_frame_dtors.cpp" line_range="55" />
<code_context>
+{
+ // MainWindow::~MainWindow iterates allTools() and deletes each.
+ // Verify the map is accessible and non-empty (tools registered at startup).
+ auto &tools = CDrawToolFactory::allTools();
+ EXPECT_FALSE(tools.isEmpty());
+}
</code_context>
<issue_to_address>
**Destructor cleanup goes unchecked**
When `MainWindow::~MainWindow` omits either cleanup operation, `AllToolsMap_IsAccessible` only checks that the tools map is nonempty, and `ClearCommand_IsSafe` calls `clearCommand()` directly. These tests pass if `MainWindow::~MainWindow` stops deleting tools or stops clearing the command stack.
Assert the cleanup effects after invoking the destructor, using a destructible test instance or an observable cleanup seam.
Also at `tests/test_frame_dtors.cpp:63`.
</issue_to_address>
### Comment 7
<location path="tests/test_cspinbox_wheelevent.cpp" line_range="67" />
<code_context>
+ QPoint(0, 120), QPoint(0, 120),
+ Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
+
+ QApplication::sendEvent(&box, &event);
+
+ // Without focus, timerStart() is never called → timer should NOT be running.
</code_context>
<issue_to_address>
**Wheel tests omit zero-delta events**
`QWheelEvent` instances are constructed with `angleDelta` and `pixelDelta` both set to `(0, 120)` or `(0, -120)`, so the pixel delta is nonzero; this does not expose whether the widget handles angle-only wheel input, leaving that common input path untested.
Add wheel-event cases with a nonzero angle delta and a zero pixel delta to verify standard wheel input handling.
</issue_to_address>
### Comment 8
<location path="tests/test_cexportimagedialog_showdir.cpp" line_range="21" />
<code_context>
+ * 1. The method can be triggered (via the save-path combo box "Other" index)
+ * and the dialog is created without crashing — a QTimer closes the modal
+ * dialog after it appears.
+ * 2. The dialog's initial directory is set to the user's home location.
+ *
+ * This is a best-effort test: in headless/offscreen mode DFileDialog::exec()
</code_context>
<issue_to_address>
**Initial directory is not verified**
The tests close the modal dialog without checking its configured directory, so the stated home-location behavior can regress while both tests still pass.
Inspect the active dialog’s directory while it is open and assert that it equals the expected home location.
</issue_to_address>Cover the remaining 0-hit coverage functions identified: - CSpinBox::wheelEvent: focused/unfocused branches with QWheelEvent - isRunning(Application&): non-crash, fresh-lock-returns-false, and pre-held-lock-returns-false via fork() (POSIX locks are per-process) - DrawToolManager::~DrawToolManager, IDrawTool::~IDrawTool: construct, register, destroy, re-construct lifecycle - FileHander::~FileHander, CPrintManager::~CPrintManager, dbusdraw_adaptor::~dbusdraw_adaptor: heap alloc/destruct, parent cleanup - MainWindow::~MainWindow: cleanup code path verification (singleton) - CGraphicsItem::~CGraphicsItem: via CGraphicsRectItem concrete subclass - DrawBoard/Page/PageView destructor paths: close page, verify instances - CDrawToolFactory::loadToolPlugin: invalid/empty/directory path returns - CExportImageDialog::showDirChoseDialog: timer-closed modal no-crash Issue: V-8787 Log: all 43 new tests pass.
1587b89 to
b4a904b
Compare
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无需修改,语法逻辑层面表现优秀。'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['抽取 QWheelEvent 构造辅助函数,消除 5 处重复。', '抽取模态对话框关闭定时器辅助函数,消除 2 处重复。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无需修改,性能层面表现优秀。'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无需修改,安全层面表现优秀。'] 💡 改进建议代码示例// 建议优化(非必须):抽取测试辅助函数消除重复
// tests/test_cspinbox_wheelevent.cpp
// 抽取前(重复 5 次):
// QWheelEvent event(QPointF(5, 5), QPointF(5, 5),
// QPoint(0, 120), QPoint(0, 120),
// Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
// 抽取后:
static QWheelEvent makeVerticalWheelEvent(int delta)
{
return QWheelEvent(QPointF(5, 5), QPointF(5, 5),
QPoint(0, delta), QPoint(0, delta),
Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false);
}
// 使用:
// QWheelEvent event = makeVerticalWheelEvent(120); // 向上滚动
// QWheelEvent event = makeVerticalWheelEvent(-120); // 向下滚动
// tests/test_cexportimagedialog_showdir.cpp
// 抽取模态对话框关闭定时器:
static QTimer *attachModalCloseTimer(int maxAttempts = 50)
{
auto *timer = new QTimer();
int *attempts = new int(0);
QObject::connect(timer, &QTimer::timeout, [timer, attempts]() {
QWidget *modal = QApplication::activeModalWidget();
if (modal != nullptr || ++(*attempts) > 50) {
if (modal != nullptr)
modal->close();
timer->stop();
}
});
timer->start(100);
return timer;
}本报告由 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 the remaining 0-hit coverage functions identified:
pre-held-lock-returns-false via fork() (POSIX locks are per-process)
register, destroy, re-construct lifecycle
dbusdraw_adaptor::~dbusdraw_adaptor: heap alloc/destruct, parent cleanup
Issue: V-8787
Log: all 43 new tests pass.