diff --git a/discover/autotests/CMakeLists.txt b/discover/autotests/CMakeLists.txt --- a/discover/autotests/CMakeLists.txt +++ b/discover/autotests/CMakeLists.txt @@ -1,6 +1,6 @@ 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) diff --git a/discover/autotests/PaginateModelTest.cpp b/discover/autotests/PaginateModelTest.cpp --- a/discover/autotests/PaginateModelTest.cpp +++ b/discover/autotests/PaginateModelTest.cpp @@ -20,17 +20,26 @@ #include #include "../PaginateModel.h" #include -#include +#include + +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,32 +89,32 @@ 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); pm.setSourceModel(&smallerModel); 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: - QStandardItemModel* const m_testModel; + QStringListModel* const m_testModel; }; QTEST_MAIN( PaginateModelTest )