File indexing completed on 2024-11-10 04:40:16
0001 /* 0002 SPDX-FileCopyrightText: 2008 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "transactiontest.h" 0008 0009 #include "collectioncreatejob.h" 0010 #include "collectiondeletejob.h" 0011 #include "collectionfetchjob.h" 0012 #include "control.h" 0013 #include "itemcreatejob.h" 0014 #include "itemfetchjob.h" 0015 #include "session.h" 0016 #include "transactionjobs.h" 0017 0018 #include "qtest_akonadi.h" 0019 0020 using namespace Akonadi; 0021 0022 QTEST_AKONADIMAIN(TransactionTest) 0023 0024 void TransactionTest::initTestCase() 0025 { 0026 AkonadiTest::checkTestIsIsolated(); 0027 Control::start(); 0028 } 0029 0030 void TransactionTest::testTransaction() 0031 { 0032 Collection basisCollection; 0033 0034 auto listJob = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive); 0035 AKVERIFYEXEC(listJob); 0036 const Collection::List list = listJob->collections(); 0037 for (const Collection &col : list) { 0038 if (col.name() == QLatin1StringView("res3")) { 0039 basisCollection = col; 0040 } 0041 } 0042 0043 Collection testCollection; 0044 testCollection.setParentCollection(basisCollection); 0045 testCollection.setName(QStringLiteral("transactionTest")); 0046 testCollection.setRemoteId(QStringLiteral("transactionTestRemoteId")); 0047 auto job = new CollectionCreateJob(testCollection, Session::defaultSession()); 0048 0049 AKVERIFYEXEC(job); 0050 0051 testCollection = job->collection(); 0052 0053 auto beginTransaction1 = new TransactionBeginJob(Session::defaultSession()); 0054 AKVERIFYEXEC(beginTransaction1); 0055 0056 auto beginTransaction2 = new TransactionBeginJob(Session::defaultSession()); 0057 AKVERIFYEXEC(beginTransaction2); 0058 0059 auto commitTransaction2 = new TransactionCommitJob(Session::defaultSession()); 0060 AKVERIFYEXEC(commitTransaction2); 0061 0062 auto commitTransaction1 = new TransactionCommitJob(Session::defaultSession()); 0063 AKVERIFYEXEC(commitTransaction1); 0064 0065 auto commitTransactionX = new TransactionCommitJob(Session::defaultSession()); 0066 QVERIFY(commitTransactionX->exec() == false); 0067 0068 auto beginTransaction3 = new TransactionBeginJob(Session::defaultSession()); 0069 AKVERIFYEXEC(beginTransaction3); 0070 0071 Item item; 0072 item.setMimeType(QStringLiteral("application/octet-stream")); 0073 item.setPayload<QByteArray>("body data"); 0074 auto appendJob = new ItemCreateJob(item, testCollection, Session::defaultSession()); 0075 AKVERIFYEXEC(appendJob); 0076 0077 auto rollbackTransaction3 = new TransactionRollbackJob(Session::defaultSession()); 0078 AKVERIFYEXEC(rollbackTransaction3); 0079 0080 auto fetchJob = new ItemFetchJob(testCollection, Session::defaultSession()); 0081 AKVERIFYEXEC(fetchJob); 0082 0083 QVERIFY(fetchJob->items().isEmpty()); 0084 0085 auto deleteJob = new CollectionDeleteJob(testCollection, Session::defaultSession()); 0086 AKVERIFYEXEC(deleteJob); 0087 } 0088 0089 #include "moc_transactiontest.cpp"