mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-07-08 03:15:54 +00:00
add tests to netctl control
(todo: netctl-auto tests)
This commit is contained in:
@ -16,7 +16,7 @@ file (GLOB SOURCES *.cpp)
|
|||||||
file (GLOB HEADERS *.h)
|
file (GLOB HEADERS *.h)
|
||||||
|
|
||||||
# include_path
|
# include_path
|
||||||
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/include/
|
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/include/
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/../
|
${CMAKE_CURRENT_BINARY_DIR}/../
|
||||||
${CMAKE_SOURCE_DIR}
|
${CMAKE_SOURCE_DIR}
|
||||||
${CMAKE_BINARY_DIR}
|
${CMAKE_BINARY_DIR}
|
||||||
|
@ -23,31 +23,51 @@
|
|||||||
#include <netctlgui/netctlgui.h>
|
#include <netctlgui/netctlgui.h>
|
||||||
|
|
||||||
|
|
||||||
void TestNetctl::createTestProfile()
|
Netctl *TestNetctl::createNetctlObj()
|
||||||
|
{
|
||||||
|
QMap<QString, QString> settings = Netctl::getRecommendedConfiguration();
|
||||||
|
settings[QString("FORCE_SUDO")] = QString("true");
|
||||||
|
Netctl *netctl = new Netctl(false, settings);
|
||||||
|
|
||||||
|
return netctl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NetctlProfile *TestNetctl::createNetctlProfileObj()
|
||||||
{
|
{
|
||||||
QMap<QString, QString> settings = NetctlProfile::getRecommendedConfiguration();
|
QMap<QString, QString> settings = NetctlProfile::getRecommendedConfiguration();
|
||||||
settings[QString("FORCE_SUDO")] = QString("true");
|
settings[QString("FORCE_SUDO")] = QString("true");
|
||||||
NetctlProfile *netctl = new NetctlProfile(false, settings);
|
NetctlProfile *netctl = new NetctlProfile(false, settings);
|
||||||
|
|
||||||
|
return netctl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestNetctl::createTestProfile()
|
||||||
|
{
|
||||||
|
NetctlProfile *netctl = createNetctlProfileObj();
|
||||||
QMap<QString, QString> profileSettings;
|
QMap<QString, QString> profileSettings;
|
||||||
profileSettings["Connection"] = QString("dummy");
|
profileSettings["Connection"] = QString("dummy");
|
||||||
profileSettings["Description"] = QString("Simple test profile");
|
profileSettings["Description"] = QString("\"Simple test profile\"");
|
||||||
profileSettings["IP"] = QString("no");
|
profileSettings["IP"] = QString("no");
|
||||||
profileSettings["IP6"] = QString("no");
|
profileSettings["IP6"] = QString("no");
|
||||||
profileSettings["Interface"] = QString("test");
|
profileSettings["Interface"] = QString("ngtest");
|
||||||
|
netctl->copyProfile(netctl->createProfile(QString("netctlgui-test-dummy"), profileSettings));
|
||||||
netctl->copyProfile(netctl->createProfile(QString("aaatest"), settings));
|
profileSettings["Connection"] = QString("dummy");
|
||||||
|
profileSettings["Description"] = QString("\"Second simple test profile\"");
|
||||||
|
profileSettings["IP"] = QString("no");
|
||||||
|
profileSettings["IP6"] = QString("no");
|
||||||
|
profileSettings["Interface"] = QString("ngtest");
|
||||||
|
netctl->copyProfile(netctl->createProfile(QString("netctlgui-test-dummy-snd"), profileSettings));
|
||||||
delete netctl;
|
delete netctl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestNetctl::removeTestProfile()
|
void TestNetctl::removeTestProfile()
|
||||||
{
|
{
|
||||||
QMap<QString, QString> settings = NetctlProfile::getRecommendedConfiguration();
|
NetctlProfile *netctl = createNetctlProfileObj();
|
||||||
settings[QString("FORCE_SUDO")] = QString("true");
|
netctl->removeProfile(QString("netctlgui-test-dummy"));
|
||||||
NetctlProfile *netctl = new NetctlProfile(false, settings);
|
netctl->removeProfile(QString("netctlgui-test-dummy-snd"));
|
||||||
|
|
||||||
netctl->removeProfile(QString("aaatest"));
|
|
||||||
delete netctl;
|
delete netctl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,21 +95,31 @@ void TestNetctl::test_getRecommendedConfiguration()
|
|||||||
for (int i=0; i<resultMap.keys().count(); i++)
|
for (int i=0; i<resultMap.keys().count(); i++)
|
||||||
result.append(resultMap.keys()[i] + QString("==") + resultMap[resultMap.keys()[i]]);
|
result.append(resultMap.keys()[i] + QString("==") + resultMap[resultMap.keys()[i]]);
|
||||||
|
|
||||||
|
QWARN("This test may fail on other configuration");
|
||||||
QCOMPARE(result, original);
|
QCOMPARE(result, original);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TestNetctl::test_getActiveProfile()
|
void TestNetctl::test_getActiveProfile()
|
||||||
{
|
{
|
||||||
QMap<QString, QString> settings = Netctl::getRecommendedConfiguration();
|
Netctl *netctl = createNetctlObj();
|
||||||
settings[QString("FORCE_SUDO")] = QString("true");
|
|
||||||
Netctl *netctl = new Netctl(false, settings);
|
|
||||||
|
|
||||||
createTestProfile();
|
createTestProfile();
|
||||||
netctl->startProfile(QString("aaatest"));
|
netctl->startProfile(QString("netctlgui-test-dummy"));
|
||||||
QString original = QString("aaatest");
|
QStringList result = netctl->getActiveProfile();
|
||||||
QString result = netctl->getActiveProfile();
|
netctl->startProfile(QString("netctlgui-test-dummy"));
|
||||||
netctl->startProfile(QString("aaatest"));
|
removeTestProfile();
|
||||||
|
delete netctl;
|
||||||
|
|
||||||
|
QVERIFY(result.contains(QString("netctlgui-test-dummy")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestNetctl::test_getProfileDescription()
|
||||||
|
{
|
||||||
|
Netctl *netctl = createNetctlObj();
|
||||||
|
createTestProfile();
|
||||||
|
QString original = QString("Simple test profile");
|
||||||
|
QString result = netctl->getProfileDescription(QString("netctlgui-test-dummy"));
|
||||||
removeTestProfile();
|
removeTestProfile();
|
||||||
delete netctl;
|
delete netctl;
|
||||||
|
|
||||||
@ -97,4 +127,93 @@ void TestNetctl::test_getActiveProfile()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QTEST_MAIN(TestNetctl)
|
void TestNetctl::test_getProfileStatus()
|
||||||
|
{
|
||||||
|
Netctl *netctl = createNetctlObj();
|
||||||
|
createTestProfile();
|
||||||
|
QStringList original;
|
||||||
|
original.append(QString("inactive (static)"));
|
||||||
|
original.append(QString("active (static)"));
|
||||||
|
original.append(QString("active (enabled)"));
|
||||||
|
original.append(QString("inactive (enabled)"));
|
||||||
|
original.append(QString("inactive (static)"));
|
||||||
|
QStringList result;
|
||||||
|
result.append(netctl->getProfileStatus(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->startProfile(QString("netctlgui-test-dummy"));
|
||||||
|
result.append(netctl->getProfileStatus(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->enableProfile(QString("netctlgui-test-dummy"));
|
||||||
|
result.append(netctl->getProfileStatus(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->startProfile(QString("netctlgui-test-dummy"));
|
||||||
|
result.append(netctl->getProfileStatus(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->enableProfile(QString("netctlgui-test-dummy"));
|
||||||
|
result.append(netctl->getProfileStatus(QString("netctlgui-test-dummy")));
|
||||||
|
removeTestProfile();
|
||||||
|
delete netctl;
|
||||||
|
|
||||||
|
QCOMPARE(result, original);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestNetctl::test_isProfileActive()
|
||||||
|
{
|
||||||
|
Netctl *netctl = createNetctlObj();
|
||||||
|
createTestProfile();
|
||||||
|
QVERIFY(!netctl->isProfileActive(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->startProfile(QString("netctlgui-test-dummy"));
|
||||||
|
QVERIFY(netctl->isProfileActive(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->startProfile(QString("netctlgui-test-dummy"));
|
||||||
|
|
||||||
|
removeTestProfile();
|
||||||
|
delete netctl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestNetctl::test_isProfileEnabled()
|
||||||
|
{
|
||||||
|
Netctl *netctl = createNetctlObj();
|
||||||
|
createTestProfile();
|
||||||
|
QVERIFY(!netctl->isProfileEnabled(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->enableProfile(QString("netctlgui-test-dummy"));
|
||||||
|
QVERIFY(netctl->isProfileEnabled(QString("netctlgui-test-dummy")));
|
||||||
|
netctl->enableProfile(QString("netctlgui-test-dummy"));
|
||||||
|
|
||||||
|
removeTestProfile();
|
||||||
|
delete netctl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestNetctl::test_reenableProfile()
|
||||||
|
{
|
||||||
|
Netctl *netctl = createNetctlObj();
|
||||||
|
createTestProfile();
|
||||||
|
QVERIFY(!netctl->isProfileEnabled(QString("netctlgui-test-dummy")));
|
||||||
|
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")));
|
||||||
|
netctl->enableProfile(QString("netctlgui-test-dummy"));
|
||||||
|
|
||||||
|
removeTestProfile();
|
||||||
|
delete netctl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TestNetctl::test_restartProfile()
|
||||||
|
{
|
||||||
|
Netctl *netctl = createNetctlObj();
|
||||||
|
createTestProfile();
|
||||||
|
QVERIFY(!netctl->isProfileActive(QString("netctlgui-test-dummy")));
|
||||||
|
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")));
|
||||||
|
netctl->startProfile(QString("netctlgui-test-dummy"));
|
||||||
|
|
||||||
|
removeTestProfile();
|
||||||
|
delete netctl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: unfortunately, some functions which is required to work
|
||||||
|
// with the working profile isn't tested here
|
||||||
|
QTEST_MAIN(TestNetctl);
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
|
class Netctl;
|
||||||
|
class NetctlProfile;
|
||||||
|
|
||||||
class TestNetctl : public QObject
|
class TestNetctl : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -28,8 +31,16 @@ class TestNetctl : public QObject
|
|||||||
private slots:
|
private slots:
|
||||||
void test_getRecommendedConfiguration();
|
void test_getRecommendedConfiguration();
|
||||||
void test_getActiveProfile();
|
void test_getActiveProfile();
|
||||||
|
void test_getProfileDescription();
|
||||||
|
void test_getProfileStatus();
|
||||||
|
void test_isProfileActive();
|
||||||
|
void test_isProfileEnabled();
|
||||||
|
void test_reenableProfile();
|
||||||
|
void test_restartProfile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Netctl *createNetctlObj();
|
||||||
|
NetctlProfile *createNetctlProfileObj();
|
||||||
void createTestProfile();
|
void createTestProfile();
|
||||||
void removeTestProfile();
|
void removeTestProfile();
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user