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