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
75 changes: 75 additions & 0 deletions tests/document/ut_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,78 @@ TEST(UT_DocumentFactory_getDocument, UT_DocumentFactory_getDocument_004)
EXPECT_TRUE(process == nullptr);
EXPECT_EQ(error, Document::FileError);
}

// SearchResult helper tests
TEST(UT_SearchResult, sectionBoundingRectEmptySection)
{
PageSection empty;
QRectF rect = SearchResult::sectionBoundingRect(empty);
EXPECT_TRUE(rect.isNull());
}

TEST(UT_SearchResult, sectionBoundingRectSingleLine)
{
PageSection section;
PageLine line;
line.rect = QRectF(10, 20, 100, 30);
section.append(line);

QRectF rect = SearchResult::sectionBoundingRect(section);
EXPECT_EQ(rect, QRectF(10, 20, 100, 30));
}

TEST(UT_SearchResult, sectionBoundingRectMultipleLines)
{
PageSection section;
PageLine l1;
l1.rect = QRectF(0, 0, 50, 10);
PageLine l2;
l2.rect = QRectF(20, 30, 60, 15);
section.append(l1);
section.append(l2);

QRectF rect = SearchResult::sectionBoundingRect(section);
EXPECT_EQ(rect, QRectF(0, 0, 80, 45));
}

TEST(UT_SearchResult, setctionsFillTextEmptySections)
{
SearchResult result;
result.page = 1;
bool ok = result.setctionsFillText([](int, QRectF) { return QString("text"); });
EXPECT_FALSE(ok);
}

TEST(UT_SearchResult, setctionsFillTextWithContent)
{
SearchResult result;
result.page = 2; // page is 1-based, so index is 1

PageSection section;
PageLine line;
line.rect = QRectF(0, 0, 10, 10);
section.append(line);
result.sections.append(section);

bool ok = result.setctionsFillText([](int index, QRectF) {
EXPECT_EQ(index, 1);
return QString("filled");
});
EXPECT_TRUE(ok);
EXPECT_EQ(result.sections.at(0).at(0).text, QString("filled"));
}

TEST(UT_SearchResult, setctionsFillTextEmptyCallbackReturnsFalse)
{
SearchResult result;
result.page = 1;

PageSection section;
PageLine line;
line.rect = QRectF(0, 0, 10, 10);
section.append(line);
result.sections.append(section);

bool ok = result.setctionsFillText([](int, QRectF) { return QString(); });
EXPECT_FALSE(ok);
}
8 changes: 8 additions & 0 deletions tests/sidebar/ut_thumbnaildelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,11 @@ TEST_F(UT_ThumbnailDelegate, UT_ThumbnailDelegate_drawBookMark)
EXPECT_TRUE(m_pView != nullptr);
delete painter;
}

TEST_F(UT_ThumbnailDelegate, UT_ThumbnailDelegate_drawBookMarkNotVisible)
{
QPainter *painter = new QPainter();
m_tester->drawBookMark(painter, m_pView->geometry(), false);
SUCCEED();
delete painter;
}
45 changes: 43 additions & 2 deletions tests/widgets/ut_colorwidgetaction.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// Copyright (C) 2019-2026 ~ 2020 UnionTech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "ColorWidgetAction.h"

Check warning on line 6 in tests/widgets/ut_colorwidgetaction.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ColorWidgetAction.h" not found.
#include "RoundColorWidget.h"

Check warning on line 7 in tests/widgets/ut_colorwidgetaction.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "RoundColorWidget.h" not found.
#include "Utils.h"

Check warning on line 8 in tests/widgets/ut_colorwidgetaction.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Utils.h" not found.

#include "stub.h"

Check warning on line 10 in tests/widgets/ut_colorwidgetaction.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "stub.h" not found.

#include <gtest/gtest.h>
#include <QTest>
Expand Down Expand Up @@ -34,7 +36,6 @@

TEST_F(TestColorWidgetAction, initTest)
{

}

TEST_F(TestColorWidgetAction, testslotBtnClicked)
Expand All @@ -43,3 +44,43 @@
m_tester->slotBtnClicked(0);
EXPECT_EQ(spy.count(), 1);
}

