more pretty tests

This commit is contained in:
arcan1s 2014-08-17 11:05:49 +04:00
parent a7911d48d1
commit 4cc9d0ec11
6 changed files with 165 additions and 19 deletions

View File

@ -71,6 +71,7 @@ if (BUILD_HELPER)
add_subdirectory (helper)
endif ()
if (BUILD_TEST)
enable_testing ()
add_subdirectory (test)
endif ()
if (BUILD_GUI)

View File

@ -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")

View File

@ -27,6 +27,8 @@ Netctl *TestNetctl::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);
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);

View File

@ -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();

View File

@ -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 <QtTest>
#include <netctlgui/netctlgui.h>
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);
return netctl;
}
NetctlProfile *TestNetctlAuto::createNetctlProfileObj()
{
QMap<QString, QString> settings = NetctlProfile::getRecommendedConfiguration();
settings[QString("FORCE_SUDO")] = QString("true");
NetctlProfile *netctl = new NetctlProfile(false, settings);
return netctl;
}
void TestNetctlAuto::createTestProfiles()
{
NetctlProfile *netctl = createNetctlProfileObj();
QMap<QString, QString> 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);

View File

@ -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 <QObject>
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 */