File indexing completed on 2024-05-12 05:17:19
0001 /* 0002 Copyright (C) 2009 Andras Mantia <amantia@kde.org> 0003 0004 Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> 0005 Author: Kevin Ottens <kevin@kdab.com> 0006 0007 This program is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This program is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 General Public License for more details. 0016 0017 You should have received a copy of the GNU General Public License 0018 along with this program; if not, write to the Free Software 0019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #include <qtest.h> 0023 0024 #include "kimap2test/fakeserver.h" 0025 #include "kimap2/session.h" 0026 #include "kimap2/createjob.h" 0027 0028 #include <QtTest> 0029 0030 class CreateJobTest: public QObject 0031 { 0032 Q_OBJECT 0033 0034 private Q_SLOTS: 0035 0036 void testCreate_data() 0037 { 0038 QTest::addColumn<QString>("mailbox"); 0039 QTest::addColumn<QList<QByteArray> >("scenario"); 0040 0041 QList<QByteArray> scenario; 0042 scenario << FakeServer::preauth() 0043 << "C: A000001 CREATE \"INBOX\"" 0044 << "S: A000001 OK CREATE completed"; 0045 QTest::newRow("good") << "INBOX" << scenario; 0046 0047 scenario.clear(); 0048 scenario << FakeServer::preauth() 0049 << "C: A000001 CREATE \"INBOX-FAIL-BAD\"" 0050 << "S: A000001 BAD command unknown or arguments invalid"; 0051 QTest::newRow("bad") << "INBOX-FAIL-BAD" << scenario; 0052 0053 scenario.clear(); 0054 scenario << FakeServer::preauth() 0055 << "C: A000001 CREATE \"INBOX-FAIL-NO\"" 0056 << "S: A000001 NO create failure"; 0057 QTest::newRow("no") << "INBOX-FAIL-NO" << scenario; 0058 0059 scenario.clear(); 0060 scenario << FakeServer::preauth() 0061 << "C: A000001 CREATE \"INBOX-FAIL-IGNOREDCODE\"" 0062 << "S: A000001 NO create failure [IGNOREDCODE]"; 0063 QTest::newRow("ignoredcode") << "INBOX-FAIL-IGNOREDCODE" << scenario; 0064 0065 scenario.clear(); 0066 scenario << FakeServer::preauth() 0067 << "C: A000001 CREATE \"INBOX-ALREADYEXISTS\"" 0068 << "S: A000001 NO create failure [ALREADYEXISTS]"; 0069 QTest::newRow("alreadyexists") << "INBOX-ALREADYEXISTS" << scenario; 0070 } 0071 0072 void testCreate() 0073 { 0074 QFETCH(QString, mailbox); 0075 QFETCH(QList<QByteArray>, scenario); 0076 0077 FakeServer fakeServer; 0078 fakeServer.setScenario(scenario); 0079 fakeServer.startAndWait(); 0080 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0081 0082 KIMAP2::CreateJob *job = new KIMAP2::CreateJob(&session); 0083 job->setMailBox(mailbox); 0084 bool result = job->exec(); 0085 QEXPECT_FAIL("bad" , "Expected failure on BAD response", Continue); 0086 QEXPECT_FAIL("no" , "Expected failure on NO response", Continue); 0087 QEXPECT_FAIL("ignoredcode" , "Expected failure on NO response with ignored response code", Continue); 0088 QVERIFY(result); 0089 if (result) { 0090 QCOMPARE(job->mailBox(), mailbox); 0091 } 0092 0093 fakeServer.quit(); 0094 } 0095 0096 }; 0097 0098 QTEST_GUILESS_MAIN(CreateJobTest) 0099 0100 #include "createjobtest.moc"