Merge lp:~unity-api-team/indicator-network/connectity-api-beginnings into lp:indicator-network/15.10

Proposed by Pete Woods
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 499
Merged at revision: 487
Proposed branch: lp:~unity-api-team/indicator-network/connectity-api-beginnings
Merge into: lp:indicator-network/15.10
Prerequisite: lp:~unity-api-team/indicator-network/restore-connectivity-headers
Diff against target: 5655 lines (+1760/-2788)
52 files modified
data/com.ubuntu.connectivity1.NetworkingStatus.xml (+5/-0)
data/com.ubuntu.connectivity1.Private.xml (+8/-0)
data/org.freedesktop.DBus.Properties.xml (+27/-0)
src/CMakeLists.txt (+2/-0)
src/connectivity-api/CMakeLists.txt (+4/-0)
src/connectivity-api/connectivity-qt/CMakeLists.txt (+52/-0)
src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp (+130/-0)
src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h (+84/-0)
src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.cpp (+156/-0)
src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.h (+57/-0)
src/indicator/agent/SecretAgent.cpp (+66/-48)
src/indicator/agent/SecretAgent.h (+28/-41)
src/indicator/agent/SecretAgentInclude.h (+1/-1)
src/indicator/agent/SecretRequest.cpp (+2/-0)
src/indicator/agent/SecretRequest.h (+1/-1)
src/indicator/connectivity-service/connectivity-service.cpp (+50/-1)
src/indicator/connectivity-service/connectivity-service.h (+13/-0)
src/indicator/main.cpp (+3/-2)
src/indicator/nmofono/kill-switch.cpp (+5/-8)
src/indicator/nmofono/manager-impl.cpp (+80/-76)
src/indicator/nmofono/manager-impl.h (+4/-4)
src/indicator/nmofono/manager.h (+10/-10)
src/indicator/sections/quick-access-section.cpp (+18/-27)
src/indicator/sections/wifi-section.cpp (+1/-13)
src/menumodel-cpp/gio-helpers/variant.h (+8/-0)
src/qdbus-stubs/CMakeLists.txt (+1/-15)
src/qdbus-stubs/dbus-types.h (+11/-9)
tests/integration/CMakeLists.txt (+0/-2)
tests/integration/connectivity-cpp/CMakeLists.txt (+0/-130)
tests/integration/connectivity-cpp/mocks/urfkill.h (+0/-162)
tests/integration/connectivity-cpp/sig_term_catcher.h (+0/-74)
tests/integration/connectivity-cpp/test_data.h.in (+0/-38)
tests/integration/connectivity-cpp/test_flight_mode.cpp (+0/-138)
tests/integration/connectivity-cpp/test_networking_status.cpp (+0/-178)
tests/integration/connectivity-cpp/test_service.h (+0/-124)
tests/integration/connectivity-cpp/test_wifi_connect.cpp (+0/-278)
tests/integration/connectivity-cpp/test_wifi_link.cpp (+0/-362)
tests/integration/connectivity-cpp/test_wifi_link_dedup.cpp (+0/-240)
tests/integration/connectivity-cpp/test_wifi_link_enable_disable.cpp (+0/-186)
tests/integration/indicator-network-test-base.cpp (+338/-0)
tests/integration/indicator-network-test-base.h (+156/-0)
tests/integration/test-connectivity-api.cpp (+289/-0)
tests/integration/test-indicator.cpp (+45/-418)
tests/unit/CMakeLists.txt (+87/-3)
tests/unit/indicator/CMakeLists.txt (+0/-6)
tests/unit/indicator/menuitems/CMakeLists.txt (+0/-39)
tests/unit/menumodel-cpp/CMakeLists.txt (+0/-35)
tests/unit/menumodel-cpp/test-menu-exporter.cpp (+9/-9)
tests/unit/secret-agent/CMakeLists.txt (+0/-71)
tests/unit/secret-agent/secret-agent-main.cpp (+1/-1)
tests/unit/secret-agent/test-secret-agent.cpp (+8/-24)
tests/unit/test_variant.h (+0/-14)
To merge this branch: bzr merge lp:~unity-api-team/indicator-network/connectity-api-beginnings
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+257045@code.launchpad.net

Commit message

Add flight mode and wifi toggles to connectivity service interface

Description of the change

Add flight mode and wifi toggles to connectivity service interface

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ted Gould (ted) wrote :

On Wed, 2015-04-22 at 10:09 +0000, Pete Woods wrote:

> Add flight mode and wifi toggles to connectivity service interface

It seems odd to me that we're adding to dbus whether the value is
changing.

+ <property name="FlightMode" type="b" access="read"/>
+ <property name="FlightModeIsChanging" type="b" access="read"/>
+
+ <property name="WifiEnabled" type="b" access="read"/>
+ <property name="WifiEnabledIsChanging" type="b" access="read"/>

Why would an application care if the value is changing?

496. By Pete Woods

Robustify the tests

Revision history for this message
Pete Woods (pete-woods) wrote :

The purpose of those properties (have now merged into one property) is to allow simple data binding in a client application for when to enable / disable the wifi and flight mode toggle buttons.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
497. By Pete Woods

Make the unit tests resistant against the dbus connection closing (as you should expect in a test case)

498. By Pete Woods

Use built in notification daemon template, instead of custom mock

499. By Pete Woods

Test that all the signals are emitted

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Diff is sane, still seems functionality sound, plus test coverage is looking good too. +1

Just a note on test coverage:

