File indexing completed on 2024-12-08 06:40:51

0001 /*
0002     SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "kselectionproxymodeltestsuite.h"
0008 
0009 #include <kselectionproxymodel.h>
0010 
0011 #include "modelselector.h"
0012 
0013 // BEGIN NoSelection
0014 
0015 /**
0016   When there is no selection, everything from the source model should be a noop in the proxy.
0017 */
0018 template<KSelectionProxyModel::FilterBehavior _filterBehaviour>
0019 class TestData<NoSelectionStrategy, _filterBehaviour> : public NoSelectionStrategy
0020 {
0021 public:
0022     TestData(ProxyModelTest *proxyModelTest)
0023         : NoSelectionStrategy(proxyModelTest)
0024         , m_proxyModelTest(proxyModelTest)
0025     {
0026     }
0027 
0028     // If there is no selection, changes in the source model have no effect.
0029     void noselection_testMoveData()
0030     {
0031         QTest::addColumn<SignalList>("signalList");
0032         QTest::addColumn<PersistentChangeList>("changeList");
0033         noopTest("move01");
0034         noopTest("move02");
0035         noopTest("move03");
0036         noopTest("move04");
0037         noopTest("move05");
0038     }
0039 
0040     KSelectionProxyModel::FilterBehavior filterBehaviour()
0041     {
0042         return _filterBehaviour;
0043     }
0044 
0045     void testInsertWhenEmptyData() override
0046     {
0047         noop_testInsertWhenEmptyData();
0048     }
0049     void testInsertInRootData() override
0050     {
0051         noop_testInsertInRootData();
0052     }
0053     void testInsertInTopLevelData() override
0054     {
0055         noop_testInsertInTopLevelData();
0056     }
0057     void testInsertInSecondLevelData() override
0058     {
0059         noop_testInsertInSecondLevelData();
0060     }
0061 
0062     void testRemoveFromRootData() override
0063     {
0064         noop_testRemoveFromRootData();
0065     }
0066     void testRemoveFromTopLevelData() override
0067     {
0068         noop_testRemoveFromTopLevelData();
0069     }
0070     void testRemoveFromSecondLevelData() override
0071     {
0072         noop_testRemoveFromSecondLevelData();
0073     }
0074 
0075     void testMoveFromRootData() override
0076     {
0077         noselection_testMoveData();
0078     }
0079     void testMoveFromTopLevelData() override
0080     {
0081         noselection_testMoveData();
0082     }
0083     void testMoveFromSecondLevelData() override
0084     {
0085         noselection_testMoveData();
0086     }
0087 
0088     void testModifyInRootData() override
0089     {
0090         noop_testModifyInRootData();
0091     }
0092     void testModifyInTopLevelData() override
0093     {
0094         noop_testModifyInTopLevelData();
0095     }
0096     void testModifyInSecondLevelData() override
0097     {
0098         noop_testModifyInSecondLevelData();
0099     }
0100 
0101 private:
0102     ProxyModelTest *m_proxyModelTest;
0103 };
0104 
0105 // END NoSelection
0106 
0107 // BEGIN ImmediateSelectionStrategy
0108 
0109 // BEGIN ChildrenOfExactSelection
0110 template<>
0111 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testInsertWhenEmptyData()
0112 {
0113     noop_testInsertWhenEmptyData();
0114 }
0115 
0116 template<>
0117 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testInsertInRootData()
0118 {
0119     noop_testInsertInRootData();
0120 }
0121 
0122 template<>
0123 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testInsertInTopLevelData()
0124 {
0125     QTest::addColumn<SignalList>("signalList");
0126     QTest::addColumn<PersistentChangeList>("changeList");
0127 
0128     IndexFinder indexFinder;
0129 
0130     newInsertTest(QStringLiteral("insert01"), indexFinder, 0, 0, 10);
0131     newInsertTest(QStringLiteral("insert02"), indexFinder, 0, 9, 10);
0132     newInsertTest(QStringLiteral("insert03"), indexFinder, 10, 10, 10);
0133     newInsertTest(QStringLiteral("insert04"), indexFinder, 10, 19, 10);
0134     newInsertTest(QStringLiteral("insert05"), indexFinder, 4, 4, 10);
0135     newInsertTest(QStringLiteral("insert06"), indexFinder, 4, 13, 10);
0136     newInsertTest(QStringLiteral("insert07"), indexFinder, 0, 0, 10);
0137     newInsertTest(QStringLiteral("insert08"), indexFinder, 10, 10, 10);
0138     newInsertTest(QStringLiteral("insert09"), indexFinder, 4, 4, 10);
0139     newInsertTest(QStringLiteral("insert10"), indexFinder, 0, 4, 10);
0140     newInsertTest(QStringLiteral("insert11"), indexFinder, 10, 14, 10);
0141     newInsertTest(QStringLiteral("insert12"), indexFinder, 4, 8, 10);
0142     noopTest(QStringLiteral("insert13"));
0143     noopTest(QStringLiteral("insert14"));
0144     noopTest(QStringLiteral("insert15"));
0145     noopTest(QStringLiteral("insert16"));
0146     noopTest(QStringLiteral("insert17"));
0147     noopTest(QStringLiteral("insert18"));
0148 }
0149 
0150 template<>
0151 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testInsertInSecondLevelData()
0152 {
0153     noop_testInsertInSecondLevelData();
0154 }
0155 
0156 template<>
0157 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testRemoveFromRootData()
0158 {
0159     noop_testRemoveFromRootData();
0160 }
0161 
0162 template<>
0163 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testRemoveFromTopLevelData()
0164 {
0165     QTest::addColumn<SignalList>("signalList");
0166     QTest::addColumn<PersistentChangeList>("changeList");
0167 
0168     IndexFinder indexFinder;
0169 
0170     newRemoveTest(QStringLiteral("remove01"), indexFinder, 0, 0, 10);
0171     newRemoveTest(QStringLiteral("remove02"), indexFinder, 0, 4, 10);
0172     newRemoveTest(QStringLiteral("remove03"), indexFinder, 9, 9, 10);
0173 }
0174 
0175 template<>
0176 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testRemoveFromSecondLevelData()
0177 {
0178     noop_testRemoveFromSecondLevelData();
0179 }
0180 
0181 template<>
0182 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testMoveFromRootData()
0183 {
0184     noop_testMoveFromRootData();
0185 }
0186 
0187 template<>
0188 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testMoveFromTopLevelData()
0189 {
0190     IndexFinder indexFinder;
0191     testForwardingMoveData(indexFinder, indexFinder);
0192 }
0193 
0194 template<>
0195 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testMoveFromSecondLevelData()
0196 {
0197     noop_testMoveFromSecondLevelData();
0198 }
0199 
0200 template<>
0201 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testModifyInRootData()
0202 {
0203     noop_testModifyInRootData();
0204 }
0205 
0206 template<>
0207 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testModifyInTopLevelData()
0208 {
0209     QTest::addColumn<SignalList>("signalList");
0210     QTest::addColumn<PersistentChangeList>("changeList");
0211     newModifyTest(QStringLiteral("modify01"), IndexFinder(), 0, 0);
0212     newModifyTest(QStringLiteral("modify02"), IndexFinder(), 0, 4);
0213     newModifyTest(QStringLiteral("modify03"), IndexFinder(), 9, 9);
0214     newModifyTest(QStringLiteral("modify04"), IndexFinder(), 6, 9);
0215     newModifyTest(QStringLiteral("modify05"), IndexFinder(), 4, 4);
0216     newModifyTest(QStringLiteral("modify06"), IndexFinder(), 3, 7);
0217     newModifyTest(QStringLiteral("modify07"), IndexFinder(), 0, 9);
0218 }
0219 
0220 template<>
0221 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ChildrenOfExactSelection>::testModifyInSecondLevelData()
0222 {
0223     noop_testModifyInSecondLevelData();
0224 }
0225 
0226 // END ChildrenOfExactSelection
0227 
0228 // BEGIN ExactSelection
0229 template<>
0230 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testInsertWhenEmptyData()
0231 {
0232     QTest::addColumn<SignalList>("signalList");
0233     QTest::addColumn<PersistentChangeList>("changeList");
0234 
0235     IndexFinder indexFinder;
0236 
0237     noopTest(QStringLiteral("insert01"));
0238     newInsertTest(QStringLiteral("insert02"), indexFinder, 0, 0, 0);
0239     newInsertTest(QStringLiteral("insert03"), indexFinder, 0, 0, 0);
0240 }
0241 
0242 template<>
0243 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testInsertInRootData()
0244 {
0245     noop_testInsertInRootData();
0246 }
0247 
0248 template<>
0249 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testInsertInTopLevelData()
0250 {
0251     noop_testInsertInTopLevelData();
0252 }
0253 
0254 template<>
0255 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testInsertInSecondLevelData()
0256 {
0257     noop_testInsertInSecondLevelData();
0258 }
0259 
0260 template<>
0261 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testRemoveFromRootData()
0262 {
0263     noop_testRemoveFromRootData();
0264 }
0265 
0266 template<>
0267 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testRemoveFromTopLevelData()
0268 {
0269     noop_testRemoveFromTopLevelData();
0270 }
0271 
0272 template<>
0273 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testRemoveFromSecondLevelData()
0274 {
0275     noop_testRemoveFromSecondLevelData();
0276 }
0277 
0278 template<>
0279 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testMoveFromRootData()
0280 {
0281     noop_testMoveFromRootData();
0282 }
0283 
0284 template<>
0285 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testMoveFromTopLevelData()
0286 {
0287     noop_testMoveFromTopLevelData();
0288 }
0289 
0290 template<>
0291 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testMoveFromSecondLevelData()
0292 {
0293     noop_testMoveFromSecondLevelData();
0294 }
0295 
0296 template<>
0297 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testModifyInRootData()
0298 {
0299     QTest::addColumn<SignalList>("signalList");
0300     QTest::addColumn<PersistentChangeList>("changeList");
0301     noopTest(QStringLiteral("modify01"));
0302     noopTest(QStringLiteral("modify02"));
0303     noopTest(QStringLiteral("modify03"));
0304     noopTest(QStringLiteral("modify04"));
0305     noopTest(QStringLiteral("modify05"));
0306     newModifyTest(QStringLiteral("modify06"), IndexFinder(), 0, 0);
0307     newModifyTest(QStringLiteral("modify07"), IndexFinder(), 0, 0);
0308 }
0309 
0310 template<>
0311 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testModifyInTopLevelData()
0312 {
0313     noop_testModifyInTopLevelData();
0314 }
0315 
0316 template<>
0317 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::ExactSelection>::testModifyInSecondLevelData()
0318 {
0319     noop_testModifyInSecondLevelData();
0320 }
0321 
0322 // END ExactSelection
0323 
0324 // BEGIN SubTrees
0325 template<>
0326 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testInsertWhenEmptyData()
0327 {
0328     QTest::addColumn<SignalList>("signalList");
0329     QTest::addColumn<PersistentChangeList>("changeList");
0330 
0331     IndexFinder indexFinder;
0332 
0333     noopTest(QStringLiteral("insert01"));
0334     newInsertTest(QStringLiteral("insert02"), indexFinder, 0, 0, 0);
0335     newInsertTest(QStringLiteral("insert03"), indexFinder, 0, 0, 0);
0336 }
0337 
0338 template<>
0339 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testInsertInRootData()
0340 {
0341     noop_testInsertInRootData();
0342 }
0343 
0344 template<>
0345 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testInsertInTopLevelData()
0346 {
0347     testForwardingInsertData(IndexFinder(QList<int>() << 0));
0348 }
0349 
0350 template<>
0351 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testInsertInSecondLevelData()
0352 {
0353     testForwardingInsertData(IndexFinder(QList<int>() << 0 << 5));
0354 }
0355 
0356 template<>
0357 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testRemoveFromRootData()
0358 {
0359     noop_testRemoveFromRootData();
0360 }
0361 
0362 template<>
0363 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testRemoveFromTopLevelData()
0364 {
0365     testForwardingRemoveData(IndexFinder(QList<int>() << 0));
0366 }
0367 
0368 template<>
0369 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testRemoveFromSecondLevelData()
0370 {
0371     testForwardingRemoveData(IndexFinder(QList<int>() << 0 << 5));
0372 }
0373 
0374 template<>
0375 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testMoveFromRootData()
0376 {
0377     noop_testMoveFromRootData();
0378 }
0379 
0380 template<>
0381 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testMoveFromTopLevelData()
0382 {
0383     testForwardingMoveData(IndexFinder(QList<int>() << 0), IndexFinder(QList<int>() << 0));
0384 }
0385 
0386 template<>
0387 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testMoveFromSecondLevelData()
0388 {
0389     testForwardingMoveData(IndexFinder(QList<int>() << 0 << 5), IndexFinder(QList<int>() << 0 << 5));
0390 }
0391 
0392 template<>
0393 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testModifyInRootData()
0394 {
0395     QTest::addColumn<SignalList>("signalList");
0396     QTest::addColumn<PersistentChangeList>("changeList");
0397     noopTest(QStringLiteral("modify01"));
0398     noopTest(QStringLiteral("modify02"));
0399     noopTest(QStringLiteral("modify03"));
0400     noopTest(QStringLiteral("modify04"));
0401     noopTest(QStringLiteral("modify05"));
0402     newModifyTest(QStringLiteral("modify06"), IndexFinder(), 0, 0);
0403     newModifyTest(QStringLiteral("modify07"), IndexFinder(), 0, 0);
0404 }
0405 
0406 template<>
0407 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testModifyInTopLevelData()
0408 {
0409     testForwardingModifyData(IndexFinder(QList<int>() << 0));
0410 }
0411 
0412 template<>
0413 void TestData<ImmediateSelectionStrategy<9>, KSelectionProxyModel::SubTrees>::testModifyInSecondLevelData()
0414 {
0415     testForwardingModifyData(IndexFinder(QList<int>() << 0 << 5));
0416 }
0417 
0418 // END SubTrees
0419 
0420 // END ImmediateSelectionStrategy
0421 
0422 /* clang-format off */
0423 PROXYMODELTEST_MAIN(SelectionProxyModelTest,
0424                     SELECTIONPROXYMODELSIMPLETEST(NoSelectionStrategy, KSelectionProxyModel::ChildrenOfExactSelection)
0425                     SELECTIONPROXYMODELSIMPLETEST(NoSelectionStrategy, KSelectionProxyModel::ExactSelection)
0426                     SELECTIONPROXYMODELSIMPLETEST(NoSelectionStrategy, KSelectionProxyModel::SubTreeRoots)
0427                     SELECTIONPROXYMODELSIMPLETEST(NoSelectionStrategy, KSelectionProxyModel::SubTrees)
0428                     SELECTIONPROXYMODELSIMPLETEST(NoSelectionStrategy, KSelectionProxyModel::SubTreesWithoutRoots)
0429 
0430                     SELECTIONCOMPLETETEST1(ImmediateSelectionStrategy, 9, KSelectionProxyModel::ChildrenOfExactSelection)
0431                     SELECTIONCOMPLETETEST1(ImmediateSelectionStrategy, 9, KSelectionProxyModel::ExactSelection)
0432                     SELECTIONCOMPLETETEST1(ImmediateSelectionStrategy, 9, KSelectionProxyModel::SubTrees)
0433                    )
0434 /* clang-format on */