qtmobility/tests/benchmarks/qsysteminfo/tst_qsysteminfo.cpp
changeset 5 453da2cfceef
parent 1 2b40d63a9c3d
child 11 06b8e2af4411
equal deleted inserted replaced
4:90517678cc4f 5:453da2cfceef
    43 #include <QDebug>
    43 #include <QDebug>
    44 
    44 
    45 QTM_USE_NAMESPACE
    45 QTM_USE_NAMESPACE
    46 Q_DECLARE_METATYPE(QSystemInfo::Version);
    46 Q_DECLARE_METATYPE(QSystemInfo::Version);
    47 Q_DECLARE_METATYPE(QSystemInfo::Feature);
    47 Q_DECLARE_METATYPE(QSystemInfo::Feature);
       
    48 Q_DECLARE_METATYPE(QSystemNetworkInfo::NetworkStatus);
       
    49 Q_DECLARE_METATYPE(QSystemNetworkInfo::NetworkMode)
    48 
    50 
    49 class tst_QSystemInfo : public QObject
    51 class tst_QSystemInfo : public QObject
    50 {
    52 {
    51     Q_OBJECT
    53     Q_OBJECT
    52 
    54 
    61     void tst_versions_data();
    63     void tst_versions_data();
    62     void tst_versions();
    64     void tst_versions();
    63 
    65 
    64     void tst_hasFeatures_data();
    66     void tst_hasFeatures_data();
    65     void tst_hasFeatures();
    67     void tst_hasFeatures();
    66 
    68     
       
    69     void tst_networkinfo_mode_data();
       
    70     void tst_networkinfo_mode();
       
    71     
       
    72     void tst_networkinfo_misc_data();
       
    73     void tst_networkinfo_misc();
       
    74     
       
    75     void tst_screeninfo_data();
       
    76     void tst_screeninfo();
       
    77     
       
    78     void tst_storageinfo_data();
       
    79     void tst_storageinfo();
       
    80 
       
    81     void tst_deviceinfo_data();
       
    82     void tst_deviceinfo();
       
    83 
       
    84     void tst_screensaver_data();
       
    85     void tst_screensaver();
       
    86     
    67 };
    87 };
    68 
    88 
    69 void tst_QSystemInfo::initTestCase()
    89 void tst_QSystemInfo::initTestCase()
    70 {
    90 {
    71     qRegisterMetaType<QSystemInfo::Version>("QSystemInfo::Version");
    91     qRegisterMetaType<QSystemInfo::Version>("QSystemInfo::Version");
   107 
   127 
   108 }
   128 }
   109 
   129 
   110 void tst_QSystemInfo::tst_versions()
   130 void tst_QSystemInfo::tst_versions()
   111 {
   131 {
   112     QBENCHMARK {
   132   QFETCH(QSystemInfo::Version, version);
   113         QFETCH(QSystemInfo::Version, version);
   133   QFETCH(QString, parameter);
   114         QFETCH(QString, parameter);
   134   QSystemInfo si;
   115         QSystemInfo si;
   135     
       
   136     QBENCHMARK { 
   116         QString vers = si.version(version, parameter);
   137         QString vers = si.version(version, parameter);
   117     }
   138     }
   118 }
   139 }
   119 
   140 
   120 void tst_QSystemInfo::tst_hasFeatures_data()
   141 void tst_QSystemInfo::tst_hasFeatures_data()
   136     QTest::newRow("HapticsFeature") << QSystemInfo::HapticsFeature;
   157     QTest::newRow("HapticsFeature") << QSystemInfo::HapticsFeature;
   137 }
   158 }
   138 
   159 
   139 void tst_QSystemInfo::tst_hasFeatures()
   160 void tst_QSystemInfo::tst_hasFeatures()
   140 {
   161 {
   141     QBENCHMARK {
   162   QFETCH(QSystemInfo::Feature, feature);
   142         QFETCH(QSystemInfo::Feature, feature);
   163   QSystemInfo si;
   143         QSystemInfo si;        
   164   
       
   165     QBENCHMARK {        
   144         si.hasFeatureSupported(feature);
   166         si.hasFeatureSupported(feature);
   145 
   167 
   146     }
   168     }
       
   169 }
       
   170 
       
   171 void tst_QSystemInfo::tst_networkinfo_misc_data() {
       
   172   QTest::addColumn<QString>("feature");
       
   173   QTest::addColumn<int>("property");
       
   174   
       
   175   QSystemNetworkInfo obj;
       
   176   const QMetaObject* metaObject = obj.metaObject();
       
   177   QStringList methods;
       
   178   for(int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
       
   179     QString name = QString::fromLatin1(metaObject->property(i).name());
       
   180     QTest::newRow(name.toAscii()) << name << i;    
       
   181   }
       
   182 }
       
   183 
       
   184 void tst_QSystemInfo::tst_networkinfo_misc() {
       
   185   QFETCH(QString, feature);
       
   186   QFETCH(int, property);  
       
   187   
       
   188   QSystemNetworkInfo obj;
       
   189   const QMetaObject* metaObject = obj.metaObject();
       
   190   QMetaProperty mprop = metaObject->property(property);
       
   191   
       
   192   if(mprop.isReadable()){
       
   193     QBENCHMARK {
       
   194       mprop.read(&obj);
       
   195     }
       
   196   }  
       
   197   else {
       
   198     QString s("Failed to find readable property: " + QString::fromLatin1(mprop.name()));
       
   199     QFAIL(s.toAscii());
       
   200   }
       
   201 }
       
   202 
       
   203 
       
   204 void tst_QSystemInfo::tst_networkinfo_mode_data()
       
   205 
       
   206 {
       
   207   QTest::addColumn<QString>("feature");
       
   208   QTest::addColumn<QString>("name");
       
   209   QTest::addColumn<QSystemNetworkInfo::NetworkMode>("mode");
       
   210   
       
   211   
       
   212   QList<QPair<QString, QSystemNetworkInfo::NetworkMode> > modes;
       
   213    
       
   214   modes += qMakePair(QString("GsmMode"), QSystemNetworkInfo::GsmMode);
       
   215   modes += qMakePair(QString("CdmaMode"), QSystemNetworkInfo::CdmaMode);
       
   216   modes += qMakePair(QString("WcdmaMode"), QSystemNetworkInfo::WcdmaMode);
       
   217   modes += qMakePair(QString("WlanMode"), QSystemNetworkInfo::WlanMode);
       
   218   modes += qMakePair(QString("EthernetMode"), QSystemNetworkInfo::EthernetMode);
       
   219   modes += qMakePair(QString("BluetoothMode"), QSystemNetworkInfo::BluetoothMode);
       
   220   modes += qMakePair(QString("WimaxMode"), QSystemNetworkInfo::WimaxMode);
       
   221   
       
   222   QPair<QString, QSystemNetworkInfo::NetworkMode> mode;
       
   223   foreach(mode, modes){    
       
   224     QTest::newRow(QString("networkStatus-" + mode.first).toAscii()) << "networkStatus" << mode.first << mode.second;  
       
   225     QTest::newRow(QString("networkSignalStrength-" + mode.first).toAscii()) << "networkSignalStrength" << mode.first << mode.second;
       
   226     QTest::newRow(QString("macAddress-" + mode.first).toAscii()) << "macAddress" << mode.first << mode.second;
       
   227     QTest::newRow(QString("networkName-" + mode.first).toAscii()) << "networkName" << mode.first << mode.second;
       
   228     QTest::newRow(QString("interfaceForMode-" + mode.first).toAscii()) << "interfaceForMode" << mode.first << mode.second;
       
   229   }
       
   230 }
       
   231 
       
   232 void tst_QSystemInfo::tst_networkinfo_mode()
       
   233 {
       
   234   QFETCH(QString, feature);
       
   235   QFETCH(QString, name);
       
   236   QFETCH(QSystemNetworkInfo::NetworkMode, mode);
       
   237   
       
   238   QSystemNetworkInfo ni;
       
   239   
       
   240   if(feature == "networkStatus"){
       
   241     QSystemNetworkInfo::NetworkStatus s = QSystemNetworkInfo::UndefinedStatus;
       
   242     QBENCHMARK {
       
   243       s = ni.networkStatus(mode);
       
   244     }
       
   245     //qDebug() << "Status: " << s;
       
   246   }
       
   247   else if(feature == "networkSignalStrength") {
       
   248     QBENCHMARK {
       
   249       ni.networkSignalStrength(mode);
       
   250     }
       
   251   }
       
   252   else if(feature == "macAddress"){
       
   253     QBENCHMARK {
       
   254       ni.macAddress(mode);
       
   255     }
       
   256   }
       
   257   else if(feature == "networkName"){
       
   258     QBENCHMARK {
       
   259       ni.networkName(mode);
       
   260     }
       
   261   }
       
   262   else if(feature == "interfaceForMode") {
       
   263     QBENCHMARK {
       
   264       ni.interfaceForMode(mode);
       
   265     }
       
   266   }
       
   267 }
       
   268 
       
   269 void tst_QSystemInfo::tst_screeninfo_data(){ 
       
   270   QTest::addColumn<QString>("feature");
       
   271   
       
   272   QTest::newRow("construction") << "construction";
       
   273   QTest::newRow("displayBrightness") << "displayBrightness";
       
   274   QTest::newRow("colorDepth") << "colorDepth";
       
   275     
       
   276 }
       
   277 
       
   278 void tst_QSystemInfo::tst_screeninfo(){
       
   279   QFETCH(QString, feature);   
       
   280 
       
   281   if(feature == "construction"){
       
   282     QBENCHMARK {
       
   283       QSystemDeviceInfo di2;
       
   284     }
       
   285   }
       
   286   else if(feature == "displayBrightness"){
       
   287     QBENCHMARK {
       
   288       QSystemDisplayInfo::displayBrightness(0);// what screen shoiuld we pick?
       
   289     }
       
   290   }
       
   291   else if(feature == "colorDepth"){
       
   292     QBENCHMARK {
       
   293       QSystemDisplayInfo::colorDepth(0);
       
   294     }
       
   295   }
       
   296   else {    
       
   297     QFAIL("Unkown feature");
       
   298   }  
       
   299 }
       
   300 
       
   301 void tst_QSystemInfo::tst_storageinfo_data(){
       
   302   QTest::addColumn<QString>("feature");
       
   303   QTest::addColumn<QString>("drive");
       
   304   
       
   305   QString d;
       
   306   QStringList drives = QSystemStorageInfo::logicalDrives();
       
   307   
       
   308   QString f;
       
   309   QStringList features;
       
   310   
       
   311   features += "totalDiskSpace";
       
   312   features += "availableDiskSpace";
       
   313   features += "typeForDrive";
       
   314   
       
   315   foreach(d, drives){
       
   316     foreach(f, features){
       
   317       QString s = f + "_" + d;
       
   318       QTest::newRow(s.toAscii()) << f << d;
       
   319     }
       
   320   }
       
   321 }
       
   322 
       
   323 void tst_QSystemInfo::tst_storageinfo(){
       
   324   QFETCH(QString, feature);
       
   325   QFETCH(QString, drive);
       
   326   
       
   327   QSystemStorageInfo si;
       
   328   
       
   329   if(feature == "totalDiskSpace"){
       
   330    QBENCHMARK {
       
   331      si.totalDiskSpace(drive);
       
   332    }
       
   333   }
       
   334   else if(feature == "availableDiskSpace"){
       
   335     QBENCHMARK {
       
   336       si.availableDiskSpace(drive);
       
   337     }
       
   338     
       
   339   }
       
   340   else if(feature == "typeForDrive"){
       
   341     QBENCHMARK {
       
   342       si.typeForDrive(drive);
       
   343     }
       
   344   }
       
   345   else {
       
   346     QFAIL("Unkown feature");
       
   347   }
       
   348 }
       
   349 
       
   350 void tst_QSystemInfo::tst_deviceinfo_data() {
       
   351   QTest::addColumn<QString>("feature");
       
   352   QTest::addColumn<int>("property");
       
   353   
       
   354   QSystemDeviceInfo obj;
       
   355   const QMetaObject* metaObject = obj.metaObject();
       
   356   QStringList methods;
       
   357   for(int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
       
   358     QString name = QString::fromLatin1(metaObject->property(i).name());
       
   359     QTest::newRow(name.toAscii()) << name << i;       
       
   360   }
       
   361 }
       
   362 
       
   363 void tst_QSystemInfo::tst_deviceinfo() {
       
   364   QFETCH(QString, feature);
       
   365   QFETCH(int, property);
       
   366   
       
   367   QSystemDeviceInfo obj;
       
   368   const QMetaObject* metaObject = obj.metaObject();
       
   369   QMetaProperty mprop = metaObject->property(property);
       
   370   
       
   371   if(mprop.isReadable()){
       
   372     QBENCHMARK {
       
   373       mprop.read(&obj);
       
   374     }
       
   375   }  
       
   376 }
       
   377 
       
   378 void tst_QSystemInfo::tst_screensaver_data() {
       
   379   QTest::addColumn<QString>("feature");
       
   380   QTest::addColumn<int>("property");
       
   381   
       
   382   QSystemScreenSaver obj;
       
   383   const QMetaObject* metaObject = obj.metaObject();
       
   384   QStringList methods;
       
   385   for(int i = metaObject->propertyOffset(); i < metaObject->propertyCount(); ++i) {
       
   386     QString name = QString::fromLatin1(metaObject->property(i).name());
       
   387     QTest::newRow(name.toAscii()) << name << i;       
       
   388   }
       
   389 }
       
   390 
       
   391 void tst_QSystemInfo::tst_screensaver() {
       
   392   QFETCH(QString, feature);
       
   393   QFETCH(int, property);
       
   394   
       
   395   QSystemScreenSaver obj;
       
   396   const QMetaObject* metaObject = obj.metaObject();
       
   397   QMetaProperty mprop = metaObject->property(property);
       
   398   
       
   399   if(mprop.isReadable()){
       
   400     QBENCHMARK {
       
   401       mprop.read(&obj);
       
   402     }
       
   403   }  
   147 }
   404 }
   148 
   405 
   149 
   406 
   150 QTEST_MAIN(tst_QSystemInfo)
   407 QTEST_MAIN(tst_QSystemInfo)
   151 #include "tst_qsysteminfo.moc"
   408 #include "tst_qsysteminfo.moc"
       
   409