diff --git a/tests/testutils.h b/tests/testutils.h index 8a8f25c..12a5dea 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -1,250 +1,252 @@ /* * Copyright (C) 2012 Christian Mollekopf * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 program. If not, see . */ #ifndef TESTUTILS_H #define TESTUTILS_H #include #include #include #include #include #include "kolabformat/kolabobject.h" Q_DECLARE_METATYPE(Kolab::ObjectType); Q_DECLARE_METATYPE(Kolab::Version); #define KCOMPARE(actual, expected) \ do {\ if ( !(actual == expected) ) { \ qDebug() << __FILE__ << ':' << __LINE__ << "Actual: " #actual ": " << actual << "\nExpected: " #expected ": " << expected; \ return false; \ } \ } while (0) #endif #define DIFFCOMPARE(actual, expected) \ do {\ if ( !(actual.simplified() == expected.simplified()) ) { \ qDebug() << "Content not the same."; \ showDiff(expected, actual); \ QTest::qFail("Compared versions differ.", __FILE__, __LINE__); \ return; \ } \ } while (0) #define TESTVALUE(type, name)\ *static_cast(QTest::qData(#name, ::qMetaTypeId())) const QString TESTFILEDIR = QString::fromLatin1(TEST_DATA_PATH "/testfiles/"); QString getPath(const char *file) { return TESTFILEDIR+QString::fromLatin1(file); } void showDiff(const QString &expected, const QString &converted) { if (expected.isEmpty() || converted.isEmpty()) { qWarning() << "files are emtpy"; return; } if (expected == converted) { qWarning() << "contents are the same"; return; } bool showDiff = true; if (showDiff) { QTemporaryFile expectedFile("expectedFile"); QTemporaryFile convertedFile("convertedFile"); if (expectedFile.open() && convertedFile.open()) { expectedFile.write(expected.toLatin1()); convertedFile.write(converted.toLatin1()); expectedFile.close(); convertedFile.close(); QProcess::execute("kdiff3", QStringList() << expectedFile.fileName() << convertedFile.fileName()); } else { qWarning() << "files are not open"; } } else { qDebug() << "EXPECTED: " << expected; qDebug() << "CONVERTED: " << converted; } } KMime::Message::Ptr readMimeFile( const QString &fileName, bool &ok) { // qDebug() << fileName; QFile file( fileName ); ok = file.open( QFile::ReadOnly ); if (!ok) { qWarning() << "failed to open file: " << fileName; return KMime::Message::Ptr(); } const QByteArray data = file.readAll(); KMime::Message::Ptr msg = KMime::Message::Ptr(new KMime::Message); msg->setContent( data ); msg->parse(); return msg; } void normalizeMimemessage(QString &content) { content.replace(QRegExp("\\bLibkolab-\\d.\\d.\\d\\b", Qt::CaseSensitive), "Libkolab-x.x.x"); content.replace(QRegExp("\\bLibkolabxml-\\d.\\d.\\d\\b", Qt::CaseSensitive), "Libkolabxml-x.x.x"); content.replace(QRegExp("\\bLibkolab-\\d.\\d\\b", Qt::CaseSensitive), "Libkolab-x.x.x"); content.replace(QRegExp("\\bLibkolabxml-\\d.\\d\\b", Qt::CaseSensitive), "Libkolabxml-x.x.x"); content.replace(QRegExp("cid:*@kolab.resource.akonadi", Qt::CaseSensitive, QRegExp::Wildcard), "cid:id@kolab.resource.akonadi"); content.replace(QRegExp("Content-ID: <*@kolab.resource.akonadi>", Qt::CaseSensitive, QRegExp::Wildcard), "Content-ID: "); content.replace(QRegExp("mailto:*", Qt::CaseSensitive, QRegExp::Wildcard), "mailto:"); content.replace(QRegExp("mailto:*", Qt::CaseSensitive, QRegExp::Wildcard), "mailto:"); content.replace(QRegExp("data:*", Qt::CaseSensitive, QRegExp::Wildcard), "data:"); content.replace(QRegExp("*", Qt::CaseSensitive, QRegExp::Wildcard), ""); + //We no longer support pobox, so remove pobox lines + content.replace(QRegExp("*", Qt::CaseSensitive, QRegExp::Wildcard), ""); content.replace(QRegExp("*", Qt::CaseSensitive, QRegExp::Wildcard), ""); content.replace(QRegExp("*", Qt::CaseSensitive, QRegExp::Wildcard), ""); content.replace(QRegExp("--nextPart\\S*", Qt::CaseSensitive), "--part"); content.replace(QRegExp("\\bboundary=\"nextPart[^\\n]*", Qt::CaseSensitive), "boundary"); content.replace(QRegExp("Date[^\\n]*", Qt::CaseSensitive), "Date"); //The sort order of the attributes in kolabV2 is unpredictable content.replace(QRegExp("", Qt::CaseSensitive, QRegExp::Wildcard), ""); //quoted-printable encoding changes where the linebreaks are every now and then (an all are valid), so we remove the linebreaks content.replace(QRegExp("=\\n", Qt::CaseSensitive), ""); } QString normalizeVCardMessage(QString content) { //The encoding changes every now and then content.replace(QRegExp("ENCODING=b;TYPE=png:*", Qt::CaseSensitive, QRegExp::Wildcard), "ENCODING=b;TYPE=png:picturedata"); return content; } //Normalize incidences for comparison void normalizeIncidence( KCalCore::Incidence::Ptr incidence) { //The UID is not persistent (it's just the internal pointer), therefore we clear it //TODO make sure that the UID does really not need to be persistent foreach(KCalCore::Attendee::Ptr attendee, incidence->attendees()) { attendee->setUid(QString()); } //FIXME even if hasDueDate can differ, it shouldn't because it breaks equality. Check why they differ in the first place. if ( incidence->type() == KCalCore::IncidenceBase::TypeTodo ) { KCalCore::Todo::Ptr todo = incidence.dynamicCast(); Q_ASSERT(todo.data()); if ( !todo->hasDueDate() && !todo->hasStartDate() ) todo->setAllDay( false ); // all day has no meaning if there are no start and due dates but may differ nevertheless } } template