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/loginjob.h" 0026 #include "kimap2/session.h" 0027 #include "kimap2/selectjob.h" 0028 0029 #include <QtTest> 0030 0031 class SelectJobTest: public QObject 0032 { 0033 Q_OBJECT 0034 0035 private Q_SLOTS: 0036 0037 void testSingleSelect_data() 0038 { 0039 QTest::addColumn<QList<QByteArray> >("scenario"); 0040 QTest::addColumn<QList<QByteArray> >("flags"); 0041 QTest::addColumn<QList<QByteArray> >("permanentflags"); 0042 QTest::addColumn<int>("messagecount"); 0043 QTest::addColumn<int>("recentcount"); 0044 QTest::addColumn<int>("firstUnseenIndex"); 0045 QTest::addColumn<qint64>("uidValidity"); 0046 QTest::addColumn<qint64>("nextUid"); 0047 QTest::addColumn<quint64>("highestmodseq"); 0048 QTest::addColumn<bool>("condstoreEnabled"); 0049 0050 QList<QByteArray> scenario; 0051 QList<QByteArray> flags; 0052 QList<QByteArray> permanentflags; 0053 scenario << FakeServer::preauth() 0054 << "C: A000001 SELECT \"INBOX\" (CONDSTORE)" 0055 << "S: * 172 EXISTS" 0056 << "S: * 1 RECENT" 0057 << "S: * OK [UNSEEN 12] Message 12 is first unseen" 0058 << "S: * OK [UIDVALIDITY 3857529045] UIDs valid" 0059 << "S: * OK [UIDNEXT 4392] Predicted next UID" 0060 << "S: * OK [HIGHESTMODSEQ 123456789]" 0061 << "S: * FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft)" 0062 << "S: * OK [PERMANENTFLAGS (\\Deleted \\Seen \\*)] Limited" 0063 << "S: A000001 OK [READ-WRITE] SELECT completed"; 0064 0065 flags << "\\Answered" << "\\Flagged" << "\\Deleted" << "\\Seen" << "\\Draft"; 0066 permanentflags << "\\Deleted" << "\\Seen" << "\\*"; 0067 QTest::newRow("good") << scenario << flags << permanentflags << 172 << 1 << 12 << (qint64)3857529045 << (qint64)4392 << (quint64)123456789 << true; 0068 0069 scenario.clear(); 0070 flags.clear(); 0071 permanentflags.clear(); 0072 scenario << FakeServer::preauth() 0073 << "C: A000001 SELECT \"INBOX\"" 0074 << "S: A000001 BAD command unknown or arguments invalid"; 0075 QTest::newRow("bad") << scenario << flags << permanentflags << 0 << 0 << 0 << (qint64)0 << (qint64)0 << (quint64)0 << false; 0076 0077 scenario.clear(); 0078 flags.clear(); 0079 permanentflags.clear(); 0080 scenario << FakeServer::preauth() 0081 << "C: A000001 SELECT \"INBOX\"" 0082 << "S: A000001 NO select failure"; 0083 QTest::newRow("no") << scenario << flags << permanentflags << 0 << 0 << 0 << (qint64)0 << (qint64)0 << (quint64)0 << false; 0084 } 0085 0086 void testSingleSelect() 0087 { 0088 QFETCH(QList<QByteArray>, scenario); 0089 QFETCH(QList<QByteArray>, flags); 0090 QFETCH(QList<QByteArray>, permanentflags); 0091 QFETCH(int, messagecount); 0092 QFETCH(int, recentcount); 0093 QFETCH(int, firstUnseenIndex); 0094 QFETCH(qint64, uidValidity); 0095 QFETCH(qint64, nextUid); 0096 QFETCH(quint64, highestmodseq); 0097 QFETCH(bool, condstoreEnabled); 0098 0099 FakeServer fakeServer; 0100 fakeServer.setScenario(scenario); 0101 fakeServer.startAndWait(); 0102 0103 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0104 0105 KIMAP2::SelectJob *job = new KIMAP2::SelectJob(&session); 0106 job->setCondstoreEnabled(condstoreEnabled); 0107 job->setMailBox(QStringLiteral("INBOX")); 0108 bool result = job->exec(); 0109 QEXPECT_FAIL("bad" , "Expected failure on BAD scenario", Continue); 0110 QEXPECT_FAIL("no" , "Expected failure on NO scenario", Continue); 0111 QVERIFY(result); 0112 if (result) { 0113 QCOMPARE(job->flags(), flags); 0114 QCOMPARE(job->permanentFlags(), permanentflags); 0115 QCOMPARE(job->messageCount(), messagecount); 0116 QCOMPARE(job->recentCount(), recentcount); 0117 QCOMPARE(job->firstUnseenIndex(), firstUnseenIndex); 0118 QCOMPARE(job->uidValidity(), uidValidity); 0119 QCOMPARE(job->nextUid(), nextUid); 0120 QCOMPARE(job->highestModSequence(), highestmodseq); 0121 } 0122 0123 fakeServer.quit(); 0124 } 0125 0126 void testSeveralSelect() 0127 { 0128 FakeServer fakeServer; 0129 fakeServer.setScenario(QList<QByteArray>() 0130 << FakeServer::preauth() 0131 << "C: A000001 SELECT \"INBOX\"" 0132 << "S: A000001 OK [READ-WRITE] SELECT completed" 0133 << "C: A000002 SELECT \"INBOX/Foo\"" 0134 << "S: A000002 OK [READ-WRITE] SELECT completed" 0135 ); 0136 fakeServer.startAndWait(); 0137 0138 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0139 0140 KIMAP2::SelectJob *job = new KIMAP2::SelectJob(&session); 0141 job->setMailBox(QStringLiteral("INBOX")); 0142 QVERIFY(job->exec()); 0143 0144 job = new KIMAP2::SelectJob(&session); 0145 job->setMailBox(QStringLiteral("INBOX/Foo")); 0146 QVERIFY(job->exec()); 0147 } 0148 0149 }; 0150 0151 QTEST_GUILESS_MAIN(SelectJobTest) 0152 0153 #include "selectjobtest.moc"