Skip to content

Conversation

@re2zero
Copy link
Contributor

@re2zero re2zero commented Nov 11, 2025

Added complete test coverage for the dfmplugin-propertydialog module including:

  • PropertyDialog plugin lifecycle tests
  • PropertyEventReceiver event handling tests
  • PropertyDialogManager view registration and creation tests
  • PropertyDialogUtil dialog management tests
  • ComputerPropertyHelper and MediaInfoFetchWorker utility tests
  • PropertyMenuScene menu integration tests

Tests cover core functionality like dialog creation, view extensions, custom views, basic field filters, and event handling with proper stubbing and mocking.

Updated .gitignore to include .spec-workflow/ directory for AI workflow configurations.

Added complete test coverage for the dfmplugin-propertydialog module including:
- PropertyDialog plugin lifecycle tests
- PropertyEventReceiver event handling tests
- PropertyDialogManager view registration and creation tests
- PropertyDialogUtil dialog management tests
- ComputerPropertyHelper and MediaInfoFetchWorker utility tests
- PropertyMenuScene menu integration tests

Tests cover core functionality like dialog creation, view extensions, custom views, basic field filters, and event handling with proper stubbing and mocking.

Updated .gitignore to include .spec-workflow/ directory for AI workflow configurations.
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @re2zero, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@deepin-ci-robot
Copy link
Contributor

deepin pr auto review

我来对这段代码进行审查,主要从以下几个方面进行分析:

  1. 语法逻辑

  2. 代码质量

  3. 代码性能

  4. 代码安全

  5. 语法逻辑审查:

  • 代码整体结构清晰,遵循了Google Test的测试框架规范
  • 使用了适当的头文件保护和命名空间
  • 测试用例命名规范,遵循了TEST_F格式
  • 使用了stub进行函数模拟,测试隔离性好
  1. 代码质量改进建议:
  • 建议在测试用例中添加更多边界条件测试,比如空URL、无效URL等情况
  • 可以增加更多的错误处理测试用例
  • 建议为测试用例添加更详细的注释,说明测试目的和预期结果
  • 可以考虑使用测试数据生成器来创建测试数据,提高测试覆盖率
  1. 代码性能优化建议:
  • 在测试用例中频繁创建和删除QWidget对象,可能会影响测试性能,建议使用对象池或智能指针管理
  • 可以考虑使用测试夹具的SetUp和TearDown方法来管理共享资源
  • 对于重复的测试代码,可以提取为公共函数
  1. 代码安全建议:
  • 在测试文件操作时,建议使用临时文件目录,避免影响实际文件系统
  • 测试中使用了/tmp/test等硬编码路径,建议使用QTemporaryDir等临时目录机制
  • 建议在测试完成后确保所有资源都被正确释放,包括QWidget对象和临时文件

具体改进建议:

  1. 在TestPropertyDialog类中添加临时目录管理:
class TestPropertyDialog : public testing::Test {
protected:
    void SetUp() override {
        tempDir.reset(new QTemporaryDir());
        ASSERT_TRUE(tempDir->isValid());
        stub.clear();
        propertyDialog.stop();
    }

    void TearDown() override {
        propertyDialog.stop();
        stub.clear();
        tempDir.reset();
    }

    QScopedPointer<QTemporaryDir> tempDir;
    stub_ext::StubExt stub;
    static PropertyDialog propertyDialog;
};
  1. 添加边界条件测试用例:
TEST_F(TestPropertyDialog, HandleShowPropertyDialogWithEmptyUrls)
{
    PropertyEventReceiver receiver;
    QList<QUrl> urls; // Empty URL list
    QVariantHash option;
    
    EXPECT_NO_THROW(receiver.handleShowPropertyDialog(urls, option));
}

TEST_F(TestPropertyDialog, HandleShowPropertyDialogWithInvalidUrls)
{
    PropertyEventReceiver receiver;
    QList<QUrl> urls;
    urls << QUrl("invalid://url");
    QVariantHash option;
    
    EXPECT_NO_THROW(receiver.handleShowPropertyDialog(urls, option));
}
  1. 使用智能指针管理QWidget对象:
TEST_F(TestPropertyDialog, CreateExtensionViewTest)
{
    PropertyDialogManager &manager = PropertyDialogManager::instance();
    auto mockView = [](const QUrl &url) -> QWidget* {
        return new QWidget();
    };
    
    manager.registerExtensionView(mockView, "test_name", 0);
    
    QUrl url = QUrl::fromLocalFile(tempDir->path());
    auto result = manager.createExtensionView(url);
    
    EXPECT_FALSE(result.isEmpty());
    
    // Use QScopedPointer for automatic cleanup
    for (QWidget *widget : result) {
        QScopedPointer<QWidget> guard(widget);
    }
}
  1. 添加错误处理测试:
TEST_F(TestPropertyDialog, HandleShowPropertyDialogWithError)
{
    PropertyEventReceiver receiver;
    
    // Mock error condition
    stub.set_lamda(&PropertyDialogUtil::showPropertyDialog,
                   [](PropertyDialogUtil *self, const QList<QUrl> &urls, const QVariantHash &option) {
                       throw std::runtime_error("Test error");
                   });
    
    QList<QUrl> urls;
    urls << QUrl::fromLocalFile(tempDir->path());
    QVariantHash option;
    
    EXPECT_THROW(receiver.handleShowPropertyDialog(urls, option), std::runtime_error);
}
  1. 提取公共测试函数:
class TestPropertyDialog : public testing::Test {
protected:
    void setupMockView() {
        mockView = [](const QUrl &url) -> QWidget* {
            return new QWidget();
        };
    }

    void cleanupWidget(QWidget* widget) {
        if (widget) {
            widget->deleteLater();
        }
    }

    std::function<QWidget*(const QUrl&)> mockView;
};

这些改进建议可以提高代码的健壮性、可维护性和测试覆盖率。

@github-actions
Copy link

  • 敏感词检查失败, 检测到1个文件存在敏感词
详情
{
    "autotests/plugins/dfmplugin-propertydialog/test_propertydialogmanager.cpp": [
        {
            "line": "    QWidget *result2 = manager.createCustomView(QUrl(\"ftp://example.com/test\"));",
            "line_number": 200,
            "rule": "S35",
            "reason": "Url link | 20432f5d9e"
        },
        {
            "line": "    QUrl ftpUrl(\"ftp://example.com/test\");",
            "line_number": 290,
            "rule": "S35",
            "reason": "Url link | 20432f5d9e"
        }
    ]
}

@deepin-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Johnson-zs, re2zero

The full list of commands accepted by this bot can be found here.

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

@Johnson-zs
Copy link
Contributor

/forcemerge

@deepin-bot
Copy link
Contributor

deepin-bot bot commented Nov 11, 2025

This pr force merged! (status: behind)

@deepin-bot deepin-bot bot merged commit b3f251e into linuxdeepin:master Nov 11, 2025
17 of 20 checks passed
@re2zero re2zero deleted the unitest branch November 11, 2025 11:38
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