connectivity-api-0.0.1+14.04.20140312/ 0000755 0000152 0177776 00000000000 12307723764 017401 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/ 0000755 0000152 0177776 00000000000 12307723764 021024 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ 0000755 0000152 0177776 00000000000 12307723764 021602 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/ 0000755 0000152 0177776 00000000000 12307723764 023124 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/ 0000755 0000152 0177776 00000000000 12307723764 025642 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/ 0000755 0000152 0177776 00000000000 12307723764 030031 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/link.h 0000644 0000152 0177776 00000006032 12307723555 031136 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_LINK
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_LINK
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
#ifndef CONNECTIVITY_CPP_EXPORT
#define CONNECTIVITY_CPP_EXPORT __attribute ((visibility ("default")))
#endif
class CONNECTIVITY_CPP_EXPORT
Link
{
public:
typedef std::shared_ptr Ptr;
Link(const Link&) = delete;
virtual ~Link() = default;
Link& operator=(const Link&) = delete;
bool operator==(const Link&) const = delete;
/// @private
enum class Type
{
wifi,
wired,
wwan,
service
};
/// @private
enum class Status
{
disabled,
offline,
connecting, // link is in process of becoming online
connected, // the link is up, but not fully configured yet
// happens with wifi for example when captive portal
// login is required
online
};
/**
* @brief Characteristics of the link.
* \see Manager::characteristics
*/
enum Characteristics : std::uint32_t
{
/** No special characteristics. */
empty = 0,
/**
* The link has monetary costs,
* No data should be transfered before getting confirmation from the user.
*/
has_monetary_costs = 1 << 0,
/**
* The link has limited volume.
* No large files should be transfered before getting a confirmation from the user.
*/
is_volume_limited = 1 << 1,
/**
* The link has limited bandwith.
* Large transfer should be postponed until high bandwith link becomes available.
*/
is_bandwidth_limited = 1 << 2
};
/// @private
virtual void enable() = 0;
/// @private
virtual void disable() = 0;
/// @private
virtual Type type() const = 0;
/// @private
virtual const core::Property& characteristics() = 0;
/// @private
virtual const core::Property& status() = 0;
/// @private
typedef unsigned int Id;
/// @private
virtual Id id() const = 0;
/// @private
virtual std::string name() const = 0;
protected:
/// @private
Link() = default;
};
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/manager.h 0000644 0000152 0177776 00000007772 12307723555 031627 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_MANAGER
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_MANAGER
#include
#include
#include
#include
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
#ifndef CONNECTIVITY_CPP_EXPORT
#define CONNECTIVITY_CPP_EXPORT __attribute ((visibility ("default")))
#endif
/**
* @brief networking manager
*
* This is the top-level manager class for accessing networking information.
*
* A new instance of this class can only be created using the static Manager::createInstance().
*
* For system networking status, see Manager::status.
* For connection characteristics, see Manager::characteristics.
*
* Examples:
* - \ref networking-status "Getting the networking status."
*/
class CONNECTIVITY_CPP_EXPORT
Manager
{
public:
Manager &operator=(const Manager&) = delete;
virtual ~Manager() = default;
Manager(const Manager&) = delete;
/**
* @brief Creates a new instance of a networking Manager.
*
* \snippet example_networking_status.cpp create manager
*
* Applications should call this function just once.
* If application needs to share the instance internally the std::unique_ptr
* can be transformed into a std::shared_ptr:
* @code
* std::shared_ptr mgr{std::move(Manager::createInstance())};
* @endcode
*
* @note This call may block.
*
* @return std::unique_ptr to new instance of a networking manager.
*/
static std::unique_ptr createInstance();
/// @private
enum class FlightModeStatus {
on,
off
};
/**
* @brief enum class for networking status
*
* Networking status may be accessed through the Manager::status property.
*/
enum class NetworkingStatus {
/** No Internet connection available. */
offline,
/** System is actively establising a connection. */
connecting,
/** System is connected to the Internet. */
online
};
/// @private
virtual void enableFlightMode() = 0;
/// @private
virtual void disableFlightMode() = 0;
/// @private
virtual const core::Property& flightMode() = 0;
/// @private
virtual const core::Property>& links() = 0;
/// @private
virtual const core::Property>& services() = 0;
/**
* status of the overall system networking
*
* \snippet example_networking_status.cpp subscribe networking status changes
*/
virtual const core::Property &status() = 0;
/**
* characteristics of the overall system networking
*
* the value is a bitfield and the individial bits are defined
* in Link::Characteristics.
*
* \snippet example_networking_status.cpp subscribe characteristics changes
*/
virtual const core::Property& characteristics() = 0;
protected:
/**
* @brief The default constructor is protected.
*
* To create an instance of the networking manager call Manager::createInstance().
*
*/
Manager();
};
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/ 0000755 0000152 0177776 00000000000 12307723764 031471 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/vpn/ 0000755 0000152 0177776 00000000000 12307723764 032274 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011217 L ustar 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/vpn/service.h connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/vpn/service0000644 0000152 0177776 00000002472 12307723555 033662 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE_VPN_SERVICE
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE_VPN_SERVICE
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
namespace service {
namespace vpn {
/// @private
class
Service : public com::ubuntu::connectivity::networking::Service
{
public:
typedef std::shared_ptr Ptr;
virtual ~Service() = default;
virtual const core::Property> &establishedOver() = 0;
protected:
Service() = default;
};
}
}
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/tor/ 0000755 0000152 0177776 00000000000 12307723764 032275 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000147 00000000000 011217 L ustar 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/tor/service.h connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/tor/service0000644 0000152 0177776 00000002425 12307723555 033661 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE_TOR_SERVICE
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE_TOR_SERVICE
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
namespace service {
namespace tor {
/// @private
class
Service : public com::ubuntu::connectivity::networking::Service
{
public:
typedef std::shared_ptr Ptr;
virtual ~Service() = default;
virtual const core::Property> &establishedOver() = 0;
};
}
}
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/tethering/ 0000755 0000152 0177776 00000000000 12307723764 033462 5 ustar pbuser nogroup 0000000 0000000 ././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011216 L ustar 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/tethering/service.h connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service/tethering/s0000644 0000152 0177776 00000002766 12307723555 033660 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE_TETHERING_SERVICE
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE_TETHERING_SERVICE
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
namespace service {
namespace tethering {
/// @private
class
Service : public com::ubuntu::connectivity::networking::Service
{
public:
typedef std::shared_ptr Ptr;
virtual ~Service() = default;
/*
* Which link is shared to the client devices.
*/
const Property> &shared() = 0;
/*
* Which link is used to serve the clients.
*/
const Property> &sharedOver() = 0;
protected:
Service() = default;
};
}
}
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/wwan/ 0000755 0000152 0177776 00000000000 12307723764 031005 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/wwan/link.h 0000644 0000152 0177776 00000002711 12307723555 032112 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_WWAN_DEVICE
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_WWAN_DEVICE
#include
#include
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
namespace wwan {
#ifndef CONNECTIVITY_CPP_EXPORT
#define CONNECTIVITY_CPP_EXPORT __attribute ((visibility ("default")))
#endif
class CONNECTIVITY_CPP_EXPORT
Link : public com::ubuntu::connectivity::networking::Link
{
public:
typedef std::shared_ptr Ptr;
enum class Type {
GSM,
CDMA,
BLUETOOTH_DUN,
BLUETOOTH_PAN
};
virtual ~Link() {}
virtual State state() const = 0;
virtual Type wwanType() const = 0;
};
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/wifi/ 0000755 0000152 0177776 00000000000 12307723764 030767 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/wifi/link.h 0000644 0000152 0177776 00000003266 12307723555 032102 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_WIFI_LINK
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_WIFI_LINK
#include
#include
#include
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
namespace wifi {
#ifndef CONNECTIVITY_CPP_EXPORT
#define CONNECTIVITY_CPP_EXPORT __attribute ((visibility ("default")))
#endif
/// @private
class CONNECTIVITY_CPP_EXPORT
Link : public com::ubuntu::connectivity::networking::Link
{
public:
typedef std::shared_ptr Ptr;
typedef unsigned int Id;
Link() = default;
Link(const Link&) = delete;
virtual ~Link() = default;
virtual const core::Property>& accessPoints() = 0;
virtual void connect_to(AccessPoint::Ptr accessPoint) = 0;
virtual const core::Property& activeAccessPoint() = 0;
};
}
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/wifi/access-point.h0000644 0000152 0177776 00000002740 12307723555 033531 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_WIFI_ACCESS_POINT
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_WIFI_ACCESS_POINT
#include
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
namespace wifi {
#ifndef CONNECTIVITY_CPP_EXPORT
#define CONNECTIVITY_CPP_EXPORT __attribute ((visibility ("default")))
#endif
/// @private
class CONNECTIVITY_CPP_EXPORT
AccessPoint
{
public:
typedef std::shared_ptr Ptr;
virtual ~AccessPoint() = default;
/* from 0.00 to 100.00,
* -1 not available
*/
virtual const core::Property& strength() = 0;
virtual std::string ssid() = 0;
virtual bool secured() = 0;
virtual bool adhoc() = 0;
};
}
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/include/com/ubuntu/connectivity/networking/service.h 0000644 0000152 0177776 00000003755 12307723555 031652 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authors:
* Antti Kaijanmäki
*/
#ifndef COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE
#define COM_UBUNTU_CONNECTIVITY_NETWORKING_SERVICE
#include
#include
namespace com {
namespace ubuntu {
namespace connectivity {
namespace networking {
#ifndef CONNECTIVITY_CPP_EXPORT
#define CONNECTIVITY_CPP_EXPORT __attribute ((visibility ("default")))
#endif
/// @private
class CONNECTIVITY_CPP_EXPORT
Service
{
public:
typedef std::shared_ptr Ptr;
enum class Type {
vpn,
tethering,
tor
};
virtual Type type() const = 0;
enum class Status {
stopped,
starting,
running
};
virtual const core::Property& status() = 0;
// which other Service this service requires to be active
// before it can be activated
virtual std::shared_ptr requires() = 0;
// possible link this service provides.
// check with:
// if (service->link()) {
// // we have a link coming from the service
// do_something_with(link);
// }
virtual Link::Ptr link() = 0;
virtual void start() = 0;
virtual void stop() = 0;
typedef unsigned int Id;
virtual Id id() const = 0;
virtual core::Property& name() = 0;
};
}
}
}
}
#endif
connectivity-api-0.0.1+14.04.20140312/cmake/ 0000755 0000152 0177776 00000000000 12307723764 020461 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/cmake/modules/ 0000755 0000152 0177776 00000000000 12307723764 022131 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/cmake/modules/Findgcovr.cmake 0000644 0000152 0177776 00000001702 12307723555 025052 0 ustar pbuser nogroup 0000000 0000000 # - Find gcovr scrip
# Will define:
#
# GCOVR_EXECUTABLE - the gcovr script
#
# Uses:
#
# GCOVR_ROOT - root to search for the script
#
# Copyright (C) 2011 by Johannes Wienke
#
# This program 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 2, or (at your option)
# any later version.
#
# This program 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.
#
INCLUDE(FindPackageHandleStandardArgs)
FIND_PROGRAM(GCOVR_EXECUTABLE gcovr HINTS ${GCOVR_ROOT} "${GCOVR_ROOT}/bin")
FIND_PACKAGE_HANDLE_STANDARD_ARGS(gcovr DEFAULT_MSG GCOVR_EXECUTABLE)
# only visible in advanced view
MARK_AS_ADVANCED(GCOVR_EXECUTABLE)
connectivity-api-0.0.1+14.04.20140312/cmake/modules/ParseArguments.cmake 0000644 0000152 0177776 00000003406 12307723555 026074 0 ustar pbuser nogroup 0000000 0000000 # Parse arguments passed to a function into several lists separated by
# upper-case identifiers and options that do not have an associated list e.g.:
#
# SET(arguments
# hello OPTION3 world
# LIST3 foo bar
# OPTION2
# LIST1 fuz baz
# )
# PARSE_ARGUMENTS(ARG "LIST1;LIST2;LIST3" "OPTION1;OPTION2;OPTION3" ${arguments})
#
# results in 7 distinct variables:
# * ARG_DEFAULT_ARGS: hello;world
# * ARG_LIST1: fuz;baz
# * ARG_LIST2:
# * ARG_LIST3: foo;bar
# * ARG_OPTION1: FALSE
# * ARG_OPTION2: TRUE
# * ARG_OPTION3: TRUE
#
# taken from http://www.cmake.org/Wiki/CMakeMacroParseArguments
MACRO(PARSE_ARGUMENTS prefix arg_names option_names)
SET(DEFAULT_ARGS)
FOREACH(arg_name ${arg_names})
SET(${prefix}_${arg_name})
ENDFOREACH(arg_name)
FOREACH(option ${option_names})
SET(${prefix}_${option} FALSE)
ENDFOREACH(option)
SET(current_arg_name DEFAULT_ARGS)
SET(current_arg_list)
FOREACH(arg ${ARGN})
SET(larg_names ${arg_names})
LIST(FIND larg_names "${arg}" is_arg_name)
IF (is_arg_name GREATER -1)
SET(${prefix}_${current_arg_name} ${current_arg_list})
SET(current_arg_name ${arg})
SET(current_arg_list)
ELSE (is_arg_name GREATER -1)
SET(loption_names ${option_names})
LIST(FIND loption_names "${arg}" is_option)
IF (is_option GREATER -1)
SET(${prefix}_${arg} TRUE)
ELSE (is_option GREATER -1)
SET(current_arg_list ${current_arg_list} ${arg})
ENDIF (is_option GREATER -1)
ENDIF (is_arg_name GREATER -1)
ENDFOREACH(arg)
SET(${prefix}_${current_arg_name} ${current_arg_list})
ENDMACRO(PARSE_ARGUMENTS)
connectivity-api-0.0.1+14.04.20140312/cmake/modules/FindGtest.cmake 0000644 0000152 0177776 00000003372 12307723555 025025 0 ustar pbuser nogroup 0000000 0000000 include(ExternalProject)
include(FindPackageHandleStandardArgs)
#gtest
set(GTEST_INSTALL_DIR /usr/src/gmock/gtest/include)
find_path(GTEST_INCLUDE_DIR gtest/gtest.h
HINTS ${GTEST_INSTALL_DIR})
#gmock
find_path(GMOCK_INSTALL_DIR gmock/CMakeLists.txt
HINTS /usr/src)
if(${GMOCK_INSTALL_DIR} STREQUAL "GMOCK_INSTALL_DIR-NOTFOUND")
message(FATAL_ERROR "google-mock package not found")
endif()
set(GMOCK_INSTALL_DIR ${GMOCK_INSTALL_DIR}/gmock)
find_path(GMOCK_INCLUDE_DIR gmock/gmock.h)
set(GMOCK_PREFIX gmock)
set(GMOCK_BINARY_DIR ${CMAKE_BINARY_DIR}/${GMOCK_PREFIX}/libs)
set(GTEST_BINARY_DIR ${GMOCK_BINARY_DIR}/gtest)
set(GTEST_CMAKE_ARGS "")
if (${MIR_IS_CROSS_COMPILING})
set(GTEST_CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_MODULE_PATH}/LinuxCrossCompile.cmake)
endif()
ExternalProject_Add(
GMock
#where to build in source tree
PREFIX ${GMOCK_PREFIX}
#where the source is external to the project
SOURCE_DIR ${GMOCK_INSTALL_DIR}
#forward the compilers to the subproject so cross-arch builds work
CMAKE_ARGS ${GTEST_CMAKE_ARGS}
BINARY_DIR ${GMOCK_BINARY_DIR}
#we don't need to install, so skip
INSTALL_COMMAND ""
)
set(GMOCK_LIBRARY ${GMOCK_BINARY_DIR}/libgmock.a)
set(GMOCK_MAIN_LIBRARY ${GMOCK_BINARY_DIR}/libgmock_main.a)
set(GMOCK_BOTH_LIBRARIES ${GMOCK_LIBRARY} ${GMOCK_MAIN_LIBRARY})
set(GTEST_LIBRARY ${GTEST_BINARY_DIR}/libgtest.a)
set(GTEST_MAIN_LIBRARY ${GTEST_BINARY_DIR}/libgtest_main.a)
set(GTEST_BOTH_LIBRARIES ${GTEST_LIBRARY} ${GTEST_MAIN_LIBRARY})
set(GTEST_ALL_LIBRARIES ${GTEST_BOTH_LIBRARIES} ${GMOCK_BOTH_LIBRARIES})
find_package_handle_standard_args(GTest DEFAULT_MSG
GMOCK_INCLUDE_DIR
GTEST_INCLUDE_DIR)
connectivity-api-0.0.1+14.04.20140312/cmake/modules/FindLcov.cmake 0000644 0000152 0177776 00000001720 12307723555 024635 0 ustar pbuser nogroup 0000000 0000000 # - Find lcov
# Will define:
#
# LCOV_EXECUTABLE - the lcov binary
# GENHTML_EXECUTABLE - the genhtml executable
#
# Copyright (C) 2010 by Johannes Wienke
#
# This program 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 2, or (at your option)
# any later version.
#
# This program 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.
#
INCLUDE(FindPackageHandleStandardArgs)
FIND_PROGRAM(LCOV_EXECUTABLE lcov)
FIND_PROGRAM(GENHTML_EXECUTABLE genhtml)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Lcov DEFAULT_MSG LCOV_EXECUTABLE GENHTML_EXECUTABLE)
# only visible in advanced view
MARK_AS_ADVANCED(LCOV_EXECUTABLE GENHTML_EXECUTABLE)
connectivity-api-0.0.1+14.04.20140312/cmake/modules/EnableCoverageReport.cmake 0000644 0000152 0177776 00000015375 12307723555 027202 0 ustar pbuser nogroup 0000000 0000000 # - Creates a special coverage build type and target on GCC.
#
# Defines a function ENABLE_COVERAGE_REPORT which generates the coverage target
# for selected targets. Optional arguments to this function are used to filter
# unwanted results using globbing expressions. Moreover targets with tests for
# the source code can be specified to trigger regenerating the report if the
# test has changed
#
# ENABLE_COVERAGE_REPORT(TARGETS target... [FILTER filter...] [TESTS test targets...])
#
# To generate a coverage report first build the project with
# CMAKE_BUILD_TYPE=coverage, then call make test and afterwards make coverage.
#
# The coverage report is based on gcov. Depending on the availability of lcov
# a HTML report will be generated and/or an XML report of gcovr is found.
# The generated coverage target executes all found solutions. Special targets
# exist to create e.g. only the xml report: coverage-xml.
#
# Copyright (C) 2010 by Johannes Wienke
#
# This program 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 2, or (at your option)
# any later version.
#
# This program 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.
#
INCLUDE(ParseArguments)
FIND_PACKAGE(Lcov)
FIND_PACKAGE(gcovr)
FUNCTION(ENABLE_COVERAGE_REPORT)
# argument parsing
PARSE_ARGUMENTS(ARG "FILTER;TARGETS;TESTS" "" ${ARGN})
SET(COVERAGE_RAW_FILE "${CMAKE_BINARY_DIR}/coverage.raw.info")
SET(COVERAGE_FILTERED_FILE "${CMAKE_BINARY_DIR}/coverage.info")
SET(COVERAGE_REPORT_DIR "${CMAKE_BINARY_DIR}/coveragereport")
SET(COVERAGE_XML_FILE "${CMAKE_BINARY_DIR}/coverage.xml")
SET(COVERAGE_XML_COMMAND_FILE "${CMAKE_BINARY_DIR}/coverage-xml.cmake")
# decide if there is any tool to create coverage data
SET(TOOL_FOUND FALSE)
IF(LCOV_FOUND OR GCOVR_FOUND)
SET(TOOL_FOUND TRUE)
ENDIF()
IF(NOT TOOL_FOUND)
MESSAGE(STATUS "Cannot enable coverage targets because neither lcov nor gcovr are found.")
ENDIF()
STRING(TOLOWER "${CMAKE_BUILD_TYPE}" COVERAGE_BUILD_TYPE)
IF(CMAKE_COMPILER_IS_GNUCXX AND TOOL_FOUND AND "${COVERAGE_BUILD_TYPE}" MATCHES "coverage")
MESSAGE(STATUS "Coverage support enabled for targets: ${ARG_TARGETS}")
# create coverage build type
SET(CMAKE_CXX_FLAGS_COVERAGE ${CMAKE_CXX_FLAGS_DEBUG} PARENT_SCOPE)
SET(CMAKE_C_FLAGS_COVERAGE ${CMAKE_C_FLAGS_DEBUG} PARENT_SCOPE)
SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_CONFIGURATION_TYPES} coverage PARENT_SCOPE)
# instrument targets
SET_TARGET_PROPERTIES(${ARG_TARGETS} PROPERTIES COMPILE_FLAGS --coverage
LINK_FLAGS --coverage)
# html report
IF (LCOV_FOUND)
MESSAGE(STATUS "Enabling HTML coverage report")
# set up coverage target
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_RAW_FILE}
COMMAND ${LCOV_EXECUTABLE} -c -d ${CMAKE_BINARY_DIR} -o ${COVERAGE_RAW_FILE}
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Collecting coverage data"
DEPENDS ${ARG_TARGETS} ${ARG_TESTS}
VERBATIM)
# filter unwanted stuff
LIST(LENGTH ARG_FILTER FILTER_LENGTH)
IF(${FILTER_LENGTH} GREATER 0)
SET(FILTER COMMAND ${LCOV_EXECUTABLE})
FOREACH(F ${ARG_FILTER})
SET(FILTER ${FILTER} -r ${COVERAGE_FILTERED_FILE} ${F})
ENDFOREACH()
SET(FILTER ${FILTER} -o ${COVERAGE_FILTERED_FILE})
ELSE()
SET(FILTER "")
ENDIF()
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_FILTERED_FILE}
COMMAND ${LCOV_EXECUTABLE} -e ${COVERAGE_RAW_FILE} "${CMAKE_SOURCE_DIR}*" -o ${COVERAGE_FILTERED_FILE}
${FILTER}
DEPENDS ${COVERAGE_RAW_FILE}
COMMENT "Filtering recorded coverage data for project-relevant entries"
VERBATIM)
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_REPORT_DIR}
COMMAND ${CMAKE_COMMAND} -E make_directory ${COVERAGE_REPORT_DIR}
COMMAND ${GENHTML_EXECUTABLE} --legend --show-details -t "${PROJECT_NAME} test coverage" -o ${COVERAGE_REPORT_DIR} ${COVERAGE_FILTERED_FILE}
DEPENDS ${COVERAGE_FILTERED_FILE}
COMMENT "Generating HTML coverage report in ${COVERAGE_REPORT_DIR}"
VERBATIM)
ADD_CUSTOM_TARGET(coverage-html
DEPENDS ${COVERAGE_REPORT_DIR})
ENDIF()
# xml coverage report
IF(GCOVR_FOUND)
MESSAGE(STATUS "Enabling XML coverage report")
# gcovr cannot write directly to a file so the execution needs to
# be wrapped in a cmake file that generates the file output
FILE(WRITE ${COVERAGE_XML_COMMAND_FILE}
"SET(ENV{LANG} en)\n")
FILE(APPEND ${COVERAGE_XML_COMMAND_FILE}
"EXECUTE_PROCESS(COMMAND \"${GCOVR_EXECUTABLE}\" --exclude=tests.* --exclude=obj-.* --exclude=cmake.* -x -r \"${CMAKE_SOURCE_DIR}\" OUTPUT_FILE \"${COVERAGE_XML_FILE}\" WORKING_DIRECTORY \"${CMAKE_BINARY_DIR}\")\n")
ADD_CUSTOM_COMMAND(OUTPUT ${COVERAGE_XML_FILE}
COMMAND ${CMAKE_COMMAND} ARGS -P ${COVERAGE_XML_COMMAND_FILE}
COMMENT "Generating coverage XML report"
VERBATIM)
ADD_CUSTOM_TARGET(coverage-xml
DEPENDS ${COVERAGE_XML_FILE})
ENDIF()
# provide a global coverage target executing both steps if available
SET(GLOBAL_DEPENDS "")
IF(LCOV_FOUND)
LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_REPORT_DIR})
ENDIF()
IF(GCOVR_FOUND)
LIST(APPEND GLOBAL_DEPENDS ${COVERAGE_XML_FILE})
ENDIF()
IF(LCOV_FOUND OR GCOVR_FOUND)
ADD_CUSTOM_TARGET(coverage
DEPENDS ${GLOBAL_DEPENDS})
ENDIF()
ENDIF()
ENDFUNCTION()
connectivity-api-0.0.1+14.04.20140312/tests/ 0000755 0000152 0177776 00000000000 12307723764 020543 5 ustar pbuser nogroup 0000000 0000000 connectivity-api-0.0.1+14.04.20140312/tests/CMakeLists.txt 0000644 0000152 0177776 00000005741 12307723555 023310 0 ustar pbuser nogroup 0000000 0000000 # Copyright © 2013 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License version 3,
# as published by the Free Software Foundation.
#
# This program 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see .
#
# Authors:
# Antti Kaijanmäki
set (OLD_CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
# Don't treat warnings as errors in 3rd_party/{gmock,cucumber-cpp}
string (REPLACE " -Werror " " " CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR})
set (CMAKE_CXX_FLAGS ${OLD_CMAKE_CXX_FLAGS})
if (NOT DEFINED GTEST_ROOT)
set(GTEST_ROOT /usr/src/gtest)
endif()
set(GTEST_SRC_DIR "${GTEST_ROOT}/src")
set(GTEST_INCLUDE_DIR ${GTEST_ROOT})
add_library(gtest STATIC
${GTEST_SRC_DIR}/gtest-all.cc
${GTEST_SRC_DIR}/gtest_main.cc
)
set_target_properties(gtest PROPERTIES INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR})
target_link_libraries(gtest ${CMAKE_THREAD_LIBS_INIT})
include_directories(${GTEST_INCLUDE_DIRS})
add_definitions(-DCORE_DBUS_ENABLE_GOOGLE_TEST_FIXTURE)
pkg_check_modules(PROCESS_CPP process-cpp)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/test_data.h.in
${CMAKE_CURRENT_BINARY_DIR}/test_data.h @ONLY
)
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
)
add_executable (
test_networking_status
test_networking_status.cpp
)
add_executable (
test_flight_mode
test_flight_mode.cpp
)
add_executable (
test_wifi_link
test_wifi_link.cpp
)
add_executable (
test_wifi_connect
test_wifi_connect.cpp
)
add_executable (
test_wifi_link_enable_disable
test_wifi_link_enable_disable.cpp
)
target_link_libraries(
test_networking_status
connectivity-cpp
gtest
${PROCESS_CPP_LIBRARIES}
)
target_link_libraries(
test_flight_mode
connectivity-cpp
gtest
${PROCESS_CPP_LIBRARIES}
)
target_link_libraries(
test_wifi_link
connectivity-cpp
gtest
${PROCESS_CPP_LIBRARIES}
)
target_link_libraries(
test_wifi_connect
connectivity-cpp
gtest
${PROCESS_CPP_LIBRARIES}
)
target_link_libraries(
test_wifi_link_enable_disable
connectivity-cpp
gtest
${PROCESS_CPP_LIBRARIES}
)
add_test(test_networking_status ${CMAKE_CURRENT_BINARY_DIR}/test_networking_status)
add_test(test_flight_mode ${CMAKE_CURRENT_BINARY_DIR}/test_flight_mode)
add_test(test_wifi_link ${CMAKE_CURRENT_BINARY_DIR}/test_wifi_link)
add_test(test_wifi_connect ${CMAKE_CURRENT_BINARY_DIR}/test_wifi_connect)
add_test(test_wifi_connect.cpp test_wifi_link_enable_disable ${CMAKE_CURRENT_BINARY_DIR}/test_wifi_connect.cpp test_wifi_link_enable_disable)
connectivity-api-0.0.1+14.04.20140312/tests/test_service.h 0000644 0000152 0177776 00000005326 12307723555 023417 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Thomas Voß
*/
#ifndef TEST_SERVICE_H_
#define TEST_SERVICE_H_
namespace test
{
struct Service
{
struct Method
{
typedef Service Interface;
inline static const std::string& name()
{
static const std::string s
{
"Method"
};
return s;
}
inline static const std::chrono::milliseconds default_timeout()
{
return std::chrono::seconds{1};
}
};
struct Signals
{
struct Dummy
{
inline static std::string name()
{
return "Dummy";
};
typedef Service Interface;
typedef int64_t ArgumentType;
};
};
struct Properties
{
struct Dummy
{
inline static std::string name()
{
return "Dummy";
};
typedef Service Interface;
typedef double ValueType;
static const bool readable = true;
static const bool writable = true;
};
};
struct Interfaces
{
struct Foo
{
static const std::string& name()
{
static const std::string s{"this.is.unlikely.to.exist.Service.Foo"};
return s;
}
struct Signals
{
struct Dummy
{
inline static std::string name()
{
return "Dummy";
}
typedef Foo Interface;
typedef int64_t ArgumentType;
};
};
};
};
};
}
#include
namespace core
{
namespace dbus
{
namespace traits
{
template<>
struct Service
{
inline static const std::string& interface_name()
{
static const std::string s
{
"this.is.unlikely.to.exist.Service"
};
return s;
}
};
}
}
}
#endif // TEST_SERVICE_H_
connectivity-api-0.0.1+14.04.20140312/tests/test_networking_status.cpp 0000644 0000152 0177776 00000016427 12307723555 026110 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Antti Kaijanmäki
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "sig_term_catcher.h"
#include "test_data.h"
#include "test_service.h"
#include
#include
#include
#include
#include
#include
#include
namespace fdo = org::freedesktop;
namespace NM = fdo::NetworkManager;
#include
namespace cuc = com::ubuntu::connectivity;
namespace dbus = core::dbus;
namespace
{
struct Service : public core::dbus::testing::Fixture {};
auto session_bus_config_file =
core::dbus::testing::Fixture::default_session_bus_config_file() =
core::testing::session_bus_configuration_file();
auto system_bus_config_file =
core::dbus::testing::Fixture::default_system_bus_config_file() =
core::testing::system_bus_configuration_file();
}
TEST_F(Service, networkingStatus)
{
core::testing::CrossProcessSync services_ready;
core::testing::CrossProcessSync client_ready;
core::testing::CrossProcessSync update_networking_status;
auto service = [&, this]()
{
core::testing::SigTermCatcher sc;
auto bus = system_bus();
bus->install_executor(core::dbus::asio::make_executor(bus));
auto nm_service = NM::Service::Mock(bus);
auto nm_root = nm_service.nm;
nm_root->object->install_method_handler([bus, nm_root](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << std::vector();
bus->send(reply);
});
nm_root->state->set(NM_STATE_UNKNOWN);
auto urfkill_service = fdo::URfkill::Service::Mock(bus);
auto urfkill_root = urfkill_service.urfkill;
urfkill_root->object->install_method_handler([bus](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << std::vector();
bus->send(reply);
});
std::thread t{[bus](){ bus->run(); }};
services_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
NM::Interface::NetworkManager::Signal::PropertiesChanged::ArgumentType properties;
properties["State"] = dbus::types::Variant::encode(NM_STATE_UNKNOWN);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_ASLEEP);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_DISCONNECTED);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_CONNECTING);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_CONNECTED_LOCAL);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_CONNECTED_SITE);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_CONNECTED_GLOBAL);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_DISCONNECTING);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_DISCONNECTED);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_CONNECTING);
nm_root->properties_changed->emit(properties);
properties["State"] = dbus::types::Variant::encode(NM_STATE_CONNECTED_GLOBAL);
nm_root->properties_changed->emit(properties);
// status change
update_networking_status.try_signal_ready_for(std::chrono::milliseconds{2000});
sc.wait_for_signal_for(std::chrono::seconds{10});
bus->stop();
if (t.joinable())
t.join();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
auto client = [&, this]()
{
EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
std::unique_ptr mgr;
mgr = cuc::networking::Manager::createInstance();
EXPECT_EQ(mgr->status().get(), cuc::networking::Manager::NetworkingStatus::offline);
std::vector states;
mgr->status().changed().connect([&states](cuc::networking::Manager::NetworkingStatus status) {
states.push_back(status);
});
client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
EXPECT_EQ(1, update_networking_status.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
sleep(1);
EXPECT_EQ(states.size(), 5);
EXPECT_EQ(states.at(0), cuc::networking::Manager::NetworkingStatus::connecting);
EXPECT_EQ(states.at(1), cuc::networking::Manager::NetworkingStatus::online);
EXPECT_EQ(states.at(2), cuc::networking::Manager::NetworkingStatus::offline);
EXPECT_EQ(states.at(3), cuc::networking::Manager::NetworkingStatus::connecting);
EXPECT_EQ(states.at(4), cuc::networking::Manager::NetworkingStatus::online);
delete mgr.release();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
}
connectivity-api-0.0.1+14.04.20140312/tests/test_wifi_connect.cpp 0000644 0000152 0177776 00000027523 12307723555 024764 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Antti Kaijanmäki
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "sig_term_catcher.h"
#include "test_data.h"
#include "test_service.h"
#include
#include
#include
#include
#include
#include
#include
namespace fdo = org::freedesktop;
namespace NM = fdo::NetworkManager;
#include
#include
#include
namespace cuc = com::ubuntu::connectivity;
namespace dbus = core::dbus;
namespace
{
struct Service : public core::dbus::testing::Fixture {};
auto session_bus_config_file =
core::dbus::testing::Fixture::default_session_bus_config_file() =
core::testing::session_bus_configuration_file();
auto system_bus_config_file =
core::dbus::testing::Fixture::default_system_bus_config_file() =
core::testing::system_bus_configuration_file();
}
TEST_F(Service, wifiLink)
{
core::testing::CrossProcessSync services_ready;
core::testing::CrossProcessSync client_ready;
core::testing::CrossProcessSync stage1;
core::testing::CrossProcessSync stage2;
auto service = [&, this]()
{
core::testing::SigTermCatcher sc;
auto bus = system_bus();
bus->install_executor(core::dbus::asio::make_executor(bus));
auto service = NM::Service::Mock(bus);
auto nm_root = service.nm;
auto wifi_dev = NM::Interface::Device(nm_root->service,
nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")));
auto ap1 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/1")));
auto ap2 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/2")));
auto wrong_settings = NM::Interface::Connection(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Settings/1")));
auto correct_settings = NM::Interface::Connection(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Settings/2")));
wrong_settings.object->install_method_handler([&](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
std::map> conf;
std::map wireless_conf;
wireless_conf["ssid"] = dbus::types::Variant::encode>({0x64, 0x65, 0x66}); // def
conf["802-11-wireless"] = wireless_conf;
reply->writer() << conf;
bus->send(reply);
});
correct_settings.object->install_method_handler([&](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
std::map> conf;
std::map wireless_conf;
wireless_conf["ssid"] = dbus::types::Variant::encode>({0x61, 0x62, 0x63}); // abc
conf["802-11-wireless"] = wireless_conf;
reply->writer() << conf;
bus->send(reply);
});
nm_root->object->install_method_handler([bus, &wifi_dev](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
std::vector devices;
devices.push_back(wifi_dev.object->path());
reply->writer() << devices;
bus->send(reply);
});
NM::Interface::Device::Property::AvailableConnections::ValueType available_connections;
available_connections.push_back(wrong_settings.object->path());
available_connections.push_back(correct_settings.object->path());
wifi_dev.available_connections->set(available_connections);
nm_root->object->install_method_handler([&](const dbus::Message::Ptr& msg)
{
std::cout << "Server: Active Connection" << std::endl;
auto reader = msg->reader();
dbus::types::ObjectPath connection = reader.pop_object_path();
dbus::types::ObjectPath device = reader.pop_object_path();
dbus::types::ObjectPath specific_object = reader.pop_object_path();
EXPECT_EQ(connection, correct_settings.object->path());
EXPECT_EQ(device, wifi_dev.object->path());
EXPECT_EQ(specific_object, ap1.object->path());
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << dbus::types::ObjectPath("/"); /// @todo return an actual ActiveConnection at some point.
bus->send(reply);
});
nm_root->object->install_method_handler([&](const dbus::Message::Ptr& msg)
{
std::cout << "Server: Add and Active Connection" << std::endl;
auto reader = msg->reader();
std::map> connection;
reader >> connection;
dbus::types::ObjectPath device = reader.pop_object_path();
dbus::types::ObjectPath specific_object = reader.pop_object_path();
EXPECT_TRUE(connection.find("802-11-wireless") != connection.end());
auto wificonf = connection["802-11-wireless"];
EXPECT_TRUE(wificonf.find("ssid") != wificonf.end());
EXPECT_EQ(wificonf["ssid"].as>(), ap2.ssid->get());
EXPECT_EQ(device, wifi_dev.object->path());
EXPECT_EQ(specific_object, ap2.object->path());
auto reply = dbus::Message::make_method_return(msg);
auto ret = std::make_tuple(dbus::types::ObjectPath("/"), dbus::types::ObjectPath("/"));
reply->writer() << ret; /// @todo return actual Settings and ActiveConnection at some point.
bus->send(reply);
});
nm_root->state->set(NM_STATE_DISCONNECTED);
wifi_dev.device_type->set(NM_DEVICE_TYPE_WIFI);
std::vector aps;
wifi_dev.object->install_method_handler([bus, &aps](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << aps;
bus->send(reply);
});
auto ap_added = wifi_dev.object->get_signal();
auto ap_removed = wifi_dev.object->get_signal();
ap1.flags->set(NM_802_11_AP_FLAGS_PRIVACY);
ap1.mode->set(NM_802_11_MODE_INFRA);
ap1.ssid->set({0x61, 0x62, 0x63}); // abc
ap1.strength->set(90);
auto ap1_pc = ap1.properties_changed;
ap2.flags->set(NM_802_11_AP_FLAGS_NONE);
ap2.mode->set(NM_802_11_MODE_ADHOC);
ap2.ssid->set({0x31, 0x32, 0x33}); // 123
ap2.strength->set(60);
auto ap2_pc = ap2.properties_changed;
auto urfkill_service = fdo::URfkill::Service::Mock(bus);
auto urfkill_root = urfkill_service.urfkill;
urfkill_root->object->install_method_handler([bus](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << std::vector();
bus->send(reply);
});
std::thread t{[bus](){ bus->run(); }};
aps.push_back(ap1.object->path());
aps.push_back(ap2.object->path());
services_ready.try_signal_ready_for(std::chrono::milliseconds{5000});
EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
stage1.try_signal_ready_for(std::chrono::milliseconds{5000});
sleep(1);
stage2.try_signal_ready_for(std::chrono::milliseconds{5000});
sc.wait_for_signal_for(std::chrono::seconds{60});
bus->stop();
if (t.joinable())
t.join();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
auto client = [&, this]()
{
EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
std::unique_ptr mgr;
mgr = cuc::networking::Manager::createInstance();
auto links = mgr->links();
EXPECT_EQ(links->size(), 1);
EXPECT_EQ((*links->begin())->type(), cuc::networking::Link::Type::wifi);
auto wifilink = std::dynamic_pointer_cast(*links->begin());
EXPECT_TRUE(wifilink.get() != nullptr);
auto aps = wifilink->accessPoints().get();
EXPECT_EQ(aps.size(), 2);
std::shared_ptr ap_abc;
std::shared_ptr ap_123;
for (auto ap : aps) {
if (ap->ssid() == "abc")
ap_abc = ap;
if (ap->ssid() == "123")
ap_123 = ap;
}
EXPECT_TRUE(ap_abc.get() != nullptr);
EXPECT_TRUE(ap_123.get() != nullptr);
client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
wifilink->connect_to(ap_abc);
sleep(1);
EXPECT_EQ(1, stage1.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
wifilink->connect_to(ap_123);
sleep(1);
delete mgr.release();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
}
connectivity-api-0.0.1+14.04.20140312/tests/sig_term_catcher.h 0000644 0000152 0177776 00000004027 12307723555 024217 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Thomas Voß
*/
#ifndef CORE_TESTING_SIG_TERM_CATCHER_H_
#define CORE_TESTING_SIG_TERM_CATCHER_H_
#include
#include
#include
#include
#include
namespace core
{
namespace testing
{
struct SigTermCatcher
{
inline SigTermCatcher()
{
sigemptyset(&signal_mask);
if (-1 == sigaddset(&signal_mask, SIGTERM))
throw std::system_error(errno, std::system_category());
if (-1 == sigprocmask(SIG_BLOCK, &signal_mask, NULL))
throw std::system_error(errno, std::system_category());
if (-1 == (signal_fd = signalfd(-1, &signal_mask, 0)))
throw std::system_error(errno, std::system_category());
}
inline ~SigTermCatcher()
{
::close(signal_fd);
}
inline void wait_for_signal_for(const std::chrono::milliseconds& ms)
{
pollfd fd; fd.fd = signal_fd; fd.events = POLLIN;
if (poll(&fd, 1, ms.count()) > 0)
{
signalfd_siginfo siginfo;
if (-1 == ::read(signal_fd, &siginfo, sizeof(siginfo)))
throw std::system_error(errno, std::system_category());
} else
{
throw std::system_error(errno, std::system_category());
}
}
sigset_t signal_mask;
int signal_fd = -1;
};
}
}
#endif // CORE_TESTING_SIG_TERM_CATCHER_H_
connectivity-api-0.0.1+14.04.20140312/tests/test_flight_mode.cpp 0000644 0000152 0177776 00000014727 12307723555 024600 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Antti Kaijanmäki
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "sig_term_catcher.h"
#include "test_data.h"
#include "test_service.h"
#include
#include
#include
#include
#include
#include
#include
namespace fdo = org::freedesktop;
namespace NM = fdo::NetworkManager;
#include
namespace cuc = com::ubuntu::connectivity;
namespace dbus = core::dbus;
namespace
{
struct Service : public core::dbus::testing::Fixture {};
auto session_bus_config_file =
core::dbus::testing::Fixture::default_session_bus_config_file() =
core::testing::session_bus_configuration_file();
auto system_bus_config_file =
core::dbus::testing::Fixture::default_system_bus_config_file() =
core::testing::system_bus_configuration_file();
}
TEST_F(Service, flightMode)
{
core::testing::CrossProcessSync services_ready;
core::testing::CrossProcessSync failing_invokations;
core::testing::CrossProcessSync client_ready;
auto service = [&, this]()
{
core::testing::SigTermCatcher sc;
auto bus = system_bus();
bus->install_executor(core::dbus::asio::make_executor(bus));
auto nm_service = NM::Service::Mock(bus);
auto nm_root = nm_service.nm;
nm_root->object->install_method_handler([bus, nm_root](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << std::vector();
bus->send(reply);
});
nm_root->state->set(0);
auto urfkill_service = fdo::URfkill::Service::Mock(bus);
auto urfkill_root = urfkill_service.urfkill;
auto rfkill_device = fdo::URfkill::Interface::Device(urfkill_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/URfkill/devices/0")));
// as we only have one device and it's not blocked the initial state should be off
rfkill_device.hard->set(false);
rfkill_device.soft->set(false);
urfkill_root->object->install_method_handler([bus](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
std::vector devices;
devices.push_back(dbus::types::ObjectPath("/org/freedesktop/URfkill/devices/0"));
reply->writer() << devices;
bus->send(reply);
});
bool fail = true;
urfkill_root->object->install_method_handler([bus, &fail](const dbus::Message::Ptr& msg)
{
auto reader = msg->reader();
// not used for now.
//std::uint32_t type = reader.pop_uint32();
//bool block = reader.pop_boolean();
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << !fail;
bus->send(reply);
});
std::thread t{[bus](){ bus->run(); }};
services_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
EXPECT_EQ(1, failing_invokations.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
fail = false;
EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
sc.wait_for_signal_for(std::chrono::seconds{10});
bus->stop();
if (t.joinable())
t.join();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
auto client = [&, this]()
{
EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
std::unique_ptr mgr;
mgr = cuc::networking::Manager::createInstance();
std::vector statuses;
try {
EXPECT_EQ(mgr->flightMode().get(), cuc::networking::Manager::FlightModeStatus::off);
mgr->flightMode().changed().connect([&statuses](cuc::networking::Manager::FlightModeStatus status) {
statuses.push_back(status);
});
mgr->enableFlightMode();
mgr->disableFlightMode();
failing_invokations.try_signal_ready_for(std::chrono::milliseconds{2000});
mgr->enableFlightMode();
mgr->disableFlightMode();
} catch (std::runtime_error e) {
std::cout << "exception: " << e.what() << std::endl;
}
client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
EXPECT_EQ(statuses.size(), 2);
EXPECT_EQ(statuses.at(0), cuc::networking::Manager::FlightModeStatus::on);
EXPECT_EQ(statuses.at(1), cuc::networking::Manager::FlightModeStatus::off);
delete mgr.release();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
}
connectivity-api-0.0.1+14.04.20140312/tests/test_data.h.in 0000644 0000152 0177776 00000005063 12307723555 023273 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Thomas Voß
*/
#ifndef TEST_DATA_H_
#define TEST_DATA_H_
namespace core
{
namespace testing
{
const char* session_bus_configuration_file()
{
return "@CMAKE_SOURCE_DIR@/data/session.conf";
}
const char* system_bus_configuration_file()
{
return "@CMAKE_SOURCE_DIR@/data/system.conf";
}
namespace com
{
namespace canonical
{
const char* user_metrics_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/com.canonical.UserMetrics.xml";
}
const char* url_dispatcher_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/com.canonical.URLDispatcher.xml";
}
}
}
namespace org
{
namespace freedesktop
{
namespace modem_manager
{
namespace modem
{
constexpr const char* cdma_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Cdma.xml";
}
constexpr const char* firmware_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Firmware.xml";
}
namespace gsm
{
constexpr const char* card_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Gsm.Card.xml";
}
constexpr const char* contact_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Gsm.Contacts.xml";
}
constexpr const char* hso_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Gsm.Hso.xml";
}
constexpr const char* network_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Gsm.Network.xml";
}
constexpr const char* sms_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Gsm.SMS.xml";
}
constexpr const char* ussd_introspection_file()
{
return "@CMAKE_CURRENT_SOURCE_DIR@/data/org.freedesktop.ModemManager.Modem.Gsm.Ussd.xml";
}
}
}
}
}
}
}
}
#endif // TEST_DATA_H_
connectivity-api-0.0.1+14.04.20140312/tests/test_wifi_link_enable_disable.cpp 0000644 0000152 0177776 00000021404 12307723555 027251 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Antti Kaijanmäki
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "sig_term_catcher.h"
#include "test_data.h"
#include "test_service.h"
#include
#include
#include
#include
#include
#include
#include
namespace fdo = org::freedesktop;
namespace NM = fdo::NetworkManager;
#include
#include
#include
namespace cuc = com::ubuntu::connectivity;
namespace dbus = core::dbus;
namespace
{
struct Service : public core::dbus::testing::Fixture {};
auto session_bus_config_file =
core::dbus::testing::Fixture::default_session_bus_config_file() =
core::testing::session_bus_configuration_file();
auto system_bus_config_file =
core::dbus::testing::Fixture::default_system_bus_config_file() =
core::testing::system_bus_configuration_file();
}
TEST_F(Service, wifiLink)
{
core::testing::CrossProcessSync services_ready;
core::testing::CrossProcessSync client_ready;
core::testing::CrossProcessSync stage1;
core::testing::CrossProcessSync stage2;
auto service = [&, this]()
{
core::testing::SigTermCatcher sc;
auto bus = system_bus();
bus->install_executor(core::dbus::asio::make_executor(bus));
auto service = NM::Service::Mock(bus);
auto nm_root = service.nm;
auto wifi_dev = NM::Interface::Device(nm_root->service,
nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")));
nm_root->object->install_method_handler([bus, &wifi_dev](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
std::vector devices;
devices.push_back(wifi_dev.object->path());
reply->writer() << devices;
bus->send(reply);
});
nm_root->state->set(NM_STATE_CONNECTED_GLOBAL);
wifi_dev.device_type->set(NM_DEVICE_TYPE_WIFI);
wifi_dev.state->set(NM_DEVICE_STATE_ACTIVATED);
wifi_dev.object->install_method_handler([&](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << std::vector();
bus->send(reply);
});
bool wireless_enabled = true;
nm_root->wireless_enabled->set(wireless_enabled);
nm_root->wireless_enabled->changed().connect([&](bool value)
{
wireless_enabled = value;
if (wireless_enabled) {
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_NONE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_SECONDARIES, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE));
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_SECONDARIES, NM_DEVICE_STATE_REASON_NONE));
}
else {
wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_REASON_NONE));
}
});
auto urfkill_service = fdo::URfkill::Service::Mock(bus);
auto urfkill_root = urfkill_service.urfkill;
urfkill_root->object->install_method_handler([bus](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << std::vector();
bus->send(reply);
});
std::thread t{[bus](){ bus->run(); }};
services_ready.try_signal_ready_for(std::chrono::milliseconds{5000});
EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
stage1.try_signal_ready_for(std::chrono::milliseconds{5000});
sleep(1);
EXPECT_FALSE(wireless_enabled);
stage2.try_signal_ready_for(std::chrono::milliseconds{5000});
sleep(1);
EXPECT_TRUE(wireless_enabled);
sc.wait_for_signal_for(std::chrono::seconds{60});
bus->stop();
if (t.joinable())
t.join();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
auto client = [&, this]()
{
EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
std::unique_ptr mgr;
mgr = cuc::networking::Manager::createInstance();
auto links = mgr->links();
EXPECT_EQ(links->size(), 1);
EXPECT_EQ((*links->begin())->type(), cuc::networking::Link::Type::wifi);
auto wifilink = std::dynamic_pointer_cast(*links->begin());
EXPECT_TRUE(wifilink.get() != nullptr);
client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
wifilink->disable();
sleep(1);
EXPECT_EQ(1, stage1.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
EXPECT_EQ(wifilink->status().get(), cuc::networking::Link::Status::disabled);
std::vector link_states;
wifilink->status().changed().connect([&](cuc::networking::Link::Status value)
{
link_states.push_back(value);
});
wifilink->enable();
sleep(1);
EXPECT_EQ(1, stage2.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
EXPECT_EQ(wifilink->status().get(), cuc::networking::Link::Status::online);
EXPECT_EQ(link_states.size(), 4);
EXPECT_EQ(link_states[0], cuc::networking::Link::Status::offline);
EXPECT_EQ(link_states[1], cuc::networking::Link::Status::connecting);
EXPECT_EQ(link_states[2], cuc::networking::Link::Status::connected);
EXPECT_EQ(link_states[3], cuc::networking::Link::Status::online);
delete mgr.release();
return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
};
EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
}
connectivity-api-0.0.1+14.04.20140312/tests/test_wifi_link.cpp 0000644 0000152 0177776 00000036000 12307723555 024256 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright © 2013 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3,
* as published by the Free Software Foundation.
*
* This program 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Antti Kaijanmäki
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "sig_term_catcher.h"
#include "test_data.h"
#include "test_service.h"
#include
#include
#include
#include
#include
#include
#include
namespace fdo = org::freedesktop;
namespace NM = fdo::NetworkManager;
#include
#include
#include
namespace cuc = com::ubuntu::connectivity;
namespace dbus = core::dbus;
namespace
{
struct Service : public core::dbus::testing::Fixture {};
auto session_bus_config_file =
core::dbus::testing::Fixture::default_session_bus_config_file() =
core::testing::session_bus_configuration_file();
auto system_bus_config_file =
core::dbus::testing::Fixture::default_system_bus_config_file() =
core::testing::system_bus_configuration_file();
}
TEST_F(Service, wifiLink)
{
core::testing::CrossProcessSync services_ready;
core::testing::CrossProcessSync client_ready;
core::testing::CrossProcessSync stage1;
core::testing::CrossProcessSync stage2;
core::testing::CrossProcessSync stage3;
auto service = [&, this]()
{
core::testing::SigTermCatcher sc;
auto bus = system_bus();
bus->install_executor(core::dbus::asio::make_executor(bus));
auto service = NM::Service::Mock(bus);
auto nm_root = service.nm;
auto wifi_dev = NM::Interface::Device(nm_root->service,
nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")));
auto ap1 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/1")));
auto ap2 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/2")));
nm_root->object->install_method_handler([bus, &wifi_dev](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
std::vector devices;
devices.push_back(wifi_dev.object->path());
reply->writer() << devices;
bus->send(reply);
});
nm_root->state->set(NM_STATE_CONNECTED_GLOBAL);
wifi_dev.device_type->set(NM_DEVICE_TYPE_WIFI);
std::vector aps;
wifi_dev.object->install_method_handler([bus, &aps](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << aps;
bus->send(reply);
});
auto ap_added = wifi_dev.object->get_signal();
auto ap_removed = wifi_dev.object->get_signal();
ap1.flags->set(NM_802_11_AP_FLAGS_PRIVACY);
ap1.mode->set(NM_802_11_MODE_INFRA);
ap1.ssid->set({0x61, 0x62, 0x63}); // abc
ap1.strength->set(90);
auto ap1_pc = ap1.properties_changed;
ap2.flags->set(NM_802_11_AP_FLAGS_NONE);
ap2.mode->set(NM_802_11_MODE_ADHOC);
ap2.ssid->set({0x31, 0x32, 0x33}); // 123
ap2.strength->set(60);
auto ap2_pc = ap2.properties_changed;
auto urfkill_service = fdo::URfkill::Service::Mock(bus);
auto urfkill_root = urfkill_service.urfkill;
urfkill_root->object->install_method_handler([bus](const dbus::Message::Ptr& msg)
{
auto reply = dbus::Message::make_method_return(msg);
reply->writer() << std::vector();
bus->send(reply);
});
std::thread t{[bus](){ bus->run(); }};
// add just one AP initially
aps.push_back(ap1.object->path());
services_ready.try_signal_ready_for(std::chrono::milliseconds{5000});
EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
NM::Interface::AccessPoint::Signal::PropertiesChanged::ArgumentType properties;
properties["Strength"] = dbus::types::Variant::encode(0);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(1);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(2);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(3);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(4);
ap1_pc->emit(properties);
stage1.try_signal_ready_for(std::chrono::milliseconds{5000});
// add second ap
aps.push_back(ap2.object->path());
ap_added->emit(ap2.object->path());
sleep(1);
properties["Strength"] = dbus::types::Variant::encode(5);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(6);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(7);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(8);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(9);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(100);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(99);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(98);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(97);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(96);
ap2_pc->emit(properties);
ap2_pc->emit(properties);
stage2.try_signal_ready_for(std::chrono::milliseconds{5000});
// remove the first ap
aps.clear();
aps.push_back(ap2.object->path());
ap_removed->emit(ap1.object->path());
sleep(1);
properties["Strength"] = dbus::types::Variant::encode(95);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(94);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(93);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(92);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(91);
ap2_pc->emit(properties);
stage3.try_signal_ready_for(std::chrono::milliseconds{5000});
// add the first ap back
aps.push_back(ap1.object->path());
ap_added->emit(ap1.object->path());
sleep(1);
properties["Strength"] = dbus::types::Variant::encode(10);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(11);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(12);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(13);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(14);
ap1_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode(90);
ap2_pc->emit(properties);
properties["Strength"] = dbus::types::Variant::encode