File indexing completed on 2024-05-12 05:17:20
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/unsubscribejob.h" 0027 0028 #include <QtTest> 0029 0030 class UnsubscribeJobTest: public QObject 0031 { 0032 Q_OBJECT 0033 0034 private Q_SLOTS: 0035 0036 void testUnsubscribe_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 UNSUBSCRIBE \"#news.comp.mail.mime\"" 0044 << "S: A000001 OK UNSUBSCRIBE completed"; 0045 QTest::newRow("good") << "#news.comp.mail.mime" << scenario; 0046 0047 scenario.clear(); 0048 scenario << FakeServer::preauth() 0049 << "C: A000001 UNSUBSCRIBE \"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 UNSUBSCRIBE \"INBOX-FAIL-NO\"" 0056 << "S: A000001 NO unsubscribe failure"; 0057 QTest::newRow("no") << "INBOX-FAIL-NO" << scenario; 0058 } 0059 0060 void testUnsubscribe() 0061 { 0062 QFETCH(QString, mailbox); 0063 QFETCH(QList<QByteArray>, scenario); 0064 0065 FakeServer fakeServer; 0066 fakeServer.setScenario(scenario); 0067 fakeServer.startAndWait(); 0068 0069 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0070 0071 KIMAP2::UnsubscribeJob *job = new KIMAP2::UnsubscribeJob(&session); 0072 job->setMailBox(mailbox); 0073 bool result = job->exec(); 0074 QEXPECT_FAIL("bad" , "Expected failure on BAD scenario", Continue); 0075 QEXPECT_FAIL("no" , "Expected failure on NO scenario", Continue); 0076 QVERIFY(result); 0077 QCOMPARE(job->mailBox(), mailbox); 0078 0079 fakeServer.quit(); 0080 } 0081 0082 }; 0083 0084 QTEST_GUILESS_MAIN(UnsubscribeJobTest) 0085 0086 #include "unsubscribejobtest.moc"