mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Fix unit test compile issues
This commit is contained in:
parent
e81d2809c1
commit
1aba6e8fe1
3 changed files with 58 additions and 62 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include <QtCore/QFileInfo>
|
#include <QtCore/QFileInfo>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <NumericalConstants.h>
|
#include <NumericalConstants.h>
|
||||||
|
#include <SharedUtil.h>
|
||||||
#include "GLMTestUtils.h"
|
#include "GLMTestUtils.h"
|
||||||
|
|
||||||
// Implements several extensions to QtTest.
|
// Implements several extensions to QtTest.
|
||||||
|
@ -37,7 +38,6 @@
|
||||||
// from scratch using QTest::qFail, for example).
|
// from scratch using QTest::qFail, for example).
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
float getErrorDifference(const float& a, const float& b) {
|
float getErrorDifference(const float& a, const float& b) {
|
||||||
return fabsf(a - b);
|
return fabsf(a - b);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ QString QTest_generateCompareFailureMessage (
|
||||||
QString pad2 = QString(")").rightJustified(pad2_, ' ');
|
QString pad2 = QString(")").rightJustified(pad2_, ' ');
|
||||||
|
|
||||||
QString msg;
|
QString msg;
|
||||||
QTextStream stream (&msg);
|
QTextStream stream(&msg);
|
||||||
stream << failMessage << "\n\t"
|
stream << failMessage << "\n\t"
|
||||||
"Actual: (" << actual_expr << pad1 << ": " << actual << "\n\t"
|
"Actual: (" << actual_expr << pad1 << ": " << actual << "\n\t"
|
||||||
"Expected: (" << expected_expr << pad2 << ": " << expected << "\n\t";
|
"Expected: (" << expected_expr << pad2 << ": " << expected << "\n\t";
|
||||||
|
@ -100,7 +100,7 @@ QString QTest_generateCompareFailureMessage (
|
||||||
QString pad2 = QString("): ").rightJustified(pad2_, ' ');
|
QString pad2 = QString("): ").rightJustified(pad2_, ' ');
|
||||||
|
|
||||||
QString msg;
|
QString msg;
|
||||||
QTextStream stream (&msg);
|
QTextStream stream(&msg);
|
||||||
stream << failMessage << "\n\t"
|
stream << failMessage << "\n\t"
|
||||||
"Actual: (" << actual_expr << pad1 << actual << "\n\t"
|
"Actual: (" << actual_expr << pad1 << actual << "\n\t"
|
||||||
"Expected: (" << expected_expr << pad2 << expected;
|
"Expected: (" << expected_expr << pad2 << expected;
|
||||||
|
@ -134,10 +134,10 @@ void QTest_failWithCustomMessage (
|
||||||
// QFAIL_WITH_MESSAGE("Message " << thing << ";");
|
// QFAIL_WITH_MESSAGE("Message " << thing << ";");
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
#define QFAIL_WITH_MESSAGE(...) \
|
#define QFAIL_WITH_MESSAGE(...) \
|
||||||
do { \
|
do { \
|
||||||
QTest_failWithCustomMessage([&](QTextStream& stream) { stream << __VA_ARGS__; }, __LINE__, __FILE__); \
|
QTest_failWithCustomMessage([&](QTextStream& stream) { stream << __VA_ARGS__; }, __LINE__, __FILE__); \
|
||||||
return; \
|
return; \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
// Calls qFail using QTest_generateCompareFailureMessage.
|
// Calls qFail using QTest_generateCompareFailureMessage.
|
||||||
|
@ -181,7 +181,7 @@ bool QTest_compareWithAbsError(
|
||||||
actual, expected, actual_expr, expected_expr, line, file,
|
actual, expected, actual_expr, expected_expr, line, file,
|
||||||
[&] (QTextStream& stream) -> QTextStream& {
|
[&] (QTextStream& stream) -> QTextStream& {
|
||||||
return stream << "Err tolerance: " << getErrorDifference((actual), (expected)) << " > " << epsilon;
|
return stream << "Err tolerance: " << getErrorDifference((actual), (expected)) << " > " << epsilon;
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -200,10 +200,10 @@ bool QTest_compareWithAbsError(
|
||||||
// return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }"
|
// return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }"
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
#define QCOMPARE_WITH_ABS_ERROR(actual, expected, epsilon) \
|
#define QCOMPARE_WITH_ABS_ERROR(actual, expected, epsilon) \
|
||||||
do { \
|
do { \
|
||||||
if (!QTest_compareWithAbsError((actual), (expected), #actual, #expected, __LINE__, __FILE__, epsilon)) \
|
if (!QTest_compareWithAbsError((actual), (expected), #actual, #expected, __LINE__, __FILE__, epsilon)) \
|
||||||
return; \
|
return; \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
// Implements QCOMPARE using an explicit, externally defined test function.
|
// Implements QCOMPARE using an explicit, externally defined test function.
|
||||||
|
@ -212,12 +212,12 @@ do { \
|
||||||
//
|
//
|
||||||
// testFunc(const T & actual, const T & expected) -> bool: true (test succeeds) | false (test fails)
|
// testFunc(const T & actual, const T & expected) -> bool: true (test succeeds) | false (test fails)
|
||||||
//
|
//
|
||||||
#define QCOMPARE_WITH_FUNCTION(actual, expected, testFunc) \
|
#define QCOMPARE_WITH_FUNCTION(actual, expected, testFunc) \
|
||||||
do { \
|
do { \
|
||||||
if (!(testFunc((actual), (expected)))) { \
|
if (!(testFunc((actual), (expected)))) { \
|
||||||
QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Implements QCOMPARE using an explicit, externally defined test function.
|
// Implements QCOMPARE using an explicit, externally defined test function.
|
||||||
|
@ -230,41 +230,40 @@ do { \
|
||||||
// });
|
// });
|
||||||
// (fails if foo is not as fooish as expectedFoo)
|
// (fails if foo is not as fooish as expectedFoo)
|
||||||
//
|
//
|
||||||
#define QCOMPARE_WITH_LAMBDA(actual, expected, testClosure) \
|
#define QCOMPARE_WITH_LAMBDA(actual, expected, testClosure) \
|
||||||
do { \
|
do { \
|
||||||
if (!(testClosure())) { \
|
if (!(testClosure())) { \
|
||||||
QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Same as QCOMPARE_WITH_FUNCTION, but with a custom fail message
|
// Same as QCOMPARE_WITH_FUNCTION, but with a custom fail message
|
||||||
#define QCOMPARE_WITH_FUNCTION_AND_MESSAGE(actual, expected, testfunc, failMessage) \
|
#define QCOMPARE_WITH_FUNCTION_AND_MESSAGE(actual, expected, testfunc, failMessage) \
|
||||||
do { \
|
do { \
|
||||||
if (!(testFunc((actual), (expected)))) { \
|
if (!(testFunc((actual), (expected)))) { \
|
||||||
QTest_failWithMessage((failMessage), (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
QTest_failWithMessage((failMessage), (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Same as QCOMPARE_WITH_FUNCTION, but with a custom fail message
|
// Same as QCOMPARE_WITH_FUNCTION, but with a custom fail message
|
||||||
#define QCOMPARE_WITH_LAMBDA_AND_MESSAGE(actual, expected, testClosure, failMessage) \
|
#define QCOMPARE_WITH_LAMBDA_AND_MESSAGE(actual, expected, testClosure, failMessage) \
|
||||||
do { \
|
do { \
|
||||||
if (!(testClosure())) { \
|
if (!(testClosure())) { \
|
||||||
QTest_failWithMessage((failMessage), (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
QTest_failWithMessage((failMessage), (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define QCOMPARE_WITH_EXPR(actual, expected, testExpr) \
|
#define QCOMPARE_WITH_EXPR(actual, expected, testExpr) \
|
||||||
do { \
|
do { \
|
||||||
if (!(testExpr)) { \
|
if (!(testExpr)) { \
|
||||||
QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
struct ByteData {
|
struct ByteData {
|
||||||
ByteData (const char* data, size_t length)
|
ByteData (const char* data, size_t length)
|
||||||
|
@ -273,25 +272,24 @@ struct ByteData {
|
||||||
size_t length;
|
size_t length;
|
||||||
};
|
};
|
||||||
|
|
||||||
QTextStream & operator << (QTextStream& stream, const ByteData & wrapper) {
|
QTextStream& operator<<(QTextStream& stream, const ByteData& wrapper) {
|
||||||
// Print bytes as hex
|
// Print bytes as hex
|
||||||
stream << QByteArray::fromRawData(wrapper.data, (int)wrapper.length).toHex();
|
stream << QByteArray::fromRawData(wrapper.data, (int)wrapper.length).toHex();
|
||||||
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool compareData (const char* data, const char* expectedData, size_t length) {
|
bool compareData(const char* data, const char* expectedData, size_t length) {
|
||||||
return memcmp(data, expectedData, length) == 0;
|
return memcmp(data, expectedData, length) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define COMPARE_DATA(actual, expected, length) \
|
#define COMPARE_DATA(actual, expected, length) \
|
||||||
QCOMPARE_WITH_EXPR((ByteData ( actual, length )), (ByteData ( expected, length )), compareData(actual, expected, length))
|
QCOMPARE_WITH_EXPR((ByteData(actual, length)), (ByteData(expected, length)), compareData(actual, expected, length))
|
||||||
|
|
||||||
|
|
||||||
// Produces a relative error test for float usable QCOMPARE_WITH_LAMBDA.
|
// Produces a relative error test for float usable QCOMPARE_WITH_LAMBDA.
|
||||||
inline auto errorTest (float actual, float expected, float acceptableRelativeError)
|
inline auto errorTest (float actual, float expected, float acceptableRelativeError)
|
||||||
-> std::function<bool ()> {
|
-> std::function<bool ()> {
|
||||||
return [actual, expected, acceptableRelativeError] () {
|
return [actual, expected, acceptableRelativeError]() {
|
||||||
if (fabsf(expected) <= acceptableRelativeError) {
|
if (fabsf(expected) <= acceptableRelativeError) {
|
||||||
return fabsf(actual - expected) < fabsf(acceptableRelativeError);
|
return fabsf(actual - expected) < fabsf(acceptableRelativeError);
|
||||||
}
|
}
|
||||||
|
@ -302,18 +300,16 @@ inline auto errorTest (float actual, float expected, float acceptableRelativeErr
|
||||||
#define QCOMPARE_WITH_RELATIVE_ERROR(actual, expected, relativeError) \
|
#define QCOMPARE_WITH_RELATIVE_ERROR(actual, expected, relativeError) \
|
||||||
QCOMPARE_WITH_LAMBDA(actual, expected, errorTest(actual, expected, relativeError))
|
QCOMPARE_WITH_LAMBDA(actual, expected, errorTest(actual, expected, relativeError))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline QString getTestResource(const QString& relativePath) {
|
inline QString getTestResource(const QString& relativePath) {
|
||||||
static QDir dir;
|
static QDir dir;
|
||||||
static std::once_flag once;
|
static std::once_flag once;
|
||||||
std::call_once(once, []{
|
std::call_once(once, [] {
|
||||||
QFileInfo fileInfo(__FILE__);
|
QFileInfo fileInfo(__FILE__);
|
||||||
auto parentDir = fileInfo.absoluteDir();
|
auto parentDir = fileInfo.absoluteDir();
|
||||||
auto rootDir = parentDir.absoluteFilePath("..");
|
auto rootDir = parentDir.absoluteFilePath("..");
|
||||||
dir = QDir::cleanPath(rootDir);
|
dir = QDir::cleanPath(rootDir);
|
||||||
});
|
});
|
||||||
|
|
||||||
return QDir::cleanPath(dir.absoluteFilePath(relativePath));
|
return QDir::cleanPath(dir.absoluteFilePath(relativePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
QTEST_MAIN(AnimTests)
|
QTEST_MAIN(AnimTests)
|
||||||
|
|
||||||
const float EPSILON = 0.001f;
|
const float TEST_EPSILON = 0.001f;
|
||||||
|
|
||||||
void AnimTests::initTestCase() {
|
void AnimTests::initTestCase() {
|
||||||
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
|
DependencyManager::registerInheritance<LimitedNodeList, NodeList>();
|
||||||
|
@ -86,12 +86,12 @@ void AnimTests::testClipEvaulate() {
|
||||||
|
|
||||||
AnimNode::Triggers triggers;
|
AnimNode::Triggers triggers;
|
||||||
clip.evaluate(vars, context, framesToSec(10.0f), triggers);
|
clip.evaluate(vars, context, framesToSec(10.0f), triggers);
|
||||||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 12.0f, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(clip._frame, 12.0f, TEST_EPSILON);
|
||||||
|
|
||||||
// does it loop?
|
// does it loop?
|
||||||
triggers.clear();
|
triggers.clear();
|
||||||
clip.evaluate(vars, context, framesToSec(12.0f), triggers);
|
clip.evaluate(vars, context, framesToSec(12.0f), triggers);
|
||||||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 3.0f, EPSILON); // Note: frame 3 and not 4, because extra frame between start and end.
|
QCOMPARE_WITH_ABS_ERROR(clip._frame, 3.0f, TEST_EPSILON); // Note: frame 3 and not 4, because extra frame between start and end.
|
||||||
|
|
||||||
// did we receive a loop trigger?
|
// did we receive a loop trigger?
|
||||||
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnLoop") != triggers.end());
|
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnLoop") != triggers.end());
|
||||||
|
@ -100,7 +100,7 @@ void AnimTests::testClipEvaulate() {
|
||||||
triggers.clear();
|
triggers.clear();
|
||||||
clip.setLoopFlagVar("FalseVar");
|
clip.setLoopFlagVar("FalseVar");
|
||||||
clip.evaluate(vars, context, framesToSec(20.0f), triggers);
|
clip.evaluate(vars, context, framesToSec(20.0f), triggers);
|
||||||
QCOMPARE_WITH_ABS_ERROR(clip._frame, 22.0f, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(clip._frame, 22.0f, TEST_EPSILON);
|
||||||
|
|
||||||
// did we receive a done trigger?
|
// did we receive a done trigger?
|
||||||
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnDone") != triggers.end());
|
QVERIFY(std::find(triggers.begin(), triggers.end(), "myClipNodeOnDone") != triggers.end());
|
||||||
|
@ -402,7 +402,7 @@ void AnimTests::testAnimPose() {
|
||||||
glm::vec3(10.0f, 5.0f, -7.5f)
|
glm::vec3(10.0f, 5.0f, -7.5f)
|
||||||
};
|
};
|
||||||
|
|
||||||
const float EPSILON = 0.001f;
|
const float TEST_EPSILON = 0.001f;
|
||||||
|
|
||||||
for (auto& scale : scaleVec) {
|
for (auto& scale : scaleVec) {
|
||||||
for (auto& rot : rotVec) {
|
for (auto& rot : rotVec) {
|
||||||
|
@ -417,7 +417,7 @@ void AnimTests::testAnimPose() {
|
||||||
AnimPose pose(scale, rot, trans);
|
AnimPose pose(scale, rot, trans);
|
||||||
glm::mat4 poseMat = pose;
|
glm::mat4 poseMat = pose;
|
||||||
|
|
||||||
QCOMPARE_WITH_ABS_ERROR(rawMat, poseMat, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(rawMat, poseMat, TEST_EPSILON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -437,7 +437,7 @@ void AnimTests::testAnimPose() {
|
||||||
// now build a new matrix from those parts.
|
// now build a new matrix from those parts.
|
||||||
glm::mat4 poseMat = pose;
|
glm::mat4 poseMat = pose;
|
||||||
|
|
||||||
QCOMPARE_WITH_ABS_ERROR(rawMat, poseMat, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(rawMat, poseMat, TEST_EPSILON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ const quat rot90 = glm::angleAxis((float)M_PI / 2.0f, yAxis);
|
||||||
|
|
||||||
QTEST_MAIN(TransformTests)
|
QTEST_MAIN(TransformTests)
|
||||||
|
|
||||||
const float EPSILON = 0.001f;
|
const float TEST_EPSILON = 0.001f;
|
||||||
|
|
||||||
void TransformTests::getMatrix() {
|
void TransformTests::getMatrix() {
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ void TransformTests::getMatrix() {
|
||||||
mat4 result_b;
|
mat4 result_b;
|
||||||
xform.getMatrix(result_b);
|
xform.getMatrix(result_b);
|
||||||
|
|
||||||
QCOMPARE_WITH_ABS_ERROR(result_a, result_b, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(result_a, result_b, TEST_EPSILON);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TransformTests::getInverseMatrix() {
|
void TransformTests::getInverseMatrix() {
|
||||||
|
@ -92,7 +92,7 @@ void TransformTests::getInverseMatrix() {
|
||||||
auto yb = transformPoint(result_b, yAxis);
|
auto yb = transformPoint(result_b, yAxis);
|
||||||
auto zb = transformPoint(result_b, zAxis);
|
auto zb = transformPoint(result_b, zAxis);
|
||||||
|
|
||||||
QCOMPARE_WITH_ABS_ERROR(xa, xb, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(xa, xb, TEST_EPSILON);
|
||||||
QCOMPARE_WITH_ABS_ERROR(ya, yb, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(ya, yb, TEST_EPSILON);
|
||||||
QCOMPARE_WITH_ABS_ERROR(za, zb, EPSILON);
|
QCOMPARE_WITH_ABS_ERROR(za, zb, TEST_EPSILON);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue