on xenial help sign in
Fix isPC property of Unity/Platform plugin
411188cPete Woods
CMakeLists.txt+5
@@ -69,6 +69,7 @@ find_package(Qt5Gui 5.6 REQUIRED)
69find_package(Qt5DBus 5.6 REQUIRED)
69find_package(Qt5DBus 5.6 REQUIRED)
70find_package(Qt5Concurrent 5.6 REQUIRED)
70find_package(Qt5Concurrent 5.6 REQUIRED)
71find_package(Qt5Sql 5.6 REQUIRED)
71find_package(Qt5Sql 5.6 REQUIRED)
72+find_package(Qt5Test 5.6 REQUIRED)
72
73
73pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=27)
74pkg_check_modules(APPLICATION_API REQUIRED unity-shell-application=27)
74pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
75pkg_check_modules(GEONAMES REQUIRED geonames>=0.2)
@@ -79,6 +80,10 @@ pkg_check_modules(QMENUMODEL REQUIRED qmenumodel)
79pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
80pkg_check_modules(GD3 REQUIRED gnome-desktop-3.0)
80pkg_check_modules(UAL REQUIRED ubuntu-app-launch-3)
81pkg_check_modules(UAL REQUIRED ubuntu-app-launch-3)
81pkg_check_modules(UBUNTUGESTURES REQUIRED UbuntuGestures)
82pkg_check_modules(UBUNTUGESTURES REQUIRED UbuntuGestures)
83+pkg_check_modules(QTDBUSTEST REQUIRED
84+ libqtdbustest-1
85+ libqtdbusmock-1
86+ )
82
87
83### Check UbuntuGestures private headers. No pkg-config (.pc) file is provided for them
88### Check UbuntuGestures private headers. No pkg-config (.pc) file is provided for them
84find_path(UBUNTUGESTUREPRIV
89find_path(UBUNTUGESTUREPRIV
debian/control+2
@@ -29,6 +29,8 @@ Build-Depends: cmake,
29 libpam0g-dev,
29 libpam0g-dev,
30 libpulse-dev,
30 libpulse-dev,
31 libqmenumodel-dev (>= 0.2.12),
31 libqmenumodel-dev (>= 0.2.12),
32+ libqtdbusmock1-dev (>= 0.7),
33+ libqtdbustest1-dev,
32 libqt5svg5-dev,
34 libqt5svg5-dev,
33 libqt5xmlpatterns5-dev,
35 libqt5xmlpatterns5-dev,
34 libsystemsettings-dev,
36 libsystemsettings-dev,
plugins/Unity/Platform/platform.cpp+9−2
@@ -17,9 +17,11 @@
17#include "platform.h"
17#include "platform.h"
18
18
19#include <QDBusConnection>
19#include <QDBusConnection>
20+#include <QSet>
21+#include <QString>
20
22
21Platform::Platform(QObject *parent)
23Platform::Platform(QObject *parent)
22− : QObject(parent)
24+ : QObject(parent), m_isPC(true), m_isMultiSession(true)
23{
25{
24 QMetaObject::invokeMethod(this, "init");
26 QMetaObject::invokeMethod(this, "init");
25}
27}
@@ -31,8 +33,13 @@ void Platform::init()
31 QDBusInterface seatIface("org.freedesktop.login1", "/org/freedesktop/login1/seat/self", "org.freedesktop.login1.Seat",
33 QDBusInterface seatIface("org.freedesktop.login1", "/org/freedesktop/login1/seat/self", "org.freedesktop.login1.Seat",
32 QDBusConnection::systemBus(), this);
34 QDBusConnection::systemBus(), this);
33
35
36+ // From the docs at https://www.freedesktop.org/wiki/Software/systemd/hostnamed/
37+ // the options are "desktop", "laptop", "server", "tablet", "handset", as well
38+ // as the special chassis types "vm" and "container".
34 m_chassis = iface.property("Chassis").toString();
39 m_chassis = iface.property("Chassis").toString();
35− m_isPC = (m_chassis == "desktop" || m_chassis == "laptop" || m_chassis == "server");
40+
41+ // A PC is not a phone or tablet.
42+ m_isPC = !QSet<QString>{"handset", "tablet"}.contains(m_chassis);
36 m_isMultiSession = seatIface.property("CanMultiSession").toBool() && seatIface.property("CanGraphical").toBool();
43 m_isMultiSession = seatIface.property("CanMultiSession").toBool() && seatIface.property("CanGraphical").toBool();
37}
44}
38
45
tests/CMakeLists.txt+1
@@ -20,6 +20,7 @@ add_subdirectory(uqmlscene)
20# Use our custom implementation of qmlscene and import dbus-test-runner
20# Use our custom implementation of qmlscene and import dbus-test-runner
21add_executable(qmlscene ALIAS uqmlscene)
21add_executable(qmlscene ALIAS uqmlscene)
22import_executables(dbus-test-runner)
22import_executables(dbus-test-runner)
23+import_executables(qdbus-simple-test-runner)
23
24
24set(UNITY_PLUGINPATH "${CMAKE_BINARY_DIR}/plugins" CACHE PATH "Path to pre-built unity8 plugin dir.")
25set(UNITY_PLUGINPATH "${CMAKE_BINARY_DIR}/plugins" CACHE PATH "Path to pre-built unity8 plugin dir.")
25set(UNITY_MOCKPATH "${CMAKE_BINARY_DIR}/tests/mocks" CACHE PATH "Path to pre-built unity8 mock dir.")
26set(UNITY_MOCKPATH "${CMAKE_BINARY_DIR}/tests/mocks" CACHE PATH "Path to pre-built unity8 mock dir.")
tests/plugins/Unity/CMakeLists.txt+1
@@ -1,3 +1,4 @@
1add_subdirectory(Indicators)
1add_subdirectory(Indicators)
2add_subdirectory(Launcher)
2add_subdirectory(Launcher)
3+add_subdirectory(Platform)
3add_subdirectory(Session)
4add_subdirectory(Session)
tests/plugins/Unity/Platform/CMakeLists.txtnew file+25
@@ -0,0 +1,25 @@
1+
2+include_directories(
3+ ${Qt5Core_INCLUDE_DIRS}
4+ ${Qt5DBus_INCLUDE_DIRS}
5+ ${Qt5Test_INCLUDE_DIRS}
6+ ${QTDBUSTEST_INCLUDE_DIRS}
7+ ${CMAKE_CURRENT_BINARY_DIR}
8+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Platform
9+)
10+
11+add_executable(platformtest
12+ platformtest.cpp
13+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Platform/platform.cpp
14+ )
15+
16+target_link_libraries(platformtest
17+ Qt5::Core
18+ Qt5::DBus
19+ Qt5::Test
20+ ${QTDBUSTEST_LDFLAGS}
21+ )
22+
23+add_unity8_unittest(platformtest qdbus-simple-test-runner
24+ ARGS "${CMAKE_BINARY_DIR}/platformtest"
25+ )
tests/plugins/Unity/Platform/platformtest.cppnew file+140
@@ -0,0 +1,140 @@
1+/*
2+ * Copyright (C) 2017 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
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 General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along 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 "platform.h"
21+
22+#include <libqtdbustest/DBusTestRunner.h>
23+#include <libqtdbusmock/DBusMock.h>
24+
25+#include <QtTest>
26+#include <QDebug>
27+
28+using namespace QtDBusTest;
29+using namespace QtDBusMock;
30+
31+class PlatformTest: public QObject
32+{
33+
34+Q_OBJECT
35+
36+private:
37+ struct TestFixture
38+ {
39+ TestFixture() :
40+ mock(dbus)
41+ {
42+ }
43+
44+ DBusTestRunner dbus;
45+ DBusMock mock;
46+ };
47+
48+ QScopedPointer<TestFixture> m_data;
49+
50+ void registerLogin1(bool canMultiSession, bool canGraphical)
51+ {
52+ m_data->mock.registerLogin1({{"DefaultSeat", QVariantMap
53+ {
54+ {"CanMultiSession", canMultiSession},
55+ {"CanGraphical", canGraphical}
56+ }}}
57+ );
58+ }
59+
60+ void registerHostname1(const QString& chassis)
61+ {
62+ m_data->mock.registerHostname1({
63+ {"Chassis", chassis}
64+ });
65+ }
66+
67+ void startServices()
68+ {
69+ m_data->dbus.startServices();
70+ }
71+
72+private Q_SLOTS:
73+
74+ void init()
75+ {
76+ m_data.reset(new TestFixture);
77+ }
78+
79+ void cleanup()
80+ {
81+ m_data.reset();
82+ }
83+
84+ void testIsPC_data()
85+ {
86+ QTest::addColumn<QString>("chassis");
87+ QTest::addColumn<bool>("result");
88+
89+ QTest::newRow("desktop") << "desktop" << true;
90+ QTest::newRow("laptop") << "laptop" << true;
91+ QTest::newRow("server") << "server" << true;
92+ QTest::newRow("tablet") << "tablet" << false;
93+ QTest::newRow("handset") << "handset" << false;
94+ QTest::newRow("vm") << "vm" << true;
95+ QTest::newRow("container") << "container" << true;
96+ }
97+
98+ void testIsPC()
99+ {
100+ QFETCH(QString, chassis);
101+ QFETCH(bool, result);
102+
103+ registerLogin1(true, true);
104+ registerHostname1(chassis);
105+ startServices();
106+
107+ Platform p;
108+ QCOMPARE(p.isPC(), result);
109+ QCOMPARE(p.chassis(), chassis);
110+ }
111+
112+ void testIsMultiSession_data()
113+ {
114+ QTest::addColumn<bool>("canMultiSession");
115+ QTest::addColumn<bool>("canGraphical");
116+ QTest::addColumn<bool>("result");
117+
118+ QTest::newRow("") << true << true << true;
119+ QTest::newRow("") << true << false << false;
120+ QTest::newRow("") << false << true << false;
121+ QTest::newRow("") << false << false << false;
122+ }
123+
124+ void testIsMultiSession()
125+ {
126+ QFETCH(bool, canMultiSession);
127+ QFETCH(bool, canGraphical);
128+ QFETCH(bool, result);
129+
130+ registerLogin1(canMultiSession, canGraphical);
131+ registerHostname1("desktop");
132+ startServices();
133+
134+ Platform p;
135+ QCOMPARE(p.isMultiSession(), result);
136+ }
137+};
138+
139+QTEST_GUILESS_MAIN(PlatformTest)
140+#include "platformtest.moc"