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 #include <ui/dependencymodel/dependencymodel.h>
0020 
0021 #include <QtTest/qtest.h>
0022 #include <QAbstractItemModelTester>
0023 #include <QObject>
0024 
0025 class DependencyModelTest : public QObject
0026 {
0027     Q_OBJECT
0028 private slots:
0029     void modelTest_data()
0030     {
0031         QTest::addColumn<QString>("file");
0032         QTest::newRow("simple") << QStringLiteral(BINDIR "single-executable");
0033         QTest::newRow("complex") << QStringLiteral(BINDIR "elf-dissector");
0034     }
0035 
0036     void modelTest()
0037     {
0038         QFETCH(QString, file);
0039         ElfFileSet s;
0040         s.addFile(file);
0041         QVERIFY(s.size() > 1);
0042 
0043         DependencyModel model;
0044         QAbstractItemModelTester modelTest(&model);
0045 
0046         model.setFileSet(&s);
0047 
0048         QCOMPARE(model.rowCount(), 1);
0049 
0050         const auto topIndex = model.index(0, 0);
0051         QVERIFY(model.rowCount(topIndex) > 0);
0052         QVERIFY(topIndex.isValid());
0053         QCOMPARE(model.rowCount(topIndex), s.file(0)->dynamicSection()->neededLibraries().size());
0054     }
0055 };
0056 
0057 QTEST_MAIN(DependencyModelTest)
0058 
0059 #include "dependencymodeltest.moc"