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/capabilitiesjob.h" 0027 0028 #include <QtTest> 0029 0030 class CapabilitiesJobTest: public QObject 0031 { 0032 Q_OBJECT 0033 0034 private Q_SLOTS: 0035 0036 void testCapabilities_data() 0037 { 0038 QTest::addColumn<QList<QByteArray> >("scenario"); 0039 QTest::addColumn<QStringList>("capabilities"); 0040 QList<QByteArray> scenario; 0041 scenario << "S: * PREAUTH" 0042 << "C: A000001 CAPABILITY" 0043 << "S: * CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI" 0044 << "S: A000001 OK CAPABILITY completed"; 0045 0046 QStringList capabilities; 0047 capabilities << QStringLiteral("IMAP4REV1") << QStringLiteral("STARTTLS") << QStringLiteral("AUTH=GSSAPI"); 0048 QTest::newRow("good") << scenario << capabilities; 0049 0050 scenario.clear(); 0051 capabilities.clear(); 0052 scenario << "S: * PREAUTH" 0053 << "C: A000001 CAPABILITY" 0054 << "S: A000001 BAD command unknown or arguments invalid"; 0055 QTest::newRow("bad") << scenario << capabilities; 0056 0057 scenario.clear(); 0058 capabilities.clear(); 0059 scenario << "S: * PREAUTH" 0060 << "C: A000001 CAPABILITY" 0061 << "S: * CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN" 0062 << "S: * some response" 0063 << "S: A000001 OK CAPABILITY completed"; 0064 0065 capabilities << QStringLiteral("IMAP4REV1") << QStringLiteral("STARTTLS") << QStringLiteral("AUTH=PLAIN"); 0066 QTest::newRow("extra-untagged") << scenario << capabilities;; 0067 } 0068 0069 void testCapabilities() 0070 { 0071 QFETCH(QList<QByteArray>, scenario); 0072 QFETCH(QStringList, capabilities); 0073 0074 FakeServer fakeServer; 0075 fakeServer.setScenario(scenario); 0076 fakeServer.startAndWait(); 0077 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0078 0079 KIMAP2::CapabilitiesJob *job = new KIMAP2::CapabilitiesJob(&session); 0080 bool result = job->exec(); 0081 QEXPECT_FAIL("bad" , "Expected failure on BAD response", Continue); 0082 QVERIFY(result); 0083 if (result) { 0084 QCOMPARE(job->capabilities(), capabilities); 0085 } 0086 fakeServer.quit(); 0087 } 0088 0089 }; 0090 0091 QTEST_GUILESS_MAIN(CapabilitiesJobTest) 0092 0093 #include "capabilitiesjobtest.moc"