1
/****************************************************************************
3
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4
** Contact: http://www.qt-project.org/legal
6
** This file is part of the test suite of the Qt Toolkit.
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.
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.
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.
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.
40
****************************************************************************/
42
//TESTED_COMPONENT=src/contacts
44
/* Force a static plugin */
45
#define QT_STATICPLUGIN
47
#include <QtTest/QtTest>
49
#include <qcontacts.h>
51
#include <QApplication>
52
QTCONTACTS_USE_NAMESPACE
54
class tst_QContactManagerPlugins : public QObject
59
tst_QContactManagerPlugins();
60
virtual ~tst_QContactManagerPlugins();
69
/* Test a static factory as well */
70
class DummyStaticEngineFactory : public QObject, public QContactManagerEngineFactory
73
Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
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";}
80
QContactManagerEngine* DummyStaticEngineFactory::engine(const QMap<QString, QString>& parameters, QContactManager::Error* error)
83
*error = QContactManager::LockedError; // random unlikely error
84
return 0; // always fail, haha
87
QContactEngineId* DummyStaticEngineFactory::createContactEngineId(const QMap<QString, QString>& parameters, const QString& engineIdString) const
90
Q_UNUSED(engineIdString);
94
Q_EXPORT_PLUGIN2(contacts_teststaticdummy, DummyStaticEngineFactory)
95
Q_IMPORT_PLUGIN(contacts_teststaticdummy)
98
Q_EXPORT_PLUGIN2(contacts_teststaticdummycopy, DummyStaticEngineFactory)
99
Q_IMPORT_PLUGIN(contacts_teststaticdummycopy)
101
/* And test an impostor as well */
102
class ImpostorEngineFactory : public QObject, public QContactManagerEngineFactory
105
Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
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";}
112
Q_EXPORT_PLUGIN2(contacts_testimpostordummy, ImpostorEngineFactory)
113
Q_IMPORT_PLUGIN(contacts_testimpostordummy)
115
/* And test another impostor as well */
116
class ImpostorEngineFactory2 : public QObject, public QContactManagerEngineFactory
119
Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
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";}
127
Q_EXPORT_PLUGIN2(contacts_testimpostordummy2, ImpostorEngineFactory2)
128
Q_IMPORT_PLUGIN(contacts_testimpostordummy2)
130
/* An empty interface name */
131
class EmptyEngineFactory : public QObject, public QContactManagerEngineFactory
134
Q_INTERFACES(QtContacts::QContactManagerEngineFactory)
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();}
141
Q_EXPORT_PLUGIN2(contacts_teststaticemptydummy, EmptyEngineFactory)
142
Q_IMPORT_PLUGIN(contacts_teststaticemptydummy)
144
/* And a different interface one too */
146
class BoringInterface
154
Q_DECLARE_INTERFACE(BoringInterface, "REALLYBORING!")
157
class BoringFactory : public QObject, public BoringInterface
160
Q_INTERFACES(BoringInterface)
163
Q_EXPORT_PLUGIN2(contacts_testboring, BoringFactory)
164
Q_IMPORT_PLUGIN(contacts_testboring)
167
tst_QContactManagerPlugins::tst_QContactManagerPlugins()
171
tst_QContactManagerPlugins::~tst_QContactManagerPlugins()
175
void tst_QContactManagerPlugins::init()
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 :/
186
void tst_QContactManagerPlugins::cleanup()
190
void tst_QContactManagerPlugins::testDummy()
192
QVERIFY(QContactManager::availableManagers().contains("testdummy"));
193
QVERIFY(QContactManager::availableManagers().contains("teststaticdummy"));
195
QContactManager m1("teststaticdummy"); // should fail
196
QVERIFY(m1.managerName() == "invalid");
197
QVERIFY(m1.error() == QContactManager::LockedError);
199
QContactManager m2("testdummy");
200
QVERIFY(m2.managerName() == "testdummy");
203
QTEST_MAIN(tst_QContactManagerPlugins)
204
#include "tst_qcontactmanagerplugins.moc"