File indexing completed on 2024-05-12 05:17:20
0001 /* 0002 Copyright (C) 2013 Christian Mollekopf <mollekopf@kolabsys.com> 0003 0004 This program is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include <qtest.h> 0020 0021 #include "kimap2test/fakeserver.h" 0022 #include "kimap2/session.h" 0023 #include "kimap2/setmetadatajob.h" 0024 0025 #include <QtTest> 0026 0027 typedef QMap<QByteArray, QByteArray> MAP; 0028 Q_DECLARE_METATYPE(MAP) 0029 0030 class SetMetadataJobTest: public QObject 0031 { 0032 Q_OBJECT 0033 0034 private Q_SLOTS: 0035 0036 void metadata_data() 0037 { 0038 QTest::addColumn<QList<QByteArray> >("scenario"); 0039 QTest::addColumn<QString>("mailbox"); 0040 QTest::addColumn<QMap<QByteArray, QByteArray> >("annotations"); 0041 0042 { 0043 QList<QByteArray> scenario; 0044 scenario << FakeServer::preauth() 0045 << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" \"comment2\" \"/shared/comment\" \"Shared comment\")" 0046 << "S: A000001 OK SETMETADATA complete"; 0047 QMap<QByteArray, QByteArray> annotations; 0048 annotations.insert("/public/comment", "comment2"); 0049 annotations.insert("/shared/comment", "Shared comment"); 0050 QTest::newRow("normal") << scenario << "Folder1" << annotations; 0051 } 0052 { 0053 QList<QByteArray> scenario; 0054 scenario << FakeServer::preauth() 0055 << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" {8}\r\ncomment2 \"/shared/comment\" {14}\r\nShared\ncomment)" 0056 << "S: A000001 OK SETMETADATA complete"; 0057 QMap<QByteArray, QByteArray> annotations; 0058 annotations.insert("/shared/comment", "Shared\ncomment"); 0059 annotations.insert("/public/comment", "comment2"); 0060 QTest::newRow( "newline" ) << scenario << "Folder1" << annotations; 0061 } 0062 { 0063 QList<QByteArray> scenario; 0064 scenario << FakeServer::preauth() 0065 << "C: A000001 SETMETADATA \"Folder1\" (\"/shared/comment\" NIL)" 0066 << "S: A000001 OK SETMETADATA complete"; 0067 QMap<QByteArray, QByteArray> annotations; 0068 annotations.insert("/shared/comment",""); 0069 QTest::newRow( "newline" ) << scenario << "Folder1" << annotations; 0070 } 0071 { 0072 QList<QByteArray> scenario; 0073 scenario << FakeServer::preauth() 0074 << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" {12}\r\ncomment\ntest \"/shared/comment\" {3}\r\nNIL)" 0075 << "S: A000001 OK SETMETADATA complete"; 0076 QMap<QByteArray, QByteArray> annotations; 0077 annotations.insert("/shared/comment",""); 0078 annotations.insert("/public/comment", "comment\ntest"); 0079 QTest::newRow( "newline2" ) << scenario << "Folder1" << annotations; 0080 } 0081 { 0082 QList<QByteArray> scenario; 0083 scenario << FakeServer::preauth() 0084 << "C: A000001 SETMETADATA \"Folder1\" (\"/public/comment\" {3}\r\nNIL \"/shared/comment\" {12}\r\ncomment\ntest)" 0085 << "S: A000001 OK SETMETADATA complete"; 0086 QMap<QByteArray, QByteArray> annotations; 0087 annotations.insert("/shared/comment", "comment\ntest"); 0088 annotations.insert("/public/comment",""); 0089 QTest::newRow( "newline2" ) << scenario << "Folder1" << annotations; 0090 } 0091 } 0092 0093 void metadata() 0094 { 0095 QFETCH(QList<QByteArray>, scenario); 0096 QFETCH(QString, mailbox); 0097 QFETCH(MAP, annotations); 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::SetMetaDataJob *setMetadataJob = new KIMAP2::SetMetaDataJob(&session); 0106 setMetadataJob->setServerCapability(KIMAP2::MetaDataJobBase::Metadata); 0107 setMetadataJob->setMailBox(mailbox); 0108 foreach (const QByteArray &entry, annotations.keys()) { 0109 setMetadataJob->addMetaData(entry, annotations[entry]); 0110 } 0111 0112 QVERIFY(setMetadataJob->exec()); 0113 0114 fakeServer.quit(); 0115 } 0116 0117 void annotatemore_data() 0118 { 0119 QTest::addColumn<QList<QByteArray> >("scenario"); 0120 QTest::addColumn<QString>("mailbox"); 0121 QTest::addColumn<QMap<QByteArray, QByteArray> >("annotations"); 0122 QTest::addColumn<bool>("legacyMode"); 0123 0124 { 0125 QList<QByteArray> scenario; 0126 scenario << FakeServer::preauth() 0127 << "C: A000001 SETANNOTATION \"Folder1\" \"/comment\" (\"value.shared\" \"Shared comment\")" 0128 << "S: A000001 OK annotations changed"; 0129 0130 QMap<QByteArray, QByteArray> annotations; 0131 annotations.insert("/comment", "Shared comment"); 0132 QTest::newRow("normal") << scenario << "Folder1" << annotations << false; 0133 QTest::newRow("legacy") << scenario << "Folder1" << annotations << true; 0134 } 0135 } 0136 0137 void annotatemore() 0138 { 0139 QFETCH(QList<QByteArray>, scenario); 0140 QFETCH(QString, mailbox); 0141 QFETCH(MAP, annotations); 0142 QFETCH(bool, legacyMode); 0143 0144 FakeServer fakeServer; 0145 fakeServer.setScenario(scenario); 0146 fakeServer.startAndWait(); 0147 0148 KIMAP2::Session session(QStringLiteral("127.0.0.1"), 5989); 0149 0150 KIMAP2::SetMetaDataJob *setMetadataJob = new KIMAP2::SetMetaDataJob(&session); 0151 setMetadataJob->setServerCapability(KIMAP2::MetaDataJobBase::Annotatemore); 0152 setMetadataJob->setMailBox(mailbox); 0153 foreach (const QByteArray &entry, annotations.keys()) { 0154 if (legacyMode) { 0155 #pragma clang diagnostic push 0156 #pragma clang diagnostic ignored "-Wdeprecated-declarations" 0157 setMetadataJob->setEntry(entry); 0158 setMetadataJob->addMetaData("value.shared", annotations[entry]); 0159 #pragma clang diagnostic pop 0160 } else { 0161 setMetadataJob->addMetaData(QByteArray("/shared") + entry, annotations[entry]); 0162 } 0163 } 0164 0165 QVERIFY(setMetadataJob->exec()); 0166 0167 fakeServer.quit(); 0168 } 0169 0170 }; 0171 0172 QTEST_GUILESS_MAIN(SetMetadataJobTest) 0173 0174 #include "setmetadatajobtest.moc"