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 <elf/elffileset.h> 0019 0020 #include <QtTest/qtest.h> 0021 #include <QObject> 0022 0023 #include <elf.h> 0024 0025 class ElfFileSetTest : public QObject 0026 { 0027 Q_OBJECT 0028 private slots: 0029 void testFindDependencies_data() 0030 { 0031 QTest::addColumn<QString>("executable"); 0032 QTest::newRow("single-executable") << QStringLiteral(BINDIR "single-executable"); 0033 QTest::newRow("structures") << QStringLiteral(BINDIR "structures"); 0034 QTest::newRow("elf-dissector") << QStringLiteral(BINDIR "elf-dissector"); 0035 } 0036 0037 void testFindDependencies() 0038 { 0039 QFETCH(QString, executable); 0040 0041 ElfFileSet f; 0042 f.addFile(executable); 0043 QVERIFY(f.size() > 1); 0044 } 0045 0046 void testInvalid_data() 0047 { 0048 QTest::addColumn<QString>("executable"); 0049 QTest::newRow("not existing") << QStringLiteral("not-existing"); 0050 QTest::newRow("text file") << QStringLiteral(BINDIR "../CMakeCache.txt"); 0051 } 0052 0053 void testInvalid() 0054 { 0055 QFETCH(QString, executable); 0056 0057 ElfFileSet f; 0058 f.addFile(executable); 0059 QCOMPARE(f.size(), 0); 0060 } 0061 0062 void testFindQt() 0063 { 0064 ElfFileSet f; 0065 f.addFile(QStringLiteral(BINDIR "elf-dissector")); 0066 bool foundQtCore = false; 0067 for (int i = 1; i < f.size(); ++i) { 0068 ElfFile *file = f.file(i); 0069 QVERIFY(file->isValid()); 0070 QVERIFY(file->dynamicSection()); 0071 if (file->dynamicSection() && file->dynamicSection()->soName() == "libQt5Core.so.5") 0072 foundQtCore = true; 0073 } 0074 QVERIFY(foundQtCore); 0075 } 0076 }; 0077 0078 QTEST_MAIN(ElfFileSetTest) 0079 0080 #include "elffilesettest.moc"