TEST_F(TestColorWidgetAction, testslotBtnClickedAllIndices)
{
// Color list has 8 colors per Utils::getHiglightColorList()
int colorCount = Utils::getHiglightColorList().size();
ASSERT_GT(colorCount, 0);

QColor lastSelectedColor;
for (int i = 0; i < colorCount; ++i) {
QSignalSpy spy(m_tester, SIGNAL(sigBtnGroupClicked()));
m_tester->slotBtnClicked(i);
EXPECT_EQ(spy.count(), 1);
lastSelectedColor = Utils::getHiglightColorList().at(i);
}

// After iterating all buttons, the current color should match last selection
EXPECT_EQ(Utils::getCurHiglightColor(), lastSelectedColor);
}

TEST_F(TestColorWidgetAction, testslotBtnClickedInvalidIndex)
{
// Invalid index should not crash and should not emit signal
QSignalSpy spy(m_tester, SIGNAL(sigBtnGroupClicked()));
m_tester->slotBtnClicked(999);
EXPECT_EQ(spy.count(), 0);
}

TEST_F(TestColorWidgetAction, testDefaultWidgetPopulated)
{
QWidget *defaultWidget = m_tester->defaultWidget();
ASSERT_NE(defaultWidget, nullptr);

auto buttons = defaultWidget->findChildren<RoundColorWidget *>();
EXPECT_GE(buttons.size(), 1);
}

TEST_F(TestColorWidgetAction, testSeparatorProperty)
{
EXPECT_TRUE(m_tester->isSeparator());
}
66 changes: 64 additions & 2 deletions tests/widgets/ut_securitydialog.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// Copyright (C) 2019-2026 ~ 2020 UnionTech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
Expand All @@ -7,8 +7,11 @@

#include "stub.h"

#include <gtest/gtest.h>

Check warning on line 10 in tests/widgets/ut_securitydialog.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.
#include <QTest>

Check warning on line 11 in tests/widgets/ut_securitydialog.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.
#include <QSignalSpy>

Check warning on line 12 in tests/widgets/ut_securitydialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 13 in tests/widgets/ut_securitydialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 14 in tests/widgets/ut_securitydialog.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

class TestSecurityDialog : public ::testing::Test
{
Expand All @@ -18,7 +21,7 @@
public:
virtual void SetUp()
{
m_tester = new SecurityDialog("123456789");
m_tester = new SecurityDialog("https://example.com/path?query=1");
m_tester->disconnect();
}

Expand All @@ -33,6 +36,65 @@

TEST_F(TestSecurityDialog, initTest)
{
}

TEST_F(TestSecurityDialog, testDialogInitialProperties)
{
EXPECT_EQ(m_tester->minimumWidth(), 380);
EXPECT_GE(m_tester->buttonCount(), 2);
}

TEST_F(TestSecurityDialog, testChangeEventFontChange)
{
QEvent event(QEvent::FontChange);
m_tester->changeEvent(&event);
SUCCEED();
}

TEST_F(TestSecurityDialog, testChangeEventThemeChange)
{
QEvent event(QEvent::ThemeChange);
m_tester->changeEvent(&event);
SUCCEED();
}

TEST_F(TestSecurityDialog, testChangeEventOther)
{
QEvent event(QEvent::None);
m_tester->changeEvent(&event);
SUCCEED();
}

// Free function tests
TEST(UT_autoCutText, emptyTextReturnsEmpty)
{
DLabel label;
NewStr result = autoCutText(QString(), &label);
EXPECT_TRUE(result.resultStr.isEmpty());
EXPECT_TRUE(result.strList.isEmpty());
}

TEST(UT_autoCutText, nullLabelReturnsEmpty)
{
NewStr result = autoCutText("hello world", nullptr);
EXPECT_TRUE(result.resultStr.isEmpty());
}

TEST(UT_autoCutText, shortTextNoWrap)
{
DLabel label;
label.setFixedWidth(1000); // Wide enough that no wrapping is needed
NewStr result = autoCutText("hi", &label);
EXPECT_EQ(result.resultStr, QString("hi"));
EXPECT_EQ(result.strList.size(), 1);
EXPECT_GT(result.fontHeifht, 0);
}

TEST(UT_autoCutText, longTextWraps)
{
DLabel label;
label.setFixedWidth(20); // Very narrow, forcing wrap
NewStr result = autoCutText("this is some long text that should wrap", &label);
EXPECT_FALSE(result.resultStr.isEmpty());
EXPECT_GE(result.strList.size(), 1);
}
Loading