1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
/*
Copyright (c) 2011 Sérgio Martins <iamsergio@gmail.com>
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 <itemfetchjob.h>
#include <itemcreatejob.h>
#include <collectionfetchjob.h>
#include <collectionfetchscope.h>
#include <qtest_akonadi.h>
#include <QTestEventLoop>
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->setUid(uid);
incidence->setSummary(QStringLiteral("summary"));
incidence->setDtStart(KDateTime::currentDateTime(KDateTime::UTC));
item.setPayload<KCalCore::Incidence::Ptr>(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>("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();
}
};
QTEST_AKONADIMAIN(FetchJobCalendarTest)
#include "fetchjobcalendartest.moc"
|