File indexing completed on 2024-12-22 04:57:35
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0003 SPDX-FileContributor: Kevin Krammer <krake@kdab.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "mixedmaildirstore.h" 0009 0010 #include "testdatautil.h" 0011 0012 #include "filestore/collectionmodifyjob.h" 0013 #include "filestore/itemfetchjob.h" 0014 0015 #include "libmaildir/maildir.h" 0016 0017 #include <QTemporaryDir> 0018 0019 #include <QDir> 0020 #include <QFileInfo> 0021 #include <QTest> 0022 0023 using namespace Akonadi; 0024 0025 class CollectionModifyTest : public QObject 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 CollectionModifyTest() 0031 : QObject() 0032 , mStore(nullptr) 0033 , mDir(nullptr) 0034 { 0035 } 0036 0037 ~CollectionModifyTest() override 0038 { 0039 delete mStore; 0040 delete mDir; 0041 } 0042 0043 private: 0044 MixedMaildirStore *mStore = nullptr; 0045 QTemporaryDir *mDir = nullptr; 0046 0047 private Q_SLOTS: 0048 void init(); 0049 void cleanup(); 0050 void testRename(); 0051 void testIndexPreservation(); 0052 void testIndexCacheUpdate(); 0053 }; 0054 0055 void CollectionModifyTest::init() 0056 { 0057 mStore = new MixedMaildirStore; 0058 0059 mDir = new QTemporaryDir; 0060 QVERIFY(mDir->isValid()); 0061 QVERIFY(QDir(mDir->path()).exists()); 0062 } 0063 0064 void CollectionModifyTest::cleanup() 0065 { 0066 delete mStore; 0067 mStore = nullptr; 0068 delete mDir; 0069 mDir = nullptr; 0070 } 0071 0072 void CollectionModifyTest::testRename() 0073 { 0074 QDir topDir(mDir->path()); 0075 QVERIFY(topDir.mkdir(QStringLiteral("topLevel"))); 0076 QVERIFY(topDir.cd(QStringLiteral("topLevel"))); 0077 0078 KPIM::Maildir topLevelMd(topDir.path(), true); 0079 QVERIFY(topLevelMd.isValid(false)); 0080 0081 KPIM::Maildir md1(topLevelMd.addSubFolder(QStringLiteral("collection1")), false); 0082 KPIM::Maildir md1_2(md1.addSubFolder(QStringLiteral("collection1_2")), false); 0083 0084 // simulate second level mbox in maildir parent 0085 QFileInfo fileInfo1_1(KPIM::Maildir::subDirPathForFolderPath(md1.path()), QStringLiteral("collection1_1")); 0086 QFile file1_1(fileInfo1_1.absoluteFilePath()); 0087 file1_1.open(QIODevice::WriteOnly); 0088 file1_1.close(); 0089 QVERIFY(fileInfo1_1.exists()); 0090 0091 KPIM::Maildir md2(topLevelMd.addSubFolder(QStringLiteral("collection2")), false); 0092 0093 // simulate first level mbox 0094 QFileInfo fileInfo3(topDir.path(), QStringLiteral("collection3")); 0095 QFile file3(fileInfo3.absoluteFilePath()); 0096 file3.open(QIODevice::WriteOnly); 0097 file3.close(); 0098 QVERIFY(fileInfo3.exists()); 0099 0100 // simulate first level mbox with subtree 0101 QFileInfo fileInfo4(topDir.path(), QStringLiteral("collection4")); 0102 QFile file4(fileInfo4.absoluteFilePath()); 0103 file4.open(QIODevice::WriteOnly); 0104 file4.close(); 0105 QVERIFY(fileInfo4.exists()); 0106 0107 QFileInfo subDirInfo4(KPIM::Maildir::subDirPathForFolderPath(fileInfo4.absoluteFilePath())); 0108 QVERIFY(topDir.mkpath(subDirInfo4.absoluteFilePath())); 0109 0110 KPIM::Maildir md4(subDirInfo4.absoluteFilePath(), true); 0111 KPIM::Maildir md4_1(md4.addSubFolder(QStringLiteral("collection4_1")), false); 0112 0113 // simulate second level mbox in mbox parent 0114 QFileInfo fileInfo4_2(subDirInfo4.absoluteFilePath(), QStringLiteral("collection4_2")); 0115 QFile file4_2(fileInfo4_2.absoluteFilePath()); 0116 file4_2.open(QIODevice::WriteOnly); 0117 file4_2.close(); 0118 QVERIFY(fileInfo4_2.exists()); 0119 0120 mStore->setPath(topDir.path()); 0121 0122 FileStore::CollectionModifyJob *job = nullptr; 0123 Collection collection; 0124 0125 // test renaming top level collection 0126 topDir.cdUp(); 0127 QVERIFY(!topDir.exists(QStringLiteral("newTopLevel"))); 0128 0129 Collection topLevelCollection = mStore->topLevelCollection(); 0130 topLevelCollection.setName(QStringLiteral("newTopLevel")); 0131 job = mStore->modifyCollection(topLevelCollection); 0132 0133 QVERIFY(job->exec()); 0134 QCOMPARE(job->error(), 0); 0135 0136 QVERIFY(topDir.exists(QStringLiteral("newTopLevel"))); 0137 QVERIFY(!topDir.exists(QStringLiteral("topLevel"))); 0138 QVERIFY(topDir.cd(QStringLiteral("newTopLevel"))); 0139 QCOMPARE(mStore->path(), topDir.path()); 0140 0141 collection = job->collection(); 0142 QCOMPARE(collection.remoteId(), mStore->path()); 0143 QCOMPARE(collection, mStore->topLevelCollection()); 0144 0145 // test failure of renaming again 0146 job = mStore->modifyCollection(topLevelCollection); 0147 QVERIFY(!job->exec()); 0148 QCOMPARE(job->error(), (int)FileStore::Job::InvalidJobContext); 0149 QCOMPARE(collection.remoteId(), mStore->path()); 0150 QCOMPARE(collection, mStore->topLevelCollection()); 0151 0152 // adjust local handles 0153 topLevelMd = KPIM::Maildir(topDir.path(), true); 0154 QVERIFY(topLevelMd.isValid(false)); 0155 0156 md1 = topLevelMd.subFolder(QStringLiteral("collection1")); 0157 QVERIFY(md1.isValid(false)); 0158 md1_2 = md1.subFolder(QStringLiteral("collection1_2")); 0159 0160 fileInfo1_1 = QFileInfo(KPIM::Maildir::subDirPathForFolderPath(md1.path()), QStringLiteral("collection1_1")); 0161 QVERIFY(fileInfo1_1.exists()); 0162 0163 md2 = topLevelMd.subFolder(QStringLiteral("collection2")); 0164 0165 fileInfo3 = QFileInfo(topDir.path(), QStringLiteral("collection3")); 0166 QVERIFY(fileInfo3.exists()); 0167 0168 fileInfo4 = QFileInfo(topDir.path(), QStringLiteral("collection4")); 0169 QVERIFY(fileInfo4.exists()); 0170 0171 subDirInfo4 = QFileInfo(KPIM::Maildir::subDirPathForFolderPath(fileInfo4.absoluteFilePath())); 0172 QVERIFY(subDirInfo4.exists()); 0173 0174 md4 = KPIM::Maildir(subDirInfo4.absoluteFilePath(), true); 0175 QVERIFY(md4.isValid(false)); 0176 md4_1 = md4.subFolder(QStringLiteral("collection4_1")); 0177 0178 fileInfo4_2 = QFileInfo(subDirInfo4.absoluteFilePath(), QStringLiteral("collection4_2")); 0179 QVERIFY(fileInfo4_2.exists()); 0180 0181 QCOMPARE(topLevelMd.subFolderList(), QStringList() << QStringLiteral("collection1") << QStringLiteral("collection2")); 0182 0183 // test rename first level maildir leaf 0184 Collection collection2; 0185 collection2.setRemoteId(QStringLiteral("collection2")); 0186 collection2.setParentCollection(mStore->topLevelCollection()); 0187 collection2.setName(QStringLiteral("collection2_renamed")); 0188 0189 job = mStore->modifyCollection(collection2); 0190 QVERIFY(job->exec()); 0191 QCOMPARE(job->error(), 0); 0192 0193 collection = job->collection(); 0194 QCOMPARE(collection.remoteId(), collection.name()); 0195 QCOMPARE(collection, collection2); 0196 QCOMPARE(topLevelMd.subFolderList(), QStringList() << QStringLiteral("collection1") << QStringLiteral("collection2_renamed")); 0197 QVERIFY(!md2.isValid(false)); 0198 md2 = topLevelMd.subFolder(collection.remoteId()); 0199 QVERIFY(md2.isValid(false)); 0200 0201 // test failure of renaming again 0202 job = mStore->modifyCollection(collection2); 0203 QVERIFY(!job->exec()); 0204 QCOMPARE(job->error(), (int)FileStore::Job::InvalidJobContext); 0205 QCOMPARE(topLevelMd.subFolderList(), QStringList() << QStringLiteral("collection1") << QStringLiteral("collection2_renamed")); 0206 QVERIFY(md2.isValid(false)); 0207 0208 // test renaming of first level mbox leaf 0209 Collection collection3; 0210 collection3.setRemoteId(QStringLiteral("collection3")); 0211 collection3.setParentCollection(mStore->topLevelCollection()); 0212 collection3.setName(QStringLiteral("collection3_renamed")); 0213 0214 job = mStore->modifyCollection(collection3); 0215 0216 QVERIFY(job->exec()); 0217 QCOMPARE(job->error(), 0); 0218 0219 collection = job->collection(); 0220 QCOMPARE(collection.remoteId(), collection.name()); 0221 QCOMPARE(collection, collection3); 0222 fileInfo3.refresh(); 0223 QVERIFY(!fileInfo3.exists()); 0224 fileInfo3 = QFileInfo(topDir.path(), collection.remoteId()); 0225 QVERIFY(fileInfo3.exists()); 0226 0227 // test failure of renaming again 0228 job = mStore->modifyCollection(collection3); 0229 QVERIFY(!job->exec()); 0230 QCOMPARE(job->error(), (int)FileStore::Job::InvalidJobContext); 0231 fileInfo3.refresh(); 0232 QVERIFY(fileInfo3.exists()); 0233 0234 // test renaming second level maildir in mbox parent 0235 Collection collection4; 0236 collection4.setRemoteId(QStringLiteral("collection4")); 0237 collection4.setParentCollection(mStore->topLevelCollection()); 0238 collection4.setName(QStringLiteral("collection4")); 0239 0240 Collection collection4_1; 0241 collection4_1.setRemoteId(QStringLiteral("collection4_1")); 0242 collection4_1.setParentCollection(collection4); 0243 collection4_1.setName(QStringLiteral("collection4_1_renamed")); 0244 0245 job = mStore->modifyCollection(collection4_1); 0246 QVERIFY(job->exec()); 0247 QCOMPARE(job->error(), 0); 0248 0249 collection = job->collection(); 0250 QCOMPARE(collection.remoteId(), collection.name()); 0251 QCOMPARE(collection, collection4_1); 0252 QCOMPARE(md4.subFolderList(), QStringList() << QStringLiteral("collection4_1_renamed")); 0253 QVERIFY(!md4_1.isValid(false)); 0254 md4_1 = md4.subFolder(collection.remoteId()); 0255 QVERIFY(md4_1.isValid(false)); 0256 0257 // test failure of renaming again 0258 job = mStore->modifyCollection(collection4_1); 0259 QVERIFY(!job->exec()); 0260 QCOMPARE(job->error(), (int)FileStore::Job::InvalidJobContext); 0261 QCOMPARE(md4.subFolderList(), QStringList() << QStringLiteral("collection4_1_renamed")); 0262 QVERIFY(md4_1.isValid(false)); 0263 0264 // test renaming of second level mbox in mbox parent 0265 Collection collection4_2; 0266 collection4_2.setRemoteId(QStringLiteral("collection4_2")); 0267 collection4_2.setParentCollection(collection4); 0268 collection4_2.setName(QStringLiteral("collection4_2_renamed")); 0269 0270 job = mStore->modifyCollection(collection4_2); 0271 0272 QVERIFY(job->exec()); 0273 QCOMPARE(job->error(), 0); 0274 0275 collection = job->collection(); 0276 QCOMPARE(collection.remoteId(), collection.name()); 0277 QCOMPARE(collection, collection4_2); 0278 fileInfo4_2.refresh(); 0279 QVERIFY(!fileInfo4_2.exists()); 0280 fileInfo4_2 = QFileInfo(md4.path(), collection.remoteId()); 0281 QVERIFY(fileInfo4_2.exists()); 0282 0283 // test failure of renaming again 0284 job = mStore->modifyCollection(collection4_2); 0285 QVERIFY(!job->exec()); 0286 QCOMPARE(job->error(), (int)FileStore::Job::InvalidJobContext); 0287 fileInfo4_2.refresh(); 0288 QVERIFY(fileInfo4_2.exists()); 0289 0290 // test renaming of maildir with subtree 0291 Collection collection1; 0292 collection1.setRemoteId(QStringLiteral("collection1")); 0293 collection1.setParentCollection(mStore->topLevelCollection()); 0294 collection1.setName(QStringLiteral("collection1_renamed")); 0295 0296 job = mStore->modifyCollection(collection1); 0297 QVERIFY(job->exec()); 0298 QCOMPARE(job->error(), 0); 0299 0300 collection = job->collection(); 0301 QCOMPARE(collection.remoteId(), collection.name()); 0302 QCOMPARE(collection, collection1); 0303 QCOMPARE(topLevelMd.subFolderList(), QStringList() << QStringLiteral("collection1_renamed") << QStringLiteral("collection2_renamed")); 0304 QVERIFY(!md1.isValid(false)); 0305 md1 = topLevelMd.subFolder(collection.remoteId()); 0306 QVERIFY(md1.isValid(false)); 0307 fileInfo1_1.refresh(); 0308 QVERIFY(!fileInfo1_1.exists()); 0309 QVERIFY(!md1_2.isValid(false)); 0310 fileInfo1_1 = QFileInfo(KPIM::Maildir::subDirPathForFolderPath(md1.path()), QStringLiteral("collection1_1")); 0311 QVERIFY(fileInfo1_1.exists()); 0312 md1_2 = md1.subFolder(QStringLiteral("collection1_2")); 0313 QVERIFY(md1_2.isValid(false)); 0314 0315 // test failure of renaming again 0316 job = mStore->modifyCollection(collection1); 0317 QVERIFY(!job->exec()); 0318 QCOMPARE(job->error(), (int)FileStore::Job::InvalidJobContext); 0319 QCOMPARE(topLevelMd.subFolderList(), QStringList() << QStringLiteral("collection1_renamed") << QStringLiteral("collection2_renamed")); 0320 QVERIFY(md2.isValid(false)); 0321 QVERIFY(fileInfo1_1.exists()); 0322 QVERIFY(md1_2.isValid(false)); 0323 0324 // test renaming of mbox with subtree 0325 collection4.setName(QStringLiteral("collection4_renamed")); 0326 job = mStore->modifyCollection(collection4); 0327 QVERIFY(job->exec()); 0328 QCOMPARE(job->error(), 0); 0329 0330 collection = job->collection(); 0331 QCOMPARE(collection.remoteId(), collection.name()); 0332 QCOMPARE(collection, collection4); 0333 fileInfo4.refresh(); 0334 QVERIFY(!fileInfo4.exists()); 0335 fileInfo4 = QFileInfo(topDir.path(), collection.remoteId()); 0336 QVERIFY(fileInfo4.exists()); 0337 md4 = KPIM::Maildir(KPIM::Maildir::subDirPathForFolderPath(fileInfo4.absoluteFilePath()), true); 0338 QVERIFY(md4.isValid(false)); 0339 0340 QVERIFY(!md4_1.isValid(false)); 0341 fileInfo4_2.refresh(); 0342 QVERIFY(!fileInfo4_2.exists()); 0343 md4_1 = md4.subFolder(QStringLiteral("collection4_1_renamed")); 0344 QVERIFY(md4_1.isValid(false)); 0345 fileInfo4_2 = QFileInfo(md4.path(), QStringLiteral("collection4_2_renamed")); 0346 QVERIFY(fileInfo4_2.exists()); 0347 0348 // test failure of renaming again 0349 job = mStore->modifyCollection(collection4); 0350 QVERIFY(!job->exec()); 0351 QCOMPARE(job->error(), (int)FileStore::Job::InvalidJobContext); 0352 fileInfo4.refresh(); 0353 QVERIFY(fileInfo4.exists()); 0354 } 0355 0356 void CollectionModifyTest::testIndexPreservation() 0357 { 0358 QVERIFY(TestDataUtil::installFolder(QStringLiteral("mbox"), mDir->path(), QStringLiteral("collection1"))); 0359 QVERIFY(TestDataUtil::installFolder(QStringLiteral("maildir"), mDir->path(), QStringLiteral("collection2"))); 0360 0361 mStore->setPath(mDir->path()); 0362 0363 const QVariant colListVar = QVariant::fromValue<Collection::List>(Collection::List()); 0364 FileStore::CollectionModifyJob *job = nullptr; 0365 FileStore::ItemFetchJob *itemFetch = nullptr; 0366 QVariant var; 0367 Collection::List collections; 0368 Item::List items; 0369 0370 QMap<QByteArray, int> flagCounts; 0371 0372 // test renaming mbox 0373 Collection collection1; 0374 collection1.setRemoteId(QStringLiteral("collection1")); 0375 collection1.setParentCollection(mStore->topLevelCollection()); 0376 collection1.setName(QStringLiteral("collection1_renamed")); 0377 0378 job = mStore->modifyCollection(collection1); 0379 QVERIFY(job->exec()); 0380 QCOMPARE(job->error(), 0); 0381 0382 var = job->property("onDiskIndexInvalidated"); 0383 QVERIFY(var.isValid()); 0384 QCOMPARE(var.userType(), colListVar.userType()); 0385 0386 collections = var.value<Collection::List>(); 0387 QCOMPARE((int)collections.count(), 1); 0388 QCOMPARE(collections.first(), collection1); 0389 0390 const QFileInfo indexFileInfo1(mDir->path(), QStringLiteral(".collection1_renamed.index")); 0391 QVERIFY(!indexFileInfo1.exists()); 0392 0393 // get the items and check the flags (see data/README) 0394 itemFetch = mStore->fetchItems(collections.first()); 0395 QVERIFY(itemFetch->exec()); 0396 QCOMPARE(itemFetch->error(), 0); 0397 0398 items = itemFetch->items(); 0399 QCOMPARE((int)items.count(), 4); 0400 for (const Item &item : std::as_const(items)) { 0401 const auto flags{item.flags()}; 0402 for (const QByteArray &flag : flags) { 0403 ++flagCounts[flag]; 0404 } 0405 } 0406 0407 QCOMPARE(flagCounts["\\SEEN"], 2); 0408 QCOMPARE(flagCounts["\\FLAGGED"], 1); 0409 QCOMPARE(flagCounts["$TODO"], 1); 0410 0411 // test renaming maildir 0412 Collection collection2; 0413 collection2.setRemoteId(QStringLiteral("collection2")); 0414 collection2.setParentCollection(mStore->topLevelCollection()); 0415 collection2.setName(QStringLiteral("collection2_renamed")); 0416 0417 job = mStore->modifyCollection(collection2); 0418 QVERIFY(job->exec()); 0419 QCOMPARE(job->error(), 0); 0420 0421 var = job->property("onDiskIndexInvalidated"); 0422 QVERIFY(var.isValid()); 0423 QCOMPARE(var.userType(), colListVar.userType()); 0424 0425 collections = var.value<Collection::List>(); 0426 QCOMPARE((int)collections.count(), 1); 0427 QCOMPARE(collections.first(), collection2); 0428 0429 const QFileInfo indexFileInfo2(mDir->path(), QStringLiteral(".collection2_renamed.index")); 0430 QVERIFY(!indexFileInfo2.exists()); 0431 0432 // get the items and check the flags (see data/README) 0433 itemFetch = mStore->fetchItems(collections.first()); 0434 QVERIFY(itemFetch->exec()); 0435 QCOMPARE(itemFetch->error(), 0); 0436 0437 items = itemFetch->items(); 0438 QCOMPARE((int)items.count(), 4); 0439 0440 flagCounts.clear(); 0441 for (const Item &item : std::as_const(items)) { 0442 const auto flags = item.flags(); 0443 for (const QByteArray &flag : flags) { 0444 ++flagCounts[flag]; 0445 } 0446 } 0447 0448 QCOMPARE(flagCounts["\\SEEN"], 2); 0449 QCOMPARE(flagCounts["\\FLAGGED"], 1); 0450 QCOMPARE(flagCounts["$TODO"], 1); 0451 } 0452 0453 void CollectionModifyTest::testIndexCacheUpdate() 0454 { 0455 KPIM::Maildir topLevelMd(mDir->path(), true); 0456 QVERIFY(topLevelMd.isValid(false)); 0457 0458 KPIM::Maildir md1(topLevelMd.addSubFolder(QStringLiteral("collection1")), false); 0459 0460 // simulate first level mbox 0461 QFileInfo fileInfo2(mDir->path(), QStringLiteral("collection2")); 0462 QFile file2(fileInfo2.absoluteFilePath()); 0463 file2.open(QIODevice::WriteOnly); 0464 file2.close(); 0465 QVERIFY(fileInfo2.exists()); 0466 0467 const QString colSubDir1 = KPIM::Maildir::subDirPathForFolderPath(md1.path()); 0468 QVERIFY(TestDataUtil::installFolder(QStringLiteral("mbox"), colSubDir1, QStringLiteral("collection1_1"))); 0469 QVERIFY(TestDataUtil::installFolder(QStringLiteral("maildir"), colSubDir1, QStringLiteral("collection1_2"))); 0470 0471 const QString colSubDir2 = KPIM::Maildir::subDirPathForFolderPath(fileInfo2.absoluteFilePath()); 0472 QVERIFY(TestDataUtil::installFolder(QStringLiteral("mbox"), colSubDir2, QStringLiteral("collection2_1"))); 0473 QVERIFY(TestDataUtil::installFolder(QStringLiteral("maildir"), colSubDir2, QStringLiteral("collection2_2"))); 0474 0475 mStore->setPath(mDir->path()); 0476 0477 FileStore::CollectionModifyJob *job = nullptr; 0478 FileStore::ItemFetchJob *itemFetch = nullptr; 0479 Collection collection; 0480 Item::List items; 0481 QMap<QByteArray, int> flagCounts; 0482 0483 // preparation: load all second level items to make sure respective index data is cached 0484 Collection collection1; 0485 collection1.setRemoteId(QStringLiteral("collection1")); 0486 collection1.setParentCollection(mStore->topLevelCollection()); 0487 collection1.setName(QStringLiteral("collection1")); 0488 0489 Collection collection1_1; 0490 collection1_1.setRemoteId(QStringLiteral("collection1_1")); 0491 collection1_1.setParentCollection(collection1); 0492 collection1_1.setName(QStringLiteral("collection1_1")); 0493 0494 itemFetch = mStore->fetchItems(collection1_1); 0495 QVERIFY(itemFetch->exec()); 0496 0497 Collection collection1_2; 0498 collection1_2.setRemoteId(QStringLiteral("collection1_2")); 0499 collection1_2.setParentCollection(collection1); 0500 collection1_2.setName(QStringLiteral("collection1_2")); 0501 0502 itemFetch = mStore->fetchItems(collection1_2); 0503 QVERIFY(itemFetch->exec()); 0504 Collection collection2; 0505 collection2.setRemoteId(QStringLiteral("collection2")); 0506 collection2.setParentCollection(mStore->topLevelCollection()); 0507 collection2.setName(QStringLiteral("collection2")); 0508 0509 Collection collection2_1; 0510 collection2_1.setRemoteId(QStringLiteral("collection2_1")); 0511 collection2_1.setParentCollection(collection2); 0512 collection2_1.setName(QStringLiteral("collection2_1")); 0513 0514 itemFetch = mStore->fetchItems(collection2_1); 0515 QVERIFY(itemFetch->exec()); 0516 Collection collection2_2; 0517 collection2_2.setRemoteId(QStringLiteral("collection2_2")); 0518 collection2_2.setParentCollection(collection2); 0519 collection2_2.setName(QStringLiteral("collection2_2")); 0520 0521 itemFetch = mStore->fetchItems(collection2_2); 0522 QVERIFY(itemFetch->exec()); 0523 0524 // test renaming the maildir parent 0525 collection1.setName(QStringLiteral("collection1_renamed")); 0526 0527 job = mStore->modifyCollection(collection1); 0528 QVERIFY(job->exec()); 0529 QCOMPARE(job->error(), 0); 0530 0531 collection = job->collection(); 0532 0533 // get the items of the children and check the flags (see data/README) 0534 collection1_1.setParentCollection(collection); 0535 itemFetch = mStore->fetchItems(collection1_1); 0536 QVERIFY(itemFetch->exec()); 0537 QCOMPARE(itemFetch->error(), 0); 0538 0539 items = itemFetch->items(); 0540 QCOMPARE((int)items.count(), 4); 0541 for (const Item &item : std::as_const(items)) { 0542 const auto flags = item.flags(); 0543 for (const QByteArray &flag : flags) { 0544 ++flagCounts[flag]; 0545 } 0546 } 0547 0548 QCOMPARE(flagCounts["\\SEEN"], 2); 0549 QCOMPARE(flagCounts["\\FLAGGED"], 1); 0550 QCOMPARE(flagCounts["$TODO"], 1); 0551 flagCounts.clear(); 0552 0553 collection1_2.setParentCollection(collection); 0554 itemFetch = mStore->fetchItems(collection1_2); 0555 QVERIFY(itemFetch->exec()); 0556 QCOMPARE(itemFetch->error(), 0); 0557 0558 items = itemFetch->items(); 0559 QCOMPARE((int)items.count(), 4); 0560 for (const Item &item : std::as_const(items)) { 0561 const auto flags = item.flags(); 0562 for (const QByteArray &flag : flags) { 0563 ++flagCounts[flag]; 0564 } 0565 } 0566 0567 QCOMPARE(flagCounts["\\SEEN"], 2); 0568 QCOMPARE(flagCounts["\\FLAGGED"], 1); 0569 QCOMPARE(flagCounts["$TODO"], 1); 0570 flagCounts.clear(); 0571 0572 // test renaming the mbox parent 0573 collection2.setName(QStringLiteral("collection2_renamed")); 0574 0575 job = mStore->modifyCollection(collection2); 0576 QVERIFY(job->exec()); 0577 QCOMPARE(job->error(), 0); 0578 0579 collection = job->collection(); 0580 0581 // get the items of the children and check the flags (see data/README) 0582 collection2_1.setParentCollection(collection); 0583 itemFetch = mStore->fetchItems(collection2_1); 0584 QVERIFY(itemFetch->exec()); 0585 QCOMPARE(itemFetch->error(), 0); 0586 0587 items = itemFetch->items(); 0588 QCOMPARE((int)items.count(), 4); 0589 for (const Item &item : std::as_const(items)) { 0590 const auto flags = item.flags(); 0591 for (const QByteArray &flag : flags) { 0592 ++flagCounts[flag]; 0593 } 0594 } 0595 0596 QCOMPARE(flagCounts["\\SEEN"], 2); 0597 QCOMPARE(flagCounts["\\FLAGGED"], 1); 0598 QCOMPARE(flagCounts["$TODO"], 1); 0599 flagCounts.clear(); 0600 0601 collection2_2.setParentCollection(collection); 0602 itemFetch = mStore->fetchItems(collection2_2); 0603 QVERIFY(itemFetch->exec()); 0604 QCOMPARE(itemFetch->error(), 0); 0605 0606 items = itemFetch->items(); 0607 QCOMPARE((int)items.count(), 4); 0608 for (const Item &item : std::as_const(items)) { 0609 const auto flags = item.flags(); 0610 for (const QByteArray &flag : flags) { 0611 ++flagCounts[flag]; 0612 } 0613 } 0614 0615 QCOMPARE(flagCounts["\\SEEN"], 2); 0616 QCOMPARE(flagCounts["\\FLAGGED"], 1); 0617 QCOMPARE(flagCounts["$TODO"], 1); 0618 flagCounts.clear(); 0619 } 0620 0621 QTEST_MAIN(CollectionModifyTest) 0622 0623 #include "collectionmodifytest.moc"