diff options
| author | Harald Sitter <sitter@kde.org> | 2015-11-24 15:05:03 (GMT) |
|---|---|---|
| committer | Harald Sitter <sitter@kde.org> | 2015-11-25 12:01:47 (GMT) |
| commit | d318a2ecc6d9268ac0af4ccb82fc2f98df958771 (patch) | |
| tree | ee3b926ad4f07bf908762ff4d12357ed228485d8 | |
| parent | 8d8744913e2e996f68b8e3824c8202f2118ff220 (diff) | |
add a pretty terrible test for finder. it manipulates apt... very meh
| -rw-r--r-- | CMakeLists.txt | 3 | ||||
| -rw-r--r-- | autotests/CMakeLists.txt | 20 | ||||
| -rw-r--r-- | autotests/findertest.cpp | 90 |
3 files changed, 113 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index db52d7f..4a83514 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,12 +10,15 @@ include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings) +set(REQUIRED_QT_VERSION 5.0) +find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Concurrent Test) find_package(KF5CoreAddons 5.0.0 REQUIRED) find_package(KF5I18n 5.0.0 REQUIRED) find_package(KF5WidgetsAddons 5.0.0 REQUIRED) find_package(QApt 3.0.0 REQUIRED) +add_subdirectory(autotests) add_subdirectory(src) feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt new file mode 100644 index 0000000..70c9a1b --- /dev/null +++ b/autotests/CMakeLists.txt @@ -0,0 +1,20 @@ +if(POLICY CMP0028) + cmake_policy(SET CMP0028 OLD) +endif() +remove_definitions(-DQT_NO_CAST_FROM_ASCII) + +include(ECMAddTests) +include(ECMCoverageOption) + +########### unittests ############### + +ecm_add_test(../src/DebugFinder.cpp + findertest.cpp + NAME_PREFIX "kubuntu-debug-installer-" + TEST_NAME "findertest" + LINK_LIBRARIES Qt5::Test QApt::Main +) + +# target_link_libraries(threadtest Qt5::Concurrent) + + diff --git a/autotests/findertest.cpp b/autotests/findertest.cpp new file mode 100644 index 0000000..0b546ea --- /dev/null +++ b/autotests/findertest.cpp @@ -0,0 +1,90 @@ +#include <QTest> +#include <QSignalSpy> + +#include "../src/DebugFinder.h" + + +/* + /usr/lib/x86_64-linux-gnu/libQt5Core.so.5 + /usr/lib/x86_64-linux-gnu/libkdeinit5_kwrite.so + /lib/x86_64-linux-gnu/libglib-2.0.so.0 +*/ + +#include <QApt/Backend> + +class FinderTest : public QObject +{ + Q_OBJECT +private Q_SLOTS: + void testAlreadyInstalled() + { + QApt::Backend apt; + apt.init(); + auto libc6_dbg = apt.package("libc6-dbg"); + apt.installPackages(QApt::PackageList() << libc6_dbg); + apt.reloadCache(); + auto intalledFiles = apt.package("libc6")->installedFilesList(); + QString path; + Q_FOREACH(const QString &file, intalledFiles) { + if (!file.endsWith(".so")) { + continue; + } + path = file; + break; + } + QVERIFY(!path.isEmpty()); + qDebug() << path; + + DebugFinder finder; + QSignalSpy spy(&finder, &DebugFinder::alreadyInstalled); + QMetaObject::invokeMethod(&finder, "find", Qt::QueuedConnection, + Q_ARG(QString, path)); + QVERIFY(spy.wait()); + QCOMPARE(spy.count(), 1); + } + + void testDebugFound() + { + QApt::Backend apt; + apt.init(); + apt.removePackages(QApt::PackageList() << apt.package("ksysguard-dbg")); + + DebugFinder finder; + QSignalSpy spy(&finder, &DebugFinder::foundDbgPkg); + QMetaObject::invokeMethod(&finder, "find", Qt::QueuedConnection, + Q_ARG(QString, QString("/usr/bin/ksysguard"))); + QVERIFY(spy.wait()); + QCOMPARE(spy.count(), 1); + QList<QVariant> sig = spy.takeAt(0); + QCOMPARE(sig.count(), 1); // 1 arg + QCOMPARE(sig.at(0).toString(), QStringLiteral("ksysguard-dbg")); + } + + void testNoDebugFound() + { + DebugFinder finder; + QSignalSpy spy(&finder, &DebugFinder::foundNoDbgPkg); + QMetaObject::invokeMethod(&finder, "find", Qt::QueuedConnection, + Q_ARG(QString, QString("/usr/lib/yolokitten.so.5"))); + QVERIFY(spy.wait()); + QCOMPARE(spy.count(), 1); + } + + void testQt4X11() + { + QApt::Backend apt; + apt.init(); + apt.removePackages(QApt::PackageList() << apt.package("libqt4-dbg")); + + DebugFinder finder; + QSignalSpy spy(&finder, &DebugFinder::foundDbgPkg); + QMetaObject::invokeMethod(&finder, "find", Qt::QueuedConnection, + Q_ARG(QString, QString("/usr/lib/x86_64-linux-gnu/libQtCore.so.4"))); + QVERIFY(spy.wait()); + QCOMPARE(spy.count(), 1); + } +}; + +QTEST_MAIN(FinderTest) + +#include "findertest.moc" |
