File indexing completed on 2024-05-12 05:17:10
0001 /* 0002 SPDX-FileCopyrightText: 2016 Daniel Vrátil <dvratil@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <QTest> 0008 0009 #include "imapset.h" 0010 #include "kimap/expungejob.h" 0011 #include "kimap/session.h" 0012 #include "kimaptest/fakeserver.h" 0013 0014 #include <QTest> 0015 0016 class ExpungeJobTest : public QObject 0017 { 0018 Q_OBJECT 0019 0020 private Q_SLOTS: 0021 0022 void testDelete_data() 0023 { 0024 QTest::addColumn<QList<QByteArray>>("scenario"); 0025 QTest::addColumn<KIMAP::ImapSet>("vanishedSet"); 0026 QTest::addColumn<quint64>("highestModSeq"); 0027 0028 QList<QByteArray> scenario; 0029 scenario << FakeServer::preauth() << "C: A000001 EXPUNGE" 0030 << "S: * 1 EXPUNGE" 0031 << "S: * 2 EXPUNGE" 0032 << "S: * 3 EXPUNGE" 0033 << "S: A000001 OK EXPUNGE completed"; 0034 QTest::newRow("good") << scenario << KIMAP::ImapSet{} << 0ULL; 0035 0036 scenario.clear(); 0037 scenario << FakeServer::preauth() << "C: A000001 EXPUNGE" 0038 << "S: * 1" // missing EXPUNGE word 0039 << "S: A000001 OK EXPUNGE completed"; 0040 QTest::newRow("non-standard response") << scenario << KIMAP::ImapSet{} << 0ULL; 0041 0042 scenario.clear(); 0043 scenario << FakeServer::preauth() << "C: A000001 EXPUNGE" 0044 << "S: A000001 BAD command unknown or arguments invalid"; 0045 QTest::newRow("bad") << scenario << KIMAP::ImapSet{} << 0ULL; 0046 0047 scenario.clear(); 0048 scenario << FakeServer::preauth() << "C: A000001 EXPUNGE" 0049 << "S: A000001 NO access denied"; 0050 QTest::newRow("no") << scenario << KIMAP::ImapSet{} << 0ULL; 0051 0052 scenario.clear(); 0053 scenario << FakeServer::preauth() << "C: A000001 EXPUNGE" 0054 << "S: * VANISHED 405,407,410:420" 0055 << "S: A000001 OK [HIGHESTMODSEQ 123456789] Expunged."; 0056 KIMAP::ImapSet vanishedSet; 0057 vanishedSet.add(QList<qint64>{405, 407}); 0058 vanishedSet.add(KIMAP::ImapInterval{410, 420}); 0059 QTest::newRow("qresync") << scenario << vanishedSet << 123456789ULL; 0060 } 0061 0062 void testDelete() 0063 { 0064 QFETCH(QList<QByteArray>, scenario); 0065 QFETCH(KIMAP::ImapSet, vanishedSet); 0066 QFETCH(quint64, highestModSeq); 0067 0068 FakeServer fakeServer; 0069 fakeServer.setScenario(scenario); 0070 fakeServer.startAndWait(); 0071 0072 KIMAP::Session session(QStringLiteral("127.0.0.1"), 5989); 0073 0074 auto job = new KIMAP::ExpungeJob(&session); 0075 bool result = job->exec(); 0076 QEXPECT_FAIL("bad", "Expected failure on BAD response", Continue); 0077 QEXPECT_FAIL("no", "Expected failure on NO response", Continue); 0078 QVERIFY(result); 0079 if (result) { 0080 QCOMPARE(job->vanishedMessages(), vanishedSet); 0081 QCOMPARE(job->newHighestModSeq(), highestModSeq); 0082 } 0083 0084 fakeServer.quit(); 0085 } 0086 }; 0087 0088 QTEST_GUILESS_MAIN(ExpungeJobTest) 0089 0090 #include "expungejobtest.moc"