mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
add dbus test to testnetctl
This commit is contained in:
parent
d7c8490724
commit
2c2919160b
@ -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})
|
||||
|
@ -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})
|
||||
|
@ -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})
|
||||
|
@ -18,10 +18,14 @@
|
||||
|
||||
#include "testnetctl.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QtTest>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
#include "version.h"
|
||||
|
||||
|
||||
Netctl *TestNetctl::createNetctlObj()
|
||||
{
|
||||
@ -66,6 +70,20 @@ void TestNetctl::removeTestProfile()
|
||||
}
|
||||
|
||||
|
||||
QList<QVariant> TestNetctl::sendDBusRequest(const QString path, const QString cmd, const QList<QVariant> 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<QVariant> 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<QVariant> 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<QVariant> 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<QVariant> 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<QVariant> 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<QVariant> 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;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define TESTNETCTL_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class Netctl;
|
||||
@ -43,10 +44,14 @@ private slots:
|
||||
void test_restartProfile();
|
||||
|
||||
private:
|
||||
bool helper;
|
||||
Netctl *createNetctlObj();
|
||||
NetctlProfile *createNetctlProfileObj();
|
||||
void createTestProfile();
|
||||
void removeTestProfile();
|
||||
QList<QVariant> sendDBusRequest(const QString path,
|
||||
const QString cmd,
|
||||
const QList<QVariant> args = QList<QVariant>());
|
||||
};
|
||||
|
||||
|
||||
|
@ -27,7 +27,6 @@ Netctl *TestNetctlAuto::createNetctlObj()
|
||||
{
|
||||
QMap<QString, QString> 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);
|
||||
|
||||
|
@ -27,6 +27,7 @@ WpaSup *TestWpaSup::createWpaSupObj()
|
||||
{
|
||||
QMap<QString, QString> settings = WpaSup::getRecommendedConfiguration();
|
||||
settings[QString("FORCE_SUDO")] = QString("true");
|
||||
settings[QString("PREFERED_IFACE")] = QString("ngtest");
|
||||
WpaSup *wpasup = new WpaSup(false, settings);
|
||||
|
||||
return wpasup;
|
||||
|
Loading…
Reference in New Issue
Block a user