1/*
2 Copyright (C) 2010 Klarälvdalens Datakonsult AB,
3 a KDAB Group company, info@kdab.net,
4 author Stephen Kelly <stephen@kdab.com>
5
6 This library is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Library General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or (at your
9 option) any later version.
10
11 This library is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301, USA.
20*/
21
22#include "proxymodeltestsuite/proxymodeltest.h"
23#include <kdescendantsproxymodel.h>
24
25#include <qapplication.h>
26#include <qdebug.h>
27
28class TestData : public ProxyModelTestData
29{
30 Q_OBJECT
31public:
32 TestData(ProxyModelTest *parent = nullptr)
33 : ProxyModelTestData(parent)
34 {
35
36 }
37
38public Q_SLOTS:
39 void testInsertWhenEmptyData() override
40 {
41 QTest::addColumn<SignalList>("signalList");
42 QTest::addColumn<PersistentChangeList>("changeList");
43
44 static const IndexFinder indexFinder;
45
46 newInsertTest(QStringLiteral("insert01"), indexFinder, 0, 0, 0);
47 newInsertTest(QStringLiteral("insert02"), indexFinder, 0, 9, 0);
48
49 // The test suite can't handle tree insertion yet, so we skip it for now.
50 skipTestData(QStringLiteral("insert03"));
51
52// processTestName("insert03");
53
54// SignalList signalList;
55// PersistentChangeList persistentList;
56
57// partialTest(&signalList, &persistentList, indexFinder, 0, 4, 0);
58// partialTest(&signalList, &persistentList, indexFinder, 1, 1, 5);
59// partialTest(&signalList, &persistentList, indexFinder, 4, 4, 6);
60// partialTest(&signalList, &persistentList, indexFinder, 7, 7, 7);
61// partialTest(&signalList, &persistentList, indexFinder, 5, 5, 8);
62
63// QTest::newRow("insert03") << signalList << persistentList;
64 }
65
66 void testInsertInRootData() override
67 {
68 QTest::addColumn<SignalList>("signalList");
69 QTest::addColumn<PersistentChangeList>("changeList");
70
71 static const IndexFinder indexFinder;
72
73 newInsertTest(QStringLiteral("insert01"), indexFinder, 0, 0, 43);
74 newInsertTest(QStringLiteral("insert02"), indexFinder, 0, 9, 43);
75 newInsertTest(QStringLiteral("insert03"), indexFinder, 43, 43, 43);
76 newInsertTest(QStringLiteral("insert04"), indexFinder, 43, 52, 43);
77 newInsertTest(QStringLiteral("insert05"), indexFinder, 7, 7, 43);
78 newInsertTest(QStringLiteral("insert06"), indexFinder, 7, 16, 43);
79 skipTestData(QStringLiteral("insert07"));
80 skipTestData(QStringLiteral("insert08"));
81 skipTestData(QStringLiteral("insert09"));
82 skipTestData(QStringLiteral("insert10"));
83 skipTestData(QStringLiteral("insert11"));
84 skipTestData(QStringLiteral("insert12"));
85 skipTestData(QStringLiteral("insert13"));
86 skipTestData(QStringLiteral("insert14"));
87 skipTestData(QStringLiteral("insert15"));
88 skipTestData(QStringLiteral("insert16"));
89 skipTestData(QStringLiteral("insert17"));
90 skipTestData(QStringLiteral("insert18"));
91 }
92
93 void testInsertInTopLevelData() override
94 {
95 QTest::addColumn<SignalList>("signalList");
96 QTest::addColumn<PersistentChangeList>("changeList");
97
98 static const IndexFinder indexFinder;
99
100 newInsertTest(QStringLiteral("insert01"), indexFinder, 9, 9, 43);
101 newInsertTest(QStringLiteral("insert02"), indexFinder, 9, 18, 43);
102 newInsertTest(QStringLiteral("insert03"), indexFinder, 37, 37, 43);
103 newInsertTest(QStringLiteral("insert04"), indexFinder, 37, 46, 43);
104 newInsertTest(QStringLiteral("insert05"), indexFinder, 15, 15, 43);
105 newInsertTest(QStringLiteral("insert06"), indexFinder, 15, 24, 43);
106 skipTestData(QStringLiteral("insert07"));
107 skipTestData(QStringLiteral("insert08"));
108 skipTestData(QStringLiteral("insert09"));
109 skipTestData(QStringLiteral("insert10"));
110 skipTestData(QStringLiteral("insert11"));
111 skipTestData(QStringLiteral("insert12"));
112 skipTestData(QStringLiteral("insert13"));
113 skipTestData(QStringLiteral("insert14"));
114 skipTestData(QStringLiteral("insert15"));
115 skipTestData(QStringLiteral("insert16"));
116 skipTestData(QStringLiteral("insert17"));
117 skipTestData(QStringLiteral("insert18"));
118 }
119
120 void testInsertInSecondLevelData() override
121 {
122 QTest::addColumn<SignalList>("signalList");
123 QTest::addColumn<PersistentChangeList>("changeList");
124
125 static const IndexFinder indexFinder;
126
127 newInsertTest(QStringLiteral("insert01"), indexFinder, 17, 17, 43);
128 newInsertTest(QStringLiteral("insert02"), indexFinder, 17, 26, 43);
129 newInsertTest(QStringLiteral("insert03"), indexFinder, 32, 32, 43);
130 newInsertTest(QStringLiteral("insert04"), indexFinder, 32, 41, 43);
131 newInsertTest(QStringLiteral("insert05"), indexFinder, 23, 23, 43);
132 newInsertTest(QStringLiteral("insert06"), indexFinder, 23, 32, 43);
133 skipTestData(QStringLiteral("insert07"));
134 skipTestData(QStringLiteral("insert08"));
135 skipTestData(QStringLiteral("insert09"));
136 skipTestData(QStringLiteral("insert10"));
137 skipTestData(QStringLiteral("insert11"));
138 skipTestData(QStringLiteral("insert12"));
139 skipTestData(QStringLiteral("insert13"));
140 skipTestData(QStringLiteral("insert14"));
141 skipTestData(QStringLiteral("insert15"));
142 skipTestData(QStringLiteral("insert16"));
143 skipTestData(QStringLiteral("insert17"));
144 skipTestData(QStringLiteral("insert18"));
145 }
146
147 void testRemoveFromRootData() override
148 {
149 QTest::addColumn<SignalList>("signalList");
150 QTest::addColumn<PersistentChangeList>("changeList");
151
152 static const IndexFinder indexFinder;
153
154 newRemoveTest(QStringLiteral("remove01"), indexFinder, 0, 0, 43);
155 newRemoveTest(QStringLiteral("remove02"), indexFinder, 0, 7, 43);
156 newRemoveTest(QStringLiteral("remove03"), indexFinder, 42, 42, 43);
157 }
158
159 void testRemoveFromTopLevelData() override
160 {
161 QTest::addColumn<SignalList>("signalList");
162 QTest::addColumn<PersistentChangeList>("changeList");
163
164 static const IndexFinder indexFinder;
165
166 newRemoveTest(QStringLiteral("remove01"), indexFinder, 9, 9, 43);
167 newRemoveTest(QStringLiteral("remove02"), indexFinder, 9, 15, 43);
168 newRemoveTest(QStringLiteral("remove03"), indexFinder, 36, 36, 43);
169 }
170
171 void testRemoveFromSecondLevelData() override
172 {
173 QTest::addColumn<SignalList>("signalList");
174 QTest::addColumn<PersistentChangeList>("changeList");
175
176 static const IndexFinder indexFinder;
177
178 newRemoveTest(QStringLiteral("remove01"), indexFinder, 17, 17, 43);
179 newRemoveTest(QStringLiteral("remove02"), indexFinder, 17, 23, 43);
180 newRemoveTest(QStringLiteral("remove03"), indexFinder, 31, 31, 43);
181 }
182
183 void testMoveFromRootData() override
184 {
185 dummyTestData();
186 }
187
188 void testMoveFromTopLevelData() override
189 {
190 dummyTestData();
191 }
192
193 void testMoveFromSecondLevelData() override
194 {
195 dummyTestData();
196 }
197
198 void testModifyInRootData() override
199 {
200 dummyTestData();
201 }
202
203 void testModifyInTopLevelData() override
204 {
205 dummyTestData();
206 }
207
208 void testModifyInSecondLevelData() override
209 {
210 dummyTestData();
211 }
212
213};
214
215class DescendantsProxyModelTest : public ProxyModelTest
216{
217 Q_OBJECT
218public:
219 DescendantsProxyModelTest(QObject *parent = nullptr)
220 : ProxyModelTest(parent)
221 {
222 }
223
224 void setTestData(TestData *data)
225 {
226 qDebug() << data;
227 connectTestSignals(data);
228 }
229
230protected:
231 QAbstractProxyModel *getProxy() override
232 {
233 return new KDescendantsProxyModel(this);
234 }
235
236private Q_SLOTS:
237 void cleanupTestCase()
238 {
239 doCleanupTestCase();
240 }
241
242 void cleanup()
243 {
244 doCleanup();
245 }
246
247private:
248 KDescendantsProxyModel *m_proxyModel;
249};
250
251PROXYMODELTEST_MAIN(DescendantsProxyModelTest,
252 PROXYMODELTEST_CUSTOM(new TestData, DynamicTree, ImmediatePersistence, "")
253 PROXYMODELTEST_CUSTOM(new TestData, DynamicTree, LazyPersistence, "")
254 PROXYMODELTEST_CUSTOM(new TestData, IntermediateProxy, ImmediatePersistence, "")
255 PROXYMODELTEST_CUSTOM(new TestData, IntermediateProxy, LazyPersistence, "")
256 )
257
258#include "kdescendantsproxymodel_smoketest.moc"
259