From 26816c21f60450e461a5b6ef4ef740f6070ce278 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Wed, 27 Jul 2016 02:26:47 +0200 Subject: Ported to the kasync revamp --- tests/accountstest.cpp | 8 ++++---- tests/clientapitest.cpp | 4 ++-- tests/dummyresourcebenchmark.cpp | 30 +----------------------------- tests/mailsynctest.cpp | 22 +++++++++++----------- tests/mailtest.cpp | 22 +++++++++++----------- tests/resourcecommunicationtest.cpp | 28 ++++++++++++++-------------- 6 files changed, 43 insertions(+), 71 deletions(-) (limited to 'tests') diff --git a/tests/accountstest.cpp b/tests/accountstest.cpp index 4be8bd6..e0a99c2 100644 --- a/tests/accountstest.cpp +++ b/tests/accountstest.cpp @@ -39,7 +39,7 @@ private slots: account.setProperty("icon", accountIcon); Store::create(account).exec().waitForFinished(); - Store::fetchAll(Query()).then>([&](const QList &accounts) { + Store::fetchAll(Query()).syncThen>([&](const QList &accounts) { QCOMPARE(accounts.size(), 1); auto account = accounts.first(); QCOMPARE(account->getProperty("type").toString(), QString("maildir")); @@ -60,7 +60,7 @@ private slots: Store::create(resource).exec().waitForFinished(); - Store::fetchAll(Query()).then>([&](const QList &resources) { + Store::fetchAll(Query()).syncThen>([&](const QList &resources) { QCOMPARE(resources.size(), 1); auto resource = resources.first(); QCOMPARE(resource->getProperty("type").toString(), QString("sink.mailtransport")); @@ -74,7 +74,7 @@ private slots: identity.setProperty("account", account.identifier()); Store::create(identity).exec().waitForFinished(); - Store::fetchAll(Query()).then>([&](const QList &identities) { + Store::fetchAll(Query()).syncThen>([&](const QList &identities) { QCOMPARE(identities.size(), 1); }) .exec().waitForFinished(); @@ -82,7 +82,7 @@ private slots: Store::remove(resource).exec().waitForFinished(); - Store::fetchAll(Query()).then>([](const QList &resources) { + Store::fetchAll(Query()).syncThen>([](const QList &resources) { QCOMPARE(resources.size(), 0); }) .exec().waitForFinished(); diff --git a/tests/clientapitest.cpp b/tests/clientapitest.cpp index b1e49c4..b5405cf 100644 --- a/tests/clientapitest.cpp +++ b/tests/clientapitest.cpp @@ -70,7 +70,7 @@ public: } resultProvider->initialResultSetComplete(parent); }); - auto job = KAsync::start([query, resultProvider]() {}); + auto job = KAsync::syncStart([query, resultProvider]() {}); mResultProvider = resultProvider; return qMakePair(job, emitter); } @@ -273,7 +273,7 @@ private slots: bool gotValue = false; auto result = Sink::Store::fetchOne(query) - .then([&gotValue](const Sink::ApplicationDomain::Event &event) { gotValue = true; }) + .syncThen([&gotValue](const Sink::ApplicationDomain::Event &event) { gotValue = true; }) .exec(); result.waitForFinished(); QVERIFY(!result.errorCode()); diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 72562c3..8636bf6 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp @@ -44,34 +44,6 @@ private slots: { } - static KAsync::Job waitForCompletion(QList> &futures) - { - auto context = new QObject; - return KAsync::start([futures, context](KAsync::Future &future) { - const auto total = futures.size(); - auto count = QSharedPointer::create(); - int i = 0; - for (KAsync::Future subFuture : futures) { - i++; - if (subFuture.isFinished()) { - *count += 1; - continue; - } - // FIXME bind lifetime all watcher to future (repectively the main job - auto watcher = QSharedPointer>::create(); - QObject::connect(watcher.data(), &KAsync::FutureWatcher::futureReady, [count, total, &future]() { - *count += 1; - if (*count == total) { - future.setFinished(); - } - }); - watcher->setFuture(subFuture); - context->setProperty(QString("future%1").arg(i).toLatin1().data(), QVariant::fromValue(watcher)); - } - }) - .then([context]() { delete context; }); - } - // Ensure we can process a command in less than 0.1s void testCommandResponsiveness() { @@ -120,7 +92,7 @@ private slots: event.setProperty("summary", "summaryValue"); waitCondition << Sink::Store::create(event).exec(); } - waitForCompletion(waitCondition).exec().waitForFinished(); + KAsync::waitForCompletion(waitCondition).exec().waitForFinished(); auto appendTime = time.elapsed(); // Ensure everything is processed diff --git a/tests/mailsynctest.cpp b/tests/mailsynctest.cpp index 4b797c8..9c57f0a 100644 --- a/tests/mailsynctest.cpp +++ b/tests/mailsynctest.cpp @@ -69,7 +69,7 @@ void MailSyncTest::testListFolders() //First figure out how many folders we have by default { auto job = Store::fetchAll(Query()) - .then>([&](const QList &folders) { + .syncThen>([&](const QList &folders) { QStringList names; for (const auto &folder : folders) { names << folder->getName(); @@ -88,7 +88,7 @@ void MailSyncTest::testListFolders() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([=](const QList &folders) { + auto job = Store::fetchAll(query).syncThen>([=](const QList &folders) { QStringList names; QHash specialPurposeFolders; for (const auto &folder : folders) { @@ -130,7 +130,7 @@ void MailSyncTest::testListNewFolder() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([](const QList &folders) { + auto job = Store::fetchAll(query).syncThen>([](const QList &folders) { QStringList names; for (const auto &folder : folders) { names << folder->getName(); @@ -155,7 +155,7 @@ void MailSyncTest::testListRemovedFolder() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([](const QList &folders) { + auto job = Store::fetchAll(query).syncThen>([](const QList &folders) { QStringList names; for (const auto &folder : folders) { names << folder->getName(); @@ -180,7 +180,7 @@ void MailSyncTest::testListFolderHierarchy() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([=](const QList &folders) { + auto job = Store::fetchAll(query).syncThen>([=](const QList &folders) { QHash map; for (const auto &folder : folders) { map.insert(folder->getName(), folder); @@ -223,7 +223,7 @@ void MailSyncTest::testListNewSubFolder() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([](const QList &folders) { + auto job = Store::fetchAll(query).syncThen>([](const QList &folders) { QStringList names; for (const auto &folder : folders) { names << folder->getName(); @@ -251,7 +251,7 @@ void MailSyncTest::testListRemovedSubFolder() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([](const QList &folders) { + auto job = Store::fetchAll(query).syncThen>([](const QList &folders) { QStringList names; for (const auto &folder : folders) { names << folder->getName(); @@ -271,7 +271,7 @@ void MailSyncTest::testListMails() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([](const QList &mails) { + auto job = Store::fetchAll(query).syncThen>([](const QList &mails) { QCOMPARE(mails.size(), 1); QVERIFY(mails.first()->getSubject().startsWith(QString("[Nepomuk] Jenkins build is still unstable"))); const auto data = mails.first()->getMimeMessage(); @@ -300,7 +300,7 @@ void MailSyncTest::testResyncMails() VERIFYEXEC(Store::synchronize(query)); ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); - auto job = Store::fetchAll(query).then>([](const QList &mails) { + auto job = Store::fetchAll(query).syncThen>([](const QList &mails) { QCOMPARE(mails.size(), 1); }); VERIFYEXEC(job); @@ -325,7 +325,7 @@ void MailSyncTest::testFetchNewRemovedMessages() ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); { - auto job = Store::fetchAll(query).then>([](const QList &mails) { + auto job = Store::fetchAll(query).syncThen>([](const QList &mails) { QCOMPARE(mails.size(), 2); }); VERIFYEXEC(job); @@ -337,7 +337,7 @@ void MailSyncTest::testFetchNewRemovedMessages() ResourceControl::flushMessageQueue(query.resources).exec().waitForFinished(); { - auto job = Store::fetchAll(query).then>([](const QList &mails) { + auto job = Store::fetchAll(query).syncThen>([](const QList &mails) { QCOMPARE(mails.size(), 1); }); VERIFYEXEC(job); diff --git a/tests/mailtest.cpp b/tests/mailtest.cpp index 908fb84..925fb70 100644 --- a/tests/mailtest.cpp +++ b/tests/mailtest.cpp @@ -66,7 +66,7 @@ void MailTest::testCreateModifyDeleteFolder() //First figure out how many folders we have by default { auto job = Store::fetchAll(Query()) - .then>([&](const QList &folders) { + .syncThen>([&](const QList &folders) { baseCount = folders.size(); }); VERIFYEXEC(job); @@ -83,7 +83,7 @@ void MailTest::testCreateModifyDeleteFolder() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) - .then>([=](const QList &folders) { + .syncThen>([=](const QList &folders) { QCOMPARE(folders.size(), baseCount + 1); QHash foldersByName; for (const auto &folder : folders) { @@ -109,7 +109,7 @@ void MailTest::testCreateModifyDeleteFolder() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) - .then>([=](const QList &folders) { + .syncThen>([=](const QList &folders) { QCOMPARE(folders.size(), baseCount + 1); QHash foldersByName; for (const auto &folder : folders) { @@ -130,7 +130,7 @@ void MailTest::testCreateModifyDeleteFolder() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Folder::Name::name << Folder::Icon::name)) - .then>([=](const QList &folders) { + .syncThen>([=](const QList &folders) { QCOMPARE(folders.size(), baseCount); }); VERIFYEXEC(job); @@ -160,7 +160,7 @@ void MailTest::testCreateModifyDeleteMail() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) - .then>([=](const QList &mails) { + .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); QCOMPARE(mail.getSubject(), subject); @@ -189,7 +189,7 @@ void MailTest::testCreateModifyDeleteMail() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) - .then>([=](const QList &mails) { + .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); QCOMPARE(mail.getSubject(), subject2); @@ -211,7 +211,7 @@ void MailTest::testCreateModifyDeleteMail() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name)) - .then>([=](const QList &mails) { + .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 0); }); VERIFYEXEC(job); @@ -247,7 +247,7 @@ void MailTest::testMoveMail() Mail modifiedMail; { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) - .then>([=, &modifiedMail](const QList &mails) { + .syncThen>([=, &modifiedMail](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); modifiedMail = mail; @@ -266,7 +266,7 @@ void MailTest::testMoveMail() VERIFYEXEC(ResourceControl::flushMessageQueue(QByteArrayList() << mResourceInstanceIdentifier)); { auto job = Store::fetchAll(Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name << Mail::MimeMessage::name)) - .then>([=](const QList &mails) { + .syncThen>([=](const QList &mails) { QCOMPARE(mails.size(), 1); auto mail = *mails.first(); QCOMPARE(mail.getFolder(), folder1.identifier()); @@ -299,7 +299,7 @@ void MailTest::testMarkMailAsRead() auto job = Store::fetchAll(Query::ResourceFilter(mResourceInstanceIdentifier) + Query::RequestedProperties(QByteArrayList() << Mail::Folder::name << Mail::Subject::name)) - .then, QList>([this](const QList &mails) { + .then>([this](const QList &mails) { ASYNCCOMPARE(mails.size(), 1); auto mail = mails.first(); mail->setUnread(false); @@ -316,7 +316,7 @@ void MailTest::testMarkMailAsRead() << Mail::Subject::name << Mail::MimeMessage::name << Mail::Unread::name)) - .then, QList>([](const QList &mails) { + .then>([](const QList &mails) { ASYNCCOMPARE(mails.size(), 1); auto mail = mails.first(); ASYNCVERIFY(!mail->getSubject().isEmpty()); diff --git a/tests/resourcecommunicationtest.cpp b/tests/resourcecommunicationtest.cpp index 1530f63..201db53 100644 --- a/tests/resourcecommunicationtest.cpp +++ b/tests/resourcecommunicationtest.cpp @@ -51,13 +51,14 @@ private slots: int errors = 0; for (int i = 0; i < count; i++) { auto result = resourceAccess.sendCommand(Sink::Commands::PingCommand) - .then([&complete]() { complete++; }, - [&errors, &complete](int error, const QString &msg) { - qWarning() << msg; - errors++; - complete++; - }) - .exec(); + .syncThen([&resourceAccess, &errors, &complete](const KAsync::Error &error) { + complete++; + if (error) { + qWarning() << error.errorMessage; + errors++; + } + }) + .exec(); } QTRY_COMPARE(complete, count); QVERIFY(!errors); @@ -76,13 +77,12 @@ private slots: int errors = 0; for (int i = 0; i < count; i++) { resourceAccess.sendCommand(Sink::Commands::PingCommand) - .then([&complete]() { complete++; }, - [&errors, &complete](int error, const QString &msg) { - qWarning() << msg; + .syncThen([&resourceAccess, &errors, &complete](const KAsync::Error &error) { + complete++; + if (error) { + qWarning() << error.errorMessage; errors++; - complete++; - }) - .then([&resourceAccess]() { + } resourceAccess.close(); resourceAccess.open(); }) @@ -104,7 +104,7 @@ private slots: auto resourceAccess = Sink::ResourceAccessFactory::instance().getAccess(resourceIdentifier, ""); weakRef = resourceAccess.toWeakRef(); resourceAccess->open(); - resourceAccess->sendCommand(Sink::Commands::PingCommand).then([resourceAccess]() { qDebug() << "Pind complete"; }).exec(); + resourceAccess->sendCommand(Sink::Commands::PingCommand).syncThen([resourceAccess]() { qDebug() << "Ping complete"; }).exec(); } QVERIFY(weakRef.toStrongRef()); QTRY_VERIFY(!weakRef.toStrongRef()); -- cgit v1.2.3