From 56f4a75b25f2b574a0ad64b320acfe09af1c407a Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 17 Aug 2014 18:26:04 +0400 Subject: [PATCH] end work on tests --- README.md | 1 - sources/test/testnetctlauto.cpp | 5 ++ sources/test/testnetctlauto.h | 1 + sources/test/testnetctlprofile.cpp | 77 +++++++++++++++++++++++++++++- sources/test/testnetctlprofile.h | 5 ++ sources/test/testwpasup.cpp | 5 ++ sources/test/testwpasup.h | 1 + 7 files changed, 92 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7a73054..6fbb96d 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,6 @@ TODO (wish list) * add helper polkit-qt integration ? * test several profiles support -* autotests (QCOMPARE(gui, lib)); Links ----- diff --git a/sources/test/testnetctlauto.cpp b/sources/test/testnetctlauto.cpp index 75d6b67..ebee734 100644 --- a/sources/test/testnetctlauto.cpp +++ b/sources/test/testnetctlauto.cpp @@ -99,6 +99,11 @@ void TestNetctlAuto::initTestCase() qDebug() << "with the working profile isn't tested here (including netctl-auto)"; QWARN("Some functions requires root privileges"); createTestProfiles(); + if (sendDBusRequest(QString("/ctrl"), QString("Active")).isEmpty()) { + helper = false; + QWARN("Helper isn't active. DBus tests will be ignored"); + } else + helper = true; } diff --git a/sources/test/testnetctlauto.h b/sources/test/testnetctlauto.h index 4194d3b..8d120a8 100644 --- a/sources/test/testnetctlauto.h +++ b/sources/test/testnetctlauto.h @@ -36,6 +36,7 @@ private slots: // netctl-auto private: + bool helper; Netctl *createNetctlObj(); NetctlProfile *createNetctlProfileObj(); void createTestProfiles(); diff --git a/sources/test/testnetctlprofile.cpp b/sources/test/testnetctlprofile.cpp index c802f8b..a0db7ae 100644 --- a/sources/test/testnetctlprofile.cpp +++ b/sources/test/testnetctlprofile.cpp @@ -18,10 +18,14 @@ #include "testnetctlprofile.h" +#include +#include #include #include +#include "version.h" + NetctlProfile *TestNetctlProfile::createNetctlProfileObj() { @@ -59,6 +63,20 @@ bool TestNetctlProfile::removeTestProfile() } +QList TestNetctlProfile::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 TestNetctlProfile::initTestCase() { qDebug() << "netctlgui library tests"; @@ -68,6 +86,11 @@ void TestNetctlProfile::initTestCase() QWARN("Some functions requires root privileges"); // arent needed // createTestProfile(); + if (sendDBusRequest(QString("/ctrl"), QString("Active")).isEmpty()) { + helper = false; + QWARN("Helper isn't active. DBus tests will be ignored"); + } else + helper = true; } @@ -98,6 +121,18 @@ void TestNetctlProfile::test_copyProfile() { NetctlProfile *netctl = createNetctlProfileObj(); QVERIFY(createTestProfile()); + if (helper) { + QList args; + args.append(QString("netctlgui-test-dummy")); + QStringList profileSettings; + profileSettings.append(QString("Connection==dummy")); + profileSettings.append(QString("Description==\"Simple test profile\"")); + profileSettings.append(QString("IP==no")); + profileSettings.append(QString("IP6==no")); + profileSettings.append(QString("Interface==ngtest")); + args.append(profileSettings); + QVERIFY(sendDBusRequest(QString("/ctrl"), QString("Create"), args)[0].toBool()); + } delete netctl; } @@ -112,7 +147,7 @@ void TestNetctlProfile::test_getValueFromProfile() original.append(QString("no")); original.append(QString("no")); original.append(QString("ngtest")); - QStringList result; + QStringList result, dbus; result.append(netctl->getValueFromProfile(QString("netctlgui-test-dummy"), QString("Connection"))); result.append(netctl->getValueFromProfile(QString("netctlgui-test-dummy"), @@ -123,6 +158,29 @@ void TestNetctlProfile::test_getValueFromProfile() QString("IP6"))); result.append(netctl->getValueFromProfile(QString("netctlgui-test-dummy"), QString("Interface"))); + if (helper) { + QList args; + args.append(QString("netctlgui-test-dummy")); + args.append(QString("Connection")); + dbus.append(sendDBusRequest(QString("/netctl"), QString("ProfileValue"), args)[0].toString()); + args.clear(); + args.append(QString("netctlgui-test-dummy")); + args.append(QString("Description")); + dbus.append(sendDBusRequest(QString("/netctl"), QString("ProfileValue"), args)[0].toString()); + args.clear(); + args.append(QString("netctlgui-test-dummy")); + args.append(QString("IP")); + dbus.append(sendDBusRequest(QString("/netctl"), QString("ProfileValue"), args)[0].toString()); + args.clear(); + args.append(QString("netctlgui-test-dummy")); + args.append(QString("IP6")); + dbus.append(sendDBusRequest(QString("/netctl"), QString("ProfileValue"), args)[0].toString()); + args.clear(); + args.append(QString("netctlgui-test-dummy")); + args.append(QString("Interface")); + dbus.append(sendDBusRequest(QString("/netctl"), QString("ProfileValue"), args)[0].toString()); + QCOMPARE(dbus, result); + } delete netctl; QCOMPARE(result, original); @@ -174,6 +232,15 @@ void TestNetctlProfile::test_createProfile() 'phase2=\"auth=PAP\"'\n\ "); QVERIFY(netctl->copyProfile(netctl->createProfile(QString("netctlgui-test-full"), profileSettings))); + if (helper) { + QList args; + args.append(QString("netctlgui-test-full")); + QStringList profileSettingsList; + for (int i=0; i args; + args.append(QString("netctlgui-test-full")); + dbus = sendDBusRequest(QString("/netctl"), QString("Profile"), args)[0].toStringList(); + } QMap resultMap = netctl->getSettingsFromProfile(QString("netctlgui-test-full")); for (int i=0; i +#include class NetctlProfile; @@ -40,9 +41,13 @@ private slots: void test_removeProfile(); private: + bool helper; NetctlProfile *createNetctlProfileObj(); bool createTestProfile(); bool removeTestProfile(); + QList sendDBusRequest(const QString path, + const QString cmd, + const QList args = QList()); }; diff --git a/sources/test/testwpasup.cpp b/sources/test/testwpasup.cpp index 987e771..98b4034 100644 --- a/sources/test/testwpasup.cpp +++ b/sources/test/testwpasup.cpp @@ -59,6 +59,11 @@ void TestWpaSup::initTestCase() qDebug() << "TODO: unfortunately, some functions which is required to work"; qDebug() << "with the working profile isn't tested here (including netctl-auto)"; QWARN("Some functions requires root privileges"); + if (sendDBusRequest(QString("/ctrl"), QString("Active")).isEmpty()) { + helper = false; + QWARN("Helper isn't active. DBus tests will be ignored"); + } else + helper = true; } diff --git a/sources/test/testwpasup.h b/sources/test/testwpasup.h index b4f3cdb..275b8ce 100644 --- a/sources/test/testwpasup.h +++ b/sources/test/testwpasup.h @@ -36,6 +36,7 @@ private slots: void test_getRecommendedConfiguration(); private: + bool helper; WpaSup *createWpaSupObj(); QList sendDBusRequest(const QString path, const QString cmd,