on xenial help sign in
Added tests for background image
commitccedc8a53902fe4105d56f5fd3c65a809871eccc authorAndrea Cimitan <andrea.cimitan@canonical.com> dateFri 26 Jul 2013, 11:48 (13 years ago) parentb9c6b58ad4743e
7 files changed+48−41
Shell.qml+1−2 tests/data/unity/backgrounds/blue.png tests/data/unity/backgrounds/red.png tests/mocks/GSettings/fake_gsettings.cpp+16−11 tests/mocks/GSettings/fake_gsettings.h+20−21 tests/mocks/GSettings/plugin.cpp+1−1 tests/qmltests/tst_Shell.qml+10−6
Shell.qml+1−2
@@ -152,6 +152,7 @@ FocusScope {
152152
153153 CrossFadeImage {
154154 id: backgroundImage
155+ objectName: "backgroundImage"
155156 source: shell.background
156157 anchors.fill: parent
157158 onStatusChanged: {
@@ -203,7 +204,6 @@ FocusScope {
203204 }
204205 }
205206
206−
207207 Item {
208208 id: stagesOuterContainer
209209
@@ -268,7 +268,6 @@ FocusScope {
268268 ignoreUnknownSignals: true
269269 }
270270
271−
272271 Stage {
273272 id: mainStage
274273
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 @@
1616
1717#include "fake_gsettings.h"
1818
19+#include <QList>
20+
1921struct GSettingsSchemaQmlPrivate {
2022 QByteArray id;
2123 QByteArray path;
@@ -25,27 +27,30 @@ struct GSettingsQmlPrivate {
2527 GSettingsSchemaQml *schema;
2628};
2729
28−bool GSettingsControllerQml::instance_exists;
29−GSettingsControllerQml* GSettingsControllerQml::_controllerInstance;
30+GSettingsControllerQml* GSettingsControllerQml::s_controllerInstance = 0;
3031
3132GSettingsControllerQml::GSettingsControllerQml() {
3233}
3334
3435GSettingsControllerQml::~GSettingsControllerQml() {
35− instance_exists = false;
36+ s_controllerInstance = 0;
3637}
3738
38−GSettingsControllerQml* GSettingsControllerQml::getInstance() {
39− if(!instance_exists) {
40− _controllerInstance = new GSettingsControllerQml();
41− instance_exists = true;
42− return _controllerInstance;
43− } else {
44− return _controllerInstance;
39+GSettingsControllerQml* GSettingsControllerQml::instance() {
40+ if(!s_controllerInstance) {
41+ s_controllerInstance = new GSettingsControllerQml();
4542 }
43+ return s_controllerInstance;
44+}
45+
46+void GSettingsControllerQml::registerSettingsObject(GSettingsQml *obj) {
47+ m_registeredGSettings.append(obj);
4648}
4749
4850void GSettingsControllerQml::setPictureUri(const QString &str) {
51+ Q_FOREACH (GSettingsQml *obj, m_registeredGSettings) {
52+ obj->setPictureUri(str);
53+ }
4954}
5055
5156GSettingsSchemaQml::GSettingsSchemaQml(QObject *parent): QObject(parent) {
@@ -83,9 +88,9 @@ void GSettingsSchemaQml::setPath(const QByteArray &path) {
8388}
8489
8590GSettingsQml::GSettingsQml(QObject *parent): QObject(parent) {
86− GSettingsControllerQml::getInstance();
8791 priv = new GSettingsQmlPrivate;
8892 priv->schema = new GSettingsSchemaQml(this);
93+ GSettingsControllerQml::instance()->registerSettingsObject(this);
8994}
9095
9196GSettingsQml::~GSettingsQml() {
tests/mocks/GSettings/fake_gsettings.h+20−21
@@ -17,29 +17,10 @@
1717#ifndef FAKE_GSETTINGS_H
1818#define FAKE_GSETTINGS_H
1919
20+#include <QList>
2021#include <QtQml>
2122#include <QQmlParserStatus>
2223
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−
4324class GSettingsSchemaQml: public QObject
4425{
4526 Q_OBJECT
@@ -74,7 +55,7 @@ public:
7455 GSettingsSchemaQml * schema() const;
7556 QString pictureUri() const;
7657
77− void setPictureUric
58+ void setPictureUri(const QString &str);
7859
7960Q_SIGNALS:
8061 void schemaChanged();
@@ -88,4 +69,22 @@ private:
8869 friend class GSettingsSchemaQml;
8970};
9071
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+
9190#endif // FAKE_GSETTINGS_H
tests/mocks/GSettings/plugin.cpp+1−1
@@ -21,7 +21,7 @@
2121
2222static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
2323{
24− return GSettingsControllerQml::getInstance();
24+ return GSettingsControllerQml::instance();
2525}
2626
2727void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
tests/qmltests/tst_Shell.qml+10−6
@@ -27,11 +27,6 @@ import "../.."
2727
2828Shell {
2929 id: shell
30−
31− GSettingsController {
32− id: gsettingsController
33− }
34−
3530 UT.UnityTestCase {
3631 name: "Shell"
3732 when: windowShown
@@ -246,8 +241,17 @@ Shell {
246241 return itemRectInShell.x < 0;
247242 }
248243
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+ }
250250
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)
251255 }
252256 }
253257}