on xenial help sign in
fix issues, add tests
commitc021e5f045deaa9f412537f0e6e696189f8044ed authorMichael Zanetti <michael.zanetti@canonical.com> dateFri 12 Feb 2016, 11:24 (11 years ago) parent9803e06
5 files changed+131−1
plugins/Utils/deviceconfigparser.cpp+9−1 tests/plugins/Utils/CMakeLists.txt+3 tests/plugins/Utils/DeviceConfigParserTest.cpp+69 tests/qmltests/CMakeLists.txt+1 tests/qmltests/tst_DeviceConfiguration.qml+49
plugins/Utils/deviceconfigparser.cpp+9−1
@@ -1,6 +1,7 @@
11#include "deviceconfigparser.h"
22
33#include <QSettings>
4+#include <QFileInfo>
45
56DeviceConfigParser::DeviceConfigParser(QObject *parent): QObject(parent)
67{
@@ -65,7 +66,14 @@ Qt::ScreenOrientation DeviceConfigParser::invertedPortraitOrientation() const
6566
6667QStringList DeviceConfigParser::readOrientationsFromConfig(const QString &key) const
6768{
68− QSettings config("/etc/unity8/devices.conf", QSettings::IniFormat);
69+ QFileInfo fi("./devices.conf");
70+ QString path;
71+ if (fi.exists()) {
72+ path = "./devices.conf";
73+ } else {
74+ path = "/etc/unity8/devices.conf";
75+ }
76+ QSettings config(path, QSettings::IniFormat);
6977 config.beginGroup(m_name);
7078
7179 if (config.contains(key)) {
tests/plugins/Utils/CMakeLists.txt+3
@@ -4,10 +4,13 @@ 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)
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)
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+}