summaryrefslogtreecommitdiff
path: root/kimap/tests/testrfccodecs.cpp
blob: 38abd348e8d339d61de7813484a7ccc3e1f44e6f (plain)
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
71
72
73
74
75
76
77
78
79
/*
   This file is part of the kimap library.
   Copyright (C) 2007 Tom Albers <tomalbers@kde.nl>
   Copyright (c) 2007 Allen Winter <winter@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License version 2 as published by the Free Software Foundation.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/
#include <qtest_kde.h>

#include "testrfccodecs.h"

QTEST_KDEMAIN_CORE( RFCCodecsTest )

#include "kimap/rfccodecs.h"
using namespace KIMAP;

void RFCCodecsTest::testIMAPEncoding()
{
  QString encoded, decoded;
  QByteArray bEncoded, 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( "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("tom\"allen");
  QCOMPARE( quoteIMAP( test ), QString("tom\\\"allen") );
  test = "tom\'allen";
  QCOMPARE( quoteIMAP( test ), QString("tom\'allen" ) );
  test =  "tom\\allen";
  QCOMPARE( quoteIMAP( test ), QString("tom\\\\allen" ) );
}