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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
/* -*- c-basic-offset: 4 -*- */
/*
* Copyright (C) 2016 Caliste Damien.
* Contact: Damien Caliste <dcaliste@free.fr>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include <QtTest>
#include <QObject>
#include <QFile>
#include <reader.h>
#include <KCalendarCore/Event>
class tst_Reader : public QObject
{
Q_OBJECT
public:
tst_Reader();
virtual ~tst_Reader();
public slots:
void initTestCase();
void cleanupTestCase();
void init();
void cleanup();
private slots:
void readICal_data();
void readICal();
void readDate_data();
void readDate();
void readAlarm_data();
void readAlarm();
};
tst_Reader::tst_Reader()
{
}
tst_Reader::~tst_Reader()
{
}
void tst_Reader::initTestCase()
{
}
void tst_Reader::cleanupTestCase()
{
}
void tst_Reader::init()
{
}
void tst_Reader::cleanup()
{
}
void tst_Reader::readICal_data()
{
QTest::addColumn<QString>("xmlFilename");
QTest::addColumn<bool>("expectedNoError");
QTest::addColumn<int>("expectedNResponses");
QTest::addColumn<int>("expectedNIncidences");
QTest::addColumn<QString>("expectedUID");
QTest::addColumn<QString>("expectedSummary");
QTest::addColumn<QString>("expectedDescription");
QTest::addColumn<bool>("expectedRecurs");
QTest::addColumn<int>("expectedNAlarms");
QTest::newRow("no XML stream")
<< QStringLiteral("data/reader_noxml.xml")
<< false
<< 0
<< 0
<< QString()
<< QString()
<< QString()
<< false
<< 0;
QTest::newRow("malformed XML stream")
<< QStringLiteral("data/reader_nodav.xml")
<< false
<< 0
<< 0
<< QString()
<< QString()
<< QString()
<< false
<< 0;
QTest::newRow("unexpected prop elements in response")
<< QStringLiteral("data/reader_unexpected_elements.xml")
<< true
<< 1
<< 1
<< QString("D77EB0B9-B481-44D3-A109-3D2BD7CE5A36")
<< QString("Bob")
<< QString()
<< true
<< 0;
QTest::newRow("no incidence response")
<< QStringLiteral("data/reader_noevent.xml")
<< true
<< 1
<< 0
<< QString()
<< QString()
<< QString()
<< false
<< 0;
QTest::newRow("basic one incidence response")
<< QStringLiteral("data/reader_base.xml")
<< true
<< 1
<< 1
<< QStringLiteral("972a7c13-bbd6-4fce-9ebb-03a808111828")
<< QStringLiteral("Test")
<< QStringLiteral("")
<< false
<< 1;
QTest::newRow("UTF8 description response")
<< QStringLiteral("data/reader_UTF8_description.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123456789")
<< QStringLiteral("Sieger F - Zweiter E")
<< QStringLiteral("UTF8 characters: nœud")
<< false
<< 0;
QTest::newRow("funny character in UID response")
<< QStringLiteral("data/reader_UID.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123-456@789%369$258*147")
<< QStringLiteral("Sieger F - Zweiter E")
<< QStringLiteral("description")
<< false
<< 0;
QTest::newRow("early UID, before VEVENT")
<< QStringLiteral("data/reader_earlyUID.xml")
<< true
<< 1
<< 1
<< QStringLiteral("1234567890abcdef")
<< QStringLiteral("early UID test")
<< QStringLiteral("")
<< false
<< 0;
QTest::newRow("description with CR response")
<< QStringLiteral("data/reader_CR_description.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123-456@789%369$258*147")
<< QStringLiteral("Sieger F - Zweiter E")
<< QStringLiteral("description\nmultilines\n")
<< false
<< 0;
QTest::newRow("basic vcalendar response")
<< QStringLiteral("data/reader_basic_vcal.xml")
<< true
<< 1
<< 1
<< QStringLiteral("572a7c13-bbd6-4fce-9ebb-03a808111828")
<< QStringLiteral("Test")
<< QStringLiteral("Test description")
<< false
<< 0;
QTest::newRow("missing version response")
<< QStringLiteral("data/reader_missing.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123456789")
<< QStringLiteral("Sieger F - Zweiter E")
<< QStringLiteral("Achtelfinale")
<< false
<< 0;
QTest::newRow("escaped xml tag within ics")
<< QStringLiteral("data/reader_xmltag.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123456789")
<< QStringLiteral("Chrzęst gąsienic été")
<< QStringLiteral("&a<b>c<d>e</d>f&g")
<< false
<< 0;
QTest::newRow("xml tags and entities within cdata")
<< QStringLiteral("data/reader_cdata.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123456789")
<< QStringLiteral("Regarder l'hôtel en Espagne")
<< QStringLiteral("&a<b>c<d>e</d>f&g")
<< false
<< 0;
QTest::newRow("url within ics description")
<< QStringLiteral("data/reader_urldescription.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123456789")
<< QStringLiteral("Sieger F - Zweiter E")
<< QStringLiteral("this https://www.sailfishos.org/test?id=one&two=2 &\"'<a> ok?")
<< false
<< 0;
QTest::newRow("relative alarm time")
<< QStringLiteral("data/reader_relativealarm.xml")
<< true
<< 1
<< 1
<< QStringLiteral("123456789")
<< QStringLiteral("Alarm")
<< QStringLiteral("Alarm with relative time.")
<< false
<< 1;
QTest::newRow("pending todo")
<< QStringLiteral("data/reader_todo_pending.xml")
<< true
<< 1
<< 1
<< QStringLiteral("20070313T123432Z-456553@example.com")
<< QStringLiteral("Submit Quebec Income Tax Return for 2006")
<< QString()
<< false
<< 0;
}
void tst_Reader::readICal()
{
QFETCH(QString, xmlFilename);
QFETCH(bool, expectedNoError);
QFETCH(int, expectedNResponses);
QFETCH(int, expectedNIncidences);
QFETCH(QString, expectedUID);
QFETCH(QString, expectedSummary);
QFETCH(QString, expectedDescription);
QFETCH(bool, expectedRecurs);
QFETCH(int, expectedNAlarms);
QFile f(QStringLiteral("%1/%2").arg(QCoreApplication::applicationDirPath(), xmlFilename));
if (!f.exists() || !f.open(QIODevice::ReadOnly)) {
QFAIL("Data file does not exist or cannot be opened for reading!");
}
Reader rd;
rd.read(f.readAll());
QCOMPARE(rd.hasError(), !expectedNoError);
if (!expectedNoError)
return;
QCOMPARE(rd.results().size(), expectedNResponses);
if (!rd.results().isEmpty())
QCOMPARE(rd.results().first().incidences.length(), expectedNIncidences);
if (!expectedNIncidences)
return;
KCalendarCore::Incidence::Ptr ev = KCalendarCore::Incidence::Ptr(rd.results().first().incidences[0]);
QCOMPARE(ev->uid(), expectedUID);
QCOMPARE(ev->summary(), expectedSummary);
QCOMPARE(ev->description(), expectedDescription);
QCOMPARE(ev->recurs(), expectedRecurs);
QCOMPARE(ev->alarms().length(), expectedNAlarms);
}
void tst_Reader::readDate_data()
{
QTest::addColumn<QString>("xmlFilename");
QTest::addColumn<bool>("expectedNoError");
QTest::addColumn<int>("expectedNResponses");
QTest::addColumn<int>("expectedNIncidences");
QTest::addColumn<QDate>("expectedStartDate");
QTest::addColumn<QDate>("expectedEndDate");
QTest::newRow("full day event")
<< QStringLiteral("data/reader_fullday.xml")
<< true
<< 1
<< 1
<< QDate(2017, 03, 24)
<< QDate(2017, 03, 24);
QTest::newRow("vcalendar full days")
<< QStringLiteral("data/reader_fullday_vcal.xml")
<< true
<< 1
<< 1
<< QDate(2017, 03, 24)
<< QDate(2017, 03, 24);
}
void tst_Reader::readDate()
{
QFETCH(QString, xmlFilename);
QFETCH(bool, expectedNoError);
QFETCH(int, expectedNResponses);
QFETCH(int, expectedNIncidences);
QFETCH(QDate, expectedStartDate);
QFETCH(QDate, expectedEndDate);
QFile f(QStringLiteral("%1/%2").arg(QCoreApplication::applicationDirPath(), xmlFilename));
if (!f.exists() || !f.open(QIODevice::ReadOnly)) {
QFAIL("Data file does not exist or cannot be opened for reading!");
}
Reader rd;
rd.read(f.readAll());
QCOMPARE(rd.hasError(), !expectedNoError);
if (!expectedNoError)
return;
QCOMPARE(rd.results().size(), expectedNResponses);
if (!rd.results().isEmpty())
QCOMPARE(rd.results().first().incidences.length(), expectedNIncidences);
if (!expectedNIncidences)
return;
KCalendarCore::Event::Ptr ev = rd.results().first().incidences[0].staticCast<KCalendarCore::Event>();
QCOMPARE(ev->dtStart().date(), expectedStartDate);
QCOMPARE(ev->dtEnd().date(), expectedEndDate);
}
void tst_Reader::readAlarm_data()
{
QTest::addColumn<QString>("xmlFilename");
QTest::addColumn<int>("expectedNAlarms");
QTest::addColumn<int>("expectedAction");
QTest::addColumn<QString>("expectedTime");
QTest::newRow("relative alarm time")
<< QStringLiteral("data/reader_relativealarm.xml")
<< 1
<< int(KCalendarCore::Alarm::Display)
<< QStringLiteral("2017-03-23T12:00:00");
}
void tst_Reader::readAlarm()
{
QFETCH(QString, xmlFilename);
QFETCH(int, expectedNAlarms);
QFETCH(int, expectedAction);
QFETCH(QString, expectedTime);
QFile f(QStringLiteral("%1/%2").arg(QCoreApplication::applicationDirPath(), xmlFilename));
if (!f.exists() || !f.open(QIODevice::ReadOnly)) {
QFAIL("Data file does not exist or cannot be opened for reading!");
}
Reader rd;
rd.read(f.readAll());
QVERIFY(!rd.hasError());
QCOMPARE(rd.results().size(), 1);
QCOMPARE(rd.results().first().incidences.length(), 1);
KCalendarCore::Incidence::Ptr ev = KCalendarCore::Incidence::Ptr(rd.results().first().incidences[0]);
QCOMPARE(ev->alarms().length(), expectedNAlarms);
KCalendarCore::Alarm::Ptr alarm(ev->alarms().at(0));
QCOMPARE(alarm->type(), KCalendarCore::Alarm::Type(expectedAction));
QCOMPARE(alarm->time(), QDateTime::fromString(expectedTime, Qt::ISODate));
}
#include "tst_reader.moc"
QTEST_MAIN(tst_Reader)
|