Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ dde-file-manager-lib/test_shutil/property/oneProperty.pro
.cursor
.specstory
.spec-workflow/
.serena/
.kiro/
.promptx/
.qoder/
.qoderignore

# autotests
Testing
Expand Down
164 changes: 164 additions & 0 deletions autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <gtest/gtest.h>

Check warning on line 5 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 5 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <gtest/gtest.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTest>

Check warning on line 6 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 6 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTest> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QApplication>

Check warning on line 7 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 7 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QApplication> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QUrl>

Check warning on line 8 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QUrl> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 8 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QUrl> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTextCursor>

Check warning on line 9 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTextCursor> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 9 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTextCursor> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFocusEvent>

Check warning on line 10 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFocusEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QFocusEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QKeyEvent>

Check warning on line 11 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QKeyEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 11 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QKeyEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 12 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 12 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QTextBlockFormat>

Check warning on line 13 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QTextBlockFormat> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QTextBlockFormat> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include "stubext.h"

Check warning on line 14 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "stubext.h" not found.

Check warning on line 14 in autotests/plugins/dfmplugin-propertydialog/test_editstackedwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "stubext.h" not found.

#include "views/editstackedwidget.h"
#include "dfmplugin_propertydialog_global.h"

DPPROPERTYDIALOG_USE_NAMESPACE

class TestEditStackedWidget : public testing::Test
{
protected:
void SetUp() override
{
stub.clear();
}

void TearDown() override
{
stub.clear();
}

stub_ext::StubExt stub;
};

// Test NameTextEdit class
TEST_F(TestEditStackedWidget, NameTextEditConstructor)
{
NameTextEdit *textEdit = new NameTextEdit("test");
EXPECT_NE(textEdit, nullptr);
delete textEdit;
}

TEST_F(TestEditStackedWidget, NameTextEditDestructor)
{
NameTextEdit *textEdit = new NameTextEdit("test");
EXPECT_NO_THROW(delete textEdit);
}

TEST_F(TestEditStackedWidget, NameTextEditIsCanceled)
{
NameTextEdit textEdit("test");
EXPECT_FALSE(textEdit.isCanceled());
}

TEST_F(TestEditStackedWidget, NameTextEditSetIsCanceled)
{
NameTextEdit textEdit("test");
textEdit.setIsCanceled(true);
EXPECT_TRUE(textEdit.isCanceled());

textEdit.setIsCanceled(false);
EXPECT_FALSE(textEdit.isCanceled());
}

TEST_F(TestEditStackedWidget, NameTextEditSetPlainText)
{
NameTextEdit textEdit("test");
textEdit.setPlainText("new text");

// Check if text is set correctly
EXPECT_EQ(textEdit.toPlainText(), "new text");
}

TEST_F(TestEditStackedWidget, NameTextEditSlotTextChanged)
{
NameTextEdit textEdit("test");
textEdit.setPlainText("new text");

// Call slot directly
EXPECT_NO_THROW(textEdit.slotTextChanged());
}

TEST_F(TestEditStackedWidget, NameTextEditFocusOutEvent)
{
NameTextEdit textEdit("test");
QFocusEvent event(QEvent::FocusOut);
EXPECT_NO_THROW(textEdit.focusOutEvent(&event));
}

TEST_F(TestEditStackedWidget, NameTextEditKeyPressEventEscape)
{
NameTextEdit textEdit("test");
QKeyEvent event(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier);
EXPECT_NO_THROW(textEdit.keyPressEvent(&event));
EXPECT_TRUE(textEdit.isCanceled());
}

TEST_F(TestEditStackedWidget, NameTextEditKeyPressEventEnter)
{
NameTextEdit textEdit("test");
QKeyEvent event(QEvent::KeyPress, Qt::Key_Enter, Qt::NoModifier);
EXPECT_NO_THROW(textEdit.keyPressEvent(&event));
EXPECT_FALSE(textEdit.isCanceled());
}

