File indexing completed on 2024-05-12 05:17:20
0001 /* 0002 Copyright (C) 2009 Kevin Ottens <ervin@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/storejob.h" 0027 0028 #include <QtTest> 0029 0030 class StoreJobTest: public QObject 0031 { 0032 Q_OBJECT 0033 0034 private Q_SLOTS: 0035 0036 void testStore_data() 0037 { 0038 QTest::addColumn<bool>("uidBased"); 0039 QTest::addColumn<qint64>("id"); 0040 QTest::addColumn<qint64>("uid"); 0041 QTest::addColumn< QList<QByteArray> >("flags"); 0042 QTest::addColumn< QList<QByteArray> >("scenario"); 0043 0044 QList<QByteArray> scenario; 0045 scenario << FakeServer::preauth() 0046 << "C: A000001 STORE 3 FLAGS (\\Seen \\Foo)" 0047 << "S: * 3 FETCH (FLAGS (\\Seen \\Foo) UID 1096)" 0048 << "S: A000001 OK STORE completed"; 0049 0050 QTest::newRow("not uid based") << false << qint64(3) << qint64(1096) 0051 << (QList<QByteArray>() << "\\Seen" << "\\Foo") 0052 << scenario; 0053 0054 scenario.clear(); 0055 scenario << FakeServer::preauth() 0056 << "C: A000001 UID STORE 1096 FLAGS (\\Seen \\Foo)" 0057 << "S: * 3 FETCH (FLAGS (\\Seen \\Foo) UID 1096)" 0058 << "S: A000001 OK STORE completed"; 0059 0060 QTest::newRow("uid based") << true << qint64(3) << qint64(1096) 0061 << (QList<QByteArray>() << "\\Seen" << "\\Foo") 0062 << scenario; 0063 0064 scenario.clear(); 0065 scenario << FakeServer::preauth() 0066 << "C: A000001 UID STORE 1096 FLAGS ()" 0067 << "S: * 3 FETCH (FLAGS () UID 1096)" 0068 << "S: A000001 OK STORE completed"; 0069 0070 QTest::newRow("set emtpy flag set") << true << qint64(3) << qint64(1096) 0071 << QList<QByteArray>() 0072 << scenario; 0073 } 0074 0075 void testStore() 0076 { 0077 QFETCH(bool, uidBased); 0078 QFETCH(qint64, id); 0079 QFETCH(qint64, uid); 0080 QFETCH(QList<QByteArray>, flags); 0081 QFETCH(QList<QByteArray>, scenario); 0082 0083 FakeServer fakeServer; 0084 fakeServer.setScenario(scenario); 0085 fakeServer.startAndWait(); 0086 0087 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0088 0089 KIMAP2::StoreJob *job = new KIMAP2::StoreJob(&session); 0090 job->setUidBased(uidBased); 0091 job->setSequenceSet(KIMAP2::ImapSet(uidBased ? uid : id)); 0092 job->setFlags(flags); 0093 job->setMode(KIMAP2::StoreJob::SetFlags); 0094 bool result = job->exec(); 0095 QVERIFY(result); 0096 if (uidBased) { 0097 QVERIFY(job->resultingFlags().contains(uid)); 0098 } else { 0099 QVERIFY(job->resultingFlags().contains(id)); 0100 } 0101 0102 fakeServer.quit(); 0103 } 0104 0105 }; 0106 0107 QTEST_GUILESS_MAIN(StoreJobTest) 0108 0109 #include "storejobtest.moc"