Changeset View
Changeset View
Standalone View
Standalone View
discover/autotests/PaginateModelTest.cpp
Show All 14 Lines | |||||
15 | * License along with this program; if not, write to the | 15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | 16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include <QtTest> | 20 | #include <QtTest> | ||
21 | #include "../PaginateModel.h" | 21 | #include "../PaginateModel.h" | ||
22 | #include <QAbstractItemModelTester> | 22 | #include <QAbstractItemModelTester> | ||
23 | #include <QStandardItemModel> | 23 | #include <QStringListModel> | ||
24 | | ||||
25 | void insertRow(QStringListModel* model, int row, const QString& appendString) { | ||||
26 | model->insertRow(row); | ||||
27 | model->setData(model->index(row, 0), appendString); | ||||
28 | } | ||||
29 | void appendRow(QStringListModel* model, const QString& appendString) { | ||||
30 | int count = model->rowCount(); | ||||
31 | insertRow(model, count, appendString); | ||||
32 | } | ||||
24 | 33 | | |||
25 | class PaginateModelTest : public QObject | 34 | class PaginateModelTest : public QObject | ||
26 | { | 35 | { | ||
27 | Q_OBJECT | 36 | Q_OBJECT | ||
28 | public: | 37 | public: | ||
29 | PaginateModelTest() | 38 | PaginateModelTest() | ||
30 | : m_testModel(new QStandardItemModel) | 39 | : m_testModel(new QStringListModel) | ||
31 | { | 40 | { | ||
32 | for(int i=0; i<13; ++i) { | 41 | for(int i=0; i<13; ++i) { | ||
33 | m_testModel->appendRow(new QStandardItem(QStringLiteral("figui%1").arg(i))); | 42 | appendRow(m_testModel, QStringLiteral("figui%1").arg(i)); | ||
34 | } | 43 | } | ||
35 | } | 44 | } | ||
36 | 45 | | |||
37 | private Q_SLOTS: | 46 | private Q_SLOTS: | ||
38 | void testPages() { | 47 | void testPages() { | ||
39 | PaginateModel pm; | 48 | PaginateModel pm; | ||
40 | new QAbstractItemModelTester(&pm, &pm); | 49 | new QAbstractItemModelTester(&pm, &pm); | ||
41 | pm.setSourceModel(m_testModel); | 50 | pm.setSourceModel(m_testModel); | ||
Show All 33 Lines | |||||
75 | 84 | | |||
76 | void testItemAdded() { | 85 | void testItemAdded() { | ||
77 | PaginateModel pm; | 86 | PaginateModel pm; | ||
78 | new QAbstractItemModelTester(&pm, &pm); | 87 | new QAbstractItemModelTester(&pm, &pm); | ||
79 | pm.setSourceModel(m_testModel); | 88 | pm.setSourceModel(m_testModel); | ||
80 | pm.setPageSize(5); | 89 | pm.setPageSize(5); | ||
81 | QCOMPARE(pm.pageCount(), 3); | 90 | QCOMPARE(pm.pageCount(), 3); | ||
82 | QSignalSpy spy(&pm, &QAbstractItemModel::rowsAboutToBeInserted); | 91 | QSignalSpy spy(&pm, &QAbstractItemModel::rowsAboutToBeInserted); | ||
83 | m_testModel->insertRow(3, new QStandardItem(QStringLiteral("mwahahaha"))); | 92 | insertRow(m_testModel, 3, QStringLiteral("mwahahaha")); | ||
84 | m_testModel->insertRow(3, new QStandardItem(QStringLiteral("mwahahaha"))); | 93 | insertRow(m_testModel, 3, QStringLiteral("mwahahaha")); | ||
85 | QCOMPARE(spy.count(), 0); | 94 | QCOMPARE(spy.count(), 0); | ||
86 | m_testModel->appendRow(new QStandardItem(QStringLiteral("mwahahaha"))); | 95 | appendRow(m_testModel, QStringLiteral("mwahahaha")); | ||
87 | 96 | | |||
88 | pm.lastPage(); | 97 | pm.lastPage(); | ||
89 | for (int i=0; i<7; ++i) | 98 | for (int i=0; i<7; ++i) | ||
90 | m_testModel->appendRow(new QStandardItem(QStringLiteral("mwahahaha%1").arg(i))); | 99 | appendRow(m_testModel, QStringLiteral("mwahahaha%1").arg(i)); | ||
91 | QCOMPARE(spy.count(), 4); | 100 | QCOMPARE(spy.count(), 4); | ||
92 | pm.firstPage(); | 101 | pm.firstPage(); | ||
93 | 102 | | |||
94 | for (int i=0; i<7; ++i) | 103 | for (int i=0; i<7; ++i) | ||
95 | m_testModel->appendRow(new QStandardItem(QStringLiteral("faraway%1").arg(i))); | 104 | appendRow(m_testModel, QStringLiteral("faraway%1").arg(i)); | ||
96 | QCOMPARE(spy.count(), 4); | 105 | QCOMPARE(spy.count(), 4); | ||
97 | } | 106 | } | ||
98 | 107 | | |||
99 | void testItemAddBeginning() { | 108 | void testItemAddBeginning() { | ||
100 | QStandardItemModel smallerModel; | 109 | QStringListModel smallerModel; | ||
101 | 110 | | |||
102 | PaginateModel pm; | 111 | PaginateModel pm; | ||
103 | new QAbstractItemModelTester(&pm, &pm); | 112 | new QAbstractItemModelTester(&pm, &pm); | ||
104 | pm.setSourceModel(&smallerModel); | 113 | pm.setSourceModel(&smallerModel); | ||
105 | pm.setPageSize(5); | 114 | pm.setPageSize(5); | ||
106 | QCOMPARE(pm.pageCount(), 1); | 115 | QCOMPARE(pm.pageCount(), 1); | ||
107 | QCOMPARE(pm.rowCount(), 0); | 116 | QCOMPARE(pm.rowCount(), 0); | ||
108 | smallerModel.insertRow(0, new QStandardItem(QStringLiteral("just one"))); | 117 | insertRow(&smallerModel, 0, QStringLiteral("just one")); | ||
109 | QCOMPARE(pm.pageCount(), 1); | 118 | QCOMPARE(pm.pageCount(), 1); | ||
110 | QCOMPARE(pm.rowCount(), 1); | 119 | QCOMPARE(pm.rowCount(), 1); | ||
111 | smallerModel.removeRow(0); | 120 | smallerModel.removeRow(0); | ||
112 | QCOMPARE(pm.pageCount(), 1); | 121 | QCOMPARE(pm.pageCount(), 1); | ||
113 | QCOMPARE(pm.rowCount(), 0); | 122 | QCOMPARE(pm.rowCount(), 0); | ||
114 | } | 123 | } | ||
115 | 124 | | |||
116 | void testItemRemoved() { | 125 | void testItemRemoved() { | ||
Show All 16 Lines | 141 | void testMove() { | |||
133 | PaginateModel pm; | 142 | PaginateModel pm; | ||
134 | new QAbstractItemModelTester(&pm, &pm); | 143 | new QAbstractItemModelTester(&pm, &pm); | ||
135 | pm.setSourceModel(m_testModel); | 144 | pm.setSourceModel(m_testModel); | ||
136 | pm.setPageSize(5); | 145 | pm.setPageSize(5); | ||
137 | m_testModel->moveRow({}, 0, {}, 3); | 146 | m_testModel->moveRow({}, 0, {}, 3); | ||
138 | } | 147 | } | ||
139 | 148 | | |||
140 | private: | 149 | private: | ||
141 | QStandardItemModel* const m_testModel; | 150 | QStringListModel* const m_testModel; | ||
142 | }; | 151 | }; | ||
143 | 152 | | |||
144 | QTEST_MAIN( PaginateModelTest ) | 153 | QTEST_MAIN( PaginateModelTest ) | ||
145 | 154 | | |||
146 | #include "PaginateModelTest.moc" | 155 | #include "PaginateModelTest.moc" |