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
47 changes: 47 additions & 0 deletions tests/app/ut_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,50 @@
EXPECT_TRUE(m_tester->saveBookmarks(strPath, bookmarks));
}


TEST_F(TestDatabase, UT_Database_prepareTabGroup_001)
{
QSqlQuery drop(m_tester->m_database);
drop.exec("DROP TABLE IF EXISTS tabgroup");

Check warning on line 148 in tests/app/ut_database.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function drop.exec() is not used.
EXPECT_TRUE(m_tester->prepareTabGroup()); // 全新建表
EXPECT_FALSE(m_tester->prepareTabGroup()); // 表已存在
}

TEST_F(TestDatabase, UT_Database_tabGroup_001)
{
QSqlQuery drop(m_tester->m_database);
drop.exec("DROP TABLE IF EXISTS tabgroup");

Check warning on line 156 in tests/app/ut_database.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Error code from the return value of function drop.exec() is not used.
ASSERT_TRUE(m_tester->prepareTabGroup());

EXPECT_TRUE(m_tester->saveTabGroup(0, QStringList() << "/tmp/a.pdf" << "/tmp/b.pdf" << "/tmp/c.pdf", 1));

int activeIndex = -1;
QStringList files = m_tester->readTabGroup(0, activeIndex);
EXPECT_EQ(files.size(), 3);
EXPECT_EQ(activeIndex, 1);
EXPECT_TRUE(files.contains("/tmp/b.pdf"));

// 覆盖旧记录后仅剩 1 条
EXPECT_TRUE(m_tester->saveTabGroup(0, QStringList() << "/tmp/d.pdf", 0));
files = m_tester->readTabGroup(0, activeIndex);
EXPECT_EQ(files.size(), 1);
EXPECT_EQ(activeIndex, 0);

EXPECT_TRUE(m_tester->clearTabGroup(0));
files = m_tester->readTabGroup(0, activeIndex);
EXPECT_TRUE(files.isEmpty());
}

TEST_F(TestDatabase, UT_Database_cleanupOrphanStates_001)
{
// 构造一条指向不存在文件的阅读记录(不在 /media、/mnt、/run/media 下)
QString orphanPath = "/tmp/deepin_reader_ut_orphan_cleanup.pdf";
QFile::remove(orphanPath);
DocSheet orphanSheet(Dr::FileType::PDF, orphanPath, nullptr);
EXPECT_TRUE(m_tester->saveOperation(&orphanSheet));

int cleaned = m_tester->cleanupOrphanStates();
EXPECT_GE(cleaned, 1);
// 孤儿记录已被清理,再次执行返回 0
EXPECT_EQ(m_tester->cleanupOrphanStates(), 0);
}
11 changes: 11 additions & 0 deletions tests/browser/ut_browserpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,14 @@ TEST_F(TestBrowserPage, UT_BrowserPage_isBigDoc_001)
s.set(A_foo, boundingRect_stub2);
EXPECT_TRUE(m_tester->isBigDoc());
}

TEST_F(TestBrowserPage, UT_BrowserPage_applyNightMode_001)
{
QPixmap nullPix;
EXPECT_TRUE(m_tester->applyNightMode(nullPix).isNull());

QPixmap src(16, 16);
src.fill(Qt::white);
QPixmap dst = m_tester->applyNightMode(src);
EXPECT_FALSE(dst.isNull());
}
20 changes: 20 additions & 0 deletions tests/browser/ut_sheetbrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "SheetBrowser.h"

Check warning on line 6 in tests/browser/ut_sheetbrowser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "SheetBrowser.h" not found.
#include "EyeProtectionManager.h"

Check warning on line 7 in tests/browser/ut_sheetbrowser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "EyeProtectionManager.h" not found.
#include <QScrollBar>

Check warning on line 8 in tests/browser/ut_sheetbrowser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 9 in tests/browser/ut_sheetbrowser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "BrowserPage.h" not found.
#include "BrowserWord.h"

Check warning on line 10 in tests/browser/ut_sheetbrowser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "BrowserWord.h" not found.
#include "BrowserMenu.h"

Check warning on line 11 in tests/browser/ut_sheetbrowser.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "BrowserMenu.h" not found.
#include "BrowserMagniFier.h"
#include "BrowserAnnotation.h"
#include "SheetRenderer.h"
Expand Down Expand Up @@ -2648,3 +2650,21 @@
qDeleteAll(g_QGraphicsItemList);
g_QGraphicsItemList.clear();
}

TEST_F(TestSheetBrowser, UT_SheetBrowser_restoreScrollPosition_001)
{
// 滚动范围未就绪分支
m_tester->restoreScrollPosition(0.5f);
SUCCEED();
}

