File indexing completed on 2024-04-14 05:12:19
0001 /* 0002 SPDX-FileCopyrightText: 2006 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include <QTest> 0008 0009 #include "rfc2047test.h" 0010 0011 #include <KCodecs> 0012 #include <kmime_codecs.cpp> 0013 using namespace KMime; 0014 0015 QTEST_MAIN(RFC2047Test) 0016 0017 void RFC2047Test::testRFC2047encode() 0018 { 0019 // empty 0020 QCOMPARE(KMime::encodeRFC2047String(QString(), "utf-8"), QByteArray()); 0021 // identity 0022 QCOMPARE(KMime::encodeRFC2047String(u"bla", "utf-8"), QByteArray("bla")); 0023 // utf-8 0024 // expected value is probably wrong, libkmime will chose 'B' instead of 'Q' encoding 0025 QEXPECT_FAIL("", "libkmime will chose 'B' instead of 'Q' encoding", Continue); 0026 QCOMPARE(KMime::encodeRFC2047String(QString::fromUtf8("Ingo Klöcker <kloecker@kde.org>"), "utf-8").constData(), 0027 "=?utf-8?q?Ingo=20Kl=C3=B6cker?= <kloecker@kde.org>"); 0028 0029 // Fallback to UTF-8 for encoding since the given charset can't encode the string 0030 const QString input = QStringLiteral("æſðđŋħł"); 0031 const QByteArray result = KMime::encodeRFC2047String(input, "latin1"); 0032 QCOMPARE(KCodecs::decodeRFC2047String(QString::fromUtf8(result)), input); 0033 QVERIFY(result.contains("utf-8")); 0034 } 0035 0036 #include "moc_rfc2047test.cpp"