fix bitrot after UDT overhaul

This commit is contained in:
Andrew Meadows 2016-12-28 18:11:54 -08:00
parent 39538db63a
commit 96a9ef8f44
2 changed files with 23 additions and 40 deletions

View file

@ -12,29 +12,29 @@
#include "PacketTests.h"
#include "../QTestExtensions.h"
#include <udt/Packet.h>
#include <NLPacket.h>
QTEST_MAIN(PacketTests)
std::unique_ptr<Packet> copyToReadPacket(std::unique_ptr<Packet>& packet) {
std::unique_ptr<NLPacket> copyToReadPacket(std::unique_ptr<NLPacket>& packet) {
auto size = packet->getDataSize();
auto data = std::unique_ptr<char[]>(new char[size]);
memcpy(data.get(), packet->getData(), size);
return Packet::fromReceivedPacket(std::move(data), size, HifiSockAddr());
return NLPacket::fromReceivedPacket(std::move(data), size, HifiSockAddr());
}
void PacketTests::emptyPacketTest() {
auto packet = Packet::create(PacketType::Unknown);
auto packet = NLPacket::create(PacketType::Unknown);
QCOMPARE(packet->getType(), PacketType::Unknown);
QCOMPARE(packet->getPayloadSize(), 0);
QCOMPARE(packet->getDataSize(), packet->totalHeadersSize());
QCOMPARE(packet->getDataSize(), NLPacket::totalHeaderSize(packet->getType()));
QCOMPARE(packet->bytesLeftToRead(), 0);
QCOMPARE(packet->bytesAvailableForWrite(), packet->getPayloadCapacity());
}
void PacketTests::packetTypeTest() {
auto packet = Packet::create(PacketType::EntityAdd);
auto packet = NLPacket::create(PacketType::EntityAdd);
QCOMPARE(packet->getType(), PacketType::EntityAdd);
@ -46,7 +46,7 @@ void PacketTests::packetTypeTest() {
}
void PacketTests::writeTest() {
auto packet = Packet::create(PacketType::Unknown);
auto packet = NLPacket::create(PacketType::Unknown);
QCOMPARE(packet->getPayloadSize(), 0);
@ -62,7 +62,7 @@ void PacketTests::writeTest() {
void PacketTests::readTest() {
// Test reads for several different size packets
for (int i = 1; i < 4; i++) {
auto packet = Packet::create(PacketType::Unknown);
auto packet = NLPacket::create(PacketType::Unknown);
auto size = packet->getPayloadCapacity();
size /= i;
@ -91,7 +91,7 @@ void PacketTests::readTest() {
}
void PacketTests::writePastCapacityTest() {
auto packet = Packet::create(PacketType::Unknown);
auto packet = NLPacket::create(PacketType::Unknown);
auto size = packet->getPayloadCapacity();
char* data = new char[size];
@ -111,20 +111,20 @@ void PacketTests::writePastCapacityTest() {
QCOMPARE(packet->bytesAvailableForWrite(), 0);
QCOMPARE(packet->getPayloadSize(), size);
QCOMPARE(Packet::PACKET_WRITE_ERROR, packet->write("data"));
// Packet::write() shouldn't allow the caller to write if no space is left
QCOMPARE(NLPacket::PACKET_WRITE_ERROR, packet->write("data")); // asserts in DEBUG
// NLPacket::write() shouldn't allow the caller to write if no space is left
QCOMPARE(packet->getPayloadSize(), size);
}
void PacketTests::primitiveTest() {
auto packet = Packet::create(PacketType::Unknown);
auto packet = NLPacket::create(PacketType::Unknown);
int value1 = 5;
char value2 = 10;
bool value3 = true;
qint64 value4 = -93404;
packet->writePrimitive(value1);
packet->writePrimitive(value2);
packet->writePrimitive(value3);
@ -133,7 +133,7 @@ void PacketTests::primitiveTest() {
auto recvPacket = copyToReadPacket(packet);
// Peek & read first value
{
{
int peekValue = 0;
QCOMPARE(recvPacket->peekPrimitive(&peekValue), (int)sizeof(peekValue));
QCOMPARE(peekValue, value1);

View file

@ -37,25 +37,10 @@ void ResourceTests::initTestCase() {
static QSharedPointer<Resource> resource;
static bool waitForSignal(QObject *sender, const char *signal, int timeout = 1000) {
QEventLoop loop;
QTimer timer;
timer.setInterval(timeout);
timer.setSingleShot(true);
loop.connect(sender, signal, SLOT(quit()));
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
timer.start();
loop.exec();
return timer.isActive();
}
void ResourceTests::downloadFirst() {
// download the Mery fst file
QUrl meryUrl = QUrl("http://hifi-public.s3.amazonaws.com/marketplace/contents/e21c0b95-e502-4d15-8c41-ea2fc40f1125/3585ddf674869a67d31d5964f7b52de1.fst");
resource = QSharedPointer<Resource>::create(meryUrl, false);
resource = QSharedPointer<Resource>::create(meryUrl);
resource->setSelf(resource);
const int timeout = 1000;
@ -64,9 +49,9 @@ void ResourceTests::downloadFirst() {
timer.setInterval(timeout);
timer.setSingleShot(true);
loop.connect(resource, SIGNAL(loaded(QNetworkReply&)), SLOT(quit()));
loop.connect(resource, SIGNAL(failed(QNetworkReply::NetworkError)), SLOT(quit()));
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
connect(resource.data(), &Resource::loaded, &loop, &QEventLoop::quit);
connect(resource.data(), &Resource::failed, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start();
resource->ensureLoading();
@ -76,10 +61,9 @@ void ResourceTests::downloadFirst() {
}
void ResourceTests::downloadAgain() {
// download the Mery fst file
QUrl meryUrl = QUrl("http://hifi-public.s3.amazonaws.com/marketplace/contents/e21c0b95-e502-4d15-8c41-ea2fc40f1125/3585ddf674869a67d31d5964f7b52de1.fst");
resource = QSharedPointer<Resource>::create(meryUrl, false);
resource = QSharedPointer<Resource>::create(meryUrl);
resource->setSelf(resource);
const int timeout = 1000;
@ -88,14 +72,13 @@ void ResourceTests::downloadAgain() {
timer.setInterval(timeout);
timer.setSingleShot(true);
loop.connect(resource, SIGNAL(loaded(QNetworkReply&)), SLOT(quit()));
loop.connect(resource, SIGNAL(failed(QNetworkReply::NetworkError)), SLOT(quit()));
loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
connect(resource.data(), &Resource::loaded, &loop, &QEventLoop::quit);
connect(resource.data(), &Resource::failed, &loop, &QEventLoop::quit);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.start();
resource->ensureLoading();
loop.exec();
QVERIFY(resource->isLoaded());
}