File indexing completed on 2024-11-10 04:40:09

0001 /*
0002     SPDX-FileCopyrightText: 2006, 2009 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "agentinstance.h"
0008 #include "agentmanager.h"
0009 #include "collectioncreatejob.h"
0010 #include "collectionpathresolver.h"
0011 #include "transactionjobs.h"
0012 
0013 #include "qtest_akonadi.h"
0014 
0015 using namespace Akonadi;
0016 
0017 class CollectionCreator : public QObject
0018 {
0019     Q_OBJECT
0020 private Q_SLOTS:
0021     void initTestCase()
0022     {
0023         AkonadiTest::checkTestIsIsolated();
0024         AkonadiTest::setAllResourcesOffline();
0025     }
0026 
0027     void createCollections_data()
0028     {
0029         QTest::addColumn<int>("count");
0030         QTest::addColumn<bool>("useTransaction");
0031 
0032         const int counts[]{1, 10, 100, 1000};
0033         const bool transactions[]{false, true};
0034         for (int count : counts) {
0035             for (bool transaction : transactions) {
0036                 QTest::newRow(
0037                     QString::fromLatin1("%1-%2").arg(count).arg(transaction ? QLatin1StringView("trans") : QLatin1StringView("notrans")).toLatin1().constData())
0038                     << count << transaction;
0039             }
0040         }
0041     }
0042 
0043     void createCollections()
0044     {
0045         QFETCH(int, count);
0046         QFETCH(bool, useTransaction);
0047 
0048         const Collection parent(AkonadiTest::collectionIdFromPath(QLatin1StringView("res3")));
0049         QVERIFY(parent.isValid());
0050 
0051         static int index = 0;
0052         Job *lastJob = 0;
0053         QBENCHMARK {
0054             if (useTransaction) {
0055                 lastJob = new TransactionBeginJob(this);
0056             }
0057             for (int i = 0; i < count; ++i) {
0058                 Collection col;
0059                 col.setParentCollection(parent);
0060                 col.setName(QLatin1StringView("col") + QString::number(++index));
0061                 lastJob = new CollectionCreateJob(col, this);
0062             }
0063             if (useTransaction) {
0064                 lastJob = new TransactionCommitJob(this);
0065             }
0066             AkonadiTest::akWaitForSignal(lastJob, SIGNAL(result(KJob *)), 15000);
0067         }
0068     }
0069 };
0070 
0071 QTEST_AKONADIMAIN(CollectionCreator)
0072 
0073 #include "collectioncreator.moc"