TEST_F(TestEditStackedWidget, NameTextEditKeyPressEventReturn)
{
NameTextEdit textEdit("test");
QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
EXPECT_NO_THROW(textEdit.keyPressEvent(&event));
EXPECT_FALSE(textEdit.isCanceled());
}

// Test EditStackedWidget class
TEST_F(TestEditStackedWidget, EditStackedWidgetConstructor)
{
EditStackedWidget *stackedWidget = new EditStackedWidget();
EXPECT_NE(stackedWidget, nullptr);
delete stackedWidget;
}

TEST_F(TestEditStackedWidget, EditStackedWidgetDestructor)
{
EditStackedWidget *stackedWidget = new EditStackedWidget();
EXPECT_NO_THROW(delete stackedWidget);
}

TEST_F(TestEditStackedWidget, EditStackedWidgetInitTextShowFrame)
{
EditStackedWidget stackedWidget;
EXPECT_NO_THROW(stackedWidget.initTextShowFrame("test file"));
}

TEST_F(TestEditStackedWidget, EditStackedWidgetRenameFile)
{
EditStackedWidget stackedWidget;
stackedWidget.selectFile(QUrl::fromLocalFile("/tmp/test.txt"));
// EXPECT_NO_THROW(stackedWidget.renameFile());
}

TEST_F(TestEditStackedWidget, EditStackedWidgetShowTextShowFrame)
{
EditStackedWidget stackedWidget;
stackedWidget.selectFile(QUrl::fromLocalFile("/tmp/test.txt"));
EXPECT_NO_THROW(stackedWidget.showTextShowFrame());
}

TEST_F(TestEditStackedWidget, EditStackedWidgetSelectFile)
{
EditStackedWidget stackedWidget;
EXPECT_NO_THROW(stackedWidget.selectFile(QUrl::fromLocalFile("/tmp/test.txt")));
}

TEST_F(TestEditStackedWidget, EditStackedWidgetMouseProcess)
{
EditStackedWidget stackedWidget;
stackedWidget.selectFile(QUrl::fromLocalFile("/tmp/test.txt"));
// stackedWidget.renameFile(); // Switch to edit mode

QMouseEvent event(QEvent::MouseButtonPress, QPointF(0, 0), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
EXPECT_NO_THROW(stackedWidget.mouseProcess(&event));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// SPDX-FileCopyrightText: 2025 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <gtest/gtest.h>
#include <QTest>
#include <QUrl>
#include <QList>
#include "stubext.h"

#include "views/multifilepropertydialog.h"
#include "dfmplugin_propertydialog_global.h"

DPPROPERTYDIALOG_USE_NAMESPACE

class TestMultiFilePropertyDialog : public testing::Test
{
protected:
void SetUp() override
{
stub.clear();
}

void TearDown() override
{
stub.clear();
}

stub_ext::StubExt stub;
};

// Test MultiFilePropertyDialog class
TEST_F(TestMultiFilePropertyDialog, MultiFilePropertyDialogConstructor)
{
QList<QUrl> urls;
urls << QUrl::fromLocalFile("/tmp/test1.txt") << QUrl::fromLocalFile("/tmp/test2.txt");

MultiFilePropertyDialog *dialog = new MultiFilePropertyDialog(urls);
EXPECT_NE(dialog, nullptr);
delete dialog;
}

TEST_F(TestMultiFilePropertyDialog, MultiFilePropertyDialogDestructor)
{
QList<QUrl> urls;
urls << QUrl::fromLocalFile("/tmp/test1.txt") << QUrl::fromLocalFile("/tmp/test2.txt");

MultiFilePropertyDialog *dialog = new MultiFilePropertyDialog(urls);
EXPECT_NO_THROW(delete dialog);
}

TEST_F(TestMultiFilePropertyDialog, MultiFilePropertyDialogUpdateFolderSizeLabel)
{
QList<QUrl> urls;
urls << QUrl::fromLocalFile("/tmp/test1.txt") << QUrl::fromLocalFile("/tmp/test2.txt");

MultiFilePropertyDialog dialog(urls);
EXPECT_NO_THROW(dialog.updateFolderSizeLabel(1024, 2, 1));
}
Loading
Loading