diff --git a/autotests/fetchjobcalendartest.cpp b/autotests/fetchjobcalendartest.cpp index e212cd7..f052c73 100644 --- a/autotests/fetchjobcalendartest.cpp +++ b/autotests/fetchjobcalendartest.cpp @@ -1,115 +1,100 @@ /* Copyright (c) 2011 Sérgio Martins This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "../src/fetchjobcalendar.h" #include #include #include #include #include -#include - using namespace Akonadi; using namespace KCalCore; class FetchJobCalendarTest : public QObject { Q_OBJECT Collection mCollection; void createIncidence(const QString &uid) { Item item; item.setMimeType(Event::eventMimeType()); - Incidence::Ptr incidence = Incidence::Ptr(new Event()); + Incidence::Ptr incidence(new Event()); incidence->setUid(uid); incidence->setSummary(QStringLiteral("summary")); incidence->setDtStart(KDateTime::currentDateTime(KDateTime::UTC)); item.setPayload(incidence); ItemCreateJob *job = new ItemCreateJob(item, mCollection, this); AKVERIFYEXEC(job); } void fetchCollection() { CollectionFetchJob *job = new CollectionFetchJob(Collection::root(), CollectionFetchJob::Recursive, this); // Get list of collections job->fetchScope().setContentMimeTypes(QStringList() << QStringLiteral("application/x-vnd.akonadi.calendar.event")); AKVERIFYEXEC(job); // Find our collection Collection::List collections = job->collections(); QVERIFY(!collections.isEmpty()); mCollection = collections.first(); QVERIFY(mCollection.isValid()); } private Q_SLOTS: void initTestCase() { AkonadiTest::checkTestIsIsolated(); fetchCollection(); qRegisterMetaType("Akonadi::Item"); } void testFetching() { - createIncidence(tr("a")); - createIncidence(tr("b")); - createIncidence(tr("c")); - createIncidence(tr("d")); - createIncidence(tr("e")); - createIncidence(tr("f")); - - FetchJobCalendar *calendar = new FetchJobCalendar(); - connect(calendar, &FetchJobCalendar::loadFinished, - this, &FetchJobCalendarTest::handleLoadFinished); - QTestEventLoop::instance().enterLoop(10); - QVERIFY(!QTestEventLoop::instance().timeout()); - - Incidence::List incidences = calendar->incidences(); - QVERIFY(incidences.count() == 6); - QVERIFY(calendar->item(tr("a")).isValid()); - QVERIFY(calendar->item(tr("b")).isValid()); - QVERIFY(calendar->item(tr("c")).isValid()); - QVERIFY(calendar->item(tr("d")).isValid()); - QVERIFY(calendar->item(tr("e")).isValid()); - QVERIFY(calendar->item(tr("f")).isValid()); - - delete calendar; - } - -public Q_SLOTS: - void handleLoadFinished(bool success, const QString &errorMessage) - { - if (!success) { - qDebug() << errorMessage; - } - QVERIFY(success); - QTestEventLoop::instance().exitLoop(); + createIncidence(QStringLiteral("a")); + createIncidence(QStringLiteral("b")); + createIncidence(QStringLiteral("c")); + createIncidence(QStringLiteral("d")); + createIncidence(QStringLiteral("e")); + createIncidence(QStringLiteral("f")); + + FetchJobCalendar calendar; + QSignalSpy spy(&calendar, &FetchJobCalendar::loadFinished); + QVERIFY(spy.wait(1000)); + QVERIFY2(spy.at(0).at(0).toBool(), qPrintable(spy.at(0).at(1).toString())); + + const Incidence::List incidences = calendar.incidences(); + QCOMPARE(incidences.count(), 6); + QVERIFY(calendar.item(QStringLiteral("a")).isValid()); + QVERIFY(calendar.item(QStringLiteral("b")).isValid()); + QVERIFY(calendar.item(QStringLiteral("c")).isValid()); + QVERIFY(calendar.item(QStringLiteral("d")).isValid()); + QVERIFY(calendar.item(QStringLiteral("e")).isValid()); + QVERIFY(calendar.item(QStringLiteral("f")).isValid()); } }; QTEST_AKONADIMAIN(FetchJobCalendarTest) #include "fetchjobcalendartest.moc"