Add very basic HTTP and HTTPS network tests.

This seems to reproduce the problem I'm having with the Conan PR
This commit is contained in:
Dale Glass 2024-06-03 01:11:48 +02:00
parent 09e5a60c8b
commit 7076669635
2 changed files with 87 additions and 0 deletions

View file

@ -0,0 +1,60 @@
//
// PacketTests.cpp
// tests/networking/src
//
// Created by Stephen Birarda on 07/14/15.
// Copyright 2015 High Fidelity, Inc.
// Copyright 2021 Vircadia contributors.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "QtNetworkTests.h"
#include <test-utils/QTestExtensions.h>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QUrl>
QTEST_MAIN(QtNetworkTests);
void QtNetworkTests::initTestCase() {
qDebug() << "Init";
qRegisterMetaType<QNetworkReply*>();
}
void QtNetworkTests::httpRequest() {
auto manager = new QNetworkAccessManager();
QSignalSpy spy(manager, &QNetworkAccessManager::finished);
QNetworkRequest req(QUrl("http://google.com"));
manager->get(req);
spy.wait();
QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
QNetworkReply *reply = arguments.at(0).value<QNetworkReply*>();
QVERIFY(!reply->error());
qDebug() << reply->readAll().length() << "Bytes received";
}
void QtNetworkTests::httpsRequest() {
auto manager = new QNetworkAccessManager();
QSignalSpy spy(manager, &QNetworkAccessManager::finished);
QNetworkRequest req(QUrl("https://google.com"));
manager->get(req);
spy.wait();
QCOMPARE(spy.count(), 1);
QList<QVariant> arguments = spy.takeFirst();
QNetworkReply *reply = arguments.at(0).value<QNetworkReply*>();
QVERIFY(!reply->error());
qDebug() << reply->readAll().length() << "Bytes received";
}

View file

@ -0,0 +1,27 @@
//
// PacketTests.h
// tests/networking/src
//
// Created by Stephen Birarda on 07/14/15.
// Copyright 2015 High Fidelity, Inc.
//
// 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
#pragma once
#include <QtTest/QtTest>
class QtNetworkTests : public QObject {
Q_OBJECT
private slots:
void initTestCase();
void httpRequest();
void httpsRequest();
};
#endif // overte_QtNetworkTests_h