1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
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 The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QtTest/qtest.h> |
30 | #include <QtCore/qdir.h> |
31 | #include <QtCore/qfileinfo.h> |
32 | #include <QtCore/qplugin.h> |
33 | #include <private/qfactoryloader_p.h> |
34 | #include "plugin1/plugininterface1.h" |
35 | #include "plugin2/plugininterface2.h" |
36 | |
37 | #if !QT_CONFIG(library) |
38 | Q_IMPORT_PLUGIN(Plugin1) |
39 | Q_IMPORT_PLUGIN(Plugin2) |
40 | #endif |
41 | |
42 | class tst_QFactoryLoader : public QObject |
43 | { |
44 | Q_OBJECT |
45 | |
46 | #ifdef Q_OS_ANDROID |
47 | QSharedPointer<QTemporaryDir> directory; |
48 | #endif |
49 | |
50 | public slots: |
51 | void initTestCase(); |
52 | |
53 | private slots: |
54 | void usingTwoFactoriesFromSameDir(); |
55 | }; |
56 | |
57 | static const char binFolderC[] = "bin" ; |
58 | |
59 | void tst_QFactoryLoader::initTestCase() |
60 | { |
61 | #ifdef Q_OS_ANDROID |
62 | directory = QEXTRACTTESTDATA("android_test_data" ); |
63 | QVERIFY(directory); |
64 | QVERIFY(directory->isValid()); |
65 | QVERIFY2(QDir::setCurrent(directory->path()), qPrintable("Could not chdir to " + directory->path())); |
66 | #endif |
67 | const QString binFolder = QFINDTESTDATA(binFolderC); |
68 | QVERIFY2(!binFolder.isEmpty(), "Unable to locate 'bin' folder" ); |
69 | #if QT_CONFIG(library) |
70 | QCoreApplication::setLibraryPaths(QStringList(QFileInfo(binFolder).absolutePath())); |
71 | #endif |
72 | } |
73 | |
74 | void tst_QFactoryLoader::usingTwoFactoriesFromSameDir() |
75 | { |
76 | const QString suffix = QLatin1Char('/') + QLatin1String(binFolderC); |
77 | QFactoryLoader loader1(PluginInterface1_iid, suffix); |
78 | |
79 | PluginInterface1 *plugin1 = qobject_cast<PluginInterface1 *>(object: loader1.instance(index: 0)); |
80 | QVERIFY2(plugin1, |
81 | qPrintable(QString::fromLatin1("Cannot load plugin '%1'" ) |
82 | .arg(QLatin1String(PluginInterface1_iid)))); |
83 | |
84 | QFactoryLoader loader2(PluginInterface2_iid, suffix); |
85 | |
86 | PluginInterface2 *plugin2 = qobject_cast<PluginInterface2 *>(object: loader2.instance(index: 0)); |
87 | QVERIFY2(plugin2, |
88 | qPrintable(QString::fromLatin1("Cannot load plugin '%1'" ) |
89 | .arg(QLatin1String(PluginInterface2_iid)))); |
90 | |
91 | QCOMPARE(plugin1->pluginName(), QLatin1String("Plugin1 ok" )); |
92 | QCOMPARE(plugin2->pluginName(), QLatin1String("Plugin2 ok" )); |
93 | } |
94 | |
95 | QTEST_MAIN(tst_QFactoryLoader) |
96 | #include "tst_qfactoryloader.moc" |
97 | |