2022-05-10 10:06:48 +00:00
|
|
|
// Copyright (C) 2020 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2011-04-27 10:05:43 +00:00
|
|
|
// This file contains benchmarks for QNetworkReply functions.
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
#include <qtest.h>
|
2020-11-26 16:31:50 +00:00
|
|
|
#include <QTest>
|
2023-01-17 19:07:18 +00:00
|
|
|
#include <QtTest/qtesteventloop.h>
|
2011-04-27 10:05:43 +00:00
|
|
|
#include <QtNetwork/qnetworkreply.h>
|
|
|
|
#include <QtNetwork/qnetworkrequest.h>
|
|
|
|
#include <QtNetwork/qnetworkaccessmanager.h>
|
2020-07-23 11:54:47 +00:00
|
|
|
#include <QtCore/QElapsedTimer>
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
class tst_qhttpnetworkconnection : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private slots:
|
|
|
|
void bigRemoteFile();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2013-07-12 08:47:58 +00:00
|
|
|
const char urlC[] = "http://download.qt-project.org/official_releases/online_installers/qt-linux-opensource-1.4.0-x86-online.run";
|
|
|
|
|
2011-04-27 10:05:43 +00:00
|
|
|
void tst_qhttpnetworkconnection::bigRemoteFile()
|
|
|
|
{
|
|
|
|
QNetworkAccessManager manager;
|
|
|
|
qint64 size;
|
2020-07-23 11:54:47 +00:00
|
|
|
QElapsedTimer t;
|
2013-07-12 08:47:58 +00:00
|
|
|
QNetworkRequest request(QUrl(QString::fromLatin1(urlC)));
|
2011-04-27 10:05:43 +00:00
|
|
|
QNetworkReply* reply = manager.get(request);
|
|
|
|
connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection);
|
2013-07-12 08:47:58 +00:00
|
|
|
qDebug() << "Starting download" << urlC;
|
2011-04-27 10:05:43 +00:00
|
|
|
t.start();
|
|
|
|
QTestEventLoop::instance().enterLoop(50);
|
|
|
|
QVERIFY(!QTestEventLoop::instance().timeout());
|
|
|
|
size = reply->size();
|
|
|
|
delete reply;
|
2019-11-11 13:03:37 +00:00
|
|
|
qDebug() << "Finished!" << Qt::endl;
|
2011-04-27 10:05:43 +00:00
|
|
|
qDebug() << "Time:" << t.elapsed() << "msec";
|
|
|
|
qDebug() << "Bytes:" << size;
|
2012-03-27 10:43:37 +00:00
|
|
|
qDebug() << "Speed:" << (size / qreal(1024)) / (t.elapsed() / qreal(1000)) << "KB/sec";
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QTEST_MAIN(tst_qhttpnetworkconnection)
|
|
|
|
|
|
|
|
#include "main.moc"
|