on xenial help sign in
fix issues, add tests
c021e5fMichael Zanetti
plugins/Utils/deviceconfigparser.cpp+9−1
@@ -1,6 +1,7 @@
1#include "deviceconfigparser.h"
1#include "deviceconfigparser.h"
2
2
3#include <QSettings>
3#include <QSettings>
4+#include <QFileInfo>
4
5
5DeviceConfigParser::DeviceConfigParser(QObject *parent): QObject(parent)
6DeviceConfigParser::DeviceConfigParser(QObject *parent): QObject(parent)
6{
7{
@@ -65,7 +66,14 @@ Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
65
66
66QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
67QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
67{
68{
69+ QFileInfo fi("./devices.conf");
70+ QString path;
71+ if (fi.exists()) {
72+ path = "./devices.conf";
73+ } else {
68− QSettings config("/etc/unity8/devices.conf", QSettings::IniFormat);
74+ path = "/etc/unity8/devices.conf";
75+ }
76+ QSettings config(path, QSettings::IniFormat);
69 config.beginGroup(m_name);
77 config.beginGroup(m_name);
70
78
71 if (config.contains(key)) {
79 if (config.contains(key)) {
tests/plugins/Utils/CMakeLists.txt+3
@@ -4,10 +4,13 @@ include_directories(
4 ${CMAKE_CURRENT_BINARY_DIR}
4 ${CMAKE_CURRENT_BINARY_DIR}
5 )
5 )
6
6
7+add_definitions(-DCONFIG_TESTING)
8+
7foreach(util_test
9foreach(util_test
8 QLimitProxyModel
10 QLimitProxyModel
9 UnitySortFilterProxyModel
11 UnitySortFilterProxyModel
10 WindowInputMonitor
12 WindowInputMonitor
13+ DeviceConfigParser
11)
14)
12 add_executable(${util_test}TestExec ${util_test}Test.cpp ModelTest.cpp)
15 add_executable(${util_test}TestExec ${util_test}Test.cpp ModelTest.cpp)
13 qt5_use_modules(${util_test}TestExec Test Core Qml)
16 qt5_use_modules(${util_test}TestExec Test Core Qml)
tests/plugins/Utils/DeviceConfigParserTest.cppnew file+69
@@ -0,0 +1,69 @@
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+
54+ DeviceConfigParser p;
55+ p.setName("fakedevice");
56+
57+ QCOMPARE(p.supportedOrientations(), Qt::PortraitOrientation | Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation);
58+ QCOMPARE(p.primaryOrientation(), Qt::InvertedLandscapeOrientation);
59+ QCOMPARE(p.portraitOrientation(), Qt::PortraitOrientation);
60+ QCOMPARE(p.invertedPortraitOrientation(), Qt::InvertedPortraitOrientation);
61+ QCOMPARE(p.landscapeOrientation(), Qt::LandscapeOrientation);
62+ QCOMPARE(p.invertedLandscapeOrientation(), Qt::InvertedLandscapeOrientation);
63+ }
64+
65+};
66+
67+QTEST_GUILESS_MAIN(DeviceConfigParserTest)
68+
69+#include "DeviceConfigParserTest.moc"
tests/qmltests/CMakeLists.txt+1
@@ -5,6 +5,7 @@ add_unity8_qmltest(. OrientedShell LIGHTDM)
5add_unity8_qmltest(. DisabledScreenNotice)
5add_unity8_qmltest(. DisabledScreenNotice)
6add_unity8_qmltest(. Shell LIGHTDM)
6add_unity8_qmltest(. Shell LIGHTDM)
7add_unity8_qmltest(. ShellWithPin LIGHTDM)
7add_unity8_qmltest(. ShellWithPin LIGHTDM)
8+add_unity8_qmltest(. DeviceConfiguration)
8add_unity8_qmltest(Components Background)
9add_unity8_qmltest(Components Background)
9add_unity8_qmltest(Components Carousel)
10add_unity8_qmltest(Components Carousel)
10add_unity8_qmltest(Components Dialogs LIGHTDM)
11add_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+}