on xenial help sign in
Make mock gsettings closer to real gsettings objects
21b7b0dMichael Terry
tests/mocks/GSettings.1.0/fake_gsettings.cpp+50−37
@@ -146,9 +146,22 @@ void GSettingsSchemaQml::setPath(const QByteArray &path) {
146}
146}
147
147
148GSettingsQml::GSettingsQml(QObject *parent)
148GSettingsQml::GSettingsQml(QObject *parent)
149− : QObject(parent)
149+ : QObject(parent),
150+ m_valid(false)
150{
151{
151 m_schema = new GSettingsSchemaQml(this);
152 m_schema = new GSettingsSchemaQml(this);
153+}
154+
155+void GSettingsQml::classBegin()
156+{
157+}
158+
159+void GSettingsQml::componentComplete()
160+{
161+ // Emulate what the real GSettings module does, and only return undefined
162+ // values until we are completed loading.
163+ m_valid = true;
164+
152 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::pictureUriChanged,
165 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::pictureUriChanged,
153 this, &GSettingsQml::pictureUriChanged);
166 this, &GSettingsQml::pictureUriChanged);
154 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::usageModeChanged,
167 connect(GSettingsControllerQml::instance(), &GSettingsControllerQml::usageModeChanged,
@@ -167,98 +180,98 @@ GSettingsSchemaQml * GSettingsQml::schema() const {
167 return m_schema;
180 return m_schema;
168}
181}
169
182
170−QString GSettingsQml::pictureUri() const
183+QVariant GSettingsQml::pictureUri() const
171{
184{
172− if (m_schema->id() == "org.gnome.desktop.background") {
185+ if (m_valid && m_schema->id() == "org.gnome.desktop.background") {
173 return GSettingsControllerQml::instance()->pictureUri();
186 return GSettingsControllerQml::instance()->pictureUri();
174 } else {
187 } else {
175− return "";
188+ return QVariant();
176 }
189 }
177}
190}
178
191
179−void GSettingsQml::setPictureUri(const QString &str)
192+void GSettingsQml::setPictureUri(const QVariant &str)
180{
193{
181− if (m_schema->id() == "org.gnome.desktop.background") {
194+ if (m_valid && m_schema->id() == "org.gnome.desktop.background") {
182− GSettingsControllerQml::instance()->setPictureUri(str);
195+ GSettingsControllerQml::instance()->setPictureUri(str.toString());
183 }
196 }
184}
197}
185
198
186−QString GSettingsQml::usageMode() const
199+QVariant GSettingsQml::usageMode() const
187{
200{
188− if (m_schema->id() == "com.canonical.Unity8") {
201+ if (m_valid && m_schema->id() == "com.canonical.Unity8") {
189 return GSettingsControllerQml::instance()->usageMode();
202 return GSettingsControllerQml::instance()->usageMode();
190 } else {
203 } else {
191− return "";
204+ return QVariant();
192 }
205 }
193}
206}
194
207
195−void GSettingsQml::setUsageMode(const QString &usageMode)
208+void GSettingsQml::setUsageMode(const QVariant &usageMode)
196{
209{
197− if (m_schema->id() == "com.canonical.Unity8") {
210+ if (m_valid && m_schema->id() == "com.canonical.Unity8") {
198− GSettingsControllerQml::instance()->setUsageMode(usageMode);
211+ GSettingsControllerQml::instance()->setUsageMode(usageMode.toString());
199 }
212 }
200}
213}
201
214
202−qint64 GSettingsQml::lockedOutTime() const
215+QVariant GSettingsQml::lockedOutTime() const
203{
216{
204− if (m_schema->id() == "com.canonical.Unity8.Greeter") {
217+ if (m_valid && m_schema->id() == "com.canonical.Unity8.Greeter") {
205 return GSettingsControllerQml::instance()->lockedOutTime();
218 return GSettingsControllerQml::instance()->lockedOutTime();
206 } else {
219 } else {
207− return 0;
220+ return QVariant();
208 }
221 }
209}
222}
210
223
211−void GSettingsQml::setLockedOutTime(qint64 timestamp)
224+void GSettingsQml::setLockedOutTime(const QVariant &timestamp)
212{
225{
213− if (m_schema->id() == "com.canonical.Unity8.Greeter") {
226+ if (m_valid && m_schema->id() == "com.canonical.Unity8.Greeter") {
214− GSettingsControllerQml::instance()->setLockedOutTime(timestamp);
227+ GSettingsControllerQml::instance()->setLockedOutTime(timestamp.value<qint64>());
215 }
228 }
216}
229}
217
230
218−QStringList GSettingsQml::lifecycleExemptAppids() const
231+QVariant GSettingsQml::lifecycleExemptAppids() const
219{
232{
220− if (m_schema->id() == "com.canonical.qtmir") {
233+ if (m_valid && m_schema->id() == "com.canonical.qtmir") {
221 return GSettingsControllerQml::instance()->lifecycleExemptAppids();
234 return GSettingsControllerQml::instance()->lifecycleExemptAppids();
222 } else {
235 } else {
223− return QStringList();
236+ return QVariant();
224 }
237 }
225}
238}
226
239
227−bool GSettingsQml::autohideLauncher() const
240+QVariant GSettingsQml::autohideLauncher() const
228{
241{
229− if (m_schema->id() == "com.canonical.Unity8") {
242+ if (m_valid && m_schema->id() == "com.canonical.Unity8") {
230 return GSettingsControllerQml::instance()->autohideLauncher();
243 return GSettingsControllerQml::instance()->autohideLauncher();
231 } else {
244 } else {
232− return false;
245+ return QVariant();
233 }
246 }
234}
247}
235
248
236−int GSettingsQml::launcherWidth() const
249+QVariant GSettingsQml::launcherWidth() const
237{
250{
238− if (m_schema->id() == "com.canonical.Unity8") {
251+ if (m_valid && m_schema->id() == "com.canonical.Unity8") {
239 return GSettingsControllerQml::instance()->launcherWidth();
252 return GSettingsControllerQml::instance()->launcherWidth();
240 } else {
253 } else {
241− return false;
254+ return QVariant();
242 }
255 }
243}
256}
244
257
245−void GSettingsQml::setLifecycleExemptAppids(const QStringList &appIds)
258+void GSettingsQml::setLifecycleExemptAppids(const QVariant &appIds)
246{
259{
247− if (m_schema->id() == "com.canonical.qtmir") {
260+ if (m_valid && m_schema->id() == "com.canonical.qtmir") {
248− GSettingsControllerQml::instance()->setLifecycleExemptAppids(appIds);
261+ GSettingsControllerQml::instance()->setLifecycleExemptAppids(appIds.toStringList());
249 }
262 }
250}
263}
251
264
252−void GSettingsQml::setAutohideLauncher(bool autohideLauncher)
265+void GSettingsQml::setAutohideLauncher(const QVariant &autohideLauncher)
253{
266{
254− if (m_schema->id() == "com.canonical.Unity8") {
267+ if (m_valid && m_schema->id() == "com.canonical.Unity8") {
255− GSettingsControllerQml::instance()->setAutohideLauncher(autohideLauncher);
268+ GSettingsControllerQml::instance()->setAutohideLauncher(autohideLauncher.toBool());
256 }
269 }
257}
270}
258
271
259−void GSettingsQml::setLauncherWidth(int launcherWidth)
272+void GSettingsQml::setLauncherWidth(const QVariant &launcherWidth)
260{
273{
261− if (m_schema->id() == "com.canonical.Unity8") {
274+ if (m_valid && m_schema->id() == "com.canonical.Unity8") {
262− GSettingsControllerQml::instance()->setLauncherWidth(launcherWidth);
275+ GSettingsControllerQml::instance()->setLauncherWidth(launcherWidth.toInt());
263 }
276 }
264}
277}
tests/mocks/GSettings.1.0/fake_gsettings.h+28−21
@@ -19,7 +19,9 @@
19
19
20#include <QList>
20#include <QList>
21#include <QObject>
21#include <QObject>
22+#include <QQmlParserStatus>
22#include <QStringList>
23#include <QStringList>
24+#include <QVariant>
23
25
24class GSettingsSchemaQml: public QObject
26class GSettingsSchemaQml: public QObject
25{
27{
@@ -41,35 +43,39 @@ private:
41 QByteArray m_path;
43 QByteArray m_path;
42};
44};
43
45
44−class GSettingsQml: public QObject
46+class GSettingsQml: public QObject, public QQmlParserStatus
45{
47{
46 Q_OBJECT
48 Q_OBJECT
49+ Q_INTERFACES(QQmlParserStatus)
47
50
48 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
51 Q_PROPERTY(GSettingsSchemaQml* schema READ schema NOTIFY schemaChanged)
49− Q_PROPERTY(QString pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
52+ Q_PROPERTY(QVariant pictureUri READ pictureUri WRITE setPictureUri NOTIFY pictureUriChanged)
50− Q_PROPERTY(QString usageMode READ usageMode WRITE setUsageMode NOTIFY usageModeChanged)
53+ Q_PROPERTY(QVariant usageMode READ usageMode WRITE setUsageMode NOTIFY usageModeChanged)
51− Q_PROPERTY(qint64 lockedOutTime READ lockedOutTime WRITE setLockedOutTime NOTIFY lockedOutTimeChanged)
54+ Q_PROPERTY(QVariant lockedOutTime READ lockedOutTime WRITE setLockedOutTime NOTIFY lockedOutTimeChanged)
52− Q_PROPERTY(QStringList lifecycleExemptAppids READ lifecycleExemptAppids WRITE setLifecycleExemptAppids NOTIFY lifecycleExemptAppidsChanged)
55+ Q_PROPERTY(QVariant lifecycleExemptAppids READ lifecycleExemptAppids WRITE setLifecycleExemptAppids NOTIFY lifecycleExemptAppidsChanged)
53− Q_PROPERTY(bool autohideLauncher READ autohideLauncher WRITE setAutohideLauncher NOTIFY autohideLauncherChanged)
56+ Q_PROPERTY(QVariant autohideLauncher READ autohideLauncher WRITE setAutohideLauncher NOTIFY autohideLauncherChanged)
54− Q_PROPERTY(int launcherWidth READ launcherWidth WRITE setLauncherWidth NOTIFY launcherWidthChanged)
57+ Q_PROPERTY(QVariant launcherWidth READ launcherWidth WRITE setLauncherWidth NOTIFY launcherWidthChanged)
55
58
56public:
59public:
57 GSettingsQml(QObject *parent = nullptr);
60 GSettingsQml(QObject *parent = nullptr);
58
61
59− GSettingsSchemaQml * schema() const;
62+ void classBegin();
60− QString pictureUri() const;
63+ void componentComplete();
61− QString usageMode() const;
62− qint64 lockedOutTime() const;
63− QStringList lifecycleExemptAppids() const;
64− bool autohideLauncher() const;
65− int launcherWidth() const;
66
64
65+ GSettingsSchemaQml * schema() const;
66+ QVariant pictureUri() const;
67+ QVariant usageMode() const;
68+ QVariant lockedOutTime() const;
69+ QVariant lifecycleExemptAppids() const;
70+ QVariant autohideLauncher() const;
71+ QVariant launcherWidth() const;
72+
67− void setPictureUri(const QString &str);
73+ void setPictureUri(const QVariant &str);
68− void setUsageMode(const QString &usageMode);
74+ void setUsageMode(const QVariant &usageMode);
69− void setLockedOutTime(qint64 timestamp);
75+ void setLockedOutTime(const QVariant &timestamp);
70− void setLifecycleExemptAppids(const QStringList &appIds);
76+ void setLifecycleExemptAppids(const QVariant &appIds);
71− void setAutohideLauncher(bool autohideLauncher);
77+ void setAutohideLauncher(const QVariant &autohideLauncher);
72− void setLauncherWidth(int launcherWidth);
78+ void setLauncherWidth(const QVariant &launcherWidth);
73
79
74Q_SIGNALS:
80Q_SIGNALS:
75 void schemaChanged();
81 void schemaChanged();
@@ -82,6 +88,7 @@ Q_SIGNALS:
82
88
83private:
89private:
84 GSettingsSchemaQml* m_schema;
90 GSettingsSchemaQml* m_schema;
91+ bool m_valid;
85
92
86 friend class GSettingsSchemaQml;
93 friend class GSettingsSchemaQml;
87};
94};
@@ -114,7 +121,7 @@ public:
114
121
115Q_SIGNALS:
122Q_SIGNALS:
116 void pictureUriChanged(const QString&);
123 void pictureUriChanged(const QString&);
117− void usageModeChanged(const QString&);
124+ void usageModeChanged(const QString &usageMode);
118 void lockedOutTimeChanged(qint64 timestamp);
125 void lockedOutTimeChanged(qint64 timestamp);
119 void lifecycleExemptAppidsChanged(const QStringList&);
126 void lifecycleExemptAppidsChanged(const QStringList&);
120 void autohideLauncherChanged(bool autohideLauncher);
127 void autohideLauncherChanged(bool autohideLauncher);
tests/qmltests/tst_OrientedShell.qml+14−5
@@ -17,6 +17,7 @@
17import QtQuick 2.4
17import QtQuick 2.4
18import QtQuick.Layouts 1.1
18import QtQuick.Layouts 1.1
19import QtTest 1.0
19import QtTest 1.0
20+import GSettings 1.0
20import Ubuntu.Components 1.3
21import Ubuntu.Components 1.3
21import Ubuntu.Components.ListItems 1.3 as ListItem
22import Ubuntu.Components.ListItems 1.3 as ListItem
22import Unity.Application 0.1
23import Unity.Application 0.1
@@ -44,9 +45,8 @@ Rectangle {
44 property int savedOrientation
45 property int savedOrientation
45 }
46 }
46
47
47− QtObject {
48+ Connections {
48− id: mockUnity8Settings
49+ target: GSettingsController
49− property string usageMode: usageModeSelector.model[usageModeSelector.selectedIndex]
50 onUsageModeChanged: {
50 onUsageModeChanged: {
51 usageModeSelector.selectedIndex = usageModeSelector.model.indexOf(usageMode)
51 usageModeSelector.selectedIndex = usageModeSelector.model.indexOf(usageMode)
52 }
52 }
@@ -157,7 +157,6 @@ Rectangle {
157 sourceComponent: Component {
157 sourceComponent: Component {
158 OrientedShell {
158 OrientedShell {
159 anchors.fill: parent
159 anchors.fill: parent
160− unity8Settings: mockUnity8Settings
161 oskSettings: mockOskSettings
160 oskSettings: mockOskSettings
162 physicalOrientation: root.physicalOrientation0
161 physicalOrientation: root.physicalOrientation0
163 orientationLocked: orientationLockedCheckBox.checked
162 orientationLocked: orientationLockedCheckBox.checked
@@ -311,7 +310,7 @@ Rectangle {
311 function selectWindowed() {selectedIndex = 1;}
310 function selectWindowed() {selectedIndex = 1;}
312 function selectAutomatic() {selectedIndex = 2;}
311 function selectAutomatic() {selectedIndex = 2;}
313 onSelectedIndexChanged: {
312 onSelectedIndexChanged: {
314− mockUnity8Settings.usageMode = usageModeSelector.model[usageModeSelector.selectedIndex]
313+ GSettingsController.setUsageMode(usageModeSelector.model[usageModeSelector.selectedIndex]);
315 }
314 }
316 }
315 }
317 MouseTouchEmulationCheckbox {
316 MouseTouchEmulationCheckbox {
@@ -1140,6 +1139,16 @@ Rectangle {
1140 orientedShellLoader.width = oldWidth;
1139 orientedShellLoader.width = oldWidth;
1141 }
1140 }
1142
1141
1142+ function test_setsUsageModeOnStartup() {
1143+ // Prepare inconsistent beginning (mouse & staged mode)
1144+ MockInputDeviceBackend.addMockDevice("/mouse0", InputInfo.Mouse);
1145+ usageModeSelector.selectStaged();
1146+
1147+ // Load shell, and have it pick desktop
1148+ loadShell("desktop");
1149+ compare(shell.usageScenario, "desktop");
1150+ }
1151+
1143 function test_overrideWindowed() {
1152 function test_overrideWindowed() {
1144 loadShell("mako")
1153 loadShell("mako")
1145
1154