void TagTest::testFetchTagIdWithItem() { const Collection res3 = Collection(collectionIdFromPath(QStringLiteral("res3"))); Tag tag; { TagCreateJob *createjob = new TagCreateJob(Tag(QStringLiteral("gid1")), this); AKVERIFYEXEC(createjob); tag = createjob->tag(); } Item item1; { item1.setMimeType(QStringLiteral("application/octet-stream")); item1.setTag(tag); ItemCreateJob *append = new ItemCreateJob(item1, res3, this); AKVERIFYEXEC(append); item1 = append->item(); } ItemFetchJob *fetchJob = new ItemFetchJob(item1, this); fetchJob->fetchScope().setFetchTags(true); fetchJob->fetchScope().tagFetchScope().setFetchIdOnly(true); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->items().first().tags().size(), 1); Tag t = fetchJob->items().first().tags().first(); QCOMPARE(t.id(), tag.id()); QVERIFY(t.gid().isEmpty()); TagDeleteJob *deleteJob = new TagDeleteJob(tag, this); AKVERIFYEXEC(deleteJob); }
void TagTest::testFetchItemsByTag() { const Collection res3 = Collection(collectionIdFromPath(QStringLiteral("res3"))); Tag tag; { TagCreateJob *createjob = new TagCreateJob(Tag(QStringLiteral("gid1")), this); AKVERIFYEXEC(createjob); tag = createjob->tag(); } Item item1; { item1.setMimeType(QStringLiteral("application/octet-stream")); ItemCreateJob *append = new ItemCreateJob(item1, res3, this); AKVERIFYEXEC(append); item1 = append->item(); //FIXME This should also be possible with create, but isn't item1.setTag(tag); } ItemModifyJob *modJob = new ItemModifyJob(item1, this); AKVERIFYEXEC(modJob); ItemFetchJob *fetchJob = new ItemFetchJob(tag, this); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->items().size(), 1); Item i = fetchJob->items().first(); QCOMPARE(i, item1); TagDeleteJob *deleteJob = new TagDeleteJob(tag, this); AKVERIFYEXEC(deleteJob); }
void TagTest::testModifyItemWithTagByGID() { const Collection res3 = Collection(collectionIdFromPath(QStringLiteral("res3"))); { Tag tag; tag.setGid("gid2"); TagCreateJob *createjob = new TagCreateJob(tag, this); AKVERIFYEXEC(createjob); } Item item1; { item1.setMimeType(QStringLiteral("application/octet-stream")); ItemCreateJob *append = new ItemCreateJob(item1, res3, this); AKVERIFYEXEC(append); item1 = append->item(); } Tag tag; tag.setGid("gid2"); item1.setTag(tag); ItemModifyJob *modJob = new ItemModifyJob(item1, this); AKVERIFYEXEC(modJob); ItemFetchJob *fetchJob = new ItemFetchJob(item1, this); fetchJob->fetchScope().setFetchTags(true); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->items().first().tags().size(), 1); TagDeleteJob *deleteJob = new TagDeleteJob(fetchJob->items().first().tags().first(), this); AKVERIFYEXEC(deleteJob); }
void ItemAppendTest::testMultipartAppend() { const Collection testFolder1(collectionIdFromPath(QStringLiteral("res2/space folder"))); QVERIFY(testFolder1.isValid()); Item item; item.setMimeType(QStringLiteral("application/octet-stream")); item.setPayload<QByteArray>("body data"); item.attribute<TestAttribute>(Item::AddIfMissing)->data = "extra data"; item.setFlag("TestFlag"); ItemCreateJob *job = new ItemCreateJob(item, testFolder1, this); AKVERIFYEXEC(job); Item ref = job->item(); ItemFetchJob *fjob = new ItemFetchJob(ref, this); fjob->fetchScope().fetchFullPayload(); fjob->fetchScope().fetchAttribute<TestAttribute>(); AKVERIFYEXEC(fjob); QCOMPARE(fjob->items().count(), 1); item = fjob->items().first(); QCOMPARE(item.payload<QByteArray>(), QByteArray("body data")); QVERIFY(item.hasAttribute<TestAttribute>()); QCOMPARE(item.attribute<TestAttribute>()->data, QByteArray("extra data")); QVERIFY(item.flags().contains("TestFlag")); ItemDeleteJob *djob = new ItemDeleteJob(ref, this); AKVERIFYEXEC(djob); }
void testMove() { QFETCH( Item::List, items ); QFETCH( Collection, destination ); Collection source( collectionIdFromPath( "res1/foo" ) ); QVERIFY( source.isValid() ); ResourceSelectJob *select = new ResourceSelectJob( "akonadi_knut_resource_0" ); AKVERIFYEXEC( select ); // for rid based moves ItemFetchJob *prefetchjob = new ItemFetchJob( destination, this ); AKVERIFYEXEC( prefetchjob ); int baseline = prefetchjob->items().size(); ItemMoveJob *move = new ItemMoveJob( items, destination, this ); AKVERIFYEXEC( move ); ItemFetchJob *fetch = new ItemFetchJob( destination, this ); fetch->fetchScope().fetchFullPayload(); AKVERIFYEXEC( fetch ); QCOMPARE( fetch->items().count(), items.count() + baseline ); foreach ( const Item& movedItem, fetch->items() ) { QVERIFY( movedItem.hasPayload() ); QVERIFY( !movedItem.payload<QByteArray>().isEmpty() ); } }
void ItemAppendTest::testContent() { const Collection testFolder1(collectionIdFromPath(QStringLiteral("res2/space folder"))); QVERIFY(testFolder1.isValid()); QFETCH(QByteArray, data); Item item; item.setMimeType(QStringLiteral("application/octet-stream")); if (!data.isNull()) { item.setPayload(data); } ItemCreateJob *job = new ItemCreateJob(item, testFolder1, this); AKVERIFYEXEC(job); Item ref = job->item(); ItemFetchJob *fjob = new ItemFetchJob(testFolder1, this); fjob->fetchScope().setCacheOnly(true); fjob->fetchScope().fetchFullPayload(); AKVERIFYEXEC(fjob); QCOMPARE(fjob->items().count(), 1); Item item2 = fjob->items().first(); QCOMPARE(item2.hasPayload(), !data.isNull()); if (item2.hasPayload()) { QCOMPARE(item2.payload<QByteArray>(), data); } ItemDeleteJob *djob = new ItemDeleteJob(ref, this); AKVERIFYEXEC(djob); }
void testCopy() { const Collection target(collectionIdFromPath(QStringLiteral("res3"))); QVERIFY(target.isValid()); ItemCopyJob *copy = new ItemCopyJob(Item(1), target); AKVERIFYEXEC(copy); Item source(1); ItemFetchJob *sourceFetch = new ItemFetchJob(source); AKVERIFYEXEC(sourceFetch); source = sourceFetch->items().first(); ItemFetchJob *fetch = new ItemFetchJob(target); fetch->fetchScope().fetchFullPayload(); fetch->fetchScope().fetchAllAttributes(); fetch->fetchScope().setCacheOnly(true); AKVERIFYEXEC(fetch); QCOMPARE(fetch->items().count(), 1); Item item = fetch->items().first(); QVERIFY(item.hasPayload()); QVERIFY(source.size() > 0); QVERIFY(item.size() > 0); QCOMPARE(item.size(), source.size()); QCOMPARE(item.attributes().count(), 1); QVERIFY(item.remoteId().isEmpty()); QEXPECT_FAIL("", "statistics are not properly updated after copy", Abort); QCOMPARE(target.statistics().count(), 1ll); }
void RelationTest::testCreateFetch() { const Collection res3 = Collection(collectionIdFromPath(QStringLiteral("res3"))); Item item1; { item1.setMimeType(QStringLiteral("application/octet-stream")); ItemCreateJob *append = new ItemCreateJob(item1, res3, this); AKVERIFYEXEC(append); item1 = append->item(); } Item item2; { item2.setMimeType(QStringLiteral("application/octet-stream")); ItemCreateJob *append = new ItemCreateJob(item2, res3, this); AKVERIFYEXEC(append); item2 = append->item(); } Relation rel(Relation::GENERIC, item1, item2); RelationCreateJob *createjob = new RelationCreateJob(rel, this); AKVERIFYEXEC(createjob); //Test fetch & create { RelationFetchJob *fetchJob = new RelationFetchJob(QVector<QByteArray>(), this); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->relations().size(), 1); QCOMPARE(fetchJob->relations().first().type(), QByteArray(Relation::GENERIC)); } //Test item fetch { ItemFetchJob *fetchJob = new ItemFetchJob(item1); fetchJob->fetchScope().setFetchRelations(true); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->items().first().relations().size(), 1); } { ItemFetchJob *fetchJob = new ItemFetchJob(item2); fetchJob->fetchScope().setFetchRelations(true); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->items().first().relations().size(), 1); } //Test delete { RelationDeleteJob *deleteJob = new RelationDeleteJob(rel, this); AKVERIFYEXEC(deleteJob); RelationFetchJob *fetchJob = new RelationFetchJob(QVector<QByteArray>(), this); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->relations().size(), 0); } }
void TagTest::testModifyItemWithTagByRID() { { ResourceSelectJob *select = new ResourceSelectJob(QStringLiteral("akonadi_knut_resource_0")); AKVERIFYEXEC(select); } const Collection res3 = Collection(collectionIdFromPath(QStringLiteral("res3"))); Tag tag3; { tag3.setGid("gid3"); tag3.setRemoteId("rid3"); TagCreateJob *createjob = new TagCreateJob(tag3, this); AKVERIFYEXEC(createjob); tag3 = createjob->tag(); } Item item1; { item1.setMimeType(QStringLiteral("application/octet-stream")); ItemCreateJob *append = new ItemCreateJob(item1, res3, this); AKVERIFYEXEC(append); item1 = append->item(); } Tag tag; tag.setRemoteId("rid2"); item1.setTag(tag); ItemModifyJob *modJob = new ItemModifyJob(item1, this); AKVERIFYEXEC(modJob); ItemFetchJob *fetchJob = new ItemFetchJob(item1, this); fetchJob->fetchScope().setFetchTags(true); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->items().first().tags().size(), 1); { TagDeleteJob *deleteJob = new TagDeleteJob(fetchJob->items().first().tags().first(), this); AKVERIFYEXEC(deleteJob); } { TagDeleteJob *deleteJob = new TagDeleteJob(tag3, this); AKVERIFYEXEC(deleteJob); } { ResourceSelectJob *select = new ResourceSelectJob(QStringLiteral("")); AKVERIFYEXEC(select); } }
void RetrieveItemsJob::Private::akonadiFetchResult(KJob *job) { if (job->error() != 0) { return; // handled by base class } ItemFetchJob *itemFetch = qobject_cast<ItemFetchJob *>(job); Q_ASSERT(itemFetch != 0); Item::List items = itemFetch->items(); itemFetch->clearItems(); // save memory qCDebug(MIXEDMAILDIR_LOG) << "Akonadi fetch got" << items.count() << "items"; mServerItemsByRemoteId.reserve(items.size()); for (int i = 0; i < items.count(); ++i) { Item &item = items[i]; // items without remoteId have not been written to the resource yet if (!item.remoteId().isEmpty()) { // set the parent collection (with all ancestors) in every item item.setParentCollection(mCollection); mServerItemsByRemoteId.insert(item.remoteId(), item); } } qCDebug(MIXEDMAILDIR_LOG) << "of which" << mServerItemsByRemoteId.count() << "have remoteId"; FileStore::ItemFetchJob *storeFetch = mStore->fetchItems(mCollection); // just basic items, no data connect(storeFetch, SIGNAL(result(KJob*)), q, SLOT(storeListResult(KJob*))); }
void ConflictHandler::slotOtherItemFetched( KJob *job ) { if ( job->error() ) { emit error( job->errorText() ); //TODO: extend error message return; } ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob*>( job ); if ( fetchJob->items().isEmpty() ) { emit error( i18n( "Did not find other item for conflict handling" ) ); return; } mConflictingItem = fetchJob->items().first(); QMetaObject::invokeMethod( this, "resolve", Qt::QueuedConnection ); }
void AkonadiSlave::stat(const QUrl &url) { qCDebug(AKONADISLAVE_LOG) << url; // Stats for a collection if (Collection::fromUrl(url).isValid()) { Collection collection = Collection::fromUrl(url); if (collection != Collection::root()) { // Check that the collection exists. CollectionFetchJob *job = new CollectionFetchJob(collection, CollectionFetchJob::Base); if (!job->exec()) { error(KIO::ERR_INTERNAL, job->errorString()); return; } if (job->collections().count() != 1) { error(KIO::ERR_DOES_NOT_EXIST, i18n("No such item.")); return; } collection = job->collections().at(0); } statEntry(entryForCollection(collection)); finished(); } // Stats for an item else if (Item::fromUrl(url).isValid()) { ItemFetchJob *job = new ItemFetchJob(Item::fromUrl(url)); if (!job->exec()) { error(KIO::ERR_INTERNAL, job->errorString()); return; } if (job->items().count() != 1) { error(KIO::ERR_DOES_NOT_EXIST, i18n("No such item.")); return; } const Item item = job->items().at(0); statEntry(entryForItem(item)); finished(); } }
void RecursiveMover::itemFetchResult( KJob *job ) { Q_ASSERT( m_currentAction == None ); --m_runningJobs; if ( job->error() ) return; // error handling is in the base class ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob*>( job ); if ( fetchJob->items().size() == 1 ) { m_currentAction = AddItem; m_agentBase->itemAdded( fetchJob->items().first(), m_currentCollection ); } else { // deleted since we started, skip m_currentItem = Item(); replayNextItem(); } }
void ItemAppendTest::testNewMimetype() { const Collection col(collectionIdFromPath(QStringLiteral("res2/space folder"))); QVERIFY(col.isValid()); Item item; item.setMimeType(QStringLiteral("application/new-type")); ItemCreateJob *job = new ItemCreateJob(item, col, this); AKVERIFYEXEC(job); item = job->item(); QVERIFY(item.isValid()); ItemFetchJob *fetch = new ItemFetchJob(item, this); AKVERIFYEXEC(fetch); QCOMPARE(fetch->items().count(), 1); QCOMPARE(fetch->items().first().mimeType(), item.mimeType()); }
void ItemAppendTest::testItemSize() { QFETCH(Akonadi::Item, item); QFETCH(qint64, size); const Collection col(collectionIdFromPath(QStringLiteral("res2/space folder"))); QVERIFY(col.isValid()); ItemCreateJob *create = new ItemCreateJob(item, col, this); AKVERIFYEXEC(create); Item newItem = create->item(); ItemFetchJob *fetch = new ItemFetchJob(newItem, this); AKVERIFYEXEC(fetch); QCOMPARE(fetch->items().count(), 1); QCOMPARE(fetch->items().first().size(), size); }
void testIllegalMove() { Collection col( collectionIdFromPath( "res2" ) ); QVERIFY( col.isValid() ); ItemFetchJob *prefetchjob = new ItemFetchJob( Item( 1 ) ); AKVERIFYEXEC( prefetchjob ); QCOMPARE( prefetchjob->items().count(), 1 ); Item item = prefetchjob->items()[0]; // move into invalid collection ItemMoveJob *store = new ItemMoveJob( item, Collection( INT_MAX ), this ); QVERIFY( !store->exec() ); // move item into folder that doesn't support its mimetype store = new ItemMoveJob( item, col, this ); QEXPECT_FAIL( "", "Check not yet implemented by the server.", Continue ); QVERIFY( !store->exec() ); }
void FilterActionJob::Private::fetchResult( KJob *job ) { if ( job->error() ) { // KCompositeJob takes care of errors. return; } ItemFetchJob *fjob = dynamic_cast<ItemFetchJob*>( job ); Q_ASSERT( fjob ); Q_ASSERT( items.isEmpty() ); items = fjob->items(); traverseItems(); }
void AkonadiSlave::get(const QUrl &url) { const Item item = Item::fromUrl(url); ItemFetchJob *job = new ItemFetchJob(item); job->fetchScope().fetchFullPayload(); if (!job->exec()) { error(KIO::ERR_INTERNAL, job->errorString()); return; } if (job->items().count() != 1) { error(KIO::ERR_DOES_NOT_EXIST, i18n("No such item.")); } else { const Item item = job->items().at(0); QByteArray tmp = item.payloadData(); data(tmp); data(QByteArray()); finished(); } finished(); }
void TransportResourceBasePrivate::fetchResult(KJob *job) { if (job->error()) { const Item::Id id = job->property("id").toLongLong(); emit transportResult(id, (int)TransportResourceBase::TransportFailed, job->errorText()); return; } ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob *>(job); Q_ASSERT(fetchJob); const Item item = fetchJob->items().at(0); q->sendItem(item); }
void TagTest::testTagItem() { Akonadi::Monitor monitor; monitor.itemFetchScope().setFetchTags(true); monitor.setAllMonitored(true); const Collection res3 = Collection(collectionIdFromPath(QStringLiteral("res3"))); Tag tag; { TagCreateJob *createjob = new TagCreateJob(Tag(QStringLiteral("gid1")), this); AKVERIFYEXEC(createjob); tag = createjob->tag(); } Item item1; { item1.setMimeType(QStringLiteral("application/octet-stream")); ItemCreateJob *append = new ItemCreateJob(item1, res3, this); AKVERIFYEXEC(append); item1 = append->item(); } item1.setTag(tag); QSignalSpy tagsSpy(&monitor, SIGNAL(itemsTagsChanged(Akonadi::Item::List,QSet<Akonadi::Tag>,QSet<Akonadi::Tag>))); QVERIFY(tagsSpy.isValid()); ItemModifyJob *modJob = new ItemModifyJob(item1, this); AKVERIFYEXEC(modJob); QTRY_VERIFY(tagsSpy.count() >= 1); QTRY_COMPARE(tagsSpy.last().first().value<Akonadi::Item::List>().first().id(), item1.id()); QTRY_COMPARE(tagsSpy.last().at(1).value< QSet<Tag> >().size(), 1); //1 added tag ItemFetchJob *fetchJob = new ItemFetchJob(item1, this); fetchJob->fetchScope().setFetchTags(true); AKVERIFYEXEC(fetchJob); QCOMPARE(fetchJob->items().first().tags().size(), 1); TagDeleteJob *deleteJob = new TagDeleteJob(tag, this); AKVERIFYEXEC(deleteJob); }
void InfoCommand::onItemsFetched(KJob *job) { if (job->error() != 0) { emit error(job->errorString()); emit finished(RuntimeError); return; } ItemFetchJob *fetchJob = qobject_cast<ItemFetchJob *>(job); Q_ASSERT(fetchJob!=0); Item::List items = fetchJob->items(); if (items.count()<1) { emit error(i18nc("@info:shell", "Cannot find '%1' as a collection or item", mEntityArg)); emit finished(RuntimeError); return; } mInfoItem = new Item(items.first()); fetchParentPath(mInfoItem->parentCollection()); }
void akonadimailsearch::onItemsFetched(KJob *job) { if (job->error()) { kWarning() << job->errorString(); } else { ItemFetchJob *itemFetchJob = qobject_cast<ItemFetchJob*>(job); foreach (const Item &item, itemFetchJob->items()) { if(item.hasPayload<KABC::Addressee>()) { const QString id = item.url().prettyUrl(); const KABC::Addressee contact = item.payload<KABC::Addressee>(); QTextStream out(stdout); if(contact.preferredEmail().size() > 0 && \ ( contact.preferredEmail().contains(mysearch) || contact.formattedName().contains(mysearch) )){ out << contact.formattedName() << " <" << contact.preferredEmail()<< ">" <<endl; } } } } if (--activeFetchJobsCount == 0) { emit finished(); } }
void MailDirRemoveReadMessages::runTest() { timer.start(); qDebug() << " Removing read messages from every folder."; CollectionFetchJob *clj4 = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive); clj4->fetchScope().setResource(currentInstance.identifier()); clj4->exec(); const Collection::List list4 = clj4->collections(); for (const Collection &collection : list4) { ItemFetchJob *ifj = new ItemFetchJob(collection, this); ifj->exec(); const auto items = ifj->items(); for (const Item &item : items) { // delete read messages if (item.hasFlag("\\SEEN")) { ItemDeleteJob *idj = new ItemDeleteJob(item, this); idj->exec(); } } } outputStats(QStringLiteral("removereaditems")); }
void ItemAppendTest::testItemAppend() { const Collection testFolder1(collectionIdFromPath(QStringLiteral("res2/space folder"))); QVERIFY(testFolder1.isValid()); QFETCH(QString, remoteId); Item ref; // for cleanup Item item(-1); item.setRemoteId(remoteId); item.setMimeType(QStringLiteral("application/octet-stream")); item.setFlag("TestFlag"); item.setSize(3456); ItemCreateJob *job = new ItemCreateJob(item, testFolder1, this); AKVERIFYEXEC(job); ref = job->item(); QCOMPARE(ref.parentCollection(), testFolder1); ItemFetchJob *fjob = new ItemFetchJob(testFolder1, this); fjob->fetchScope().setAncestorRetrieval(ItemFetchScope::Parent); AKVERIFYEXEC(fjob); QCOMPARE(fjob->items().count(), 1); QCOMPARE(fjob->items()[0], ref); QCOMPARE(fjob->items()[0].remoteId(), remoteId); QVERIFY(fjob->items()[0].flags().contains("TestFlag")); QCOMPARE(fjob->items()[0].parentCollection(), ref.parentCollection()); qint64 size = 3456; QCOMPARE(fjob->items()[0].size(), size); ItemDeleteJob *djob = new ItemDeleteJob(ref, this); AKVERIFYEXEC(djob); fjob = new ItemFetchJob(testFolder1, this); AKVERIFYEXEC(fjob); QVERIFY(fjob->items().isEmpty()); }
void DupeTest::testDupes() { QFETCH(QString, message); QFETCH(int, count); QFETCH(int, delay); // clean sink ItemFetchJob *fjob = new ItemFetchJob(sink, this); AKVERIFYEXEC(fjob); if (fjob->items().count() > 0) { // this test is needed because ItemDeleteJob gives error if no items are found ItemDeleteJob *djob = new ItemDeleteJob(sink, this); AKVERIFYEXEC(djob); } fjob = new ItemFetchJob(sink, this); AKVERIFYEXEC(fjob); QCOMPARE(fjob->items().count(), 0); // queue messages Q_ASSERT(monitor); QSignalSpy *addSpy = new QSignalSpy(monitor, SIGNAL(itemAdded(Akonadi::Item,Akonadi::Collection))); qDebug() << "Queuing" << count << "messages..."; for (int i = 0; i < count; i++) { //qDebug() << "Queuing message" << i + 1 << "of" << count; Message::Ptr msg = Message::Ptr(new Message); msg->setContent(QStringLiteral("%1-msg%2\n").arg(message).arg(i + 1, 2, 10, QLatin1Char('0')).toLatin1()); MessageQueueJob *job = new MessageQueueJob(this); job->setMessage(msg); job->transportAttribute().setTransportId(TransportManager::self()->defaultTransportId()); // default dispatch mode // default sent-mail collection job->addressAttribute().setFrom(QStringLiteral("naiba")); job->addressAttribute().setTo(QStringList() << QStringLiteral("dracu")); //AKVERIFYEXEC( job ); job->start(); QTest::qWait(delay); } qDebug() << "Queued" << count << "messages."; // wait for the MDA to send them int seconds = 0; while (true) { seconds++; QTest::qWait(1000); qDebug() << seconds << "seconds elapsed." << addSpy->count() << "messages got to sink."; if (addSpy->count() >= count) { break; } #if 0 if (seconds >= TIMEOUT_SECONDS) { qDebug() << "Timeout, gdb master!"; QTest::qWait(1000 * 1000); } #endif QVERIFY2(seconds < TIMEOUT_SECONDS, "Timeout"); } // TODO I should verify that the MDA has actually finished its work and has an empty queue QTest::qWait(2000); // verify what has been sent fjob = new ItemFetchJob(sink, this); fjob->fetchScope().fetchFullPayload(); AKVERIFYEXEC(fjob); const Item::List items = fjob->items(); int found[ MAXCOUNT ]; for (int i = 0; i < count; i++) { found[i] = 0; } for (int i = 0; i < items.count(); i++) { QVERIFY(items[i].hasPayload<Message::Ptr>()); Message::Ptr msg = items[i].payload<Message::Ptr>(); const QByteArray content = msg->encodedContent(); //qDebug() << "i" << i << "content" << content; int loc = content.indexOf("-msg"); QVERIFY(loc >= 0); bool ok; int who = content.mid(loc + 4, 2).toInt(&ok); QVERIFY(ok); //qDebug() << "identified msg" << who; QVERIFY(who > 0 && who <= count); found[ who - 1 ]++; } for (int i = 0; i < count; i++) { if (found[i] > 1) { qDebug() << "found duplicate message" << i + 1 << "(" << found[i] << "times )"; } else if (found[i] < 1) { qDebug() << "didn't find message" << i + 1; } QCOMPARE(found[i], 1); } QCOMPARE(addSpy->count(), count); QCOMPARE(items.count(), count); }
// TODO: test signals void testMove() { QFETCH( Collection, source ); QFETCH( Collection, destination ); QFETCH( bool, crossResource ); QVERIFY( source.isValid() ); QVERIFY( destination.isValid() ); CollectionFetchJob *fetch = new CollectionFetchJob( source, CollectionFetchJob::Base, this ); AKVERIFYEXEC( fetch ); QCOMPARE( fetch->collections().count(), 1 ); source = fetch->collections().first(); // obtain reference listing fetch = new CollectionFetchJob( source, CollectionFetchJob::Recursive ); AKVERIFYEXEC( fetch ); QHash<Collection, Item::List> referenceData; foreach ( const Collection &c, fetch->collections() ) { ItemFetchJob *job = new ItemFetchJob( c, this ); AKVERIFYEXEC( job ); referenceData.insert( c, job->items() ); } // move collection CollectionMoveJob *mod = new CollectionMoveJob( source, destination, this ); AKVERIFYEXEC( mod ); // check if source was modified correctly CollectionFetchJob *ljob = new CollectionFetchJob( source, CollectionFetchJob::Base ); AKVERIFYEXEC( ljob ); Collection::List list = ljob->collections(); QCOMPARE( list.count(), 1 ); Collection col = list.first(); QCOMPARE( col.name(), source.name() ); QCOMPARE( col.parentCollection(), destination ); // list destination and check if everything is still there ljob = new CollectionFetchJob( destination, CollectionFetchJob::Recursive ); AKVERIFYEXEC( ljob ); list = ljob->collections(); QVERIFY( list.count() >= referenceData.count() ); for ( QHash<Collection, Item::List>::ConstIterator it = referenceData.constBegin(); it != referenceData.constEnd(); ++it ) { QVERIFY( list.contains( it.key() ) ); if ( crossResource ) { QVERIFY( list[ list.indexOf( it.key() ) ].resource() != it.key().resource() ); } else { QCOMPARE( list[ list.indexOf( it.key() ) ].resource(), it.key().resource() ); } ItemFetchJob *job = new ItemFetchJob( it.key(), this ); job->fetchScope().fetchFullPayload(); AKVERIFYEXEC( job ); QCOMPARE( job->items().count(), it.value().count() ); foreach ( const Item &item, job->items() ) { QVERIFY( it.value().contains( item ) ); QVERIFY( item.hasPayload() ); } } // cleanup mod = new CollectionMoveJob( col, source.parentCollection(), this ); AKVERIFYEXEC( mod ); }
void testLink() { SearchCreateJob *create = new SearchCreateJob( "linkTestFolder", "dummy query", this ); AKVERIFYEXEC( create ); CollectionFetchJob *list = new CollectionFetchJob( Collection( 1 ), CollectionFetchJob::Recursive, this ); AKVERIFYEXEC( list ); Collection col; foreach ( const Collection &c, list->collections() ) { if ( c.name() == "linkTestFolder" ) { col = c; } } QVERIFY( col.isValid() ); Item::List items; items << Item( 3 ) << Item( 4 ) << Item( 6 ); Monitor *monitor = new Monitor( this ); monitor->setCollectionMonitored( col ); monitor->itemFetchScope().fetchFullPayload(); qRegisterMetaType<Akonadi::Collection>(); qRegisterMetaType<Akonadi::Item>(); QSignalSpy lspy( monitor, SIGNAL(itemLinked(Akonadi::Item,Akonadi::Collection)) ); QSignalSpy uspy( monitor, SIGNAL(itemUnlinked(Akonadi::Item,Akonadi::Collection)) ); QVERIFY( lspy.isValid() ); QVERIFY( uspy.isValid() ); LinkJob *link = new LinkJob( col, items, this ); AKVERIFYEXEC( link ); QTest::qWait( 1000 ); QVERIFY( uspy.isEmpty() ); QCOMPARE( lspy.count(), 3 ); QList<QVariant> arg = lspy.takeFirst(); Item item = arg.at( 0 ).value<Item>(); QCOMPARE( item.mimeType(), QString::fromLatin1( "application/octet-stream" ) ); QVERIFY( item.hasPayload<QByteArray>() ); lspy.clear(); ItemFetchJob *fetch = new ItemFetchJob( col ); AKVERIFYEXEC( fetch ); QCOMPARE( fetch->items().count(), 3 ); foreach ( const Item &item, fetch->items() ) { QVERIFY( items.contains( item ) ); } UnlinkJob *unlink = new UnlinkJob( col, items, this ); AKVERIFYEXEC( unlink ); QTest::qWait( 1000 ); QVERIFY( lspy.isEmpty() ); QCOMPARE( uspy.count(), 3 ); fetch = new ItemFetchJob( col ); AKVERIFYEXEC( fetch ); QCOMPARE( fetch->items().count(), 0 ); }