diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index ed2ecef..9ef5b4b 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -28,12 +28,16 @@ option (BUILD_HELPER "Build helper" ON) option (BUILD_LIBRARY "Build library" ON) option (BUILD_DATAENGINE "Build data engine" ON) option (BUILD_PLASMOID "Build plasmoid" ON) +option (BUILD_TEST "Build unit test for the library" OFF) if (BUILD_GUI OR BUILD_HELPER) set (BUILD_LIBRARY ON) endif () if (BUILD_PLASMOID) set (BUILD_DATAENGINE ON) endif () +if (BUILD_TEST) + set (BUILD_LIBRARY ON) +endif () # documentation option (BUILD_DOCS "Build documentation and install headers" ON) if (BUILD_DOCS) @@ -66,6 +70,9 @@ endif () if (BUILD_HELPER) add_subdirectory (helper) endif () +if (BUILD_TEST) + add_subdirectory (test) +endif () if (BUILD_GUI) add_subdirectory (gui) endif () diff --git a/sources/gui/src/dbusoperation.cpp b/sources/gui/src/dbusoperation.cpp index bd0420c..5d72103 100644 --- a/sources/gui/src/dbusoperation.cpp +++ b/sources/gui/src/dbusoperation.cpp @@ -89,13 +89,13 @@ QList sendDBusRequest(const QString service, const QString path, QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); if (!args.isEmpty()) request.setArguments(args); - response = bus.call(request); + response = bus.call(request, QDBus::BlockWithGui); } else { QDBusConnection bus = QDBusConnection::sessionBus(); QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); if (!args.isEmpty()) request.setArguments(args); - response = bus.call(request); + response = bus.call(request, QDBus::BlockWithGui); } arguments = response.arguments(); if (arguments.size() == 0) diff --git a/sources/plasmoid/netctl.cpp b/sources/plasmoid/netctl.cpp index 3a52cc8..52c862b 100644 --- a/sources/plasmoid/netctl.cpp +++ b/sources/plasmoid/netctl.cpp @@ -628,7 +628,7 @@ QList Netctl::sendDBusRequest(const QString cmd, const QList DBUS_HELPER_INTERFACE, cmd); if (!args.isEmpty()) request.setArguments(args); - QDBusMessage response = bus.call(request); + QDBusMessage response = bus.call(request, QDBus::BlockWithGui); QList arguments = response.arguments(); if (arguments.size() == 0) if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage(); diff --git a/sources/test/CMakeLists.txt b/sources/test/CMakeLists.txt new file mode 100644 index 0000000..60aadd3 --- /dev/null +++ b/sources/test/CMakeLists.txt @@ -0,0 +1,45 @@ +enable_testing () + +# set project name +set (SUBPROJECT netctlgui-test) +message (STATUS "Subproject ${SUBPROJECT}") + +# set directories +set (SUBPROJECT_BINARY_DIR bin) + +# additional targets +set (TARGETS "") +set (HEADERS "") + +# set files +file (GLOB SOURCES *.cpp) +file (GLOB HEADERS *.h) + +# include_path +include_directories (${CMAKE_CURRENT_SOURCE_DIR}/../../${PROJECT_LIBRARY}/include/ + ${CMAKE_CURRENT_BINARY_DIR}/../ + ${CMAKE_SOURCE_DIR} + ${CMAKE_BINARY_DIR} + ${CMAKE_CURRENT_BINARY_DIR}) +link_directories (${PROJECT_LIBRARY}/src/lib) + +if (USE_QT5) + find_package(Qt5Core 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}) + qt5_wrap_cpp (MOC_SOURCES ${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}) +endif() + +add_executable (${SUBPROJECT} ${HEADERS} ${SOURCES} ${MOC_SOURCES}) +target_link_libraries (${SUBPROJECT} ${PROJECT_LIBRARY} ${QT_NEEDED_LIBS}) +# install properties +add_test (BaseTest ${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT}) + diff --git a/sources/test/testnetctl.cpp b/sources/test/testnetctl.cpp new file mode 100644 index 0000000..8f744a1 --- /dev/null +++ b/sources/test/testnetctl.cpp @@ -0,0 +1,63 @@ +/*************************************************************************** + * 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 "testnetctl.h" + +#include + +#include + + +void TestNetctl::test_getRecommendedConfiguration() +{ + QStringList original; +// original.append(QString("CTRL_DIR==/run/wpa_supplicant_netctl-gui")); +// original.append(QString("CTRL_GROUP==network")); + original.append(QString("FORCE_SUDO==false")); + original.append(QString("IFACE_DIR==/sys/class/net")); + original.append(QString("NETCTLAUTO_PATH==/usr/bin/netctl-auto")); + original.append(QString("NETCTLAUTO_SERVICE==netctl-auto")); + original.append(QString("NETCTL_PATH==/usr/bin/netctl")); +// original.append(QString("PID_FILE==/run/wpa_supplicant_netctl-gui.pid")); + original.append(QString("PREFERED_IFACE==wifi0")); + original.append(QString("PROFILE_DIR==/etc/netctl")); + original.append(QString("SUDO_PATH==/usr/bin/sudo")); + original.append(QString("SYSTEMCTL_PATH==/usr/bin/systemctl")); +// original.append(QString("WPACLI_PATH==/usr/bin/wpa_cli")); +// original.append(QString("WPASUP_PATH==/usr/bin/wpa_supplicant")); +// original.append(QString("WPA_DRIVERS==nl80211,wext")); + QMap resultMap = Netctl::getRecommendedConfiguration(); + QStringList result; + for (int i=0; i settings = Netctl::getRecommendedConfiguration(); + settings[QString("FORCE_SUDO")] = QString("true"); + Netctl *netctl = new Netctl(false, settings); + + delete netctl; +} + + +QTEST_MAIN(TestNetctl) diff --git a/sources/test/testnetctl.h b/sources/test/testnetctl.h new file mode 100644 index 0000000..1166293 --- /dev/null +++ b/sources/test/testnetctl.h @@ -0,0 +1,34 @@ +/*************************************************************************** + * 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 TESTNETCTL_H +#define TESTNETCTL_H + +#include + + +class TestNetctl : public QObject +{ + Q_OBJECT + +private slots: + void test_getRecommendedConfiguration(); + void test_getActiveProfile(); +}; + + +#endif /* TESTNETCTL_H */