~chris.gagnon/+junk/qtpim-coverage

« back to all changes in this revision

Viewing changes to tests/auto/contacts/qcontactmanagerplugins/unittest/tst_qcontactmanagerplugins.cpp

  • Committer: chris.gagnon
  • Date: 2013-12-10 23:09:37 UTC
  • Revision ID: chris.gagnon@canonical.com-20131210230937-2akf1ft1edcttk87
first post

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/legal
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** Commercial License Usage
 
10
** Licensees holding valid commercial Qt licenses may use this file in
 
11
** accordance with the commercial license agreement provided with the
 
12
** Software or, alternatively, in accordance with the terms contained in
 
13
** a written agreement between you and Digia.  For licensing terms and
 
14
** conditions see http://qt.digia.com/licensing.  For further information
 
15
** use the contact form at http://qt.digia.com/contact-us.
 
16
**
 
17
** GNU Lesser General Public License Usage
 
18
** Alternatively, this file may be used under the terms of the GNU Lesser
 
19
** General Public License version 2.1 as published by the Free Software
 
20
** Foundation and appearing in the file LICENSE.LGPL included in the
 
21
** packaging of this file.  Please review the following information to
 
22
** ensure the GNU Lesser General Public License version 2.1 requirements
 
23
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
24
**
 
25
** In addition, as a special exception, Digia gives you certain additional
 
26
** rights.  These rights are described in the Digia Qt LGPL Exception
 
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
28
**
 
29
** GNU General Public License Usage
 
30
** Alternatively, this file may be used under the terms of the GNU
 
31
** General Public License version 3.0 as published by the Free Software
 
32
** Foundation and appearing in the file LICENSE.GPL included in the
 
33
** packaging of this file.  Please review the following information to
 
34
** ensure the GNU General Public License version 3.0 requirements will be
 
35
** met: http://www.gnu.org/copyleft/gpl.html.
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
//TESTED_COMPONENT=src/contacts
 
43
 
 
44
/* Force a static plugin */
 
45
#define QT_STATICPLUGIN
 
46
 
 
47
#include <QtTest/QtTest>
 
48
 
 
49
#include <qcontacts.h>
 
50
 
 
51
#include <QApplication>
 
52
QTCONTACTS_USE_NAMESPACE
 
53
 
 
54
class tst_QContactManagerPlugins : public QObject
 
55
{
 
56
Q_OBJECT
 
57
 
 
58
public:
 
59
    tst_QContactManagerPlugins();
 
60
    virtual ~tst_QContactManagerPlugins();
 
61
 
 
62
public slots:
 
63
    void init();
 
64
    void cleanup();
 
65
private slots:
 
66
    void testDummy();
 
67
};
 
68
 
 
69
/* Test a static factory as well */
 
70
class DummyStaticEngineFactory : public QObject, public QContactManagerEngineFactory
 
71
{
 
72
    Q_OBJECT
 
73
    Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
 
74
    public:
 
75
        QContactManagerEngine* engine(const QMap<QString, QString>& parameters, QContactManager::Error* error);
 
76
        QContactEngineId* createContactEngineId(const QMap<QString, QString>& parameters, const QString& engineIdString) const;
 
77
        QString managerName() const {return "teststaticdummy";}
 
78
};
 
79
 
 
80
QContactManagerEngine* DummyStaticEngineFactory::engine(const QMap<QString, QString>& parameters, QContactManager::Error* error)
 
81
{
 
82
    Q_UNUSED(parameters);
 
83
    *error = QContactManager::LockedError; // random unlikely error
 
84
    return 0; // always fail, haha
 
85
}
 
86
 
 
87
QContactEngineId* DummyStaticEngineFactory::createContactEngineId(const QMap<QString, QString>& parameters, const QString& engineIdString) const
 
88
{
 
89
    Q_UNUSED(parameters);
 
90
    Q_UNUSED(engineIdString);
 
91
    return 0;
 
92
}
 
93
 
 
94
Q_EXPORT_PLUGIN2(contacts_teststaticdummy, DummyStaticEngineFactory)
 
95
Q_IMPORT_PLUGIN(contacts_teststaticdummy)
 
96
 
 
97
/* And a copy */
 
98
Q_EXPORT_PLUGIN2(contacts_teststaticdummycopy, DummyStaticEngineFactory)
 
99
Q_IMPORT_PLUGIN(contacts_teststaticdummycopy)
 
100
 
 
101
/* And test an impostor as well */
 
102
class ImpostorEngineFactory : public QObject, public QContactManagerEngineFactory
 
