~ci-train-bot/ubuntu-system-settings/ubuntu-system-settings-ubuntu-zesty-1721

« back to all changes in this revision

Viewing changes to tests/tst_plugins.cpp

  • Committer: Iain Lane
  • Date: 2014-02-28 17:14:49 UTC
  • mto: This revision was merged to the branch mainline in revision 863.
  • Revision ID: iain.lane@canonical.com-20140228171449-s2zlo2vzhsvw6h3l
Add some tests for the new reset api

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <QDebug>
26
26
#include <QObject>
 
27
#include <QQmlContext>
 
28
#include <QQmlEngine>
27
29
#include <QSignalSpy>
28
30
#include <QTest>
29
31
 
40
42
    void testCategory();
41
43
    void testKeywords();
42
44
    void testSorting();
 
45
    void testReset();
 
46
    void testResetInPlugin();
43
47
};
44
48
 
45
49
void PluginsTest::testCategory()
49
53
    manager.componentComplete();
50
54
 
51
55
    QSet<QString> expectedCategories;
52
 
    expectedCategories << "phone" << "network";
 
56
    expectedCategories << "phone" << "network" << "misc";
53
57
    QCOMPARE(manager.categories().toSet(), expectedCategories);
54
58
 
55
59
    QMap<QString, Plugin *> plugins = manager.plugins("phone");
118
122
    QCOMPARE(cellular->displayName(), QString("Bluetooth"));
119
123
}
120
124
 
 
125
void PluginsTest::testReset()
 
126
{
 
127
 
 
128
    PluginManager manager;
 
129
    manager.classBegin();
 
130
    manager.componentComplete();
 
131
 
 
132
    QAbstractItemModel *model(manager.itemModel("network"));
 
133
    Plugin *wireless = (Plugin *) model->data(model->index(0, 0),
 
134
                                         ItemModel::ItemRole).value<QObject *>();
 
135
 
 
136
    QQmlEngine engine;
 
137
    QQmlContext *context = new QQmlContext(engine.rootContext());
 
138
    QQmlEngine::setContextForObject(wireless, context);
 
139
 
 
140
    /* This is how you check that a debug message was printed */
 
141
    QTest::ignoreMessage(QtDebugMsg, "Hello");
 
142
    wireless->reset();
 
143
}
 
144
 
 
145
void PluginsTest::testResetInPlugin()
 
146
{
 
147
    PluginManager manager;
 
148
    manager.classBegin();
 
149
    manager.componentComplete();
 
150
 
 
151
    QAbstractItemModel *model(manager.itemModel("misc"));
 
152
    Plugin *phone = (Plugin *) model->data(model->index(0, 0),
 
153
                                         ItemModel::ItemRole).value<QObject *>();
 
154
 
 
155
    QQmlEngine engine;
 
156
    QQmlContext *context = new QQmlContext(engine.rootContext());
 
157
    QQmlEngine::setContextForObject(phone, context);
 
158
 
 
159
    /* This is how you check that a debug message was printed */
 
160
    /* qDebug() inserts a space at the end */
 
161
    QTest::ignoreMessage(QtDebugMsg, "reset function in plugin ");
 
162
 
 
163
    phone->reset();
 
164
}
 
165
 
121
166
QTEST_MAIN(PluginsTest);
122
167
#include "tst_plugins.moc"