Verified Commit 8e63f68d authored by Daniel Vrátil's avatar Daniel Vrátil 🤖
Browse files

Merge test_util into qtest_akonadi header

This makes the many useful utilities for writing Akonadi-enabled
tests available to everyone.
parent b074c98d
Pipeline #21190 passed with stage
in 15 minutes and 4 seconds
......@@ -28,7 +28,6 @@
#include "itemdeletejob.h"
#include <qtest_akonadi.h>
#include "test_utils.h"
using namespace Akonadi;
......@@ -40,10 +39,10 @@ void AutoIncrementTest::initTestCase()
Control::start();
AkonadiTest::setAllResourcesOffline();
itemTargetCollection = Collection(collectionIdFromPath(QStringLiteral("res2/space folder")));
itemTargetCollection = Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(itemTargetCollection.isValid());
collectionTargetCollection = Collection(collectionIdFromPath(QStringLiteral("res3")));
collectionTargetCollection = Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res3")));
QVERIFY(collectionTargetCollection.isValid());
}
......@@ -87,7 +86,7 @@ void AutoIncrementTest::testItemAutoIncrement()
// Restart the server, then test item creation again. The new id of the item
// should be higher than all ids before.
restartAkonadiServer();
AkonadiTest::restartAkonadiServer();
ItemCreateJob *job = createItemCreateJob();
AKVERIFYEXEC(job);
Item newItem = job->item();
......@@ -119,7 +118,7 @@ void AutoIncrementTest::testCollectionAutoIncrement()
// Restart the server, then test collection creation again. The new id of the collection
// should be higher than all ids before.
restartAkonadiServer();
AkonadiTest::restartAkonadiServer();
CollectionCreateJob *job = createCollectionCreateJob(0);
AKVERIFYEXEC(job);
......
......@@ -17,8 +17,6 @@
02110-1301, USA.
*/
#include "test_utils.h"
#include "collection.h"
#include "collectionfetchjob.h"
#include "collectionmodifyjob.h"
......@@ -28,6 +26,7 @@
#include "agentmanager.h"
#include "agentinstance.h"
#include "itemcopyjob.h"
#include "qtest_akonadi.h"
#include <QHash>
......@@ -53,7 +52,7 @@ private Q_SLOTS:
}
void testRetrievalErrorBurst() // caused rare server crashs with old item retrieval code
{
Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
QVERIFY(col.isValid());
enableAgent(QStringLiteral("akonadi_knut_resource_0"), false);
......@@ -134,7 +133,7 @@ private Q_SLOTS:
enableAgent(QStringLiteral("akonadi_knut_resource_0"), resourceEnabled);
Collection dest(collectionIdFromPath(QStringLiteral("res3")));
Collection dest(AkonadiTest::collectionIdFromPath(QStringLiteral("res3")));
QVERIFY(dest.isValid());
ItemCopyJob *copy = new ItemCopyJob(item, dest, this);
......
......@@ -25,7 +25,7 @@
#include "item.h"
#include "itemfetchjob.h"
#include "itemfetchscope.h"
#include "test_utils.h"
#include "qtest_akonadi.h"
#include <QObject>
......@@ -50,8 +50,8 @@ private Q_SLOTS:
void testCopy()
{
const Collection target(collectionIdFromPath(QStringLiteral("res3")));
Collection source(collectionIdFromPath(QStringLiteral("res1/foo")));
const Collection target(AkonadiTest::collectionIdFromPath(QStringLiteral("res3")));
Collection source(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
QVERIFY(target.isValid());
QVERIFY(source.isValid());
......
......@@ -19,11 +19,11 @@
*
*/
#include "test_utils.h"
#include "collectioncreatejob.h"
#include "collectionfetchjob.h"
#include "collectiondeletejob.h"
#include "entitydisplayattribute.h"
#include "qtest_akonadi.h"
using namespace Akonadi;
......@@ -39,13 +39,13 @@ private Q_SLOTS:
void testCreateCollection()
{
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy spy(monitor.get(), &Monitor::collectionAdded);
Collection col;
col.setName(QLatin1String("test_collection"));
col.setContentMimeTypes({ Collection::mimeType() });
col.setParentCollection(Collection(collectionIdFromPath(QLatin1String("res1"))));
col.setParentCollection(Collection(AkonadiTest::collectionIdFromPath(QLatin1String("res1"))));
col.setRights(Collection::AllRights);
CollectionCreateJob *cj = new CollectionCreateJob(col, this);
......
......@@ -24,7 +24,6 @@
#include "transactionjobs.h"
#include "qtest_akonadi.h"
#include "test_utils.h"
using namespace Akonadi;
......@@ -58,7 +57,7 @@ private Q_SLOTS:
QFETCH(int, count);
QFETCH(bool, useTransaction);
const Collection parent(collectionIdFromPath(QLatin1String("res3")));
const Collection parent(AkonadiTest::collectionIdFromPath(QLatin1String("res3")));
QVERIFY(parent.isValid());
static int index = 0;
......
......@@ -22,7 +22,6 @@
#include <sys/types.h>
#include <qtest_akonadi.h>
#include "test_utils.h"
#include "testattribute.h"
#include "agentmanager.h"
......@@ -440,7 +439,7 @@ void CollectionJobTest::testModify_data()
QTest::addColumn<qint64>("uid");
QTest::addColumn<QString>("rid");
QTest::newRow("uid") << collectionIdFromPath(QStringLiteral("res1/foo")) << QString();
QTest::newRow("uid") << AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")) << QString();
QTest::newRow("rid") << -1ll << QStringLiteral("10");
}
......
......@@ -19,12 +19,12 @@
*
*/
#include "test_utils.h"
#include "collectioncreatejob.h"
#include "collectionfetchjob.h"
#include "collectionmodifyjob.h"
#include "collectiondeletejob.h"
#include "entitydisplayattribute.h"
#include "qtest_akonadi.h"
using namespace Akonadi;
......@@ -43,7 +43,7 @@ private Q_SLOTS:
Collection col;
col.setName(QLatin1String("test_collection"));
col.setContentMimeTypes({ Collection::mimeType() });
col.setParentCollection(Collection(collectionIdFromPath(QLatin1String("res1"))));
col.setParentCollection(Collection(AkonadiTest::collectionIdFromPath(QLatin1String("res1"))));
col.setRights(Collection::AllRights);
CollectionCreateJob *cj = new CollectionCreateJob(col, this);
......
......@@ -17,8 +17,7 @@
02110-1301, USA.
*/
#include "test_utils.h"
#include "qtest_akonadi.h"
#include "collection.h"
#include "collectionfetchjob.h"
#include "collectionmovejob.h"
......@@ -43,9 +42,9 @@ private Q_SLOTS:
QTest::addColumn<Collection>("source");
QTest::addColumn<Collection>("destination");
const Collection res1(collectionIdFromPath(QStringLiteral("res1")));
const Collection res1foo(collectionIdFromPath(QStringLiteral("res1/foo")));
const Collection res1bla(collectionIdFromPath(QStringLiteral("res1/foo/bar/bla")));
const Collection res1(AkonadiTest::collectionIdFromPath(QStringLiteral("res1")));
const Collection res1foo(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
const Collection res1bla(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bar/bla")));
QTest::newRow("non-existing-target") << res1 << Collection(INT_MAX);
QTest::newRow("root") << Collection::root() << res1;
......@@ -71,11 +70,11 @@ private Q_SLOTS:
QTest::addColumn<Collection>("destination");
QTest::addColumn<bool>("crossResource");
QTest::newRow("inter-resource") << Collection(collectionIdFromPath(QStringLiteral("res1")))
<< Collection(collectionIdFromPath(QStringLiteral("res2")))
QTest::newRow("inter-resource") << Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res1")))
<< Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res2")))
<< true;
QTest::newRow("intra-resource") << Collection(collectionIdFromPath(QStringLiteral("res1/foo/bla")))
<< Collection(collectionIdFromPath(QStringLiteral("res1/foo/bar/bla")))
QTest::newRow("intra-resource") << Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bla")))
<< Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bar/bla")))
<< false;
}
......
......@@ -17,8 +17,6 @@
02110-1301, USA.
*/
#include "test_utils.h"
#include "agentmanager.h"
#include "agentinstance.h"
#include "control.h"
......
......@@ -19,8 +19,6 @@
#include <QObject>
#include "test_utils.h"
#include "entitytreemodel.h"
#include "control.h"
#include "entitytreemodel_p.h"
......@@ -157,7 +155,7 @@ void EtmPopulationTest::initTestCase()
AkonadiTest::checkTestIsIsolated();
AkonadiTest::setAllResourcesOffline();
res = Collection(collectionIdFromPath(QStringLiteral("res3")));
res = Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res3")));
mainCollectionName = QStringLiteral("main");
monitorCol = createCollection(mainCollectionName, res);
......
......@@ -18,7 +18,6 @@
*/
#include "test_utils.h"
#include "entitytreemodel.h"
#include "control.h"
#include "entitytreemodel_p.h"
......@@ -112,7 +111,7 @@ InspectableETM *FavoriteProxyTest::createETM()
*/
void FavoriteProxyTest::testItemAdded()
{
Collection res3 = Collection(collectionIdFromPath(QStringLiteral("res3")));
Collection res3 = Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res3")));
InspectableETM *model = createETM();
......
......@@ -30,7 +30,6 @@
#include "itemfetchscope.h"
#include "itemmodifyjob.h"
#include "qtest_akonadi.h"
#include "test_utils.h"
#include "itemserializer_p.h"
#include "itemserializerplugin.h"
......@@ -133,9 +132,8 @@ void GidTest::testSetAndFetch()
void GidTest::testCreate()
{
CollectionPathResolver *resolver = new CollectionPathResolver(QStringLiteral("res1/foo/bar"), this);
AKVERIFYEXEC(resolver);
int colId = resolver->collection();
const int colId = AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bar"));
QVERIFY(colId > -1);
Item item;
item.setMimeType(QStringLiteral("application/octet-stream"));
......@@ -175,10 +173,8 @@ void GidTest::testSetWithIgnorePayload()
void GidTest::testFetchScope()
{
CollectionPathResolver *resolver = new CollectionPathResolver(QStringLiteral("res1/foo/bar"), this);
AKVERIFYEXEC(resolver);
int colId = resolver->collection();
const int colId = AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bar"));
QVERIFY(colId > -1);
Item item;
item.setMimeType(QStringLiteral("application/octet-stream"));
......
......@@ -23,7 +23,6 @@
#include "itemfetchjob.h"
#include "itemfetchscope.h"
#include "qtest_akonadi.h"
#include "test_utils.h"
#include "control.h"
using namespace Akonadi;
......@@ -47,7 +46,7 @@ void InvalidateCacheJobTest::initTestCase()
void InvalidateCacheJobTest::shouldClearPayload()
{
// Find collection by name
Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
const int colId = col.id();
QVERIFY(colId > 0);
......
......@@ -18,10 +18,10 @@
*/
#include "itemappendtest.h"
#include "qtest_akonadi.h"
#include "control.h"
#include "testattribute.h"
#include "test_utils.h"
#include "agentinstance.h"
#include "agentmanager.h"
......@@ -60,7 +60,7 @@ void ItemAppendTest::testItemAppend_data()
void ItemAppendTest::testItemAppend()
{
const Collection testFolder1(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection testFolder1(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(testFolder1.isValid());
QFETCH(QString, remoteId);
......@@ -116,7 +116,7 @@ void ItemAppendTest::testContent_data()
void ItemAppendTest::testContent()
{
const Collection testFolder1(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection testFolder1(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(testFolder1.isValid());
QFETCH(QByteArray, data);
......@@ -148,7 +148,7 @@ void ItemAppendTest::testContent()
void ItemAppendTest::testNewMimetype()
{
const Collection col(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(col.isValid());
Item item;
......@@ -167,7 +167,7 @@ void ItemAppendTest::testNewMimetype()
void ItemAppendTest::testIllegalAppend()
{
const Collection testFolder1(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection testFolder1(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(testFolder1.isValid());
Item item;
......@@ -178,7 +178,7 @@ void ItemAppendTest::testIllegalAppend()
QVERIFY(!job->exec());
// adding item into a collection which can't handle items of this type
const Collection col(collectionIdFromPath(QStringLiteral("res1/foo/bla")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bla")));
QVERIFY(col.isValid());
job = new ItemCreateJob(item, col, this);
QEXPECT_FAIL("", "Test not yet implemented in the server.", Continue);
......@@ -187,7 +187,7 @@ void ItemAppendTest::testIllegalAppend()
void ItemAppendTest::testMultipartAppend()
{
const Collection testFolder1(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection testFolder1(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(testFolder1.isValid());
Item item;
......@@ -253,7 +253,7 @@ void ItemAppendTest::testItemSize()
QFETCH(Akonadi::Item, item);
QFETCH(qint64, size);
const Collection col(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(col.isValid());
ItemCreateJob *create = new ItemCreateJob(item, col, this);
......@@ -328,7 +328,7 @@ void ItemAppendTest::testItemMerge()
QFETCH(Akonadi::Item, mergedItem);
QFETCH(bool, silent);
const Collection col(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(col.isValid());
ItemCreateJob *create = new ItemCreateJob(item1, col, this);
......@@ -364,7 +364,7 @@ void ItemAppendTest::testItemMerge()
void ItemAppendTest::testForeignPayload()
{
const Collection col(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
QVERIFY(col.isValid());
const QString filePath = QString::fromUtf8(qgetenv("TMPDIR")) + QStringLiteral("/foreignPayloadFile.mbox");
......
......@@ -26,7 +26,6 @@
#include "itemfetchscope.h"
#include "itemmodifyjob.h"
#include "qtest_akonadi.h"
#include "test_utils.h"
#include <QDebug>
......@@ -85,7 +84,7 @@ private Q_SLOTS:
QFETCH(int, count);
QFETCH(int, size);
const Collection parent(collectionIdFromPath(QStringLiteral("res1/foo")));
const Collection parent(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
QVERIFY(parent.isValid());
Item item(QStringLiteral("application/octet-stream"));
......
......@@ -27,7 +27,6 @@
#include "itemfetchscope.h"
#include "itemcreatejob.h"
#include "test_utils.h"
#include "qtest_akonadi.h"
#include <QObject>
......@@ -53,7 +52,7 @@ private Q_SLOTS:
void testCopy()
{
const Collection target(collectionIdFromPath(QStringLiteral("res3")));
const Collection target(AkonadiTest::collectionIdFromPath(QStringLiteral("res3")));
QVERIFY(target.isValid());
ItemCopyJob *copy = new ItemCopyJob(Item(1), target);
......@@ -104,7 +103,7 @@ private Q_SLOTS:
file.write("123456789");
file.close();
const Collection source(collectionIdFromPath(QStringLiteral("res2")));
const Collection source(AkonadiTest::collectionIdFromPath(QStringLiteral("res2")));
Item item(QStringLiteral("application/octet-stream"));
item.setPayloadPath(file.fileName());
......@@ -113,7 +112,7 @@ private Q_SLOTS:
AKVERIFYEXEC(create);
item = create->item();
const Collection target(collectionIdFromPath(QStringLiteral("res2/space folder")));
const Collection target(AkonadiTest::collectionIdFromPath(QStringLiteral("res2/space folder")));
auto copy = new ItemCopyJob(item, target, this);
AKVERIFYEXEC(copy);
......
......@@ -28,7 +28,6 @@
#include "itemmodifyjob.h"
#include "resourceselectjob_p.h"
#include "monitor.h"
#include "test_utils.h"
#include <QObject>
......@@ -58,7 +57,7 @@ private Q_SLOTS:
void testDelete()
{
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
ItemFetchJob *fjob = new ItemFetchJob(Item(1), this);
......@@ -80,7 +79,7 @@ private Q_SLOTS:
void testDeleteFromUnselectedCollection()
{
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
const QString path = QLatin1String("res1") +
......@@ -114,14 +113,14 @@ private Q_SLOTS:
void testRidDelete()
{
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
{
ResourceSelectJob *select = new ResourceSelectJob(QStringLiteral("akonadi_knut_resource_0"));
AKVERIFYEXEC(select);
}
const Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
QVERIFY(col.isValid());
Item i;
......@@ -153,7 +152,7 @@ private Q_SLOTS:
void testTagDelete()
{
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
// Create tag
......@@ -164,7 +163,7 @@ private Q_SLOTS:
AKVERIFYEXEC(tjob);
tag = tjob->tag();
const Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
QVERIFY(col.isValid());
Item i;
......@@ -197,10 +196,10 @@ private Q_SLOTS:
void testCollectionDelete()
{
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy spy(monitor.get(), &Monitor::itemsRemoved);
const Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
const Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
ItemFetchJob *fjob = new ItemFetchJob(col, this);
AKVERIFYEXEC(fjob);
auto items = fjob->items();
......
......@@ -17,8 +17,6 @@
02110-1301, USA.
*/
#include "test_utils.h"
#include "collection.h"
#include "control.h"
#include "itemfetchjob.h"
......@@ -52,12 +50,12 @@ private Q_SLOTS:
QTest::addColumn<Collection>("destination");
QTest::addColumn<Collection>("source");
Collection destination(collectionIdFromPath(QStringLiteral("res1/foo/bar")));
Collection destination(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bar")));
QVERIFY(destination.isValid());
QTest::newRow("intra-res single uid") << (Item::List() << Item(5)) << destination << Collection();
destination = Collection(collectionIdFromPath(QStringLiteral("res3")));
destination = Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res3")));
QVERIFY(destination.isValid());
QTest::newRow("inter-res single uid") << (Item::List() << Item(1)) << destination << Collection();
......@@ -125,7 +123,7 @@ private Q_SLOTS:
void testIllegalMove()
{
Collection col(collectionIdFromPath(QStringLiteral("res2")));
Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res2")));
QVERIFY(col.isValid());
ItemFetchJob *prefetchjob = new ItemFetchJob(Item(1));
......@@ -137,7 +135,7 @@ private Q_SLOTS:
ItemMoveJob *store = new ItemMoveJob(item, Collection(INT_MAX), this);
QVERIFY(!store->exec());
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy itemMovedSpy(monitor.get(), &Monitor::itemsMoved);
// move item into folder that doesn't support its mimetype
......@@ -151,11 +149,11 @@ private Q_SLOTS:
void testMoveNotifications()
{
auto monitor = getTestMonitor();
auto monitor = AkonadiTest::getTestMonitor();
QSignalSpy itemMovedSpy(monitor.get(), &Monitor::itemsMoved);
QSignalSpy itemAddedSpy(monitor.get(), &Monitor::itemAdded);
Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
Collection col(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
Item item(QStringLiteral("application/octet-stream"));
item.setFlags({ "\\SEEN", "$ENCRYPTED" });
item.setPayload(QByteArray("This is a test payload"));
......@@ -170,7 +168,7 @@ private Q_SLOTS:
QCOMPARE(ntfItem.id(), item.id());
QCOMPARE(ntfItem.flags(), item.flags());
Collection dest(collectionIdFromPath(QStringLiteral("res1/foo/bar")));
Collection dest(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo/bar")));
auto move = new ItemMoveJob(item, dest, this);
AKVERIFYEXEC(move);
......
......@@ -17,7 +17,7 @@
02110-1301, USA.
*/
#include "test_utils.h"
#include "qtest_akonadi.h"
#include "collection.h"
#include "item.h"
......
......@@ -34,7 +34,6 @@
#include "itemmodifyjob_p.h"
#include "resourceselectjob_p.h"
#include "qtest_akonadi.h"
#include "test_utils.h"
using namespace Akonadi;
......@@ -51,11 +50,11 @@ void ItemStoreTest::initTestCase()
AttributeFactory::registerAttribute<TestAttribute>();
// get the collections we run the tests on
res1_foo = Collection(collectionIdFromPath(QStringLiteral("res1/foo")));
res1_foo = Collection(AkonadiTest::collectionIdFromPath(QStringLiteral("res1/foo")));
QVERIFY(res1_foo.isValid());