File indexing completed on 2024-05-12 05:17:19
0001 /* 0002 Copyright (C) 2013 Christian Mollekopf <mollekopf@kolabsys.com> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include <qtest.h> 0020 0021 #include "kimap2test/fakeserver.h" 0022 #include "kimap2/session.h" 0023 #include "kimap2/appendjob.h" 0024 0025 #include <QtTest> 0026 #include <QDateTime> 0027 0028 class AppendJobTest: public QObject 0029 { 0030 Q_OBJECT 0031 0032 private Q_SLOTS: 0033 0034 void testAppend_data() 0035 { 0036 QTest::addColumn<QString>("mailbox"); 0037 QTest::addColumn<QList<QByteArray> >("scenario"); 0038 QTest::addColumn<QList<QByteArray> >("flags"); 0039 QTest::addColumn<QDateTime>("internaldate"); 0040 QTest::addColumn<QByteArray>("content"); 0041 QTest::addColumn<qint64>("uid"); 0042 0043 QList<QByteArray> flags; 0044 flags << QByteArray("\\Seen"); 0045 { 0046 QList<QByteArray> scenario; 0047 scenario << FakeServer::preauth() 0048 << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent" 0049 << "S: A000001 OK APPEND completed. [ APPENDUID 492 2671 ]"; 0050 QTest::newRow("good") << "INBOX" << scenario << flags << QDateTime() << QByteArray("content") << qint64(2671); 0051 } 0052 { 0053 QList<QByteArray> scenario; 0054 scenario << FakeServer::preauth() 0055 << "C: A000001 APPEND \"INBOX\" (\\Seen) \"26-Feb-2014 12:38:00 +0000\" {7}\r\ncontent" 0056 << "S: A000001 OK APPEND completed. [ APPENDUID 493 2672 ]"; 0057 QTest::newRow("good, with internalDate set") << "INBOX" << scenario << flags << QDateTime::fromString(QStringLiteral("2014-02-26T12:38:00Z"), Qt::ISODate) << QByteArray("content") << qint64(2672); 0058 } 0059 0060 { 0061 QList<QByteArray> scenario; 0062 scenario << FakeServer::preauth() 0063 << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent" 0064 << "S: BYE" 0065 << "X" ; 0066 QTest::newRow("bad") << "INBOX" << scenario << flags << QDateTime() << QByteArray("content") << qint64(0); 0067 } 0068 { 0069 QList<QByteArray> scenario; 0070 scenario << FakeServer::preauth() 0071 << "C: A000001 APPEND \"INBOX\" (\\Seen) {7}\r\ncontent" 0072 << "S: " 0073 << "X" ; 0074 QTest::newRow("Don't crash on empty response") << "INBOX" << scenario << flags << QDateTime() << QByteArray("content") << qint64(0); 0075 } 0076 } 0077 0078 void testAppend() 0079 { 0080 QFETCH(QString, mailbox); 0081 QFETCH(QList<QByteArray>, scenario); 0082 QFETCH(QList<QByteArray>, flags); 0083 QFETCH(QDateTime, internaldate); 0084 QFETCH(QByteArray, content); 0085 QFETCH(qint64, uid); 0086 0087 FakeServer fakeServer; 0088 fakeServer.setScenario(scenario); 0089 fakeServer.startAndWait(); 0090 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0091 0092 KIMAP2::AppendJob *job = new KIMAP2::AppendJob(&session); 0093 job->setContent(content); 0094 job->setFlags(flags); 0095 job->setInternalDate(internaldate); 0096 job->setMailBox(mailbox); 0097 const bool result = job->exec(); 0098 QEXPECT_FAIL("bad" , "Expected failure on connection abort", Continue); 0099 QEXPECT_FAIL("Don't crash on empty response" , "Expected failure on connection abort", Continue); 0100 QVERIFY(result); 0101 QCOMPARE(job->uid(), uid); 0102 0103 fakeServer.quit(); 0104 } 0105 0106 }; 0107 0108 QTEST_GUILESS_MAIN(AppendJobTest) 0109 0110 #include "appendjobtest.moc"