diff --git a/messagecore/autotests/attachmentfromurljobtest.cpp b/messagecore/autotests/attachmentfromurljobtest.cpp index f89c6d60..6a3dd0e8 100644 --- a/messagecore/autotests/attachmentfromurljobtest.cpp +++ b/messagecore/autotests/attachmentfromurljobtest.cpp @@ -1,103 +1,108 @@ /* Copyright (c) 2009 Constantin Berzan 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 "attachmentfromurljobtest.h" #include "qtest_messagecore.h" #include #include #include using namespace MessageCore; QTEST_MAIN(AttachmentFromUrlJobTest) #define PATH_ATTACHMENTS QLatin1String( KDESRCDIR "/attachments/" ) +void AttachmentFromUrlJobTest::initTestCase() +{ + qputenv("KDE_FORK_SLAVES", "yes"); // To avoid a runtime dependency on klauncher +} + void AttachmentFromUrlJobTest::testAttachments_data() { QTest::addColumn("url"); QTest::addColumn("filename"); QTest::addColumn("mimetype"); // PATH_ATTACHMENTS is defined by CMake. QTest::newRow("png image") << QUrl::fromLocalFile(PATH_ATTACHMENTS + QString::fromLatin1("image.png")) << QString::fromLatin1("image.png") << QByteArray("image/png"); QTest::newRow("pdf doc") << QUrl::fromLocalFile(PATH_ATTACHMENTS + QString::fromLatin1("doc.pdf")) << QString::fromLatin1("doc.pdf") << QByteArray("application/pdf"); QTest::newRow("text file") << QUrl::fromLocalFile(PATH_ATTACHMENTS + QString::fromLatin1("file.txt")) << QString::fromLatin1("file.txt") << QByteArray("text/plain"); } void AttachmentFromUrlJobTest::testAttachments() { QFETCH(QUrl, url); QFETCH(QString, filename); QFETCH(QByteArray, mimetype); QFile file(url.path()); QVERIFY(file.open(QIODevice::ReadOnly)); QByteArray data = file.readAll(); file.close(); AttachmentFromUrlJob *ljob = new AttachmentFromUrlJob(url, this); VERIFYEXEC(ljob); AttachmentPart::Ptr part = ljob->attachmentPart(); delete ljob; ljob = 0; QCOMPARE(part->name(), filename); QCOMPARE(part->fileName(), filename); QVERIFY(!part->isInline()); QCOMPARE(part->mimeType(), mimetype); QCOMPARE(part->data(), data); } void AttachmentFromUrlJobTest::testAttachmentTooBig() { const QUrl url = QUrl::fromLocalFile(PATH_ATTACHMENTS + QString::fromLatin1("doc.pdf")); const QString name = QString::fromLatin1("doc.pdf"); const QByteArray mimetype("application/pdf"); AttachmentFromUrlJob *ljob = new AttachmentFromUrlJob(url, this); ljob->setMaximumAllowedSize(1024); // 1KiB, whereas the file is >9KiB. QVERIFY(!ljob->exec()); } void AttachmentFromUrlJobTest::testAttachmentCharset() { const QByteArray charset("iso-8859-2"); const QString filename = QString::fromLatin1("file.txt"); QUrl url = QUrl::fromLocalFile(PATH_ATTACHMENTS + filename); MessageCore::StringUtil::setEncodingFile(url, QString::fromLatin1(charset)); AttachmentFromUrlJob *ljob = new AttachmentFromUrlJob(url, this); VERIFYEXEC(ljob); AttachmentPart::Ptr part = ljob->attachmentPart(); delete ljob; ljob = 0; QCOMPARE(part->name(), filename); QCOMPARE(part->fileName(), filename); QCOMPARE(part->charset(), charset); } diff --git a/messagecore/autotests/attachmentfromurljobtest.h b/messagecore/autotests/attachmentfromurljobtest.h index b3484afc..92c2b7d6 100644 --- a/messagecore/autotests/attachmentfromurljobtest.h +++ b/messagecore/autotests/attachmentfromurljobtest.h @@ -1,35 +1,36 @@ /* Copyright (c) 2009 Constantin Berzan 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. */ #ifndef ATTACHMENTFROMURLJOBTEST_H #define ATTACHMENTFROMURLJOBTEST_H #include class AttachmentFromUrlJobTest : public QObject { Q_OBJECT private Q_SLOTS: + void initTestCase(); void testAttachments_data(); void testAttachments(); void testAttachmentTooBig(); void testAttachmentCharset(); }; #endif