Expand the test

This commit is contained in:
Dale Glass 2024-06-03 20:55:38 +02:00
parent 62cd9c64c1
commit 57fcc378bf
2 changed files with 77 additions and 10 deletions

View file

@ -2,9 +2,8 @@
// PacketTests.cpp
// tests/networking/src
//
// Created by Stephen Birarda on 07/14/15.
// Copyright 2015 High Fidelity, Inc.
// Copyright 2021 Vircadia contributors.
// Created by Dale Glass on 02/06/2024
// Copyright 2024 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
@ -17,6 +16,25 @@
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
#include <QHostInfo>
#include <QTcpSocket>
#include <QSslSocket>
#include <QSslCipher>
/**
* @brief Test basic Qt networking functionality
*
* This test was created to test a problem found with the Conan PR.
* Possibly some sort of library trouble.
*
* Normally there's no reason why this should go wrong, so it's mostly
* a test of that Qt is deployed and working properly.
*
*/
const QUrl HTTP_URL("http://ping.archlinux.org/");
const QUrl HTTPS_URL("https://ping.archlinux.org/");
const QString TCP_HOST("ping.archlinux.org");
const QString SSL_HOST("ping.archlinux.org");
@ -27,11 +45,50 @@ void QtNetworkTests::initTestCase() {
qRegisterMetaType<QNetworkReply*>();
}
void QtNetworkTests::tcpSocket() {
QTcpSocket sock;
QSignalSpy spy(&sock, &QTcpSocket::connected);
qDebug() << "Connecting to" << TCP_HOST << "on port 80";
sock.connectToHost(TCP_HOST, 80);
spy.wait();
QVERIFY(sock.waitForConnected());
QVERIFY(sock.localPort() > 0);
qDebug() << "Local address is" << sock.localAddress() << ":" << sock.localPort();
}
void QtNetworkTests::sslSocket() {
QSslSocket sock;
QSignalSpy spy(&sock, &QSslSocket::connected);
QVERIFY(QSslSocket::supportsSsl());
qDebug() << "SSL library version: " << QSslSocket::sslLibraryVersionString();
qDebug() << "Connecting to" << SSL_HOST << "on port 443";
sock.connectToHostEncrypted(SSL_HOST, 443);
spy.wait();
QVERIFY(sock.waitForEncrypted());
QVERIFY(sock.localPort() > 0);
QVERIFY(!sock.sslConfiguration().isNull());
QVERIFY(sock.sslHandshakeErrors().length() == 0);
QVERIFY(sock.sessionProtocol() != QSsl::UnknownProtocol);
qDebug() << "Local address is" << sock.localAddress() << ":" << sock.localPort();
qDebug() << "SSL protocol : " << sock.sessionProtocol();
qDebug() << "SSL cipher : " << sock.sessionCipher().protocolString();
qDebug() << "SSL cert : " << sock.peerCertificate();
}
void QtNetworkTests::httpRequest() {
auto manager = new QNetworkAccessManager();
qDebug() << "Making request to" << HTTP_URL;
QSignalSpy spy(manager, &QNetworkAccessManager::finished);
QNetworkRequest req(QUrl("http://google.com"));
QNetworkRequest req(HTTP_URL);
manager->get(req);
spy.wait();
@ -40,14 +97,18 @@ void QtNetworkTests::httpRequest() {
QList<QVariant> arguments = spy.takeFirst();
QNetworkReply *reply = arguments.at(0).value<QNetworkReply*>();
QVERIFY(!reply->error());
qDebug() << reply->readAll().length() << "Bytes received";
QVERIFY(!reply->sslConfiguration().isNull());
QString data = reply->readAll();
qDebug() << "DATA: " << data;
}
void QtNetworkTests::httpsRequest() {
auto manager = new QNetworkAccessManager();
qDebug() << "Making request to" << HTTPS_URL;
QSignalSpy spy(manager, &QNetworkAccessManager::finished);
QNetworkRequest req(QUrl("https://google.com"));
QNetworkRequest req(HTTPS_URL);
manager->get(req);
spy.wait();
@ -56,5 +117,8 @@ void QtNetworkTests::httpsRequest() {
QList<QVariant> arguments = spy.takeFirst();
QNetworkReply *reply = arguments.at(0).value<QNetworkReply*>();
QVERIFY(!reply->error());
qDebug() << reply->readAll().length() << "Bytes received";
QVERIFY(!reply->sslConfiguration().isNull());
QString data = reply->readAll();
qDebug() << "DATA: " << data;
}

View file

@ -1,14 +1,15 @@
//
// PacketTests.h
// PacketTests.cpp
// tests/networking/src
//
// Created by Stephen Birarda on 07/14/15.
// Copyright 2015 High Fidelity, Inc.
// Created by Dale Glass on 02/06/2024
// Copyright 2024 Overte e.V.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef overte_QtNetworkTests_h
#define overte_QtNetworkTests_h
@ -20,6 +21,8 @@ class QtNetworkTests : public QObject {
Q_OBJECT
private slots:
void initTestCase();
void tcpSocket();
void sslSocket();
void httpRequest();
void httpsRequest();
};