0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 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 test suite of the Qt Toolkit.
|
|
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 <QDebug>
|
|
42 |
#include <qtest.h>
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <QtNetwork/qnetworkreply.h>
|
|
45 |
#include <QtNetwork/qnetworkrequest.h>
|
|
46 |
#include <QtNetwork/qnetworkaccessmanager.h>
|
|
47 |
#include <QtCore/QTemporaryFile>
|
|
48 |
#include <QtCore/QFile>
|
|
49 |
#include "../../auto/network-settings.h"
|
|
50 |
|
|
51 |
class qfile_vs_qnetworkaccessmanager : public QObject
|
|
52 |
{
|
|
53 |
Q_OBJECT
|
|
54 |
// do not use on symbian.. 100 MB is too large..
|
|
55 |
// but.. this is a manual test anyway, so :)
|
|
56 |
protected:
|
|
57 |
void qnamFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request);
|
|
58 |
void qfileFileRead_iteration();
|
|
59 |
static const int iterations = 10;
|
|
60 |
|
|
61 |
private slots:
|
|
62 |
void qnamFileRead();
|
|
63 |
void qfileFileRead();
|
|
64 |
|
|
65 |
void initTestCase();
|
|
66 |
void cleanupTestCase();
|
|
67 |
|
|
68 |
public:
|
|
69 |
qint64 size;
|
|
70 |
QTemporaryFile testFile;
|
|
71 |
|
|
72 |
qfile_vs_qnetworkaccessmanager() : QObject(), size(0) {};
|
|
73 |
};
|
|
74 |
|
|
75 |
void qfile_vs_qnetworkaccessmanager::initTestCase()
|
|
76 |
{
|
|
77 |
testFile.open();
|
|
78 |
QByteArray qba(1*1024*1024, 'x'); // 1 MB
|
|
79 |
for (int i = 0; i < 100; i++) {
|
|
80 |
testFile.write(qba);
|
|
81 |
testFile.flush();
|
|
82 |
size += qba.size();
|
|
83 |
} // 100 MB
|
|
84 |
testFile.reset();
|
|
85 |
}
|
|
86 |
|
|
87 |
void qfile_vs_qnetworkaccessmanager::cleanupTestCase()
|
|
88 |
{
|
|
89 |
|
|
90 |
}
|
|
91 |
|
|
92 |
void qfile_vs_qnetworkaccessmanager::qnamFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request)
|
|
93 |
{
|
|
94 |
QNetworkReply* reply = manager.get(request);
|
|
95 |
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
|
96 |
QTestEventLoop::instance().enterLoop(10);
|
|
97 |
QVERIFY(!QTestEventLoop::instance().timeout());
|
|
98 |
QByteArray qba = reply->readAll();
|
|
99 |
delete reply;
|
|
100 |
}
|
|
101 |
|
|
102 |
void qfile_vs_qnetworkaccessmanager::qnamFileRead()
|
|
103 |
{
|
|
104 |
QNetworkAccessManager manager;
|
|
105 |
QTime t;
|
|
106 |
QNetworkRequest request(QUrl(testFile.fileName()));
|
|
107 |
|
|
108 |
// do 3 dry runs for cache warmup
|
|
109 |
qnamFileRead_iteration(manager, request);
|
|
110 |
qnamFileRead_iteration(manager, request);
|
|
111 |
qnamFileRead_iteration(manager, request);
|
|
112 |
|
|
113 |
t.start();
|
|
114 |
// 10 real runs
|
|
115 |
QBENCHMARK_ONCE {
|
|
116 |
for (int i = 0; i < iterations; i++) {
|
|
117 |
qnamFileRead_iteration(manager, request);
|
|
118 |
}
|
|
119 |
}
|
|
120 |
|
|
121 |
qint64 elapsed = t.elapsed();
|
|
122 |
qDebug() << endl << "Finished!";
|
|
123 |
qDebug() << "Bytes:" << size;
|
|
124 |
qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec";
|
|
125 |
}
|
|
126 |
|
|
127 |
void qfile_vs_qnetworkaccessmanager::qfileFileRead_iteration()
|
|
128 |
{
|
|
129 |
testFile.reset();
|
|
130 |
QByteArray qba = testFile.readAll();
|
|
131 |
}
|
|
132 |
|
|
133 |
void qfile_vs_qnetworkaccessmanager::qfileFileRead()
|
|
134 |
{
|
|
135 |
QTime t;
|
|
136 |
|
|
137 |
// do 3 dry runs for cache warmup
|
|
138 |
qfileFileRead_iteration();
|
|
139 |
qfileFileRead_iteration();
|
|
140 |
qfileFileRead_iteration();
|
|
141 |
|
|
142 |
t.start();
|
|
143 |
// 10 real runs
|
|
144 |
QBENCHMARK_ONCE {
|
|
145 |
for (int i = 0; i < iterations; i++) {
|
|
146 |
qfileFileRead_iteration();
|
|
147 |
}
|
|
148 |
}
|
|
149 |
|
|
150 |
qint64 elapsed = t.elapsed();
|
|
151 |
qDebug() << endl << "Finished!";
|
|
152 |
qDebug() << "Bytes:" << size;
|
|
153 |
qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec";
|
|
154 |
}
|
|
155 |
|
|
156 |
QTEST_MAIN(qfile_vs_qnetworkaccessmanager)
|
|
157 |
|
|
158 |
#include "main.moc"
|