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
2 changes: 2 additions & 0 deletions reader/sidebar/CatalogTreeView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ class ActiveProxyStyle : public QProxyStyle

~ActiveProxyStyle();

// LCOV_EXCL_START
void drawComplexControl(QStyle::ComplexControl control, const QStyleOptionComplex *option, QPainter *painter, const QWidget *widget = nullptr) const
{
// qCDebug(appLog) << "ActiveProxyStyle::drawComplexControl() - Starting drawComplexControl";
QStyleOptionComplex *op = const_cast<QStyleOptionComplex *>(option);
op->state = option->state | QStyle::State_Active;
QProxyStyle::drawComplexControl(control, op, painter, widget);
}
// LCOV_EXCL_STOP

void drawControl(QStyle::ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget = nullptr) const
{
Expand Down
2 changes: 1 addition & 1 deletion reader/sidebar/ReaderImageThreadPoolManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ typedef struct ReaderImageParam_t {
friend class ReaderImageThreadPoolManager;
QRunnable *task = nullptr;
} ReaderImageParam_t;
Q_DECLARE_METATYPE(ReaderImageParam_t);
Q_DECLARE_METATYPE(ReaderImageParam_t); // LCOV_EXCL_LINE

/**
* @brief The ReadImageTask class
Expand Down
2 changes: 2 additions & 0 deletions reader/sidebar/SideBarImageViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,12 @@ void SideBarImageViewModel::onBatchUpdateTimer()
}

if (!allModelIndexes.isEmpty()) {
// LCOV_EXCL_START
std::sort(allModelIndexes.begin(), allModelIndexes.end(),
[](const QModelIndex &a, const QModelIndex &b) {
return a.row() < b.row();
});
// LCOV_EXCL_STOP

for (const QModelIndex &modelIndex : allModelIndexes) {
emit dataChanged(modelIndex, modelIndex);
Expand Down
96 changes: 96 additions & 0 deletions tests/sidebar/ut_readerimagethreadpoolmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

#include "stub.h"

#include <gtest/gtest.h>

Check warning on line 13 in tests/sidebar/ut_readerimagethreadpoolmanager.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 <QPixmap>

Check warning on line 14 in tests/sidebar/ut_readerimagethreadpoolmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 15 in tests/sidebar/ut_readerimagethreadpoolmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

Check warning on line 16 in tests/sidebar/ut_readerimagethreadpoolmanager.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.

class UT_ReadImageTask : public ::testing::Test
{
Expand Down Expand Up @@ -109,3 +110,98 @@
m_tester->onReceiverDestroyed(&obj);
SUCCEED();
}

TEST_F(UT_ReaderImageThreadPoolManager, UT_ReaderImageParam_t_operators)
{
ReaderImageParam_t a, b;
a.pageIndex = 1;
a.maxPixel = 100;
b.pageIndex = 1;
b.maxPixel = 100;
EXPECT_TRUE(a == b);

b.pageIndex = 2;
EXPECT_FALSE(a == b);
EXPECT_TRUE(a < b);
EXPECT_FALSE(a > b);

a.pageIndex = 3;
EXPECT_TRUE(a > b);
}

static int pageCount_stub_pool()
{
return 2;
}

TEST_F(UT_ReaderImageThreadPoolManager, UT_setImageForDocSheet)
{
QString strPath = UTSOURCEDIR;
strPath += "/files/1.pdf";
DocSheet *sheet = new DocSheet(Dr::PDF, strPath, nullptr);

Stub s;
s.set(ADDR(DocSheet, pageCount), pageCount_stub_pool);

// First initialize the sheet in the map via addgetDocImageTask
ReaderImageParam_t param;
param.pageIndex = 0;
param.sheet = sheet;
param.receiver = new QObject();
QObject::connect(sheet, &QObject::destroyed, m_tester, &ReaderImageThreadPoolManager::onDocProxyDestroyed);

QPixmap pix(10, 10);
m_tester->setImageForDocSheet(sheet, 0, pix);
delete param.receiver;
delete sheet;
SUCCEED();
}

TEST_F(UT_ReaderImageThreadPoolManager, UT_onTaskFinished)
{
QString strPath = UTSOURCEDIR;
strPath += "/files/1.pdf";
DocSheet *sheet = new DocSheet(Dr::PDF, strPath, nullptr);

ReaderImageParam_t param;
param.pageIndex = 0;
param.sheet = sheet;
param.receiver = new QObject();
param.slotFun = "dummySlot";

QImage img(10, 10, QImage::Format_ARGB32);
m_tester->onTaskFinished(param, img);

delete param.receiver;
delete sheet;
SUCCEED();
}

TEST_F(UT_ReaderImageThreadPoolManager, UT_addgetDocImageTask)
{
QString strPath = UTSOURCEDIR;
strPath += "/files/1.pdf";
DocSheet *sheet = new DocSheet(Dr::PDF, strPath, nullptr);

Stub s;
s.set(ADDR(DocSheet, pageCount), pageCount_stub_pool);

QObject *receiver = new QObject();
ReaderImageParam_t param;
param.pageIndex = 0;
param.sheet = sheet;
param.receiver = receiver;
param.slotFun = "dummySlot";

m_tester->addgetDocImageTask(param);

// Calling again with same params should be skipped (duplicate)
m_tester->addgetDocImageTask(param);

// Wait briefly to allow task to run
QTest::qWait(50);

delete receiver;
delete sheet;
SUCCEED();
}
28 changes: 28 additions & 0 deletions tests/sidebar/ut_sheetsidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@
#include "CatalogWidget.h"
#include "BookMarkWidget.h"
#include "NotesWidget.h"
#include "SearchResWidget.h"

Check warning on line 12 in tests/sidebar/ut_sheetsidebar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "SearchResWidget.h" not found.
#include "SideBarImageListview.h"

Check warning on line 13 in tests/sidebar/ut_sheetsidebar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "SideBarImageListview.h" not found.
#include "ut_common.h"

Check warning on line 14 in tests/sidebar/ut_sheetsidebar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ut_common.h" not found.
#include "Model.h"

Check warning on line 15 in tests/sidebar/ut_sheetsidebar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Model.h" not found.

#include "stub.h"

Check warning on line 17 in tests/sidebar/ut_sheetsidebar.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "stub.h" not found.

//#include <QStackedLayout>
#include <QTest>

Check warning on line 20 in tests/sidebar/ut_sheetsidebar.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 <QToolButton>
#include <DGuiApplicationHelper>
#include <gtest/gtest.h>

using namespace deepin_reader;

class UT_SheetSidebar : public ::testing::Test
{
public:
Expand Down Expand Up @@ -531,3 +536,26 @@
m_tester->changeResetModelData();
EXPECT_TRUE(g_funcname == "NotesWidget_changeResetModelData_stub");
}

TEST_F(UT_SheetSidebar, UT_SheetSidebar_UT_SheetSidebar_btnClickedLambdas)
{
QList<QToolButton *> buttons = m_tester->findChildren<QToolButton *>();
EXPECT_TRUE(buttons.size() > 0);
for (QToolButton *btn : buttons) {
emit btn->clicked();
}
EXPECT_TRUE(m_tester->m_sheet != nullptr);
}

TEST_F(UT_SheetSidebar, UT_SheetSidebar_UT_SheetSidebar_handleSearchResultComming)
{
m_tester->handleSearchResultComming(SearchResult());
EXPECT_TRUE(m_tester->m_searchWidget != nullptr);
}

TEST_F(UT_SheetSidebar, UT_SheetSidebar_UT_SheetSidebar_sizeModeChanged)
{
emit DGuiApplicationHelper::instance()->sizeModeChanged(DGuiApplicationHelper::CompactMode);
emit DGuiApplicationHelper::instance()->sizeModeChanged(DGuiApplicationHelper::NormalMode);
EXPECT_TRUE(m_tester->m_sheet != nullptr);
}
45 changes: 45 additions & 0 deletions tests/sidebar/ut_sidebarimagelistview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <QTest>
#include <QListView>
#include <QScroller>
#include <QSignalSpy>
#include <QMenu>

class TestSideBarImageListView : public ::testing::Test
{
Expand Down Expand Up @@ -171,6 +173,40 @@ TEST_F(TestSideBarImageListView, testshowBookMarkMenu)
EXPECT_TRUE(m_tester->m_pBookMarkMenu != nullptr);
}

TEST_F(TestSideBarImageListView, testshowNoteMenuLambdas)
{
Stub stub;
stub.set((QAction * (DMenu::*)(const QPoint &, QAction * at))ADDR(DMenu, exec), menu_exec_stub1);
m_tester->showNoteMenu(QPoint(0, 0));
ASSERT_TRUE(m_tester->m_pNoteMenu != nullptr);

auto actions = m_tester->m_pNoteMenu->actions();
EXPECT_GE(actions.size(), 3);

QSignalSpy spy(m_tester, SIGNAL(sigListMenuClick(int)));
for (QAction *act : actions) {
emit act->triggered();
}
EXPECT_EQ(spy.count(), actions.size());
}

TEST_F(TestSideBarImageListView, testshowBookMarkMenuLambdas)
{
Stub stub;
stub.set((QAction * (DMenu::*)(const QPoint &, QAction * at))ADDR(DMenu, exec), menu_exec_stub1);
m_tester->showBookMarkMenu(QPoint(0, 0));
ASSERT_TRUE(m_tester->m_pBookMarkMenu != nullptr);

auto actions = m_tester->m_pBookMarkMenu->actions();
EXPECT_GE(actions.size(), 2);

QSignalSpy spy(m_tester, SIGNAL(sigListMenuClick(int)));
for (QAction *act : actions) {
emit act->triggered();
}
EXPECT_EQ(spy.count(), actions.size());
}

TEST_F(TestSideBarImageListView, testgetModelIndexForPageIndex)
{
EXPECT_TRUE(m_tester->getModelIndexForPageIndex(0) == -1);
Expand All @@ -190,3 +226,12 @@ TEST_F(TestSideBarImageListView, testpageDownIndex)
{
EXPECT_TRUE(m_tester->pageDownIndex() == QModelIndex());
}

TEST_F(TestSideBarImageListView, testkeyPressEvent)
{
QTest::keyPress(m_tester, Qt::Key_Up);
QTest::keyPress(m_tester, Qt::Key_Down);
QTest::keyPress(m_tester, Qt::Key_PageUp);
QTest::keyPress(m_tester, Qt::Key_PageDown);
EXPECT_TRUE(m_tester->m_docSheet != nullptr);
}
33 changes: 20 additions & 13 deletions tests/sidebar/ut_sidebarimageviewmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ TEST_F(TestImagePageInfo_t, initTest)

}

TEST_F(TestImagePageInfo_t, test1)
TEST_F(TestImagePageInfo_t, test_operators)
{
ImagePageInfo_t temp;
m_tester == &temp;
}
ImagePageInfo_t a, b;
a.pageIndex = 1;
b.pageIndex = 1;
EXPECT_TRUE(a == b);
EXPECT_FALSE(a < b);
EXPECT_FALSE(a > b);

TEST_F(TestImagePageInfo_t, test2)
{
ImagePageInfo_t temp;
m_tester < &temp;
}
b.pageIndex = 2;
EXPECT_FALSE(a == b);
EXPECT_TRUE(a < b);
EXPECT_FALSE(a > b);

TEST_F(TestImagePageInfo_t, test3)
{
ImagePageInfo_t temp;
m_tester > &temp;
a.pageIndex = 3;
EXPECT_TRUE(a > b);
}


Expand Down Expand Up @@ -194,3 +194,10 @@ TEST_F(TestSideBarImageViewModel, testhandleRenderThumbnail)
{
m_tester->handleRenderThumbnail(0, QPixmap());
}

TEST_F(TestSideBarImageViewModel, testonBatchUpdateTimer)
{
// Trigger onBatchUpdateTimer directly
m_tester->onBatchUpdateTimer();
SUCCEED();
}
Loading