on xenial help sign in
Allow loading the device configuration from an external file

Approved by: Daniel d'Andrada

commitabf4a12bdc5e9cbc762c0a98bbc6829a9dad0e8e authorMichael Zanetti <michael.zanetti@canonical.com> dateThu 10 Mar 2016, 22:41 (11 years ago) parentebb76911890820
13 files changed+430−17
debian/unity8-doc.install+1 doc/devices.conf+30 plugins/Utils/CMakeLists.txt+1 plugins/Utils/deviceconfigparser.cpp+150 plugins/Utils/deviceconfigparser.h+62 plugins/Utils/plugin.cpp+2 qml/DeviceConfiguration.qml+54−16 tests/mocks/Utils/CMakeLists.txt+1 tests/mocks/Utils/plugin.cpp+2 tests/plugins/Utils/CMakeLists.txt+7−1 tests/plugins/Utils/DeviceConfigParserTest.cpp+70 tests/qmltests/CMakeLists.txt+1 tests/qmltests/tst_DeviceConfiguration.qml+49
debian/unity8-doc.install+1
@@ -1 +1,2 @@
1+doc/devices.conf usr/share/doc/unity8/
12usr/share/doc/unity8/*
doc/devices.confnew file+30
@@ -0,0 +1,30 @@
1+# This file can hold multiple device configs. Devices are separated by sections.
2+#
3+# SupportedOrientations holds a list of all enabled orientations. A standard
4+# phone will usually have Portrait,Landcape,InvertedLandscape in order to
5+# disable upside down usage.
6+#
7+# PrimaryOrientation gives the orientation the device will start up with
8+# when there is no orientations sensor input available (yet) or lock to
9+# when an application specifies to be locked to PrimaryOrientation.
10+#
11+# The other Orientation settings can be used to re-map the orientations.
12+# A device might be used with different orientations than how the screen
13+# is physically mounted on the hardware.
14+#
15+# Category can be phone, tablet, or desktop. This option determines
16+# whether the side stage is shown (tablet) or not (phone). Using
17+# desktop will load the shell in windowed mode. Note that the user
18+# can override/change this by connecting input hardware or change
19+# user settings.
20+#
21+# Any options not listed will default to the values of the example below.
22+
23+[devicename]
24+SupportedOrientations=Portrait,InvertedPortrait,Landscape,InvertedLandscape
25+PrimaryOrientation=PrimaryOrienation
26+PortraitOrientation=Portrait
27+InvertedPortraitOrientation=InvertedPortrait
28+LandscapeOrientation=Landscape
29+InvertedLandscapeOrientation=InvertedLandscape
30+Category=phone
plugins/Utils/CMakeLists.txt+1
@@ -23,6 +23,7 @@ set(QMLPLUGIN_SRC
2323 windowstatestorage.cpp
2424 timezoneFormatter.cpp
2525 inputeventgenerator.cpp
26+ deviceconfigparser.cpp
2627 plugin.cpp
2728 )
2829
plugins/Utils/deviceconfigparser.cppnew file+150
@@ -0,0 +1,150 @@
1+/*
2+ * Copyright 2016 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser 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 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+
17+#include "deviceconfigparser.h"
18+
19+#include <QSettings>
20+#include <QFileInfo>
21+#include <QDebug>
22+#include <QStandardPaths>
23+
24+DeviceConfigParser::DeviceConfigParser(QObject *parent): QObject(parent)
25+{
26+ QString path;
27+ Q_FOREACH (const QString &standardPath, QStandardPaths::standardLocations(QStandardPaths::GenericConfigLocation)) {
28+ if (QFileInfo(standardPath + "/devices.conf").exists()) {
29+ path = standardPath + "/devices.conf";
30+ break;
31+ }
32+ }
33+
34+ if (path.isEmpty()) {
35+ path = "/etc/ubuntu/devices.conf";
36+ }
37+ qDebug() << "Using" << path << "as device configuration file";
38+ m_config = new QSettings(path, QSettings::IniFormat, this);
39+}
40+
41+QString DeviceConfigParser::name() const
42+{
43+ return m_name;
44+}
45+
46+void DeviceConfigParser::setName(const QString &name)
47+{
48+ if (m_name == name) {
49+ return;
50+ }
51+ m_name = name;
52+ Q_EMIT changed();
53+}
54+
55+Qt::ScreenOrientation DeviceConfigParser::primaryOrientation() const
56+{
57+ return stringToOrientation(readOrientationFromConfig("PrimaryOrientation"), Qt::PrimaryOrientation);
58+}
59+
60+Qt::ScreenOrientations DeviceConfigParser::supportedOrientations() const
61+{
62+ QStringList values = readOrientationsFromConfig("SupportedOrientations");
63+ if (values.isEmpty()) {
64+ return Qt::PortraitOrientation
65+ | Qt::InvertedPortraitOrientation
66+ | Qt::LandscapeOrientation
67+ | Qt::InvertedLandscapeOrientation;
68+ }
69+
70+ Qt::ScreenOrientations ret = Qt::PrimaryOrientation;
71+ Q_FOREACH(const QString &orientationString, values) {
72+ ret |= stringToOrientation(orientationString, Qt::PrimaryOrientation);
73+ }
74+ return ret;
75+}
76+
77+Qt::ScreenOrientation DeviceConfigParser::landscapeOrientation() const
78+{
79+ return stringToOrientation(readOrientationFromConfig("LandscapeOrientation"), Qt::LandscapeOrientation);
80+}
81+
82+Qt::ScreenOrientation DeviceConfigParser::invertedLandscapeOrientation() const
83+{
84+ return stringToOrientation(readOrientationFromConfig("InvertedLandscapeOrientation"), Qt::InvertedLandscapeOrientation);
85+}
86+
87+Qt::ScreenOrientation DeviceConfigParser::portraitOrientation() const
88+{
89+ return stringToOrientation(readOrientationFromConfig("PortraitOrientation"), Qt::PortraitOrientation);
90+}
91+
92+Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
93+{
94+ return stringToOrientation(readOrientationFromConfig("InvertedPortraitOrientation"), Qt::InvertedPortraitOrientation);
95+}
96+
97+QString DeviceConfigParser::category() const
98+{
99+ QStringList supportedValues = {"phone", "tablet", "desktop"};
100+ m_config->beginGroup(m_name);
101+ QString value = m_config->value("Category", "phone").toString();
102+ if (!supportedValues.contains(value)) {
103+ qWarning().nospace().noquote() << "Unknown option \"" << value << "\" in " << m_config->fileName()
104+ << ". Supported options are: " << supportedValues.join(", ") << ".";
105+ return "phone";
106+ }
107+ m_config->endGroup();
108+ return value;
109+}
110+
111+QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
112+{
113+ m_config->beginGroup(m_name);
114+
115+ QStringList ret;
116+ if (m_config->contains(key)) {
117+ ret = m_config->value(key).toStringList();
118+ }
119+
120+ m_config->endGroup();
121+ return ret;
122+}
123+
124+QString DeviceConfigParser::readOrientationFromConfig(const QString &key) const
125+{
126+ QStringList ret = readOrientationsFromConfig(key);
127+ return ret.count() > 0 ? ret.first() : QString();
128+}
129+
130+Qt::ScreenOrientation DeviceConfigParser::stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const
131+{
132+ if (orientationString == "Landscape") {
133+ return Qt::LandscapeOrientation;
134+ }
135+ if (orientationString == "InvertedLandscape") {
136+ return Qt::InvertedLandscapeOrientation;
137+ }
138+ if (orientationString == "Portrait") {
139+ return Qt::PortraitOrientation;
140+ }
141+ if (orientationString == "InvertedPortrait") {
142+ return Qt::InvertedPortraitOrientation;
143+ }
144+ if (!orientationString.isEmpty()) {
145+ // Some option we don't know. Give some hint on what went wrong.
146+ qWarning().nospace().noquote() << "Unknown option \"" << orientationString << "\" in " << m_config->fileName()
147+ << ". Supported options are: Landscape, InvertedLandscape, Portrait and InvertedPortrait.";
148+ }
149+ return defaultValue;
150+}
plugins/Utils/deviceconfigparser.hnew file+62
@@ -0,0 +1,62 @@
1+/*
2+ * Copyright 2016 Canonical Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU Lesser 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 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+
17+#ifndef DEVICECONFIGPARSER_H
18+#define DEVICECONFIGPARSER_H
19+
20+#include <QObject>
21+#include <QSettings>
22+
23+class DeviceConfigParser: public QObject
24+{
25+ Q_OBJECT
26+ Q_PROPERTY(QString name READ name WRITE setName NOTIFY changed)
27+
28+ Q_PROPERTY(Qt::ScreenOrientation primaryOrientation READ primaryOrientation NOTIFY changed)
29+ Q_PROPERTY(Qt::ScreenOrientations supportedOrientations READ supportedOrientations NOTIFY changed)
30+ Q_PROPERTY(Qt::ScreenOrientation landscapeOrientation READ landscapeOrientation NOTIFY changed)
31+ Q_PROPERTY(Qt::ScreenOrientation invertedLandscapeOrientation READ invertedLandscapeOrientation NOTIFY changed)
32+ Q_PROPERTY(Qt::ScreenOrientation portraitOrientation READ portraitOrientation NOTIFY changed)
33+ Q_PROPERTY(Qt::ScreenOrientation invertedPortraitOrientation READ invertedPortraitOrientation NOTIFY changed)
34+ Q_PROPERTY(QString category READ category NOTIFY changed)
35+
36+public:
37+ DeviceConfigParser(QObject *parent = nullptr);
38+
39+ QString name() const;
40+ void setName(const QString &name);
41+
42+ Qt::ScreenOrientation primaryOrientation() const;
43+ Qt::ScreenOrientations supportedOrientations() const;
44+ Qt::ScreenOrientation landscapeOrientation() const;
45+ Qt::ScreenOrientation invertedLandscapeOrientation() const;
46+ Qt::ScreenOrientation portraitOrientation() const;
47+ Qt::ScreenOrientation invertedPortraitOrientation() const;
48+ QString category() const;
49+
50+Q_SIGNALS:
51+ void changed();
52+
53+private:
54+ QString m_name;
55+ QSettings *m_config;
56+
57+ QStringList readOrientationsFromConfig(const QString &key) const;
58+ QString readOrientationFromConfig(const QString &key) const;
59+ Qt::ScreenOrientation stringToOrientation(const QString &orientationString, Qt::ScreenOrientation defaultValue) const;
60+};
61+
62+#endif
plugins/Utils/plugin.cpp+2
@@ -37,6 +37,7 @@
3737#include "timezoneFormatter.h"
3838#include "applicationsfiltermodel.h"
3939#include "inputeventgenerator.h"
40+#include "deviceconfigparser.h"
4041
4142static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
4243{
@@ -70,6 +71,7 @@ void UtilsPlugin::registerTypes(const char *uri)
7071 qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
7172 qmlRegisterType<ApplicationsFilterModel>(uri, 0, 1, "ApplicationsFilterModel");
7273 qmlRegisterType<InputEventGenerator>(uri, 0, 1, "InputEventGenerator");
74+ qmlRegisterType<DeviceConfigParser>(uri, 0, 1, "DeviceConfigParser");
7375}
7476
7577void UtilsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
qml/DeviceConfiguration.qml+54−16
@@ -1,5 +1,5 @@
11/*
2− * Copyright (C) 2015 Canonical, Ltd.
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
@@ -15,6 +15,7 @@
1515 */
1616
1717import QtQuick 2.4
18+import Utils 0.1
1819
1920QtObject {
2021 id: root
@@ -34,57 +35,83 @@ QtObject {
3435
3536 readonly property alias category: priv.category
3637
38+ readonly property var deviceConfigParser: DeviceConfigParser {
39+ name: root.name
40+ }
41+
3742 readonly property var priv: StateGroup {
3843 id: priv
3944
40− property int primaryOrientation: root.useNativeOrientation
45+ property int primaryOrientation: deviceConfigParser.primaryOrientation == Qt.PrimaryOrientation ?
46+ root.useNativeOrientation : deviceConfigParser.primaryOrientation
4147
42− property int supportedOrientations: Qt.PortraitOrientation
43− | Qt.InvertedPortraitOrientation
44− | Qt.LandscapeOrientation
45− | Qt.InvertedLandscapeOrientation
48+ property int supportedOrientations: deviceConfigParser.supportedOrientations
4649
47− property int landscapeOrientation: Qt.LandscapeOrientation
48− property int invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
49− property int portraitOrientation: Qt.PortraitOrientation
50− property int invertedPortraitOrientation: Qt.InvertedPortraitOrientation
51−
52− // Supported values so far:
53− // "phone", "tablet" or "desktop"
54− property string category: "phone"
50+ property int landscapeOrientation: deviceConfigParser.landscapeOrientation
51+ property int invertedLandscapeOrientation: deviceConfigParser.invertedLandscapeOrientation
52+ property int portraitOrientation: deviceConfigParser.portraitOrientation
53+ property int invertedPortraitOrientation: deviceConfigParser.invertedPortraitOrientation
54+ property string category: deviceConfigParser.category
5555
5656 states: [
5757 State {
5858 name: "mako"
5959 PropertyChanges {
6060 target: priv
61+ primaryOrientation: root.useNativeOrientation
6162 supportedOrientations: Qt.PortraitOrientation
6263 | Qt.LandscapeOrientation
6364 | Qt.InvertedLandscapeOrientation
65+ landscapeOrientation: Qt.LandscapeOrientation
66+ invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
67+ portraitOrientation: Qt.PortraitOrientation
68+ invertedPortraitOrientation: Qt.InvertedPortraitOrientation
69+ category: "phone"
6470 }
6571 },
6672 State {
6773 name: "krillin"
6874 PropertyChanges {
6975 target: priv
76+ primaryOrientation: root.useNativeOrientation
7077 supportedOrientations: Qt.PortraitOrientation
7178 | Qt.LandscapeOrientation
7279 | Qt.InvertedLandscapeOrientation
80+ landscapeOrientation: Qt.LandscapeOrientation
81+ invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
82+ portraitOrientation: Qt.PortraitOrientation
83+ invertedPortraitOrientation: Qt.InvertedPortraitOrientation
84+ category: "phone"
7385 }
7486 },
7587 State {
7688 name: "arale"
7789 PropertyChanges {
7890 target: priv
91+ primaryOrientation: root.useNativeOrientation
7992 supportedOrientations: Qt.PortraitOrientation
8093 | Qt.LandscapeOrientation
8194 | Qt.InvertedLandscapeOrientation
95+ landscapeOrientation: Qt.LandscapeOrientation
96+ invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
97+ portraitOrientation: Qt.PortraitOrientation
98+ invertedPortraitOrientation: Qt.InvertedPortraitOrientation
99+ category: "phone"
82100 }
83101 },
84102 State {
85103 name: "manta"
86104 PropertyChanges {
87105 target: priv
106+ primaryOrientation: root.useNativeOrientation
107+ supportedOrientations: Qt.PortraitOrientation
108+ | Qt.InvertedPortraitOrientation
109+ | Qt.LandscapeOrientation
110+ | Qt.InvertedLandscapeOrientation
111+ landscapeOrientation: Qt.LandscapeOrientation
112+ invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
113+ portraitOrientation: Qt.PortraitOrientation
114+ invertedPortraitOrientation: Qt.InvertedPortraitOrientation
88115 category: "tablet"
89116 }
90117 },
@@ -92,9 +119,15 @@ QtObject {
92119 name: "flo"
93120 PropertyChanges {
94121 target: priv
122+ primaryOrientation: Qt.InvertedLandscapeOrientation
123+ supportedOrientations: Qt.PortraitOrientation
124+ | Qt.InvertedPortraitOrientation
125+ | Qt.LandscapeOrientation
126+ | Qt.InvertedLandscapeOrientation
95127 landscapeOrientation: Qt.InvertedLandscapeOrientation
96128 invertedLandscapeOrientation: Qt.LandscapeOrientation
97− primaryOrientation: Qt.InvertedLandscapeOrientation
129+ portraitOrientation: Qt.PortraitOrientation
130+ invertedPortraitOrientation: Qt.InvertedPortraitOrientation
98131 category: "tablet"
99132 }
100133 },
@@ -102,8 +135,13 @@ QtObject {
102135 name: "desktop"
103136 PropertyChanges {
104137 target: priv
105− category: "desktop"
138+ primaryOrientation: root.useNativeOrientation
106139 supportedOrientations: root.useNativeOrientation
140+ landscapeOrientation: Qt.LandscapeOrientation
141+ invertedLandscapeOrientation: Qt.InvertedLandscapeOrientation
142+ portraitOrientation: Qt.PortraitOrientation
143+ invertedPortraitOrientation: Qt.InvertedPortraitOrientation
144+ category: "desktop"
107145 }
108146 }
109147 ]
tests/mocks/Utils/CMakeLists.txt+1
@@ -18,6 +18,7 @@ set(QMLPLUGIN_SRC
1818 ${CMAKE_SOURCE_DIR}/plugins/Utils/inputwatcher.cpp
1919 ${CMAKE_SOURCE_DIR}/plugins/Utils/applicationsfiltermodel.cpp
2020 ${CMAKE_SOURCE_DIR}/plugins/Utils/inputeventgenerator.cpp
21+ ${CMAKE_SOURCE_DIR}/plugins/Utils/deviceconfigparser.cpp
2122 ${APPLICATION_API_INCLUDEDIR}/unity/shell/application/ApplicationManagerInterface.h
2223 constants.cpp
2324 plugin.cpp
tests/mocks/Utils/plugin.cpp+2
@@ -37,6 +37,7 @@
3737#include <easingcurve.h>
3838#include <applicationsfiltermodel.h>
3939#include <inputeventgenerator.h>
40+#include <deviceconfigparser.h>
4041
4142static QObject *createWindowStateStorage(QQmlEngine *engine, QJSEngine *scriptEngine)
4243{
@@ -67,6 +68,7 @@ void FakeUtilsPlugin::registerTypes(const char *uri)
6768 qmlRegisterType<ActiveFocusLogger>(uri, 0, 1, "ActiveFocusLogger");
6869 qmlRegisterType<ApplicationsFilterModel>(uri, 0, 1, "ApplicationsFilterModel");
6970 qmlRegisterType<InputEventGenerator>(uri, 0, 1, "InputEventGenerator");
71+ qmlRegisterType<DeviceConfigParser>(uri, 0, 1, "DeviceConfigParser");
7072}
7173
7274void FakeUtilsPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
tests/plugins/Utils/CMakeLists.txt+7−1
@@ -4,15 +4,21 @@ include_directories(
44 ${CMAKE_CURRENT_BINARY_DIR}
55 )
66
7+add_definitions(-DCONFIG_TESTING)
8+
79foreach(util_test
810 QLimitProxyModel
911 UnitySortFilterProxyModel
1012 WindowInputMonitor
13+ DeviceConfigParser
1114)
1215 add_executable(${util_test}TestExec ${util_test}Test.cpp ModelTest.cpp)
1316 qt5_use_modules(${util_test}TestExec Test Core Qml)
1417 target_link_libraries(${util_test}TestExec Utils-qml)
15− add_unity8_unittest(${util_test} ${util_test}TestExec ADD_TEST)
18+ add_unity8_unittest(${util_test} ${util_test}TestExec ADD_TEST
19+ ENVIRONMENT XDG_CONFIG_HOME=${CMAKE_CURRENT_BINARY_DIR}
20+ )
21+
1622endforeach()
1723
1824# plain qml test
tests/plugins/Utils/DeviceConfigParserTest.cppnew file+70
@@ -0,0 +1,70 @@
1+/*
2+ * Copyright (C) 2016 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+
17+// local
18+#include "deviceconfigparser.h"
19+
20+// Qt
21+#include <QTest>
22+#include <QDebug>
23+#include <QSettings>
24+
25+class DeviceConfigParserTest : public QObject
26+{
27+ Q_OBJECT
28+
29+private Q_SLOTS:
30+
31+ void initTestCase() {
32+ }
33+
34+ void testDefaults()
35+ {
36+ DeviceConfigParser p;
37+ p.setName("nonexistent");
38+
39+ QCOMPARE(p.supportedOrientations(), Qt::PortraitOrientation | Qt::InvertedPortraitOrientation | Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation);
40+ QCOMPARE(p.primaryOrientation(), Qt::PrimaryOrientation);
41+ QCOMPARE(p.portraitOrientation(), Qt::PortraitOrientation);
42+ QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
43+ QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
44+ QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
45+ }
46+
47+ void testCustomFile() {
48+ QSettings s("./devices.conf", QSettings::IniFormat);
49+ s.beginGroup("fakedevice");
50+
51+ s.setValue("SupportedOrientations", QStringList() << "Portrait" << "Landscape" << "InvertedLandscape");
52+ s.setValue("PrimaryOrientation", "InvertedLandscape");
53+ s.sync();
54+
55+ DeviceConfigParser p;
56+ p.setName("fakedevice");
57+
58+ QCOMPARE(p.supportedOrientations(), Qt::PortraitOrientation | Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation);
59+ QCOMPARE(p.primaryOrientation(), Qt::InvertedLandscapeOrientation);
60+ QCOMPARE(p.portraitOrientation(), Qt::PortraitOrientation);
61+ QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
62+ QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
63+ QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
64+ }
65+
66+};
67+
68+QTEST_GUILESS_MAIN(DeviceConfigParserTest)
69+
70+#include "DeviceConfigParserTest.moc"
tests/qmltests/CMakeLists.txt+1
@@ -5,6 +5,7 @@ add_unity8_qmltest(. OrientedShell LIGHTDM)
55add_unity8_qmltest(. DisabledScreenNotice)
66add_unity8_qmltest(. Shell LIGHTDM)
77add_unity8_qmltest(. ShellWithPin LIGHTDM)
8+add_unity8_qmltest(. DeviceConfiguration)
89add_unity8_qmltest(Components Background)
910add_unity8_qmltest(Components Carousel)
1011add_unity8_qmltest(Components Dialogs LIGHTDM)
tests/qmltests/tst_DeviceConfiguration.qmlnew file+49
@@ -0,0 +1,49 @@
1+/*
2+ * Copyright (C) 2016 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+
17+import QtQuick 2.4
18+import QtTest 1.0
19+import Unity.Test 0.1
20+import "../../qml"
21+
22+Item {
23+ id: root
24+ width: units.gu(40)
25+ height: units.gu(70)
26+
27+ DeviceConfiguration {
28+ id: deviceConfiguration
29+ }
30+
31+ UnityTestCase {
32+ id: testCase
33+ name: "DeviceConfiguration"
34+ when: windowShown
35+
36+ function test_defaults() {
37+ deviceConfiguration.name = "nonexisting"
38+ compare(deviceConfiguration.primaryOrientation, -1)
39+ compare(deviceConfiguration.landscapeOrientation, Qt.LandscapeOrientation)
40+ compare(deviceConfiguration.portraitOrientation, Qt.PortraitOrientation)
41+ compare(deviceConfiguration.invertedLandscapeOrientation, Qt.InvertedLandscapeOrientation)
42+ compare(deviceConfiguration.invertedPortraitOrientation, Qt.InvertedPortraitOrientation)
43+ compare(deviceConfiguration.supportedOrientations, Qt.PortraitOrientation
44+ | Qt.InvertedPortraitOrientation
45+ | Qt.LandscapeOrientation
46+ | Qt.InvertedLandscapeOrientation)
47+ }
48+ }
49+}