File: testrfccodecs.cpp

package info (click to toggle)
kimap 25.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,648 kB
  • sloc: cpp: 12,450; makefile: 16; sh: 1
file content (70 lines) | stat: -rw-r--r-- 2,892 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
   This file is part of the kimap library.
   SPDX-FileCopyrightText: 2007 Tom Albers <tomalbers@kde.nl>
   SPDX-FileCopyrightText: 2007 Allen Winter <winter@kde.org>

   SPDX-License-Identifier: LGPL-2.0-only
*/
#include <QTest>

#include "testrfccodecs.h"

QTEST_GUILESS_MAIN(RFCCodecsTest)

#include "rfccodecs.h"
using namespace KIMAP;

void RFCCodecsTest::testIMAPEncoding()
{
    QString encoded;
    QString decoded;
    QByteArray bEncoded;
    QByteArray bDecoded;

    encoded = encodeImapFolderName(QString::fromUtf8("Test.Frode Rønning"));
    QCOMPARE(encoded, QString::fromUtf8("Test.Frode R&APg-nning"));
    bEncoded = encodeImapFolderName(QString::fromUtf8("Test.Frode Rønning").toUtf8());
    QCOMPARE(bEncoded, QString::fromUtf8("Test.Frode R&APg-nning").toUtf8());

    decoded = decodeImapFolderName(QString::fromLatin1("Test.Frode R&APg-nning"));
    QCOMPARE(decoded, QString::fromUtf8("Test.Frode Rønning"));
    bDecoded = decodeImapFolderName(QString::fromUtf8("Test.Frode Rønning").toUtf8());
    QCOMPARE(bDecoded, QString::fromUtf8("Test.Frode Rønning").toUtf8());

    encoded = encodeImapFolderName(QString::fromUtf8("Test.tom & jerry"));
    QCOMPARE(encoded, QString::fromUtf8("Test.tom &- jerry"));
    bEncoded = encodeImapFolderName(QString::fromUtf8("Test.tom & jerry").toUtf8());
    QCOMPARE(bEncoded, QString::fromUtf8("Test.tom &- jerry").toUtf8());

    decoded = decodeImapFolderName(QString::fromUtf8("Test.tom &- jerry"));
    QCOMPARE(decoded, QString::fromUtf8("Test.tom & jerry"));
    bDecoded = decodeImapFolderName(QString::fromUtf8("Test.tom &- jerry").toUtf8());
    QCOMPARE(bDecoded, QString::fromUtf8("Test.tom & jerry").toUtf8());

    // Try to feed already encoded
    encoded = encodeImapFolderName(QString::fromUtf8("Test.Cl&AOE-udio"));
    QCOMPARE(encoded, QString::fromUtf8("Test.Cl&-AOE-udio"));
    bEncoded = encodeImapFolderName(QString::fromUtf8("Test.Cl&AOE-udio").toUtf8());
    QCOMPARE(bEncoded, QString::fromUtf8("Test.Cl&-AOE-udio").toUtf8());

    decoded = decodeImapFolderName(QString::fromUtf8("Test.Cl&-AOE-udio"));
    QCOMPARE(decoded, QString::fromUtf8("Test.Cl&AOE-udio"));
    bDecoded = decodeImapFolderName(QString::fromUtf8("Test.Cl&-AOE-udio").toUtf8());
    QCOMPARE(bDecoded, QString::fromUtf8("Test.Cl&AOE-udio").toUtf8());

    // With UTF8 characters
    bEncoded = "INBOX/&AOQ- &APY- &APw- @ &IKw-";
    QCOMPARE(decodeImapFolderName(bEncoded), QByteArray("INBOX/ä ö ü @ €"));
}

void RFCCodecsTest::testQuotes()
{
    QString test(QStringLiteral("tom\"allen"));
    QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\\\"allen"));
    test = QStringLiteral("tom\'allen");
    QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\'allen"));
    test = QStringLiteral("tom\\allen");
    QCOMPARE(quoteIMAP(test), QString::fromLatin1("tom\\\\allen"));
}

#include "moc_testrfccodecs.cpp"