Merge lp:~jonas-drange/ubuntu-system-settings/brightness-qml-testing into lp:ubuntu-system-settings

Proposed by Jonas G. Drange on 2016-10-14
Status: Approved
Approved by: Ken VanDine on 2016-10-26
Approved revision: 1734
Proposed branch: lp:~jonas-drange/ubuntu-system-settings/brightness-qml-testing
Merge into: lp:ubuntu-system-settings
Diff against target: 1355 lines (+1131/-20)
27 files modified
debian/control (+1/-0)
plugins/brightness/CMakeLists.txt (+1/-1)
plugins/brightness/PageComponent.qml (+3/-0)
plugins/brightness/WifiDisplays.qml (+22/-19)
tests/mocks/CMakeLists.txt (+1/-0)
tests/mocks/GSettings1.0/CMakeLists.txt (+19/-0)
tests/mocks/GSettings1.0/fake_gsettings.cpp (+127/-0)
tests/mocks/GSettings1.0/fake_gsettings.h (+101/-0)
tests/mocks/GSettings1.0/plugin.cpp (+35/-0)
tests/mocks/GSettings1.0/plugin.h (+33/-0)
tests/mocks/GSettings1.0/qmldir (+2/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt (+20/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDevice.h (+63/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.cpp (+95/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.h (+63/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp (+89/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h (+96/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp (+51/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h (+58/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp (+33/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.h (+33/-0)
tests/mocks/Ubuntu/SystemSettings/Brightness/qmldir (+2/-0)
tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt (+1/-0)
tests/plugins/CMakeLists.txt (+10/-0)
tests/plugins/brightness/Source/qmldir (+3/-0)
tests/plugins/brightness/tst_BrightnessPageComponent.qml (+90/-0)
tests/plugins/brightness/tst_BrightnessWifiDisplays.qml (+79/-0)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-system-settings/brightness-qml-testing
Reviewer Review Type Date Requested Status
Ken VanDine 2016-10-14 Approve on 2016-10-26
system-apps-ci-bot continuous-integration Needs Fixing on 2016-10-17
Review via email: mp+308508@code.launchpad.net

Commit Message

* mocks brightness panel plugin
* mocks aethercast plugin
* adds qml-test infrastructure for the brightness plugin in addition to some tests

Description of the Change

This is not a complete set of tests for the current brightness panel, but rather a small set such that the review process is easier.

To post a comment you must log in.

FAILED: Continuous integration, rev:1731
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/210/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/system-apps/job/build/1845/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/1846
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1686/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/1686/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/210/rebuild

review: Needs Fixing (continuous-integration)

FAILED: Continuous integration, rev:1732
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/212/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/system-apps/job/build/1849/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/1850
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1690/console
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/1690/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/212/rebuild

review: Needs Fixing (continuous-integration)

FAILED: Continuous integration, rev:1734
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/214/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/system-apps/job/build/1862/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-0-fetch/1863
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1703
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=vivid+overlay/1703/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1703
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=xenial+overlay/1703/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=amd64,release=yakkety/1703/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1703
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=vivid+overlay/1703/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1703
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=xenial+overlay/1703/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1703
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=armhf,release=yakkety/1703/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=vivid+overlay/1703/console
    SUCCESS: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1703
        deb: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=xenial+overlay/1703/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/system-apps/job/build-2-binpkg/arch=i386,release=yakkety/1703/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/system-apps/job/lp-ubuntu-system-settings-ci/214/rebuild

review: Needs Fixing (continuous-integration)
Jonas G. Drange (jonas-drange) wrote :

These test failures are addressed in silo 2066.

Ken VanDine (ken-vandine) wrote :

Looks good

review: Approve

Unmerged revisions

1734. By Jonas G. Drange on 2016-10-17

add includes

1733. By Jonas G. Drange on 2016-10-14

add fake gsettings

1732. By Jonas G. Drange on 2016-10-14

remove unused flags

1731. By Jonas G. Drange on 2016-10-14

add test that uses a model

1730. By Jonas G. Drange on 2016-10-14

add wifi displays test

1729. By Jonas G. Drange on 2016-10-14

add mock, test

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2016-09-30 13:48:06 +0000
3+++ debian/control 2016-10-17 15:07:00 +0000
4@@ -45,6 +45,7 @@
5 dpkg-dev,
6 qml-module-qttest,
7 qml-module-qtquick2,
8+ qtdeclarative5-ubuntu-settings-components (>= 0.8),
9 qtdeclarative5-ubuntu-ui-toolkit-plugin | qtdeclarative5-ubuntu-ui-toolkit-plugin-gles,
10 libubuntuoneauth-2.0-dev,
11 libqtdbusmock1-dev (>= 0.2+14.04.20140724),
12
13=== modified file 'plugins/brightness/CMakeLists.txt'
14--- plugins/brightness/CMakeLists.txt 2016-04-28 15:24:19 +0000
15+++ plugins/brightness/CMakeLists.txt 2016-10-17 15:07:00 +0000
16@@ -33,7 +33,7 @@
17
18 set(PLUG_DIR ${PLUGIN_PRIVATE_MODULE_DIR}/Ubuntu/SystemSettings/Brightness)
19 install(TARGETS UbuntuBrightnessPanel DESTINATION ${PLUG_DIR})
20-install(FILES qmldir DESTINATION ${PLUG_DIR})
21+install(FILES qmldir.in DESTINATION ${PLUG_DIR} RENAME qmldir)
22 install(FILES brightness.settings DESTINATION ${PLUGIN_MANIFEST_DIR})
23 install(FILES settings-brightness.svg DESTINATION ${PLUGIN_MANIFEST_DIR}/icons)
24 install(FILES ${QML_SOURCES} DESTINATION ${PLUGIN_QML_DIR}/brightness)
25
26=== modified file 'plugins/brightness/PageComponent.qml'
27--- plugins/brightness/PageComponent.qml 2016-07-06 15:38:55 +0000
28+++ plugins/brightness/PageComponent.qml 2016-10-17 15:07:00 +0000
29@@ -42,6 +42,7 @@
30
31 AethercastDisplays {
32 id: aethercastDisplays
33+ objectName: "aethercastDisplays"
34 onEnabledChanged: {
35 /* This is a hack to ensure the aethercast enabled switch stays
36 * in sync with the enabled property
37@@ -53,6 +54,7 @@
38
39 UbuntuBrightnessPanel {
40 id: brightnessPanel
41+ objectName: "brightnessPanel"
42 }
43
44 QDBusActionGroup {
45@@ -137,6 +139,7 @@
46 }
47
48 ListItem.Standard {
49+ objectName: "externalDisplayControl"
50 text: i18n.tr("External display")
51 enabled: brightnessPanel.widiSupported
52 onClicked: enabledCheck.trigger()
53
54=== modified file 'plugins/brightness/WifiDisplays.qml'
55--- plugins/brightness/WifiDisplays.qml 2016-07-14 08:31:08 +0000
56+++ plugins/brightness/WifiDisplays.qml 2016-10-17 15:07:00 +0000
57@@ -57,6 +57,26 @@
58 }
59 }
60
61+ AethercastDisplays {
62+ id: displays
63+ objectName: "aethercastDisplays"
64+
65+ onConnectError: {
66+ console.error("onConnectError: " + error);
67+ showError(error);
68+ }
69+
70+ // Log some info to help debug
71+ onConnectedDevicesChanged: {
72+ console.warn("ConnectedDevices: " + displays.connectedDevices.count);
73+ }
74+
75+ // Log some info to help debug
76+ onDisconnectedDevicesChanged: {
77+ console.warn("DisconnectedDevices: " + displays.disconnectedDevices.count);
78+ }
79+ }
80+
81 Flickable {
82 id: pageFlickable
83 anchors.fill: parent
84@@ -68,26 +88,8 @@
85 Flickable.DragAndOvershootBounds :
86 Flickable.StopAtBounds
87
88- AethercastDisplays {
89- id: displays
90-
91- onConnectError: {
92- console.error("onConnectError: " + error);
93- showError(error);
94- }
95-
96- // Log some info to help debug
97- onConnectedDevicesChanged: {
98- console.warn("ConnectedDevices: " + displays.connectedDevices.count);
99- }
100-
101- // Log some info to help debug
102- onDisconnectedDevicesChanged: {
103- console.warn("DisconnectedDevices: " + displays.disconnectedDevices.count);
104- }
105- }
106-
107 Label {
108+ objectName: "noDisplaysDetected"
109 anchors {
110 left: parent.left
111 right: parent.right
112@@ -114,6 +116,7 @@
113 }
114
115 Repeater {
116+ objectName: "displayRepeater"
117 model: displays.connectedDevices ? displays.connectedDevices : null
118 delegate: ListItem.Subtitled {
119 id: displayDelegate
120
121=== renamed file 'plugins/brightness/qmldir' => 'plugins/brightness/qmldir.in'
122=== modified file 'tests/mocks/CMakeLists.txt'
123--- tests/mocks/CMakeLists.txt 2016-07-25 13:54:08 +0000
124+++ tests/mocks/CMakeLists.txt 2016-10-17 15:07:00 +0000
125@@ -31,5 +31,6 @@
126 )
127 endmacro()
128
129+add_subdirectory(GSettings1.0)
130 add_subdirectory(QMenuModel)
131 add_subdirectory(Ubuntu)
132
133=== added directory 'tests/mocks/GSettings1.0'
134=== added file 'tests/mocks/GSettings1.0/CMakeLists.txt'
135--- tests/mocks/GSettings1.0/CMakeLists.txt 1970-01-01 00:00:00 +0000
136+++ tests/mocks/GSettings1.0/CMakeLists.txt 2016-10-17 15:07:00 +0000
137@@ -0,0 +1,19 @@
138+include_directories(
139+ ${CMAKE_CURRENT_BINARY_DIR}
140+ ${Qt5Core_INCLUDE_DIRS}
141+ ${Qt5Quick_INCLUDE_DIRS}
142+)
143+
144+set(GSettingsQML_SOURCES
145+ fake_gsettings.cpp
146+ plugin.cpp
147+)
148+
149+add_library(FakeGSettingsQml MODULE ${GSettingsQML_SOURCES})
150+target_link_libraries(FakeGSettingsQml
151+ ${Qt5Core_LIBRARIES}
152+ ${Qt5Quick_LIBRARIES}
153+)
154+
155+qt5_use_modules(FakeGSettingsQml Qml)
156+add_uss_mock(GSettings 1.0 GSettings.1.0 TARGETS FakeGSettingsQml)
157
158=== added file 'tests/mocks/GSettings1.0/fake_gsettings.cpp'
159--- tests/mocks/GSettings1.0/fake_gsettings.cpp 1970-01-01 00:00:00 +0000
160+++ tests/mocks/GSettings1.0/fake_gsettings.cpp 2016-10-17 15:07:00 +0000
161@@ -0,0 +1,127 @@
162+/*
163+ * This file is part of system-settings
164+ *
165+ * Copyright (C) 2016 Canonical Ltd.
166+ *
167+ * This program is free software: you can redistribute it and/or modify it
168+ * under the terms of the GNU General Public License version 3, as published
169+ * by the Free Software Foundation.
170+ *
171+ * This program is distributed in the hope that it will be useful, but
172+ * WITHOUT ANY WARRANTY; without even the implied warranties of
173+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
174+ * PURPOSE. See the GNU General Public License for more details.
175+ *
176+ * You should have received a copy of the GNU General Public License along
177+ * with this program. If not, see <http://www.gnu.org/licenses/>.
178+ */
179+
180+#include "fake_gsettings.h"
181+
182+#include <QList>
183+
184+GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
185+
186+GSettingsControllerQml::GSettingsControllerQml()
187+ : m_autoBrightness(false)
188+{
189+}
190+
191+GSettingsControllerQml::~GSettingsControllerQml() {
192+ s_controllerInstance = 0;
193+}
194+
195+GSettingsControllerQml* GSettingsControllerQml::instance() {
196+ if (!s_controllerInstance) {
197+ s_controllerInstance = new GSettingsControllerQml();
198+ }
199+ return s_controllerInstance;
200+}
201+
202+bool GSettingsControllerQml::autoBrightness() const
203+{
204+ return m_autoBrightness;
205+}
206+
207+void GSettingsControllerQml::setAutoBrightness(bool val)
208+{
209+ if (val != m_autoBrightness) {
210+ m_autoBrightness = val;
211+ Q_EMIT autoBrightnessChanged();
212+ }
213+}
214+
215+GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
216+}
217+
218+QByteArray GSettingsSchemaQml::id() const {
219+ return m_id;
220+}
221+
222+void GSettingsSchemaQml::setId(const QByteArray &id) {
223+ if (!m_id.isEmpty()) {
224+ qWarning("GSettings.schema.id may only be set on construction");
225+ return;
226+ }
227+
228+ m_id = id;
229+}
230+
231+QByteArray GSettingsSchemaQml::path() const {
232+ return m_path;
233+}
234+
235+void GSettingsSchemaQml::setPath(const QByteArray &path) {
236+ if (!m_path.isEmpty()) {
237+ qWarning("GSettings.schema.path may only be set on construction");
238+ return;
239+ }
240+
241+ m_path = path;
242+}
243+
244+GSettingsQml::GSettingsQml(QObject *parent)
245+ : QObject(parent),
246+ m_valid(false)
247+{
248+ m_schema = new GSettingsSchemaQml(this);
249+}
250+
251+void GSettingsQml::classBegin()
252+{
253+}
254+
255+void GSettingsQml::componentComplete()
256+{
257+ // Emulate what the real GSettings module does, and only return undefined
258+ // values until we are completed loading.
259+ m_valid = true;
260+
261+ // FIXME: We should make this dynamic, instead of hard-coding all possible
262+ // properties in one object. We should create properties based on the schema.
263+ connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::autoBrightnessChanged,
264+ this, &GSettingsQml::autoBrightnessChanged);
265+
266+ Q_EMIT autoBrightnessChanged();
267+}
268+
269+GSettingsSchemaQml * GSettingsQml::schema() const {
270+ return m_schema;
271+}
272+
273+QVariant GSettingsQml::autoBrightness() const
274+{
275+ if (m_valid && m_schema->id() == "com.ubuntu.touch.system") {
276+ return GSettingsControllerQml::instance()->autoBrightness();
277+ } else {
278+ return QVariant();
279+ }
280+}
281+
282+void GSettingsQml::setAutoBrightness(const QVariant &val)
283+{
284+ if (m_valid && m_schema->id() == "com.ubuntu.touch.system") {
285+ GSettingsControllerQml::instance()->setAutoBrightness(val.toBool());
286+ }
287+}
288+
289
290=== added file 'tests/mocks/GSettings1.0/fake_gsettings.h'
291--- tests/mocks/GSettings1.0/fake_gsettings.h 1970-01-01 00:00:00 +0000
292+++ tests/mocks/GSettings1.0/fake_gsettings.h 2016-10-17 15:07:00 +0000
293@@ -0,0 +1,101 @@
294+/*
295+ * This file is part of system-settings
296+ *
297+ * Copyright (C) 2016 Canonical Ltd.
298+ *
299+ * This program is free software: you can redistribute it and/or modify it
300+ * under the terms of the GNU General Public License version 3, as published
301+ * by the Free Software Foundation.
302+ *
303+ * This program is distributed in the hope that it will be useful, but
304+ * WITHOUT ANY WARRANTY; without even the implied warranties of
305+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
306+ * PURPOSE. See the GNU General Public License for more details.
307+ *
308+ * You should have received a copy of the GNU General Public License along
309+ * with this program. If not, see <http://www.gnu.org/licenses/>.
310+ */
311+
312+#ifndef FAKE_GSETTINGS_H
313+#define FAKE_GSETTINGS_H
314+
315+#include <QList>
316+#include <QObject>
317+#include <QQmlParserStatus>
318+#include <QStringList>
319+#include <QVariant>
320+
321+class GSettingsSchemaQml: public QObject
322+{
323+ Q_OBJECT
324+
325+ Q_PROPERTY(QByteArray id READ id WRITE setId)
326+
327+public:
328+ GSettingsSchemaQml(QObject *parent = nullptr);
329+
330+ QByteArray id() const;
331+ void setId(const QByteArray &id);
332+
333+ QByteArray path() const;
334+ void setPath(const QByteArray &path);
335+
336+private:
337+ QByteArray m_id;
338+ QByteArray m_path;
339+};
340+
341+class GSettingsQml: public QObject, public QQmlParserStatus
342+{
343+ Q_OBJECT
344+ Q_INTERFACES(QQmlParserStatus)
345+
346+ Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
347+ Q_PROPERTY(QVariant autoBrightness READ autoBrightness WRITE setAutoBrightness NOTIFY autoBrightnessChanged)
348+
349+public:
350+ GSettingsQml(QObject *parent = nullptr);
351+
352+ void classBegin() override;
353+ void componentComplete() override;
354+
355+ GSettingsSchemaQml * schema() const;
356+ QVariant autoBrightness() const;
357+
358+ void setAutoBrightness(const QVariant &val);
359+
360+Q_SIGNALS:
361+ void autoBrightnessChanged();
362+ void schemaChanged();
363+
364+private:
365+ GSettingsSchemaQml* m_schema;
366+ bool m_valid;
367+
368+ friend class GSettingsSchemaQml;
369+};
370+
371+class GSettingsControllerQml: public QObject
372+{
373+ Q_OBJECT
374+
375+public:
376+ static GSettingsControllerQml* instance();
377+ ~GSettingsControllerQml();
378+
379+ bool autoBrightness() const;
380+ Q_INVOKABLE void setAutoBrightness(bool val);
381+
382+Q_SIGNALS:
383+ void autoBrightnessChanged();
384+
385+private:
386+ GSettingsControllerQml();
387+
388+ bool m_autoBrightness;
389+
390+ static GSettingsControllerQml* s_controllerInstance;
391+ QList<GSettingsQml *> m_registeredGSettings;
392+};
393+
394+#endif // FAKE_GSETTINGS_H
395
396=== added file 'tests/mocks/GSettings1.0/plugin.cpp'
397--- tests/mocks/GSettings1.0/plugin.cpp 1970-01-01 00:00:00 +0000
398+++ tests/mocks/GSettings1.0/plugin.cpp 2016-10-17 15:07:00 +0000
399@@ -0,0 +1,35 @@
400+/*
401+ * This file is part of system-settings
402+ *
403+ * Copyright (C) 2016 Canonical Ltd.
404+ *
405+ * This program is free software: you can redistribute it and/or modify it
406+ * under the terms of the GNU General Public License version 3, as published
407+ * by the Free Software Foundation.
408+ *
409+ * This program is distributed in the hope that it will be useful, but
410+ * WITHOUT ANY WARRANTY; without even the implied warranties of
411+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
412+ * PURPOSE. See the GNU General Public License for more details.
413+ *
414+ * You should have received a copy of the GNU General Public License along
415+ * with this program. If not, see <http://www.gnu.org/licenses/>.
416+ */
417+
418+#include "plugin.h"
419+#include "fake_gsettings.h"
420+
421+#include <QtQml/qqml.h>
422+
423+static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
424+{
425+ return GSettingsControllerQml::instance();
426+}
427+
428+void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
429+{
430+ qmlRegisterSingletonType<GSettingsControllerQml>(uri, 1, 0, "GSettingsController", controllerProvider);
431+ qmlRegisterType<GSettingsQml>(uri, 1, 0, "GSettings");
432+ qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
433+ "GSettingsSchema can only be used inside of a GSettings component");
434+}
435
436=== added file 'tests/mocks/GSettings1.0/plugin.h'
437--- tests/mocks/GSettings1.0/plugin.h 1970-01-01 00:00:00 +0000
438+++ tests/mocks/GSettings1.0/plugin.h 2016-10-17 15:07:00 +0000
439@@ -0,0 +1,33 @@
440+/*
441+ * This file is part of system-settings
442+ *
443+ * Copyright (C) 2016 Canonical Ltd.
444+ *
445+ * This program is free software: you can redistribute it and/or modify it
446+ * under the terms of the GNU General Public License version 3, as published
447+ * by the Free Software Foundation.
448+ *
449+ * This program is distributed in the hope that it will be useful, but
450+ * WITHOUT ANY WARRANTY; without even the implied warranties of
451+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
452+ * PURPOSE. See the GNU General Public License for more details.
453+ *
454+ * You should have received a copy of the GNU General Public License along
455+ * with this program. If not, see <http://www.gnu.org/licenses/>.
456+ */
457+
458+#ifndef PLUGIN_H
459+#define PLUGIN_H
460+
461+#include <QtQml/QQmlExtensionPlugin>
462+
463+class FakeGSettingsQmlPlugin : public QQmlExtensionPlugin
464+{
465+ Q_OBJECT
466+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
467+
468+public:
469+ void registerTypes(const char *uri) override;
470+};
471+
472+#endif // PLUGIN_H
473
474=== added file 'tests/mocks/GSettings1.0/qmldir'
475--- tests/mocks/GSettings1.0/qmldir 1970-01-01 00:00:00 +0000
476+++ tests/mocks/GSettings1.0/qmldir 2016-10-17 15:07:00 +0000
477@@ -0,0 +1,2 @@
478+module GSettings
479+plugin FakeGSettingsQml
480
481=== added directory 'tests/mocks/Ubuntu/SystemSettings/Brightness'
482=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt'
483--- tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt 1970-01-01 00:00:00 +0000
484+++ tests/mocks/Ubuntu/SystemSettings/Brightness/CMakeLists.txt 2016-10-17 15:07:00 +0000
485@@ -0,0 +1,20 @@
486+include_directories(
487+ ${CMAKE_CURRENT_BINARY_DIR}
488+ ${CMAKE_SOURCE_DIR}/plugins/brightness/
489+)
490+
491+set(MOCK_BRIGHTNESS_SRCS
492+ MockAethercastDevice.h
493+ MockAethercastDeviceModel.cpp
494+ MockAethercastDisplays.cpp
495+ MockBrightness.cpp
496+ plugin.cpp
497+)
498+
499+add_library(MockBrightnessPanel MODULE ${MOCK_BRIGHTNESS_SRCS})
500+
501+target_link_libraries(MockBrightnessPanel)
502+qt5_use_modules(MockBrightnessPanel Qml Quick Core)
503+
504+add_uss_mock(Ubuntu.SystemSettings.Brightness 1.0 Ubuntu/SystemSettings/Brightness
505+ TARGETS MockBrightnessPanel)
506
507=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDevice.h'
508--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDevice.h 1970-01-01 00:00:00 +0000
509+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDevice.h 2016-10-17 15:07:00 +0000
510@@ -0,0 +1,63 @@
511+/*
512+ * This file is part of system-settings
513+ *
514+ * Copyright (C) 2016 Canonical Ltd.
515+ *
516+ * This program is free software: you can redistribute it and/or modify it
517+ * under the terms of the GNU General Public License version 3, as published
518+ * by the Free Software Foundation.
519+ *
520+ * This program is distributed in the hope that it will be useful, but
521+ * WITHOUT ANY WARRANTY; without even the implied warranties of
522+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
523+ * PURPOSE. See the GNU General Public License for more details.
524+ *
525+ * You should have received a copy of the GNU General Public License along
526+ * with this program. If not, see <http://www.gnu.org/licenses/>.
527+ */
528+
529+#ifndef MOCK_AETHERCAST_DEVICE_H
530+#define MOCK_AETHERCAST_DEVICE_H
531+
532+#include <QObject>
533+#include <QString>
534+#include <QStringList>
535+
536+class MockAethercastDevice : public QObject
537+{
538+ Q_OBJECT
539+ Q_PROPERTY(QString Address READ address)
540+ Q_PROPERTY(QStringList Capabilities READ capabilities)
541+ Q_PROPERTY(QString Name READ name)
542+ Q_PROPERTY(State state READ state)
543+public:
544+ MockAethercastDevice(QObject *parent = 0) {
545+ Q_UNUSED(parent)
546+ };
547+ ~MockAethercastDevice() {};
548+
549+ enum State { Idle=1, Disconnected=2, Association=4, Configuration=8, Connected=16, Failure=32 };
550+ Q_ENUMS(State)
551+ Q_DECLARE_FLAGS(States, State)
552+
553+ inline QString address() const
554+ { return m_address; }
555+
556+ inline QStringList capabilities() const
557+ { return m_capabilities; }
558+
559+ inline QString name() const
560+ { return m_name; }
561+
562+ inline State state() const
563+ { return m_state; }
564+
565+ QString m_address = QString::null;
566+ QStringList m_capabilities;
567+ QString m_name = QString::null;
568+ State m_state = MockAethercastDevice::Idle;
569+};
570+
571+Q_DECLARE_OPERATORS_FOR_FLAGS(MockAethercastDevice::States)
572+
573+#endif // MOCK_AETHERCAST_DEVICE_H
574
575=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.cpp'
576--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.cpp 1970-01-01 00:00:00 +0000
577+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.cpp 2016-10-17 15:07:00 +0000
578@@ -0,0 +1,95 @@
579+/*
580+ * This file is part of system-settings
581+ *
582+ * Copyright (C) 2016 Canonical Ltd.
583+ *
584+ * This program is free software: you can redistribute it and/or modify it
585+ * under the terms of the GNU General Public License version 3, as published
586+ * by the Free Software Foundation.
587+ *
588+ * This program is distributed in the hope that it will be useful, but
589+ * WITHOUT ANY WARRANTY; without even the implied warranties of
590+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
591+ * PURPOSE. See the GNU General Public License for more details.
592+ *
593+ * You should have received a copy of the GNU General Public License along
594+ * with this program. If not, see <http://www.gnu.org/licenses/>.
595+ */
596+#include "MockAethercastDeviceModel.h"
597+
598+int MockAethercastDeviceModel::rowCount(const QModelIndex &parent) const
599+{
600+ Q_UNUSED(parent);
601+ return m_devices.size();
602+}
603+
604+QVariant MockAethercastDeviceModel::data(const QModelIndex &index, int role) const
605+{
606+ QVariant ret;
607+ if ((0<=index.row()) && (index.row()<m_devices.size())) {
608+ auto device = m_devices[index.row()];
609+ QString displayName;
610+
611+ switch (role) {
612+ case Qt::DisplayRole:
613+ displayName = device->name();
614+
615+ if (displayName.isEmpty())
616+ displayName = device->address();
617+
618+ ret = displayName;
619+ break;
620+
621+ case StateRole:
622+ ret = device->state();
623+ break;
624+
625+ case AddressRole:
626+ ret = device->address();
627+ break;
628+
629+ }
630+ }
631+ return ret;
632+}
633+
634+QHash<int,QByteArray> MockAethercastDeviceModel::roleNames() const
635+{
636+ static QHash<int,QByteArray> names;
637+ if (Q_UNLIKELY(names.empty())) {
638+ names[Qt::DisplayRole] = "displayName";
639+ names[StateRole] = "stateName";
640+ names[AddressRole] = "addressName";
641+ }
642+ return names;
643+}
644+
645+QSharedPointer<MockAethercastDevice> MockAethercastDeviceModel::getDeviceFromAddress(const QString &address)
646+{
647+ Q_UNUSED(address)
648+ return QSharedPointer<MockAethercastDevice>(nullptr);
649+}
650+
651+QSharedPointer<MockAethercastDevice> MockAethercastDeviceModel::getDeviceFromPath(const QString &path)
652+{
653+ Q_UNUSED(path)
654+ return QSharedPointer<MockAethercastDevice>(nullptr);
655+}
656+
657+void MockAethercastDeviceModel::addDevice(const QString &address,
658+ const QString &name,
659+ const int &state)
660+{
661+ QSharedPointer<MockAethercastDevice> dev =
662+ QSharedPointer<MockAethercastDevice>(new MockAethercastDevice);
663+ dev->m_address = address;
664+ dev->m_name = name;
665+ dev->m_state = (MockAethercastDevice::State) state;
666+
667+ uint row = m_devices.size();
668+ beginInsertRows(QModelIndex(), row, row);
669+ m_devices.append(dev);
670+ endInsertRows();
671+
672+ emit countChanged(rowCount());
673+}
674
675=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.h'
676--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.h 1970-01-01 00:00:00 +0000
677+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDeviceModel.h 2016-10-17 15:07:00 +0000
678@@ -0,0 +1,63 @@
679+/*
680+ * This file is part of system-settings
681+ *
682+ * Copyright (C) 2016 Canonical Ltd.
683+ *
684+ * This program is free software: you can redistribute it and/or modify it
685+ * under the terms of the GNU General Public License version 3, as published
686+ * by the Free Software Foundation.
687+ *
688+ * This program is distributed in the hope that it will be useful, but
689+ * WITHOUT ANY WARRANTY; without even the implied warranties of
690+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
691+ * PURPOSE. See the GNU General Public License for more details.
692+ *
693+ * You should have received a copy of the GNU General Public License along
694+ * with this program. If not, see <http://www.gnu.org/licenses/>.
695+ */
696+
697+#ifndef MOCK_AETHERCAST_DEVICE_MODEL_H
698+#define MOCK_AETHERCAST_DEVICE_MODEL_H
699+
700+#include "MockAethercastDevice.h"
701+
702+#include <QAbstractListModel>
703+#include <QList>
704+#include <QObject>
705+#include <QSharedPointer>
706+
707+class MockAethercastDeviceModel : public QAbstractListModel
708+{
709+ Q_OBJECT
710+ Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
711+public:
712+ MockAethercastDeviceModel(QObject *parent = 0) {
713+ Q_UNUSED(parent)
714+ };
715+ ~MockAethercastDeviceModel() {};
716+
717+ enum Roles
718+ {
719+ // Qt::DisplayRole holds device name
720+ TypeRole = Qt::UserRole,
721+ AddressRole,
722+ StateRole,
723+ LastRole = StateRole
724+ };
725+ // implemented virtual methods from QAbstractTableModel
726+ int rowCount(const QModelIndex &parent = QModelIndex()) const;
727+ QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
728+ QHash<int,QByteArray> roleNames() const;
729+
730+ QSharedPointer<MockAethercastDevice> getDeviceFromAddress(const QString &address);
731+ QSharedPointer<MockAethercastDevice> getDeviceFromPath(const QString &path);
732+ Q_INVOKABLE void addDevice(const QString &address, const QString &name,
733+ const int &state); // mock only
734+Q_SIGNALS:
735+ void countChanged(int count);
736+
737+private:
738+ QList<QSharedPointer<MockAethercastDevice> > m_devices;
739+};
740+
741+#endif // MOCK_AETHERCAST_DEVICE_MODEL_H
742
743=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp'
744--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp 1970-01-01 00:00:00 +0000
745+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.cpp 2016-10-17 15:07:00 +0000
746@@ -0,0 +1,89 @@
747+/*
748+ * This file is part of system-settings
749+ *
750+ * Copyright (C) 2016 Canonical Ltd.
751+ *
752+ * This program is free software: you can redistribute it and/or modify it
753+ * under the terms of the GNU General Public License version 3, as published
754+ * by the Free Software Foundation.
755+ *
756+ * This program is distributed in the hope that it will be useful, but
757+ * WITHOUT ANY WARRANTY; without even the implied warranties of
758+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
759+ * PURPOSE. See the GNU General Public License for more details.
760+ *
761+ * You should have received a copy of the GNU General Public License along
762+ * with this program. If not, see <http://www.gnu.org/licenses/>.
763+ */
764+#include "MockAethercastDisplays.h"
765+
766+#include <QQmlEngine>
767+
768+void MockDisplays::connectDevice(const QString &address)
769+{
770+ Q_UNUSED(address)
771+}
772+
773+void MockDisplays::disconnectDevice(const QString &address)
774+{
775+ Q_UNUSED(address)
776+}
777+
778+void MockDisplays::scan()
779+{
780+ m_scanning = true;
781+ Q_EMIT scanningChanged(m_scanning);
782+}
783+
784+void MockDisplays::stopScan()
785+{
786+ m_scanning = false;
787+ Q_EMIT scanningChanged(m_scanning);
788+}
789+
790+void MockDisplays::setProperties(const QMap<QString, QVariant> &properties)
791+{
792+ Q_UNUSED(properties)
793+}
794+
795+QAbstractItemModel* MockDisplays::devices()
796+{
797+ auto ret = &m_devices;
798+ QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
799+ return ret;
800+}
801+
802+QAbstractItemModel* MockDisplays::connectedDevices()
803+{
804+ auto ret = &m_connectedDevices;
805+ QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
806+ return ret;
807+}
808+
809+QAbstractItemModel* MockDisplays::disconnectedDevices()
810+{
811+ auto ret = &m_disconnectedDevices;
812+ QQmlEngine::setObjectOwnership(ret, QQmlEngine::CppOwnership);
813+ return ret;
814+}
815+
816+bool MockDisplays::scanning() const
817+{
818+ return m_scanning;
819+}
820+
821+bool MockDisplays::enabled() const
822+{
823+ return m_enabled;
824+}
825+
826+void MockDisplays::setEnabled(const bool enabled)
827+{
828+ m_enabled = enabled;
829+ Q_EMIT enabledChanged(enabled);
830+}
831+
832+QString MockDisplays::state() const
833+{
834+ return m_state;
835+}
836
837=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h'
838--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h 1970-01-01 00:00:00 +0000
839+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockAethercastDisplays.h 2016-10-17 15:07:00 +0000
840@@ -0,0 +1,96 @@
841+/*
842+ * This file is part of system-settings
843+ *
844+ * Copyright (C) 2016 Canonical Ltd.
845+ *
846+ * This program is free software: you can redistribute it and/or modify it
847+ * under the terms of the GNU General Public License version 3, as published
848+ * by the Free Software Foundation.
849+ *
850+ * This program is distributed in the hope that it will be useful, but
851+ * WITHOUT ANY WARRANTY; without even the implied warranties of
852+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
853+ * PURPOSE. See the GNU General Public License for more details.
854+ *
855+ * You should have received a copy of the GNU General Public License along
856+ * with this program. If not, see <http://www.gnu.org/licenses/>.
857+ */
858+
859+#ifndef MOCK_AETHERCAST_DISPLAYS_H
860+#define MOCK_AETHERCAST_DISPLAYS_H
861+
862+#include "MockAethercastDeviceModel.h"
863+
864+#include <QObject>
865+
866+class MockDisplays : public QObject
867+{
868+ Q_OBJECT
869+ Q_PROPERTY (QAbstractItemModel* devices
870+ READ devices
871+ CONSTANT)
872+ Q_PROPERTY (QAbstractItemModel* connectedDevices
873+ READ connectedDevices
874+ NOTIFY connectedDevicesChanged)
875+ Q_PROPERTY (QAbstractItemModel* disconnectedDevices
876+ READ disconnectedDevices
877+ NOTIFY disconnectedDevicesChanged)
878+ Q_PROPERTY (bool scanning
879+ READ scanning
880+ NOTIFY scanningChanged)
881+ Q_PROPERTY (bool enabled
882+ READ enabled
883+ WRITE setEnabled
884+ NOTIFY enabledChanged)
885+ Q_PROPERTY (QString state
886+ READ state
887+ NOTIFY stateChanged)
888+public:
889+ explicit MockDisplays(QObject *parent = nullptr) {
890+ Q_UNUSED(parent)
891+ };
892+ ~MockDisplays() {}
893+
894+ enum Error {
895+ None,
896+ Failed,
897+ Already,
898+ ParamInvalid,
899+ InvalidState,
900+ NotConnected,
901+ NotReady,
902+ Unknown
903+ };
904+ Q_ENUMS(Error)
905+
906+ Q_INVOKABLE void connectDevice(const QString &address);
907+ Q_INVOKABLE void disconnectDevice(const QString &address);
908+ Q_INVOKABLE void scan();
909+ Q_INVOKABLE void stopScan(); // mock only
910+ Q_INVOKABLE void setEnabled(const bool enabled);
911+ void setProperties(const QMap<QString, QVariant> &properties);
912+ QAbstractItemModel * devices();
913+ QAbstractItemModel * connectedDevices();
914+ QAbstractItemModel * disconnectedDevices();
915+ bool scanning() const;
916+ bool enabled() const;
917+ QString state() const;
918+ MockAethercastDeviceModel m_devices;
919+ MockAethercastDeviceModel m_connectedDevices;
920+ MockAethercastDeviceModel m_disconnectedDevices;
921+ QString m_state = QString::null;
922+
923+private:
924+ bool m_scanning = false;
925+ bool m_enabled = false;
926+
927+Q_SIGNALS:
928+ void scanningChanged(bool isActive);
929+ void enabledChanged(bool enabled);
930+ void stateChanged();
931+ void connectedDevicesChanged();
932+ void disconnectedDevicesChanged();
933+ void connectError(int error);
934+};
935+
936+#endif // MOCK_AETHERCAST_DISPLAYS_H
937
938=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp'
939--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp 1970-01-01 00:00:00 +0000
940+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.cpp 2016-10-17 15:07:00 +0000
941@@ -0,0 +1,51 @@
942+/*
943+ * This file is part of system-settings
944+ *
945+ * Copyright (C) 2016 Canonical Ltd.
946+ *
947+ * This program is free software: you can redistribute it and/or modify it
948+ * under the terms of the GNU General Public License version 3, as published
949+ * by the Free Software Foundation.
950+ *
951+ * This program is distributed in the hope that it will be useful, but
952+ * WITHOUT ANY WARRANTY; without even the implied warranties of
953+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
954+ * PURPOSE. See the GNU General Public License for more details.
955+ *
956+ * You should have received a copy of the GNU General Public License along
957+ * with this program. If not, see <http://www.gnu.org/licenses/>.
958+ */
959+#include "MockBrightness.h"
960+
961+bool MockBrightness::getPowerdRunning() const
962+{
963+ return m_powerdRunning;
964+}
965+
966+bool MockBrightness::getAutoBrightnessAvailable() const
967+{
968+ return m_autoBrightnessAvailable;
969+}
970+
971+bool MockBrightness::getWidiSupported() const
972+{
973+ return m_widiSupported;
974+}
975+
976+void MockBrightness::setPowerdRunning(const bool running)
977+{
978+ m_powerdRunning = running;
979+ Q_EMIT powerdRunningChanged();
980+}
981+
982+void MockBrightness::setAutoBrightnessAvailable(const bool available)
983+{
984+ m_autoBrightnessAvailable = available;
985+ Q_EMIT autoBrightnessAvailableChanged();
986+}
987+
988+void MockBrightness::setWidiSupported(const bool supported)
989+{
990+ m_widiSupported = supported;
991+ Q_EMIT widiSupportedChanged();
992+}
993
994=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h'
995--- tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h 1970-01-01 00:00:00 +0000
996+++ tests/mocks/Ubuntu/SystemSettings/Brightness/MockBrightness.h 2016-10-17 15:07:00 +0000
997@@ -0,0 +1,58 @@
998+/*
999+ * This file is part of system-settings
1000+ *
1001+ * Copyright (C) 2016 Canonical Ltd.
1002+ *
1003+ * This program is free software: you can redistribute it and/or modify it
1004+ * under the terms of the GNU General Public License version 3, as published
1005+ * by the Free Software Foundation.
1006+ *
1007+ * This program is distributed in the hope that it will be useful, but
1008+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1009+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1010+ * PURPOSE. See the GNU General Public License for more details.
1011+ *
1012+ * You should have received a copy of the GNU General Public License along
1013+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1014+ */
1015+
1016+#ifndef MOCK_BRIGHTNESS_H
1017+#define MOCK_BRIGHTNESS_H
1018+
1019+#include <QObject>
1020+
1021+class MockBrightness : public QObject
1022+{
1023+ Q_OBJECT
1024+ Q_PROPERTY( bool powerdRunning
1025+ READ getPowerdRunning
1026+ NOTIFY powerdRunningChanged)
1027+ Q_PROPERTY (bool autoBrightnessAvailable
1028+ READ getAutoBrightnessAvailable
1029+ NOTIFY autoBrightnessAvailableChanged)
1030+ Q_PROPERTY (bool widiSupported
1031+ READ getWidiSupported
1032+ NOTIFY widiSupportedChanged)
1033+public:
1034+ explicit MockBrightness(QObject *parent = 0) {
1035+ Q_UNUSED(parent)
1036+ };
1037+ bool getPowerdRunning() const;
1038+ bool getAutoBrightnessAvailable() const;
1039+ bool getWidiSupported() const;
1040+ Q_INVOKABLE void setPowerdRunning(const bool running); // mock only
1041+ Q_INVOKABLE void setAutoBrightnessAvailable(const bool available); // mock only
1042+ Q_INVOKABLE void setWidiSupported(const bool supported); // mock only
1043+
1044+Q_SIGNALS:
1045+ void powerdRunningChanged(); // mock only
1046+ void autoBrightnessAvailableChanged(); // mock only
1047+ void widiSupportedChanged(); // mock only
1048+
1049+private:
1050+ bool m_powerdRunning = false;
1051+ bool m_autoBrightnessAvailable = false;
1052+ bool m_widiSupported = false;
1053+};
1054+
1055+#endif // MOCK_BRIGHTNESS_H
1056
1057=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp'
1058--- tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp 1970-01-01 00:00:00 +0000
1059+++ tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.cpp 2016-10-17 15:07:00 +0000
1060@@ -0,0 +1,33 @@
1061+/*
1062+ * This file is part of system-settings
1063+ *
1064+ * Copyright (C) 2016 Canonical Ltd.
1065+ *
1066+ * This program is free software: you can redistribute it and/or modify it
1067+ * under the terms of the GNU General Public License version 3, as published
1068+ * by the Free Software Foundation.
1069+ *
1070+ * This program is distributed in the hope that it will be useful, but
1071+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1072+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1073+ * PURPOSE. See the GNU General Public License for more details.
1074+ *
1075+ * You should have received a copy of the GNU General Public License along
1076+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1077+ */
1078+
1079+#include "plugin.h"
1080+#include "MockBrightness.h"
1081+#include "MockAethercastDevice.h"
1082+#include "MockAethercastDeviceModel.h"
1083+#include "MockAethercastDisplays.h"
1084+
1085+#include <QtQml>
1086+
1087+void BackendPlugin::registerTypes(const char *uri)
1088+{
1089+ Q_ASSERT(uri == QLatin1String("Ubuntu.SystemSettings.Brightness"));
1090+ qmlRegisterType<MockBrightness>(uri, 1, 0, "UbuntuBrightnessPanel");
1091+ qmlRegisterType<MockAethercastDevice>(uri, 1, 0, "AethercastDevice");
1092+ qmlRegisterType<MockDisplays>(uri, 1, 0, "AethercastDisplays");
1093+}
1094
1095=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.h'
1096--- tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.h 1970-01-01 00:00:00 +0000
1097+++ tests/mocks/Ubuntu/SystemSettings/Brightness/plugin.h 2016-10-17 15:07:00 +0000
1098@@ -0,0 +1,33 @@
1099+/*
1100+ * This file is part of system-settings
1101+ *
1102+ * Copyright (C) 2016 Canonical Ltd.
1103+ *
1104+ * This program is free software: you can redistribute it and/or modify it
1105+ * under the terms of the GNU General Public License version 3, as published
1106+ * by the Free Software Foundation.
1107+ *
1108+ * This program is distributed in the hope that it will be useful, but
1109+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1110+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1111+ * PURPOSE. See the GNU General Public License for more details.
1112+ *
1113+ * You should have received a copy of the GNU General Public License along
1114+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1115+ */
1116+
1117+#ifndef MOCK_SYSTEMSETTINGS_BRIGHTNESS_PLUGIN_H
1118+#define MOCK_SYSTEMSETTINGS_BRIGHTNESS_PLUGIN_H
1119+
1120+#include <QQmlExtensionPlugin>
1121+
1122+class BackendPlugin : public QQmlExtensionPlugin
1123+{
1124+ Q_OBJECT
1125+ Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
1126+
1127+public:
1128+ void registerTypes(const char *uri) override;
1129+};
1130+
1131+#endif // MOCK_SYSTEMSETTINGS_BRIGHTNESS_PLUGIN_H
1132
1133=== added file 'tests/mocks/Ubuntu/SystemSettings/Brightness/qmldir'
1134--- tests/mocks/Ubuntu/SystemSettings/Brightness/qmldir 1970-01-01 00:00:00 +0000
1135+++ tests/mocks/Ubuntu/SystemSettings/Brightness/qmldir 2016-10-17 15:07:00 +0000
1136@@ -0,0 +1,2 @@
1137+module Ubuntu.SystemSettings.Brightness
1138+plugin MockBrightnessPanel
1139
1140=== modified file 'tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt'
1141--- tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt 2016-08-19 12:30:40 +0000
1142+++ tests/mocks/Ubuntu/SystemSettings/CMakeLists.txt 2016-10-17 15:07:00 +0000
1143@@ -1,3 +1,4 @@
1144+add_subdirectory(Brightness)
1145 add_subdirectory(Notifications)
1146 add_subdirectory(Update)
1147 add_subdirectory(Wifi)
1148
1149=== added directory 'tests/mocks/plugins/brightness'
1150=== modified file 'tests/plugins/CMakeLists.txt'
1151--- tests/plugins/CMakeLists.txt 2016-08-19 12:30:40 +0000
1152+++ tests/plugins/CMakeLists.txt 2016-10-17 15:07:00 +0000
1153@@ -55,3 +55,13 @@
1154 add_qml_test(system-update systemupdate_download_handler
1155 IMPORT_PATHS ${SYSTEMUPDATE_IMPORT_PATHS}
1156 )
1157+
1158+
1159+set(BRIGHTNESS_IMPORT_PATHS
1160+ ${CMAKE_SOURCE_DIR}/src
1161+ ${CMAKE_BINARY_DIR}/tests/utils/modules
1162+ ${CMAKE_BINARY_DIR}/tests/mocks/
1163+ ${CMAKE_SOURCE_DIR}/tests/plugins/brightness
1164+)
1165+add_qml_test(brightness BrightnessPageComponent IMPORT_PATHS ${BRIGHTNESS_IMPORT_PATHS})
1166+add_qml_test(brightness BrightnessWifiDisplays IMPORT_PATHS ${BRIGHTNESS_IMPORT_PATHS})
1167
1168=== added directory 'tests/plugins/brightness'
1169=== added directory 'tests/plugins/brightness/Source'
1170=== added file 'tests/plugins/brightness/Source/qmldir'
1171--- tests/plugins/brightness/Source/qmldir 1970-01-01 00:00:00 +0000
1172+++ tests/plugins/brightness/Source/qmldir 2016-10-17 15:07:00 +0000
1173@@ -0,0 +1,3 @@
1174+module Source
1175+PageComponent 1.0 ../../../../plugins/brightness/PageComponent.qml
1176+WifiDisplays 1.0 ../../../../plugins/brightness/WifiDisplays.qml
1177
1178=== added file 'tests/plugins/brightness/tst_BrightnessPageComponent.qml'
1179--- tests/plugins/brightness/tst_BrightnessPageComponent.qml 1970-01-01 00:00:00 +0000
1180+++ tests/plugins/brightness/tst_BrightnessPageComponent.qml 2016-10-17 15:07:00 +0000
1181@@ -0,0 +1,90 @@
1182+/*
1183+ * This file is part of system-settings
1184+ *
1185+ * Copyright (C) 2016 Canonical Ltd.
1186+ *
1187+ * This program is free software: you can redistribute it and/or modify it
1188+ * under the terms of the GNU General Public License version 3, as published
1189+ * by the Free Software Foundation.
1190+ *
1191+ * This program is distributed in the hope that it will be useful, but
1192+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1193+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1194+ * PURPOSE. See the GNU General Public License for more details.
1195+ *
1196+ * You should have received a copy of the GNU General Public License along
1197+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1198+ */
1199+
1200+import QtQuick 2.4
1201+import QtTest 1.0
1202+import Ubuntu.Components 1.3
1203+import Ubuntu.SystemSettings.Brightness 1.0
1204+import Ubuntu.Test 0.1
1205+
1206+import Source 1.0
1207+
1208+Item {
1209+ id: testRoot
1210+ width: 300
1211+ height: 500
1212+
1213+ Component {
1214+ id: pageComponent
1215+ PageComponent {
1216+ anchors.fill: parent
1217+ }
1218+ }
1219+
1220+ UbuntuTestCase {
1221+ name: "BrightnessPageComponent"
1222+ when: windowShown
1223+
1224+ property var instance: null
1225+
1226+ function init() {
1227+ instance = pageComponent.createObject(testRoot, {});
1228+ }
1229+
1230+ function cleanup() {
1231+ instance.destroy();
1232+ }
1233+
1234+ function get_panel_plugin() {
1235+ return findInvisibleChild(instance, "brightnessPanel");
1236+ }
1237+
1238+ function get_aethercast_displays_plugin() {
1239+ return findInvisibleChild(instance, "aethercastDisplays");
1240+ }
1241+
1242+ function test_brightness_title() {
1243+ compare(instance.title, i18n.tr("Brightness"));
1244+ }
1245+
1246+ function test_brightness_and_displays_title() {
1247+ get_panel_plugin().setWidiSupported(true);
1248+ compare(instance.title, i18n.tr("Brightness & Display"));
1249+ }
1250+
1251+ function test_switch_disabled() {
1252+ var swtch = findChild(instance, "externalDisplayControl");
1253+ verify(!swtch.enabled);
1254+ }
1255+
1256+ function test_switch_enabled() {
1257+ get_panel_plugin().setWidiSupported(true);
1258+ var swtch = findChild(instance, "externalDisplayControl");
1259+ verify(swtch.enabled);
1260+ }
1261+
1262+ function test_casting_enabled() {
1263+ get_panel_plugin().setWidiSupported(true);
1264+ get_aethercast_displays_plugin().setEnabled(true);
1265+ var entry = findChild(instance, "displayCasting");
1266+
1267+ verify(entry.enabled);
1268+ compare(entry.value, i18n.tr("Not connected"));
1269+ }
1270+ }
1271+}
1272
1273=== added file 'tests/plugins/brightness/tst_BrightnessWifiDisplays.qml'
1274--- tests/plugins/brightness/tst_BrightnessWifiDisplays.qml 1970-01-01 00:00:00 +0000
1275+++ tests/plugins/brightness/tst_BrightnessWifiDisplays.qml 2016-10-17 15:07:00 +0000
1276@@ -0,0 +1,79 @@
1277+/*
1278+ * This file is part of system-settings
1279+ *
1280+ * Copyright (C) 2016 Canonical Ltd.
1281+ *
1282+ * This program is free software: you can redistribute it and/or modify it
1283+ * under the terms of the GNU General Public License version 3, as published
1284+ * by the Free Software Foundation.
1285+ *
1286+ * This program is distributed in the hope that it will be useful, but
1287+ * WITHOUT ANY WARRANTY; without even the implied warranties of
1288+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
1289+ * PURPOSE. See the GNU General Public License for more details.
1290+ *
1291+ * You should have received a copy of the GNU General Public License along
1292+ * with this program. If not, see <http://www.gnu.org/licenses/>.
1293+ */
1294+
1295+import QtQuick 2.4
1296+import QtTest 1.0
1297+import Ubuntu.Components 1.3
1298+import Ubuntu.SystemSettings.Brightness 1.0
1299+import Ubuntu.Test 0.1
1300+
1301+import Source 1.0
1302+
1303+Item {
1304+ id: testRoot
1305+ width: 300
1306+ height: 500
1307+
1308+ Component {
1309+ id: wifiDisplays
1310+ WifiDisplays {
1311+ anchors.fill: parent
1312+ }
1313+ }
1314+
1315+ UbuntuTestCase {
1316+ name: "BrightnessWifiDisplays"
1317+ when: windowShown
1318+
1319+ property var instance: null
1320+
1321+ function get_aethercast_displays_plugin() {
1322+ return findInvisibleChild(instance, "aethercastDisplays");
1323+ }
1324+
1325+ function init() {
1326+ instance = wifiDisplays.createObject(testRoot, {});
1327+ }
1328+
1329+ function cleanup() {
1330+ instance.destroy();
1331+ }
1332+
1333+ function test_no_devices() {
1334+ var label = findChild(instance, "noDisplaysDetected");
1335+ verify(label.visible);
1336+ compare(label.text, i18n.tr("No displays detected"));
1337+ }
1338+
1339+ function test_one_device() {
1340+ var plugin = get_aethercast_displays_plugin();
1341+ plugin.devices.addDevice("addr", "my display", AethercastDevice.Idle);
1342+ plugin.connectedDevices.addDevice("addr", "my display", AethercastDevice.Idle);
1343+
1344+ var label = findChild(instance, "noDisplaysDetected");
1345+ verify(!label.visible);
1346+
1347+ var header = findChild(instance, "connectedDisplay");
1348+ verify(header.visible);
1349+
1350+ var repeater = findChild(instance, "displayRepeater");
1351+ compare(repeater.count, 1);
1352+ }
1353+
1354+ }
1355+}

Subscribers

People subscribed via source and target branches