File indexing completed on 2024-04-28 05:52:32

0001 /*
0002     This file is part of the Okteta Core library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2006, 2011 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "charcodeciftest.hpp"
0010 
0011 // test object
0012 #include <charcodec.hpp>
0013 // lib
0014 #include <character.hpp>
0015 // Qt
0016 #include <QTest>
0017 
0018 namespace Okteta {
0019 
0020 void CharCodecIfTest::init()
0021 {
0022     mCharCodec = createCodec();
0023 }
0024 
0025 void CharCodecIfTest::cleanup()
0026 {
0027     deleteCodec(mCharCodec);
0028 }
0029 
0030 void CharCodecIfTest::testEncodeDecode_data()
0031 {
0032     QTest::addColumn<int>("byteValue");
0033 
0034     for (int i = 0; i < 256; ++i) {
0035         const QString rowTitle = QStringLiteral("byte %1").arg(i);
0036         QTest::newRow(rowTitle.toLatin1().constData()) << i;
0037     }
0038 }
0039 
0040 // TODO: is duplication with what is on CharCodecTest
0041 // (though that is complete, TextCharCodecCharCodecIfTest ATM misses to test all TextCharCodecs)
0042 void CharCodecIfTest::testEncodeDecode()
0043 {
0044     QFETCH(int, byteValue);
0045 
0046     // current assumption: the mapping of chars to byte values is biunique for all used charsets
0047     const Byte byte = Byte(byteValue);
0048     Character character = mCharCodec->decode(byte);
0049     if (!character.isUndefined()) {
0050         QVERIFY(mCharCodec->canEncode(character));
0051 
0052         Byte encodedByte;
0053         const bool encodeSuccess = mCharCodec->encode(&encodedByte, character);
0054         QVERIFY(encodeSuccess);
0055         QCOMPARE(encodedByte, byte);
0056     }
0057 }
0058 
0059 }
0060 
0061 #include "moc_charcodeciftest.cpp"