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
17 changes: 10 additions & 7 deletions tests/app/ut_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,14 @@ TEST_F(TestDatabase, UT_Database_prepareBookmark_001)
// EXPECT_TRUE(m_tester->readBookmarks(strPath, bookmarks));
//}

//TEST_F(TestDatabase, UT_Database_saveBookmarks_001)
//{
// QString strPath = UTSOURCEDIR;
// strPath += "/files/normal.pdf";
// QSet<int> bookmarks = {0, 1};
// EXPECT_TRUE(m_tester->saveBookmarks(strPath, bookmarks));
//}
TEST_F(TestDatabase, UT_Database_saveBookmarks_001)
{
QString strPath = UTSOURCEDIR;
strPath += "/files/normal.pdf";
QSet<int> bookmarks = {0, 1};

Stub s;
s.set((bool (QSqlQuery::*)())ADDR(QSqlQuery, exec), ut_sqlquery_exec);
EXPECT_TRUE(m_tester->saveBookmarks(strPath, bookmarks));
}

14 changes: 14 additions & 0 deletions tests/widgets/ut_colorwidgetaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,17 @@ TEST_F(TestColorWidgetAction, testSeparatorProperty)
{
EXPECT_TRUE(m_tester->isSeparator());
}

TEST_F(TestColorWidgetAction, testRoundColorWidgetClickedLambda)
{
// Triggering the button click lambda (Qt6 path) inside initWidget
QWidget *defaultWidget = m_tester->defaultWidget();
ASSERT_NE(defaultWidget, nullptr);

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

QSignalSpy spy(m_tester, SIGNAL(sigBtnGroupClicked()));
emit buttons.first()->clicked();
EXPECT_EQ(spy.count(), 1);
}
52 changes: 52 additions & 0 deletions tests/widgets/ut_fileattrwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,33 @@

#include "stub.h"

#include <gtest/gtest.h>

Check warning on line 13 in tests/widgets/ut_fileattrwidget.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 14 in tests/widgets/ut_fileattrwidget.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 <QVBoxLayout>

Check warning on line 15 in tests/widgets/ut_fileattrwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 16 in tests/widgets/ut_fileattrwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 17 in tests/widgets/ut_fileattrwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 18 in tests/widgets/ut_fileattrwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 19 in tests/widgets/ut_fileattrwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

// ImageWidget is defined in FileAttrWidget.cpp as a top-level class
// deriving from DWidget. We redeclare it here so we can call setPixmap
// and paintEvent directly. Layout must match the real definition.
class ImageWidget : public DWidget
{
public:
explicit ImageWidget(DWidget *parent) : DWidget(parent) {}
void setPixmap(const QPixmap &pixmap)
{
if (!pixmap.isNull()) {
m_pixmap = pixmap;
update();
}
}
protected:
void paintEvent(QPaintEvent *event) override;
private:
QPixmap m_pixmap;
};
namespace {
class TestFileAttrWidget : public ::testing::Test
{
Expand Down Expand Up @@ -77,3 +101,31 @@
m_tester->showScreenCenter();
EXPECT_TRUE(g_funcname == "show_stub");
}

TEST_F(TestFileAttrWidget, testsizeModeChanged)
{
emit DGuiApplicationHelper::instance()->sizeModeChanged(DGuiApplicationHelper::CompactMode);
emit DGuiApplicationHelper::instance()->sizeModeChanged(DGuiApplicationHelper::NormalMode);
EXPECT_TRUE(m_tester->m_pVBoxLayout != nullptr);
}

TEST_F(TestFileAttrWidget, testImageWidgetPaintEvent)
{
// frameImage is the private ImageWidget* member created in initImageLabel().
ASSERT_NE(m_tester->frameImage, nullptr);

// Provide a non-null pixmap so paintEvent performs drawing.
QPixmap pix(20, 20);
pix.fill(Qt::red);
static_cast<ImageWidget *>(m_tester->frameImage)->setPixmap(pix);

// Force a paint event via the public repaint() slot.
m_tester->frameImage->repaint();

// Also call paintEvent directly through -fno-access-control to ensure
// the uncovered function gets executed.
QRect rect(0, 0, m_tester->frameImage->width(), m_tester->frameImage->height());
QPaintEvent event(rect);
static_cast<ImageWidget *>(m_tester->frameImage)->paintEvent(&event);
SUCCEED();
}
7 changes: 7 additions & 0 deletions tests/widgets/ut_findwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,10 @@ TEST_F(TestFindWidget, testkeyPressEvent)
EXPECT_TRUE(g_funcname == "keyPressEvent_stub");
}
}

TEST_F(TestFindWidget, testupdatePosition)
{
m_mainWidget->resize(200, 200);
m_tester->updatePosition();
SUCCEED();
}
12 changes: 12 additions & 0 deletions tests/widgets/ut_shortcutshow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,15 @@ TEST_F(UT_ShortCutShow, UT_ShortCutShow_initPDF)
EXPECT_TRUE(m_tester->m_shortcutMap.count() > 0);
}

