File indexing completed on 2024-11-10 04:40:18
0001 /* 0002 SPDX-FileCopyrightText: 2014 Christian Mollekopf <mollekopf@kolabsys.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QObject> 0008 0009 #include "private/scope_p.h" 0010 0011 #include "aktest.h" 0012 #include "dbinitializer.h" 0013 #include "entities.h" 0014 #include "fakeakonadiserver.h" 0015 #include "storage/storagedebugger.h" 0016 0017 #include <QTest> 0018 0019 using namespace Akonadi; 0020 using namespace Akonadi::Server; 0021 0022 class CollectionFetchHandlerTest : public QObject 0023 { 0024 Q_OBJECT 0025 0026 FakeAkonadiServer mAkonadi; 0027 0028 public: 0029 CollectionFetchHandlerTest() 0030 : QObject() 0031 { 0032 mAkonadi.setPopulateDb(false); 0033 mAkonadi.init(); 0034 { 0035 MimeType mt(QStringLiteral("mimetype1")); 0036 mt.insert(); 0037 } 0038 { 0039 MimeType mt(QStringLiteral("mimetype2")); 0040 mt.insert(); 0041 } 0042 { 0043 MimeType mt(QStringLiteral("mimetype3")); 0044 mt.insert(); 0045 } 0046 { 0047 MimeType mt(QStringLiteral("mimetype4")); 0048 mt.insert(); 0049 } 0050 } 0051 0052 Protocol::FetchCollectionsCommandPtr 0053 createCommand(const Scope &scope, 0054 Protocol::FetchCollectionsCommand::Depth depth = Akonadi::Protocol::FetchCollectionsCommand::BaseCollection, 0055 Protocol::Ancestor::Depth ancDepth = Protocol::Ancestor::NoAncestor, 0056 const QStringList &mimeTypes = QStringList(), 0057 const QString &resource = QString()) 0058 { 0059 auto cmd = Protocol::FetchCollectionsCommandPtr::create(scope); 0060 cmd->setDepth(depth); 0061 cmd->setAncestorsDepth(ancDepth); 0062 cmd->setMimeTypes(mimeTypes); 0063 cmd->setResource(resource); 0064 return cmd; 0065 } 0066 0067 QScopedPointer<DbInitializer> initializer; 0068 private Q_SLOTS: 0069 0070 void testList_data() 0071 { 0072 initializer.reset(new DbInitializer); 0073 Resource res = initializer->createResource("testresource"); 0074 Collection col1 = initializer->createCollection("col1"); 0075 Collection col2 = initializer->createCollection("col2", col1); 0076 Collection col3 = initializer->createCollection("col3", col2); 0077 Collection col4 = initializer->createCollection("col4"); 0078 0079 QTest::addColumn<TestScenario::List>("scenarios"); 0080 0081 { 0082 TestScenario::List scenarios; 0083 scenarios << FakeAkonadiServer::loginScenario() 0084 << TestScenario::create(5, TestScenario::ClientCmd, createCommand(Scope(), Protocol::FetchCollectionsCommand::AllCollections)) 0085 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(initializer->collection("Search"))) 0086 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0087 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0088 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col3)) 0089 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col4)) 0090 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0091 QTest::newRow("recursive list") << scenarios; 0092 } 0093 { 0094 TestScenario::List scenarios; 0095 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, createCommand(col1.id())) 0096 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0097 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0098 QTest::newRow("base list") << scenarios; 0099 } 0100 { 0101 TestScenario::List scenarios; 0102 scenarios << FakeAkonadiServer::loginScenario() 0103 << TestScenario::create(5, TestScenario::ClientCmd, createCommand(col1.id(), Protocol::FetchCollectionsCommand::ParentCollection)) 0104 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0105 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0106 QTest::newRow("first level list") << scenarios; 0107 } 0108 { 0109 TestScenario::List scenarios; 0110 scenarios << FakeAkonadiServer::loginScenario() 0111 << TestScenario::create(5, TestScenario::ClientCmd, createCommand(col1.id(), Protocol::FetchCollectionsCommand::AllCollections)) 0112 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0113 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col3)) 0114 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0115 QTest::newRow("recursive list that filters collection") << scenarios; 0116 } 0117 { 0118 TestScenario::List scenarios; 0119 scenarios << FakeAkonadiServer::loginScenario() 0120 << TestScenario::create(5, 0121 TestScenario::ClientCmd, 0122 createCommand(col2.id(), Protocol::FetchCollectionsCommand::BaseCollection, Protocol::Ancestor::AllAncestors)) 0123 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2, true)) 0124 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0125 QTest::newRow("base ancestors") << scenarios; 0126 } 0127 { 0128 TestScenario::List scenarios; 0129 scenarios << FakeAkonadiServer::loginScenario() 0130 << TestScenario::create(5, 0131 TestScenario::ClientCmd, 0132 createCommand(col2.id(), Protocol::FetchCollectionsCommand::BaseCollection, Protocol::Ancestor::AllAncestors)) 0133 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2, true)) 0134 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0135 QTest::newRow("first level ancestors") << scenarios; 0136 } 0137 { 0138 TestScenario::List scenarios; 0139 scenarios << FakeAkonadiServer::loginScenario() 0140 << TestScenario::create(5, 0141 TestScenario::ClientCmd, 0142 createCommand(col1.id(), Protocol::FetchCollectionsCommand::AllCollections, Protocol::Ancestor::AllAncestors)) 0143 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2, true)) 0144 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col3, true)) 0145 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0146 QTest::newRow("recursive ancestors") << scenarios; 0147 } 0148 { 0149 TestScenario::List scenarios; 0150 scenarios << FakeAkonadiServer::loginScenario() 0151 << TestScenario::create(5, TestScenario::ClientCmd, createCommand(Scope(), Protocol::FetchCollectionsCommand::ParentCollection)) 0152 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(initializer->collection("Search"))) 0153 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0154 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col4)) 0155 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0156 QTest::newRow("first level root list") << scenarios; 0157 } 0158 } 0159 0160 void testList() 0161 { 0162 QFETCH(TestScenario::List, scenarios); 0163 0164 mAkonadi.setScenarios(scenarios); 0165 mAkonadi.runTest(); 0166 } 0167 0168 void testListFiltered_data() 0169 { 0170 initializer.reset(new DbInitializer); 0171 0172 MimeType mtCalendar(QStringLiteral("text/calendar")); 0173 mtCalendar.insert(); 0174 0175 Resource res = initializer->createResource("testresource"); 0176 Collection col1 = initializer->createCollection("col1"); 0177 col1.update(); 0178 Collection col2 = initializer->createCollection("col2", col1); 0179 col2.addMimeType(mtCalendar); 0180 col2.update(); 0181 0182 QTest::addColumn<TestScenario::List>("scenarios"); 0183 0184 { 0185 TestScenario::List scenarios; 0186 scenarios << FakeAkonadiServer::loginScenario() 0187 << TestScenario::create(5, 0188 TestScenario::ClientCmd, 0189 createCommand(Scope(), 0190 Protocol::FetchCollectionsCommand::AllCollections, 0191 Protocol::Ancestor::NoAncestor, 0192 {QLatin1StringView("text/calendar")})) 0193 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1, false, false)) 0194 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0195 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0196 QTest::newRow("recursive list to display including local override") << scenarios; 0197 } 0198 } 0199 0200 void testListFiltered() 0201 { 0202 QFETCH(TestScenario::List, scenarios); 0203 0204 mAkonadi.setScenarios(scenarios); 0205 mAkonadi.runTest(); 0206 } 0207 0208 void testListFilterByResource() 0209 { 0210 initializer.reset(new DbInitializer); 0211 0212 Resource res2; 0213 res2.setName(QStringLiteral("testresource2")); 0214 QVERIFY(res2.insert()); 0215 0216 Resource res = initializer->createResource("testresource"); 0217 Collection col1 = initializer->createCollection("col1"); 0218 0219 Collection col2; 0220 col2.setName(QStringLiteral("col2")); 0221 col2.setRemoteId(QStringLiteral("col2")); 0222 col2.setResource(res2); 0223 QVERIFY(col2.insert()); 0224 0225 TestScenario::List scenarios; 0226 scenarios << FakeAkonadiServer::loginScenario() 0227 << TestScenario::create(5, 0228 TestScenario::ClientCmd, 0229 createCommand(Scope(), 0230 Protocol::FetchCollectionsCommand::AllCollections, 0231 Protocol::Ancestor::NoAncestor, 0232 {}, 0233 QStringLiteral("testresource"))) 0234 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0235 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0236 0237 mAkonadi.setScenarios(scenarios); 0238 mAkonadi.runTest(); 0239 0240 col2.remove(); 0241 res2.remove(); 0242 } 0243 0244 void testListEnabled_data() 0245 { 0246 initializer.reset(new DbInitializer); 0247 Resource res = initializer->createResource("testresource"); 0248 Collection col1 = initializer->createCollection("col1"); 0249 Collection col2 = initializer->createCollection("col2", col1); 0250 col2.setEnabled(false); 0251 col2.setSyncPref(Collection::True); 0252 col2.setDisplayPref(Collection::True); 0253 col2.setIndexPref(Collection::True); 0254 col2.update(); 0255 Collection col3 = initializer->createCollection("col3", col2); 0256 col3.setEnabled(true); 0257 col3.setSyncPref(Collection::False); 0258 col3.setDisplayPref(Collection::False); 0259 col3.setIndexPref(Collection::False); 0260 col3.update(); 0261 0262 QTest::addColumn<TestScenario::List>("scenarios"); 0263 0264 { 0265 TestScenario::List scenarios; 0266 0267 auto cmd = createCommand(col3.id()); 0268 cmd->setDisplayPref(true); 0269 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, cmd) 0270 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col3)) 0271 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0272 // Listing a disabled collection should still work for base listing 0273 QTest::newRow("list base of disabled collection") << scenarios; 0274 } 0275 { 0276 TestScenario::List scenarios; 0277 0278 auto cmd = createCommand(Scope(), Protocol::FetchCollectionsCommand::AllCollections); 0279 cmd->setDisplayPref(true); 0280 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, cmd) 0281 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(initializer->collection("Search"))) 0282 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0283 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0284 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0285 QTest::newRow("recursive list to display including local override") << scenarios; 0286 } 0287 { 0288 TestScenario::List scenarios; 0289 0290 auto cmd = createCommand(Scope(), Protocol::FetchCollectionsCommand::AllCollections); 0291 cmd->setSyncPref(true); 0292 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, cmd) 0293 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(initializer->collection("Search"))) 0294 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0295 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0296 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0297 QTest::newRow("recursive list to sync including local override") << scenarios; 0298 } 0299 { 0300 TestScenario::List scenarios; 0301 0302 auto cmd = createCommand(Scope(), Protocol::FetchCollectionsCommand::AllCollections); 0303 cmd->setIndexPref(true); 0304 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, cmd) 0305 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(initializer->collection("Search"))) 0306 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0307 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0308 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0309 QTest::newRow("recursive list to index including local override") << scenarios; 0310 } 0311 { 0312 TestScenario::List scenarios; 0313 0314 auto cmd = createCommand(Scope(), Protocol::FetchCollectionsCommand::AllCollections); 0315 cmd->setEnabled(true); 0316 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, cmd) 0317 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(initializer->collection("Search"))) 0318 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0319 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0320 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col3)) 0321 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0322 QTest::newRow("recursive list of enabled") << scenarios; 0323 } 0324 } 0325 0326 void testListEnabled() 0327 { 0328 QFETCH(TestScenario::List, scenarios); 0329 0330 mAkonadi.setScenarios(scenarios); 0331 mAkonadi.runTest(); 0332 } 0333 0334 void testListAttribute_data() 0335 { 0336 initializer.reset(new DbInitializer); 0337 Resource res = initializer->createResource("testresource"); 0338 Collection col1 = initializer->createCollection("col1"); 0339 Collection col2 = initializer->createCollection("col2"); 0340 0341 CollectionAttribute attr1; 0342 attr1.setType("type"); 0343 attr1.setValue("value"); 0344 attr1.setCollection(col1); 0345 attr1.insert(); 0346 0347 CollectionAttribute attr2; 0348 attr2.setType("type"); 0349 attr2.setValue(QStringLiteral("Umlautäöü").toUtf8()); 0350 attr2.setCollection(col2); 0351 attr2.insert(); 0352 0353 QTest::addColumn<TestScenario::List>("scenarios"); 0354 0355 { 0356 TestScenario::List scenarios; 0357 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, createCommand(col1.id())) 0358 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1, false, true)) 0359 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0360 QTest::newRow("list attribute") << scenarios; 0361 } 0362 0363 { 0364 TestScenario::List scenarios; 0365 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, createCommand(col2.id())) 0366 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2, false, true)) 0367 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0368 QTest::newRow("list attribute") << scenarios; 0369 } 0370 } 0371 0372 void testListAttribute() 0373 { 0374 QFETCH(TestScenario::List, scenarios); 0375 0376 mAkonadi.setScenarios(scenarios); 0377 mAkonadi.runTest(); 0378 } 0379 0380 void testListAncestorAttributes_data() 0381 { 0382 initializer.reset(new DbInitializer); 0383 Resource res = initializer->createResource("testresource"); 0384 Collection col1 = initializer->createCollection("col1"); 0385 0386 CollectionAttribute attr1; 0387 attr1.setType("type"); 0388 attr1.setValue("value"); 0389 attr1.setCollection(col1); 0390 attr1.insert(); 0391 0392 Collection col2 = initializer->createCollection("col2", col1); 0393 0394 QTest::addColumn<TestScenario::List>("scenarios"); 0395 0396 { 0397 TestScenario::List scenarios; 0398 0399 auto cmd = createCommand(col2.id(), Protocol::FetchCollectionsCommand::BaseCollection, Protocol::Ancestor::AllAncestors); 0400 cmd->setAncestorsAttributes({"type"}); 0401 scenarios << FakeAkonadiServer::loginScenario() << TestScenario::create(5, TestScenario::ClientCmd, cmd) 0402 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2, true, true, {QLatin1StringView("type")})) 0403 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0404 QTest::newRow("list ancestor attribute with fetch scope") << scenarios; 0405 } 0406 } 0407 0408 void testListAncestorAttributes() 0409 { 0410 QFETCH(TestScenario::List, scenarios); 0411 0412 mAkonadi.setScenarios(scenarios); 0413 mAkonadi.runTest(); 0414 } 0415 0416 void testIncludeAncestors_data() 0417 { 0418 // The collection we are querying contains a load of disabled collections (typical scenario with many shared folders) 0419 // The collection we are NOT querying contains a reasonable amount of enabled collections (to test the performance impact of the manually filtering by 0420 // tree) 0421 initializer.reset(new DbInitializer); 0422 Resource res = initializer->createResource("testresource"); 0423 0424 MimeType mtDirectory = MimeType::retrieveByName(QStringLiteral("mimetype1")); 0425 0426 Collection col1 = initializer->createCollection("col1"); 0427 col1.addMimeType(mtDirectory); 0428 col1.update(); 0429 Collection col2 = initializer->createCollection("col2", col1); 0430 Collection col3 = initializer->createCollection("col3", col2); 0431 Collection col4 = initializer->createCollection("col4", col3); 0432 col4.addMimeType(mtDirectory); 0433 col4.update(); 0434 0435 QTest::addColumn<TestScenario::List>("scenarios"); 0436 0437 { 0438 TestScenario::List scenarios; 0439 scenarios << FakeAkonadiServer::loginScenario() 0440 << TestScenario::create(5, 0441 TestScenario::ClientCmd, 0442 createCommand(Scope(), 0443 Protocol::FetchCollectionsCommand::AllCollections, 0444 Protocol::Ancestor::NoAncestor, 0445 {QLatin1StringView("mimetype1")})) 0446 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col1)) 0447 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0448 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col3)) 0449 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col4)) 0450 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0451 QTest::newRow("ensure filtered grandparent is included") << scenarios; 0452 } 0453 { 0454 TestScenario::List scenarios; 0455 scenarios << FakeAkonadiServer::loginScenario() 0456 << TestScenario::create(5, 0457 TestScenario::ClientCmd, 0458 createCommand(col1.id(), 0459 Protocol::FetchCollectionsCommand::AllCollections, 0460 Protocol::Ancestor::NoAncestor, 0461 {QLatin1StringView("mimetype1")})) 0462 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col2)) 0463 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col3)) 0464 << TestScenario::create(5, TestScenario::ServerCmd, initializer->listResponse(col4)) 0465 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponsePtr::create()); 0466 // This also ensures col1 is excluded although it matches the mimetype filter 0467 QTest::newRow("ensure filtered grandparent is included with specified parent") << scenarios; 0468 } 0469 } 0470 0471 void testIncludeAncestors() 0472 { 0473 QFETCH(TestScenario::List, scenarios); 0474 0475 mAkonadi.setScenarios(scenarios); 0476 mAkonadi.runTest(); 0477 } 0478 0479 // No point in running the benchmark every time 0480 #if 0 0481 0482 void testListEnabledBenchmark_data() 0483 { 0484 //The collection we are querying contains a load of disabled collections (typical scenario with many shared folders) 0485 //The collection we are NOT querying contains a reasonable amount of enabled collections (to test the performance impact of the manually filtering by tree) 0486 initializer.reset(new DbInitializer); 0487 Resource res = initializer->createResource("testresource"); 0488 0489 Collection toplevel = initializer->createCollection("toplevel"); 0490 0491 Collection col1 = initializer->createCollection("col1", toplevel); 0492 Collection col2 = initializer->createCollection("col2", col1); 0493 Collection col3 = initializer->createCollection("col3", col2); 0494 0495 Collection col4 = initializer->createCollection("col4", toplevel); 0496 Collection col5 = initializer->createCollection("col5", col4); 0497 col5.setEnabled(false); 0498 col5.update(); 0499 Collection col6 = initializer->createCollection("col6", col5); 0500 col5.setEnabled(false); 0501 col5.update(); 0502 0503 MimeType mt1 = MimeType::retrieveByName(QLatin1StringView("mimetype1")); 0504 MimeType mt2 = MimeType::retrieveByName(QLatin1StringView("mimetype2")); 0505 MimeType mt3 = MimeType::retrieveByName(QLatin1StringView("mimetype3")); 0506 MimeType mt4 = MimeType::retrieveByName(QLatin1StringView("mimetype4")); 0507 0508 QTime t; 0509 t.start(); 0510 for (int i = 0; i < 100000; i++) { 0511 QByteArray name = QString::fromLatin1("col%1").arg(i+4).toLatin1(); 0512 Collection col = initializer->createCollection(name.data(), col3); 0513 col.setEnabled(false); 0514 col.addMimeType(mt1); 0515 col.addMimeType(mt2); 0516 col.addMimeType(mt3); 0517 col.addMimeType(mt4); 0518 col.update(); 0519 } 0520 for (int i = 0; i < 1000; i++) { 0521 QByteArray name = QString::fromLatin1("col%1").arg(i+100004).toLatin1(); 0522 Collection col = initializer->createCollection(name.data(), col5); 0523 col.addMimeType(mt1); 0524 col.addMimeType(mt2); 0525 col.update(); 0526 } 0527 0528 qDebug() << "Created 100000 collections in" << t.elapsed() << "msecs"; 0529 0530 QTest::addColumn<TestScenario::List>("scenarios"); 0531 0532 // { 0533 // QList<QByteArray> scenario; 0534 // scenario << FakeAkonadiServer::defaultScenario() 0535 // << "C: 2 LIST " + QByteArray::number(toplevel.id()) + " INF (ENABLED ) ()" 0536 // << "S: IGNORE 1006" 0537 // << "S: 2 OK List completed"; 0538 // QTest::newRow("recursive list of enabled") << scenario; 0539 // } 0540 // { 0541 // QList<QByteArray> scenario; 0542 // scenario << FakeAkonadiServer::defaultScenario() 0543 // << "C: 2 LIST " + QByteArray::number(toplevel.id()) + " INF (MIMETYPE (mimetype1) RESOURCE \"testresource\") ()" 0544 // // << "C: 2 LIST " + QByteArray::number(0) + " INF (RESOURCE \"testresource\") ()" 0545 // << "S: IGNORE 101005" 0546 // << "S: 2 OK List completed"; 0547 // QTest::newRow("recursive list filtered by mimetype") << scenario; 0548 // } 0549 { 0550 TestScenario::List scenarios; 0551 scenarios << FakeAkonadiServer::loginScenario() 0552 << TestScenario::create(5, TestScenario::ClientCmd, createCommand(toplevel.id(), Protocol::FetchCollectionsCommand::AllCollections, 0553 Protocol::Ancestor::AllAncestors, { QLatin1StringView("mimetype1") }, QLatin1StringView("testresource"))) 0554 << TestScenario::ignore(101005) 0555 << TestScenario::create(5, TestScenario::ServerCmd, Protocol::FetchCollectionsResponse()); 0556 QTest::newRow("recursive list filtered by mimetype with ancestors") << scenarios; 0557 } 0558 } 0559 0560 void testListEnabledBenchmark() 0561 { 0562 QFETCH(TestScenario::List, scenarios); 0563 // StorageDebugger::instance()->enableSQLDebugging(true); 0564 // StorageDebugger::instance()->writeToFile(QLatin1StringView("sqllog.txt")); 0565 0566 QBENCHMARK { 0567 mAkonadi.setScenarios(scenarios); 0568 mAkonadi.runTest(); 0569 } 0570 } 0571 0572 #endif 0573 }; 0574 0575 AKTEST_FAKESERVER_MAIN(CollectionFetchHandlerTest) 0576 0577 #include "collectionfetchhandlertest.moc"