File indexing completed on 2024-04-28 05:41:06
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 #include <elf/elfsymboltablesection.h> 0020 #include <ui/elfmodel/elfmodel.h> 0021 0022 #include <QtTest/qtest.h> 0023 #include <QAbstractItemModelTester> 0024 #include <QObject> 0025 0026 #include <elf.h> 0027 0028 class ElfModelTest : public QObject 0029 { 0030 Q_OBJECT 0031 private slots: 0032 void modelTest() 0033 { 0034 ElfFileSet s; 0035 s.addFile(QStringLiteral(BINDIR "single-executable")); 0036 QVERIFY(s.size() > 1); 0037 0038 ElfModel model; 0039 QAbstractItemModelTester modelTest(&model); 0040 0041 model.setFileSet(&s); 0042 0043 QCOMPARE(model.rowCount(), s.size()); 0044 } 0045 0046 void navigationTest() 0047 { 0048 ElfFileSet s; 0049 s.addFile(QStringLiteral(BINDIR "elf-dissector")); 0050 QVERIFY(s.size() > 1); 0051 0052 ElfModel model; 0053 model.setFileSet(&s); 0054 0055 auto file = s.file(0); 0056 auto symTab = file->symbolTable(); 0057 for (uint i = 0; i < symTab->header()->entryCount(); ++i) { 0058 auto idx = model.indexForNode(symTab->entry(i)); 0059 QVERIFY(idx.isValid()); 0060 if (strcmp(symTab->entry(i)->name(), "") == 0) 0061 continue; 0062 QCOMPARE(idx.data(Qt::DisplayRole).toString(), QString(symTab->entry(i)->name())); 0063 auto url = idx.data(ElfModel::NodeUrl).toUrl(); 0064 QVERIFY(url.isValid()); 0065 QVERIFY(!url.path().isEmpty()); 0066 QVERIFY(!url.scheme().isEmpty()); 0067 0068 auto idx2 = model.indexForUrl(url); 0069 QCOMPARE(idx, idx2); 0070 } 0071 } 0072 }; 0073 0074 QTEST_MAIN(ElfModelTest) 0075 0076 #include "elfmodeltest.moc"