From 2c2919160b4b533e0791c5f988665c2bbeee3ad0 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 17 Aug 2014 16:34:51 +0400 Subject: [PATCH] add dbus test to testnetctl --- sources/gui/src/CMakeLists.txt | 5 +-- sources/helper/src/CMakeLists.txt | 4 +- sources/test/CMakeLists.txt | 12 +++--- sources/test/testnetctl.cpp | 61 +++++++++++++++++++++++++++++++ sources/test/testnetctl.h | 5 +++ sources/test/testnetctlauto.cpp | 1 - sources/test/testwpasup.cpp | 1 + 7 files changed, 75 insertions(+), 14 deletions(-) diff --git a/sources/gui/src/CMakeLists.txt b/sources/gui/src/CMakeLists.txt index 27d1e48..abcb618 100644 --- a/sources/gui/src/CMakeLists.txt +++ b/sources/gui/src/CMakeLists.txt @@ -19,10 +19,7 @@ if (USE_QT5) find_package(Qt5DBus REQUIRED) find_package(Qt5Widgets REQUIRED) find_package(Qt5LinguistTools REQUIRED) - add_definitions(${Qt5Core_DEFINITIONS}) - add_definitions(${Qt5DBus_DEFINITIONS}) - add_definitions(${Qt5Widgets_DEFINITIONS}) - add_definitions(${Qt5LinguistTools_DEFINITIONS}) + add_definitions(${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Widgets_DEFINITIONS} ${Qt5LinguistTools_DEFINITIONS}) include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Widgets_INCLUDE_DIRS}) set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Widgets_LIBRARIES}) qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) diff --git a/sources/helper/src/CMakeLists.txt b/sources/helper/src/CMakeLists.txt index befdbed..9a9f4f5 100644 --- a/sources/helper/src/CMakeLists.txt +++ b/sources/helper/src/CMakeLists.txt @@ -17,9 +17,7 @@ if (USE_QT5) find_package(Qt5Core REQUIRED) find_package(Qt5DBus REQUIRED) find_package(Qt5LinguistTools REQUIRED) - add_definitions(${Qt5Core_DEFINITIONS}) - add_definitions(${Qt5DBus_DEFINITIONS}) - add_definitions(${Qt5LinguistTools_DEFINITIONS}) + add_definitions(${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5LinguistTools_DEFINITIONS}) include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}) set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES}) qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index 142f011..8285370 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -32,19 +32,19 @@ link_directories (${PROJECT_LIBRARY}/src/lib) if (USE_QT5) find_package(Qt5Core REQUIRED) + find_package(Qt5DBus REQUIRED) find_package(Qt5Test REQUIRED) - add_definitions(${Qt5Core_DEFINITIONS}) - add_definitions(${Qt5Test_DEFINITIONS}) - include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS}) - set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5Test_LIBRARIES}) + add_definitions(${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS} ${Qt5Test_DEFINITIONS}) + include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS}) + set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES} ${Qt5Test_LIBRARIES}) qt5_wrap_cpp (NETCTL_MOC_SOURCES ${NETCTL_HEADERS}) qt5_wrap_cpp (NETCTLAUTO_MOC_SOURCES ${NETCTLAUTO_HEADERS}) qt5_wrap_cpp (PROFILE_MOC_SOURCES ${PROFILE_HEADERS}) qt5_wrap_cpp (WPASUP_MOC_SOURCES ${WPASUP_HEADERS}) else () - find_package (Qt4 COMPONENTS QtCore QtTest REQUIRED) + find_package (Qt4 COMPONENTS QtCore QtDBus QtTest REQUIRED) include (${QT_USE_FILE}) - set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY}) + set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTDBUS_LIBRARY} ${QT_QTTEST_LIBRARY}) qt4_wrap_cpp (NETCTL_MOC_SOURCES ${NETCTL_HEADERS}) qt4_wrap_cpp (NETCTLAUTO_MOC_SOURCES ${NETCTLAUTO_HEADERS}) qt4_wrap_cpp (PROFILE_MOC_SOURCES ${PROFILE_HEADERS}) diff --git a/sources/test/testnetctl.cpp b/sources/test/testnetctl.cpp index 4f65812..a26266a 100644 --- a/sources/test/testnetctl.cpp +++ b/sources/test/testnetctl.cpp @@ -18,10 +18,14 @@ #include "testnetctl.h" +#include +#include #include #include +#include "version.h" + Netctl *TestNetctl::createNetctlObj() { @@ -66,6 +70,20 @@ void TestNetctl::removeTestProfile() } +QList TestNetctl::sendDBusRequest(const QString path, const QString cmd, const QList args) +{ + QDBusConnection bus = QDBusConnection::systemBus(); + QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, path, + DBUS_HELPER_INTERFACE, cmd); + if (!args.isEmpty()) + request.setArguments(args); + QDBusMessage response = bus.call(request); + QList arguments = response.arguments(); + + return arguments; +} + + void TestNetctl::initTestCase() { qDebug() << "netctlgui library tests"; @@ -74,6 +92,11 @@ void TestNetctl::initTestCase() qDebug() << "with the working profile isn't tested here (including netctl-auto)"; QWARN("Some functions requires root privileges"); createTestProfile(); + if (sendDBusRequest(QString("/ctrl"), QString("Active")).isEmpty()) { + helper = false; + QWARN("Helper isn't active. DBus tests will be ignored"); + } else + helper = true; } @@ -110,10 +133,15 @@ void TestNetctl::test_getActiveProfile() Netctl *netctl = createNetctlObj(); netctl->startProfile(QString("netctlgui-test-dummy")); QStringList result = netctl->getActiveProfile(); + QStringList dbus; + if (helper) + dbus = sendDBusRequest(QString("/netctl"), QString("ActiveProfile")) + [0].toString().split(QChar('|')); netctl->startProfile(QString("netctlgui-test-dummy")); delete netctl; QVERIFY(result.contains(QString("netctlgui-test-dummy"))); + if (helper) QCOMPARE(dbus, result); } @@ -122,9 +150,18 @@ void TestNetctl::test_getProfileDescription() Netctl *netctl = createNetctlObj(); QString original = QString("Simple test profile"); QString result = netctl->getProfileDescription(QString("netctlgui-test-dummy")); + QString dbus; + if (helper) { + QList args; + args.append(QString("netctlgui-test-dummy")); + args.append(QString("Description")); + dbus = sendDBusRequest(QString("/netctl"), QString("ProfileValue"), args) + [0].toString(); + } delete netctl; QCOMPARE(result, original); + if (helper) QCOMPARE(dbus, result); } @@ -156,9 +193,13 @@ void TestNetctl::test_getProfileStatus() void TestNetctl::test_isProfileActive() { Netctl *netctl = createNetctlObj(); + QList args; + args.append(QString("netctlgui-test-dummy")); QVERIFY(!netctl->isProfileActive(QString("netctlgui-test-dummy"))); + if (helper) QVERIFY(!sendDBusRequest(QString("/netctl"), QString("isProfileActive"), args)[0].toBool()); netctl->startProfile(QString("netctlgui-test-dummy")); QVERIFY(netctl->isProfileActive(QString("netctlgui-test-dummy"))); + if (helper) QVERIFY(sendDBusRequest(QString("/netctl"), QString("isProfileActive"), args)[0].toBool()); netctl->startProfile(QString("netctlgui-test-dummy")); delete netctl; } @@ -167,9 +208,13 @@ void TestNetctl::test_isProfileActive() void TestNetctl::test_isProfileEnabled() { Netctl *netctl = createNetctlObj(); + QList args; + args.append(QString("netctlgui-test-dummy")); QVERIFY(!netctl->isProfileEnabled(QString("netctlgui-test-dummy"))); + if (helper) QVERIFY(!sendDBusRequest(QString("/netctl"), QString("isProfileEnabled"), args)[0].toBool()); netctl->enableProfile(QString("netctlgui-test-dummy")); QVERIFY(netctl->isProfileEnabled(QString("netctlgui-test-dummy"))); + if (helper) QVERIFY(sendDBusRequest(QString("/netctl"), QString("isProfileEnabled"), args)[0].toBool()); netctl->enableProfile(QString("netctlgui-test-dummy")); delete netctl; } @@ -178,11 +223,19 @@ void TestNetctl::test_isProfileEnabled() void TestNetctl::test_reenableProfile() { Netctl *netctl = createNetctlObj(); + QList args; + args.append(QString("netctlgui-test-dummy")); QVERIFY(!netctl->isProfileEnabled(QString("netctlgui-test-dummy"))); + if (helper) QVERIFY(!sendDBusRequest(QString("/netctl"), QString("isProfileEnabled"), args)[0].toBool()); netctl->enableProfile(QString("netctlgui-test-dummy")); QVERIFY(netctl->isProfileEnabled(QString("netctlgui-test-dummy"))); QVERIFY(netctl->reenableProfile(QString("netctlgui-test-dummy"))); QVERIFY(netctl->isProfileEnabled(QString("netctlgui-test-dummy"))); + if (helper) { + QVERIFY(sendDBusRequest(QString("/netctl"), QString("isProfileEnabled"), args)[0].toBool()); + QVERIFY(sendDBusRequest(QString("/ctrl"), QString("Reenable"), args)[0].toBool()); + QVERIFY(sendDBusRequest(QString("/netctl"), QString("isProfileEnabled"), args)[0].toBool()); + } netctl->enableProfile(QString("netctlgui-test-dummy")); delete netctl; } @@ -191,11 +244,19 @@ void TestNetctl::test_reenableProfile() void TestNetctl::test_restartProfile() { Netctl *netctl = createNetctlObj(); + QList args; + args.append(QString("netctlgui-test-dummy")); QVERIFY(!netctl->isProfileActive(QString("netctlgui-test-dummy"))); + if (helper) QVERIFY(!sendDBusRequest(QString("/netctl"), QString("isProfileActive"), args)[0].toBool()); netctl->startProfile(QString("netctlgui-test-dummy")); QVERIFY(netctl->isProfileActive(QString("netctlgui-test-dummy"))); QVERIFY(netctl->restartProfile(QString("netctlgui-test-dummy"))); QVERIFY(netctl->isProfileActive(QString("netctlgui-test-dummy"))); + if (helper) { + QVERIFY(sendDBusRequest(QString("/netctl"), QString("isProfileActive"), args)[0].toBool()); + QVERIFY(sendDBusRequest(QString("/ctrl"), QString("Restart"), args)[0].toBool()); + QVERIFY(sendDBusRequest(QString("/netctl"), QString("isProfileActive"), args)[0].toBool()); + } netctl->startProfile(QString("netctlgui-test-dummy")); delete netctl; } diff --git a/sources/test/testnetctl.h b/sources/test/testnetctl.h index a632106..ad0c55e 100644 --- a/sources/test/testnetctl.h +++ b/sources/test/testnetctl.h @@ -19,6 +19,7 @@ #define TESTNETCTL_H #include +#include class Netctl; @@ -43,10 +44,14 @@ private slots: void test_restartProfile(); private: + bool helper; Netctl *createNetctlObj(); NetctlProfile *createNetctlProfileObj(); void createTestProfile(); void removeTestProfile(); + QList sendDBusRequest(const QString path, + const QString cmd, + const QList args = QList()); }; diff --git a/sources/test/testnetctlauto.cpp b/sources/test/testnetctlauto.cpp index 030bdbb..c1699f8 100644 --- a/sources/test/testnetctlauto.cpp +++ b/sources/test/testnetctlauto.cpp @@ -27,7 +27,6 @@ Netctl *TestNetctlAuto::createNetctlObj() { QMap settings = Netctl::getRecommendedConfiguration(); settings[QString("FORCE_SUDO")] = QString("true"); - // to test netctl-auto with dummy profiles settings[QString("PREFERED_IFACE")] = QString("ngtest"); Netctl *netctl = new Netctl(false, settings); diff --git a/sources/test/testwpasup.cpp b/sources/test/testwpasup.cpp index f379e6c..c7227e8 100644 --- a/sources/test/testwpasup.cpp +++ b/sources/test/testwpasup.cpp @@ -27,6 +27,7 @@ WpaSup *TestWpaSup::createWpaSupObj() { QMap settings = WpaSup::getRecommendedConfiguration(); settings[QString("FORCE_SUDO")] = QString("true"); + settings[QString("PREFERED_IFACE")] = QString("ngtest"); WpaSup *wpasup = new WpaSup(false, settings); return wpasup;