TEST_F(TestSheetBrowser, UT_SheetBrowser_eyeProtectionMode_lambda_001)
{
EyeProtectionManager::Mode prev = EyeProtectionManager::instance()->mode();
EyeProtectionManager::Mode next = (EyeProtectionManager::Off == prev)
? EyeProtectionManager::Classic : EyeProtectionManager::Off;
// 触发构造函数中注册的护眼模式变化 lambda
EyeProtectionManager::instance()->setMode(next);
EyeProtectionManager::instance()->setMode(prev);
SUCCEED();
}
6 changes: 6 additions & 0 deletions tests/document/ut_djvumodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,9 @@ TEST_F(TestDjVuDocument, UT_TestDjVuDocument_searchAllPagesForText)
}
EXPECT_GT(searchesRun, 0);
}

TEST_F(TestDjVuDocument, UT_DjVuDocument_fileIdentifier_001)
{
// 基类 Document::fileIdentifier 默认实现返回空串
EXPECT_TRUE(m_tester->fileIdentifier().isEmpty());
}
6 changes: 6 additions & 0 deletions tests/document/ut_pdfmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,3 +760,9 @@ TEST_F(TestPDFDocument, UT_PDFDocument_loadDocument_001)
EXPECT_TRUE(m_tester->loadDocument(filePath, password, error) == nullptr);
EXPECT_TRUE(error == Document::WrongPassword);
}

TEST_F(TestPDFDocument, UT_PDFDocument_fileIdentifier_001)
{
QString id1 = m_tester->fileIdentifier();
EXPECT_TRUE(id1 == m_tester->fileIdentifier());
}
77 changes: 77 additions & 0 deletions tests/eyeprotection/ut_eyeprotection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "EyeProtectionManager.h"

Check warning on line 5 in tests/eyeprotection/ut_eyeprotection.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "EyeProtectionManager.h" not found.
#include "EyeProtectionAction.h"

Check warning on line 6 in tests/eyeprotection/ut_eyeprotection.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "EyeProtectionAction.h" not found.
#include "RoundColorWidget.h"
#include "SheetBrowser.h"

#include <DWidget>
#include <QSignalSpy>

#include <gtest/gtest.h>

DWIDGET_USE_NAMESPACE

/********测试EyeProtectionManager/EyeProtectionAction***********/
class UT_EyeProtection : public ::testing::Test
{
public:
virtual void SetUp();

virtual void TearDown();

protected:
DWidget *m_parent = nullptr;
};

void UT_EyeProtection::SetUp()
{
m_parent = new DWidget;
}

void UT_EyeProtection::TearDown()
{
EyeProtectionManager::instance()->setMode(EyeProtectionManager::Off);
delete m_parent;
}

TEST_F(UT_EyeProtection, UT_EyeProtectionManager_colors_001)
{
EXPECT_TRUE(EyeProtectionManager::instance()->pageBackgroundColor().isValid());
EXPECT_TRUE(EyeProtectionManager::instance()->foregroundColor().isValid());
}

TEST_F(UT_EyeProtection, UT_EyeProtectionManager_setMode_001)
{
QSignalSpy spy(EyeProtectionManager::instance(), &EyeProtectionManager::modeChanged);

EyeProtectionManager::instance()->setMode(EyeProtectionManager::Classic);
EXPECT_TRUE(EyeProtectionManager::instance()->mode() == EyeProtectionManager::Classic);
EXPECT_EQ(spy.count(), 1);

// 相同模式早退分支
EyeProtectionManager::instance()->setMode(EyeProtectionManager::Classic);
EXPECT_EQ(spy.count(), 1);
}

TEST_F(UT_EyeProtection, UT_EyeProtectionAction_onModeChanged_001)
{
EyeProtectionAction action(m_parent);

EyeProtectionManager::instance()->setMode(EyeProtectionManager::Green);
action.onModeChanged(3);

RoundColorWidget *btn = action.defaultWidget()->findChild<RoundColorWidget *>("eye_2");
ASSERT_NE(btn, nullptr);
emit btn->clicked(); // initWidget 中 connect 的 lambda -> onBtnClicked
EXPECT_TRUE(EyeProtectionManager::instance()->mode() == EyeProtectionManager::Green);
}

TEST_F(UT_EyeProtection, UT_SheetBrowser_eyeModeLambda_001)
{
SheetBrowser browser;
EyeProtectionManager::instance()->setMode(EyeProtectionManager::Night);
EXPECT_TRUE(EyeProtectionManager::instance()->mode() == EyeProtectionManager::Night);
}
24 changes: 24 additions & 0 deletions tests/sidebar/ut_catalogtreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <gtest/gtest.h>
#include <QTest>
#include <QListView>
#include <QStandardItemModel>

class TestCatalogTreeView : public ::testing::Test
{
Expand Down Expand Up @@ -200,3 +201,26 @@ TEST_F(TestCatalogTreeView, testkeyPressEvent_direct)
m_tester->keyPressEvent(&event);
EXPECT_FALSE(m_tester->rightnotifypagechanged);
}

