void CalendarBaseTest::createInitialIncidences() { mExpectedSlotResult = true; for (int i=0; i<5; ++i) { Event::Ptr event = Event::Ptr(new Event()); event->setUid(QStringLiteral("event") + QString::number(i)); event->setSummary(QStringLiteral("summary") + QString::number(i)); event->setDtStart(KDateTime::currentDateTime(KDateTime::UTC)); mUids.append(event->uid()); QVERIFY(mCalendar->addEvent(event)); QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); } mOneEventUid = mUids.last(); for (int i=0; i<5; ++i) { Todo::Ptr todo = Todo::Ptr(new Todo()); todo->setUid(QStringLiteral("todo") + QString::number(i)); todo->setDtStart(KDateTime::currentDateTime(KDateTime::UTC)); todo->setSummary(QStringLiteral("summary") + QString::number(i)); mUids.append(todo->uid()); QVERIFY(mCalendar->addTodo(todo)); QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); } mOneTodoUid = mUids.last(); for (int i=0; i<5; ++i) { Journal::Ptr journal = Journal::Ptr(new Journal()); journal->setUid(QStringLiteral("journal") + QString::number(i)); journal->setSummary(QStringLiteral("summary") + QString::number(i)); journal->setDtStart(KDateTime::currentDateTime(KDateTime::UTC)); mUids.append(journal->uid()); QVERIFY(mCalendar->addJournal(journal)); QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); } mOneJournalUid = mUids.last(); for (int i=0; i<5; ++i) { Incidence::Ptr incidence = Incidence::Ptr(new Event()); incidence->setUid(QStringLiteral("incidence") + QString::number(i)); incidence->setSummary(QStringLiteral("summary") + QString::number(i)); incidence->setDtStart(KDateTime::currentDateTime(KDateTime::UTC)); mUids.append(incidence->uid()); QVERIFY(mCalendar->addIncidence(incidence)); QTestEventLoop::instance().enterLoop(5); QVERIFY(!QTestEventLoop::instance().timeout()); } mOneIncidenceUid = mUids.last(); }
void ICalFormatTest::testCharsets() { ICalFormat format; const QDate currentDate = QDate::currentDate(); Event::Ptr event = Event::Ptr( new Event() ); event->setUid( "12345" ); event->setDtStart( KDateTime( currentDate ) ); event->setDtEnd( KDateTime( currentDate.addDays( 1 ) ) ); // ΓΌ const QChar latin1_umlaut[] = { 0xFC, '\0' }; event->setSummary( QString( latin1_umlaut ) ); // Test if toString( Incidence ) didn't mess charsets const QString serialized = format.toString( event.staticCast<Incidence>() ); const QChar utf_umlaut[] = { 0xC3, 0XBC, '\0' }; QVERIFY( serialized.toUtf8().contains( QString( utf_umlaut ).toLatin1().constData() ) ); QVERIFY( !serialized.toUtf8().contains( QString( latin1_umlaut ).toLatin1().constData() ) ); QVERIFY( serialized.toLatin1().contains( QString( latin1_umlaut ).toLatin1().constData() ) ); QVERIFY( !serialized.toLatin1().contains( QString( utf_umlaut ).toLatin1().constData() ) ); // test fromString( QString ) const QString serializedCalendar = "BEGIN:VCALENDAR\nPRODID:-//K Desktop Environment//NONSGML libkcal 3.2//EN\nVERSION:2.0\n" + serialized + "\nEND:VCALENDAR"; Incidence::Ptr event2 = format.fromString( serializedCalendar ); QVERIFY( event->summary() == event2->summary() ); QVERIFY( event2->summary().toUtf8() == QByteArray( QString( utf_umlaut ).toLatin1().constData() ) ); // test save() MemoryCalendar::Ptr calendar( new MemoryCalendar( "UTC" ) ); calendar->addIncidence( event ); QVERIFY( format.save( calendar, "hommer.ics" ) ); // Make sure hommer.ics is in UTF-8 QFile file( "hommer.ics" ); QVERIFY( file.open( QIODevice::ReadOnly | QIODevice::Text ) ); const QByteArray bytesFromFile = file.readAll(); QVERIFY( bytesFromFile.contains( QString( utf_umlaut ).toLatin1().constData() ) ); QVERIFY( !bytesFromFile.contains( QString( latin1_umlaut ).toLatin1().constData() ) ); file.close(); // Test load: MemoryCalendar::Ptr calendar2( new MemoryCalendar( "UTC" ) ); QVERIFY( format.load( calendar2, "hommer.ics" ) ); QVERIFY( calendar2->incidences().count() == 1 ); // kDebug() << format.toString( event.staticCast<Incidence>() ); // kDebug() << format.toString( calendar2->incidences().first() ); Event::Ptr loadedEvent = calendar2->incidences().first().staticCast<Event>(); QVERIFY( loadedEvent->summary().toUtf8() == QByteArray( QString( utf_umlaut ).toLatin1().constData() ) ); QVERIFY( *loadedEvent == *event ); // Test fromRawString() MemoryCalendar::Ptr calendar3( new MemoryCalendar( "UTC" ) ); format.fromRawString( calendar3, bytesFromFile ); QVERIFY( calendar3->incidences().count() == 1 ); QVERIFY( *calendar3->incidences().first() == *event ); unlink( "hommer.ics" ); }