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

0001 /*
0002    This file is part of the kimap library.
0003    SPDX-FileCopyrightText: 2007 Tom Albers <tomalbers@kde.nl>
0004    SPDX-FileCopyrightText: 2007 Allen Winter <winter@kde.org>
0005 
0006    SPDX-License-Identifier: LGPL-2.0-only
0007 */
0008 #include <QTest>
0009 
0010 #include "testrfccodecs.h"
0011 
0012 QTEST_GUILESS_MAIN(RFCCodecsTest)
0013 
0014 #include "rfccodecs.h"
0015 using namespace KIMAP;
0016 
0017 void RFCCodecsTest::testIMAPEncoding()
0018 {
0019     QString encoded;
0020     QString decoded;
0021     QByteArray bEncoded;
0022     QByteArray bDecoded;
0023 
0024     encoded = encodeImapFolderName(QString::fromUtf8("Test.Frode Rønning"));
0025     QCOMPARE(encoded, QString::fromUtf8("Test.Frode R&APg-nning"));
0026     bEncoded = encodeImapFolderName(QString::fromUtf8("Test.Frode Rønning").toUtf8());
0027     QCOMPARE(bEncoded, QString::fromUtf8("Test.Frode R&APg-nning").toUtf8());
0028 
0029     decoded = decodeImapFolderName(QString::fromLatin1("Test.Frode R&APg-nning"));
0030     QCOMPARE(decoded, QString::fromUtf8("Test.Frode Rønning"));
0031     bDecoded = decodeImapFolderName(QString::fromUtf8("Test.Frode Rønning").toUtf8());
0032     QCOMPARE(bDecoded, QString::fromUtf8("Test.Frode Rønning").toUtf8());
0033 
0034     encoded = encodeImapFolderName(QString::fromUtf8("Test.tom & jerry"));
0035     QCOMPARE(encoded, QString::fromUtf8("Test.tom &- jerry"));
0036     bEncoded = encodeImapFolderName(QString::fromUtf8("Test.tom & jerry").toUtf8());
0037     QCOMPARE(bEncoded, QString::fromUtf8("Test.tom &- jerry").toUtf8());
0038 
0039     decoded = decodeImapFolderName(QString::fromUtf8("Test.tom &- jerry"));
0040     QCOMPARE(decoded, QString::fromUtf8("Test.tom & jerry"));
0041     bDecoded = decodeImapFolderName(QString::fromUtf8("Test.tom &- jerry").toUtf8());
0042     QCOMPARE(bDecoded, QString::fromUtf8("Test.tom & jerry").toUtf8());
0043 
0044     // Try to feed already encoded
0045     encoded = encodeImapFolderName(QString::fromUtf8("Test.Cl&AOE-udio"));
0046     QCOMPARE(encoded, QString::fromUtf8("Test.Cl&-AOE-udio"));
0047     bEncoded = encodeImapFolderName(QString::fromUtf8("Test.Cl&AOE-udio").toUtf8());
0048     QCOMPARE(bEncoded, QString::fromUtf8("Test.Cl&-AOE-udio").toUtf8());
0049 
0050     decoded = decodeImapFolderName(QString::fromUtf8("Test.Cl&-AOE-udio"));
0051     QCOMPARE(decoded, QString::fromUtf8("Test.Cl&AOE-udio"));
0052     bDecoded = decodeImapFolderName(QString::fromUtf8("Test.Cl&-AOE-udio").toUtf8());
0053     QCOMPARE(bDecoded, QString::fromUtf8("Test.Cl&AOE-udio").toUtf8());
0054 
0055     // With UTF8 characters
0056     bEncoded = "INBOX/&AOQ- &APY- &APw- @ &IKw-";
0057     QCOMPARE(decodeImapFolderName(bEncoded), QByteArray("INBOX/ä ö ü @ €"));
0058 }
0059 
0060 void RFCCodecsTest::testQuotes()
0061 {
0062     QString test(QStringLiteral("tom\"allen"));
0063     QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\\\"allen"));
0064     test = QStringLiteral("tom\'allen");
0065     QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\'allen"));
0066     test = QStringLiteral("tom\\allen");
0067     QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\\\\allen"));
0068 }
0069 
0070 #include "moc_testrfccodecs.cpp"