File indexing completed on 2024-05-19 04:41:19
0001 /* 0002 SPDX-FileCopyrightText: 2014 Kevin Funk <kfunk@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "../manpagedocumentation.h" 0008 #include "../manpagemodel.h" 0009 // Qt 0010 #include <QAbstractItemModelTester> 0011 #include <QDebug> 0012 #include <QSignalSpy> 0013 #include <QTest> 0014 #include <QStandardPaths> 0015 0016 class TestManPageModel : public QObject 0017 { 0018 Q_OBJECT 0019 0020 private Q_SLOTS: 0021 void initTestCase() { QStandardPaths::setTestModeEnabled(true); } 0022 void testModel(); 0023 void testDocumentation(); 0024 }; 0025 0026 void TestManPageModel::testModel() 0027 { 0028 ManPageModel model; 0029 0030 new QAbstractItemModelTester(&model, this); 0031 0032 QTRY_VERIFY(model.isLoaded() || model.hasError()); 0033 if (model.isLoaded()) 0034 QVERIFY(model.rowCount() > 0); 0035 } 0036 0037 void TestManPageModel::testDocumentation() 0038 { 0039 ManPageDocumentation documentation(QStringLiteral("dlopen"), QUrl(QStringLiteral("man: (3)/dlmopen"))); 0040 QSignalSpy spy(&documentation, SIGNAL(descriptionChanged())); 0041 QVERIFY(spy.wait()); 0042 0043 const QString description = documentation.description(); 0044 qDebug() << "Description:" << description; 0045 if (description.isEmpty() || description.contains(QLatin1String("No man page matching to dlmopen found"))) { 0046 QSKIP("This test requires installed man pages for dlmopen & friends"); 0047 } 0048 0049 // check that we've found the correct page by checking some references 0050 QVERIFY(description.contains("dlclose")); 0051 QVERIFY(description.contains("dlerror")); 0052 QVERIFY(description.contains("dlopen")); 0053 } 0054 0055 QTEST_MAIN(TestManPageModel) 0056 0057 #include "test_manpagemodel.moc"