File indexing completed on 2025-01-26 04:57:21
0001 /* 0002 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "riceencodingdecodertest.h" 0008 #include "../riceencodingdecoder.h" 0009 #include <QList> 0010 #include <QTest> 0011 0012 RiceEncodingDecoderTest::RiceEncodingDecoderTest(QObject *parent) 0013 : QObject(parent) 0014 { 0015 } 0016 0017 RiceEncodingDecoderTest::~RiceEncodingDecoderTest() = default; 0018 0019 void RiceEncodingDecoderTest::shouldDecodeRiceIndices_data() 0020 { 0021 QTest::addColumn<QByteArray>("firstValue"); 0022 QTest::addColumn<int>("riceParameter"); 0023 QTest::addColumn<int>("numberEntries"); 0024 QTest::addColumn<QByteArray>("encodingData"); 0025 QTest::addColumn<QList<quint32>>("result"); 0026 QTest::newRow("empty") << QByteArray() << 0 << 0 << QByteArray() << QList<quint32>(); 0027 QList<quint32> result; 0028 result << 3; 0029 QTest::newRow("zero value") << QByteArray("3") << 2 << 0 << QByteArray() << result; 0030 0031 result.clear(); 0032 result << 5 << 20 << 29; 0033 QTest::newRow("test1") << QByteArray("5") << 2 << 2 << QByteArrayLiteral("\xf7\x2") << result; 0034 0035 result.clear(); 0036 QTest::newRow("failedempty") << QByteArray("3") << 5 << 1 << QByteArray() << result; 0037 0038 result.clear(); 0039 // TODO fixme 0040 // QTest::newRow("failednegativeentries") << QByteArray("3") << 5 << -1 << QByteArray() << result; 0041 0042 result.clear(); 0043 // QTest::newRow("failednonpositive") << QByteArray("3") << 0 << 1 << QByteArrayLiteral("a") << result; 0044 result.clear(); 0045 QTest::newRow("failednonpositive1") << QByteArray("3") << -1 << 1 << QByteArrayLiteral("a") << result; 0046 } 0047 0048 void RiceEncodingDecoderTest::shouldDecodeRiceIndices() 0049 { 0050 QFETCH(QByteArray, firstValue); 0051 QFETCH(int, riceParameter); 0052 QFETCH(int, numberEntries); 0053 QFETCH(QByteArray, encodingData); 0054 QFETCH(QList<quint32>, result); 0055 WebEngineViewer::RiceEncodingDecoder decoding; 0056 WebEngineViewer::RiceDeltaEncoding deltaEncoding; 0057 deltaEncoding.encodingData = encodingData; 0058 deltaEncoding.firstValue = firstValue; 0059 deltaEncoding.numberEntries = numberEntries; 0060 deltaEncoding.riceParameter = riceParameter; 0061 QList<quint32> list = decoding.decodeRiceIndiceDelta(deltaEncoding); 0062 QCOMPARE(list.count(), result.count()); 0063 QCOMPARE(list, result); 0064 } 0065 0066 void RiceEncodingDecoderTest::shouldDecodeRiceHashes_data() 0067 { 0068 QTest::addColumn<QByteArray>("firstValue"); 0069 QTest::addColumn<int>("riceParameter"); 0070 QTest::addColumn<int>("numberEntries"); 0071 QTest::addColumn<QByteArray>("encodingData"); 0072 QTest::addColumn<QList<quint32>>("result"); 0073 QList<quint32> r; 0074 QTest::newRow("empty") << QByteArray() << 0 << 0 << QByteArray() << r; 0075 r.clear(); 0076 r = {5, 0xad934c0cu, 0x6ff67f56u, 0x81316fceu}; 0077 QTest::newRow("test1") << QByteArrayLiteral("5") << 28 << 3 << QByteArrayLiteral("\xbf\xa8\x3f\xfb\xf\xf\x5e\x27\xe6\xc3\x1d\xc6\x38") << r; 0078 } 0079 0080 void RiceEncodingDecoderTest::shouldDecodeRiceHashes() 0081 { 0082 QFETCH(QByteArray, firstValue); 0083 QFETCH(int, riceParameter); 0084 QFETCH(int, numberEntries); 0085 QFETCH(QByteArray, encodingData); 0086 QFETCH(QList<quint32>, result); 0087 WebEngineViewer::RiceEncodingDecoder decoding; 0088 WebEngineViewer::RiceDeltaEncoding deltaEncoding; 0089 deltaEncoding.encodingData = encodingData; 0090 deltaEncoding.firstValue = firstValue; 0091 deltaEncoding.numberEntries = numberEntries; 0092 deltaEncoding.riceParameter = riceParameter; 0093 const QList<quint32> hash = decoding.decodeRiceHashesDelta(deltaEncoding); 0094 qDebug() << " hash " << hash << " 0xad934c0cu" << 0xad934c0cu; 0095 QCOMPARE(hash, result); 0096 } 0097 0098 QTEST_GUILESS_MAIN(RiceEncodingDecoderTest) 0099 0100 #include "moc_riceencodingdecodertest.cpp"