Skip to content

Commit

Permalink
feat: add some UT
Browse files Browse the repository at this point in the history
Log:
  • Loading branch information
xzl01 authored and Whale107 committed Aug 28, 2024
1 parent 4c21ed6 commit 6d76f96
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ set(WIDGET_TEST
testcases/widgets/ut_dipv4lineedit.cpp
testcases/widgets/ut_dkeysequenceedit.cpp
testcases/widgets/ut_dlabel.cpp
testcases/widgets/ut_dlicensedialog.cpp
testcases/widgets/ut_dlineedit.cpp
testcases/widgets/ut_dlistview.cpp
testcases/widgets/ut_dloadingindicator.cpp
Expand Down Expand Up @@ -92,6 +93,7 @@ set(WIDGET_TEST
testcases/widgets/ut_dstyleoption.cpp
testcases/widgets/ut_dsuggestbutton.cpp
testcases/widgets/ut_dswitchbutton.cpp
testcases/widgets/ut_dswitchlineexpand.cpp
testcases/widgets/ut_dtabbar.cpp
testcases/widgets/ut_dtextedit.cpp
testcases/widgets/ut_dtickeffect.cpp
Expand Down
1 change: 1 addition & 0 deletions tests/data.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>data/titlebar-settings.json</file>
<file>data/example-license.json</file>
</qresource>
</RCC>
32 changes: 32 additions & 0 deletions tests/data/example-license.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"name": "pkg-config",
"version": "",
"copyright": "NOASSERTION",
"license": "MIT"
},
{
"name": "lshw",
"version": "",
"copyright": "NOASSERTION",
"license": "GPL-2"
},
{
"name": "debhelper",
"version": "",
"copyright": "NOASSERTION",
"license": "GPL-2"
},
{
"name": "pkg-config",
"version": "",
"copyright": "NOASSERTION",
"license": "MIT"
},
{
"name": "debhelper",
"version": "",
"copyright": "NOASSERTION",
"license": "GPL-2"
}
]
40 changes: 40 additions & 0 deletions tests/testcases/widgets/ut_dlicensedialog.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <gtest/gtest.h>
#include "dlicensedialog.h"
DWIDGET_USE_NAMESPACE
class ut_DLicenseDialog : public testing::Test
{
protected:
void SetUp() override
{
target = new DLicenseDialog();
}
void TearDown() override
{
if (target) {
delete target;
target = nullptr;
}
}
DLicenseDialog *target = nullptr;

};

TEST_F(ut_DLicenseDialog, setFile)
{
target->setFile(":/data/example-license.json");
target->load();
ASSERT_TRUE(target->isValid());
};



TEST_F(ut_DLicenseDialog, isValid)
{
target->setFile("XXXXXXX");
target->load();
ASSERT_FALSE(target->isValid());
};
60 changes: 60 additions & 0 deletions tests/testcases/widgets/ut_dswitchlineexpand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <gtest/gtest.h>
#include <QTest>

#include "dswitchlineexpand.h"

DWIDGET_USE_NAMESPACE

class ut_DSwitchLineExpand : public testing::Test
{
protected:
void SetUp() override;
void TearDown() override;
DSwitchLineExpand *target = nullptr;
QWidget *widget = nullptr;
};

void ut_DSwitchLineExpand::SetUp()
{
widget = new QWidget;
target = new DSwitchLineExpand(widget);
widget->resize(300, 200);
}

void ut_DSwitchLineExpand::TearDown()
{
widget->deleteLater();
}

TEST_F(ut_DSwitchLineExpand, testSetTitle)
{
// 测试设置标题
target->setTitle("test");
ASSERT_EQ(target->m_headerLine->title(), "test");
}

TEST_F(ut_DSwitchLineExpand, testSetExpand)
{
// 测试设置展开
target->setExpand(true);
ASSERT_TRUE(target->m_headerLine->m_switchButton->isChecked());
target->setExpand(false);
ASSERT_FALSE(target->m_headerLine->m_switchButton->isChecked());
}

TEST_F(ut_DSwitchLineExpand, testHeader)
{
// 测试获取头部
ASSERT_EQ(target->header() , target->m_headerLine);
}

TEST_F(ut_DSwitchLineExpand, testResizeEvent)
{
// 测试重置大小
target->resize(QSize(100, 100));
ASSERT_EQ(target->size(), QSize(100, 100));
}

0 comments on commit 6d76f96

Please sign in to comment.