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/deletejob.h" 0027 0028 #include <QtTest> 0029 0030 class DeleteJobTest: public QObject 0031 { 0032 Q_OBJECT 0033 0034 private Q_SLOTS: 0035 0036 void testDelete_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 DELETE \"foo\"" 0044 << "S: A000001 OK DELETE completed"; 0045 QTest::newRow("good") << "foo" << scenario; 0046 0047 scenario.clear(); 0048 scenario << FakeServer::preauth() 0049 << "C: A000001 DELETE \"foo-BAD\"" 0050 << "S: A000001 BAD command unknown or arguments invalid"; 0051 QTest::newRow("bad") << "foo-BAD" << scenario; 0052 0053 scenario.clear(); 0054 scenario << FakeServer::preauth() 0055 << "C: A000001 DELETE \"foo\"" 0056 << "S: A000001 Name \"foo\" has inferior hierarchical names"; 0057 QTest::newRow("no") << "foo" << scenario; 0058 0059 scenario.clear(); 0060 scenario << FakeServer::preauth() 0061 << "C: A000001 DELETE \"foo-IGNOREDCODE\"" 0062 << "S: A000001 NO Name \"foo-IGNOREDCODE\" does not exist [IGNOREDCODE]"; 0063 QTest::newRow("ignoredcode") << "foo-IGNOREDCODE" << scenario; 0064 0065 scenario.clear(); 0066 scenario << FakeServer::preauth() 0067 << "C: A000001 DELETE \"foo-NONEXISTENT\"" 0068 << "S: A000001 NO Name \"foo-NONEXISTENT\" does not exist [NONEXISTENT]"; 0069 QTest::newRow("nonexistent") << "foo-NONEXISTENT" << scenario; 0070 0071 scenario.clear(); 0072 scenario << FakeServer::preauth() 0073 << "C: A000001 DELETE \"foo/bar\"" 0074 << "S: A000001 OK DELETE completed"; 0075 QTest::newRow("hierarchical") << "foo/bar" << scenario; 0076 } 0077 0078 void testDelete() 0079 { 0080 QFETCH(QString, mailbox); 0081 QFETCH(QList<QByteArray>, scenario); 0082 0083 FakeServer fakeServer; 0084 fakeServer.setScenario(scenario); 0085 fakeServer.startAndWait(); 0086 0087 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0088 0089 KIMAP2::DeleteJob *job = new KIMAP2::DeleteJob(&session); 0090 job->setMailBox(mailbox); 0091 bool result = job->exec(); 0092 QEXPECT_FAIL("bad" , "Expected failure on BAD response", Continue); 0093 QEXPECT_FAIL("no" , "Expected failure on NO response", Continue); 0094 QEXPECT_FAIL("ignoredcode" , "Expected failure on NO response with ignored response code", Continue); 0095 QVERIFY(result); 0096 if (result) { 0097 QCOMPARE(job->mailBox(), mailbox); 0098 } 0099 0100 fakeServer.quit(); 0101 } 0102 0103 }; 0104 0105 QTEST_GUILESS_MAIN(DeleteJobTest) 0106 0107 #include "deletejobtest.moc"