tests/benchmarks/serviceframework/tst_serviceframework.cpp
changeset 0 876b1a06bc25
equal deleted inserted replaced
-1:000000000000 0:876b1a06bc25
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2010 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 Qt Mobility Components.
       
     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 #include "qservicemanager.h"
       
    43 #include <QDebug>
       
    44 
       
    45 QTM_USE_NAMESPACE
       
    46 
       
    47 class tst_serviceframework : public QObject
       
    48 {
       
    49     Q_OBJECT
       
    50 
       
    51 private slots:
       
    52     void initTestCase();
       
    53 
       
    54     void tst_createTime();
       
    55     void tst_addService_data();
       
    56     void tst_addService();
       
    57 
       
    58     void tst_findServices();
       
    59 
       
    60     void tst_loadService_data();
       
    61     void tst_loadService();
       
    62 
       
    63     void tst_invalidLoad();
       
    64 
       
    65 private:
       
    66     QServiceManager *manager;
       
    67 
       
    68 };
       
    69 
       
    70 void tst_serviceframework::initTestCase()
       
    71 {
       
    72     manager = new QServiceManager;
       
    73     QStringList exampleXmlFiles;
       
    74     //exampleXmlFiles <<"voipdialerservice.xml" << "landlinedialerservice.xml";
       
    75     exampleXmlFiles << "bm_sampleservice.xml";
       
    76     foreach (const QString &fileName, exampleXmlFiles) {
       
    77         QString path = QCoreApplication::applicationDirPath() + "/plugins" + "/xmldata/" + fileName;
       
    78         //qDebug() << "Addning: " << path;
       
    79         manager->addService(path);
       
    80     }
       
    81 }
       
    82 
       
    83 void tst_serviceframework::tst_createTime()
       
    84 {
       
    85     QBENCHMARK {
       
    86         QServiceManager qsm;
       
    87     }    
       
    88 }
       
    89 
       
    90 void tst_serviceframework::tst_addService_data()
       
    91 {    
       
    92     QTest::addColumn<QString>("service");
       
    93 
       
    94     QStringList exampleXmlFiles;
       
    95     //exampleXmlFiles <<"voipdialerservice.xml" << "landlinedialerservice.xml";
       
    96     exampleXmlFiles << "bm_sampleservice.xml";
       
    97     foreach (const QString &fileName, exampleXmlFiles) {        
       
    98         QString path = QCoreApplication::applicationDirPath() + "/plugins" + "/xmldata/" + fileName;
       
    99         //qDebug() << "Addning: " << path;
       
   100         QTest::newRow(fileName.toAscii()) << path;
       
   101     }
       
   102 }
       
   103 
       
   104 void tst_serviceframework::tst_addService()
       
   105 {
       
   106     QServiceManager qsm;
       
   107     QFETCH(QString, service);
       
   108 
       
   109     QBENCHMARK {
       
   110         qsm.addService(service);
       
   111     }
       
   112 }
       
   113 
       
   114 Q_DECLARE_METATYPE ( QServiceInterfaceDescriptor )
       
   115 
       
   116 void tst_serviceframework::tst_loadService_data()
       
   117 {
       
   118     qRegisterMetaType<QServiceInterfaceDescriptor>("QServiceInterfaceDescriptor");
       
   119 
       
   120     QTest::addColumn<QString>("path");
       
   121     QTest::addColumn<QString>("service");
       
   122     QTest::addColumn<QServiceInterfaceDescriptor>("interface");    
       
   123 
       
   124     QStringList exampleXmlFiles;
       
   125     //exampleXmlFiles <<"voipdialerservice.xml" << "landlinedialerservice.xml";
       
   126     exampleXmlFiles << "bm_sampleservice.xml";
       
   127     foreach (const QString &fileName, exampleXmlFiles) {
       
   128         QServiceManager qsm;
       
   129         QString path = QCoreApplication::applicationDirPath() + "/plugins" + "/xmldata/" + fileName;
       
   130         //qDebug() << "Adding: " << path;
       
   131         qsm.addService(path);
       
   132         QStringList servicesList = qsm.findServices();
       
   133         foreach (QString service, servicesList) {
       
   134             //qDebug() << "Service: " << service;
       
   135             QList<QServiceInterfaceDescriptor> qlid = qsm.findInterfaces(service);
       
   136             while(!qlid.isEmpty()){
       
   137                 QServiceInterfaceDescriptor id = qlid.takeFirst();
       
   138                 QStringList name;
       
   139                 QString verM, verm;
       
   140                 verM.setNum(id.majorVersion(), 10);
       
   141                 verm.setNum(id.minorVersion(), 10);
       
   142                 name << "Service: " << service << " Interface: " << id.interfaceName() << " version: " << verM << "/" << verm;
       
   143                 QTest::newRow(name.join("").toAscii()) << path << service << id;
       
   144             }
       
   145         }
       
   146     }
       
   147 }
       
   148 
       
   149 void tst_serviceframework::tst_loadService()
       
   150 {
       
   151     QServiceManager qsm;
       
   152     QFETCH(QString, path);
       
   153     QFETCH(QString, service);
       
   154     QFETCH(QServiceInterfaceDescriptor, interface);    
       
   155 
       
   156     qsm.addService(path);
       
   157 
       
   158     QBENCHMARK {        
       
   159         QObject *o = qsm.loadInterface(interface);
       
   160         Q_UNUSED(o);
       
   161     }
       
   162 }
       
   163 
       
   164 
       
   165 void tst_serviceframework::tst_findServices()
       
   166 {
       
   167     QServiceManager qsm;
       
   168     QStringList s;
       
   169     QBENCHMARK {
       
   170         s = qsm.findServices();
       
   171     }    
       
   172 }
       
   173 
       
   174 void tst_serviceframework::tst_invalidLoad()
       
   175 {
       
   176     QServiceManager qsm;    
       
   177 
       
   178     QBENCHMARK {
       
   179         qsm.addService("invalid_filename_that_we_home_does_not_exist_aspasdm");
       
   180     }
       
   181 }
       
   182 
       
   183 
       
   184 
       
   185 QTEST_MAIN(tst_serviceframework)
       
   186 #include "tst_serviceframework.moc"