File indexing completed on 2024-05-12 05:17:20

0001 /*
0002    This file is part of the kimap library.
0003    Copyright (C) 2007 Tom Albers <tomalbers@kde.nl>
0004    Copyright (c) 2007 Allen Winter <winter@kde.org>
0005 
0006    This library is free software; you can redistribute it and/or
0007    modify it under the terms of the GNU Library General Public
0008    License version 2 as published by the Free Software Foundation.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018    Boston, MA 02110-1301, USA.
0019 */
0020 #include <qtest.h>
0021 
0022 #include "testrfccodecs.h"
0023 
0024 QTEST_GUILESS_MAIN(RFCCodecsTest)
0025 
0026 #include "rfccodecs.h"
0027 using namespace KIMAP2;
0028 
0029 void RFCCodecsTest::testIMAPEncoding()
0030 {
0031     QString encoded, decoded;
0032     QByteArray bEncoded, bDecoded;
0033 
0034     encoded = encodeImapFolderName(QString::fromUtf8("Test.Frode Rønning"));
0035     QCOMPARE(encoded, QString::fromUtf8("Test.Frode R&APg-nning"));
0036     bEncoded = encodeImapFolderName(QString::fromUtf8("Test.Frode Rønning").toUtf8());
0037     QCOMPARE(bEncoded, QString::fromUtf8("Test.Frode R&APg-nning").toUtf8());
0038 
0039     decoded = decodeImapFolderName(QString::fromLatin1("Test.Frode R&APg-nning"));
0040     QCOMPARE(decoded, QString::fromUtf8("Test.Frode Rønning"));
0041     bDecoded = decodeImapFolderName(QString::fromUtf8("Test.Frode Rønning").toUtf8());
0042     QCOMPARE(bDecoded, QString::fromUtf8("Test.Frode Rønning").toUtf8());
0043 
0044     encoded = encodeImapFolderName(QString::fromUtf8("Test.tom & jerry"));
0045     QCOMPARE(encoded, QString::fromUtf8("Test.tom &- jerry"));
0046     bEncoded = encodeImapFolderName(QString::fromUtf8("Test.tom & jerry").toUtf8());
0047     QCOMPARE(bEncoded, QString::fromUtf8("Test.tom &- jerry").toUtf8());
0048 
0049     decoded = decodeImapFolderName(QString::fromUtf8("Test.tom &- jerry"));
0050     QCOMPARE(decoded, QString::fromUtf8("Test.tom & jerry"));
0051     bDecoded = decodeImapFolderName(QString::fromUtf8("Test.tom &- jerry").toUtf8());
0052     QCOMPARE(bDecoded, QString::fromUtf8("Test.tom & jerry").toUtf8());
0053 
0054     // Try to feed already encoded
0055     encoded = encodeImapFolderName(QString::fromUtf8("Test.Cl&AOE-udio"));
0056     QCOMPARE(encoded, QString::fromUtf8("Test.Cl&-AOE-udio"));
0057     bEncoded = encodeImapFolderName(QString::fromUtf8("Test.Cl&AOE-udio").toUtf8());
0058     QCOMPARE(bEncoded, QString::fromUtf8("Test.Cl&-AOE-udio").toUtf8());
0059 
0060     decoded = decodeImapFolderName(QString::fromUtf8("Test.Cl&-AOE-udio"));
0061     QCOMPARE(decoded, QString::fromUtf8("Test.Cl&AOE-udio"));
0062     bDecoded = decodeImapFolderName(QString::fromUtf8("Test.Cl&-AOE-udio").toUtf8());
0063     QCOMPARE(bDecoded, QString::fromUtf8("Test.Cl&AOE-udio").toUtf8());
0064 
0065     // With UTF8 characters
0066     bEncoded = "INBOX/&AOQ- &APY- &APw- @ &IKw-";
0067     QCOMPARE(decodeImapFolderName(bEncoded), QByteArray("INBOX/ä ö ü @ €"));
0068 }
0069 
0070 void RFCCodecsTest::testQuotes()
0071 {
0072     QString test(QStringLiteral("tom\"allen"));
0073     QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\\\"allen"));
0074     test = QStringLiteral("tom\'allen");
0075     QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\'allen"));
0076     test =  QStringLiteral("tom\\allen");
0077     QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\\\\allen"));
0078 }