TEST_F(UT_ShortCutShow, UT_ShortCutShow_KeyDataList_defaultConstructor)
{
ShortCutShow::KeyDataList list;
EXPECT_TRUE(list.isEmpty());

ShortCutShow::KeyDataList list2{{"Ctrl+S", "Save"}, {"Ctrl+O", "Open"}};
EXPECT_EQ(list2.count(), 2);

list2.removeKey("Ctrl+S");
EXPECT_EQ(list2.count(), 1);
}

57 changes: 57 additions & 0 deletions tests/widgets/ut_slidewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
#include "ut_compat.h"
#include <QTimer>
#include <QTest>
#include <QPropertyAnimation>

Check warning on line 20 in tests/widgets/ut_slidewidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 21 in tests/widgets/ut_slidewidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 22 in tests/widgets/ut_slidewidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

namespace {
void ReaderImageThreadPoolManager_addgetDocImageTask_stub(const ReaderImageParam_t &);
Expand Down Expand Up @@ -302,3 +304,58 @@
EXPECT_TRUE(g_funcname == "0");
}

TEST_F(TestSlideWidget, testsizeModeChanged)
{
emit DGuiApplicationHelper::instance()->sizeModeChanged(DGuiApplicationHelper::CompactMode);
emit DGuiApplicationHelper::instance()->sizeModeChanged(DGuiApplicationHelper::NormalMode);
EXPECT_TRUE(m_tester->m_slidePlayWidget != nullptr);
}

TEST_F(TestSlideWidget, testpaintEvent)
{
m_tester->resize(200, 200);
m_tester->m_offset = 0;
m_tester->m_blefttoright = true;
QPaintEvent event(QRect(0, 0, 100, 100));
m_tester->paintEvent(&event);
EXPECT_TRUE(m_tester->m_loadSpinner != nullptr);
}

TEST_F(TestSlideWidget, testmouseReleaseEvent)
{
Stub stub;
stub.set(ADDR(DocSheet, pageCount), pageCount_stub);
stub.set(ADDR(SlideWidget, playImage), playImage_stub);

QMouseEvent *event = createMouseEvent(QEvent::MouseButtonRelease, QPointF(50, 50), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
m_tester->mouseReleaseEvent(event);
delete event;
EXPECT_TRUE(g_funcname == "playImage_stub");
}

TEST_F(TestSlideWidget, testwheelEvent)
{
Stub stub;
stub.set(ADDR(DocSheet, pageCount), pageCount_stub);
stub.set(ADDR(SlideWidget, playImage), playImage_stub);

m_tester->m_curPageIndex = 2;

QPointF pos(50, 50);
int delta = 120;
Qt::MouseButtons buttons = Qt::NoButton;
Qt::KeyboardModifiers modifiers = Qt::NoModifier;
QWheelEvent *event = createWheelEvent(pos, delta, buttons, modifiers);
m_tester->wheelEvent(event);
EXPECT_TRUE(g_funcname == "playImage_stub");
delete event;
}

TEST_F(TestSlideWidget, testonImageAniFinished)
{
Stub stub;
stub.set(ADDR(DocSheet, pageCount), pageCount_stub);
m_tester->onImageAniFinished();
SUCCEED();
}

25 changes: 25 additions & 0 deletions tests/widgets/ut_texteditwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <QSignalSpy>
#include <QDebug>
#include <QTest>

#include <gtest/gtest.h>

Expand Down Expand Up @@ -67,6 +68,20 @@ TEST_F(UT_TextEditShadowWidgetayWidget, UT_TextEditShadowWidgetayWidget_slotClos
EXPECT_TRUE(m_tester->m_TextEditWidget != nullptr);
}

TEST_F(UT_TextEditShadowWidgetayWidget, UT_TextEditShadowWidgetayWidget_slotCloseNoteWidget_isEsc)
{
m_tester->showWidget(QPoint());
m_tester->slotCloseNoteWidget(true);
SUCCEED();
}

TEST_F(UT_TextEditShadowWidgetayWidget, UT_TextEditShadowWidgetayWidget_slotCloseNoteWidget_notEsc)
{
m_tester->showWidget(QPoint());
m_tester->slotCloseNoteWidget(false);
SUCCEED();
}


class TestTextEditWidget : public ::testing::Test
{
Expand Down Expand Up @@ -203,3 +218,13 @@ TEST_F(TestTextEditWidget, test_TestTextEditWidget_focusOutEvent)
EXPECT_TRUE(spy.count() == 1);
}

TEST_F(TestTextEditWidget, test_TestTextEditWidget_showMenuTimerLambda)
{
// Trigger the lambda connected to m_showMenuTimer->timeout
Stub stub;
UTCommon::stub_QWidget_isVisible(stub, false); // not visible -> early return
QMetaObject::invokeMethod(m_tester->m_showMenuTimer, "timeout");
QTest::qWait(50);
SUCCEED();
}

Loading