tests/benchmarks/network/kernel/qhostinfo/main.cpp
changeset 19 fcece45ef507
parent 18 2f34d5167611
equal deleted inserted replaced
18:2f34d5167611 19:fcece45ef507
    46 #include <QString>
    46 #include <QString>
    47 
    47 
    48 #include <qtest.h>
    48 #include <qtest.h>
    49 #include <qtesteventloop.h>
    49 #include <qtesteventloop.h>
    50 
    50 
       
    51 #include "private/qhostinfo_p.h"
       
    52 
    51 class tst_qhostinfo : public QObject
    53 class tst_qhostinfo : public QObject
    52 {
    54 {
    53     Q_OBJECT
    55     Q_OBJECT
       
    56 public slots:
       
    57     void init();
    54 private slots:
    58 private slots:
       
    59     void lookupSpeed_data();
    55     void lookupSpeed();
    60     void lookupSpeed();
    56 };
    61 };
    57 
    62 
    58 class SignalReceiver : public QObject
    63 class SignalReceiver : public QObject
    59 {
    64 {
    68         if (receiveCount == neededReceiveCount)
    73         if (receiveCount == neededReceiveCount)
    69             QTestEventLoop::instance().exitLoop();
    74             QTestEventLoop::instance().exitLoop();
    70     }
    75     }
    71 };
    76 };
    72 
    77 
       
    78 void tst_qhostinfo::init()
       
    79 {
       
    80     // delete the cache so inidividual testcase results are independant from each other
       
    81     qt_qhostinfo_clear_cache();
       
    82 }
       
    83 
       
    84 void tst_qhostinfo::lookupSpeed_data()
       
    85 {
       
    86     QTest::addColumn<bool>("cache");
       
    87     QTest::newRow("WithCache") << true;
       
    88     QTest::newRow("WithoutCache") << false;
       
    89 }
       
    90 
    73 void tst_qhostinfo::lookupSpeed()
    91 void tst_qhostinfo::lookupSpeed()
    74 {
    92 {
       
    93     QFETCH(bool, cache);
       
    94     qt_qhostinfo_enable_cache(cache);
       
    95 
    75     QStringList hostnameList;
    96     QStringList hostnameList;
    76     hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no"
    97     hostnameList << "www.ovi.com" << "www.nokia.com" << "qt.nokia.com" << "www.trolltech.com" << "troll.no"
    77             << "www.qtcentre.org" << "forum.nokia.com" << "www.forum.nokia.com" << "wiki.forum.nokia.com"
    98             << "www.qtcentre.org" << "forum.nokia.com" << "www.forum.nokia.com" << "wiki.forum.nokia.com"
    78             << "www.nokia.no" << "nokia.de" << "127.0.0.1" << "----";
    99             << "www.nokia.no" << "nokia.de" << "127.0.0.1" << "----";
    79     // also add some duplicates:
   100     // also add some duplicates:
    80     hostnameList << "www.nokia.com" << "127.0.0.1" << "www.trolltech.com";
   101     hostnameList << "www.nokia.com" << "127.0.0.1" << "www.trolltech.com";
       
   102     // and some more
       
   103     hostnameList << hostnameList;
       
   104 
    81     const int COUNT = hostnameList.size();
   105     const int COUNT = hostnameList.size();
    82 
   106 
    83     SignalReceiver receiver(COUNT);
   107     SignalReceiver receiver(COUNT);
    84 
   108 
    85     QBENCHMARK {
   109     QBENCHMARK {