Commit 120ee5cb authored by Dan Leinir Turthra Jensen's avatar Dan Leinir Turthra Jensen 🌈
Browse files

Don't require QtGui for the PaginateModel test

Summary:
This is done by switching from the QStandardItemModel, which requires
QtGui, to QStringListModel, which is in QtCore. The result is a much
leaner test, and it's all done by adding a couple of helper functions
which add the simplistic data addition functions from QSIM, except
locked to QStrings (the way it was being used anyway).

Test Plan: Run the tests, which still pass

Reviewers: #discover_software_store, bshah, apol

Reviewed By: #discover_software_store, apol

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24156
parent ae2a1dbd
set(plasma_discover_autotest_SRCS)
ecm_qt_declare_logging_category(plasma_discover_autotest_SRCS HEADER discover_debug.h IDENTIFIER DISCOVER_LOG CATEGORY_NAME org.kde.plasma.discover)
ecm_add_test(PaginateModelTest.cpp ../PaginateModel.cpp ${plasma_discover_autotest_SRCS} TEST_NAME PaginateModelTest LINK_LIBRARIES Qt5::Test Qt5::Gui)
ecm_add_test(PaginateModelTest.cpp ../PaginateModel.cpp ${plasma_discover_autotest_SRCS} TEST_NAME PaginateModelTest LINK_LIBRARIES Qt5::Test)
target_include_directories(PaginateModelTest PUBLIC ${CMAKE_SOURCE_DIR}/libdiscover/)
if(BUILD_DummyBackend)
......
......@@ -20,17 +20,26 @@
#include <QtTest>
#include "../PaginateModel.h"
#include <QAbstractItemModelTester>
#include <QStandardItemModel>
#include <QStringListModel>
void insertRow(QStringListModel* model, int row, const QString& appendString) {
model->insertRow(row);
model->setData(model->index(row, 0), appendString);
}
void appendRow(QStringListModel* model, const QString& appendString) {
int count = model->rowCount();
insertRow(model, count, appendString);
}
class PaginateModelTest : public QObject
{
Q_OBJECT
public:
PaginateModelTest()
: m_testModel(new QStandardItemModel)
: m_testModel(new QStringListModel)
{
for(int i=0; i<13; ++i) {
m_testModel->appendRow(new QStandardItem(QStringLiteral("figui%1").arg(i)));
appendRow(m_testModel, QStringLiteral("figui%1").arg(i));
}
}
......@@ -80,24 +89,24 @@ private Q_SLOTS:
pm.setPageSize(5);
QCOMPARE(pm.pageCount(), 3);
QSignalSpy spy(&pm, &QAbstractItemModel::rowsAboutToBeInserted);
m_testModel->insertRow(3, new QStandardItem(QStringLiteral("mwahahaha")));
m_testModel->insertRow(3, new QStandardItem(QStringLiteral("mwahahaha")));
insertRow(m_testModel, 3, QStringLiteral("mwahahaha"));
insertRow(m_testModel, 3, QStringLiteral("mwahahaha"));
QCOMPARE(spy.count(), 0);
m_testModel->appendRow(new QStandardItem(QStringLiteral("mwahahaha")));
appendRow(m_testModel, QStringLiteral("mwahahaha"));
pm.lastPage();
for (int i=0; i<7; ++i)
m_testModel->appendRow(new QStandardItem(QStringLiteral("mwahahaha%1").arg(i)));
appendRow(m_testModel, QStringLiteral("mwahahaha%1").arg(i));
QCOMPARE(spy.count(), 4);
pm.firstPage();
for (int i=0; i<7; ++i)
m_testModel->appendRow(new QStandardItem(QStringLiteral("faraway%1").arg(i)));
appendRow(m_testModel, QStringLiteral("faraway%1").arg(i));
QCOMPARE(spy.count(), 4);
}
void testItemAddBeginning() {
QStandardItemModel smallerModel;
QStringListModel smallerModel;
PaginateModel pm;
new QAbstractItemModelTester(&pm, &pm);
......@@ -105,7 +114,7 @@ private Q_SLOTS:
pm.setPageSize(5);
QCOMPARE(pm.pageCount(), 1);
QCOMPARE(pm.rowCount(), 0);
smallerModel.insertRow(0, new QStandardItem(QStringLiteral("just one")));
insertRow(&smallerModel, 0, QStringLiteral("just one"));
QCOMPARE(pm.pageCount(), 1);
QCOMPARE(pm.rowCount(), 1);
smallerModel.removeRow(0);
......@@ -138,7 +147,7 @@ private Q_SLOTS:
}
private:
QStandardItemModel* const m_testModel;
QStringListModel* const m_testModel;
};
QTEST_MAIN( PaginateModelTest )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment