Skip to content

Commit a9a6668

Browse files
Kakueeendeepin-bot[bot]
authored andcommitted
test: add unit tests for canvas interface shells
1. Added comprehensive unit tests for CanvasGridShell covering constructor, initialization, item retrieval, and grid operations 2. Implemented tests for CanvasInterface including initialization, shell creation, and icon level management 3. Added tests for CanvasManagerShell focusing on initialization and icon level functionality 4. Created tests for CanvasModelShell covering refresh, fetch, and take operations 5. Implemented tests for CanvasSelectionShell including constructor and selection model retrieval 6. Added tests for CanvasViewShell covering grid positioning, visual rects, and event handling 7. Created tests for FileInfoModelShell including model operations and state management 8. Fixed existing test assertions in CollectionItemDelegate and ItemEditor to match actual behavior 9. Updated VirtualBluetoothPlugin test to use correct DialogManager method signature These tests ensure the canvas interface shells work correctly and provide proper error handling. The test coverage includes all major functionality of the organizer plugin's canvas integration layer. Influence: 1. Run all new unit tests to verify canvas shell functionality 2. Test canvas grid operations with valid and invalid parameters 3. Verify icon level management and event handling 4. Check file model operations and state transitions 5. Validate selection model functionality 6. Test visual positioning and grid calculations 7. Verify event propagation and signal handling test: 新增画布接口外壳单元测试 1. 为 CanvasGridShell 添加全面的单元测试,包括构造函数、初始化、项目检索 和网格操作 2. 实现 CanvasInterface 测试,包括初始化、外壳创建和图标级别管理 3. 添加 CanvasManagerShell 测试,专注于初始化和图标级别功能 4. 创建 CanvasModelShell 测试,涵盖刷新、获取和移除操作 5. 实现 CanvasSelectionShell 测试,包括构造函数和选择模型检索 6. 添加 CanvasViewShell 测试,涵盖网格定位、可视矩形和事件处理 7. 创建 FileInfoModelShell 测试,包括模型操作和状态管理 8. 修复 CollectionItemDelegate 和 ItemEditor 中现有测试断言以匹配实际 行为 9. 更新 VirtualBluetoothPlugin 测试以使用正确的 DialogManager 方法签名 这些测试确保画布接口外壳正常工作并提供正确的错误处理。测试覆盖范围包括组 织器插件画布集成层的所有主要功能。 Influence: 1. 运行所有新单元测试以验证画布外壳功能 2. 使用有效和无效参数测试画布网格操作 3. 验证图标级别管理和事件处理 4. 检查文件模型操作和状态转换 5. 验证选择模型功能 6. 测试视觉定位和网格计算 7. 验证事件传播和信号处理
1 parent 2ed7ffc commit a9a6668

9 files changed

+975
-28
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
2+
//
3+
// SPDX-License-Identifier: GPL-3.0-or-later
4+
5+
#include "stubext.h"
6+
#include "interface/canvasgridshell.h"
7+
8+
#include <dfm-framework/dpf.h>
9+
10+
#include <gtest/gtest.h>
11+
#include <QPoint>
12+
13+
using namespace ddplugin_organizer;
14+
DPF_USE_NAMESPACE
15+
16+
class UT_CanvasGridShell : public testing::Test
17+
{
18+
protected:
19+
void SetUp() override
20+
{
21+
shell = new CanvasGridShell();
22+
}
23+
24+
void TearDown() override
25+
{
26+
delete shell;
27+
shell = nullptr;
28+
stub.clear();
29+
}
30+
31+
public:
32+
stub_ext::StubExt stub;
33+
CanvasGridShell *shell = nullptr;
34+
};
35+
36+
TEST_F(UT_CanvasGridShell, Constructor_Default_InitializesCorrectly)
37+
{
38+
EXPECT_NE(shell, nullptr);
39+
}
40+
41+
TEST_F(UT_CanvasGridShell, Constructor_WithParent_SetsParent)
42+
{
43+
QObject parent;
44+
CanvasGridShell shellWithParent(&parent);
45+
EXPECT_EQ(shellWithParent.parent(), &parent);
46+
}
47+
48+
TEST_F(UT_CanvasGridShell, initialize_Always_ReturnsTrue)
49+
{
50+
bool result = shell->initialize();
51+
EXPECT_TRUE(result);
52+
}
53+
54+
TEST_F(UT_CanvasGridShell, item_WithValidParams_ReturnsItemFromChannel)
55+
{
56+
QString expectedItem = "file:///home/test/file.txt";
57+
typedef QVariant (EventChannelManager::*Push)(const QString &, const QString &, int, const QPoint &);
58+
stub.set_lamda(static_cast<Push>(&EventChannelManager::push), [&expectedItem]() {
59+
__DBG_STUB_INVOKE__
60+
return QVariant(expectedItem);
61+
});
62+
63+
QString result = shell->item(0, QPoint(1, 2));
64+
EXPECT_EQ(result, expectedItem);
65+
}
66+
67+
TEST_F(UT_CanvasGridShell, item_WithInvalidIndex_ReturnsEmptyString)
68+
{
69+
typedef QVariant (EventChannelManager::*Push)(const QString &, const QString &, int &, const QPoint &);
70+
stub.set_lamda(static_cast<Push>(&EventChannelManager::push), []() {
71+
__DBG_STUB_INVOKE__
72+
return QVariant(QString());
73+
});
74+
75+
QString result = shell->item(-1, QPoint(0, 0));
76+
EXPECT_TRUE(result.isEmpty());
77+
}
78+
79+
TEST_F(UT_CanvasGridShell, tryAppendAfter_WithItems_CallsChannel)
80+
{
81+
bool channelCalled = false;
82+
typedef QVariant (EventChannelManager::*Push)(const QString &, const QString &, QStringList, int &, const QPoint &);
83+
stub.set_lamda(static_cast<Push>(&EventChannelManager::push), [&channelCalled]() {
84+
__DBG_STUB_INVOKE__
85+
channelCalled = true;
86+
return QVariant();
87+
});
88+
89+
QStringList items = { "item1", "item2" };
90+
shell->tryAppendAfter(items, 0, QPoint(1, 1));
91+
EXPECT_TRUE(channelCalled);
92+
}
93+
94+
TEST_F(UT_CanvasGridShell, point_WithValidItem_ReturnsIndex)
95+
{
96+
int expectedIndex = 1;
97+
typedef QVariant (EventChannelManager::*Push)(const QString &, const QString &, QString, QPoint *&);
98+
stub.set_lamda(static_cast<Push>(&EventChannelManager::push), [expectedIndex]() {
99+
__DBG_STUB_INVOKE__
100+
return QVariant(expectedIndex);
101+
});
102+
103+
QPoint pos;
104+
int result = shell->point("file:///test.txt", &pos);
105+
EXPECT_EQ(result, expectedIndex);
106+
}
107+

0 commit comments

Comments
 (0)