tests/benchmarks/qnetworkreply/tst_qnetworkreply.cpp
branchRCL_3
changeset 4 3b1da2848fc7
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 4:3b1da2848fc7
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the test suite of the Qt Toolkit.
     7 ** This file is part of the test suite of the Qt Toolkit.
     8 **
     8 **
   260         QTcpServer server;
   260         QTcpServer server;
   261         server.listen();
   261         server.listen();
   262         port = server.serverPort();
   262         port = server.serverPort();
   263         ready.release();
   263         ready.release();
   264 
   264 
   265         server.waitForNewConnection(-1);
   265         QVERIFY(server.waitForNewConnection(10*1000));
   266         client = server.nextPendingConnection();
   266         client = server.nextPendingConnection();
       
   267 
       
   268         // read lines until we read the empty line seperating HTTP request from HTTP request body
       
   269         do {
       
   270             if (client->canReadLine()) {
       
   271                 QString line = client->readLine();
       
   272                 if (line == "\n" || line == "\r\n")
       
   273                     break; // empty line
       
   274             }
       
   275             if (!client->waitForReadyRead(10*1000)) {
       
   276                 client->close();
       
   277                 return;
       
   278             }
       
   279         } while (client->state() == QAbstractSocket::ConnectedState);
       
   280 
   267         client->write("HTTP/1.0 200 OK\r\n");
   281         client->write("HTTP/1.0 200 OK\r\n");
   268         client->write("Content-length: 0\r\n");
   282         client->write("Content-length: 0\r\n");
   269         client->write("\r\n");
   283         client->write("\r\n");
   270         client->flush();
   284         client->flush();
   271 
   285 
   559 
   573 
   560       QTime time;
   574       QTime time;
   561       generator.start();
   575       generator.start();
   562       time.start();
   576       time.start();
   563       QTestEventLoop::instance().enterLoop(40);
   577       QTestEventLoop::instance().enterLoop(40);
       
   578       qint64 elapsed = time.elapsed();
       
   579       reader.exit();
       
   580       reader.wait();
       
   581       QVERIFY(reply->isFinished());
   564       QCOMPARE(reply->error(), QNetworkReply::NoError);
   582       QCOMPARE(reply->error(), QNetworkReply::NoError);
   565       QVERIFY(!QTestEventLoop::instance().timeout());
   583       QVERIFY(!QTestEventLoop::instance().timeout());
   566 
   584 
   567       qint64 elapsed = time.elapsed();
       
   568       qDebug() << "tst_QNetworkReply::httpUploadPerformance" << elapsed << "msec, "
   585       qDebug() << "tst_QNetworkReply::httpUploadPerformance" << elapsed << "msec, "
   569               << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec";
   586               << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec";
   570 
       
   571       reader.exit();
       
   572       reader.wait();
       
   573 }
   587 }
   574 
   588 
   575 
   589 
   576 void tst_qnetworkreply::performanceControlRate()
   590 void tst_qnetworkreply::performanceControlRate()
   577 {
   591 {