7
by Alberto Mardegan
Test plugin loading |
1 |
/*
|
2 |
* This file is part of system-settings
|
|
3 |
*
|
|
4 |
* Copyright (C) 2013 Canonical Ltd.
|
|
5 |
*
|
|
6 |
* Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
|
|
7 |
*
|
|
8 |
* This program is free software: you can redistribute it and/or modify it
|
|
9 |
* under the terms of the GNU General Public License version 3, as published
|
|
10 |
* by the Free Software Foundation.
|
|
11 |
*
|
|
12 |
* This program is distributed in the hope that it will be useful, but
|
|
13 |
* WITHOUT ANY WARRANTY; without even the implied warranties of
|
|
14 |
* MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
|
|
15 |
* PURPOSE. See the GNU General Public License for more details.
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License along
|
|
18 |
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 |
*/
|
|
20 |
||
21 |
#include "test-plugin.h" |
|
22 |
||
10
by Alberto Mardegan
Export pageComponent and entryComponent to QML |
23 |
#include <QDebug> |
7
by Alberto Mardegan
Test plugin loading |
24 |
#include <QStringList> |
8
by Alberto Mardegan
PluginBase->ItemBase |
25 |
#include <SystemSettings/ItemBase> |
7
by Alberto Mardegan
Test plugin loading |
26 |
|
27 |
using namespace SystemSettings; |
|
28 |
||
8
by Alberto Mardegan
PluginBase->ItemBase |
29 |
class TestItem: public ItemBase |
7
by Alberto Mardegan
Test plugin loading |
30 |
{
|
31 |
Q_OBJECT
|
|
32 |
||
33 |
public: |
|
34 |
TestItem(const QVariantMap &staticData, QObject *parent = 0); |
|
35 |
~TestItem(); |
|
36 |
||
37 |
virtual QQmlComponent *entryComponent(QQmlEngine *engine, |
|
38 |
QObject *parent = 0); |
|
39 |
virtual QQmlComponent *pageComponent(QQmlEngine *engine, |
|
40 |
QObject *parent = 0); |
|
1502.2.2
by jonas-drange
foobar |
41 |
QString name() const; |
492.4.4
by Iain Lane
Add some tests for the new reset api |
42 |
private: |
43 |
QQmlComponent *m_pageComponent; |
|
7
by Alberto Mardegan
Test plugin loading |
44 |
};
|
45 |
||
46 |
TestItem::TestItem(const QVariantMap &staticData, QObject *parent): |
|
492.4.4
by Iain Lane
Add some tests for the new reset api |
47 |
ItemBase(staticData, parent), |
48 |
m_pageComponent(0) |
|
7
by Alberto Mardegan
Test plugin loading |
49 |
{
|
1502.2.3
by jonas-drange
refactor |
50 |
QString name = staticData["name"].toString(); |
51 |
if (name == "Wireless") { |
|
1502.2.2
by jonas-drange
foobar |
52 |
QStringList keywords; |
53 |
keywords << "one" << "two" << "three"; |
|
54 |
setKeywords(keywords); |
|
1502.2.3
by jonas-drange
refactor |
55 |
} else if (name == "Brightness") { |
1502.2.2
by jonas-drange
foobar |
56 |
setName("Brightness & Display"); |
57 |
}
|
|
7
by Alberto Mardegan
Test plugin loading |
58 |
}
|
59 |
||
60 |
TestItem::~TestItem() |
|
61 |
{
|
|
62 |
}
|
|
63 |
||
64 |
QQmlComponent *TestItem::entryComponent(QQmlEngine *engine, QObject *parent) |
|
65 |
{
|
|
66 |
Q_UNUSED(engine); |
|
67 |
Q_UNUSED(parent); |
|
68 |
return 0; |
|
69 |
}
|
|
70 |
||
492.4.5
by Iain Lane
Try to wait for the page component to be ready to avoid test failures, maybe |
71 |
|
7
by Alberto Mardegan
Test plugin loading |
72 |
QQmlComponent *TestItem::pageComponent(QQmlEngine *engine, QObject *parent) |
73 |
{
|
|
492.4.4
by Iain Lane
Add some tests for the new reset api |
74 |
if (m_pageComponent == NULL) { |
75 |
QQmlComponent *page = new QQmlComponent(engine, parent); |
|
1496.2.10
by Ken VanDine
bump QtQuick imports to 2.4 |
76 |
page->setData("import QtQuick 2.4\n" |
492.4.4
by Iain Lane
Add some tests for the new reset api |
77 |
"Rectangle {\n" |
492.4.6
by Iain Lane
Don't leak component, don't include unused 'reset' property in tests |
78 |
" function reset() { console.log('Hello') }\n" |
492.4.4
by Iain Lane
Add some tests for the new reset api |
79 |
" width: 200; height: 200;\n" |
80 |
" objectName: \"myRect\"\n" |
|
81 |
" color: \"red\"" |
|
82 |
"}", |
|
83 |
QUrl()); |
|
84 |
m_pageComponent = page; |
|
85 |
}
|
|
86 |
return m_pageComponent; |
|
7
by Alberto Mardegan
Test plugin loading |
87 |
}
|
88 |
||
89 |
TestPlugin::TestPlugin(): |
|
90 |
QObject() |
|
91 |
{
|
|
92 |
}
|
|
93 |
||
8
by Alberto Mardegan
PluginBase->ItemBase |
94 |
ItemBase *TestPlugin::createItem(const QVariantMap &staticData, |
95 |
QObject *parent) |
|
7
by Alberto Mardegan
Test plugin loading |
96 |
{
|
97 |
return new TestItem(staticData, parent); |
|
98 |
}
|
|
99 |
||
100 |
#include "test-plugin.moc" |