TEST_F(TestCatalogTreeView, testGetAndRestoreExpandedSections)
{
QStandardItemModel *model = new QStandardItemModel(m_tester);
QStandardItem *root1 = new QStandardItem("Chapter1");
QStandardItem *child1 = new QStandardItem("Section1");
root1->appendRow(child1);
QStandardItem *root2 = new QStandardItem("Chapter2");
model->appendRow(root1);
model->appendRow(root2);
m_tester->setModel(model);

m_tester->expand(model->indexFromItem(root1));
QStringList sections = m_tester->getExpandedSections();
EXPECT_TRUE(sections.contains("Chapter1"));

// 空列表分支
m_tester->restoreExpandedSections(QStringList());

m_tester->collapseAll();
m_tester->restoreExpandedSections(sections);
EXPECT_TRUE(m_tester->isExpanded(model->indexFromItem(root1)));
}
10 changes: 10 additions & 0 deletions tests/sidebar/ut_catalogwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,13 @@ TEST_F(UT_CatalogWidget, UT_CatalogWidget_pageUp)
m_tester->pageUp();
EXPECT_TRUE(m_tester->m_pTree != nullptr);
}

TEST_F(UT_CatalogWidget, UT_CatalogWidget_expandedSections_001)
{
EXPECT_TRUE(m_tester->m_pTree != nullptr);
QStringList sections = m_tester->getExpandedSections();
EXPECT_TRUE(sections.isEmpty());
m_tester->restoreExpandedSections(QStringList());
m_tester->restoreExpandedSections(QStringList() << "Chapter1");
SUCCEED();
}
8 changes: 8 additions & 0 deletions tests/sidebar/ut_sheetsidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,11 @@ TEST_F(UT_SheetSidebar, UT_SheetSidebar_UT_SheetSidebar_sizeModeChanged)
emit DGuiApplicationHelper::instance()->sizeModeChanged(DGuiApplicationHelper::NormalMode);
EXPECT_TRUE(m_tester->m_sheet != nullptr);
}

TEST_F(UT_SheetSidebar, UT_SheetSidebar_expandedSections_001)
{
QStringList sections = m_tester->getExpandedSections();
EXPECT_TRUE(sections.isEmpty());
m_tester->restoreExpandedSections(QStringList() << "Chapter1");
SUCCEED();
}
10 changes: 10 additions & 0 deletions tests/sidebar/ut_sidebarimagelistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
#include <QListView>
#include <QScroller>
#include <QSignalSpy>
#include <DGuiApplicationHelper>
#include <QMenu>

DGUI_USE_NAMESPACE

class TestSideBarImageListView : public ::testing::Test
{
public:
Expand Down Expand Up @@ -235,3 +238,10 @@ TEST_F(TestSideBarImageListView, testkeyPressEvent)
QTest::keyPress(m_tester, Qt::Key_PageDown);
EXPECT_TRUE(m_tester->m_docSheet != nullptr);
}

TEST_F(TestSideBarImageListView, testThemeChanged_lambda)
{
// 触发构造函数中注册的主题切换 lambda(刷新缩略图)
emit DGuiApplicationHelper::instance()->themeTypeChanged(DGuiApplicationHelper::LightType);
SUCCEED();
}
21 changes: 21 additions & 0 deletions tests/uiframe/ut_central.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "TitleMenu.h"
#include "MainWindow.h"
#include "CentralDocPage.h"
#include "RestoreTipWidget.h"
#include "ShortCutShow.h"
#include "TitleWidget.h"
#include "stub.h"
Expand Down Expand Up @@ -618,3 +619,23 @@ TEST_F(TestCentral, UT_Central_resizeEvent_001)
EXPECT_TRUE(g_funcName == "resizeEvent_stub");
delete event;
}

TEST_F(TestCentral, UT_Central_docPage_sigShowRestoreTip_lambda_001)
{
CentralDocPage *docPage = m_tester->docPage();
ASSERT_NE(docPage, nullptr);
ASSERT_NE(m_tester->m_restoreTipWidget, nullptr);
// 无当前 sheet 分支
emit docPage->sigShowRestoreTip(nullptr);
SUCCEED();
}

TEST_F(TestCentral, UT_Central_jumpToFirstPage_lambda_001)
{
m_tester->docPage();
RestoreTipWidget *tip = m_tester->m_restoreTipWidget;
ASSERT_NE(tip, nullptr);
// m_docPage 存在但当前无 sheet
emit tip->sigJumpToFirstPage();
SUCCEED();
}
7 changes: 7 additions & 0 deletions tests/uiframe/ut_centraldocpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,3 +1368,10 @@ TEST_F(TestCentralDocPage, UT_CentralDocPage_onCentralMoveIn_invoke)

// Note: isFullScreen/openFullScreen require MainWindow in parent hierarchy
// which is not available in this test fixture - skipping to avoid crash.

TEST_F(TestCentralDocPage, UT_CentralDocPage_setActiveTabByFilePath_001)
{
m_tester->setActiveTabByFilePath(QString());
m_tester->setActiveTabByFilePath("/tmp/ut_not_exist_active_file.pdf");
SUCCEED();
}
Loading
Loading