mirror of
https://github.com/AleziaKurdis/overte.git
synced 2025-04-19 08:18:05 +02:00
Merge pull request #9281 from AndrewMeadows/unit-test-cleanup
fix bitrot in unit tests
This commit is contained in:
commit
ff19bdceaa
8 changed files with 49 additions and 62 deletions
|
@ -370,7 +370,7 @@ glm::quat glmExtractRotation(const glm::mat4& matrix) {
|
|||
glm::vec3 extractScale(const glm::mat4& matrix) {
|
||||
glm::mat3 m(matrix);
|
||||
float det = glm::determinant(m);
|
||||
if (det < 0) {
|
||||
if (det < 0.0f) {
|
||||
// left handed matrix, flip sign to compensate.
|
||||
return glm::vec3(-glm::length(m[0]), glm::length(m[1]), glm::length(m[2]));
|
||||
} else {
|
||||
|
|
|
@ -36,7 +36,7 @@ void AudioRingBufferTests::runAllTests() {
|
|||
int readIndexAt;
|
||||
|
||||
|
||||
AudioRingBuffer ringBuffer(10, false, 10); // makes buffer of 100 int16_t samples
|
||||
AudioRingBuffer ringBuffer(10, 10); // makes buffer of 100 int16_t samples
|
||||
for (int T = 0; T < 300; T++) {
|
||||
|
||||
writeIndexAt = 0;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
||||
}
|
||||
|
|
|
@ -255,11 +255,11 @@ void GeometryUtilTests::testTwistSwingDecomposition() {
|
|||
glm::quat measuredTwistRotation;
|
||||
glm::quat measuredSwingRotation;
|
||||
swingTwistDecomposition(totalRotation, twistAxis, measuredSwingRotation, measuredTwistRotation);
|
||||
|
||||
|
||||
// dot decomposed with components
|
||||
float twistDot = fabsf(glm::dot(twistRotation, measuredTwistRotation));
|
||||
float swingDot = fabsf(glm::dot(swingRotation, measuredSwingRotation));
|
||||
|
||||
|
||||
// the dot products should be very close to 1.0
|
||||
const float MIN_ERROR = 1.0e-6f;
|
||||
QCOMPARE_WITH_ABS_ERROR(1.0f, twistDot, MIN_ERROR);
|
||||
|
@ -277,7 +277,7 @@ void GeometryUtilTests::testSphereCapsulePenetration() {
|
|||
glm::vec3 capsuleEnd(0.0f, 10.0f, 0.0f);
|
||||
float capsuleRadius = 1.0f;
|
||||
|
||||
glm::vec3 penetration(glm::vec3::_null);
|
||||
glm::vec3 penetration(0.0f);
|
||||
bool hit = findSphereCapsulePenetration(sphereCenter, sphereRadius, capsuleStart, capsuleEnd, capsuleRadius, penetration);
|
||||
QCOMPARE(hit, true);
|
||||
QCOMPARE_WITH_ABS_ERROR(penetration, glm::vec3(-0.5f, 0.0f, 0.0f), EPSILON);
|
||||
|
|
|
@ -39,19 +39,21 @@ void MovingPercentileTests::testRunningMedian() {
|
|||
}
|
||||
|
||||
|
||||
float MovingPercentileTests::random() {
|
||||
return rand() / (float)RAND_MAX;
|
||||
int64_t MovingPercentileTests::random() {
|
||||
return ((int64_t) rand() << 48) ^
|
||||
((int64_t) rand() << 32) ^
|
||||
((int64_t) rand() << 16) ^
|
||||
((int64_t) rand());
|
||||
}
|
||||
|
||||
void MovingPercentileTests::testRunningMinForN (int n) {
|
||||
|
||||
// Stores the last n samples
|
||||
QQueue<float> samples;
|
||||
QQueue<int64_t> samples;
|
||||
|
||||
MovingPercentile movingMin (n, 0.0f);
|
||||
|
||||
for (int s = 0; s < 3 * n; ++s) {
|
||||
float sample = random();
|
||||
int64_t sample = random();
|
||||
|
||||
samples.push_back(sample);
|
||||
if (samples.size() > n)
|
||||
|
@ -64,30 +66,32 @@ void MovingPercentileTests::testRunningMinForN (int n) {
|
|||
movingMin.updatePercentile(sample);
|
||||
|
||||
// Calculate the minimum of the moving samples
|
||||
float expectedMin = std::numeric_limits<float>::max();
|
||||
int64_t expectedMin = std::numeric_limits<int64_t>::max();
|
||||
|
||||
int prevSize = samples.size();
|
||||
for (auto val : samples)
|
||||
for (auto val : samples) {
|
||||
expectedMin = std::min(val, expectedMin);
|
||||
}
|
||||
QCOMPARE(samples.size(), prevSize);
|
||||
|
||||
QCOMPARE(movingMin.getValueAtPercentile(), expectedMin);
|
||||
QVERIFY(movingMin.getValueAtPercentile() - expectedMin == 0L);
|
||||
}
|
||||
}
|
||||
|
||||
void MovingPercentileTests::testRunningMaxForN (int n) {
|
||||
|
||||
// Stores the last n samples
|
||||
QQueue<float> samples;
|
||||
QQueue<int64_t> samples;
|
||||
|
||||
MovingPercentile movingMax (n, 1.0f);
|
||||
|
||||
for (int s = 0; s < 10000; ++s) {
|
||||
float sample = random();
|
||||
int64_t sample = random();
|
||||
|
||||
samples.push_back(sample);
|
||||
if (samples.size() > n)
|
||||
if (samples.size() > n) {
|
||||
samples.pop_front();
|
||||
}
|
||||
|
||||
if (samples.size() == 0) {
|
||||
QFAIL_WITH_MESSAGE("\n\n\n\tWTF\n\tsamples.size() = " << samples.size() << ", n = " << n);
|
||||
|
@ -96,22 +100,22 @@ void MovingPercentileTests::testRunningMaxForN (int n) {
|
|||
movingMax.updatePercentile(sample);
|
||||
|
||||
// Calculate the maximum of the moving samples
|
||||
float expectedMax = std::numeric_limits<float>::min();
|
||||
int64_t expectedMax = std::numeric_limits<int64_t>::min();
|
||||
for (auto val : samples)
|
||||
expectedMax = std::max(val, expectedMax);
|
||||
|
||||
QCOMPARE(movingMax.getValueAtPercentile(), expectedMax);
|
||||
QVERIFY(movingMax.getValueAtPercentile() - expectedMax == 0L);
|
||||
}
|
||||
}
|
||||
|
||||
void MovingPercentileTests::testRunningMedianForN (int n) {
|
||||
// Stores the last n samples
|
||||
QQueue<float> samples;
|
||||
QQueue<int64_t> samples;
|
||||
|
||||
MovingPercentile movingMedian (n, 0.5f);
|
||||
|
||||
for (int s = 0; s < 10000; ++s) {
|
||||
float sample = random();
|
||||
int64_t sample = random();
|
||||
|
||||
samples.push_back(sample);
|
||||
if (samples.size() > n)
|
||||
|
|
|
@ -25,7 +25,7 @@ private slots:
|
|||
|
||||
private:
|
||||
// Utilities and helper functions
|
||||
float random();
|
||||
int64_t random();
|
||||
void testRunningMinForN (int n);
|
||||
void testRunningMaxForN (int n);
|
||||
void testRunningMedianForN (int n);
|
||||
|
|
|
@ -28,7 +28,7 @@ void TraceTests::testTraceSerialization() {
|
|||
auto start = usecTimestampNow();
|
||||
PROFILE_RANGE(test, "TestEvent")
|
||||
for (size_t i = 0; i < 10000; ++i) {
|
||||
SAMPLE_PROFILE_COUNTER(0.1f, test, "TestCounter", { { "i", i } })
|
||||
SAMPLE_PROFILE_COUNTER(0.1f, test, "TestCounter", { { "i", (int)i } })
|
||||
}
|
||||
auto duration = usecTimestampNow() - start;
|
||||
duration /= USECS_PER_MSEC;
|
||||
|
|
Loading…
Reference in a new issue