1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtSystems module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL21$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34//TESTED_COMPONENT=src/serviceframework
35
36#include <QtTest/QtTest>
37#include <QtCore>
38#define private public
39#define SERVICE_XML_GENERATOR
40#include <qserviceinterfacedescriptor.h>
41#include <private/qserviceinterfacedescriptor_p.h>
42#if !defined(Q_CC_MINGW)
43 #include "../../../../src/serviceframework/qserviceinterfacedescriptor.cpp"
44#endif
45#define IGNORE_SERVICEMETADATA_EXPORT
46#include "private/servicemetadata_p.h"
47#include "../../../../src/serviceframework/servicemetadata.cpp"
48
49QT_USE_NAMESPACE
50class ServiceMetadataTest: public QObject
51{
52 Q_OBJECT
53
54private slots:
55 void initTestCase();
56 void parseInvalidServiceXML_oldXml();
57 void parseValidServiceXML();
58 void parseInvalidServiceXML_data();
59 void parseInvalidServiceXML();
60 void noCapability();
61 void checkVersion_data();
62 void checkVersion();
63 void latestInterfaceVersion_data();
64 void latestInterfaceVersion();
65 void cleanupTestCase();
66
67private:
68 QDir dir;
69
70};
71void ServiceMetadataTest::initTestCase()
72{
73 const QString directory = QFINDTESTDATA("testdata");
74 QVERIFY2(!directory.isEmpty(), "Unable to locate 'testdata'.");
75 dir = QDir(directory);
76}
77
78void ServiceMetadataTest::cleanupTestCase()
79{
80}
81
82void ServiceMetadataTest::parseInvalidServiceXML_oldXml()
83{
84 ServiceMetaData parser(dir.absoluteFilePath(fileName: "ServiceTestOld.xml"));
85 QCOMPARE(parser.extractMetadata(), false);
86}
87
88void ServiceMetadataTest::parseValidServiceXML()
89{
90 ServiceMetaData parser(dir.absoluteFilePath(fileName: "ServiceTest.xml"));
91 QCOMPARE(parser.extractMetadata(),true);
92 const ServiceMetaDataResults data = parser.parseResults();
93 QCOMPARE(data.name, QString("TestService"));
94 QCOMPARE(data.description, QString("Test service description"));
95 QCOMPARE(data.location, QString("C:/TestData/testservice.dll"));
96
97 ServiceMetaData parserIPC(dir.absoluteFilePath(fileName: "ServiceTestIPC.xml"));
98 QCOMPARE(parserIPC.extractMetadata(),true);
99 const ServiceMetaDataResults dataIPC = parserIPC.parseResults();
100 QCOMPARE(dataIPC.name, QString("TestIPCService"));
101 QCOMPARE(dataIPC.description, QString("Test IPC service description"));
102 QCOMPARE(dataIPC.location, QString("test_service"));
103
104 QList<QServiceInterfaceDescriptor> allInterfaces = data.interfaces;
105 allInterfaces.append(t: dataIPC.interfaces);
106
107 QServiceInterfaceDescriptor aInterface = allInterfaces.at(i: 0);
108 QCOMPARE(aInterface.interfaceName(),QString("com.nokia.qt.tests.IDownloader"));
109 QCOMPARE(aInterface.majorVersion(), 1);
110 QCOMPARE(aInterface.minorVersion(), 4);
111 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().count() == 0);
112 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides download support"));
113 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::Plugin);
114
115 aInterface = allInterfaces.at(i: 1);
116 QCOMPARE(aInterface.interfaceName(),QString("com.nokia.qt.tests.ILocation"));
117 QCOMPARE(aInterface.majorVersion(), 1);
118 QCOMPARE(aInterface.minorVersion(), 4);
119 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().count() == 0);
120 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides location support"));
121 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::Plugin);
122
123 aInterface = allInterfaces.at(i: 2);
124 QCOMPARE(aInterface.interfaceName(),QString("com.nokia.qt.tests.ISysInfo"));
125 QCOMPARE(aInterface.majorVersion(), 2);
126 QCOMPARE(aInterface.minorVersion(), 3);
127 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().count() == 1);
128 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().contains("ReadUserData"));
129 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides system information support"));
130 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::Plugin);
131
132 aInterface = allInterfaces.at(i: 3);
133 QCOMPARE(aInterface.interfaceName(),QString("com.nokia.qt.tests.ISendMessage"));
134 QCOMPARE(aInterface.majorVersion(), 3);
135 QCOMPARE(aInterface.minorVersion(), 0);
136 QStringList capabilities = aInterface.attribute(which: QServiceInterfaceDescriptor::Capabilities).toStringList();
137 QVERIFY(capabilities.count() == 2);
138 QVERIFY(capabilities.contains("ReadUserData"));
139 QVERIFY(capabilities.contains("WriteUserData"));
140 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides message sending support"));
141 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::Plugin);
142
143 aInterface = allInterfaces.at(i: 4);
144 QCOMPARE(aInterface.interfaceName(), QString("com.nokia.qt.tests.IReceiveMessage"));
145 QCOMPARE(aInterface.majorVersion(), 1);
146 QCOMPARE(aInterface.minorVersion(), 1);
147 capabilities = aInterface.attribute(which: QServiceInterfaceDescriptor::Capabilities).toStringList();
148 QVERIFY(capabilities.count() == 3);
149 QVERIFY(capabilities.contains("ReadUserData"));
150 QVERIFY(capabilities.contains("WriteUserData"));
151 QVERIFY(capabilities.contains("ExecUserData"));
152 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides message receiving support"));
153 QCOMPARE(aInterface.customAttribute("key1"), QString("value1"));
154 QCOMPARE(aInterface.customAttribute("key2"), QString("value2"));
155 QCOMPARE(aInterface.customAttribute("key3"), QString(""));
156 QCOMPARE(aInterface.customAttribute("key4"), QString());
157 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::Plugin);
158
159 aInterface = allInterfaces.at(i: 5);
160 QCOMPARE(aInterface.interfaceName(),QString("com.nokia.qt.tests.IDownloader"));
161 QCOMPARE(aInterface.majorVersion(), 1);
162 QCOMPARE(aInterface.minorVersion(), 4);
163 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().count() == 0);
164 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides download support"));
165 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::InterProcess);
166
167 aInterface = allInterfaces.at(i: 6);
168 QCOMPARE(aInterface.interfaceName(),QString("com.nokia.qt.tests.ILocation"));
169 QCOMPARE(aInterface.majorVersion(), 1);
170 QCOMPARE(aInterface.minorVersion(), 4);
171 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().count() == 0);
172 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides location support"));
173 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::InterProcess);
174
175 aInterface = allInterfaces.at(i: 7);
176 QCOMPARE(aInterface.interfaceName(),QString("com.nokia.qt.tests.ISysInfo"));
177 QCOMPARE(aInterface.majorVersion(), 2);
178 QCOMPARE(aInterface.minorVersion(), 3);
179 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().count() == 1);
180 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::Capabilities).toStringList().contains("ReadUserData"));
181 QCOMPARE(aInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(), QString("Interface that provides system information support"));
182 QVERIFY(aInterface.attribute(QServiceInterfaceDescriptor::ServiceType) == QService::InterProcess);
183
184 ServiceMetaData parser1(dir.absoluteFilePath(fileName: "WrongOrder.xml"));
185 QCOMPARE(parser1.extractMetadata(),true);
186 QList<QServiceInterfaceDescriptor> allInterfacesWrongOrder = parser1.parseResults().interfaces;
187 foreach(const QServiceInterfaceDescriptor d, allInterfacesWrongOrder) {
188 QCOMPARE(d.serviceName(), QString("ovi"));
189 QCOMPARE(d.attribute(QServiceInterfaceDescriptor::Location).toString(), QString("C:/Nokia/ovi.dll"));
190 QCOMPARE(d.attribute(QServiceInterfaceDescriptor::ServiceDescription).toString(), QString("Ovi Services"));
191 }
192}
193
194void ServiceMetadataTest::parseInvalidServiceXML_data()
195{
196 QTest::addColumn<QString>(name: "fileName");
197 QTest::addColumn<int>(name: "expectedError");
198
199 QTest::newRow(dataTag: "no such file") << "!#@!CSC" << (int)ServiceMetaData::SFW_ERROR_UNABLE_TO_OPEN_FILE;
200
201 QTest::newRow(dataTag: "Test1.xml") << "Test1.xml" << (int)ServiceMetaData::SFW_ERROR_INVALID_XML_FILE;
202 QTest::newRow(dataTag: "Test2.xml") << "Test2.xml" << (int)ServiceMetaData::SFW_ERROR_NO_SERVICE;
203 QTest::newRow(dataTag: "Test3.xml") << "Test3.xml" << (int)ServiceMetaData::SFW_ERROR_PARSE_SERVICE;
204 QTest::newRow(dataTag: "Test4.xml") << "Test4.xml" << (int)ServiceMetaData::SFW_ERROR_NO_INTERFACE_VERSION;
205 QTest::newRow(dataTag: "Test5.xml") << "Test5.xml" << (int)ServiceMetaData::SFW_ERROR_NO_SERVICE_PATH;
206 QTest::newRow(dataTag: "Test7.xml") << "Test7.xml" << (int)ServiceMetaData::SFW_ERROR_PARSE_SERVICE;
207 QTest::newRow(dataTag: "Test8.xml") << "Test8.xml" << (int)ServiceMetaData::SFW_ERROR_PARSE_INTERFACE;
208 QTest::newRow(dataTag: "Test9.xml") << "Test9.xml" << (int)ServiceMetaData::SFW_ERROR_PARSE_SERVICE; ///check error code
209 QTest::newRow(dataTag: "Test10.xml") << "Test10.xml" << (int)ServiceMetaData::SFW_ERROR_NO_SERVICE_INTERFACE;
210 QTest::newRow(dataTag: "Test11.xml") << "Test11.xml" << (int)ServiceMetaData::SFW_ERROR_NO_INTERFACE_NAME;
211 QTest::newRow(dataTag: "Test12.xml") << "Test12.xml" << (int)ServiceMetaData::SFW_ERROR_NO_SERVICE_PATH;
212 //QTest::newRow("Test8.xml") << "Test8.xml" << (int)ServiceMetaData::SFW_ERROR_NO_INTERFACE_NAME;
213
214 QStringList badVersionXml;
215 badVersionXml << "Test14.xml" << "Test15.xml" << "Test17.xml" << "Test18.xml";
216 for (int i=0; i<badVersionXml.count(); i++)
217 QTest::newRow(qPrintable(badVersionXml[i])) << badVersionXml[i] << (int)ServiceMetaData::SFW_ERROR_INVALID_VERSION;
218
219 QTest::newRow(dataTag: "empty interface name") << "emptyInterfaceName.xml" << (int)ServiceMetaData::SFW_ERROR_NO_INTERFACE_NAME;
220 QTest::newRow(dataTag: "empty service name") << "emptyServiceName.xml" << (int)ServiceMetaData::SFW_ERROR_NO_SERVICE_NAME;
221 QTest::newRow(dataTag: "empty version") << "emptyVersion.xml" << (int)ServiceMetaData::SFW_ERROR_NO_INTERFACE_VERSION;
222 QTest::newRow(dataTag: "duplicated interface A") << "Test13.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_INTERFACE;
223 QTest::newRow(dataTag: "duplicated interface B") << "Test19.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_INTERFACE;
224 QTest::newRow(dataTag: "duplicated service tag") << "DuplicatedServiceTag.xml" << (int)ServiceMetaData::SFW_ERROR_INVALID_XML_FILE;
225
226 QTest::newRow(dataTag: "Test20.xml") << "Test20.xml" << (int)ServiceMetaData::SFW_ERROR_NO_SERVICE_NAME;
227 QTest::newRow(dataTag: "Test21.xml") << "Test21.xml" << (int)ServiceMetaData::SFW_ERROR_NO_SERVICE_INTERFACE;
228 QTest::newRow(dataTag: "Test22.xml") << "Test22.xml" << (int)ServiceMetaData::SFW_ERROR_NO_INTERFACE_NAME;
229 //duplicated service name tag
230 QTest::newRow(dataTag: "Test23.xml") << "Test23.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_TAG;
231 //duplicated service description tag
232 QTest::newRow(dataTag: "Test24.xml") << "Test24.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_TAG;
233 //duplicated service filepath tag
234 QTest::newRow(dataTag: "Test25.xml") << "Test25.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_TAG;
235 //duplicated interface name tag
236 QTest::newRow(dataTag: "Test26.xml") << "Test26.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_TAG;
237 //duplicated interface version tag
238 QTest::newRow(dataTag: "Test27.xml") << "Test27.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_TAG;
239 //duplicated interface description tag
240 QTest::newRow(dataTag: "Test28.xml") << "Test28.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_TAG;
241 //duplicated interface capabilities tag
242 QTest::newRow(dataTag: "Test29.xml") << "Test29.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_TAG;
243 //missing key attribute for custom property tag
244 QTest::newRow(dataTag: "Test30.xml") << "Test30.xml" << (int)ServiceMetaData::SFW_ERROR_INVALID_CUSTOM_TAG;
245 //empty key attribute for custom property tag
246 QTest::newRow(dataTag: "Test31.xml") << "Test31.xml" << (int)ServiceMetaData::SFW_ERROR_INVALID_CUSTOM_TAG;
247 //same key exists twice
248 QTest::newRow(dataTag: "Test32.xml") << "Test32.xml" << (int)ServiceMetaData::SFW_ERROR_DUPLICATED_CUSTOM_KEY;
249 //multiple definitions of the service type
250 QTest::newRow(dataTag: "Test33.xml") << "Test33.xml" << (int)ServiceMetaData::SFW_ERROR_MULTIPLE_SERVICE_TYPES;
251 //invalid filepath from ipc service type prefix
252 QTest::newRow(dataTag: "Test34.xml") << "Test34.xml" << (int)ServiceMetaData::SFW_ERROR_INVALID_FILEPATH;
253 //invalid version in service version tag
254 QTest::newRow(dataTag: "Test35.xml") << "Test35.xml" << (int)ServiceMetaData::SFW_ERROR_INVALID_XML_VERSION;
255 //invalid missing version attribute in service version tag
256 QTest::newRow(dataTag: "Test36.xml") << "Test36.xml" << (int)ServiceMetaData::SFW_ERROR_INVALID_XML_VERSION;
257 //unsupported version attribute in service version tag
258 QTest::newRow(dataTag: "Test37.xml") << "Test37.xml" << (int)ServiceMetaData::SFW_ERROR_UNSUPPORTED_XML_VERSION;
259 //unsupported version attribute in service version tag
260 QTest::newRow(dataTag: "Test38.xml") << "Test38.xml" << (int)ServiceMetaData::SFW_ERROR_UNSUPPORTED_IPC;
261}
262
263void ServiceMetadataTest::parseInvalidServiceXML()
264{
265 QFETCH(QString, fileName);
266 QFETCH(int, expectedError);
267
268 ServiceMetaData parser(dir.absoluteFilePath(fileName));
269 QVERIFY(!parser.extractMetadata());
270 QCOMPARE(parser.getLatestError(), expectedError);
271}
272
273void ServiceMetadataTest::noCapability()
274{
275 ServiceMetaData parser(dir.absoluteFilePath(fileName: "Test6.xml"));
276 QVERIFY(parser.extractMetadata());
277}
278
279void ServiceMetadataTest::checkVersion_data()
280{
281 QTest::addColumn<QString>(name: "version");
282 QTest::addColumn<bool>(name: "result");
283 QTest::addColumn<int>(name: "major");
284 QTest::addColumn<int>(name: "minor");
285
286 QTest::newRow(dataTag: "checkVersion_data():Invalid 1") << "" << false << -1 << -1;
287 QTest::newRow(dataTag: "checkVersion_data():Invalid 2") << "0.3" << false << -1 << -1;
288 QTest::newRow(dataTag: "checkVersion_data():Invalid 3") << "01.3" << false << -1 << -1;
289 QTest::newRow(dataTag: "checkVersion_data():Invalid 4") << "1.03" << false << -1 << -1;
290 QTest::newRow(dataTag: "checkVersion_data():Invalid 5") << "x.y" << false << -1 << -1;
291 QTest::newRow(dataTag: "checkVersion_data():Invalid 6") << "23" << false << -1 << -1;
292 QTest::newRow(dataTag: "checkVersion_data():Invalid 7") << "sdfsfs" << false << -1 << -1;
293 QTest::newRow(dataTag: "checkVersion_data():Invalid 8") << "%#5346" << false << -1 << -1;
294 QTest::newRow(dataTag: "checkVersion_data():Invalid 9") << ".66" << false << -1 << -1;
295 QTest::newRow(dataTag: "checkVersion_data():Invalid 10") << "1.3.4" << false << -1 << -1;
296 QTest::newRow(dataTag: "checkVersion_data():Invalid 11") << "1.a" << false << -1 << -1;
297 QTest::newRow(dataTag: "checkVersion_data():Invalid 12") << "b.1" << false << -1 << -1;
298 QTest::newRow(dataTag: "checkVersion_data():Invalid 13") << "3." << false << -1 << -1;
299 QTest::newRow(dataTag: "checkVersion_data():Invalid 14") << "-1" << false << -1 << -1;
300 QTest::newRow(dataTag: "checkVersion_data():Invalid 15") << "0.0" << false << -1 << -1;
301 QTest::newRow(dataTag: "checkVersion_data():Invalid 16") << ".x" << false << -1 << -1;
302 QTest::newRow(dataTag: "checkVersion_data():Invalid 17") << "x." << false << -1 << -1;
303 QTest::newRow(dataTag: "checkVersion_data():Invalid 18") << "1. 0" << false << -1 << -1;
304 QTest::newRow(dataTag: "checkVersion_data():Invalid 19") << "1 .0" << false << -1 << -1;
305 QTest::newRow(dataTag: "checkVersion_data():Invalid 20") << "1 0" << false << -1 << -1;
306 QTest::newRow(dataTag: "checkVersion_data():Invalid 21") << "1 . 0" << false << -1 << -1;
307 QTest::newRow(dataTag: "checkVersion_data():Invalid 22") << " 1.5" << false << -1 << -1;
308 QTest::newRow(dataTag: "checkVersion_data():Invalid 23") << "1.5 " << false << -1 << -1;
309 QTest::newRow(dataTag: "checkVersion_data():Invalid 24") << " 1.5 " << false << -1 << -1;
310 QTest::newRow(dataTag: "checkVersion_data():Invalid 25") << "1.5 1.6" << false << -1 << -1;
311 QTest::newRow(dataTag: "checkVersion_data():Invalid 26") << "-1.0" << false << -1 << -1;
312 QTest::newRow(dataTag: "checkVersion_data():Invalid 27") << "1.-1" << false << -1 << -1;
313 QTest::newRow(dataTag: "checkVersion_data():Invalid 28") << "-5.-1" << false << -1 << -1;
314 QTest::newRow(dataTag: "checkVersion_data():Invalid 29") << "4,8" << false << -1 << -1;
315 QTest::newRow(dataTag: "checkVersion_data():Invalid 30") << " " << false << -1 << -1;
316 QTest::newRow(dataTag: "checkVersion_data():Invalid 31") << "1.9b" << false << -1 << -1;
317
318 QTest::newRow(dataTag: "checkVersion_data():Valid 1") << "1.0" << true << 1 << 0;
319 QTest::newRow(dataTag: "checkVersion_data():Valid 2") << "1.00" << true << 1 << 0;
320 QTest::newRow(dataTag: "checkVersion_data():Valid 3") << "99.99" << true << 99 << 99;
321 QTest::newRow(dataTag: "checkVersion_data():Valid 4") << "2.3" << true << 2 << 3;
322 QTest::newRow(dataTag: "checkVersion_data():Valid 5") << "10.3" << true << 10 << 3;
323 QTest::newRow(dataTag: "checkVersion_data():Valid 6") << "5.10" << true << 5 << 10;
324 QTest::newRow(dataTag: "checkVersion_data():Valid 7") << "10.10" << true << 10 << 10;
325}
326
327void ServiceMetadataTest::checkVersion()
328{
329 QFETCH(QString, version);
330 QFETCH(bool, result);
331 QFETCH(int, major);
332 QFETCH(int, minor);
333
334 ServiceMetaData parser(dir.absoluteFilePath(fileName: "ServiceTest.xml"));
335 QCOMPARE(parser.checkVersion(version), result);
336 int majorVer;
337 int minorVer;
338 parser.transformVersion(version, major: &majorVer, minor: &minorVer);
339 QCOMPARE(majorVer, major);
340 QCOMPARE(minorVer, minor);
341}
342
343void ServiceMetadataTest::latestInterfaceVersion_data()
344{
345 QTest::addColumn<QString>(name: "fileName");
346 QTest::addColumn<int>(name: "major");
347 QTest::addColumn<int>(name: "minor");
348
349 //cases 1-3 contains services with more than one interface
350 QTest::newRow(dataTag: "latestVersion_data() 1") << "latestVersion.xml" << 2 << 1; //latest version in middle
351 QTest::newRow(dataTag: "latestVersion_data() 2") << "latestVersion2.xml" << 3 << 0; //latest version at end
352 QTest::newRow(dataTag: "latestVersion_data() 3") << "latestVersion3.xml" << 5 << 7; //latest version at start
353 QTest::newRow(dataTag: "latestVersion_data() 4") << "latestVersion4.xml" << 1 << 7; //only one version
354
355}
356
357void ServiceMetadataTest::latestInterfaceVersion()
358{
359 QFETCH(QString, fileName);
360 QFETCH(int, major);
361 QFETCH(int, minor);
362
363 ServiceMetaData parser(dir.absoluteFilePath(fileName));
364 QCOMPARE(parser.extractMetadata(), true);
365 QServiceInterfaceDescriptor serviceInterface = parser.latestInterfaceVersion(interfaceName: "com.nokia.service.contacts");
366 QCOMPARE(serviceInterface.majorVersion(), major);
367 QCOMPARE(serviceInterface.minorVersion(), minor);
368 QCOMPARE(serviceInterface.attribute(QServiceInterfaceDescriptor::InterfaceDescription).toString(),
369 QString("Contacts management service")); //make sure we're getting the right interface
370}
371
372QTEST_MAIN(ServiceMetadataTest)
373#include "tst_servicemetadata.moc"
374

source code of qtsystems/tests/auto/serviceframework/qservicemetadata/tst_servicemetadata.cpp