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/renamejob.h"
0027 
0028 #include <QtTest>
0029 
0030 class RenameJobTest: public QObject
0031 {
0032     Q_OBJECT
0033 
0034 private Q_SLOTS:
0035 
0036     void testRename_data()
0037     {
0038         QTest::addColumn<QString>("mailbox");
0039         QTest::addColumn<QString>("newname");
0040         QTest::addColumn<QList<QByteArray> >("scenario");
0041 
0042         QList<QByteArray> scenario;
0043         scenario << FakeServer::preauth()
0044                  << "C: A000001 RENAME \"INBOX\" \"oldmail\""
0045                  << "S: A000001 OK RENAME completed";
0046         QTest::newRow("good") << "INBOX" << "oldmail" << scenario;
0047 
0048         scenario.clear();
0049         scenario << FakeServer::preauth()
0050                  << "C: A000001 RENAME \"INBOX-FAIL-BAD\" \"oldmail-bad\""
0051                  << "S: A000001 BAD command unknown or arguments invalid";
0052         QTest::newRow("bad") << "INBOX-FAIL-BAD"  << "oldmail-bad" << scenario;
0053 
0054         scenario.clear();
0055         scenario << FakeServer::preauth()
0056                  << "C: A000001 RENAME \"INBOX-FAIL-NO\" \"oldmail-no\""
0057                  << "S: A000001 NO rename failure";
0058         QTest::newRow("no") << "INBOX-FAIL-NO" << "oldmail-no" << scenario;
0059     }
0060 
0061     void testRename()
0062     {
0063         QFETCH(QString, mailbox);
0064         QFETCH(QString, newname);
0065         QFETCH(QList<QByteArray>, scenario);
0066 
0067         FakeServer fakeServer;
0068         fakeServer.setScenario(scenario);
0069         fakeServer.startAndWait();
0070 
0071         KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989);
0072 
0073         KIMAP2::RenameJob *job = new KIMAP2::RenameJob(&session);
0074         job->setSourceMailBox(mailbox);
0075         job->setDestinationMailBox(newname);
0076         bool result = job->exec();
0077         QEXPECT_FAIL("bad" , "Expected failure on BAD response", Continue);
0078         QEXPECT_FAIL("no" , "Expected failure on NO response", Continue);
0079         QVERIFY(result);
0080         QCOMPARE(job->sourceMailBox(), mailbox);
0081         QCOMPARE(job->destinationMailBox(), newname);
0082 
0083         fakeServer.quit();
0084     }
0085 
0086 };
0087 
0088 QTEST_GUILESS_MAIN(RenameJobTest)
0089 
0090 #include "renamejobtest.moc"