|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the test suite of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <QtTest/QtTest> |
|
42 |
|
43 #include <QCoreApplication> |
|
44 #include <QDebug> |
|
45 #include <QDir> |
|
46 #include <QPluginLoader> |
|
47 |
|
48 class tst_QPlugin : public QObject |
|
49 { |
|
50 Q_OBJECT |
|
51 |
|
52 QDir dir; |
|
53 |
|
54 public: |
|
55 tst_QPlugin(); |
|
56 |
|
57 private slots: |
|
58 void loadDebugPlugin(); |
|
59 void loadReleasePlugin(); |
|
60 }; |
|
61 |
|
62 tst_QPlugin::tst_QPlugin() |
|
63 : dir("plugins") |
|
64 { |
|
65 } |
|
66 |
|
67 void tst_QPlugin::loadDebugPlugin() |
|
68 { |
|
69 foreach (QString fileName, dir.entryList(QStringList() << "*debug*", QDir::Files)) { |
|
70 if (!QLibrary::isLibrary(fileName)) |
|
71 continue; |
|
72 QPluginLoader loader(dir.filePath(fileName)); |
|
73 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) |
|
74 // we can always load a plugin on unix |
|
75 QVERIFY(loader.load()); |
|
76 QObject *object = loader.instance(); |
|
77 QVERIFY(object != 0); |
|
78 #else |
|
79 // loading a plugin is dependent on which lib we are running against |
|
80 # if defined(QT_NO_DEBUG) |
|
81 // release build, we cannot load debug plugins |
|
82 QVERIFY(!loader.load()); |
|
83 # else |
|
84 // debug build, we can load debug plugins |
|
85 QVERIFY(loader.load()); |
|
86 QObject *object = loader.instance(); |
|
87 QVERIFY(object != 0); |
|
88 # endif |
|
89 #endif |
|
90 } |
|
91 } |
|
92 |
|
93 void tst_QPlugin::loadReleasePlugin() |
|
94 { |
|
95 foreach (QString fileName, dir.entryList(QStringList() << "*release*", QDir::Files)) { |
|
96 if (!QLibrary::isLibrary(fileName)) |
|
97 continue; |
|
98 QPluginLoader loader(dir.filePath(fileName)); |
|
99 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) |
|
100 // we can always load a plugin on unix |
|
101 QVERIFY(loader.load()); |
|
102 QObject *object = loader.instance(); |
|
103 QVERIFY(object != 0); |
|
104 #else |
|
105 // loading a plugin is dependent on which lib we are running against |
|
106 # if defined(QT_NO_DEBUG) |
|
107 // release build, we can load debug plugins |
|
108 QVERIFY(loader.load()); |
|
109 QObject *object = loader.instance(); |
|
110 QVERIFY(object != 0); |
|
111 # else |
|
112 // debug build, we cannot load debug plugins |
|
113 QVERIFY(!loader.load()); |
|
114 # endif |
|
115 #endif |
|
116 } |
|
117 } |
|
118 |
|
119 QTEST_MAIN(tst_QPlugin) |
|
120 #include "tst_qplugin.moc" |