103
{
 
104
    Q_OBJECT
 
105
    Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
 
106
    public:
 
107
        QContactManagerEngine* engine(const QMap<QString, QString>& , QContactManager::Error* ) {return 0;}
 
108
        QContactEngineId* createContactEngineId(const QMap<QString, QString>& parameters, const QString& engineIdString) const {return 0;}
 
109
        QString managerName() const {return "memory";}
 
110
};
 
111
 
 
112
Q_EXPORT_PLUGIN2(contacts_testimpostordummy, ImpostorEngineFactory)
 
113
Q_IMPORT_PLUGIN(contacts_testimpostordummy)
 
114
 
 
115
/* And test another impostor as well */
 
116
class ImpostorEngineFactory2 : public QObject, public QContactManagerEngineFactory
 
117
{
 
118
    Q_OBJECT
 
119
    Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
 
120
    public:
 
121
        QContactManagerEngine* engine(const QMap<QString, QString>& , QContactManager::Error* ) {return 0;}
 
122
        QContactEngineId* createContactEngineId(const QMap<QString, QString>& parameters, const QString& engineIdString) const {return 0;}
 
123
        QString managerName() const {return "invalid";}
 
124
};
 
125
 
 
126
 
 
127
Q_EXPORT_PLUGIN2(contacts_testimpostordummy2, ImpostorEngineFactory2)
 
128
Q_IMPORT_PLUGIN(contacts_testimpostordummy2)
 
129
 
 
130
/* An empty interface name */
 
131
class EmptyEngineFactory : public QObject, public QContactManagerEngineFactory
 
132
{
 
133
    Q_OBJECT
 
134
    Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
 
135
    public:
 
136
        QContactManagerEngine* engine(const QMap<QString, QString>& , QContactManager::Error* ) {return 0;}
 
137
        QContactEngineId* createContactEngineId(const QMap<QString, QString>& parameters, const QString& engineIdString) const {return 0;}
 
138
        QString managerName() const {return QString();}
 
139
};
 
140
 
 
141
Q_EXPORT_PLUGIN2(contacts_teststaticemptydummy, EmptyEngineFactory)
 
142
Q_IMPORT_PLUGIN(contacts_teststaticemptydummy)
 
143
 
 
144
/* And a different interface one too */
 
145
 
 
146
class BoringInterface
 
147
{
 
148
    public:
 
149
        void doNothing() {}
 
150
 
 
151
};
 
152
 
 
153
QT_BEGIN_NAMESPACE
 
154
Q_DECLARE_INTERFACE(BoringInterface, "REALLYBORING!")
 
155
QT_END_NAMESPACE
 
156
 
 
157
class BoringFactory : public QObject, public BoringInterface
 
158
{
 
159
    Q_OBJECT
 
160
    Q_INTERFACES(BoringInterface)
 
161
};
 
162
 
 
163
Q_EXPORT_PLUGIN2(contacts_testboring, BoringFactory)
 
164
Q_IMPORT_PLUGIN(contacts_testboring)
 
165
 
 
166
 
 
167
tst_QContactManagerPlugins::tst_QContactManagerPlugins()
 
168
{
 
169
}
 
170
 
 
171
tst_QContactManagerPlugins::~tst_QContactManagerPlugins()
 
172
{
 
173
}
 
174
 
 
175
void tst_QContactManagerPlugins::init()
 
176
{
 
177
    /* Add a path to our plugin path */
 
178
    QString path = QApplication::applicationDirPath() + "/dummyplugin/plugins";
 
179
    QApplication::addLibraryPath(path);
 
180
    QApplication::addLibraryPath(path); // Test the plugin path deduplication code
 
181
    path = QApplication::applicationDirPath() + "/dummyplugin";
 
182
    QApplication::addLibraryPath(path);
 
183
    QApplication::addLibraryPath("/"); // strictly to test a cdUp :/
 
184
}
 
185
 
 
186
void tst_QContactManagerPlugins::cleanup()
 
187
{
 
188
}
 
189
 
 
190
void tst_QContactManagerPlugins::testDummy()
 
191
{
 
192
    QVERIFY(QContactManager::availableManagers().contains("testdummy"));
 
193
    QVERIFY(QContactManager::availableManagers().contains("teststaticdummy"));
 
194
 
 
195
    QContactManager m1("teststaticdummy"); // should fail
 
196
    QVERIFY(m1.managerName() == "invalid");
 
197
    QVERIFY(m1.error() == QContactManager::LockedError);
 
198
 
 
199
    QContactManager m2("testdummy");
 
200
    QVERIFY(m2.managerName() == "testdummy");
 
201
}
 
202
 
 
203
QTEST_MAIN(tst_QContactManagerPlugins)
 
204
#include "tst_qcontactmanagerplugins.moc"