File indexing completed on 2024-04-28 05:41:05
0001 /* 0002 Copyright (C) 2015 Volker Krause <vkrause@kde.org> 0003 0004 This program is free software; you can redistribute it and/or modify it 0005 under the terms of the GNU Library General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or (at your 0007 option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, but WITHOUT 0010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0011 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 0012 License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program. If not, see <https://www.gnu.org/licenses/>. 0016 */ 0017 0018 #include <dwarf/dwarfleb128.h> 0019 0020 #include <QtTest/qtest.h> 0021 #include <QObject> 0022 0023 class DwarfLEB128Test : public QObject 0024 { 0025 Q_OBJECT 0026 private slots: 0027 void testDecodeULEB128_data() 0028 { 0029 QTest::addColumn<QByteArray>("data"); 0030 QTest::addColumn<uint64_t>("result"); 0031 QTest::addColumn<int>("size"); 0032 0033 QTest::newRow("0") << QByteArray("\x00") << uint64_t(0) << 1; 0034 QTest::newRow("42") << QByteArray("\x2A") << uint64_t(42) << 1; 0035 QTest::newRow("624485") << QByteArray("\xE5\x8E\x26") << uint64_t(624485) << 3; 0036 } 0037 0038 void testDecodeULEB128() 0039 { 0040 QFETCH(QByteArray, data); 0041 QFETCH(uint64_t, result); 0042 QFETCH(int, size); 0043 0044 int decodedSize = 0; 0045 QCOMPARE(DwarfLEB128::decodeUnsigned(data.constData(), &decodedSize), result); 0046 QCOMPARE(decodedSize, size); 0047 QCOMPARE(DwarfLEB128::decodeUnsigned(data.constData()), result); 0048 } 0049 0050 void testDecodeSLEB128_data() 0051 { 0052 QTest::addColumn<QByteArray>("data"); 0053 QTest::addColumn<int64_t>("result"); 0054 QTest::addColumn<int>("size"); 0055 0056 QTest::newRow("0") << QByteArray("\x00") << int64_t(0) << 1; 0057 QTest::newRow("42") << QByteArray("\x2A") << int64_t(42) << 1; 0058 QTest::newRow("-624485") << QByteArray("\x9b\xf1\x59") << int64_t(-624485) << 3; 0059 } 0060 0061 void testDecodeSLEB128() 0062 { 0063 QFETCH(QByteArray, data); 0064 QFETCH(int64_t, result); 0065 QFETCH(int, size); 0066 0067 int decodedSize = 0; 0068 QCOMPARE(DwarfLEB128::decodeSigned(data.constData(), &decodedSize), result); 0069 QCOMPARE(decodedSize, size); 0070 QCOMPARE(DwarfLEB128::decodeSigned(data.constData()), result); 0071 } 0072 }; 0073 0074 QTEST_MAIN(DwarfLEB128Test) 0075 0076 #include "dwarfleb128test.moc"