summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vrátil <dvratil@kde.org>2016-09-07 14:31:59 (GMT)
committerDaniel Vrátil <dvratil@kde.org>2016-09-07 14:31:59 (GMT)
commitfa3ee6c55654be79a70757bee1a518c036f57d4a (patch)
tree66f62ae6838a219272570699cd649cc04279a19c
parentdbe3e080eaa5848ffe2a2378805afdff932b7a8a (diff)
Extend ItemDeleteTest
-rw-r--r--autotests/libs/itemdeletetest.cpp53
-rw-r--r--autotests/libs/test_utils.h21
2 files changed, 72 insertions, 2 deletions
diff --git a/autotests/libs/itemdeletetest.cpp b/autotests/libs/itemdeletetest.cpp
index bb580cb..9e014ed 100644
--- a/autotests/libs/itemdeletetest.cpp
+++ b/autotests/libs/itemdeletetest.cpp
@@ -27,6 +27,7 @@
#include <tagcreatejob.h>
#include <itemmodifyjob.h>
#include <resourceselectjob_p.h>
+#include <monitor.h>
#include "test_utils.h"
#include <QtCore/QObject>
@@ -57,6 +58,9 @@ private Q_SLOTS:
void testDelete()
{
+ auto monitor = getTestMonitor();
+ QSignalSpy spy(monitor, &Monitor::itemsRemoved);
+
ItemFetchJob *fjob = new ItemFetchJob(Item(1), this);
AKVERIFYEXEC(fjob);
QCOMPARE(fjob->items().count(), 1);
@@ -66,10 +70,19 @@ private Q_SLOTS:
fjob = new ItemFetchJob(Item(1), this);
QVERIFY(!fjob->exec());
+
+ QTRY_COMPARE(spy.count(), 1);
+ auto items = spy.at(0).at(0).value<Akonadi::Item::List>();
+ QCOMPARE(items.count(), 1);
+ QCOMPARE(items.at(0).id(), 1);
+ QVERIFY(items.at(0).parentCollection().isValid());
}
void testDeleteFromUnselectedCollection()
{
+ auto monitor = getTestMonitor();
+ QSignalSpy spy(monitor, &Monitor::itemsRemoved);
+
const QString path = QStringLiteral("res1") +
CollectionPathResolver::pathDelimiter() +
QStringLiteral("foo");
@@ -91,10 +104,19 @@ private Q_SLOTS:
fjob = new ItemFetchJob(items[ 0 ], this);
QVERIFY(!fjob->exec());
+
+ QTRY_COMPARE(spy.count(), 1);
+ auto ntfItems = spy.at(0).at(0).value<Akonadi::Item::List>();
+ QCOMPARE(ntfItems.count(), 1);
+ QCOMPARE(ntfItems.at(0).id(), items[0].id());
+ QVERIFY(ntfItems.at(0).parentCollection().isValid());
}
void testRidDelete()
{
+ auto monitor = getTestMonitor();
+ QSignalSpy spy(monitor, &Monitor::itemsRemoved);
+
{
ResourceSelectJob *select = new ResourceSelectJob(QStringLiteral("akonadi_knut_resource_0"));
AKVERIFYEXEC(select);
@@ -108,11 +130,18 @@ private Q_SLOTS:
ItemFetchJob *fjob = new ItemFetchJob(i, this);
fjob->setCollection(col);
AKVERIFYEXEC(fjob);
- QCOMPARE(fjob->items().count(), 1);
+ auto items = fjob->items();
+ QCOMPARE(items.count(), 1);
ItemDeleteJob *djob = new ItemDeleteJob(i, this);
AKVERIFYEXEC(djob);
+ QTRY_COMPARE(spy.count(), 1);
+ auto ntfItems = spy.at(0).at(0).value<Akonadi::Item::List>();
+ QCOMPARE(ntfItems.count(), 1);
+ QCOMPARE(ntfItems.at(0).id(), items[0].id());
+ QVERIFY(ntfItems.at(0).parentCollection().isValid());
+
fjob = new ItemFetchJob(i, this);
fjob->setCollection(col);
QVERIFY(!fjob->exec());
@@ -124,6 +153,9 @@ private Q_SLOTS:
void testTagDelete()
{
+ auto monitor = getTestMonitor();
+ QSignalSpy spy(monitor, &Monitor::itemsRemoved);
+
// Create tag
Tag tag;
tag.setName(QStringLiteral("Tag1"));
@@ -152,6 +184,12 @@ private Q_SLOTS:
ItemDeleteJob *djob = new ItemDeleteJob(tag, this);
AKVERIFYEXEC(djob);
+ QTRY_COMPARE(spy.count(), 1);
+ auto ntfItems = spy.at(0).at(0).value<Akonadi::Item::List>();
+ QCOMPARE(ntfItems.count(), 1);
+ QCOMPARE(ntfItems.at(0).id(), i.id());
+ QVERIFY(ntfItems.at(0).parentCollection().isValid());
+
// Try to fetch the item again, there should be none
fjob = new ItemFetchJob(i, this);
QVERIFY(!fjob->exec());
@@ -159,15 +197,26 @@ private Q_SLOTS:
void testCollectionDelete()
{
+ auto monitor = getTestMonitor();
+ QSignalSpy spy(monitor, &Monitor::itemsRemoved);
+
const Collection col(collectionIdFromPath(QStringLiteral("res1/foo")));
ItemFetchJob *fjob = new ItemFetchJob(col, this);
AKVERIFYEXEC(fjob);
- QVERIFY(fjob->items().count() > 0);
+ auto items = fjob->items();
+ QVERIFY(items.count() > 0);
// delete from non-empty collection
ItemDeleteJob *djob = new ItemDeleteJob(col, this);
AKVERIFYEXEC(djob);
+ QTRY_COMPARE(spy.count(), 1);
+ auto ntfItems = spy.at(0).at(0).value<Akonadi::Item::List>();
+ QCOMPARE(ntfItems.count(), items.count());
+ if (ntfItems.count() > 0) {
+ QVERIFY(ntfItems.at(0).parentCollection().isValid());
+ }
+
fjob = new ItemFetchJob(col, this);
AKVERIFYEXEC(fjob);
QCOMPARE(fjob->items().count(), 0);
diff --git a/autotests/libs/test_utils.h b/autotests/libs/test_utils.h
index 4d285e6..ac8f036 100644
--- a/autotests/libs/test_utils.h
+++ b/autotests/libs/test_utils.h
@@ -24,6 +24,10 @@
#include "kdbusconnectionpool.h"
#include "servermanager.h"
#include "qtest_akonadi.h"
+#include "monitor.h"
+#include "collectionfetchscope.h"
+#include "itemfetchscope.h"
+
#include <QDBusInterface>
#include <QDBusReply>
@@ -93,4 +97,21 @@ bool trackAkonadiProcess(bool track)
}
}
+Akonadi::Monitor *getTestMonitor()
+{
+ auto m = new Akonadi::Monitor();
+ m->fetchCollection(true);
+ m->collectionMonitored(Akonadi::Collection::root(), true);
+ m->setAllMonitored(true);
+ auto &itemFS = m->itemFetchScope();
+ itemFS.setAncestorRetrieval(Akonadi::ItemFetchScope::All);
+ auto &colFS = m->collectionFetchScope();
+ colFS.setAncestorRetrieval(Akonadi::CollectionFetchScope::All);
+
+ QSignalSpy readySpy(m, &Akonadi::Monitor::monitorReady);
+ readySpy.wait();
+
+ return m;
+}
+
#endif