on xenial help sign in
Added tests for background image
ccedc8aAndrea Cimitan
Shell.qml+1−2
@@ -152,6 +152,7 @@ FocusScope {
152
152
153 CrossFadeImage {
153 CrossFadeImage {
154 id: backgroundImage
154 id: backgroundImage
155+ objectName: "backgroundImage"
155 source: shell.background
156 source: shell.background
156 anchors.fill: parent
157 anchors.fill: parent
157 onStatusChanged: {
158 onStatusChanged: {
@@ -203,7 +204,6 @@ FocusScope {
203 }
204 }
204 }
205 }
205
206
206−
207 Item {
207 Item {
208 id: stagesOuterContainer
208 id: stagesOuterContainer
209
209
@@ -268,7 +268,6 @@ FocusScope {
268 ignoreUnknownSignals: true
268 ignoreUnknownSignals: true
269 }
269 }
270
270
271−
272 Stage {
271 Stage {
273 id: mainStage
272 id: mainStage
274
273
tests/data/unity/backgrounds/blue.pngnew file

Binary file not shown.

tests/data/unity/backgrounds/red.pngnew file

Binary file not shown.

tests/mocks/GSettings/fake_gsettings.cpp+16−11
@@ -16,6 +16,8 @@
16
16
17#include "fake_gsettings.h"
17#include "fake_gsettings.h"
18
18
19+#include <QList>
20+
19struct GSettingsSchemaQmlPrivate {
21struct GSettingsSchemaQmlPrivate {
20 QByteArray id;
22 QByteArray id;
21 QByteArray path;
23 QByteArray path;
@@ -25,27 +27,30 @@ struct GSettingsQmlPrivate {
25 GSettingsSchemaQml *schema;
27 GSettingsSchemaQml *schema;
26};
28};
27
29
28−bool GSettingsControllerQml::instance_exists;
29−GSettingsControllerQml* GSettingsControllerQml::_controllerInstance;
30+GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
30
31
31GSettingsControllerQml::GSettingsControllerQml() {
32GSettingsControllerQml::GSettingsControllerQml() {
32}
33}
33
34
34GSettingsControllerQml::~GSettingsControllerQml() {
35GSettingsControllerQml::~GSettingsControllerQml() {
35− instance_exists = false;
36+ s_controllerInstance = 0;
36}
37}
37
38
38−GSettingsControllerQml* GSettingsControllerQml::getInstance() {
39+GSettingsControllerQml* GSettingsControllerQml::instance() {
39− if(!instance_exists) {
40+ if(!s_controllerInstance) {
40− _controllerInstance = new GSettingsControllerQml();
41+ s_controllerInstance = new GSettingsControllerQml();
41− instance_exists = true;
42− return _controllerInstance;
43− } else {
44− return _controllerInstance;
45 }
42 }
43+ return s_controllerInstance;
44+}
45+
46+void GSettingsControllerQml::registerSettingsObject(GSettingsQml *obj) {
47+ m_registeredGSettings.append(obj);
46}
48}
47
49
48void GSettingsControllerQml::setPictureUri(const QString &str) {
50void GSettingsControllerQml::setPictureUri(const QString &str) {
51+ Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
52+ obj->setPictureUri(str);
53+ }
49}
54}
50
55
51GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
56GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
@@ -83,9 +88,9 @@ void GSettingsSchemaQml::setPath(const QByteArray &path) {
83}
88}
84
89
85GSettingsQml::GSettingsQml(QObject *parent): QObject(parent) {
90GSettingsQml::GSettingsQml(QObject *parent): QObject(parent) {
86− GSettingsControllerQml::getInstance();
87 priv = new GSettingsQmlPrivate;
91 priv = new GSettingsQmlPrivate;
88 priv->schema = new GSettingsSchemaQml(this);
92 priv->schema = new GSettingsSchemaQml(this);
93+ GSettingsControllerQml::instance()->registerSettingsObject(this);
89}
94}
90
95
91GSettingsQml::~GSettingsQml() {
96GSettingsQml::~GSettingsQml() {
tests/mocks/GSettings/fake_gsettings.h+20−21
@@ -17,29 +17,10 @@
17#ifndef FAKE_GSETTINGS_H
17#ifndef FAKE_GSETTINGS_H
18#define FAKE_GSETTINGS_H
18#define FAKE_GSETTINGS_H
19
19
20+#include <QList>
20#include <QtQml>
21#include <QtQml>
21#include <QQmlParserStatus>
22#include <QQmlParserStatus>
22
23
23−class GSettingsControllerQml: public QObject
24−{
25− Q_OBJECT
26−
27−public:
28− static GSettingsControllerQml* getInstance();
29− ~GSettingsControllerQml();
30−
31− void setPictureUri(const QString &str);
32−
33−private:
34− GSettingsControllerQml();
35− GSettingsControllerQml(const GSettingsControllerQml&);
36− GSettingsControllerQml& operator=(const GSettingsControllerQml&);
37−
38− static bool instance_exists;
39−
40− static GSettingsControllerQml* _controllerInstance;
41−};
42−
43class GSettingsSchemaQml: public QObject
24class GSettingsSchemaQml: public QObject
44{
25{
45 Q_OBJECT
26 Q_OBJECT
@@ -74,7 +55,7 @@ public:
74 GSettingsSchemaQml * schema() const;
55 GSettingsSchemaQml * schema() const;
75 QString pictureUri() const;
56 QString pictureUri() const;
76
57
77− void setPictureUric
58+ void setPictureUri(const QString &str);
78
59
79Q_SIGNALS:
60Q_SIGNALS:
80 void schemaChanged();
61 void schemaChanged();
@@ -88,4 +69,22 @@ private:
88 friend class GSettingsSchemaQml;
69 friend class GSettingsSchemaQml;
89};
70};
90
71
72+class GSettingsControllerQml: public QObject
73+{
74+ Q_OBJECT
75+
76+public:
77+ static GSettingsControllerQml* instance();
78+ ~GSettingsControllerQml();
79+
80+ void registerSettingsObject(GSettingsQml *obj);
81+ Q_INVOKABLE void setPictureUri(const QString &str);
82+
83+private:
84+ GSettingsControllerQml();
85+
86+ static GSettingsControllerQml* s_controllerInstance;
87+ QList<GSettingsQml *> m_registeredGSettings;
88+};
89+
91#endif // FAKE_GSETTINGS_H
90#endif // FAKE_GSETTINGS_H
tests/mocks/GSettings/plugin.cpp+1−1
@@ -21,7 +21,7 @@
21
21
22static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
22static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
23{
23{
24− return GSettingsControllerQml::getInstance();
24+ return GSettingsControllerQml::instance();
25}
25}
26
26
27void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
27void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
tests/qmltests/tst_Shell.qml+10−6
@@ -27,11 +27,6 @@ import "../.."
27
27
28Shell {
28Shell {
29 id: shell
29 id: shell
30−
31− GSettingsController {
32− id: gsettingsController
33− }
34−
35 UT.UnityTestCase {
30 UT.UnityTestCase {
36 name: "Shell"
31 name: "Shell"
37 when: windowShown
32 when: windowShown
@@ -246,8 +241,17 @@ Shell {
246 return itemRectInShell.x < 0;
241 return itemRectInShell.x < 0;
247 }
242 }
248
243
249− function test_wallpaper() {
244+ function test_wallpaper_data() {
245+ return [
246+ {tag: "red", url: "tests/data/unity/backgrounds/red.png"},
247+ {tag: "blue", url: "tests/data/unity/backgrounds/blue.png"}
248+ ]
249+ }
250
250
251+ function test_wallpaper(data) {
252+ var backgroundImage = findChild(shell, "backgroundImage")
253+ GSettingsController.setPictureUri(data.url)
254+ tryCompareFunction(function() { return backgroundImage.source.toString().indexOf(data.url) !== -1; }, true)
251 }
255 }
252 }
256 }
253}
257}