dRonin  adbada4
dRonin GCS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
tst_pluginspec.cpp
Go to the documentation of this file.
1 
13 /*
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful, but
20  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
21  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  * for more details.
23  *
24  * You should have received a copy of the GNU General Public License along
25  * with this program; if not, see <http://www.gnu.org/licenses/>
26  */
27 
28 #include "testplugin/testplugin.h"
29 
34 
35 #include <QtCore/QObject>
36 #include <QtTest/QtTest>
37 
38 using namespace ExtensionSystem;
39 
40 class tst_PluginSpec : public QObject
41 {
42  Q_OBJECT
43 
44 private slots:
45  void read();
46  void readError();
47  void isValidVersion();
48  void versionCompare();
49  void provides();
50  void locationAndPath();
51  void resolveDependencies();
52  void loadLibrary();
53  void initializePlugin();
54  void initializeExtensions();
55 };
56 
57 void tst_PluginSpec::read()
58 {
60  QCOMPARE(spec.state, PluginSpec::Invalid);
61  QVERIFY(spec.read("testspecs/spec1.xml"));
62  QCOMPARE(spec.state, PluginSpec::Read);
63  QVERIFY(!spec.hasError);
64  QVERIFY(spec.errorString.isEmpty());
65  QCOMPARE(spec.name, QString("test"));
66  QCOMPARE(spec.version, QString("1.0.1"));
67  QCOMPARE(spec.compatVersion, QString("1.0.0"));
68  QCOMPARE(spec.vendor, QString("Trolltech"));
69  QCOMPARE(spec.copyright, QString("(C) 2007 Trolltech ASA"));
70  QCOMPARE(spec.license, QString("This is a default license bla\nblubbblubb\nend of terms"));
71  QCOMPARE(spec.description, QString("This plugin is just a test.\n it demonstrates the great use of the plugin spec."));
72  QCOMPARE(spec.url, QString("http://www.trolltech.com"));
73  PluginDependency dep1;
74  dep1.name = QString("SomeOtherPlugin");
75  dep1.version = QString("2.3.0_2");
76  PluginDependency dep2;
77  dep2.name = QString("EvenOther");
78  dep2.version = QString("1.0.0");
79  QCOMPARE(spec.dependencies, QList<PluginDependency>() << dep1 << dep2);
80 
81  // test missing compatVersion behavior
82  QVERIFY(spec.read("testspecs/spec2.xml"));
83  QCOMPARE(spec.version, QString("3.1.4_10"));
84  QCOMPARE(spec.compatVersion, QString("3.1.4_10"));
85 }
86 
87 void tst_PluginSpec::readError()
88 {
90  QCOMPARE(spec.state, PluginSpec::Invalid);
91  QVERIFY(!spec.read("non-existing-file.xml"));
92  QCOMPARE(spec.state, PluginSpec::Invalid);
93  QVERIFY(spec.hasError);
94  QVERIFY(!spec.errorString.isEmpty());
95  QVERIFY(!spec.read("testspecs/spec_wrong1.xml"));
96  QCOMPARE(spec.state, PluginSpec::Invalid);
97  QVERIFY(spec.hasError);
98  QVERIFY(!spec.errorString.isEmpty());
99  QVERIFY(!spec.read("testspecs/spec_wrong2.xml"));
100  QCOMPARE(spec.state, PluginSpec::Invalid);
101  QVERIFY(spec.hasError);
102  QVERIFY(!spec.errorString.isEmpty());
103  QVERIFY(!spec.read("testspecs/spec_wrong3.xml"));
104  QCOMPARE(spec.state, PluginSpec::Invalid);
105  QVERIFY(spec.hasError);
106  QVERIFY(!spec.errorString.isEmpty());
107  QVERIFY(!spec.read("testspecs/spec_wrong4.xml"));
108  QCOMPARE(spec.state, PluginSpec::Invalid);
109  QVERIFY(spec.hasError);
110  QVERIFY(!spec.errorString.isEmpty());
111  QVERIFY(!spec.read("testspecs/spec_wrong5.xml"));
112  QCOMPARE(spec.state, PluginSpec::Invalid);
113  QVERIFY(spec.hasError);
114  QVERIFY(!spec.errorString.isEmpty());
115 }
116 
117 void tst_PluginSpec::isValidVersion()
118 {
126 
130  QVERIFY(!Internal::PluginSpecPrivate::isValidVersion("1.0.0.0"));
131 }
132 
133 void tst_PluginSpec::versionCompare()
134 {
135  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3", "3") == 0);
136  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.0.0", "3") == 0);
137  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.0", "3") == 0);
138  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.0.0_1", "3_1") == 0);
139  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.0_21", "3_21") == 0);
140 
141  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3", "1") > 0);
142  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3", "1.0_12") > 0);
143  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3_1", "3") > 0);
144  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.1.0_23", "3.1") > 0);
145  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.1_23", "3.1_12") > 0);
146 
147  QVERIFY(Internal::PluginSpecPrivate::versionCompare("1", "3") < 0);
148  QVERIFY(Internal::PluginSpecPrivate::versionCompare("1.0_12", "3") < 0);
149  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3", "3_1") < 0);
150  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.1", "3.1.0_23") < 0);
151  QVERIFY(Internal::PluginSpecPrivate::versionCompare("3.1_12", "3.1_23") < 0);
152 }
153 
154 void tst_PluginSpec::provides()
155 {
157  QVERIFY(spec.read("testspecs/simplespec.xml"));
158  QVERIFY(!spec.provides("SomeOtherPlugin", "2.2.3_9"));
159  QVERIFY(!spec.provides("MyPlugin", "2.2.3_10"));
160  QVERIFY(!spec.provides("MyPlugin", "2.2.4"));
161  QVERIFY(!spec.provides("MyPlugin", "2.3.11_1"));
162  QVERIFY(!spec.provides("MyPlugin", "2.3"));
163  QVERIFY(!spec.provides("MyPlugin", "3.0"));
164  QVERIFY(!spec.provides("MyPlugin", "1.9.9_99"));
165  QVERIFY(!spec.provides("MyPlugin", "1.9"));
166  QVERIFY(!spec.provides("MyPlugin", "0.9"));
167  QVERIFY(!spec.provides("MyPlugin", "1"));
168 
169  QVERIFY(spec.provides("myplugin", "2.2.3_9"));
170  QVERIFY(spec.provides("MyPlugin", "2.2.3_9"));
171  QVERIFY(spec.provides("MyPlugin", "2.2.3_8"));
172  QVERIFY(spec.provides("MyPlugin", "2.2.3"));
173  QVERIFY(spec.provides("MyPlugin", "2.2.2"));
174  QVERIFY(spec.provides("MyPlugin", "2.1.2_10"));
175  QVERIFY(spec.provides("MyPlugin", "2.0_10"));
176  QVERIFY(spec.provides("MyPlugin", "2"));
177 }
178 
179 void tst_PluginSpec::locationAndPath()
180 {
182  QVERIFY(spec.read("testspecs/simplespec.xml"));
183  QCOMPARE(spec.location, QDir::currentPath()+"/testspecs");
184  QCOMPARE(spec.filePath, QDir::currentPath()+"/testspecs/simplespec.xml");
185  QVERIFY(spec.read("testdir/../testspecs/simplespec.xml"));
186  QCOMPARE(spec.location, QDir::currentPath()+"/testspecs");
187  QCOMPARE(spec.filePath, QDir::currentPath()+"/testspecs/simplespec.xml");
188  QVERIFY(spec.read("testdir/spec.xml"));
189  QCOMPARE(spec.location, QDir::currentPath()+"/testdir");
190  QCOMPARE(spec.filePath, QDir::currentPath()+"/testdir/spec.xml");
191 }
192 
193 void tst_PluginSpec::resolveDependencies()
194 {
195  QSet<PluginSpec *> specs;
197  specs.insert(spec1);
199  spec1Priv->read("testdependencies/spec1.xml");
201  specs.insert(spec2);
202  Internal::PluginManagerPrivate::privateSpec(spec2)->read("testdependencies/spec2.xml");
204  specs.insert(spec3);
205  Internal::PluginManagerPrivate::privateSpec(spec3)->read("testdependencies/spec3.xml");
207  specs.insert(spec4);
209  spec4Priv->read("testdependencies/spec4.xml");
211  specs.insert(spec5);
212  Internal::PluginManagerPrivate::privateSpec(spec5)->read("testdependencies/spec5.xml");
213  QVERIFY(spec1Priv->resolveDependencies(specs));
214  QCOMPARE(spec1Priv->dependencySpecs.size(), 2);
215  QVERIFY(spec1Priv->dependencySpecs.contains(spec2));
216  QVERIFY(spec1Priv->dependencySpecs.contains(spec3));
217  QCOMPARE(spec1Priv->state, PluginSpec::Resolved);
218  QVERIFY(!spec4Priv->resolveDependencies(specs));
219  QVERIFY(spec4Priv->hasError);
220  QCOMPARE(spec4Priv->state, PluginSpec::Read);
221 }
222 
223 void tst_PluginSpec::loadLibrary()
224 {
227  PluginManager *manager = new PluginManager();
228  QVERIFY(spec->read("testplugin/testplugin.xml"));
229  QVERIFY(spec->resolveDependencies(QSet<PluginSpec *>()));
230  QVERIFY(spec->loadLibrary());
231  QVERIFY(qobject_cast<MyPlugin::MyPluginImpl*>(spec->plugin) != 0);
232  QCOMPARE(spec->state, PluginSpec::Loaded);
233  QVERIFY(!spec->hasError);
234  QCOMPARE(spec->plugin->pluginSpec(), ps);
235  delete manager;
236  delete ps;
237 }
238 
239 void tst_PluginSpec::initializePlugin()
240 {
243  QVERIFY(spec.read("testplugin/testplugin.xml"));
244  QVERIFY(spec.resolveDependencies(QSet<PluginSpec *>()));
245  QVERIFY(spec.loadLibrary());
246  impl = qobject_cast<MyPlugin::MyPluginImpl*>(spec.plugin);
247  QVERIFY(impl != 0);
248  QVERIFY(!impl->isInitialized());
249  QVERIFY(spec.initializePlugin());
250  QCOMPARE(spec.state, PluginSpec::Initialized);
251  QVERIFY(!spec.hasError);
252  QVERIFY(impl->isInitialized());
253 }
254 
255 void tst_PluginSpec::initializeExtensions()
256 {
259  QVERIFY(spec.read("testplugin/testplugin.xml"));
260  QVERIFY(spec.resolveDependencies(QSet<PluginSpec *>()));
261  QVERIFY(spec.loadLibrary());
262  impl = qobject_cast<MyPlugin::MyPluginImpl*>(spec.plugin);
263  QVERIFY(impl != 0);
264  QVERIFY(spec.initializePlugin());
265  QVERIFY(spec.initializeExtensions());
266  QCOMPARE(spec.state, PluginSpec::Running);
267  QVERIFY(!spec.hasError);
268  QVERIFY(impl->isExtensionsInitialized());
269 }
270 
271 QTEST_MAIN(tst_PluginSpec)
272 
273 #include "tst_pluginspec.moc"
Core plugin system that manages the plugins, their life cycle and their registered objects...
Definition: pluginmanager.h:53
static bool isValidVersion(const QString &version)
Definition: pluginspec.cpp:677
static PluginSpecPrivate * privateSpec(PluginSpec *spec)
bool read(const QString &fileName)
Definition: pluginspec.cpp:395
static int versionCompare(const QString &version1, const QString &version2)
Definition: pluginspec.cpp:686
bool resolveDependencies(const QList< PluginSpec * > &specs)
Definition: pluginspec.cpp:711
Contains the information of the plugins xml description file and information about the plugin's curre...
Definition: pluginspec.h:63
Struct that contains the name and required compatible version number of a plugin's dependency...
Definition: pluginspec.h:49
Definition: icore.h:39
PluginSpec * pluginSpec() const
Definition: iplugin.cpp:281