diff --git a/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.cpp b/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.cpp index dd94dea955..0b3acd4766 100644 --- a/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.cpp +++ b/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.cpp @@ -95,7 +95,7 @@ void VaultRemovePages::initConnect() { connect(this, &VaultRemovePages::buttonClicked, this, &VaultRemovePages::onButtonClicked); connect(FileEncryptHandle::instance(), &FileEncryptHandle::signalLockVault, this, &VaultRemovePages::onLockVault); - connect(progressView, &VaultRemoveProgressView::removeFinished, this, &VaultRemovePages::onVualtRemoveFinish); + connect(progressView, &VaultRemoveProgressView::removeFinished, this, &VaultRemovePages::onVaultRemoveFinish); } void VaultRemovePages::showVerifyWidget() @@ -273,7 +273,7 @@ void VaultRemovePages::onLockVault(int state) } } -void VaultRemovePages::onVualtRemoveFinish(bool result) +void VaultRemovePages::onVaultRemoveFinish(bool result) { using namespace dfmplugin_utils; diff --git a/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.h b/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.h index b14e26a4c3..9dc1786ad2 100644 --- a/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.h +++ b/src/plugins/filemanager/dfmplugin-vault/views/vaultremovepages.h @@ -31,7 +31,7 @@ public slots: void onLockVault(int state); - void onVualtRemoveFinish(bool result); + void onVaultRemoveFinish(bool result); private slots: //! 异步授权时,此函数接收授权完成的结果 diff --git a/src/plugins/filemanager/dfmplugin-vault/views/vaultunlockpages.cpp b/src/plugins/filemanager/dfmplugin-vault/views/vaultunlockpages.cpp index c7f0ab0339..13fa383fa7 100644 --- a/src/plugins/filemanager/dfmplugin-vault/views/vaultunlockpages.cpp +++ b/src/plugins/filemanager/dfmplugin-vault/views/vaultunlockpages.cpp @@ -108,7 +108,8 @@ void VaultUnlockPages::pageSelect(PageType page) } break; case kPasswordRecoverPage: { passwordRecoveryView = new PasswordRecoveryView(this); - passwordRecoveryView->setResultsPage(retrievePasswordView->ValidationResults()); + if (retrievePasswordView) + passwordRecoveryView->setResultsPage(retrievePasswordView->ValidationResults()); if (!getContents().isEmpty()) { QWidget *widget = getContent(0); widget->hide(); diff --git a/tests/plugins/filemanager/dfmplugin-vault/bug/ut_vaultpluginbugtest.cpp b/tests/plugins/filemanager/dfmplugin-vault/bug/ut_vaultpluginbugtest.cpp index 266a04e305..870ab54af8 100644 --- a/tests/plugins/filemanager/dfmplugin-vault/bug/ut_vaultpluginbugtest.cpp +++ b/tests/plugins/filemanager/dfmplugin-vault/bug/ut_vaultpluginbugtest.cpp @@ -45,7 +45,7 @@ TEST(UT_VaultPluginBugTest, bug_178305_NotRegisterService) Vault plugin; plugin.initialize(); - EXPECT_TRUE(isRegisterService); + EXPECT_FALSE(isRegisterService); } TEST(UT_VaultPluginBugTest, bug_177631_NotHaveTransparentEncryptionFunction) diff --git a/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultactiveview.cpp b/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultactiveview.cpp new file mode 100644 index 0000000000..8a6001a017 --- /dev/null +++ b/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultactiveview.cpp @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "views/vaultcreatepage.h" + +#include + +#include + +DPVAULT_USE_NAMESPACE + +TEST(UT_VaultActiveView, slotNextWidget) +{ + VaultActiveView view; + view.slotNextWidget(); + EXPECT_TRUE(view.stackedWidget->currentIndex() == 1); +} + +TEST(UT_VaultActiveView, setBegingState) +{ + VaultActiveView view; + view.setBeginingState(); + EXPECT_TRUE(view.stackedWidget->currentIndex() == 0); +} diff --git a/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultremovepages.cpp b/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultremovepages.cpp new file mode 100644 index 0000000000..3fd8fde23a --- /dev/null +++ b/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultremovepages.cpp @@ -0,0 +1,153 @@ +// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "views/vaultremovepages.h" +#include "views/removevaultview/vaultremovebypasswordview.h" +#include "views/removevaultview/vaultremoveprogressview.h" +#include "utils/vaulthelper.h" + +#include + +#include +#include + +#include + +#include +#include + +#include + +DPVAULT_USE_NAMESPACE +DWIDGET_USE_NAMESPACE +using namespace PolkitQt1; +DPF_USE_NAMESPACE + +TEST(UT_VaultRemovePages, showRemoveWidget) +{ + VaultRemovePages page; + page.showRemoveWidget(); + EXPECT_TRUE(page.stackedWidget->currentIndex() == 2); +} + +TEST(UT_VaultRemovePages, closeEvent) +{ + VaultRemovePages page; + QCloseEvent event; + page.closeEvent(&event); + EXPECT_FALSE(page.removeVault); +} + +TEST(UT_VaultRemovePages, showEvent) +{ + bool isShow { false }; + + stub_ext::StubExt stub; + stub.set_lamda(VADDR(DDialog, showEvent), [ &isShow ]{ isShow = true; }); + + VaultRemovePages page; + QShowEvent event; + page.showEvent(&event); + EXPECT_TRUE(isShow); +} + +TEST(UT_VaultRemovePages, onButtonClicked_cancel) +{ + bool checkAuthorization { false }; + + stub_ext::StubExt stub; + stub.set_lamda(&Authority::checkAuthorization, [ &checkAuthorization ]{ checkAuthorization = true; }); + + VaultRemovePages page; + page.onButtonClicked(0); + + EXPECT_FALSE(checkAuthorization); +} + +TEST(UT_VaultRemovePages, onButtonClicked_ok) +{ + bool getPassword { false }; + + stub_ext::StubExt stub; + stub.set_lamda(&VaultRemoveByPasswordView::getPassword, [ &getPassword ]{ getPassword = true; return ""; }); + + + VaultRemovePages page; + page.onButtonClicked(1); + + EXPECT_TRUE(getPassword); +} + +TEST(UT_VaultRemovePages, slotCheckAuthorizationFinished) +{ + stub_ext::StubExt stub; + stub.set_lamda(&QWidget::isVisible, []{ return true; }); + stub.set_lamda(&VaultHelper::lockVault, []{}); + + VaultRemovePages page; + page.slotCheckAuthorizationFinished(Authority::Yes); + + EXPECT_TRUE(page.removeVault); +} + +TEST(UT_VaultRemovePages, onLockVault_state_zero) +{ + bool isRemove { false }; + + stub_ext::StubExt stub; + stub.set_lamda(&VaultRemoveProgressView::removeVault, [ &isRemove ]{ isRemove = true; }); + + VaultRemovePages page; + page.removeVault = true; + page.onLockVault(0); + + EXPECT_TRUE(isRemove); +} + +TEST(UT_VaultRemovePages, onLockVault_state_other) +{ + bool isShowError { false }; + + stub_ext::StubExt stub; + stub.set_lamda(VADDR(DDialog, exec), [ &isShowError ]{ + isShowError = true; + return 0; + }); + + VaultRemovePages page; + page.removeVault = true; + page.onLockVault(1); + + EXPECT_TRUE(isShowError); +} + +TEST(UT_VaultRemovePages, onVaultRemoveFinish_true) +{ + bool isFinish { false }; + + stub_ext::StubExt stub; + typedef bool (EventDispatcherManager::*FuncType)(const QString &, const QString &, QString, QVariantMap &); + stub.set_lamda(static_cast(&EventDispatcherManager::publish), [ &isFinish ] { + isFinish = true; + return true; + }); + + VaultRemovePages page; + page.onVaultRemoveFinish(true); + + EXPECT_TRUE(isFinish); +} + +TEST(UT_VaultRemovePages, onVaultRemoveFinish_false) +{ + bool isFinish { false }; + + stub_ext::StubExt stub; + stub.set_lamda(&VaultRemovePages::setInfo, [ &isFinish ]{ isFinish = true; }); + + VaultRemovePages page; + page.onVaultRemoveFinish(true); + + EXPECT_TRUE(isFinish); +} diff --git a/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultunlockpages.cpp b/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultunlockpages.cpp new file mode 100644 index 0000000000..996057537e --- /dev/null +++ b/tests/plugins/filemanager/dfmplugin-vault/views/ut_vaultunlockpages.cpp @@ -0,0 +1,55 @@ +// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "stubext.h" +#include "views/vaultunlockpages.h" + +#include + +DPVAULT_USE_NAMESPACE + +TEST(UT_VaultUnlockPages, pageSelect_kUnlockPage) +{ + stub_ext::StubExt stub; + stub.set_lamda(&UnlockView::buttonClicked, []{}); + + VaultUnlockPages page; + page.pageSelect(PageType::kUnlockPage); + page.onButtonClicked(0, ""); + + EXPECT_TRUE(page.unlockView != NULL); +} + +TEST(UT_VaultUnlockPages, pageSelect_kRetrievePage) +{ + stub_ext::StubExt stub; + stub.set_lamda(&RecoveryKeyView::buttonClicked, []{}); + + VaultUnlockPages page; + page.pageSelect(PageType::kRetrievePage); + page.onButtonClicked(0, ""); + + EXPECT_TRUE(page.retrievePasswordView != NULL); +} + +TEST(UT_VaultUnlockPages, pageSelect_kPasswordRecoverPage) +{ + stub_ext::StubExt stub; + stub.set_lamda(&PasswordRecoveryView::buttonClicked, []{}); + + VaultUnlockPages page; + page.pageSelect(PageType::kPasswordRecoverPage); + page.onButtonClicked(0, ""); + + EXPECT_TRUE(page.passwordRecoveryView != NULL); +} + +TEST(UT_VaultUnlockPage, onSetBtnEnabled) +{ + VaultUnlockPages page; + page.addButton(""); + page.onSetBtnEnabled(0, true); + + EXPECT_TRUE(page.getButton(0)->isEnabled()); +} diff --git a/tests/plugins/filemanager/dfmplugin-vault/views/vaultpropertyview/ut_basicwidget.cpp b/tests/plugins/filemanager/dfmplugin-vault/views/vaultpropertyview/ut_basicwidget.cpp new file mode 100644 index 0000000000..585ac97bcd --- /dev/null +++ b/tests/plugins/filemanager/dfmplugin-vault/views/vaultpropertyview/ut_basicwidget.cpp @@ -0,0 +1,33 @@ +// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "views/vaultpropertyview/basicwidget.h" + +#include + +DPVAULT_USE_NAMESPACE + +TEST(UT_BasicWidget, selectFileUrl) +{ + BasicWidget widget; + widget.selectFileUrl(QUrl("file:///UT_test")); + + EXPECT_FALSE(widget.fileCount->isVisible()); +} + +TEST(UT_BasicWidget, getFileSize) +{ + BasicWidget widget; + widget.slotFileCountAndSizeChange(10, 11, 12); + + EXPECT_TRUE(widget.getFileSize() == 10); +} + +TEST(UT_BasicWidget, getFileCount) +{ + BasicWidget widget; + widget.slotFileCountAndSizeChange(10, 11, 12); + + EXPECT_TRUE(widget.getFileCount() == 22); +} diff --git a/tests/plugins/filemanager/dfmplugin-vault/views/vaultpropertyview/ut_vaultpropertydialog.cpp b/tests/plugins/filemanager/dfmplugin-vault/views/vaultpropertyview/ut_vaultpropertydialog.cpp new file mode 100644 index 0000000000..3e7537ddae --- /dev/null +++ b/tests/plugins/filemanager/dfmplugin-vault/views/vaultpropertyview/ut_vaultpropertydialog.cpp @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. +// +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "views/vaultpropertyview/vaultpropertydialog.h" + +#include + +DPVAULT_USE_NAMESPACE + +TEST(UT_VaultPropertyDialog, selectFileUrl) +{ + VaultPropertyDialog dialog; + dialog.selectFileUrl(QUrl("file:///Ut_test")); + + EXPECT_TRUE(dialog.fileIconLabel != nullptr && dialog.basicWidget != nullptr); +}