From 4cc9d0ec1111cb5d1ae556de92f7034c2306f190 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sun, 17 Aug 2014 11:05:49 +0400 Subject: [PATCH] more pretty tests --- sources/CMakeLists.txt | 1 + sources/test/CMakeLists.txt | 30 ++++++++---- sources/test/testnetctl.cpp | 20 ++++---- sources/test/testnetctl.h | 3 ++ sources/test/testnetctlauto.cpp | 86 +++++++++++++++++++++++++++++++++ sources/test/testnetctlauto.h | 44 +++++++++++++++++ 6 files changed, 165 insertions(+), 19 deletions(-) create mode 100644 sources/test/testnetctlauto.cpp create mode 100644 sources/test/testnetctlauto.h diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 9ef5b4b..87abcc3 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -71,6 +71,7 @@ if (BUILD_HELPER) add_subdirectory (helper) endif () if (BUILD_TEST) + enable_testing () add_subdirectory (test) endif () if (BUILD_GUI) diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt index abe1114..61011b1 100644 --- a/sources/test/CMakeLists.txt +++ b/sources/test/CMakeLists.txt @@ -1,5 +1,3 @@ -enable_testing () - # set project name set (SUBPROJECT netctlgui-test) message (STATUS "Subproject ${SUBPROJECT}") @@ -9,11 +7,14 @@ set (SUBPROJECT_BINARY_DIR bin) # additional targets set (TARGETS "") -set (HEADERS "") # set files -file (GLOB SOURCES *.cpp) -file (GLOB HEADERS *.h) +# netctl +set (NETCTL_HEADERS testnetctl.h) +set (NETCTL_SOURCES testnetctl.cpp) +# netctl-auto +set (NETCTLAUTO_HEADERS testnetctlauto.h) +set (NETCTLAUTO_SOURCES testnetctlauto.cpp) # include_path include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/include/ @@ -30,16 +31,25 @@ if (USE_QT5) add_definitions(${Qt5Test_DEFINITIONS}) include_directories (${Qt5Core_INCLUDE_DIRS} ${Qt5Test_INCLUDE_DIRS}) set (QT_NEEDED_LIBS ${Qt5Core_LIBRARIES} ${Qt5Test_LIBRARIES}) - qt5_wrap_cpp (MOC_SOURCES ${HEADERS}) + qt5_wrap_cpp (NETCTL_MOC_SOURCES ${NETCTL_HEADERS}) + qt5_wrap_cpp (NETCTLAUTO_MOC_SOURCES ${NETCTLAUTO_HEADERS}) else () find_package (Qt4 COMPONENTS QtCore QtTest REQUIRED) include (${QT_USE_FILE}) set (QT_NEEDED_LIBS ${QT_QTCORE_LIBRARY} ${QT_QTTEST_LIBRARY}) - qt4_wrap_cpp (MOC_SOURCES ${HEADERS}) + qt4_wrap_cpp (NETCTL_MOC_SOURCES ${NETCTL_HEADERS}) + qt4_wrap_cpp (NETCTLAUTO_MOC_SOURCES ${NETCTLAUTO_HEADERS}) endif() -add_executable (${SUBPROJECT} ${HEADERS} ${SOURCES} ${MOC_SOURCES}) -target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS}) +# netctl +add_executable (${SUBPROJECT}-netctl ${NETCTL_HEADERS} ${NETCTL_SOURCES} ${NETCTL_MOC_SOURCES}) +target_link_libraries (${SUBPROJECT}-netctl ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS}) +# netctl-auto +add_executable (${SUBPROJECT}-netctlauto ${NETCTLAUTO_HEADERS} ${NETCTLAUTO_SOURCES} ${NETCTLAUTO_MOC_SOURCES}) +target_link_libraries (${SUBPROJECT}-netctlauto ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS}) # install properties -add_test (BaseTest ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}) +add_test (NAME Netctl COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-netctl + "-o" "../Testing/output-netctl.log") +add_test (NAME NetctlAuto COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}-netctlauto + "-o" "../Testing/output-netctlauto.log") diff --git a/sources/test/testnetctl.cpp b/sources/test/testnetctl.cpp index 10dfc74..1b967b6 100644 --- a/sources/test/testnetctl.cpp +++ b/sources/test/testnetctl.cpp @@ -27,6 +27,8 @@ Netctl *TestNetctl::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); return netctl; @@ -53,12 +55,6 @@ void TestNetctl::createTestProfile() profileSettings["IP6"] = QString("no"); profileSettings["Interface"] = QString("ngtest"); netctl->copyProfile(netctl->createProfile(QString("netctlgui-test-dummy"), profileSettings)); - 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; } @@ -67,11 +63,19 @@ void TestNetctl::removeTestProfile() { NetctlProfile *netctl = createNetctlProfileObj(); netctl->removeProfile(QString("netctlgui-test-dummy")); - netctl->removeProfile(QString("netctlgui-test-dummy-snd")); delete netctl; } +void TestNetctl::initTestCase() +{ + qDebug() << "netctlgui library tests"; + 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"); +} + + void TestNetctl::test_getRecommendedConfiguration() { QStringList original; @@ -214,6 +218,4 @@ void TestNetctl::test_restartProfile() } -// TODO: unfortunately, some functions which is required to work -// with the working profile isn't tested here QTEST_MAIN(TestNetctl); diff --git a/sources/test/testnetctl.h b/sources/test/testnetctl.h index d6ed4eb..90d1f2a 100644 --- a/sources/test/testnetctl.h +++ b/sources/test/testnetctl.h @@ -29,6 +29,9 @@ class TestNetctl : public QObject Q_OBJECT private slots: + // initialization + void initTestCase(); + // netctl void test_getRecommendedConfiguration(); void test_getActiveProfile(); void test_getProfileDescription(); diff --git a/sources/test/testnetctlauto.cpp b/sources/test/testnetctlauto.cpp new file mode 100644 index 0000000..144324c --- /dev/null +++ b/sources/test/testnetctlauto.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** + * This file is part of netctl-gui * + * * + * netctl-gui is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * netctl-gui is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + + +#include "testnetctlauto.h" + +#include + +#include + + +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); + + return netctl; +} + + +NetctlProfile *TestNetctlAuto::createNetctlProfileObj() +{ + QMap settings = NetctlProfile::getRecommendedConfiguration(); + settings[QString("FORCE_SUDO")] = QString("true"); + NetctlProfile *netctl = new NetctlProfile(false, settings); + + return netctl; +} + + +void TestNetctlAuto::createTestProfiles() +{ + NetctlProfile *netctl = createNetctlProfileObj(); + QMap profileSettings; + profileSettings["Connection"] = QString("dummy"); + profileSettings["Description"] = QString("\"Simple test profile\""); + profileSettings["IP"] = QString("no"); + profileSettings["IP6"] = QString("no"); + profileSettings["Interface"] = QString("ngtest"); + netctl->copyProfile(netctl->createProfile(QString("netctlgui-test-dummy"), profileSettings)); + 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; +} + + +void TestNetctlAuto::removeTestProfiles() +{ + NetctlProfile *netctl = createNetctlProfileObj(); + netctl->removeProfile(QString("netctlgui-test-dummy")); + netctl->removeProfile(QString("netctlgui-test-dummy-snd")); + delete netctl; +} + + +void TestNetctlAuto::initTestCase() +{ + qDebug() << "netctlgui library tests"; + 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"); +} + + +QTEST_MAIN(TestNetctlAuto); diff --git a/sources/test/testnetctlauto.h b/sources/test/testnetctlauto.h new file mode 100644 index 0000000..08c5cf2 --- /dev/null +++ b/sources/test/testnetctlauto.h @@ -0,0 +1,44 @@ +/*************************************************************************** + * This file is part of netctl-gui * + * * + * netctl-gui is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * netctl-gui is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef TESTNETCTLAUTO_H +#define TESTNETCTLAUTO_H + +#include + + +class Netctl; +class NetctlProfile; + +class TestNetctlAuto : public QObject +{ + Q_OBJECT + +private slots: + // initialization + void initTestCase(); + // netctl-auto + +private: + Netctl *createNetctlObj(); + NetctlProfile *createNetctlProfileObj(); + void createTestProfiles(); + void removeTestProfiles(); +}; + + +#endif /* TESTNETCTLAUTO_H */