File indexing completed on 2024-05-05 16:21:36

0001 /*
0002     SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "../src/lib/bitvector_p.h"
0008 #include "../src/lib/reedsolomon_p.h"
0009 
0010 #include <QDebug>
0011 #include <QObject>
0012 #include <QTest>
0013 
0014 Q_DECLARE_METATYPE(Prison::BitVector)
0015 
0016 using namespace Prison;
0017 
0018 class ReedSolomonTest : public QObject
0019 {
0020     Q_OBJECT
0021 private Q_SLOTS:
0022     void rsTest_data()
0023     {
0024         QTest::addColumn<int>("poly");
0025         QTest::addColumn<int>("symCount");
0026         QTest::addColumn<BitVector>("input");
0027         QTest::addColumn<BitVector>("output");
0028 
0029         BitVector in;
0030         BitVector out;
0031         out.appendMSB(0, 20);
0032         QTest::newRow("empty") << (int)ReedSolomon::GF16 << 5 << in << out;
0033 
0034         in.clear();
0035         out.clear();
0036         in.appendMSB(0x5c, 8);
0037         out.appendMSB(7, 6);
0038         out.appendMSB(5, 7);
0039         out.appendMSB(0x4d, 7);
0040         QTest::newRow("GF16") << (int)ReedSolomon::GF16 << 5 << in << out;
0041     }
0042 
0043     void rsTest()
0044     {
0045         QFETCH(int, poly);
0046         QFETCH(int, symCount);
0047         QFETCH(BitVector, input);
0048         QFETCH(BitVector, output);
0049 
0050         ReedSolomon rs(poly, symCount);
0051         const auto res = rs.encode(input);
0052         QCOMPARE(res.size(), output.size());
0053         if (res != output) {
0054             qDebug() << "Actual  :" << res;
0055             qDebug() << "Expected:" << output;
0056         }
0057         QCOMPARE(res, output);
0058     }
0059 };
0060 
0061 QTEST_APPLESS_MAIN(ReedSolomonTest)
0062 
0063 #include "reedsolomontest.moc"