Skip to content

fix: Move dnetwork-secret-dialog from dde-session-ui - #415

Merged
caixr23 merged 1 commit into
linuxdeepin:masterfrom
caixr23:master
Oct 17, 2025
Merged

caixr23 merged 1 commit into
linuxdeepin:masterfrom
caixr23:master

Conversation

@caixr23

@caixr23 caixr23 commented Oct 17, 2025

Copy link
Copy Markdown
Contributor

Move dnetwork-secret-dialog from dde-session-ui

pms: TASK-381263

@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.

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

Please try again later or upgrade to continue using Sourcery

Move dnetwork-secret-dialog from dde-session-ui

pms: TASK-381263
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

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

  1. 代码结构调整:
  • 将dde-network-secret-dialog的源文件移到了src目录下,这是一个好的实践,使项目结构更清晰
  • 新增了tests目录和相应的测试文件,有利于代码质量保证
  1. CMakeLists.txt改进:
  • 添加了BUILD_TESTS选项,使测试构建更灵活,不再依赖于Debug构建类型
  • 将dde-network-secret-dialog的构建配置拆分到src/CMakeLists.txt中,提高了代码组织性
  1. 测试代码质量:
  • 测试用例覆盖了主要功能点:WEP密钥验证、WPA-PSK验证、提交功能和按键事件
  • 使用了Google Test框架,测试结构清晰
  • 添加了内存检查工具(ASan)支持

建议改进:

  1. 测试用例完善:
// 在ut_networksecretdialog.cpp中增加边界条件测试
TEST_F(Ut_NetworkSecretDialog, boundaryTest)
{
    // 测试空字符串
    EXPECT_FALSE(dialog->wepKeyIsValid("", NetworkSecretDialog::Passphrase));
    // 测试超长字符串
    EXPECT_FALSE(dialog->wepKeyIsValid(std::string(100, 'a').c_str(), NetworkSecretDialog::Passphrase));
    // 测试特殊字符
    EXPECT_TRUE(dialog->wepKeyIsValid("abc!@#$", NetworkSecretDialog::Passphrase));
}
  1. CMakeLists.txt优化:
# 在tests/CMakeLists.txt中添加编译选项优化
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    target_compile_options(${UT_Dnetwork_Secret_Dialog_Name} PRIVATE
        -g
        -O0
        -Wall
        -Wextra
        -fprofile-arcs
        -ftest-coverage
    )
else()
    target_compile_options(${UT_Dnetwork_Secret_Dialog_Name} PRIVATE
        -O2
        -DNDEBUG
    )
endif()
  1. 安全性改进:
// 在main.cpp中增加安全检查
int main(int argc, char *argv[])
{
    // 添加输入参数验证
    if (argc < 1) {
        qCritical() << "Invalid arguments";
        return -1;
    }
    
    // 设置环境变量时进行错误检查
    if (!qputenv("QT_QPA_PLATFORM", "offscreen")) {
        qWarning() << "Failed to set QT_QPA_PLATFORM";
    }
    
    // ... 其余代码
}
  1. 性能优化建议:
  • 在测试文件中使用智能指针管理资源
class Ut_NetworkSecretDialog : public testing::Test
{
public:
    void SetUp() override {
        QString json = "{\"connName\":\"UtNetworkSecretDialog\", \"connType\":\"Wiredless\", \"secrets\":[\"wep\"]}";
        dialog = std::make_unique<NetworkSecretDialog>(QJsonDocument::fromJson(json.toUtf8()));
    }

    void TearDown() override {
        dialog.reset();
    }

private:
    std::unique_ptr<NetworkSecretDialog> dialog;
};
  1. 错误处理改进:
// 在networksecretdialog.cpp中增加错误处理
bool NetworkSecretDialog::wepKeyIsValid(const QString& key, WepKeyType type)
{
    if (key.isEmpty()) {
        qWarning() << "Empty WEP key provided";
        return false;
    }
    
    // 原有验证逻辑...
    
    if (!isValid) {
        qWarning() << "Invalid WEP key format";
    }
    
    return isValid;
}

这些改进建议主要围绕:

  1. 增强测试覆盖率
  2. 提高代码安全性
  3. 改进错误处理
  4. 优化性能
  5. 提高代码可维护性

整体来说,这次改动是正向的,提高了代码的组织性和可测试性。建议继续完善测试用例,增加边界条件测试,并加强错误处理机制。

@caixr23
caixr23 requested a review from mhduiy October 17, 2025 07:19
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23, mhduiy

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

@caixr23
caixr23 merged commit 8a8d20f into linuxdeepin:master Oct 17, 2025
16 of 18 checks passed
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