692 + if (!d->m_systemConnection.registerObject(NM_DBUS_PATH_SECRET_AGENT, this)) {
693 throw logic_error(

Its tricky to recreate some of these failure conditions, but we should consider coming back some time to test things like this. I.e. check that the indicator doesn't completely fall apart when these exceptions are thrown.

review: Approve
Revision history for this message
Ted Gould (ted) wrote :

Applications don't need to toggle the buttons, they only need to know the
state of things. The only person chaning it should be the network
indicator.

On Thursday, April 23, 2015 11:04:06 AM BST, Pete Woods wrote:
> The purpose of those properties (have now merged into one
> property) is to allow simple data binding in a client
> application for when to enable / disable the wifi and flight
> mode toggle buttons.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/com.ubuntu.connectivity1.NetworkingStatus.xml'
--- data/com.ubuntu.connectivity1.NetworkingStatus.xml 2015-03-20 15:24:02 +0000
+++ data/com.ubuntu.connectivity1.NetworkingStatus.xml 2015-04-23 13:23:11 +0000
@@ -6,6 +6,11 @@
6 <property name="Limitations" type="as" access="read"/>6 <property name="Limitations" type="as" access="read"/>
7 <property name="Status" type="s" access="read"/>7 <property name="Status" type="s" access="read"/>
88
9 <property name="FlightMode" type="b" access="read"/>
10 <property name="WifiEnabled" type="b" access="read"/>
11
12 <property name="UnstoppableOperationHappening" type="b" access="read"/>
13
9 </interface>14 </interface>
10</node>15</node>
1116
1217
=== modified file 'data/com.ubuntu.connectivity1.Private.xml'
--- data/com.ubuntu.connectivity1.Private.xml 2015-03-23 14:46:24 +0000
+++ data/com.ubuntu.connectivity1.Private.xml 2015-04-23 13:23:11 +0000
@@ -9,6 +9,14 @@
9 <method name="UnlockModem">9 <method name="UnlockModem">
10 <arg type="s" direction="in" name="modem"/>10 <arg type="s" direction="in" name="modem"/>
11 </method>11 </method>
12
13 <method name="SetFlightMode">
14 <arg type="b" direction="in" name="enabled"/>
15 </method>
16
17 <method name="SetWifiEnabled">
18 <arg type="b" direction="in" name="enabled"/>
19 </method>
1220
13 </interface>21 </interface>
14</node>22</node>
1523
=== added file 'data/org.freedesktop.DBus.Properties.xml'
--- data/org.freedesktop.DBus.Properties.xml 1970-01-01 00:00:00 +0000
+++ data/org.freedesktop.DBus.Properties.xml 2015-04-23 13:23:11 +0000
@@ -0,0 +1,27 @@
1<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
2 "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
3<node>
4 <interface name="org.freedesktop.DBus.Properties">
5 <method name="Get">
6 <arg type="s" name="interface_name" direction="in"/>
7 <arg type="s" name="property_name" direction="in"/>
8 <arg type="v" name="value" direction="out"/>
9 </method>
10 <method name="GetAll">
11 <arg type="s" name="interface_name" direction="in"/>
12 <arg type="a{sv}" name="properties" direction="out"/>
13 <annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="QVariantMap"/>
14 </method>
15 <method name="Set">
16 <arg type="s" name="interface_name" direction="in"/>
17 <arg type="s" name="property_name" direction="in"/>
18 <arg type="v" name="value" direction="in"/>
19 </method>
20 <signal name="PropertiesChanged">
21 <arg type="s" name="interface_name"/>
22 <arg type="a{sv}" name="changed_properties"/>
23 <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QVariantMap"/>
24 <arg type="as" name="invalidated_properties"/>
25 </signal>
26 </interface>
27</node>
028
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2015-04-23 13:23:11 +0000
+++ src/CMakeLists.txt 2015-04-23 13:23:11 +0000
@@ -3,6 +3,8 @@
3 set(COMMON_FLAGS "${COMMON_FLAGS} -Werror")3 set(COMMON_FLAGS "${COMMON_FLAGS} -Werror")
4endif()4endif()
55
6add_subdirectory(connectivity-api)
7
6add_subdirectory(indicator)8add_subdirectory(indicator)
7add_subdirectory(menumodel-cpp)9add_subdirectory(menumodel-cpp)
8add_subdirectory(qdbus-stubs)10add_subdirectory(qdbus-stubs)
911
=== added directory 'src/connectivity-api'
=== added file 'src/connectivity-api/CMakeLists.txt'
--- src/connectivity-api/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/connectivity-api/CMakeLists.txt 2015-04-23 13:23:11 +0000
@@ -0,0 +1,4 @@
1
2#add_subdirectory(connectivity-cpp)
3add_subdirectory(connectivity-qt)
4add_subdirectory(connectivity-qml)
0\ No newline at end of file5\ No newline at end of file
16
=== renamed directory 'src/connectivity-cpp' => 'src/connectivity-api/connectivity-cpp'
=== added directory 'src/connectivity-api/connectivity-qml'
=== added file 'src/connectivity-api/connectivity-qml/CMakeLists.txt'
=== added directory 'src/connectivity-api/connectivity-qt'
=== added file 'src/connectivity-api/connectivity-qt/CMakeLists.txt'
--- src/connectivity-api/connectivity-qt/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/connectivity-api/connectivity-qt/CMakeLists.txt 2015-04-23 13:23:11 +0000
@@ -0,0 +1,52 @@
1
2include_directories("${CMAKE_SOURCE_DIR}/src/qdbus-stubs")
3
4set(
5 CONNECTIVITY_QT_SRC
6 connectivityqt/internal/dbus-property-cache.cpp
7 connectivityqt/connectivity.cpp
8)
9
10set_source_files_properties(
11 "${DATA_DIR}/org.freedesktop.DBus.Properties.xml"
12 "${DATA_DIR}/com.ubuntu.connectivity1.NetworkingStatus.xml"
13 "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml"
14 PROPERTIES
15 NO_NAMESPACE YES
16)
17
18
19qt5_add_dbus_interface(
20 CONNECTIVITY_QT_SRC
21 "${DATA_DIR}/com.ubuntu.connectivity1.NetworkingStatus.xml"
22 NetworkingStatusInterface
23)
24
25qt5_add_dbus_interface(
26 CONNECTIVITY_QT_SRC
27 "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml"
28 NetworkingStatusPrivateInterface
29)
30
31qt5_add_dbus_interface(
32 CONNECTIVITY_QT_SRC
33 "${DATA_DIR}/org.freedesktop.DBus.Properties.xml"
34 PropertiesInterface
35)
36
37add_library(
38 connectivity-qt
39 SHARED
40 ${CONNECTIVITY_QT_SRC}
41)
42
43qt5_use_modules(
44 connectivity-qt
45 Core
46 DBus
47)
48
49target_link_libraries(
50 connectivity-qt
51 qdbus-stubs
52)
053
=== added directory 'src/connectivity-api/connectivity-qt/connectivityqt'
=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp'
--- src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp 1970-01-01 00:00:00 +0000
+++ src/connectivity-api/connectivity-qt/connectivityqt/connectivity.cpp 2015-04-23 13:23:11 +0000
@@ -0,0 +1,130 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Pete Woods <pete.woods@canonical.com>
18 */
19
20#include <connectivityqt/connectivity.h>
21#include <connectivityqt/internal/dbus-property-cache.h>
22#include <dbus-types.h>
23#include <NetworkingStatusInterface.h>
24#include <NetworkingStatusPrivateInterface.h>
25
26#include <QDebug>
27
28using namespace std;
29
30namespace connectivityqt
31{
32
33class Connectivity::Priv: public QObject
34{
35 Q_OBJECT
36public:
37 Priv(Connectivity& parent, const QDBusConnection& sessionConnection) :
38 p(parent), m_sessionConnection(sessionConnection)
39 {
40 }
41
42 Connectivity& p;
43
44 QDBusConnection m_sessionConnection;
45
46 shared_ptr<internal::DBusPropertyCache> m_propertyCache;
47
48 shared_ptr<ComUbuntuConnectivity1NetworkingStatusInterface> m_readInterface;
49
50 shared_ptr<ComUbuntuConnectivity1PrivateInterface> m_writeInterface;
51
52public Q_SLOTS:
53
54 void propertyChanged(const QString& name, const QVariant& value)
55 {
56 if (name == "FlightMode")
57 {
58 Q_EMIT p.flightModeUpdated(value.toBool());
59 }
60 else if (name == "WifiEnabled")
61 {
62 Q_EMIT p.wifiEnabledUpdated(value.toBool());
63 }
64 else if (name == "UnstoppableOperationHappening")
65 {
66 Q_EMIT p.unstoppableOperationHappeningUpdated(value.toBool());
67 }
68 }
69};
70
71Connectivity::Connectivity(const QDBusConnection& sessionConnection) :
72 d(new Priv(*this, sessionConnection))
73{
74 d->m_readInterface = make_shared<
75 ComUbuntuConnectivity1NetworkingStatusInterface>(
76 DBusTypes::DBUS_NAME, DBusTypes::SERVICE_PATH,
77 d->m_sessionConnection);
78
79 d->m_writeInterface = make_shared<ComUbuntuConnectivity1PrivateInterface>(
80 DBusTypes::DBUS_NAME, DBusTypes::PRIVATE_PATH,
81 d->m_sessionConnection);
82
83 d->m_propertyCache = make_shared<internal::DBusPropertyCache>(
84 DBusTypes::DBUS_NAME, DBusTypes::SERVICE_INTERFACE,
85 DBusTypes::SERVICE_PATH, sessionConnection);
86 connect(d->m_propertyCache.get(),
87 &internal::DBusPropertyCache::propertyChanged, d.get(),
88 &Priv::propertyChanged);
89 connect(d->m_propertyCache.get(),
90 &internal::DBusPropertyCache::initialized, this,
91 &Connectivity::initialized);
92}
93
94Connectivity::~Connectivity()
95{
96}
97
98bool Connectivity::flightMode() const
99{
100 return d->m_propertyCache->get("FlightMode").toBool();
101}
102
103bool Connectivity::wifiEnabled() const
104{
105 return d->m_propertyCache->get("WifiEnabled").toBool();
106}
107
108bool Connectivity::unstoppableOperationHappening() const
109{
110 return d->m_propertyCache->get("UnstoppableOperationHappening").toBool();
111}
112
113void Connectivity::setFlightMode(bool enabled)
114{
115 d->m_writeInterface->SetFlightMode(enabled);
116}
117
118void Connectivity::setwifiEnabled(bool enabled)
119{
120 d->m_writeInterface->SetWifiEnabled(enabled);
121}
122
123bool Connectivity::isInitialized() const
124{
125 return d->m_propertyCache->isInitialized();
126}
127
128}
129
130#include "connectivity.moc"
0131
=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h'
--- src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h 1970-01-01 00:00:00 +0000
+++ src/connectivity-api/connectivity-qt/connectivityqt/connectivity.h 2015-04-23 13:23:11 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Pete Woods <pete.woods@canonical.com>
18 */
19
20#pragma once
21
22#include <QDBusConnection>
23#include <QObject>
24#include <QStringList>
25#include <memory>
26
27#include <unity/util/DefinesPtrs.h>
28
29namespace connectivityqt
30{
31
32class Q_DECL_EXPORT Connectivity: public QObject
33{
34 Q_OBJECT
35
36public:
37 UNITY_DEFINES_PTRS(Connectivity);
38
39 Connectivity(const QDBusConnection& sessionConnection = QDBusConnection::sessionBus());
40
41 ~Connectivity();
42
43 Q_PROPERTY(bool FlightMode READ flightMode WRITE setFlightMode NOTIFY flightModeUpdated)
44 bool flightMode() const;
45
46// Q_PROPERTY(QStringList Limitations READ limitations NOTIFY limitationsUpdated)
47// QStringList limitations() const;
48
49// Q_PROPERTY(QString Status READ status NOTIFY statusUpdated)
50// QString status() const;
51
52 Q_PROPERTY(bool WifiEnabled READ wifiEnabled WRITE setwifiEnabled NOTIFY wifiEnabledUpdated)
53 bool wifiEnabled() const;
54
55 Q_PROPERTY(bool UnstoppableOperationHappening READ unstoppableOperationHappening NOTIFY unstoppableOperationHappeningUpdated)
56 bool unstoppableOperationHappening() const;
57
58 Q_PROPERTY(bool Initialized READ isInitialized NOTIFY initialized)
59 bool isInitialized() const;
60
61public Q_SLOTS:
62 void setFlightMode(bool enabled);
63
64 void setwifiEnabled(bool enabled);
65
66Q_SIGNALS:
67 void flightModeUpdated(bool);
68
69// void limitationsUpdated(const QStringList&);
70
71// void statusUpdated(const QString&);
72
73 void wifiEnabledUpdated(bool);
74
75 void unstoppableOperationHappeningUpdated(bool);
76
77 void initialized();
78
79protected:
80 class Priv;
81 std::shared_ptr<Priv> d;
82};
83
84}
085
=== added directory 'src/connectivity-api/connectivity-qt/connectivityqt/internal'
=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.cpp'
--- src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.cpp 1970-01-01 00:00:00 +0000
+++ src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.cpp 2015-04-23 13:23:11 +0000
@@ -0,0 +1,156 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Pete Woods <pete.woods@canonical.com>
18 */
19
20#include <connectivityqt/internal/dbus-property-cache.h>
21
22#include <PropertiesInterface.h>
23
24using namespace std;
25
26namespace connectivityqt
27{
28namespace internal
29{
30
31class DBusPropertyCache::Priv: public QObject
32{
33 Q_OBJECT
34
35public:
36 Priv(DBusPropertyCache& parent, const QDBusConnection& connection) :
37 p(parent), m_connection(connection)
38 {
39 }
40
41 DBusPropertyCache& p;
42
43 QDBusConnection m_connection;
44
45 QString m_service;
46
47 QString m_interface;
48
49 QString m_path;
50
51 shared_ptr<QDBusServiceWatcher> m_serviceWatcher;
52
53 shared_ptr<OrgFreedesktopDBusPropertiesInterface> m_propertiesInterface;
54
55 QVariantMap m_propertyCache;
56
57 void refreshProperties(const QStringList& names)
58 {
59 for(const QString& name: names)
60 {
61 QDBusVariant value = m_propertiesInterface->Get(m_interface, name);
62 m_propertyCache[name] = value.variant();
63 Q_EMIT p.propertyChanged(name, value.variant());
64 }
65 }
66
67public Q_SLOTS:
68 void serviceOwnerChanged(const QString &, const QString &,
69 const QString & newOwner)
70 {
71 m_propertiesInterface.reset();
72 m_propertyCache.clear();
73
74 if (newOwner.isEmpty())
75 {
76 return;
77 }
78
79 m_propertiesInterface = make_shared<
80 OrgFreedesktopDBusPropertiesInterface>(m_service, m_path,
81 m_connection);
82
83 connect(m_propertiesInterface.get(),
84 &OrgFreedesktopDBusPropertiesInterface::PropertiesChanged, this,
85 &Priv::propertiesChanged);
86
87 m_propertyCache = m_propertiesInterface->GetAll(m_interface);
88 QMapIterator<QString, QVariant> it(m_propertyCache);
89 while (it.hasNext())
90 {
91 it.next();
92 Q_EMIT p.propertyChanged(it.key(), it.value());
93 }
94
95 Q_EMIT p.initialized();
96 }
97
98 void propertiesChanged(const QString &,
99 const QVariantMap &changedProperties,
100 const QStringList &invalidatedProperties)
101 {
102 QMapIterator<QString, QVariant> it(changedProperties);
103 while (it.hasNext())
104 {
105 it.next();
106 m_propertyCache[it.key()] = it.value();
107 Q_EMIT p.propertyChanged(it.key(), it.value());
108 }
109
110 refreshProperties(invalidatedProperties);
111 }
112};
113
114DBusPropertyCache::DBusPropertyCache(const QString &service,
115 const QString &interface,
116 const QString &path,
117 const QDBusConnection &connection) :
118 d(new Priv(*this, connection))
119{
120 d->m_service = service;
121 d->m_interface = interface;
122 d->m_path = path;
123
124 d->m_serviceWatcher = make_shared<QDBusServiceWatcher>(service,
125 connection);
126
127 connect(d->m_serviceWatcher.get(), &QDBusServiceWatcher::serviceOwnerChanged,
128 d.get(), &Priv::serviceOwnerChanged);
129
130 // If the service is already registered
131 QString serviceOwner = connection.interface()->serviceOwner(service);
132 if (!serviceOwner.isEmpty())
133 {
134 d->serviceOwnerChanged(service, "", serviceOwner);
135 }
136}
137
138DBusPropertyCache::~DBusPropertyCache()
139{
140}
141
142QVariant DBusPropertyCache::get(const QString& name)
143{
144 return d->m_propertyCache[name];
145}
146
147bool DBusPropertyCache::isInitialized() const
148{
149 return !d->m_propertyCache.empty();
150}
151
152}
153}
154
155#include "dbus-property-cache.moc"
156
0157
=== added file 'src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.h'
--- src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.h 1970-01-01 00:00:00 +0000
+++ src/connectivity-api/connectivity-qt/connectivityqt/internal/dbus-property-cache.h 2015-04-23 13:23:11 +0000
@@ -0,0 +1,57 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Pete Woods <pete.woods@canonical.com>
18 */
19
20#pragma once
21
22#include <QDBusConnection>
23#include <QObject>
24#include <QString>
25#include <memory>
26
27namespace connectivityqt
28{
29namespace internal
30{
31
32class DBusPropertyCache: public QObject
33{
34 Q_OBJECT
35
36public:
37 DBusPropertyCache(const QString &service, const QString& interface,
38 const QString &path, const QDBusConnection &connection);
39
40 ~DBusPropertyCache();
41
42 QVariant get(const QString& name);
43
44 bool isInitialized() const;
45
46Q_SIGNALS:
47 void propertyChanged(const QString& name, const QVariant& value);
48
49 void initialized();
50
51protected:
52 class Priv;
53 std::shared_ptr<Priv> d;
54};
55
56}
57}
058
=== modified file 'src/indicator/agent/SecretAgent.cpp'
--- src/indicator/agent/SecretAgent.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/agent/SecretAgent.cpp 2015-04-23 13:23:11 +0000
@@ -16,12 +16,13 @@
16 * Author: Pete Woods <pete.woods@canonical.com>16 * Author: Pete Woods <pete.woods@canonical.com>
17 */17 */
1818
19#include <menumodel-cpp/gio-helpers/util.h>
20#include <agent/SecretAgent.h>19#include <agent/SecretAgent.h>
20#include <agent/SecretRequest.h>
21#include <AgentManagerInterface.h>
22#include <NotificationsInterface.h>
21#include <SecretAgentAdaptor.h>23#include <SecretAgentAdaptor.h>
2224
23#include <NetworkManager.h>25#include <NetworkManager.h>
24
25#include <stdexcept>26#include <stdexcept>
2627
27using namespace std;28using namespace std;
@@ -29,53 +30,67 @@
29namespace agent30namespace agent
30{31{
3132
32const QString SecretAgent::CONNECTION_SETTING_NAME("connection");33class SecretAgent::Priv : public QObject {
33const QString SecretAgent::WIRELESS_SECURITY_SETTING_NAME(34 Q_OBJECT
34 "802-11-wireless-security");35
3536public:
36const QString SecretAgent::CONNECTION_ID("id");37 Priv(const QDBusConnection &systemConnection,
3738 const QDBusConnection &sessionConnection) :
38const QString SecretAgent::WIRELESS_SECURITY_PSK("psk");39 m_systemConnection(systemConnection),
39const QString SecretAgent::WIRELESS_SECURITY_WEP_KEY0("wep-key0");40 m_sessionConnection(sessionConnection),
4041 m_managerWatcher(NM_DBUS_SERVICE, m_systemConnection),
41const QString SecretAgent::WIRELESS_SECURITY_KEY_MGMT("key-mgmt");42 m_agentManager(NM_DBUS_SERVICE, NM_DBUS_PATH_AGENT_MANAGER, m_systemConnection),
4243 m_notifications("org.freedesktop.Notifications", "/org/freedesktop/Notifications", m_sessionConnection),
43const QString SecretAgent::KEY_MGMT_WPA_NONE("wpa-none");44 m_request(nullptr) {
44const QString SecretAgent::KEY_MGMT_WPA_PSK("wpa-psk");45 }
45const QString SecretAgent::KEY_MGMT_NONE("none");46
47public Q_SLOTS:
48 void serviceOwnerChanged(const QString &name, const QString &oldOwner,
49 const QString &newOwner)
50 {
51 Q_UNUSED(name)
52 Q_UNUSED(oldOwner)
53 if (!newOwner.isEmpty()) {
54 m_agentManager.Register("com.canonical.indicator.SecretAgent").waitForFinished();
55 }
56 }
57
58public:
59 QDBusConnection m_systemConnection;
60
61 QDBusConnection m_sessionConnection;
62
63 QDBusServiceWatcher m_managerWatcher;
64
65 OrgFreedesktopNetworkManagerAgentManagerInterface m_agentManager;
66
67 OrgFreedesktopNotificationsInterface m_notifications;
68
69 std::shared_ptr<SecretRequest> m_request;
70};
4671
47SecretAgent::SecretAgent(const QDBusConnection &systemConnection,72SecretAgent::SecretAgent(const QDBusConnection &systemConnection,
48 const QDBusConnection &sessionConnection, QObject *parent) :73 const QDBusConnection &sessionConnection, QObject *parent) :
49 QObject(parent), m_adaptor(new SecretAgentAdaptor(this)), m_systemConnection(74 QObject(parent), d(new Priv(systemConnection, sessionConnection))
50 systemConnection), m_sessionConnection(sessionConnection), m_managerWatcher(75 {
51 NM_DBUS_SERVICE, m_systemConnection), m_agentManager(NM_DBUS_SERVICE,76 // Memory managed by Qt
52 NM_DBUS_PATH_AGENT_MANAGER, m_systemConnection), m_notifications(77 new SecretAgentAdaptor(this);
53 "org.freedesktop.Notifications", "/org/freedesktop/Notifications",78
54 m_sessionConnection), m_request(nullptr) {79 if (!d->m_systemConnection.registerObject(NM_DBUS_PATH_SECRET_AGENT, this)) {
55 if (!m_systemConnection.registerObject(NM_DBUS_PATH_SECRET_AGENT, this)) {
56 throw logic_error(80 throw logic_error(
57 "Unable to register user secret agent object on DBus");81 "Unable to register user secret agent object on DBus");
58 }82 }
5983
60 // Watch for NM restarting (or starting after we do)84 // Watch for NM restarting (or starting after we do)
61 connect(&m_managerWatcher, SIGNAL(serviceOwnerChanged(QString, QString, QString)),85 connect(&d->m_managerWatcher, &QDBusServiceWatcher::serviceOwnerChanged,
62 this, SLOT(serviceOwnerChanged(QString, QString, QString)));86 d.get(), &Priv::serviceOwnerChanged);
6387
64 m_agentManager.Register("com.canonical.indicator.SecretAgent").waitForFinished();88 d->m_agentManager.Register("com.canonical.indicator.SecretAgent").waitForFinished();
65}89}
6690
67SecretAgent::~SecretAgent() {91SecretAgent::~SecretAgent() {
68 m_agentManager.Unregister().waitForFinished();92 d->m_agentManager.Unregister().waitForFinished();
69 m_systemConnection.unregisterObject(NM_DBUS_PATH_SECRET_AGENT);93 d->m_systemConnection.unregisterObject(NM_DBUS_PATH_SECRET_AGENT);
70}
71
72void SecretAgent::serviceOwnerChanged(const QString &name,
73 const QString &oldOwner, const QString &newOwner) {
74 Q_UNUSED(name)
75 Q_UNUSED(oldOwner)
76 if (!newOwner.isEmpty()) {
77 m_agentManager.Register("com.canonical.indicator.SecretAgent").waitForFinished();
78 }
79}94}
8095
81/**96/**
@@ -123,11 +138,11 @@
123 setDelayedReply(true);138 setDelayedReply(true);
124139
125 if (flags == 0) {140 if (flags == 0) {
126 m_systemConnection.send(141 d->m_systemConnection.send(
127 message().createErrorReply(QDBusError::InternalError,142 message().createErrorReply(QDBusError::InternalError,
128 "No password found for this connection."));143 "No password found for this connection."));
129 } else {144 } else {
130 m_request.reset(new SecretRequest(*this, connection,145 d->m_request.reset(new SecretRequest(*this, connection,
131 connectionPath, settingName, hints, flags, message()));146 connectionPath, settingName, hints, flags, message()));
132 }147 }
133148
@@ -136,23 +151,23 @@
136151
137void SecretAgent::FinishGetSecrets(SecretRequest &request, bool error) {152void SecretAgent::FinishGetSecrets(SecretRequest &request, bool error) {
138 if (error) {153 if (error) {
139 m_systemConnection.send(154 d->m_systemConnection.send(
140 request.message().createErrorReply(QDBusError::InternalError,155 request.message().createErrorReply(QDBusError::InternalError,
141 "No password found for this connection."));156 "No password found for this connection."));
142 } else {157 } else {
143 m_systemConnection.send(158 d->m_systemConnection.send(
144 request.message().createReply(159 request.message().createReply(
145 QVariant::fromValue(request.connection())));160 QVariant::fromValue(request.connection())));
146 }161 }
147162
148 m_request.reset();163 d->m_request.reset();
149}164}
150165
151void SecretAgent::CancelGetSecrets(const QDBusObjectPath &connectionPath,166void SecretAgent::CancelGetSecrets(const QDBusObjectPath &connectionPath,
152 const QString &settingName) {167 const QString &settingName) {
153 Q_UNUSED(connectionPath);168 Q_UNUSED(connectionPath);
154 Q_UNUSED(settingName);169 Q_UNUSED(settingName);
155 m_request.reset();170 d->m_request.reset();
156}171}
157172
158void SecretAgent::DeleteSecrets(const QVariantDictMap &connection,173void SecretAgent::DeleteSecrets(const QVariantDictMap &connection,
@@ -168,7 +183,10 @@
168}183}
169184
170OrgFreedesktopNotificationsInterface & SecretAgent::notifications() {185OrgFreedesktopNotificationsInterface & SecretAgent::notifications() {
171 return m_notifications;186 return d->m_notifications;
172}187}
173188
174}189}
190
191#include "SecretAgent.moc"
192
175193
=== modified file 'src/indicator/agent/SecretAgent.h'
--- src/indicator/agent/SecretAgent.h 2015-04-23 13:23:11 +0000
+++ src/indicator/agent/SecretAgent.h 2015-04-23 13:23:11 +0000
@@ -18,50 +18,52 @@
1818
19#pragma once19#pragma once
2020
21#include <dbus-types.h>
22
21#include <memory>23#include <memory>
2224
23#include <QScopedPointer>
24#include <QDBusConnection>25#include <QDBusConnection>
25#include <QDBusContext>26#include <QDBusContext>
26#include <QMap>27#include <QMap>
2728
28#include <DBusTypes.h>29class OrgFreedesktopNotificationsInterface;
29#include <agent/SecretRequest.h>
30#include <AgentManagerInterface.h>
31#include <NotificationsInterface.h>
32
33class SecretAgentAdaptor;30class SecretAgentAdaptor;
3431
35namespace agent32namespace agent
36{33{
3734
35class SecretRequest;
36
38class SecretAgent: public QObject, protected QDBusContext {37class SecretAgent: public QObject, protected QDBusContext {
39Q_OBJECT38 Q_OBJECT
39
40 friend SecretAgentAdaptor;
41 friend SecretRequest;
4042
41public:43public:
42 typedef std::shared_ptr<SecretAgent> Ptr;44 typedef std::shared_ptr<SecretAgent> Ptr;
43 typedef std::unique_ptr<SecretAgent> UPtr;45 typedef std::unique_ptr<SecretAgent> UPtr;
4446
45 static const QString CONNECTION_SETTING_NAME;47 static constexpr char const* CONNECTION_SETTING_NAME = "connection";
46 static const QString WIRELESS_SECURITY_SETTING_NAME;48 static constexpr char const* WIRELESS_SECURITY_SETTING_NAME = "802-11-wireless-security";
4749
48 static const QString CONNECTION_ID;50 static constexpr char const* CONNECTION_ID = "id";
4951
50 static const QString WIRELESS_SECURITY_PSK;52 static constexpr char const* WIRELESS_SECURITY_PSK = "psk";
51 static const QString WIRELESS_SECURITY_WEP_KEY0;53 static constexpr char const* WIRELESS_SECURITY_WEP_KEY0 = "wep-key0";
5254
53 static const QString WIRELESS_SECURITY_KEY_MGMT;55 static constexpr char const* WIRELESS_SECURITY_KEY_MGMT = "key-mgmt";
5456
55 static const QString KEY_MGMT_WPA_NONE;57 static constexpr char const* KEY_MGMT_WPA_NONE = "wpa-none";
56 static const QString KEY_MGMT_WPA_PSK;58 static constexpr char const* KEY_MGMT_WPA_PSK = "wpa-psk";
57 static const QString KEY_MGMT_NONE;59 static constexpr char const* KEY_MGMT_NONE = "none";
5860
59 explicit SecretAgent(const QDBusConnection &systemConnection,61 explicit SecretAgent(const QDBusConnection &systemConnection,
60 const QDBusConnection &sessionConnection, QObject *parent = 0);62 const QDBusConnection &sessionConnection, QObject *parent = 0);
6163
62 virtual ~SecretAgent();64 virtual ~SecretAgent();
6365
64public Q_SLOTS:66protected Q_SLOTS:
65 QVariantDictMap GetSecrets(const QVariantDictMap &connection,67 QVariantDictMap GetSecrets(const QVariantDictMap &connection,
66 const QDBusObjectPath &connectionPath, const QString &settingName,68 const QDBusObjectPath &connectionPath, const QString &settingName,
67 const QStringList &hints, uint flags);69 const QStringList &hints, uint flags);
@@ -79,24 +81,9 @@
7981
80 OrgFreedesktopNotificationsInterface & notifications();82 OrgFreedesktopNotificationsInterface & notifications();
8183
82protected Q_SLOTS:
83 void serviceOwnerChanged(const QString &name, const QString &oldOwner,
84 const QString &newOwner);
85
86protected:84protected:
87 QScopedPointer<SecretAgentAdaptor> m_adaptor;85 class Priv;
8886 std::shared_ptr<Priv> d;
89 QDBusConnection m_systemConnection;
90
91 QDBusConnection m_sessionConnection;
92
93 QDBusServiceWatcher m_managerWatcher;
94
95 OrgFreedesktopNetworkManagerAgentManagerInterface m_agentManager;
96
97 OrgFreedesktopNotificationsInterface m_notifications;
98
99 std::shared_ptr<SecretRequest> m_request;
100};87};
10188
102}89}
10390
=== modified file 'src/indicator/agent/SecretAgentInclude.h'
--- src/indicator/agent/SecretAgentInclude.h 2015-04-23 13:23:11 +0000
+++ src/indicator/agent/SecretAgentInclude.h 2015-04-23 13:23:11 +0000
@@ -18,6 +18,6 @@
1818
19#pragma once19#pragma once
2020
21#include <DBusTypes.h>21#include <dbus-types.h>
22#include <agent/SecretAgent.h>22#include <agent/SecretAgent.h>
2323
2424
=== modified file 'src/indicator/agent/SecretRequest.cpp'
--- src/indicator/agent/SecretRequest.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/agent/SecretRequest.cpp 2015-04-23 13:23:11 +0000
@@ -20,6 +20,8 @@
20#include <agent/SecretAgent.h>20#include <agent/SecretAgent.h>
21#include <util/localisation.h>21#include <util/localisation.h>
2222
23#include <NotificationsInterface.h>
24
23namespace agent25namespace agent
24{26{
2527
2628
=== modified file 'src/indicator/agent/SecretRequest.h'
--- src/indicator/agent/SecretRequest.h 2015-04-23 13:23:11 +0000
+++ src/indicator/agent/SecretRequest.h 2015-04-23 13:23:11 +0000
@@ -18,7 +18,7 @@
1818
19#pragma once19#pragma once
2020
21#include <DBusTypes.h>21#include <dbus-types.h>
22#include <agent/PasswordMenu.h>22#include <agent/PasswordMenu.h>
2323
24#include <QDBusMessage>24#include <QDBusMessage>
2525
=== modified file 'src/indicator/connectivity-service/connectivity-service.cpp'
--- src/indicator/connectivity-service/connectivity-service.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/connectivity-service/connectivity-service.cpp 2015-04-23 13:23:11 +0000
@@ -20,7 +20,7 @@
20#include <connectivity-service/connectivity-service.h>20#include <connectivity-service/connectivity-service.h>
21#include <NetworkingStatusAdaptor.h>21#include <NetworkingStatusAdaptor.h>
22#include <NetworkingStatusPrivateAdaptor.h>22#include <NetworkingStatusPrivateAdaptor.h>
23#include <DBusTypes.h>23#include <dbus-types.h>
2424
25using namespace nmofono;25using namespace nmofono;
26using namespace std;26using namespace std;
@@ -69,6 +69,27 @@
69 }69 }
7070
71public Q_SLOTS:71public Q_SLOTS:
72 void flightModeUpdated()
73 {
74 notifyPropertyChanged(DBusTypes::SERVICE_PATH,
75 DBusTypes::SERVICE_INTERFACE,
76 { "FlightMode" });
77 }
78
79 void wifiEnabledUpdated()
80 {
81 notifyPropertyChanged(DBusTypes::SERVICE_PATH,
82 DBusTypes::SERVICE_INTERFACE,
83 { "WifiEnabled" });
84 }
85
86 void unstoppableOperationHappeningUpdated()
87 {
88 notifyPropertyChanged(DBusTypes::SERVICE_PATH,
89 DBusTypes::SERVICE_INTERFACE,
90 { "UnstoppableOperationHappening" });
91 }
92
72 void updateNetworkingStatus()93 void updateNetworkingStatus()
73 {94 {
74 QStringList changed;95 QStringList changed;
@@ -125,6 +146,9 @@
125146
126 connect(d->m_manager.get(), &Manager::characteristicsUpdated, d.get(), &Private::updateNetworkingStatus);147 connect(d->m_manager.get(), &Manager::characteristicsUpdated, d.get(), &Private::updateNetworkingStatus);
127 connect(d->m_manager.get(), &Manager::statusUpdated, d.get(), &Private::updateNetworkingStatus);148 connect(d->m_manager.get(), &Manager::statusUpdated, d.get(), &Private::updateNetworkingStatus);
149 connect(d->m_manager.get(), &Manager::flightModeUpdated, d.get(), &Private::flightModeUpdated);
150 connect(d->m_manager.get(), &Manager::wifiEnabledUpdated, d.get(), &Private::wifiEnabledUpdated);
151 connect(d->m_manager.get(), &Manager::unstoppableOperationHappeningUpdated, d.get(), &Private::unstoppableOperationHappeningUpdated);
128152
129 d->updateNetworkingStatus();153 d->updateNetworkingStatus();
130154
@@ -160,6 +184,21 @@
160 return d->m_status;184 return d->m_status;
161}185}
162186
187bool ConnectivityService::wifiEnabled() const
188{
189 return d->m_manager->wifiEnabled();
190}
191
192bool ConnectivityService::flightMode() const
193{
194 return (d->m_manager->flightMode() == Manager::FlightModeStatus::on);
195}
196
197bool ConnectivityService::unstoppableOperationHappening() const
198{
199 return d->m_manager->unstoppableOperationHappening();
200}
201
163PrivateService::PrivateService(ConnectivityService& parent) :202PrivateService::PrivateService(ConnectivityService& parent) :
164 p(parent)203 p(parent)
165{204{
@@ -177,6 +216,16 @@
177 Q_EMIT p.unlockModem(modem);216 Q_EMIT p.unlockModem(modem);
178}217}
179218
219void PrivateService::SetFlightMode(bool enabled)
220{
221 p.d->m_manager->setFlightMode(enabled);
222}
223
224void PrivateService::SetWifiEnabled(bool enabled)
225{
226 p.d->m_manager->setWifiEnabled(enabled);
227}
228
180}229}
181230
182#include "connectivity-service.moc"231#include "connectivity-service.moc"
183232
=== modified file 'src/indicator/connectivity-service/connectivity-service.h'
--- src/indicator/connectivity-service/connectivity-service.h 2015-04-23 13:23:11 +0000
+++ src/indicator/connectivity-service/connectivity-service.h 2015-04-23 13:23:11 +0000
@@ -50,6 +50,15 @@
50 Q_PROPERTY(QString Status READ status)50 Q_PROPERTY(QString Status READ status)
51 QString status() const;51 QString status() const;
5252
53 Q_PROPERTY(bool WifiEnabled READ wifiEnabled)
54 bool wifiEnabled() const;
55
56 Q_PROPERTY(bool FlightMode READ flightMode)
57 bool flightMode() const;
58
59 Q_PROPERTY(bool UnstoppableOperationHappening READ unstoppableOperationHappening)
60 bool unstoppableOperationHappening() const;
61
53Q_SIGNALS:62Q_SIGNALS:
54 void unlockAllModems();63 void unlockAllModems();
5564
@@ -76,6 +85,10 @@
7685
77 void UnlockModem(const QString &modem);86 void UnlockModem(const QString &modem);
7887
88 void SetFlightMode(bool enabled);
89
90 void SetWifiEnabled(bool enabled);
91
79protected:92protected:
80 ConnectivityService& p;93 ConnectivityService& p;
81};94};
8295
=== modified file 'src/indicator/main.cpp'
--- src/indicator/main.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/main.cpp 2015-04-23 13:23:11 +0000
@@ -19,7 +19,7 @@
1919
20#include <factory.h>20#include <factory.h>
21#include <util/unix-signal-handler.h>21#include <util/unix-signal-handler.h>
22#include <DBusTypes.h>22#include <dbus-types.h>
2323
24#include <QCoreApplication>24#include <QCoreApplication>
2525
@@ -38,6 +38,7 @@
38{38{
39 QCoreApplication app(argc, argv);39 QCoreApplication app(argc, argv);
40 DBusTypes::registerMetaTypes();40 DBusTypes::registerMetaTypes();
41 Variant::registerMetaTypes();
4142
42 util::UnixSignalHandler handler([]{43 util::UnixSignalHandler handler([]{
43 QCoreApplication::exit(0);44 QCoreApplication::exit(0);
@@ -60,8 +61,8 @@
60 {61 {
61 Factory factory;62 Factory factory;
62 auto menu = factory.newMenuBuilder();63 auto menu = factory.newMenuBuilder();
64 auto secretAgent = factory.newSecretAgent();
63 auto connectivityService = factory.newConnectivityService();65 auto connectivityService = factory.newConnectivityService();
64 auto secretAgent = factory.newSecretAgent();
6566
66 QObject::connect(connectivityService.get(), &ConnectivityService::unlockAllModems, menu.get(), &MenuBuilder::unlockAllModems);67 QObject::connect(connectivityService.get(), &ConnectivityService::unlockAllModems, menu.get(), &MenuBuilder::unlockAllModems);
67 QObject::connect(connectivityService.get(), &ConnectivityService::unlockModem, menu.get(), &MenuBuilder::unlockModem);68 QObject::connect(connectivityService.get(), &ConnectivityService::unlockModem, menu.get(), &MenuBuilder::unlockModem);
6869
=== modified file 'src/indicator/nmofono/kill-switch.cpp'
--- src/indicator/nmofono/kill-switch.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/nmofono/kill-switch.cpp 2015-04-23 13:23:11 +0000
@@ -20,14 +20,11 @@
2020
21#include <nmofono/kill-switch.h>21#include <nmofono/kill-switch.h>
22#include <backend-utils.h>22#include <backend-utils.h>
23#include <dbus-types.h>
2324
24#include <URfkillInterface.h>25#include <URfkillInterface.h>
25#include <URfkillKillswitchInterface.h>26#include <URfkillKillswitchInterface.h>
2627
27static QString const cBusName = "org.freedesktop.URfkill";
28static QString const cURfkillPath = "/org/freedesktop/URfkill";
29static QString const cURfkillKillswitchPath = "/org/freedesktop/URfkill/WLAN";
30
31namespace nmofono28namespace nmofono
32{29{
3330
@@ -60,12 +57,12 @@
6057
61KillSwitch::KillSwitch(const QDBusConnection& systemBus)58KillSwitch::KillSwitch(const QDBusConnection& systemBus)
62{59{
63 auto urfkill = std::make_shared<OrgFreedesktopURfkillInterface>(cBusName,60 auto urfkill = std::make_shared<OrgFreedesktopURfkillInterface>(DBusTypes::URFKILL_BUS_NAME,
64 cURfkillPath,61 DBusTypes::URFKILL_OBJ_PATH,
65 systemBus);62 systemBus);
6663
67 auto killSwitch = std::make_shared<OrgFreedesktopURfkillKillswitchInterface>(cBusName,64 auto killSwitch = std::make_shared<OrgFreedesktopURfkillKillswitchInterface>(DBusTypes::URFKILL_BUS_NAME,
68 cURfkillKillswitchPath,65 DBusTypes::URFKILL_WIFI_OBJ_PATH,
69 systemBus);66 systemBus);
7067
71 connect(urfkill.get(), SIGNAL(FlightModeChanged(bool)), this, SLOT(setFlightMode(bool)));68 connect(urfkill.get(), SIGNAL(FlightModeChanged(bool)), this, SLOT(setFlightMode(bool)));
7269
=== modified file 'src/indicator/nmofono/manager-impl.cpp'
--- src/indicator/nmofono/manager-impl.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/nmofono/manager-impl.cpp 2015-04-23 13:23:11 +0000
@@ -53,12 +53,13 @@
53 shared_ptr<QOfonoManager> m_ofono;53 shared_ptr<QOfonoManager> m_ofono;
5454
55 Manager::FlightModeStatus m_flightMode = FlightModeStatus::on;55 Manager::FlightModeStatus m_flightMode = FlightModeStatus::on;
56 bool m_unstoppableOperationHappening = false;
56 Manager::NetworkingStatus m_status = NetworkingStatus::offline;57 Manager::NetworkingStatus m_status = NetworkingStatus::offline;
57 uint32_t m_characteristics = 0;58 uint32_t m_characteristics = 0;
5859
59 bool m_hasWifi = false;60 bool m_hasWifi = false;
60 bool m_wifiEnabled = false;61 bool m_wifiEnabled = false;
61 KillSwitch::Ptr m_wifiKillSwitch;62 KillSwitch::Ptr m_killSwitch;
6263
63 QSet<Link::Ptr> m_nmLinks;64 QSet<Link::Ptr> m_nmLinks;
64 QMap<QString, wwan::Modem::Ptr> m_ofonoLinks;65 QMap<QString, wwan::Modem::Ptr> m_ofonoLinks;
@@ -71,13 +72,24 @@
71 {72 {
72 }73 }
7374
75 void setUnstoppableOperationHappening(bool happening)
76 {
77 if (m_unstoppableOperationHappening == happening)
78 {
79 return;
80 }
81
82 m_unstoppableOperationHappening = happening;
83 Q_EMIT p.unstoppableOperationHappeningUpdated(m_unstoppableOperationHappening);
84 }
85
74public Q_SLOTS:86public Q_SLOTS:
75 void updateHasWifi()87 void updateHasWifi()
76 {88 {
77 if (m_wifiKillSwitch->state() != KillSwitch::State::not_available)89 if (m_killSwitch->state() != KillSwitch::State::not_available)
78 {90 {
79 m_hasWifi = true;91 m_hasWifi = true;
80 if (m_wifiKillSwitch->state() == KillSwitch::State::unblocked)92 if (m_killSwitch->state() == KillSwitch::State::unblocked)
81 {93 {
82 m_wifiEnabled = true;94 m_wifiEnabled = true;
83 }95 }
@@ -107,15 +119,15 @@
107119
108 void setFlightMode(bool flightMode)120 void setFlightMode(bool flightMode)
109 {121 {
110 if (flightMode)122 FlightModeStatus newStatus =
111 {123 flightMode ? FlightModeStatus::on : FlightModeStatus::off;
112 m_flightMode = Manager::FlightModeStatus::on;124
113 }125 if (m_flightMode == newStatus)
114 else126 {
115 {127 return;
116 m_flightMode = Manager::FlightModeStatus::off;128 }
117 }129
118130 m_flightMode = newStatus;
119 Q_EMIT p.flightModeUpdated(m_flightMode);131 Q_EMIT p.flightModeUpdated(m_flightMode);
120 }132 }
121133
@@ -212,8 +224,8 @@
212 /// @todo offload the initialization to a thread or something224 /// @todo offload the initialization to a thread or something
213 /// @todo those Id() thingies225 /// @todo those Id() thingies
214226
215 d->m_wifiKillSwitch = make_shared<KillSwitch>(systemConnection);227 d->m_killSwitch = make_shared<KillSwitch>(systemConnection);
216 connect(d->m_wifiKillSwitch.get(), &KillSwitch::stateChanged, d.get(), &Private::updateHasWifi);228 connect(d->m_killSwitch.get(), &KillSwitch::stateChanged, d.get(), &Private::updateHasWifi);
217229
218 connect(d->nm.get(), &OrgFreedesktopNetworkManagerInterface::DeviceAdded, this, &ManagerImpl::device_added);230 connect(d->nm.get(), &OrgFreedesktopNetworkManagerInterface::DeviceAdded, this, &ManagerImpl::device_added);
219 QList<QDBusObjectPath> devices(d->nm->GetDevices());231 QList<QDBusObjectPath> devices(d->nm->GetDevices());
@@ -225,10 +237,10 @@
225 updateNetworkingStatus(d->nm->state());237 updateNetworkingStatus(d->nm->state());
226 connect(d->nm.get(), &OrgFreedesktopNetworkManagerInterface::PropertiesChanged, this, &ManagerImpl::nm_properties_changed);238 connect(d->nm.get(), &OrgFreedesktopNetworkManagerInterface::PropertiesChanged, this, &ManagerImpl::nm_properties_changed);
227239
228 connect(d->m_wifiKillSwitch.get(), &KillSwitch::flightModeChanged, d.get(), &Private::setFlightMode);240 connect(d->m_killSwitch.get(), &KillSwitch::flightModeChanged, d.get(), &Private::setFlightMode);
229 try241 try
230 {242 {
231 d->setFlightMode(d->m_wifiKillSwitch->isFlightMode());243 d->setFlightMode(d->m_killSwitch->isFlightMode());
232 }244 }
233 catch (exception const& e)245 catch (exception const& e)
234 {246 {
@@ -299,7 +311,7 @@
299 if (dev->deviceType() == NM_DEVICE_TYPE_WIFI) {311 if (dev->deviceType() == NM_DEVICE_TYPE_WIFI) {
300 link = make_shared<wifi::WifiLinkImpl>(dev,312 link = make_shared<wifi::WifiLinkImpl>(dev,
301 d->nm,313 d->nm,
302 d->m_wifiKillSwitch);314 d->m_killSwitch);
303 }315 }
304 } catch (const exception &e) {316 } catch (const exception &e) {
305 qDebug() << __PRETTY_FUNCTION__ << ": failed to create Device proxy for "<< path.path() << ": ";317 qDebug() << __PRETTY_FUNCTION__ << ": failed to create Device proxy for "<< path.path() << ": ";
@@ -318,27 +330,23 @@
318330
319331
320void332void
321ManagerImpl::enableFlightMode()333ManagerImpl::setFlightMode(bool enabled)
322{334{
323#ifdef INDICATOR_NETWORK_TRACE_MESSAGES335#ifdef INDICATOR_NETWORK_TRACE_MESSAGES
324 cout << __PRETTY_FUNCTION__ << endl;336 qDebug() << __PRETTY_FUNCTION__ << enabled;
325#endif337#endif
326 if (!d->m_wifiKillSwitch->flightMode(true))338 if (enabled == d->m_killSwitch->isFlightMode())
327 {339 {
328 qWarning() << "Failed to enable flightmode.";340 return;
329 }341 }
330}342
331343 d->setUnstoppableOperationHappening(true);
332void344
333ManagerImpl::disableFlightMode()345 if (!d->m_killSwitch->flightMode(enabled))
334{346 {
335#ifdef INDICATOR_NETWORK_TRACE_MESSAGES347 qWarning() << "Failed to change flightmode.";
336 cout << __PRETTY_FUNCTION__ << endl;348 }
337#endif349 d->setUnstoppableOperationHappening(false);
338 if (!d->m_wifiKillSwitch->flightMode(false))
339 {
340 qWarning() << "Failed to disable flightmode";
341 }
342}350}
343351
344Manager::FlightModeStatus352Manager::FlightModeStatus
@@ -350,6 +358,12 @@
350 return d->m_flightMode;358 return d->m_flightMode;
351}359}
352360
361bool
362ManagerImpl::unstoppableOperationHappening() const
363{
364 return d->m_unstoppableOperationHappening;
365}
366
353QSet<Link::Ptr>367QSet<Link::Ptr>
354ManagerImpl::links() const368ManagerImpl::links() const
355{369{
@@ -387,57 +401,47 @@
387401
388402
389bool403bool
390ManagerImpl::enableWifi()404ManagerImpl::setWifiEnabled(bool enabled)
391{405{
392 if (!d->m_hasWifi)406 if (!d->m_hasWifi)
393 {407 {
394 return false;408 return false;
395 }409 }
396410
397 if (d->m_wifiEnabled)411 if (d->m_wifiEnabled == enabled)
398 {412 {
399 return false;413 return false;
400 }414 }
401415
416 bool success = true;
417 d->setUnstoppableOperationHappening(true);
418
402 try419 try
403 {420 {
404 if (d->m_wifiKillSwitch->state() == KillSwitch::State::soft_blocked)421 if (enabled)
405 {422 {
406 // try to unblock. throws if fails.423 if (d->m_killSwitch->state() == KillSwitch::State::soft_blocked)
407 d->m_wifiKillSwitch->unblock();424 {
408 }425 // try to unblock. throws if fails.
409 d->nm->setWirelessEnabled(true);426 d->m_killSwitch->unblock();
410 } catch(runtime_error &e) {427 }
428 }
429 else
430 {
431 if (d->m_killSwitch->state() == KillSwitch::State::unblocked) {
432 // block the device. that will disable it also
433 d->m_killSwitch->block();
434 }
435 }
436 d->nm->setWirelessEnabled(enabled);
437 }
438 catch (runtime_error &e)
439 {
411 qWarning() << __PRETTY_FUNCTION__ << ": " << e.what();440 qWarning() << __PRETTY_FUNCTION__ << ": " << e.what();
412 return false;441 success = false;
413 }442 }
414 return true;443 d->setUnstoppableOperationHappening(false);
415}444 return success;
416
417bool
418ManagerImpl::disableWifi()
419{
420 if (!d->m_hasWifi)
421 {
422 return false;
423 }
424
425 if (!d->m_wifiEnabled)
426 {
427 return false;
428 }
429
430 try {
431 if (d->m_wifiKillSwitch->state() == KillSwitch::State::unblocked) {
432 // block the device. that will disable it also
433 d->m_wifiKillSwitch->block();
434 }
435 d->nm->setWirelessEnabled(false);
436 } catch(runtime_error &e) {
437 cerr << __PRETTY_FUNCTION__ << ": " << e.what() << endl;
438 return false;
439 }
440 return true;
441}445}
442446
443bool447bool
444448
=== modified file 'src/indicator/nmofono/manager-impl.h'
--- src/indicator/nmofono/manager-impl.h 2015-04-23 13:23:11 +0000
+++ src/indicator/nmofono/manager-impl.h 2015-04-23 13:23:11 +0000
@@ -42,15 +42,15 @@
42 ManagerImpl(const QDBusConnection& systemBus);42 ManagerImpl(const QDBusConnection& systemBus);
4343
44 // Public API44 // Public API
45 void enableFlightMode() override;45 void setFlightMode(bool) override;
46 void disableFlightMode() override;
47 Manager::FlightModeStatus flightMode() const override;46 Manager::FlightModeStatus flightMode() const override;
4847
48 bool unstoppableOperationHappening() const override;
49
49 bool hasWifi() const override;50 bool hasWifi() const override;
50 bool wifiEnabled() const override;51 bool wifiEnabled() const override;
5152
52 bool enableWifi() override;53 bool setWifiEnabled(bool) override;
53 bool disableWifi() override;
5454
55 bool roaming() const override;55 bool roaming() const override;
5656
5757
=== modified file 'src/indicator/nmofono/manager.h'
--- src/indicator/nmofono/manager.h 2015-04-23 13:23:11 +0000
+++ src/indicator/nmofono/manager.h 2015-04-23 13:23:11 +0000
@@ -81,15 +81,12 @@
81 };81 };
8282
83 /// @private83 /// @private
84 virtual void enableFlightMode() = 0;
85
86 /// @private
87 virtual void disableFlightMode() = 0;
88
89 /// @private
90 Q_PROPERTY(Manager::FlightModeStatus flightMode READ flightMode NOTIFY flightModeUpdated)84 Q_PROPERTY(Manager::FlightModeStatus flightMode READ flightMode NOTIFY flightModeUpdated)
91 virtual FlightModeStatus flightMode() const = 0;85 virtual FlightModeStatus flightMode() const = 0;
9286
87 Q_PROPERTY(bool unstoppableOperationHappening READ unstoppableOperationHappening NOTIFY unstoppableOperationHappeningUpdated)
88 virtual bool unstoppableOperationHappening() const = 0;
89
93 /// @private90 /// @private
94 Q_PROPERTY(QSet<Link::Ptr> links READ links NOTIFY linksUpdated)91 Q_PROPERTY(QSet<Link::Ptr> links READ links NOTIFY linksUpdated)
95 virtual QSet<Link::Ptr> links() const = 0;92 virtual QSet<Link::Ptr> links() const = 0;
@@ -123,10 +120,6 @@
123 Q_PROPERTY(bool wifiEnabled READ wifiEnabled NOTIFY wifiEnabledUpdated)120 Q_PROPERTY(bool wifiEnabled READ wifiEnabled NOTIFY wifiEnabledUpdated)
124 virtual bool wifiEnabled() const = 0;121 virtual bool wifiEnabled() const = 0;
125122
126 virtual bool enableWifi() = 0;
127
128 virtual bool disableWifi() = 0;
129
130 virtual bool roaming() const = 0;123 virtual bool roaming() const = 0;
131124
132 virtual void unlockModem(wwan::Modem::Ptr modem) = 0;125 virtual void unlockModem(wwan::Modem::Ptr modem) = 0;
@@ -148,6 +141,13 @@
148141
149 void wifiEnabledUpdated(bool);142 void wifiEnabledUpdated(bool);
150143
144 void unstoppableOperationHappeningUpdated(bool);
145
146public Q_SLOTS:
147 virtual bool setWifiEnabled(bool) = 0;
148
149 virtual void setFlightMode(bool) = 0;
150
151protected:151protected:
152 /**152 /**
153 * @brief The default constructor is protected.153 * @brief The default constructor is protected.
154154
=== modified file 'src/indicator/sections/quick-access-section.cpp'
--- src/indicator/sections/quick-access-section.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/sections/quick-access-section.cpp 2015-04-23 13:23:11 +0000
@@ -48,6 +48,18 @@
48 Private(Manager::Ptr manager, SwitchItem::Ptr wifiSwitch);48 Private(Manager::Ptr manager, SwitchItem::Ptr wifiSwitch);
4949
50public Q_SLOTS:50public Q_SLOTS:
51 void unstoppableOperationHappeningUpdated(bool happening)
52 {
53 m_flightModeSwitch->setEnabled(!happening);
54 m_wifiSwitch->setEnabled(!happening);
55
56 if (happening)
57 {
58 // Give the GActionGroup a chance to emit its Changed signal
59 runGMainloop();
60 }
61 }
62
51 void flightModeUpdated(Manager::FlightModeStatus value)63 void flightModeUpdated(Manager::FlightModeStatus value)
52 {64 {
53 switch (value) {65 switch (value) {
@@ -59,32 +71,6 @@
59 break;71 break;
60 }72 }
61 }73 }
62
63 void flightModeSwitchActivated(bool state)
64 {
65 m_flightModeSwitch->setEnabled(false);
66 m_wifiSwitch->setEnabled(false);
67
68 // Give the GActionGroup a change to emit its Changed signal
69 runGMainloop();
70
71 if (state) {
72 try {
73 m_manager->enableFlightMode();
74 } catch (const std::exception &e) {
75 std::cerr << e.what() << std::endl;
76 }
77 } else {
78 try {
79 m_manager->disableFlightMode();
80 } catch (const std::exception &e) {
81 std::cerr << e.what() << std::endl;
82 }
83 }
84
85 m_flightModeSwitch->setEnabled(true);
86 m_wifiSwitch->setEnabled(true);
87 }
88};74};
8975
90QuickAccessSection::Private::Private(Manager::Ptr manager,76QuickAccessSection::Private::Private(Manager::Ptr manager,
@@ -97,10 +83,15 @@
97 m_flightModeSwitch = std::make_shared<SwitchItem>(_("Flight Mode"), "airplane", "enabled");83 m_flightModeSwitch = std::make_shared<SwitchItem>(_("Flight Mode"), "airplane", "enabled");
98 flightModeUpdated(m_manager->flightMode());84 flightModeUpdated(m_manager->flightMode());
99 connect(m_manager.get(), &Manager::flightModeUpdated, this, &Private::flightModeUpdated);85 connect(m_manager.get(), &Manager::flightModeUpdated, this, &Private::flightModeUpdated);
100 connect(m_flightModeSwitch.get(), &SwitchItem::stateUpdated, this, &Private::flightModeSwitchActivated);86 connect(m_flightModeSwitch.get(), &SwitchItem::stateUpdated, m_manager.get(), &Manager::setFlightMode);
10187
102 m_actionGroupMerger->add(m_flightModeSwitch->actionGroup());88 m_actionGroupMerger->add(m_flightModeSwitch->actionGroup());
103 m_menu->append(m_flightModeSwitch->menuItem());89 m_menu->append(m_flightModeSwitch->menuItem());
90
91 // Connect the unstoppable operation property to the toggle enabled properties
92 // Make sure we don't also connect this signal in the wifi-section.cpp
93 connect(m_manager.get(), &Manager::unstoppableOperationHappeningUpdated,
94 this, &Private::unstoppableOperationHappeningUpdated);
104}95}
10596
106QuickAccessSection::QuickAccessSection(Manager::Ptr manager, SwitchItem::Ptr wifiSwitch)97QuickAccessSection::QuickAccessSection(Manager::Ptr manager, SwitchItem::Ptr wifiSwitch)
10798
=== modified file 'src/indicator/sections/wifi-section.cpp'
--- src/indicator/sections/wifi-section.cpp 2015-04-23 13:23:11 +0000
+++ src/indicator/sections/wifi-section.cpp 2015-04-23 13:23:11 +0000
@@ -67,7 +67,7 @@
6767
68 m_switch->setState(m_manager->wifiEnabled());68 m_switch->setState(m_manager->wifiEnabled());
69 connect(m_manager.get(), &Manager::wifiEnabledUpdated, m_switch.get(), &SwitchItem::setState);69 connect(m_manager.get(), &Manager::wifiEnabledUpdated, m_switch.get(), &SwitchItem::setState);
70 connect(m_switch.get(), &SwitchItem::stateUpdated, this, &Private::switchActivated);70 connect(m_switch.get(), &SwitchItem::stateUpdated, m_manager.get(), &Manager::setWifiEnabled);
7171
72 m_openWifiSettings = std::make_shared<TextItem>(_("Wi-Fi settingsā€¦"), "wifi", "settings");72 m_openWifiSettings = std::make_shared<TextItem>(_("Wi-Fi settingsā€¦"), "wifi", "settings");
73 connect(m_openWifiSettings.get(), &TextItem::activated, this, &Private::openWiFiSettings);73 connect(m_openWifiSettings.get(), &TextItem::activated, this, &Private::openWiFiSettings);
@@ -115,18 +115,6 @@
115 break;115 break;
116 }116 }
117 }117 }
118
119 void switchActivated(bool state)
120 {
121 m_switch->setEnabled(false);
122 runGMainloop();
123 if (state) {
124 m_manager->enableWifi();
125 } else {
126 m_manager->disableWifi();
127 }
128 m_switch->setEnabled(true);
129 }
130};118};
131119
132WifiSection::WifiSection(Manager::Ptr manager)120WifiSection::WifiSection(Manager::Ptr manager)
133121
=== modified file 'src/menumodel-cpp/gio-helpers/variant.h'
--- src/menumodel-cpp/gio-helpers/variant.h 2015-04-01 08:39:34 +0000
+++ src/menumodel-cpp/gio-helpers/variant.h 2015-04-23 13:23:11 +0000
@@ -24,6 +24,7 @@
24#include <vector>24#include <vector>
25#include <memory>25#include <memory>
26#include <gio/gio.h>26#include <gio/gio.h>
27#include <QObject>
2728
28#include <cassert>29#include <cassert>
2930
@@ -31,6 +32,8 @@
3132
32class Variant;33class Variant;
3334
35Q_DECLARE_METATYPE(Variant)
36
34template<typename T>37template<typename T>
35struct Codec38struct Codec
36{39{
@@ -41,6 +44,11 @@
41class Variant44class Variant
42{45{
43public:46public:
47 static void registerMetaTypes()
48 {
49 qRegisterMetaType<Variant>("Variant");
50 }
51
44 static Variant fromGVariant(GVariant *variant) {52 static Variant fromGVariant(GVariant *variant) {
45 return Variant(variant);53 return Variant(variant);
46 }54 }
4755
=== modified file 'src/qdbus-stubs/CMakeLists.txt'
--- src/qdbus-stubs/CMakeLists.txt 2015-04-23 13:23:11 +0000
+++ src/qdbus-stubs/CMakeLists.txt 2015-04-23 13:23:11 +0000
@@ -21,8 +21,6 @@
21 "${DATA_DIR}/nm-access-point.xml"21 "${DATA_DIR}/nm-access-point.xml"
22 "${DATA_DIR}/nm-active-connection.xml"22 "${DATA_DIR}/nm-active-connection.xml"
23 "${DATA_DIR}/nm-agent-manager.xml"23 "${DATA_DIR}/nm-agent-manager.xml"
24 "${DATA_DIR}/com.ubuntu.connectivity1.NetworkingStatus.xml"
25 "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml"
26 "${DATA_DIR}/org.freedesktop.URfkill.xml"24 "${DATA_DIR}/org.freedesktop.URfkill.xml"
27 "${DATA_DIR}/org.freedesktop.URfkill.Device.xml"25 "${DATA_DIR}/org.freedesktop.URfkill.Device.xml"
28 "${DATA_DIR}/org.freedesktop.URfkill.Killswitch.xml"26 "${DATA_DIR}/org.freedesktop.URfkill.Killswitch.xml"
@@ -36,7 +34,7 @@
36 "${DATA_DIR}/org.freedesktop.Notifications.xml"34 "${DATA_DIR}/org.freedesktop.Notifications.xml"
37 PROPERTIES35 PROPERTIES
38 NO_NAMESPACE YES36 NO_NAMESPACE YES
39 INCLUDE "DBusTypes.h"37 INCLUDE "dbus-types.h"
40)38)
4139
42qt5_add_dbus_interface(40qt5_add_dbus_interface(
@@ -105,18 +103,6 @@
105 NotificationsInterface103 NotificationsInterface
106)104)
107105
108qt5_add_dbus_interface(
109 CONNECTIVITY_BACKEND_SRC
110 "${DATA_DIR}/com.ubuntu.connectivity1.NetworkingStatus.xml"
111 NetworkingStatusInterface
112)
113
114qt5_add_dbus_interface(
115 CONNECTIVITY_BACKEND_SRC
116 "${DATA_DIR}/com.ubuntu.connectivity1.Private.xml"
117 NetworkingStatusPrivateInterface
118)
119
120add_library(106add_library(
121 qdbus-stubs107 qdbus-stubs
122 STATIC108 STATIC
123109
=== renamed file 'src/qdbus-stubs/DBusTypes.h' => 'src/qdbus-stubs/dbus-types.h'
--- src/qdbus-stubs/DBusTypes.h 2015-03-23 14:46:24 +0000
+++ src/qdbus-stubs/dbus-types.h 2015-04-23 13:23:11 +0000
@@ -16,8 +16,7 @@
16 * Author: Pete Woods <pete.woods@canonical.com>16 * Author: Pete Woods <pete.woods@canonical.com>
17 */17 */
1818
19#ifndef DBUSTYPES_H_19#pragma once
20#define DBUSTYPES_H_
2120
22#include <QDBusMetaType>21#include <QDBusMetaType>
23#include <QtCore>22#include <QtCore>
@@ -27,10 +26,9 @@
27typedef QMap<QString, QVariantMap> QVariantDictMap;26typedef QMap<QString, QVariantMap> QVariantDictMap;
28Q_DECLARE_METATYPE(QVariantDictMap)27Q_DECLARE_METATYPE(QVariantDictMap)
2928
30class DBusTypes {29namespace DBusTypes
31public:30{
32 static void31 inline void registerMetaTypes()
33 registerMetaTypes()
34 {32 {
35 qRegisterMetaType<QVariantDictMap>("QVariantDictMap");33 qRegisterMetaType<QVariantDictMap>("QVariantDictMap");
3634
@@ -46,6 +44,10 @@
46 static constexpr char const* SERVICE_PATH = "/com/ubuntu/connectivity1/NetworkingStatus";44 static constexpr char const* SERVICE_PATH = "/com/ubuntu/connectivity1/NetworkingStatus";
4745
48 static constexpr char const* PRIVATE_PATH = "/com/ubuntu/connectivity1/Private";46 static constexpr char const* PRIVATE_PATH = "/com/ubuntu/connectivity1/Private";
49};47
5048 static constexpr char const* URFKILL_BUS_NAME = "org.freedesktop.URfkill";
51#endif /* DBUSTYPES_H_ */49
50 static constexpr char const* URFKILL_OBJ_PATH = "/org/freedesktop/URfkill";
51
52 static constexpr char const* URFKILL_WIFI_OBJ_PATH = "/org/freedesktop/URfkill/WLAN";
53}
5254
=== renamed file 'tests/integration/indicator/CMakeLists.txt' => 'tests/integration/CMakeLists.txt'
--- tests/integration/indicator/CMakeLists.txt 2015-02-19 11:14:56 +0000
+++ tests/integration/CMakeLists.txt 2015-04-23 13:23:11 +0000
@@ -1,9 +1,16 @@
11
2add_definitions(-DNETWORK_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator/indicator-network-service")2add_definitions(-DNETWORK_SERVICE_BIN="${CMAKE_BINARY_DIR}/src/indicator/indicator-network-service")
33
4include_directories(
5 "${CMAKE_SOURCE_DIR}/src/connectivity-api/connectivity-qt"
6 "${CMAKE_SOURCE_DIR}/src/qdbus-stubs"
7)
8
4set(9set(
5 INTEGRATION_TESTS_SRC10 INTEGRATION_TESTS_SRC
6 TestIndicatorNetworkService.cpp11 indicator-network-test-base.cpp
12 test-indicator.cpp
13 test-connectivity-api.cpp
7)14)
815
9add_executable(16add_executable(
@@ -22,6 +29,7 @@
22 integration-tests29 integration-tests
23 test-utils30 test-utils
24 menuharness31 menuharness
32 connectivity-qt
25 ${QTDBUSMOCK_LDFLAGS}33 ${QTDBUSMOCK_LDFLAGS}
26 ${QTDBUSTEST_LDFLAGS}34 ${QTDBUSTEST_LDFLAGS}
27 ${GTEST_LIBRARIES}35 ${GTEST_LIBRARIES}
2836
=== removed file 'tests/integration/CMakeLists.txt'
--- tests/integration/CMakeLists.txt 2015-03-31 10:39:35 +0000
+++ tests/integration/CMakeLists.txt 1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
1#add_subdirectory(connectivity-cpp)
2add_subdirectory(indicator)
30
=== removed directory 'tests/integration/connectivity-cpp'
=== removed file 'tests/integration/connectivity-cpp/CMakeLists.txt'
--- tests/integration/connectivity-cpp/CMakeLists.txt 2015-02-16 18:33:09 +0000
+++ tests/integration/connectivity-cpp/CMakeLists.txt 1970-01-01 00:00:00 +0000
@@ -1,130 +0,0 @@
1# Copyright Ā© 2013 Canonical Ltd.
2#
3# This program is free software: you can redistribute it and/or modify it
4# under the terms of the GNU Lesser General Public License version 3,
5# as published by the Free Software Foundation.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10# GNU Lesser General Public License for more details.
11#
12# You should have received a copy of the GNU Lesser General Public License
13# along with this program. If not, see <http://www.gnu.org/licenses/>.
14#
15# Authors:
16# Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17
18
19include_directories(${GMOCK_INCLUDE_DIR} ${GTEST_INCLUDE_DIR})
20
21if (NOT DEFINED GTEST_ROOT)
22 set(GTEST_ROOT /usr/src/gtest)
23endif()
24
25set(GTEST_SRC_DIR "${GTEST_ROOT}/src")
26set(GTEST_INCLUDE_DIR ${GTEST_ROOT})
27
28add_library(connectivity-gtest STATIC
29${GTEST_SRC_DIR}/gtest-all.cc
30${GTEST_SRC_DIR}/gtest_main.cc
31
32)
33
34set_target_properties(connectivity-gtest PROPERTIES INCLUDE_DIRECTORIES ${GTEST_INCLUDE_DIR})
35target_link_libraries(connectivity-gtest ${CMAKE_THREAD_LIBS_INIT})
36
37include_directories(${GTEST_INCLUDE_DIRS})
38
39add_definitions(-DCORE_DBUS_ENABLE_GOOGLE_TEST_FIXTURE)
40
41pkg_check_modules(PROCESS_CPP process-cpp)
42
43configure_file(
44 ${CMAKE_CURRENT_SOURCE_DIR}/test_data.h.in
45 ${CMAKE_CURRENT_BINARY_DIR}/test_data.h @ONLY
46)
47include_directories(
48 ${CMAKE_CURRENT_BINARY_DIR}
49 ${CMAKE_SOURCE_DIR}/src/connectivity-cpp/include
50 ${CMAKE_SOURCE_DIR}/src/connectivity-cpp/dbus-cpp
51)
52
53add_executable (
54 test_networking_status
55 test_networking_status.cpp
56)
57
58add_executable (
59 test_flight_mode
60 test_flight_mode.cpp
61)
62
63add_executable (
64 test_wifi_link
65 test_wifi_link.cpp
66)
67
68add_executable (
69 test_wifi_link_dedup
70 test_wifi_link_dedup.cpp
71)
72
73add_executable (
74 test_wifi_connect
75 test_wifi_connect.cpp
76)
77
78add_executable (
79 test_wifi_link_enable_disable
80 test_wifi_link_enable_disable.cpp
81)
82
83target_link_libraries(
84 test_networking_status
85 connectivity-cpp
86 connectivity-gtest
87 ${PROCESS_CPP_LIBRARIES}
88)
89
90target_link_libraries(
91 test_flight_mode
92 connectivity-cpp
93 connectivity-gtest
94 ${PROCESS_CPP_LIBRARIES}
95)
96
97target_link_libraries(
98 test_wifi_link
99 connectivity-cpp
100 connectivity-gtest
101 ${PROCESS_CPP_LIBRARIES}
102)
103
104target_link_libraries(
105 test_wifi_link_dedup
106 connectivity-cpp
107 connectivity-gtest
108 ${PROCESS_CPP_LIBRARIES}
109)
110
111target_link_libraries(
112 test_wifi_connect
113 connectivity-cpp
114 connectivity-gtest
115 ${PROCESS_CPP_LIBRARIES}
116)
117
118target_link_libraries(
119 test_wifi_link_enable_disable
120 connectivity-cpp
121 connectivity-gtest
122 ${PROCESS_CPP_LIBRARIES}
123)
124
125add_test(test_networking_status ${CMAKE_CURRENT_BINARY_DIR}/test_networking_status)
126add_test(test_flight_mode ${CMAKE_CURRENT_BINARY_DIR}/test_flight_mode)
127add_test(test_wifi_link ${CMAKE_CURRENT_BINARY_DIR}/test_wifi_link)
128add_test(test_wifi_link_dedup ${CMAKE_CURRENT_BINARY_DIR}/test_wifi_link_dedup)
129add_test(test_wifi_connect ${CMAKE_CURRENT_BINARY_DIR}/test_wifi_connect)
130add_test(test_wifi_link_enable_disable ${CMAKE_CURRENT_BINARY_DIR}/test_wifi_link_enable_disable)
1310
=== removed directory 'tests/integration/connectivity-cpp/mocks'
=== removed file 'tests/integration/connectivity-cpp/mocks/urfkill.h'
--- tests/integration/connectivity-cpp/mocks/urfkill.h 2014-08-19 19:55:15 +0000
+++ tests/integration/connectivity-cpp/mocks/urfkill.h 1970-01-01 00:00:00 +0000
@@ -1,162 +0,0 @@
1/*
2 * Copyright Ā© 2014 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17 */
18
19#ifndef MOCKS_URFKILL_H
20#define MOCKS_URFKILL_H
21
22#include <services/urfkill.h>
23
24class DefaultURfkillMock : public org::freedesktop::URfkill::Service::Mock
25{
26 typedef org::freedesktop::URfkill::Interface::Killswitch Killswitch;
27
28 bool inFlightMode;
29
30public:
31
32 DefaultURfkillMock() = delete;
33 DefaultURfkillMock(const core::dbus::Bus::Ptr& bus)
34 : org::freedesktop::URfkill::Service::Mock(bus),
35 inFlightMode{false},
36 bt{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::bluetooth)),
37 Killswitch::Type::bluetooth)},
38 fm{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::fm)),
39 Killswitch::Type::fm)},
40 gps{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::gps)),
41 Killswitch::Type::gps)},
42 nfc{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::nfc)),
43 Killswitch::Type::nfc)},
44 uwb{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::uwb)),
45 Killswitch::Type::uwb)},
46 wimax{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::wimax)),
47 Killswitch::Type::wimax)},
48 wlan{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::wlan)),
49 Killswitch::Type::wlan)},
50 wwan{Killswitch(urfkill->service->add_object_for_path(Killswitch::path(Killswitch::Type::wwan)),
51 Killswitch::Type::wwan)}
52 {
53 urfkill->object->install_method_handler
54 <org::freedesktop::URfkill::Interface::URfkill::Method::Block>
55 ([this, bus](const core::dbus::Message::Ptr& msg)
56 {
57 auto reader = msg->reader();
58
59 std::uint32_t type = reader.pop_uint32();
60 bool value = reader.pop_boolean();
61
62 auto reply = core::dbus::Message::make_method_return(msg);
63 reply->writer() << block(type, value);
64 bus->send(reply);
65 });
66
67 urfkill->object->install_method_handler
68 <org::freedesktop::URfkill::Interface::URfkill::Method::FlightMode>
69 ([this, bus](const core::dbus::Message::Ptr& msg)
70 {
71 auto reply = core::dbus::Message::make_method_return(msg);
72
73 auto reader = msg->reader();
74 bool value = reader.pop_boolean();
75
76 reply->writer() << true;
77 bus->send(reply);
78
79 if (inFlightMode != value) {
80 inFlightMode = value;
81 auto signal_flightmode_changed
82 = urfkill->object->get_signal<org::freedesktop::URfkill::Interface::URfkill::Signal::FlightModeChanged>();
83 signal_flightmode_changed->emit(inFlightMode);
84
85 block(1, inFlightMode);
86 }
87 });
88
89 urfkill->object->install_method_handler
90 <org::freedesktop::URfkill::Interface::URfkill::Method::IsFlightMode>
91 ([this, bus](const core::dbus::Message::Ptr& msg)
92 {
93 auto reply = core::dbus::Message::make_method_return(msg);
94 reply->writer() << inFlightMode;
95 bus->send(reply);
96 });
97
98 bt._state->set(0);
99 fm._state->set(0);
100 gps._state->set(0);
101 nfc._state->set(0);
102 uwb._state->set(0);
103 wimax._state->set(0);
104 wlan._state->set(0);
105 wwan._state->set(0);
106 }
107
108 bool block(std::uint32_t type, bool block)
109 {
110 switch (type) {
111 case 1:
112 {
113 if (block)
114 wlan._state->set(1); // soft blocked
115 else
116 wlan._state->set(0); // unblocked
117
118 auto signal_properties_changed
119 = wlan.object->get_signal<core::dbus::interfaces::Properties::Signals::PropertiesChanged>();
120 std::map<std::string, core::dbus::types::Variant> changed;
121 changed["state"] = core::dbus::types::TypedVariant<std::int32_t>(wlan._state->get());
122 core::dbus::interfaces::Properties::Signals::PropertiesChanged::ArgumentType args
123 (org::freedesktop::URfkill::Interface::Killswitch::name(),
124 changed,
125 {}
126 );
127 signal_properties_changed->emit(args);
128 break;
129 }
130 case 2:
131 //Killswitch::Type::bluetooth
132 case 3:
133 //Killswitch::Type::uwb
134 case 4:
135 //Killswitch::Type::wimax
136 case 5:
137 //Killswitch::Type::wwan
138 case 6:
139 //Killswitch::Type::gps
140 case 7:
141 //Killswitch::Type::fm
142 case 8:
143 //Killswitch::Type::nfc
144 break;
145 default:
146 std::logic_error("Unknown killswitch id: " + std::to_string(type));
147 }
148
149 return true;
150 }
151
152 org::freedesktop::URfkill::Interface::Killswitch bt;
153 org::freedesktop::URfkill::Interface::Killswitch fm;
154 org::freedesktop::URfkill::Interface::Killswitch gps;
155 org::freedesktop::URfkill::Interface::Killswitch nfc;
156 org::freedesktop::URfkill::Interface::Killswitch uwb;
157 org::freedesktop::URfkill::Interface::Killswitch wimax;
158 org::freedesktop::URfkill::Interface::Killswitch wlan;
159 org::freedesktop::URfkill::Interface::Killswitch wwan;
160};
161
162#endif
1630
=== removed file 'tests/integration/connectivity-cpp/sig_term_catcher.h'
--- tests/integration/connectivity-cpp/sig_term_catcher.h 2014-08-19 19:55:15 +0000
+++ tests/integration/connectivity-cpp/sig_term_catcher.h 1970-01-01 00:00:00 +0000
@@ -1,74 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas VoƟ <thomas.voss@canonical.com>
17 */
18
19#ifndef CORE_TESTING_SIG_TERM_CATCHER_H_
20#define CORE_TESTING_SIG_TERM_CATCHER_H_
21
22#include <system_error>
23
24#include <signal.h>
25#include <unistd.h>
26#include <poll.h>
27#include <sys/signalfd.h>
28
29namespace core
30{
31namespace testing
32{
33struct SigTermCatcher
34{
35 inline SigTermCatcher()
36 {
37 sigemptyset(&signal_mask);
38
39 if (-1 == sigaddset(&signal_mask, SIGTERM))
40 throw std::system_error(errno, std::system_category());
41
42 if (-1 == sigprocmask(SIG_BLOCK, &signal_mask, NULL))
43 throw std::system_error(errno, std::system_category());
44
45 if (-1 == (signal_fd = signalfd(-1, &signal_mask, 0)))
46 throw std::system_error(errno, std::system_category());
47 }
48
49 inline ~SigTermCatcher()
50 {
51 ::close(signal_fd);
52 }
53
54 inline void wait_for_signal_for(const std::chrono::milliseconds& ms)
55 {
56 pollfd fd; fd.fd = signal_fd; fd.events = POLLIN;
57 if (poll(&fd, 1, ms.count()) > 0)
58 {
59 signalfd_siginfo siginfo;
60 if (-1 == ::read(signal_fd, &siginfo, sizeof(siginfo)))
61 throw std::system_error(errno, std::system_category());
62 } else
63 {
64 throw std::system_error(errno, std::system_category());
65 }
66 }
67
68 sigset_t signal_mask;
69 int signal_fd = -1;
70};
71}
72}
73
74#endif // CORE_TESTING_SIG_TERM_CATCHER_H_
750
=== removed file 'tests/integration/connectivity-cpp/test_data.h.in'
--- tests/integration/connectivity-cpp/test_data.h.in 2014-08-19 20:17:22 +0000
+++ tests/integration/connectivity-cpp/test_data.h.in 1970-01-01 00:00:00 +0000
@@ -1,38 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas VoƟ <thomas.voss@canonical.com>
17 */
18
19#ifndef TEST_DATA_H_
20#define TEST_DATA_H_
21
22namespace core
23{
24namespace testing
25{
26
27constexpr const char* session_bus_configuration_file()
28{
29 return "@CMAKE_SOURCE_DIR@/src/connectivity-cpp/data/session.conf";
30}
31
32constexpr const char* system_bus_configuration_file()
33{
34 return "@CMAKE_SOURCE_DIR@/src/connectivity-cpp/data/system.conf";
35}
36}
37}
38#endif // TEST_DATA_H_
390
=== removed file 'tests/integration/connectivity-cpp/test_flight_mode.cpp'
--- tests/integration/connectivity-cpp/test_flight_mode.cpp 2014-08-19 19:55:15 +0000
+++ tests/integration/connectivity-cpp/test_flight_mode.cpp 1970-01-01 00:00:00 +0000
@@ -1,138 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17 */
18
19#include <core/dbus/dbus.h>
20#include <core/dbus/fixture.h>
21#include <core/dbus/object.h>
22#include <core/dbus/property.h>
23#include <core/dbus/service.h>
24#include <core/dbus/interfaces/properties.h>
25#include <core/dbus/types/stl/tuple.h>
26#include <core/dbus/types/stl/vector.h>
27
28#include <core/dbus/asio/executor.h>
29
30#include "sig_term_catcher.h"
31#include "test_data.h"
32#include "test_service.h"
33
34#include <core/testing/cross_process_sync.h>
35#include <core/testing/fork_and_run.h>
36
37#include <gtest/gtest.h>
38
39#include <system_error>
40#include <thread>
41
42#include <services/nm.h>
43#include "mocks/urfkill.h"
44namespace fdo = org::freedesktop;
45namespace NM = fdo::NetworkManager;
46
47#include <connectivity/networking/manager.h>
48
49namespace dbus = core::dbus;
50
51namespace
52{
53struct Service : public core::dbus::testing::Fixture {};
54
55auto session_bus_config_file =
56 core::dbus::testing::Fixture::default_session_bus_config_file() =
57 core::testing::session_bus_configuration_file();
58
59auto system_bus_config_file =
60 core::dbus::testing::Fixture::default_system_bus_config_file() =
61 core::testing::system_bus_configuration_file();
62
63}
64
65TEST_F(Service, flightMode)
66{
67 core::testing::CrossProcessSync services_ready;
68 core::testing::CrossProcessSync client_ready;
69
70 auto service = [&, this]()
71 {
72 core::testing::SigTermCatcher sc;
73
74 auto bus = system_bus();
75 bus->install_executor(core::dbus::asio::make_executor(bus));
76
77 auto nm_service = NM::Service::Mock(bus);
78 auto nm_root = nm_service.nm;
79
80 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::GetDevices>([bus, nm_root](const dbus::Message::Ptr& msg)
81 {
82 auto reply = dbus::Message::make_method_return(msg);
83 reply->writer() << std::vector<dbus::types::ObjectPath>();
84 bus->send(reply);
85 });
86
87 nm_root->state->set(0);
88
89 DefaultURfkillMock urfkill(bus);
90
91 std::thread t{[bus](){ bus->run(); }};
92
93 services_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
94
95 EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
96 sc.wait_for_signal_for(std::chrono::seconds{10});
97
98 bus->stop();
99
100 if (t.joinable())
101 t.join();
102
103 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
104 };
105
106 auto client = [&, this]()
107 {
108 EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
109 std::unique_ptr<connectivity::networking::Manager> mgr;
110 mgr = connectivity::networking::Manager::createInstance();
111
112 std::vector<connectivity::networking::Manager::FlightModeStatus> statuses;
113 try {
114 EXPECT_EQ(mgr->flightMode().get(), connectivity::networking::Manager::FlightModeStatus::off);
115
116 mgr->flightMode().changed().connect([&statuses](connectivity::networking::Manager::FlightModeStatus status) {
117 statuses.push_back(status);
118 });
119
120 mgr->enableFlightMode();
121 mgr->disableFlightMode();
122
123 } catch (const std::runtime_error &e) {
124 std::cout << "exception: " << e.what() << std::endl;
125 }
126
127 sleep(1);
128 client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
129
130 EXPECT_EQ(statuses.size(), 2);
131 EXPECT_EQ(statuses.at(0), connectivity::networking::Manager::FlightModeStatus::on);
132 EXPECT_EQ(statuses.at(1), connectivity::networking::Manager::FlightModeStatus::off);
133
134 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
135 };
136
137 EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
138}
1390
=== removed file 'tests/integration/connectivity-cpp/test_networking_status.cpp'
--- tests/integration/connectivity-cpp/test_networking_status.cpp 2014-08-19 19:55:15 +0000
+++ tests/integration/connectivity-cpp/test_networking_status.cpp 1970-01-01 00:00:00 +0000
@@ -1,178 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17 */
18
19#include <core/dbus/dbus.h>
20#include <core/dbus/fixture.h>
21#include <core/dbus/object.h>
22#include <core/dbus/property.h>
23#include <core/dbus/service.h>
24#include <core/dbus/interfaces/properties.h>
25#include <core/dbus/types/stl/tuple.h>
26#include <core/dbus/types/stl/vector.h>
27
28#include <core/dbus/asio/executor.h>
29
30#include "sig_term_catcher.h"
31#include "test_data.h"
32#include "test_service.h"
33
34#include <core/testing/cross_process_sync.h>
35#include <core/testing/fork_and_run.h>
36
37#include <gtest/gtest.h>
38
39#include <system_error>
40#include <thread>
41
42#include "mocks/urfkill.h"
43
44#include <services/nm.h>
45namespace fdo = org::freedesktop;
46namespace NM = fdo::NetworkManager;
47
48#include <connectivity/networking/manager.h>
49
50namespace dbus = core::dbus;
51
52namespace
53{
54struct Service : public core::dbus::testing::Fixture {};
55
56auto session_bus_config_file =
57 core::dbus::testing::Fixture::default_session_bus_config_file() =
58 core::testing::session_bus_configuration_file();
59
60auto system_bus_config_file =
61 core::dbus::testing::Fixture::default_system_bus_config_file() =
62 core::testing::system_bus_configuration_file();
63
64}
65
66TEST_F(Service, networkingStatus)
67{
68 core::testing::CrossProcessSync services_ready;
69 core::testing::CrossProcessSync client_ready;
70 core::testing::CrossProcessSync update_networking_status;
71
72
73 auto service = [&, this]()
74 {
75 core::testing::SigTermCatcher sc;
76
77 auto bus = system_bus();
78 bus->install_executor(core::dbus::asio::make_executor(bus));
79
80 DefaultURfkillMock urfkill(bus);
81
82 auto nm_service = NM::Service::Mock(bus);
83 auto nm_root = nm_service.nm;
84
85 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::GetDevices>([bus, nm_root](const dbus::Message::Ptr& msg)
86 {
87 auto reply = dbus::Message::make_method_return(msg);
88 reply->writer() << std::vector<dbus::types::ObjectPath>();
89 bus->send(reply);
90 });
91
92 nm_root->state->set(NM_STATE_UNKNOWN);
93
94 std::thread t{[bus](){ bus->run(); }};
95
96 services_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
97 EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
98
99 NM::Interface::NetworkManager::Signal::PropertiesChanged::ArgumentType properties;
100
101 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_UNKNOWN);
102 nm_root->properties_changed->emit(properties);
103
104 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_ASLEEP);
105 nm_root->properties_changed->emit(properties);
106
107 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_DISCONNECTED);
108 nm_root->properties_changed->emit(properties);
109
110 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_CONNECTING);
111 nm_root->properties_changed->emit(properties);
112
113 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_CONNECTED_LOCAL);
114 nm_root->properties_changed->emit(properties);
115
116 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_CONNECTED_SITE);
117 nm_root->properties_changed->emit(properties);
118
119 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_CONNECTED_GLOBAL);
120 nm_root->properties_changed->emit(properties);
121
122 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_DISCONNECTING);
123 nm_root->properties_changed->emit(properties);
124
125 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_DISCONNECTED);
126 nm_root->properties_changed->emit(properties);
127
128 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_CONNECTING);
129 nm_root->properties_changed->emit(properties);
130
131 properties["State"] = dbus::types::Variant::encode<std::uint32_t>(NM_STATE_CONNECTED_GLOBAL);
132 nm_root->properties_changed->emit(properties);
133
134 // status change
135 update_networking_status.try_signal_ready_for(std::chrono::milliseconds{2000});
136
137 sc.wait_for_signal_for(std::chrono::seconds{10});
138
139 bus->stop();
140
141 if (t.joinable())
142 t.join();
143
144 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
145 };
146
147 auto client = [&, this]()
148 {
149 EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
150 std::unique_ptr<connectivity::networking::Manager> mgr;
151 mgr = connectivity::networking::Manager::createInstance();
152
153 EXPECT_EQ(mgr->status().get(), connectivity::networking::Manager::NetworkingStatus::offline);
154
155 std::vector<connectivity::networking::Manager::NetworkingStatus> states;
156 mgr->status().changed().connect([&states](connectivity::networking::Manager::NetworkingStatus status) {
157 states.push_back(status);
158 });
159
160 client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
161
162 EXPECT_EQ(1, update_networking_status.wait_for_signal_ready_for(std::chrono::milliseconds{2000}));
163
164 sleep(1);
165
166 EXPECT_EQ(states.size(), 5);
167 EXPECT_EQ(states.at(0), connectivity::networking::Manager::NetworkingStatus::connecting);
168 EXPECT_EQ(states.at(1), connectivity::networking::Manager::NetworkingStatus::online);
169 EXPECT_EQ(states.at(2), connectivity::networking::Manager::NetworkingStatus::offline);
170 EXPECT_EQ(states.at(3), connectivity::networking::Manager::NetworkingStatus::connecting);
171 EXPECT_EQ(states.at(4), connectivity::networking::Manager::NetworkingStatus::online);
172
173 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
174 };
175
176 EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
177}
178
1790
=== removed file 'tests/integration/connectivity-cpp/test_service.h'
--- tests/integration/connectivity-cpp/test_service.h 2014-08-19 19:55:15 +0000
+++ tests/integration/connectivity-cpp/test_service.h 1970-01-01 00:00:00 +0000
@@ -1,124 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Thomas VoƟ <thomas.voss@canonical.com>
17 */
18
19#ifndef TEST_SERVICE_H_
20#define TEST_SERVICE_H_
21
22namespace test
23{
24struct Service
25{
26 struct Method
27 {
28 typedef Service Interface;
29
30 inline static const std::string& name()
31 {
32 static const std::string s
33 {
34 "Method"
35 };
36 return s;
37 }
38
39 inline static const std::chrono::milliseconds default_timeout()
40 {
41 return std::chrono::seconds{1};
42 }
43 };
44
45 struct Signals
46 {
47 struct Dummy
48 {
49 inline static std::string name()
50 {
51 return "Dummy";
52 };
53 typedef Service Interface;
54 typedef int64_t ArgumentType;
55 };
56 };
57
58 struct Properties
59 {
60 struct Dummy
61 {
62 inline static std::string name()
63 {
64 return "Dummy";
65 };
66 typedef Service Interface;
67 typedef double ValueType;
68 static const bool readable = true;
69 static const bool writable = true;
70 };
71 };
72
73 struct Interfaces
74 {
75 struct Foo
76 {
77 static const std::string& name()
78 {
79 static const std::string s{"this.is.unlikely.to.exist.Service.Foo"};
80 return s;
81 }
82
83 struct Signals
84 {
85 struct Dummy
86 {
87 inline static std::string name()
88 {
89 return "Dummy";
90 }
91 typedef Foo Interface;
92 typedef int64_t ArgumentType;
93 };
94 };
95 };
96 };
97};
98}
99
100#include <core/dbus/traits/service.h>
101
102namespace core
103{
104namespace dbus
105{
106namespace traits
107{
108template<>
109struct Service<test::Service>
110{
111 inline static const std::string& interface_name()
112 {
113 static const std::string s
114 {
115 "this.is.unlikely.to.exist.Service"
116 };
117 return s;
118 }
119};
120}
121}
122}
123
124#endif // TEST_SERVICE_H_
1250
=== removed file 'tests/integration/connectivity-cpp/test_wifi_connect.cpp'
--- tests/integration/connectivity-cpp/test_wifi_connect.cpp 2014-08-23 18:11:18 +0000
+++ tests/integration/connectivity-cpp/test_wifi_connect.cpp 1970-01-01 00:00:00 +0000
@@ -1,278 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17 */
18
19#include <core/dbus/dbus.h>
20#include <core/dbus/fixture.h>
21#include <core/dbus/object.h>
22#include <core/dbus/property.h>
23#include <core/dbus/service.h>
24#include <core/dbus/interfaces/properties.h>
25#include <core/dbus/types/stl/tuple.h>
26#include <core/dbus/types/stl/vector.h>
27
28#include <core/dbus/asio/executor.h>
29
30#include "sig_term_catcher.h"
31#include "test_data.h"
32#include "test_service.h"
33
34#include <core/testing/cross_process_sync.h>
35#include <core/testing/fork_and_run.h>
36
37#include <gtest/gtest.h>
38
39#include <system_error>
40#include <thread>
41
42#include <services/nm.h>
43namespace fdo = org::freedesktop;
44namespace NM = fdo::NetworkManager;
45
46#include "mocks/urfkill.h"
47
48#include <connectivity/networking/manager.h>
49#include <connectivity/networking/wifi/link.h>
50#include <connectivity/networking/wifi/access-point.h>
51
52namespace dbus = core::dbus;
53
54namespace
55{
56struct Service : public core::dbus::testing::Fixture {};
57
58auto session_bus_config_file =
59 core::dbus::testing::Fixture::default_session_bus_config_file() =
60 core::testing::session_bus_configuration_file();
61
62auto system_bus_config_file =
63 core::dbus::testing::Fixture::default_system_bus_config_file() =
64 core::testing::system_bus_configuration_file();
65
66}
67
68TEST_F(Service, wifiLink)
69{
70 core::testing::CrossProcessSync services_ready;
71 core::testing::CrossProcessSync client_ready;
72 core::testing::CrossProcessSync stage1;
73 core::testing::CrossProcessSync stage2;
74
75 auto service = [&, this]()
76 {
77 core::testing::SigTermCatcher sc;
78
79 auto bus = system_bus();
80 bus->install_executor(core::dbus::asio::make_executor(bus));
81
82 auto service = NM::Service::Mock(bus);
83 auto nm_root = service.nm;
84
85 auto wifi_dev = NM::Interface::Device(nm_root->service,
86 nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")));
87 auto ap1 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/1")));
88 auto ap2 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/2")));
89
90 auto wrong_settings = NM::Interface::Connection(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Settings/1")));
91 auto correct_settings = NM::Interface::Connection(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Settings/2")));
92
93 wrong_settings.object->install_method_handler<NM::Interface::Connection::Method::GetSettings>([&](const dbus::Message::Ptr& msg)
94 {
95 auto reply = dbus::Message::make_method_return(msg);
96 std::map<std::string, std::map<std::string, core::dbus::types::Variant>> conf;
97 std::map<std::string, dbus::types::Variant> wireless_conf;
98 wireless_conf["ssid"] = dbus::types::Variant::encode<std::vector<std::int8_t>>({0x64, 0x65, 0x66}); // def
99 conf["802-11-wireless"] = wireless_conf;
100 reply->writer() << conf;
101 bus->send(reply);
102 });
103
104 correct_settings.object->install_method_handler<NM::Interface::Connection::Method::GetSettings>([&](const dbus::Message::Ptr& msg)
105 {
106 auto reply = dbus::Message::make_method_return(msg);
107 std::map<std::string, std::map<std::string, core::dbus::types::Variant>> conf;
108 std::map<std::string, dbus::types::Variant> wireless_conf;
109 wireless_conf["ssid"] = dbus::types::Variant::encode<std::vector<std::int8_t>>({static_cast<std::int8_t>(0xC3),
110 static_cast<std::int8_t>(0xA4),
111 static_cast<std::int8_t>(0x62),
112 static_cast<std::int8_t>(0x63)}); // Ƥbc
113 conf["802-11-wireless"] = wireless_conf;
114 reply->writer() << conf;
115 bus->send(reply);
116 });
117
118 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::GetDevices>([bus, &wifi_dev](const dbus::Message::Ptr& msg)
119 {
120 auto reply = dbus::Message::make_method_return(msg);
121 std::vector<dbus::types::ObjectPath> devices;
122 devices.push_back(wifi_dev.object->path());
123 reply->writer() << devices;
124 bus->send(reply);
125 });
126
127 NM::Interface::Device::Property::AvailableConnections::ValueType available_connections;
128 available_connections.push_back(wrong_settings.object->path());
129 available_connections.push_back(correct_settings.object->path());
130 wifi_dev.available_connections->set(available_connections);
131
132 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::ActivateConnection>([&](const dbus::Message::Ptr& msg)
133 {
134 std::cout << "Server: Active Connection" << std::endl;
135 auto reader = msg->reader();
136
137 dbus::types::ObjectPath connection = reader.pop_object_path();
138 dbus::types::ObjectPath device = reader.pop_object_path();
139 dbus::types::ObjectPath specific_object = reader.pop_object_path();
140
141 EXPECT_EQ(connection, correct_settings.object->path());
142 EXPECT_EQ(device, wifi_dev.object->path());
143 EXPECT_EQ(specific_object, ap1.object->path());
144
145 auto reply = dbus::Message::make_method_return(msg);
146 reply->writer() << dbus::types::ObjectPath("/"); /// @todo return an actual ActiveConnection at some point.
147 bus->send(reply);
148 });
149 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::AddAndActivateConnection>([&](const dbus::Message::Ptr& msg)
150 {
151 std::cout << "Server: Add and Active Connection" << std::endl;
152 auto reader = msg->reader();
153
154 std::map<std::string, std::map<std::string, core::dbus::types::Variant>> connection;
155 reader >> connection;
156 dbus::types::ObjectPath device = reader.pop_object_path();
157 dbus::types::ObjectPath specific_object = reader.pop_object_path();
158
159 EXPECT_TRUE(connection.find("802-11-wireless") != connection.end());
160 auto wificonf = connection["802-11-wireless"];
161 EXPECT_TRUE(wificonf.find("ssid") != wificonf.end());
162 EXPECT_EQ(wificonf["ssid"].as<std::vector<std::int8_t>>(), ap2.ssid->get());
163 EXPECT_EQ(device, wifi_dev.object->path());
164 EXPECT_EQ(specific_object, ap2.object->path());
165
166 auto reply = dbus::Message::make_method_return(msg);
167 auto ret = std::make_tuple(dbus::types::ObjectPath("/"), dbus::types::ObjectPath("/"));
168 reply->writer() << ret; /// @todo return actual Settings and ActiveConnection at some point.
169 bus->send(reply);
170 });
171
172
173 nm_root->state->set(NM_STATE_DISCONNECTED);
174 wifi_dev.device_type->set(NM_DEVICE_TYPE_WIFI);
175
176 std::vector<dbus::types::ObjectPath> aps;
177 wifi_dev.object->install_method_handler<NM::Interface::Device::Wireless::Method::GetAccessPoints>([bus, &aps](const dbus::Message::Ptr& msg)
178 {
179 auto reply = dbus::Message::make_method_return(msg);
180 reply->writer() << aps;
181 bus->send(reply);
182 });
183
184 auto ap_added = wifi_dev.object->get_signal<NM::Interface::Device::Wireless::Signal::AccessPointAdded>();
185 auto ap_removed = wifi_dev.object->get_signal<NM::Interface::Device::Wireless::Signal::AccessPointRemoved>();
186
187 ap1.flags->set(NM_802_11_AP_FLAGS_PRIVACY);
188 ap1.mode->set(NM_802_11_MODE_INFRA);
189 // SSID name is Ƥbc to test that utf-8 in names works.
190 // The casts are because the underlying datatype is
191 // signed char (should be unsigned) and 0x63 > 127.
192 ap1.ssid->set({static_cast<std::int8_t>(0xC3),
193 static_cast<std::int8_t>(0xA4),
194 static_cast<std::int8_t>(0x62),
195 static_cast<std::int8_t>(0x63)});
196 ap1.strength->set(90);
197
198 auto ap1_pc = ap1.properties_changed;
199
200 ap2.flags->set(NM_802_11_AP_FLAGS_NONE);
201 ap2.mode->set(NM_802_11_MODE_ADHOC);
202 ap2.ssid->set({0x31, 0x32, 0x33}); // 123
203 ap2.strength->set(60);
204 auto ap2_pc = ap2.properties_changed;
205
206 DefaultURfkillMock urfkill(bus);
207
208 std::thread t{[bus](){ bus->run(); }};
209
210 aps.push_back(ap1.object->path());
211 aps.push_back(ap2.object->path());
212
213 services_ready.try_signal_ready_for(std::chrono::milliseconds{5000});
214 EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
215
216
217 stage1.try_signal_ready_for(std::chrono::milliseconds{5000});
218
219 sleep(1);
220
221 stage2.try_signal_ready_for(std::chrono::milliseconds{5000});
222
223 sc.wait_for_signal_for(std::chrono::seconds{60});
224
225 bus->stop();
226
227 if (t.joinable())
228 t.join();
229
230 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
231 };
232
233 auto client = [&, this]()
234 {
235 EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
236 std::unique_ptr<connectivity::networking::Manager> mgr;
237 mgr = connectivity::networking::Manager::createInstance();
238
239 auto links = mgr->links();
240 EXPECT_EQ(links->size(), 1);
241
242 EXPECT_EQ((*links->begin())->type(), connectivity::networking::Link::Type::wifi);
243 auto wifilink = std::dynamic_pointer_cast<connectivity::networking::wifi::Link>(*links->begin());
244 EXPECT_TRUE(wifilink.get() != nullptr);
245
246 auto aps = wifilink->accessPoints().get();
247 EXPECT_EQ(aps.size(), 2);
248
249 std::shared_ptr<connectivity::networking::wifi::AccessPoint> ap_abc;
250 std::shared_ptr<connectivity::networking::wifi::AccessPoint> ap_123;
251 for (auto ap : aps) {
252 if (ap->ssid() == "Ƥbc")
253 ap_abc = ap;
254 if (ap->ssid() == "123")
255 ap_123 = ap;
256 }
257
258 EXPECT_TRUE(ap_abc.get() != nullptr);
259 EXPECT_TRUE(ap_123.get() != nullptr);
260
261 client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
262
263 wifilink->connect_to(ap_abc);
264
265 sleep(1);
266
267 EXPECT_EQ(1, stage1.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
268
269 wifilink->connect_to(ap_123);
270
271 sleep(1);
272
273 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
274 };
275
276 EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
277}
278
2790
=== removed file 'tests/integration/connectivity-cpp/test_wifi_link.cpp'
--- tests/integration/connectivity-cpp/test_wifi_link.cpp 2014-08-20 19:18:40 +0000
+++ tests/integration/connectivity-cpp/test_wifi_link.cpp 1970-01-01 00:00:00 +0000
@@ -1,362 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17 */
18
19#include <core/dbus/dbus.h>
20#include <core/dbus/fixture.h>
21#include <core/dbus/object.h>
22#include <core/dbus/property.h>
23#include <core/dbus/service.h>
24#include <core/dbus/interfaces/properties.h>
25#include <core/dbus/types/stl/tuple.h>
26#include <core/dbus/types/stl/vector.h>
27
28#include <core/dbus/asio/executor.h>
29
30#include "sig_term_catcher.h"
31#include "test_data.h"
32#include "test_service.h"
33
34#include <core/testing/cross_process_sync.h>
35#include <core/testing/fork_and_run.h>
36
37#include <gtest/gtest.h>
38
39#include <system_error>
40#include <thread>
41
42#include <services/nm.h>
43namespace fdo = org::freedesktop;
44namespace NM = fdo::NetworkManager;
45
46#include "mocks/urfkill.h"
47
48#include <connectivity/networking/manager.h>
49#include <connectivity/networking/wifi/link.h>
50#include <connectivity/networking/wifi/access-point.h>
51
52namespace dbus = core::dbus;
53
54namespace
55{
56struct Service : public core::dbus::testing::Fixture {};
57
58auto session_bus_config_file =
59 core::dbus::testing::Fixture::default_session_bus_config_file() =
60 core::testing::session_bus_configuration_file();
61
62auto system_bus_config_file =
63 core::dbus::testing::Fixture::default_system_bus_config_file() =
64 core::testing::system_bus_configuration_file();
65
66}
67
68TEST_F(Service, wifiLink)
69{
70 core::testing::CrossProcessSync services_ready;
71 core::testing::CrossProcessSync client_ready;
72 core::testing::CrossProcessSync stage1;
73 core::testing::CrossProcessSync stage2;
74 core::testing::CrossProcessSync stage3;
75
76 auto service = [&, this]()
77 {
78 core::testing::SigTermCatcher sc;
79
80 auto bus = system_bus();
81 bus->install_executor(core::dbus::asio::make_executor(bus));
82
83 auto service = NM::Service::Mock(bus);
84 auto nm_root = service.nm;
85
86 auto wifi_dev = NM::Interface::Device(nm_root->service,
87 nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")));
88 auto ap1 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/1")));
89 auto ap2 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/2")));
90
91 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::GetDevices>([bus, &wifi_dev](const dbus::Message::Ptr& msg)
92 {
93 auto reply = dbus::Message::make_method_return(msg);
94 std::vector<dbus::types::ObjectPath> devices;
95 devices.push_back(wifi_dev.object->path());
96 reply->writer() << devices;
97 bus->send(reply);
98 });
99
100 nm_root->state->set(NM_STATE_CONNECTED_GLOBAL);
101
102 wifi_dev.device_type->set(NM_DEVICE_TYPE_WIFI);
103
104 std::vector<dbus::types::ObjectPath> aps;
105 wifi_dev.object->install_method_handler<NM::Interface::Device::Wireless::Method::GetAccessPoints>([bus, &aps](const dbus::Message::Ptr& msg)
106 {
107 auto reply = dbus::Message::make_method_return(msg);
108 reply->writer() << aps;
109 bus->send(reply);
110 });
111
112 auto ap_added = wifi_dev.object->get_signal<NM::Interface::Device::Wireless::Signal::AccessPointAdded>();
113 auto ap_removed = wifi_dev.object->get_signal<NM::Interface::Device::Wireless::Signal::AccessPointRemoved>();
114
115 ap1.flags->set(NM_802_11_AP_FLAGS_PRIVACY);
116 ap1.mode->set(NM_802_11_MODE_INFRA);
117 ap1.ssid->set({0x61, 0x62, 0x63}); // abc
118 ap1.strength->set(90);
119
120 auto ap1_pc = ap1.properties_changed;
121
122 ap2.flags->set(NM_802_11_AP_FLAGS_NONE);
123 ap2.mode->set(NM_802_11_MODE_ADHOC);
124 ap2.ssid->set({0x31, 0x32, 0x33}); // 123
125 ap2.strength->set(60);
126 auto ap2_pc = ap2.properties_changed;
127
128 DefaultURfkillMock urfkill(bus);
129
130 std::thread t{[bus](){ bus->run(); }};
131
132 // add just one AP initially
133 aps.push_back(ap1.object->path());
134
135 services_ready.try_signal_ready_for(std::chrono::milliseconds{5000});
136 EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
137
138 NM::Interface::AccessPoint::Signal::PropertiesChanged::ArgumentType properties;
139
140 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(0);
141 ap1_pc->emit(properties);
142 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(1);
143 ap1_pc->emit(properties);
144 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(2);
145 ap1_pc->emit(properties);
146 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(3);
147 ap1_pc->emit(properties);
148 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(4);
149 ap1_pc->emit(properties);
150
151 stage1.try_signal_ready_for(std::chrono::milliseconds{5000});
152
153 // add second ap
154 aps.push_back(ap2.object->path());
155 ap_added->emit(ap2.object->path());
156
157 sleep(5);
158
159 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(5);
160 ap1_pc->emit(properties);
161 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(6);
162 ap1_pc->emit(properties);
163 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(7);
164 ap1_pc->emit(properties);
165 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(8);
166 ap1_pc->emit(properties);
167 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(9);
168 ap1_pc->emit(properties);
169
170 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(100);
171 ap2_pc->emit(properties);
172 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(99);
173 ap2_pc->emit(properties);
174 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(98);
175 ap2_pc->emit(properties);
176 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(97);
177 ap2_pc->emit(properties);
178 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(96);
179 ap2_pc->emit(properties);
180 ap2_pc->emit(properties);
181
182 stage2.try_signal_ready_for(std::chrono::milliseconds{10000});
183
184 // remove the first ap
185 aps.clear();
186 aps.push_back(ap2.object->path());
187 ap_removed->emit(ap1.object->path());
188
189 sleep(5);
190
191 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(95);
192 ap2_pc->emit(properties);
193 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(94);
194 ap2_pc->emit(properties);
195 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(93);
196 ap2_pc->emit(properties);
197 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(92);
198 ap2_pc->emit(properties);
199 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(91);
200 ap2_pc->emit(properties);
201
202 stage3.try_signal_ready_for(std::chrono::milliseconds{10000});
203
204 // add the first ap back
205 aps.push_back(ap1.object->path());
206 ap_added->emit(ap1.object->path());
207
208 sleep(5);
209
210 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(10);
211 ap1_pc->emit(properties);
212 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(11);
213 ap1_pc->emit(properties);
214 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(12);
215 ap1_pc->emit(properties);
216 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(13);
217 ap1_pc->emit(properties);
218 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(14);
219 ap1_pc->emit(properties);
220
221 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(90);
222 ap2_pc->emit(properties);
223 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(89);
224 ap2_pc->emit(properties);
225 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(88);
226 ap2_pc->emit(properties);
227 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(87);
228 ap2_pc->emit(properties);
229 properties["Strength"] = dbus::types::Variant::encode<std::int8_t>(86);
230 ap2_pc->emit(properties);
231
232 sc.wait_for_signal_for(std::chrono::seconds{60});
233
234 bus->stop();
235
236 if (t.joinable())
237 t.join();
238
239 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
240 };
241
242 auto client = [&, this]()
243 {
244 EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
245 std::unique_ptr<connectivity::networking::Manager> mgr;
246 mgr = connectivity::networking::Manager::createInstance();
247
248 auto links = mgr->links();
249 EXPECT_EQ(links->size(), 1);
250
251 EXPECT_EQ((*links->begin())->type(), connectivity::networking::Link::Type::wifi);
252 auto wifilink = std::dynamic_pointer_cast<connectivity::networking::wifi::Link>(*links->begin());
253 EXPECT_TRUE(wifilink.get() != nullptr);
254
255 std::vector<double> values_abc;
256 std::vector<double> values_123;
257 std::map<std::shared_ptr<connectivity::networking::wifi::AccessPoint>, core::ScopedConnection> connections;
258 auto ap_connect = [&](std::shared_ptr<connectivity::networking::wifi::AccessPoint> ap) {
259 if (ap->ssid() == "abc") {
260 EXPECT_TRUE(ap->secured());
261 EXPECT_FALSE(ap->adhoc());
262 auto con = ap->strength().changed().connect([&values_abc](double value){
263 values_abc.push_back(value);
264 });
265 connections.insert(std::make_pair(ap, core::ScopedConnection(con)));
266 } else if (ap->ssid() == "123") {
267 EXPECT_FALSE(ap->secured());
268 EXPECT_TRUE(ap->adhoc());
269 auto con = ap->strength().changed().connect([&values_123](double value){
270 values_123.push_back(value);
271 });
272 connections.insert(std::make_pair(ap, core::ScopedConnection(con)));
273 }
274 };
275 auto aps = wifilink->accessPoints().get();
276 EXPECT_EQ(aps.size(), 1);
277 for (auto ap : aps) {
278 ap_connect(ap);
279 }
280 aps.clear();
281 wifilink->accessPoints().changed().connect([&](std::set<std::shared_ptr<connectivity::networking::wifi::AccessPoint>> aps) {
282 connections.clear();
283 for (auto ap: aps)
284 ap_connect(ap);
285 });
286
287 client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
288
289 sleep(5);
290
291 EXPECT_EQ(values_abc.size(), 5);
292 EXPECT_EQ(values_123.size(), 0);
293
294 EXPECT_FLOAT_EQ(values_abc[0], 0);
295 EXPECT_FLOAT_EQ(values_abc[1], 1);
296 EXPECT_FLOAT_EQ(values_abc[2], 2);
297 EXPECT_FLOAT_EQ(values_abc[3], 3);
298 EXPECT_FLOAT_EQ(values_abc[4], 4);
299
300 values_abc.clear();
301 values_123.clear();
302 EXPECT_EQ(1, stage1.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
303
304 sleep(5);
305
306 EXPECT_EQ(values_abc.size(), 5);
307 EXPECT_EQ(values_123.size(), 5);
308
309 EXPECT_FLOAT_EQ(values_abc[0], 5);
310 EXPECT_FLOAT_EQ(values_abc[1], 6);
311 EXPECT_FLOAT_EQ(values_abc[2], 7);
312 EXPECT_FLOAT_EQ(values_abc[3], 8);
313 EXPECT_FLOAT_EQ(values_abc[4], 9);
314
315 EXPECT_FLOAT_EQ(values_123[0], 100);
316 EXPECT_FLOAT_EQ(values_123[1], 99);
317 EXPECT_FLOAT_EQ(values_123[2], 98);
318 EXPECT_FLOAT_EQ(values_123[3], 97);
319 EXPECT_FLOAT_EQ(values_123[4], 96);
320
321 values_abc.clear();
322 values_123.clear();
323 EXPECT_EQ(1, stage2.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
324
325 sleep(5);
326
327 EXPECT_EQ(values_abc.size(), 0);
328 EXPECT_EQ(values_123.size(), 5);
329
330 EXPECT_FLOAT_EQ(values_123[0], 95);
331 EXPECT_FLOAT_EQ(values_123[1], 94);
332 EXPECT_FLOAT_EQ(values_123[2], 93);
333 EXPECT_FLOAT_EQ(values_123[3], 92);
334 EXPECT_FLOAT_EQ(values_123[4], 91);
335
336 values_abc.clear();
337 values_123.clear();
338 EXPECT_EQ(1, stage3.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
339
340 sleep(5);
341
342 EXPECT_EQ(values_abc.size(), 5);
343 EXPECT_EQ(values_123.size(), 5);
344
345 EXPECT_FLOAT_EQ(values_abc[0], 10);
346 EXPECT_FLOAT_EQ(values_abc[1], 11);
347 EXPECT_FLOAT_EQ(values_abc[2], 12);
348 EXPECT_FLOAT_EQ(values_abc[3], 13);
349 EXPECT_FLOAT_EQ(values_abc[4], 14);
350
351 EXPECT_FLOAT_EQ(values_123[0], 90);
352 EXPECT_FLOAT_EQ(values_123[1], 89);
353 EXPECT_FLOAT_EQ(values_123[2], 88);
354 EXPECT_FLOAT_EQ(values_123[3], 87);
355 EXPECT_FLOAT_EQ(values_123[4], 86);
356
357 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
358 };
359
360 EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
361}
362
3630
=== removed file 'tests/integration/connectivity-cpp/test_wifi_link_dedup.cpp'
--- tests/integration/connectivity-cpp/test_wifi_link_dedup.cpp 2014-08-20 20:16:32 +0000
+++ tests/integration/connectivity-cpp/test_wifi_link_dedup.cpp 1970-01-01 00:00:00 +0000
@@ -1,240 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17 */
18
19#include <core/dbus/dbus.h>
20#include <core/dbus/fixture.h>
21#include <core/dbus/object.h>
22#include <core/dbus/property.h>
23#include <core/dbus/service.h>
24#include <core/dbus/interfaces/properties.h>
25#include <core/dbus/types/stl/tuple.h>
26#include <core/dbus/types/stl/vector.h>
27
28#include <core/dbus/asio/executor.h>
29
30#include "sig_term_catcher.h"
31#include "test_data.h"
32#include "test_service.h"
33
34#include <core/testing/cross_process_sync.h>
35#include <core/testing/fork_and_run.h>
36
37#include <gtest/gtest.h>
38
39#include <system_error>
40#include <thread>
41
42#include <services/nm.h>
43namespace fdo = org::freedesktop;
44namespace NM = fdo::NetworkManager;
45
46#include "mocks/urfkill.h"
47
48#include <connectivity/networking/manager.h>
49#include <connectivity/networking/wifi/link.h>
50#include <connectivity/networking/wifi/access-point.h>
51
52namespace dbus = core::dbus;
53
54namespace
55{
56struct Service : public core::dbus::testing::Fixture {};
57
58auto session_bus_config_file =
59 core::dbus::testing::Fixture::default_session_bus_config_file() =
60 core::testing::session_bus_configuration_file();
61
62auto system_bus_config_file =
63 core::dbus::testing::Fixture::default_system_bus_config_file() =
64 core::testing::system_bus_configuration_file();
65
66}
67
68TEST_F(Service, wifiLink)
69{
70 core::testing::CrossProcessSync services_ready;
71 core::testing::CrossProcessSync client_ready;
72 core::testing::CrossProcessSync stage1;
73 core::testing::CrossProcessSync stage2;
74 core::testing::CrossProcessSync stage3;
75 core::testing::CrossProcessSync stage4;
76
77 auto service = [&, this]()
78 {
79 core::testing::SigTermCatcher sc;
80
81 auto bus = system_bus();
82 bus->install_executor(core::dbus::asio::make_executor(bus));
83
84 auto service = NM::Service::Mock(bus);
85 auto nm_root = service.nm;
86
87 auto wifi_dev = NM::Interface::Device(nm_root->service,
88 nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")));
89 auto ap1 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/1")));
90 auto ap2 = NM::Interface::AccessPoint(nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/AccessPoint/2")));
91
92 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::GetDevices>([bus, &wifi_dev](const dbus::Message::Ptr& msg)
93 {
94 auto reply = dbus::Message::make_method_return(msg);
95 std::vector<dbus::types::ObjectPath> devices;
96 devices.push_back(wifi_dev.object->path());
97 reply->writer() << devices;
98 bus->send(reply);
99 });
100
101 nm_root->state->set(NM_STATE_CONNECTED_GLOBAL);
102
103 wifi_dev.device_type->set(NM_DEVICE_TYPE_WIFI);
104
105 std::vector<dbus::types::ObjectPath> aps;
106 wifi_dev.object->install_method_handler<NM::Interface::Device::Wireless::Method::GetAccessPoints>([bus, &aps](const dbus::Message::Ptr& msg)
107 {
108 auto reply = dbus::Message::make_method_return(msg);
109 reply->writer() << aps;
110 bus->send(reply);
111 });
112
113 auto ap_added = wifi_dev.object->get_signal<NM::Interface::Device::Wireless::Signal::AccessPointAdded>();
114 auto ap_removed = wifi_dev.object->get_signal<NM::Interface::Device::Wireless::Signal::AccessPointRemoved>();
115
116 ap1.flags->set(NM_802_11_AP_FLAGS_PRIVACY);
117 ap1.mode->set(NM_802_11_MODE_INFRA);
118 ap1.ssid->set({0x61, 0x62, 0x63}); // abc
119 ap1.strength->set(60);
120
121 auto ap1_pc = ap1.properties_changed;
122
123 ap2.flags->set(NM_802_11_AP_FLAGS_PRIVACY);
124 ap2.mode->set(NM_802_11_MODE_INFRA);
125 ap2.ssid->set({0x61, 0x62, 0x63}); // abc
126 ap2.strength->set(90);
127 auto ap2_pc = ap2.properties_changed;
128
129 DefaultURfkillMock urfkill(bus);
130
131 std::thread t{[bus](){ bus->run(); }};
132
133 // add just one AP initially
134 aps.push_back(ap1.object->path());
135
136 services_ready.try_signal_ready_for(std::chrono::milliseconds{10000});
137 EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
138
139 NM::Interface::AccessPoint::Signal::PropertiesChanged::ArgumentType properties;
140
141 stage1.try_signal_ready_for(std::chrono::milliseconds{10000});
142
143 // add second ap
144 aps.push_back(ap2.object->path());
145 ap_added->emit(ap2.object->path());
146
147 sleep(5);
148
149 stage2.try_signal_ready_for(std::chrono::milliseconds{10000});
150
151 // remove second ap
152 aps.clear();
153 aps.push_back(ap1.object->path());
154 ap_removed->emit(ap2.object->path());
155
156 sleep(5);
157
158 stage3.try_signal_ready_for(std::chrono::milliseconds{10000});
159
160 aps.clear();
161 ap_removed->emit(ap1.object->path());
162
163 sleep(5);
164
165 stage4.try_signal_ready_for(std::chrono::milliseconds{10000});
166
167 bus->stop();
168
169 if (t.joinable())
170 t.join();
171
172 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
173 };
174
175 auto client = [&, this]()
176 {
177 EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
178 std::unique_ptr<connectivity::networking::Manager> mgr;
179 mgr = connectivity::networking::Manager::createInstance();
180
181 auto links = mgr->links();
182 EXPECT_EQ(links->size(), 1);
183
184 EXPECT_EQ((*links->begin())->type(), connectivity::networking::Link::Type::wifi);
185 auto wifilink = std::dynamic_pointer_cast<connectivity::networking::wifi::Link>(*links->begin());
186 EXPECT_TRUE(wifilink.get() != nullptr);
187
188 std::vector<double> values_abc;
189 std::vector<double> values_123;
190 std::map<std::shared_ptr<connectivity::networking::wifi::AccessPoint>, core::ScopedConnection> connections;
191 auto ap_connect = [&](std::shared_ptr<connectivity::networking::wifi::AccessPoint> ap) {
192 EXPECT_EQ(ap->ssid(), "abc");
193 EXPECT_TRUE(ap->secured());
194 EXPECT_FALSE(ap->adhoc());
195 //connections.insert(std::make_pair(ap, core::ScopedConnection(con)));
196 };
197
198 wifilink->accessPoints().changed().connect([&](std::set<std::shared_ptr<connectivity::networking::wifi::AccessPoint>> aps) {
199 connections.clear();
200 for (auto ap: aps)
201 ap_connect(ap);
202 });
203
204 client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
205
206 auto aps = wifilink->accessPoints().get();
207 EXPECT_EQ(aps.size(), 1);
208 EXPECT_EQ((*aps.begin())->strength().get(), 60);
209 sleep(5);
210
211 EXPECT_EQ(1, stage1.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
212
213 aps = wifilink->accessPoints().get();
214 EXPECT_EQ(aps.size(), 1);
215 EXPECT_EQ((*aps.begin())->strength().get(), 90);
216
217
218 EXPECT_EQ(1, stage2.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
219
220 sleep(5);
221
222 aps = wifilink->accessPoints().get();
223 EXPECT_EQ(aps.size(), 1);
224 EXPECT_EQ((*aps.begin())->strength().get(), 60);
225
226 EXPECT_EQ(1, stage3.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
227
228 sleep(5);
229
230 aps = wifilink->accessPoints().get();
231 EXPECT_EQ(aps.size(), 0);
232
233 EXPECT_EQ(1, stage4.wait_for_signal_ready_for(std::chrono::milliseconds{10000}));
234
235 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
236 };
237
238 EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
239}
240
2410
=== removed file 'tests/integration/connectivity-cpp/test_wifi_link_enable_disable.cpp'
--- tests/integration/connectivity-cpp/test_wifi_link_enable_disable.cpp 2014-08-19 19:55:15 +0000
+++ tests/integration/connectivity-cpp/test_wifi_link_enable_disable.cpp 1970-01-01 00:00:00 +0000
@@ -1,186 +0,0 @@
1/*
2 * Copyright Ā© 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Antti KaijanmƤki <antti.kaijanmaki@canonical.com>
17 */
18
19#include <core/dbus/dbus.h>
20#include <core/dbus/fixture.h>
21#include <core/dbus/object.h>
22#include <core/dbus/property.h>
23#include <core/dbus/service.h>
24#include <core/dbus/interfaces/properties.h>
25#include <core/dbus/types/stl/tuple.h>
26#include <core/dbus/types/stl/vector.h>
27
28#include <core/dbus/asio/executor.h>
29
30#include "sig_term_catcher.h"
31#include "test_data.h"
32#include "test_service.h"
33
34#include <core/testing/cross_process_sync.h>
35#include <core/testing/fork_and_run.h>
36
37#include <gtest/gtest.h>
38
39#include <system_error>
40#include <thread>
41
42#include <services/nm.h>
43namespace fdo = org::freedesktop;
44namespace NM = fdo::NetworkManager;
45
46#include "mocks/urfkill.h"
47
48#include <connectivity/networking/manager.h>
49#include <connectivity/networking/wifi/link.h>
50#include <connectivity/networking/wifi/access-point.h>
51
52namespace dbus = core::dbus;
53
54namespace
55{
56struct Service : public core::dbus::testing::Fixture {};
57
58auto session_bus_config_file =
59 core::dbus::testing::Fixture::default_session_bus_config_file() =
60 core::testing::session_bus_configuration_file();
61
62auto system_bus_config_file =
63 core::dbus::testing::Fixture::default_system_bus_config_file() =
64 core::testing::system_bus_configuration_file();
65
66}
67
68TEST_F(Service, wifiLink)
69{
70 core::testing::CrossProcessSync services_ready;
71 core::testing::CrossProcessSync client_ready;
72 core::testing::CrossProcessSync stage1;
73 core::testing::CrossProcessSync stage2;
74
75 auto service = [&, this]()
76 {
77 core::testing::SigTermCatcher sc;
78
79 auto bus = system_bus();
80 bus->install_executor(core::dbus::asio::make_executor(bus));
81
82 auto service = NM::Service::Mock(bus);
83 auto nm_root = service.nm;
84
85 auto wifi_dev = NM::Interface::Device(nm_root->service,
86 nm_root->service->add_object_for_path(dbus::types::ObjectPath("/org/freedesktop/NetworkManager/Devices/0")));
87
88 nm_root->object->install_method_handler<NM::Interface::NetworkManager::Method::GetDevices>([bus, &wifi_dev](const dbus::Message::Ptr& msg)
89 {
90 auto reply = dbus::Message::make_method_return(msg);
91 std::vector<dbus::types::ObjectPath> devices;
92 devices.push_back(wifi_dev.object->path());
93 reply->writer() << devices;
94 bus->send(reply);
95 });
96
97 nm_root->state->set(NM_STATE_CONNECTED_GLOBAL);
98 wifi_dev.device_type->set(NM_DEVICE_TYPE_WIFI);
99 wifi_dev.state->set(NM_DEVICE_STATE_ACTIVATED);
100
101 wifi_dev.object->install_method_handler<NM::Interface::Device::Wireless::Method::GetAccessPoints>([&](const dbus::Message::Ptr& msg)
102 {
103 auto reply = dbus::Message::make_method_return(msg);
104 reply->writer() << std::vector<dbus::types::ObjectPath>();
105 bus->send(reply);
106 });
107
108 DefaultURfkillMock urfkill(bus);
109 urfkill.wlan.state.changed().connect([&](fdo::URfkill::Interface::Killswitch::State value) {
110 typedef fdo::URfkill::Interface::Killswitch Killswitch;
111 switch (value) {
112 case Killswitch::State::not_available:
113 case Killswitch::State::unblocked:
114 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE));
115 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_NONE));
116 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE));
117 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE));
118 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_NEED_AUTH, NM_DEVICE_STATE_REASON_NONE));
119 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE));
120 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE));
121 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_SECONDARIES, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE));
122 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_SECONDARIES, NM_DEVICE_STATE_REASON_NONE));
123 break;
124 case Killswitch::State::soft_blocked:
125 case Killswitch::State::hard_blocked:
126 wifi_dev.state_changed->emit(std::make_tuple(NM_DEVICE_STATE_UNAVAILABLE, NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_REASON_NONE));
127 }
128 });
129
130 std::thread t{[bus](){ bus->run(); }};
131
132 services_ready.try_signal_ready_for(std::chrono::milliseconds{5000});
133 EXPECT_EQ(1, client_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
134
135
136 stage1.try_signal_ready_for(std::chrono::milliseconds{5000});
137 sleep(1);
138
139 stage2.try_signal_ready_for(std::chrono::milliseconds{5000});
140 sleep(1);
141
142 sc.wait_for_signal_for(std::chrono::seconds{60});
143
144 bus->stop();
145
146 if (t.joinable())
147 t.join();
148
149 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
150 };
151
152 auto client = [&, this]()
153 {
154 EXPECT_EQ(1, services_ready.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
155 std::unique_ptr<connectivity::networking::Manager> mgr;
156 mgr = connectivity::networking::Manager::createInstance();
157
158 auto links = mgr->links();
159 EXPECT_EQ(links->size(), 1);
160
161 EXPECT_EQ((*links->begin())->type(), connectivity::networking::Link::Type::wifi);
162 auto wifilink = std::dynamic_pointer_cast<connectivity::networking::wifi::Link>(*links->begin());
163 EXPECT_TRUE(wifilink.get() != nullptr);
164
165 client_ready.try_signal_ready_for(std::chrono::milliseconds{2000});
166
167 wifilink->disable();
168 sleep(1);
169
170 EXPECT_EQ(1, stage1.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
171
172 EXPECT_EQ(wifilink->status().get(), connectivity::networking::Link::Status::disabled);
173
174 wifilink->enable();
175
176 sleep(1);
177 EXPECT_EQ(1, stage2.wait_for_signal_ready_for(std::chrono::milliseconds{5000}));
178
179 EXPECT_EQ(wifilink->status().get(), connectivity::networking::Link::Status::online);
180
181 return ::testing::Test::HasFailure() ? core::posix::exit::Status::failure : core::posix::exit::Status::success;
182 };
183
184 EXPECT_EQ(core::testing::ForkAndRunResult::empty, core::testing::fork_and_run(service, client));
185}
186
1870
=== removed directory 'tests/integration/indicator'
=== added file 'tests/integration/indicator-network-test-base.cpp'
--- tests/integration/indicator-network-test-base.cpp 1970-01-01 00:00:00 +0000
+++ tests/integration/indicator-network-test-base.cpp 2015-04-23 13:23:11 +0000
@@ -0,0 +1,338 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <indicator-network-test-base.h>
20#include <dbus-types.h>
21
22using namespace QtDBusTest;
23using namespace QtDBusMock;
24using namespace std;
25using namespace testing;
26namespace mh = menuharness;
27
28IndicatorNetworkTestBase::IndicatorNetworkTestBase() :
29 dbusMock(dbusTestRunner)
30{
31}
32
33IndicatorNetworkTestBase::~IndicatorNetworkTestBase()
34{
35}
36
37void IndicatorNetworkTestBase::SetUp()
38{
39 if (qEnvironmentVariableIsSet("TEST_WITH_BUSTLE"))
40 {
41 const TestInfo* const test_info =
42 UnitTest::GetInstance()->current_test_info();
43
44 QDir::temp().mkpath("indicator-network-tests");
45 QDir testDir(QDir::temp().filePath("indicator-network-tests"));
46
47 dbusTestRunner.registerService(
48 DBusServicePtr(
49 new QProcessDBusService(
50 "", QDBusConnection::SessionBus,
51 "/usr/bin/bustle-pcap",
52 QStringList{"-e", testDir.filePath(QString("%1-%2").arg(test_info->name(), "session.log"))})));
53 dbusTestRunner.registerService(
54 DBusServicePtr(
55 new QProcessDBusService(
56 "", QDBusConnection::SystemBus,
57 "/usr/bin/bustle-pcap",
58 QStringList{"-y", testDir.filePath(QString("%1-%2").arg(test_info->name(), "system.log"))})));
59 }
60
61 dbusMock.registerNetworkManager();
62 dbusMock.registerNotificationDaemon();
63 // By default the ofono mock starts with one modem
64 dbusMock.registerOfono();
65 dbusMock.registerURfkill();
66
67 dbusTestRunner.startServices();
68
69 // Identify the test when looking at Bustle logs
70 QDBusConnection systemConnection = dbusTestRunner.systemConnection();
71 systemConnection.registerService("org.TestIndicatorNetworkService");
72 QDBusConnection sessionConnection = dbusTestRunner.sessionConnection();
73 sessionConnection.registerService("org.TestIndicatorNetworkService");
74}
75
76mh::MenuMatcher::Parameters IndicatorNetworkTestBase::phoneParameters()
77{
78 return mh::MenuMatcher::Parameters(
79 "com.canonical.indicator.network",
80 { { "indicator", "/com/canonical/indicator/network" } },
81 "/com/canonical/indicator/network/phone");
82}
83
84mh::MenuMatcher::Parameters IndicatorNetworkTestBase::unlockSimParameters(std::string const& busName, int exportId)
85{
86 return mh::MenuMatcher::Parameters(
87 busName,
88 { { "notifications", "/com/canonical/indicator/network/unlocksim" + to_string(exportId) } },
89 "/com/canonical/indicator/network/unlocksim" + to_string(exportId));
90}
91
92void IndicatorNetworkTestBase::startIndicator()
93{
94 try
95 {
96 indicator.reset(
97 new QProcessDBusService(DBusTypes::DBUS_NAME,
98 QDBusConnection::SessionBus,
99 NETWORK_SERVICE_BIN,
100 QStringList()));
101 indicator->start(dbusTestRunner.sessionConnection());
102 }
103 catch (exception const& e)
104 {
105 cout << "startIndicator(): " << e.what() << endl;
106 throw;
107 }
108}
109
110QString IndicatorNetworkTestBase::createWiFiDevice(int state, const QString& id)
111{
112 auto& networkManager(dbusMock.networkManagerInterface());
113 auto reply = networkManager.AddWiFiDevice(id, "eth1", state);
114 reply.waitForFinished();
115 return reply;
116}
117
118QString IndicatorNetworkTestBase::randomMac()
119{
120 int high = 254;
121 int low = 1;
122 QString hardwareAddress;
123 bool first = true;
124
125 for (unsigned int i = 0; i < 6; ++i)
126 {
127 if (!first)
128 {
129 hardwareAddress.append(":");
130 }
131 int r = qrand() % ((high + 1) - low) + low;
132 hardwareAddress.append(QString("%1").arg(r, 2, 16, QChar('0')));
133 first = false;
134 }
135
136 return hardwareAddress;
137}
138
139void IndicatorNetworkTestBase::enableWiFi()
140{
141 auto& urfkillInterface = dbusMock.urfkillInterface();
142 urfkillInterface.Block(1, false).waitForFinished();
143}
144
145void IndicatorNetworkTestBase::disableWiFi()
146{
147 auto& urfkillInterface = dbusMock.urfkillInterface();
148 urfkillInterface.Block(1, true).waitForFinished();
149}
150
151QString IndicatorNetworkTestBase::createAccessPoint(const QString& id, const QString& ssid, const QString& device, int strength,
152 Secure secure, ApMode apMode)
153{
154
155 auto& networkManager(dbusMock.networkManagerInterface());
156 auto reply = networkManager.AddAccessPoint(
157 device, id, ssid,
158 randomMac(),
159 apMode == ApMode::adhoc ? NM_802_11_MODE_ADHOC : NM_802_11_MODE_INFRA,
160 0, 0, strength,
161 secure == Secure::secure ? NM_802_11_AP_SEC_KEY_MGMT_PSK : NM_802_11_AP_SEC_NONE);
162 reply.waitForFinished();
163 return reply;
164}
165
166void IndicatorNetworkTestBase::removeAccessPoint(const QString& device, const QString& ap)
167{
168 auto& nm = dbusMock.networkManagerInterface();
169 nm.RemoveAccessPoint(device, ap).waitForFinished();
170}
171
172QString IndicatorNetworkTestBase::createAccessPointConnection(const QString& id, const QString& ssid, const QString& device)
173{
174 auto& networkManager(dbusMock.networkManagerInterface());
175 auto reply = networkManager.AddWiFiConnection(device, id, ssid,
176 "");
177 reply.waitForFinished();
178 return reply;
179}
180
181void IndicatorNetworkTestBase::removeWifiConnection(const QString& device, const QString& connection)
182{
183 auto& nm = dbusMock.networkManagerInterface();
184 nm.RemoveWifiConnection(device, connection).waitForFinished();
185}
186
187QString IndicatorNetworkTestBase::createActiveConnection(const QString& id, const QString& device, const QString& connection, const QString& ap)
188{
189 auto& nm = dbusMock.networkManagerInterface();
190 auto reply = nm.AddActiveConnection(QStringList() << device,
191 connection,
192 ap,
193 id,
194 NM_ACTIVE_CONNECTION_STATE_ACTIVATED);
195 reply.waitForFinished();
196 return reply;
197}
198
199void IndicatorNetworkTestBase::removeActiveConnection(const QString& device, const QString& active_connection)
200{
201 auto& nm = dbusMock.networkManagerInterface();
202 nm.RemoveActiveConnection(device, active_connection).waitForFinished();
203}
204
205void IndicatorNetworkTestBase::setGlobalConnectedState(int state)
206{
207 auto& nm = dbusMock.networkManagerInterface();
208 nm.SetGlobalConnectionState(state).waitForFinished();
209}
210
211void IndicatorNetworkTestBase::setNmProperty(const QString& path, const QString& iface, const QString& name, const QVariant& value)
212{
213 auto& nm = dbusMock.networkManagerInterface();
214 nm.SetProperty(path, iface, name, QDBusVariant(value)).waitForFinished();
215}
216
217QString IndicatorNetworkTestBase::createModem(const QString& id)
218{
219 auto& ofono(dbusMock.ofonoInterface());
220 QVariantMap modemProperties {{ "Powered", false } };
221 return ofono.AddModem(id, modemProperties);
222}
223
224void IndicatorNetworkTestBase::setModemProperty(const QString& path, const QString& propertyName, const QVariant& value)
225{
226 auto& ofono(dbusMock.ofonoModemInterface(path));
227 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
228}
229
230void IndicatorNetworkTestBase::setSimManagerProperty(const QString& path, const QString& propertyName, const QVariant& value)
231{
232 auto& ofono(dbusMock.ofonoSimManagerInterface(path));
233 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
234}
235
236void IndicatorNetworkTestBase::setConnectionManagerProperty(const QString& path, const QString& propertyName, const QVariant& value)
237{
238 auto& ofono(dbusMock.ofonoConnectionManagerInterface(path));
239 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
240}
241
242void IndicatorNetworkTestBase::setNetworkRegistrationProperty(const QString& path, const QString& propertyName, const QVariant& value)
243{
244 auto& ofono(dbusMock.ofonoNetworkRegistrationInterface(path));
245 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
246}
247
248OrgFreedesktopDBusMockInterface& IndicatorNetworkTestBase::notificationsMockInterface()
249{
250 return dbusMock.mockInterface("org.freedesktop.Notifications",
251 "/org/freedesktop/Notifications",
252 "org.freedesktop.Notifications",
253 QDBusConnection::SessionBus);
254}
255
256OrgFreedesktopDBusMockInterface& IndicatorNetworkTestBase::modemMockInterface(const QString& path)
257{
258 return dbusMock.mockInterface("org.ofono",
259 path,
260 "",
261 QDBusConnection::SystemBus);
262}
263
264bool IndicatorNetworkTestBase::qDBusArgumentToMap(QVariant const& variant, QVariantMap& map)
265{
266 if (variant.canConvert<QDBusArgument>())
267 {
268 QDBusArgument value(variant.value<QDBusArgument>());
269 if (value.currentType() == QDBusArgument::MapType)
270 {
271 value >> map;
272 return true;
273 }
274 }
275 return false;
276}
277
278QString IndicatorNetworkTestBase::firstModem()
279{
280 return "/ril_0";
281}
282
283mh::MenuItemMatcher IndicatorNetworkTestBase::flightModeSwitch(bool toggled)
284{
285 return mh::MenuItemMatcher::checkbox()
286 .label("Flight Mode")
287 .action("indicator.airplane.enabled")
288 .toggled(toggled);
289}
290
291mh::MenuItemMatcher IndicatorNetworkTestBase::accessPoint(const string& ssid, Secure secure,
292 ApMode apMode, ConnectionStatus connectionStatus, int strength)
293{
294 return mh::MenuItemMatcher::checkbox()
295 .label(ssid)
296 .widget("unity.widgets.systemsettings.tablet.accesspoint")
297 .toggled(connectionStatus == ConnectionStatus::connected)
298 .pass_through_attribute(
299 "x-canonical-wifi-ap-strength-action",
300 shared_ptr<GVariant>(g_variant_new_byte(strength), &mh::gvariant_deleter))
301 .boolean_attribute("x-canonical-wifi-ap-is-secure", secure == Secure::secure)
302 .boolean_attribute("x-canonical-wifi-ap-is-adhoc", apMode == ApMode::adhoc);
303}
304
305mh::MenuItemMatcher IndicatorNetworkTestBase::wifiEnableSwitch(bool toggled)
306{
307 return mh::MenuItemMatcher::checkbox()
308 .label("Wi-Fi")
309 .action("indicator.wifi.enable") // This action is accessed by system-settings-ui, do not change it
310 .toggled(toggled);
311}
312
313mh::MenuItemMatcher IndicatorNetworkTestBase::wifiSettings()
314{
315 return mh::MenuItemMatcher()
316 .label("Wi-Fi settingsā€¦")
317 .action("indicator.wifi.settings");
318}
319
320mh::MenuItemMatcher IndicatorNetworkTestBase::modemInfo(const string& simIdentifier, const string& label, const string& statusIcon, bool locked)
321{
322 return mh::MenuItemMatcher()
323 .widget("com.canonical.indicator.network.modeminfoitem")
324 .pass_through_string_attribute("x-canonical-modem-sim-identifier-label-action", simIdentifier)
325 .pass_through_string_attribute("x-canonical-modem-connectivity-icon-action", "")
326 .pass_through_string_attribute("x-canonical-modem-status-label-action", label)
327 .pass_through_string_attribute("x-canonical-modem-status-icon-action", statusIcon)
328 .pass_through_boolean_attribute("x-canonical-modem-roaming-action", false)
329 .pass_through_boolean_attribute("x-canonical-modem-locked-action", locked);
330}
331
332mh::MenuItemMatcher IndicatorNetworkTestBase::cellularSettings()
333{
334 return mh::MenuItemMatcher()
335 .label("Cellular settingsā€¦")
336 .action("indicator.cellular.settings");
337}
338
0339
=== added file 'tests/integration/indicator-network-test-base.h'
--- tests/integration/indicator-network-test-base.h 1970-01-01 00:00:00 +0000
+++ tests/integration/indicator-network-test-base.h 2015-04-23 13:23:11 +0000
@@ -0,0 +1,156 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#pragma once
20
21#include <libqtdbustest/DBusTestRunner.h>
22#include <libqtdbustest/QProcessDBusService.h>
23#include <libqtdbusmock/DBusMock.h>
24
25#include <menuharness/MatchUtils.h>
26#include <menuharness/MenuMatcher.h>
27
28#include <NetworkManager.h>
29#include <gmock/gmock.h>
30#include <gtest/gtest.h>
31
32inline void PrintTo(const QVariant& variant, std::ostream* os) {
33 *os << "QVariant(" << variant.toString().toStdString() << ")";
34}
35
36#define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\
37{\
38 while (signalSpy.size() < signalsExpected)\
39 {\
40 ASSERT_TRUE(signalSpy.wait());\
41 }\
42 ASSERT_EQ(signalsExpected, signalSpy.size());\
43}
44
45#define CHECK_METHOD_CALL(signalSpy, signalIndex, methodName, ...)\
46{\
47 QVariantList const& call(signalSpy.at(signalIndex));\
48 EXPECT_EQ(methodName, call.at(0));\
49 auto arguments = vector<pair<int, QVariant>>{__VA_ARGS__};\
50 if (!arguments.empty())\
51 {\
52 QVariantList const& args(call.at(1).toList());\
53 ASSERT_LE(arguments.back().first + 1, args.size());\
54 for (auto const& argument : arguments)\
55 {\
56 EXPECT_EQ(argument.second, args.at(argument.first));\
57 }\
58 }\
59}
60
61class IndicatorNetworkTestBase: public testing::Test
62{
63public:
64 enum class Secure
65 {
66 secure,
67 insecure
68 };
69
70 enum class ApMode
71 {
72 infra,
73 adhoc
74 };
75
76 enum class ConnectionStatus
77 {
78 connected,
79 disconnected
80 };
81
82 IndicatorNetworkTestBase();
83
84 ~IndicatorNetworkTestBase();
85
86protected:
87 void SetUp() override;
88
89 static menuharness::MenuMatcher::Parameters phoneParameters();
90
91 static menuharness::MenuMatcher::Parameters unlockSimParameters(std::string const& busName, int exportId);
92
93 void startIndicator();
94
95 QString createWiFiDevice(int state, const QString& id = "0");
96
97 static QString randomMac();
98
99 void enableWiFi();
100
101 void disableWiFi();
102
103 QString createAccessPoint(const QString& id, const QString& ssid, const QString& device, int strength = 100,
104 Secure secure = Secure::secure, ApMode apMode = ApMode::infra);
105
106 void removeAccessPoint(const QString& device, const QString& ap);
107
108 QString createAccessPointConnection(const QString& id, const QString& ssid, const QString& device);
109
110 void removeWifiConnection(const QString& device, const QString& connection);
111
112 QString createActiveConnection(const QString& id, const QString& device, const QString& connection, const QString& ap);
113
114 void removeActiveConnection(const QString& device, const QString& active_connection);
115
116 void setGlobalConnectedState(int state);
117
118 void setNmProperty(const QString& path, const QString& iface, const QString& name, const QVariant& value);
119
120 QString createModem(const QString& id);
121
122 void setModemProperty(const QString& path, const QString& propertyName, const QVariant& value);
123
124 void setSimManagerProperty(const QString& path, const QString& propertyName, const QVariant& value);
125
126 void setConnectionManagerProperty(const QString& path, const QString& propertyName, const QVariant& value);
127
128 void setNetworkRegistrationProperty(const QString& path, const QString& propertyName, const QVariant& value);
129
130 OrgFreedesktopDBusMockInterface& notificationsMockInterface();
131
132 OrgFreedesktopDBusMockInterface& modemMockInterface(const QString& path);
133
134 static bool qDBusArgumentToMap(QVariant const& variant, QVariantMap& map);
135
136 static QString firstModem();
137
138 static menuharness::MenuItemMatcher flightModeSwitch(bool toggled = false);
139
140 static menuharness::MenuItemMatcher accessPoint(const std::string& ssid, Secure secure,
141 ApMode apMode, ConnectionStatus connectionStatus, int strength = 100);
142
143 static menuharness::MenuItemMatcher wifiEnableSwitch(bool toggled = true);
144
145 static menuharness::MenuItemMatcher wifiSettings();
146
147 static menuharness::MenuItemMatcher modemInfo(const std::string& simIdentifier, const std::string& label, const std::string& statusIcon, bool locked = false);
148
149 static menuharness::MenuItemMatcher cellularSettings();
150
151 QtDBusTest::DBusTestRunner dbusTestRunner;
152
153 QtDBusMock::DBusMock dbusMock;
154
155 QtDBusTest::DBusServicePtr indicator;
156};
0157
=== added file 'tests/integration/test-connectivity-api.cpp'
--- tests/integration/test-connectivity-api.cpp 1970-01-01 00:00:00 +0000
+++ tests/integration/test-connectivity-api.cpp 2015-04-23 13:23:11 +0000
@@ -0,0 +1,289 @@
1/*
2 * Copyright (C) 2015 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Pete Woods <pete.woods@canonical.com>
17 */
18
19#include <indicator-network-test-base.h>
20#include <connectivityqt/connectivity.h>
21#include <dbus-types.h>
22
23#include <QDebug>
24#include <QTestEventLoop>
25#include <QSignalSpy>
26
27using namespace std;
28using namespace testing;
29using namespace connectivityqt;
30
31namespace
32{
33
34class TestConnectivityApi: public IndicatorNetworkTestBase
35{
36protected:
37 Connectivity::UPtr newConnectivity()
38 {
39 auto connectivity = make_unique<Connectivity>(dbusTestRunner.sessionConnection());
40
41 if (!connectivity->isInitialized())
42 {
43 QSignalSpy initSpy(connectivity.get(), SIGNAL(initialized()));
44 initSpy.wait();
45 }
46
47 return connectivity;
48 }
49};
50
51TEST_F(TestConnectivityApi, FollowsFlightMode)
52{
53 // Set up disconnected with flight mode on
54 setGlobalConnectedState(NM_STATE_DISCONNECTED);
55 ASSERT_TRUE(dbusMock.urfkillInterface().FlightMode(true));
56
57 // Start the indicator
58 ASSERT_NO_THROW(startIndicator());
59
60 // Connect to the service
61 auto connectivity(newConnectivity());
62
63 // Check flight mode is enabled
64 EXPECT_TRUE(connectivity->flightMode());
65
66 // Now disable flight mode
67 ASSERT_TRUE(dbusMock.urfkillInterface().FlightMode(false));
68
69 // Check that flight mode gets updated
70 {
71 QSignalSpy spy(connectivity.get(), SIGNAL(flightModeUpdated(bool)));
72 ASSERT_TRUE(spy.wait());
73 ASSERT_EQ(1, spy.size());
74 }
75 // Check that flight mode is disabled
76 EXPECT_FALSE(connectivity->flightMode());
77}
78
79TEST_F(TestConnectivityApi, FlightModeTalksToURfkill)
80{
81 // Start the indicator
82 ASSERT_NO_THROW(startIndicator());
83
84 // Connect to the UrfKill mock
85 auto& urfkillInterface = dbusMock.urfkillInterface();
86 QSignalSpy urfkillSpy(&urfkillInterface, SIGNAL(FlightModeChanged(bool)));
87
88 // Connect the the service
89 auto connectivity(newConnectivity());
90
91 // Follow the flightMode property
92 QSignalSpy flightModeSpy(connectivity.get(), SIGNAL(flightModeUpdated(bool)));
93
94 // Follow the unstoppableOperationHappening property
95 QSignalSpy operationSpy(connectivity.get(), SIGNAL(unstoppableOperationHappeningUpdated(bool)));
96
97 // Check that nothing is happening yet
98 EXPECT_FALSE(connectivity->unstoppableOperationHappening());
99
100 // Enable flight mode
101 connectivity->setFlightMode(true);
102
103 // We should first get the unstoppable operation change
104 ASSERT_TRUE(operationSpy.wait());
105 ASSERT_EQ(1, operationSpy.size());
106 EXPECT_EQ(operationSpy.first(), QVariantList() << QVariant(true));
107
108 // Wait to be notified that flight mode was enabled
109 if (urfkillSpy.size() != 1)
110 {
111 ASSERT_TRUE(urfkillSpy.wait());
112 }
113 ASSERT_EQ(1, urfkillSpy.size());
114 EXPECT_EQ(urfkillSpy.first(), QVariantList() << QVariant(true));
115
116 // The unstoppable operation should complete
117 if (operationSpy.size() != 2)
118 {
119 ASSERT_TRUE(operationSpy.wait());
120 }
121 ASSERT_EQ(2, operationSpy.size());
122 EXPECT_EQ(operationSpy.last(), QVariantList() << QVariant(false));
123
124 // Wait for flight mode property change
125 if (flightModeSpy.size() != 1)
126 {
127 ASSERT_TRUE(flightModeSpy.wait());
128 }
129 ASSERT_EQ(1, flightModeSpy.size());
130 EXPECT_EQ(flightModeSpy.first(), QVariantList() << QVariant(true));
131
132 // Check that nothing is happening again
133 EXPECT_FALSE(connectivity->unstoppableOperationHappening());
134
135 // The icing on the cake
136 EXPECT_TRUE(connectivity->flightMode());
137
138 // Start again
139 urfkillSpy.clear();
140 operationSpy.clear();
141 flightModeSpy.clear();
142
143 // Disable flight mode
144 connectivity->setFlightMode(false);
145
146 // We should first get the unstoppable operation change
147 ASSERT_TRUE(operationSpy.wait());
148 ASSERT_EQ(1, operationSpy.size());
149 EXPECT_EQ(operationSpy.first(), QVariantList() << QVariant(true));
150
151 // Wait to be notified that flight mode was disabled
152 if (urfkillSpy.size() != 1)
153 {
154 ASSERT_TRUE(urfkillSpy.wait());
155 }
156 ASSERT_EQ(1, urfkillSpy.size());
157 EXPECT_EQ(urfkillSpy.first(), QVariantList() << QVariant(false));
158
159 // The unstoppable operation should complete
160 if (operationSpy.size() != 2)
161 {
162 ASSERT_TRUE(operationSpy.wait());
163 }
164 ASSERT_EQ(2, operationSpy.size());
165 EXPECT_EQ(operationSpy.last(), QVariantList() << QVariant(false));
166
167 // Wait for flight mode property change
168 if (flightModeSpy.size() != 1)
169 {
170 ASSERT_TRUE(flightModeSpy.wait());
171 }
172 ASSERT_EQ(1, flightModeSpy.size());
173 EXPECT_EQ(flightModeSpy.first(), QVariantList() << QVariant(false));
174
175 // Check that nothing is happening again
176 EXPECT_FALSE(connectivity->unstoppableOperationHappening());
177
178 // The icing on the cake
179 EXPECT_FALSE(connectivity->flightMode());
180}
181
182TEST_F(TestConnectivityApi, WifiToggleTalksToUrfkill)
183{
184 // Start the indicator
185 ASSERT_NO_THROW(startIndicator());
186
187 // Connect to the UrfKill mock
188 OrgFreedesktopURfkillKillswitchInterface wifiKillswitchInterface(
189 DBusTypes::URFKILL_BUS_NAME, DBusTypes::URFKILL_WIFI_OBJ_PATH,
190 dbusTestRunner.systemConnection());
191 QSignalSpy urfkillSpy(&wifiKillswitchInterface, SIGNAL(StateChanged()));
192
193 // Connect the the service
194 auto connectivity(newConnectivity());
195
196 // Follow the wifiEnabled property
197 QSignalSpy wifiEnabledSpy(connectivity.get(), SIGNAL(wifiEnabledUpdated(bool)));
198
199 // Follow the unstoppableOperationHappening property
200 QSignalSpy operationSpy(connectivity.get(), SIGNAL(unstoppableOperationHappeningUpdated(bool)));
201
202 // Check that nothing is happening yet
203 EXPECT_FALSE(connectivity->unstoppableOperationHappening());
204 EXPECT_TRUE(connectivity->wifiEnabled());
205 EXPECT_EQ(0, wifiKillswitchInterface.state());
206
207 // Disable WiFi
208 connectivity->setwifiEnabled(false);
209
210 // We should first get the unstoppable operation change
211 ASSERT_TRUE(operationSpy.wait());
212 ASSERT_EQ(1, operationSpy.size());
213 EXPECT_EQ(operationSpy.first(), QVariantList() << QVariant(true));
214
215 // Wait to be notified that wifi was toggled
216 if (urfkillSpy.size() != 1)
217 {
218 ASSERT_TRUE(urfkillSpy.wait());
219 }
220 ASSERT_EQ(1, urfkillSpy.size());
221
222 // The unstoppable operation should complete
223 if (operationSpy.size() != 2)
224 {
225 ASSERT_TRUE(operationSpy.wait());
226 }
227 ASSERT_EQ(2, operationSpy.size());
228 EXPECT_EQ(operationSpy.last(), QVariantList() << QVariant(false));
229
230 // Wait for wifi enabled property change
231 if (wifiEnabledSpy.size() != 1)
232 {
233 ASSERT_TRUE(wifiEnabledSpy.wait());
234 }
235 ASSERT_EQ(1, wifiEnabledSpy.size());
236 EXPECT_EQ(wifiEnabledSpy.first(), QVariantList() << QVariant(false));
237
238 // Check that nothing is happening again
239 EXPECT_FALSE(connectivity->unstoppableOperationHappening());
240
241 // The icing on the cake
242 EXPECT_FALSE(connectivity->wifiEnabled());
243 EXPECT_EQ(1, wifiKillswitchInterface.state());
244
245 // Start again
246 urfkillSpy.clear();
247 operationSpy.clear();
248 wifiEnabledSpy.clear();
249
250 // Disable flight mode
251 connectivity->setwifiEnabled(true);
252
253 // We should first get the unstoppable operation change
254 ASSERT_TRUE(operationSpy.wait());
255 ASSERT_EQ(1, operationSpy.size());
256 EXPECT_EQ(operationSpy.first(), QVariantList() << QVariant(true));
257
258 // Wait to be notified that wifi was toggled
259 if (urfkillSpy.size() != 1)
260 {
261 ASSERT_TRUE(urfkillSpy.wait());
262 }
263 ASSERT_EQ(1, urfkillSpy.size());
264
265 // The unstoppable operation should complete
266 if (operationSpy.size() != 2)
267 {
268 ASSERT_TRUE(operationSpy.wait());
269 }
270 ASSERT_EQ(2, operationSpy.size());
271 EXPECT_EQ(operationSpy.last(), QVariantList() << QVariant(false));
272
273 // Wait for wifi enabled property change
274 if (wifiEnabledSpy.size() != 1)
275 {
276 ASSERT_TRUE(wifiEnabledSpy.wait());
277 }
278 ASSERT_EQ(1, wifiEnabledSpy.size());
279 EXPECT_EQ(wifiEnabledSpy.first(), QVariantList() << QVariant(true));
280
281 // Check that nothing is happening again
282 EXPECT_FALSE(connectivity->unstoppableOperationHappening());
283
284 // The icing on the cake
285 EXPECT_TRUE(connectivity->wifiEnabled());
286 EXPECT_EQ(0, wifiKillswitchInterface.state());
287}
288
289}
0290
=== renamed file 'tests/integration/indicator/TestIndicatorNetworkService.cpp' => 'tests/integration/test-indicator.cpp'
--- tests/integration/indicator/TestIndicatorNetworkService.cpp 2015-03-27 08:34:44 +0000
+++ tests/integration/test-indicator.cpp 2015-04-23 13:23:11 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2013 Canonical, Ltd.2 * Copyright (C) 2015 Canonical, Ltd.
3 *3 *
4 * This program is free software: you can redistribute it and/or modify it4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published5 * under the terms of the GNU General Public License version 3, as published
@@ -16,397 +16,24 @@
16 * Author: Pete Woods <pete.woods@canonical.com>16 * Author: Pete Woods <pete.woods@canonical.com>
17 */17 */
1818
19#include <libqtdbustest/DBusTestRunner.h>19#include <indicator-network-test-base.h>
20#include <libqtdbustest/QProcessDBusService.h>
21#include <libqtdbusmock/DBusMock.h>
22
23#include <menuharness/MatchUtils.h>
24#include <menuharness/MenuMatcher.h>
25
26#include <NetworkManager.h>
2720
28#include <QDebug>21#include <QDebug>
29#include <QTestEventLoop>22#include <QTestEventLoop>
30#include <QSignalSpy>23#include <QSignalSpy>
3124
32#include <gmock/gmock.h>
33#include <gtest/gtest.h>
34
35void PrintTo(const QVariant& variant, std::ostream* os) {
36 *os << "QVariant(" << variant.toString().toStdString() << ")";
37}
38
39
40#define WAIT_FOR_SIGNALS(signalSpy, signalsExpected)\
41{\
42 while (signalSpy.size() < signalsExpected)\
43 {\
44 ASSERT_TRUE(signalSpy.wait());\
45 }\
46 ASSERT_EQ(signalsExpected, signalSpy.size());\
47}
48
49#define CHECK_METHOD_CALL(signalSpy, signalIndex, methodName, ...)\
50{\
51 QVariantList const& call(signalSpy.at(signalIndex));\
52 EXPECT_EQ(methodName, call.at(0));\
53 auto arguments = vector<pair<int, QVariant>>{__VA_ARGS__};\
54 if (!arguments.empty())\
55 {\
56 QVariantList const& args(call.at(1).toList());\
57 ASSERT_LE(arguments.back().first + 1, args.size());\
58 for (auto const& argument : arguments)\
59 {\
60 EXPECT_EQ(argument.second, args.at(argument.first));\
61 }\
62 }\
63}
64
65using namespace std;25using namespace std;
66using namespace testing;26using namespace testing;
67using namespace QtDBusTest;
68using namespace QtDBusMock;
69
70namespace mh = menuharness;27namespace mh = menuharness;
7128
72namespace29namespace
73{30{
74enum class Secure31
75{32class TestIndicator: public IndicatorNetworkTestBase
76 secure,33{
77 insecure34};
78};35
7936TEST_F(TestIndicator, BasicMenuContents)
80enum class ApMode
81{
82 infra,
83 adhoc
84};
85
86enum class ConnectionStatus
87{
88 connected,
89 disconnected
90};
91
92class TestIndicatorNetworkService : public Test
93{
94protected:
95 TestIndicatorNetworkService() :
96 dbusMock(dbusTestRunner)
97 {
98 }
99
100 void SetUp() override
101 {
102 if (qEnvironmentVariableIsSet("TEST_WITH_BUSTLE"))
103 {
104 const TestInfo* const test_info =
105 UnitTest::GetInstance()->current_test_info();
106
107 QDir::temp().mkpath("indicator-network-tests");
108 QDir testDir(QDir::temp().filePath("indicator-network-tests"));
109
110 dbusTestRunner.registerService(
111 DBusServicePtr(
112 new QProcessDBusService(
113 "", QDBusConnection::SessionBus,
114 "/usr/bin/bustle-pcap",
115 QStringList{"-e", testDir.filePath(QString("%1-%2").arg(test_info->name(), "session.log"))})));
116 dbusTestRunner.registerService(
117 DBusServicePtr(
118 new QProcessDBusService(
119 "", QDBusConnection::SystemBus,
120 "/usr/bin/bustle-pcap",
121 QStringList{"-y", testDir.filePath(QString("%1-%2").arg(test_info->name(), "system.log"))})));
122 }
123
124 dbusMock.registerNetworkManager();
125 dbusMock.registerNotificationDaemon();
126 // By default the ofono mock starts with one modem
127 dbusMock.registerOfono();
128 dbusMock.registerURfkill();
129
130 dbusTestRunner.startServices();
131
132 // Identify the test when looking at Bustle logs
133 QDBusConnection systemConnection = dbusTestRunner.systemConnection();
134 systemConnection.registerService("org.TestIndicatorNetworkService");
135 QDBusConnection sessionConnection = dbusTestRunner.sessionConnection();
136 sessionConnection.registerService("org.TestIndicatorNetworkService");
137 }
138
139 static mh::MenuMatcher::Parameters phoneParameters()
140 {
141 return mh::MenuMatcher::Parameters(
142 "com.canonical.indicator.network",
143 { { "indicator", "/com/canonical/indicator/network" } },
144 "/com/canonical/indicator/network/phone");
145 }
146
147 mh::MenuMatcher::Parameters unlockSimParameters(std::string const& busName, int exportId)
148 {
149 return mh::MenuMatcher::Parameters(
150 busName,
151 { { "notifications", "/com/canonical/indicator/network/unlocksim" + to_string(exportId) } },
152 "/com/canonical/indicator/network/unlocksim" + to_string(exportId));
153 }
154
155 void startIndicator()
156 {
157 try
158 {
159 indicator.reset(
160 new QProcessDBusService("com.canonical.indicator.network",
161 QDBusConnection::SessionBus,
162 NETWORK_SERVICE_BIN,
163 QStringList()));
164 indicator->start(dbusTestRunner.sessionConnection());
165 }
166 catch (exception const& e)
167 {
168 cout << "startIndicator(): " << e.what() << endl;
169 throw;
170 }
171 }
172
173 QString createWiFiDevice(int state, const QString& id = "0")
174 {
175 auto& networkManager(dbusMock.networkManagerInterface());
176 auto reply = networkManager.AddWiFiDevice(id, "eth1", state);
177 reply.waitForFinished();
178 return reply;
179 }
180
181 static QString randomMac()
182 {
183 int high = 254;
184 int low = 1;
185 QString hardwareAddress;
186 bool first = true;
187
188 for (unsigned int i = 0; i < 6; ++i)
189 {
190 if (!first)
191 {
192 hardwareAddress.append(":");
193 }
194 int r = qrand() % ((high + 1) - low) + low;
195 hardwareAddress.append(QString("%1").arg(r, 2, 16, QChar('0')));
196 first = false;
197 }
198
199 return hardwareAddress;
200 }
201
202 void enableWiFi()
203 {
204 auto& urfkillInterface = dbusMock.urfkillInterface();
205 urfkillInterface.Block(1, false).waitForFinished();
206 }
207
208 void disableWiFi()
209 {
210 auto& urfkillInterface = dbusMock.urfkillInterface();
211 urfkillInterface.Block(1, true).waitForFinished();
212 }
213
214 QString createAccessPoint(const QString& id, const QString& ssid, const QString& device, int strength = 100,
215 Secure secure = Secure::secure, ApMode apMode = ApMode::infra)
216 {
217
218 auto& networkManager(dbusMock.networkManagerInterface());
219 auto reply = networkManager.AddAccessPoint(
220 device, id, ssid,
221 randomMac(),
222 apMode == ApMode::adhoc ? NM_802_11_MODE_ADHOC : NM_802_11_MODE_INFRA,
223 0, 0, strength,
224 secure == Secure::secure ? NM_802_11_AP_SEC_KEY_MGMT_PSK : NM_802_11_AP_SEC_NONE);
225 reply.waitForFinished();
226 return reply;
227 }
228
229 void removeAccessPoint(const QString& device, const QString& ap)
230 {
231 auto& nm = dbusMock.networkManagerInterface();
232 nm.RemoveAccessPoint(device, ap).waitForFinished();
233 }
234
235 QString createAccessPointConnection(const QString& id, const QString& ssid, const QString& device)
236 {
237 auto& networkManager(dbusMock.networkManagerInterface());
238 auto reply = networkManager.AddWiFiConnection(device, id, ssid,
239 "");
240 reply.waitForFinished();
241 return reply;
242 }
243
244 void removeWifiConnection(const QString& device, const QString& connection)
245 {
246 auto& nm = dbusMock.networkManagerInterface();
247 nm.RemoveWifiConnection(device, connection).waitForFinished();
248 }
249
250 QString createActiveConnection(const QString& id, const QString& device, const QString& connection, const QString& ap)
251 {
252 auto& nm = dbusMock.networkManagerInterface();
253 auto reply = nm.AddActiveConnection(QStringList() << device,
254 connection,
255 ap,
256 id,
257 NM_ACTIVE_CONNECTION_STATE_ACTIVATED);
258 reply.waitForFinished();
259 return reply;
260 }
261
262 void removeActiveConnection(const QString& device, const QString& active_connection)
263 {
264 auto& nm = dbusMock.networkManagerInterface();
265 nm.RemoveActiveConnection(device, active_connection).waitForFinished();
266 }
267
268 void setGlobalConnectedState(int state)
269 {
270 auto& nm = dbusMock.networkManagerInterface();
271 nm.SetGlobalConnectionState(state).waitForFinished();
272 }
273
274 void setNmProperty(const QString& path, const QString& iface, const QString& name, const QVariant& value)
275 {
276 auto& nm = dbusMock.networkManagerInterface();
277 nm.SetProperty(path, iface, name, QDBusVariant(value)).waitForFinished();
278 }
279
280 QString createModem(const QString& id)
281 {
282 auto& ofono(dbusMock.ofonoInterface());
283 QVariantMap modemProperties {{ "Powered", false } };
284 return ofono.AddModem(id, modemProperties);
285 }
286
287 void setModemProperty(const QString& path, const QString& propertyName, const QVariant& value)
288 {
289 auto& ofono(dbusMock.ofonoModemInterface(path));
290 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
291 }
292
293 void setSimManagerProperty(const QString& path, const QString& propertyName, const QVariant& value)
294 {
295 auto& ofono(dbusMock.ofonoSimManagerInterface(path));
296 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
297 }
298
299 void setConnectionManagerProperty(const QString& path, const QString& propertyName, const QVariant& value)
300 {
301 auto& ofono(dbusMock.ofonoConnectionManagerInterface(path));
302 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
303 }
304
305 void setNetworkRegistrationProperty(const QString& path, const QString& propertyName, const QVariant& value)
306 {
307 auto& ofono(dbusMock.ofonoNetworkRegistrationInterface(path));
308 ofono.SetProperty(propertyName, QDBusVariant(value)).waitForFinished();
309 }
310
311 OrgFreedesktopDBusMockInterface* notificationsMockInterface()
312 {
313 return &dbusMock.mockInterface("org.freedesktop.Notifications",
314 "/org/freedesktop/Notifications",
315 "org.freedesktop.Notifications",
316 QDBusConnection::SessionBus);
317 }
318
319 OrgFreedesktopDBusMockInterface* modemMockInterface(const QString& path)
320 {
321 return &dbusMock.mockInterface("org.ofono",
322 path,
323 "",
324 QDBusConnection::SystemBus);
325 }
326
327 bool qDBusArgumentToMap(QVariant const& variant, QVariantMap& map)
328 {
329 if (variant.canConvert<QDBusArgument>())
330 {
331 QDBusArgument value(variant.value<QDBusArgument>());
332 if (value.currentType() == QDBusArgument::MapType)
333 {
334 value >> map;
335 return true;
336 }
337 }
338 return false;
339 }
340
341 QString firstModem()
342 {
343 return "/ril_0";
344 }
345
346 static mh::MenuItemMatcher flightModeSwitch(bool toggled = false)
347 {
348 return mh::MenuItemMatcher::checkbox()
349 .label("Flight Mode")
350 .action("indicator.airplane.enabled")
351 .toggled(toggled);
352 }
353
354 static mh::MenuItemMatcher accessPoint(const string& ssid, Secure secure,
355 ApMode apMode, ConnectionStatus connectionStatus, int strength = 100)
356 {
357 return mh::MenuItemMatcher::checkbox()
358 .label(ssid)
359 .widget("unity.widgets.systemsettings.tablet.accesspoint")
360 .toggled(connectionStatus == ConnectionStatus::connected)
361 .pass_through_attribute(
362 "x-canonical-wifi-ap-strength-action",
363 shared_ptr<GVariant>(g_variant_new_byte(strength), &mh::gvariant_deleter))
364 .boolean_attribute("x-canonical-wifi-ap-is-secure", secure == Secure::secure)
365 .boolean_attribute("x-canonical-wifi-ap-is-adhoc", apMode == ApMode::adhoc);
366 }
367
368 static mh::MenuItemMatcher wifiEnableSwitch(bool toggled = true)
369 {
370 return mh::MenuItemMatcher::checkbox()
371 .label("Wi-Fi")
372 .action("indicator.wifi.enable") // This action is accessed by system-settings-ui, do not change it
373 .toggled(toggled);
374 }
375
376 static mh::MenuItemMatcher wifiSettings()
377 {
378 return mh::MenuItemMatcher()
379 .label("Wi-Fi settingsā€¦")
380 .action("indicator.wifi.settings");
381 }
382
383 static mh::MenuItemMatcher modemInfo(const string& simIdentifier, const string& label, const string& statusIcon, bool locked = false)
384 {
385 return mh::MenuItemMatcher()
386 .widget("com.canonical.indicator.network.modeminfoitem")
387 .pass_through_string_attribute("x-canonical-modem-sim-identifier-label-action", simIdentifier)
388 .pass_through_string_attribute("x-canonical-modem-connectivity-icon-action", "")
389 .pass_through_string_attribute("x-canonical-modem-status-label-action", label)
390 .pass_through_string_attribute("x-canonical-modem-status-icon-action", statusIcon)
391 .pass_through_boolean_attribute("x-canonical-modem-roaming-action", false)
392 .pass_through_boolean_attribute("x-canonical-modem-locked-action", locked);
393 }
394
395 static mh::MenuItemMatcher cellularSettings()
396 {
397 return mh::MenuItemMatcher()
398 .label("Cellular settingsā€¦")
399 .action("indicator.cellular.settings");
400 }
401
402 DBusTestRunner dbusTestRunner;
403
404 DBusMock dbusMock;
405
406 DBusServicePtr indicator;
407};
408
409TEST_F(TestIndicatorNetworkService, BasicMenuContents)
410{37{
411 setGlobalConnectedState(NM_STATE_DISCONNECTED);38 setGlobalConnectedState(NM_STATE_DISCONNECTED);
412 ASSERT_NO_THROW(startIndicator());39 ASSERT_NO_THROW(startIndicator());
@@ -428,7 +55,7 @@
428 ).match());55 ).match());
429}56}
43057
431TEST_F(TestIndicatorNetworkService, OneDisconnectedAccessPointAtStartup)58TEST_F(TestIndicator, OneDisconnectedAccessPointAtStartup)
432{59{
433 setGlobalConnectedState(NM_STATE_DISCONNECTED);60 setGlobalConnectedState(NM_STATE_DISCONNECTED);
434 auto device = createWiFiDevice(NM_DEVICE_STATE_DISCONNECTED);61 auto device = createWiFiDevice(NM_DEVICE_STATE_DISCONNECTED);
@@ -456,7 +83,7 @@
456 ).match());83 ).match());
457}84}
45885
459TEST_F(TestIndicatorNetworkService, OneConnectedAccessPointAtStartup)86TEST_F(TestIndicator, OneConnectedAccessPointAtStartup)
460{87{
461 setGlobalConnectedState(NM_STATE_CONNECTED_GLOBAL);88 setGlobalConnectedState(NM_STATE_CONNECTED_GLOBAL);
462 auto device = createWiFiDevice(NM_DEVICE_STATE_ACTIVATED);89 auto device = createWiFiDevice(NM_DEVICE_STATE_ACTIVATED);
@@ -485,7 +112,7 @@
485 ).match());112 ).match());
486}113}
487114
488TEST_F(TestIndicatorNetworkService, AddOneDisconnectedAccessPointAfterStartup)115TEST_F(TestIndicator, AddOneDisconnectedAccessPointAfterStartup)
489{116{
490 setGlobalConnectedState(NM_STATE_DISCONNECTED);117 setGlobalConnectedState(NM_STATE_DISCONNECTED);
491 auto device = createWiFiDevice(NM_DEVICE_STATE_DISCONNECTED);118 auto device = createWiFiDevice(NM_DEVICE_STATE_DISCONNECTED);
@@ -512,7 +139,7 @@
512 ).match());139 ).match());
513}140}
514141
515TEST_F(TestIndicatorNetworkService, AddOneConnectedAccessPointAfterStartup)142TEST_F(TestIndicator, AddOneConnectedAccessPointAfterStartup)
516{143{
517 setGlobalConnectedState(NM_STATE_DISCONNECTED);144 setGlobalConnectedState(NM_STATE_DISCONNECTED);
518 auto device = createWiFiDevice(NM_DEVICE_STATE_DISCONNECTED);145 auto device = createWiFiDevice(NM_DEVICE_STATE_DISCONNECTED);
@@ -542,7 +169,7 @@
542 ).match());169 ).match());
543}170}
544171
545TEST_F(TestIndicatorNetworkService, SecondModem)172TEST_F(TestIndicator, SecondModem)
546{173{
547 createModem("ril_1"); // ril_0 already exists174 createModem("ril_1"); // ril_0 already exists
548 ASSERT_NO_THROW(startIndicator());175 ASSERT_NO_THROW(startIndicator());
@@ -562,7 +189,7 @@
562 ).match());189 ).match());
563}190}
564191
565TEST_F(TestIndicatorNetworkService, FlightModeTalksToURfkill)192TEST_F(TestIndicator, FlightModeTalksToURfkill)
566{193{
567 ASSERT_NO_THROW(startIndicator());194 ASSERT_NO_THROW(startIndicator());
568195
@@ -583,7 +210,7 @@
583 EXPECT_EQ(urfkillSpy.first(), QVariantList() << QVariant(true));210 EXPECT_EQ(urfkillSpy.first(), QVariantList() << QVariant(true));
584}211}
585212
586TEST_F(TestIndicatorNetworkService, IndicatorListensToURfkill)213TEST_F(TestIndicator, IndicatorListensToURfkill)
587{214{
588 setGlobalConnectedState(NM_STATE_CONNECTED_GLOBAL);215 setGlobalConnectedState(NM_STATE_CONNECTED_GLOBAL);
589 auto device = createWiFiDevice(NM_DEVICE_STATE_ACTIVATED);216 auto device = createWiFiDevice(NM_DEVICE_STATE_ACTIVATED);
@@ -621,7 +248,7 @@
621 ).match());248 ).match());
622}249}
623250
624TEST_F(TestIndicatorNetworkService, SimStates_NoSIM)251TEST_F(TestIndicator, SimStates_NoSIM)
625{252{
626 // set flight mode off, wifi off, and cell data off253 // set flight mode off, wifi off, and cell data off
627 setGlobalConnectedState(NM_STATE_DISCONNECTED);254 setGlobalConnectedState(NM_STATE_DISCONNECTED);
@@ -646,7 +273,7 @@
646 ).match());273 ).match());
647}274}
648275
649TEST_F(TestIndicatorNetworkService, SimStates_NoSIM2)276TEST_F(TestIndicator, SimStates_NoSIM2)
650{277{
651 // set flight mode off, wifi off, and cell data off278 // set flight mode off, wifi off, and cell data off
652 setGlobalConnectedState(NM_STATE_DISCONNECTED);279 setGlobalConnectedState(NM_STATE_DISCONNECTED);
@@ -673,7 +300,7 @@
673 ).match());300 ).match());
674}301}
675302
676TEST_F(TestIndicatorNetworkService, SimStates_LockedSIM)303TEST_F(TestIndicator, SimStates_LockedSIM)
677{304{
678 // set flight mode off, wifi off, and cell data off, and sim in305 // set flight mode off, wifi off, and cell data off, and sim in
679 setGlobalConnectedState(NM_STATE_DISCONNECTED);306 setGlobalConnectedState(NM_STATE_DISCONNECTED);
@@ -717,7 +344,7 @@
717 ).match());344 ).match());
718}345}
719346
720TEST_F(TestIndicatorNetworkService, SimStates_LockedSIM2)347TEST_F(TestIndicator, SimStates_LockedSIM2)
721{348{
722 // set flight mode off, wifi off, and cell data off, and sim in349 // set flight mode off, wifi off, and cell data off, and sim in
723 setGlobalConnectedState(NM_STATE_DISCONNECTED);350 setGlobalConnectedState(NM_STATE_DISCONNECTED);
@@ -762,7 +389,7 @@
762 ).match());389 ).match());
763}390}
764391
765TEST_F(TestIndicatorNetworkService, SimStates_UnlockedSIM)392TEST_F(TestIndicator, SimStates_UnlockedSIM)
766{393{
767 // set flight mode off, wifi off, cell data off, sim in, and sim unlocked394 // set flight mode off, wifi off, cell data off, sim in, and sim unlocked
768 setGlobalConnectedState(NM_STATE_DISCONNECTED);395 setGlobalConnectedState(NM_STATE_DISCONNECTED);
@@ -886,7 +513,7 @@
886 ).match());513 ).match());
887}514}
888515
889TEST_F(TestIndicatorNetworkService, SimStates_UnlockedSIM2)516TEST_F(TestIndicator, SimStates_UnlockedSIM2)
890{517{
891 // set flight mode off, wifi off, cell data off, sim in, and sim unlocked518 // set flight mode off, wifi off, cell data off, sim in, and sim unlocked
892 setGlobalConnectedState(NM_STATE_DISCONNECTED);519 setGlobalConnectedState(NM_STATE_DISCONNECTED);
@@ -1018,7 +645,7 @@
1018 ).match());645 ).match());
1019}646}
1020647
1021TEST_F(TestIndicatorNetworkService, FlightMode_NoSIM)648TEST_F(TestIndicator, FlightMode_NoSIM)
1022{649{
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches