diff --git a/tests/physics/src/BulletUtilTests.h b/tests/physics/src/BulletUtilTests.h index 5d31e2af10..e8bf565428 100644 --- a/tests/physics/src/BulletUtilTests.h +++ b/tests/physics/src/BulletUtilTests.h @@ -13,7 +13,6 @@ #define hifi_BulletUtilTests_h #include - // Add additional qtest functionality (the include order is important!) #include "GlmTestUtils.h" #include "../QTestExtensions.hpp" diff --git a/tests/physics/src/PhysicsTestUtil.h b/tests/physics/src/PhysicsTestUtil.h deleted file mode 100644 index d334203550..0000000000 --- a/tests/physics/src/PhysicsTestUtil.h +++ /dev/null @@ -1,52 +0,0 @@ -// -// PhysicsTestUtil.h -// tests/physics/src -// -// Created by Andrew Meadows on 02/21/2014. -// Copyright 2014 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 hifi_PhysicsTestUtil_h -#define hifi_PhysicsTestUtil_h - -#include -#include -#include - -#include - -#include - -const glm::vec3 origin(0.0f); -const glm::vec3 xAxis(1.0f, 0.0f, 0.0f); -const glm::vec3 yAxis(0.0f, 1.0f, 0.0f); -const glm::vec3 zAxis(0.0f, 0.0f, 1.0f); - -// Implement these functions for whatever data types you need. -// -// fuzzyCompare takes two args of type T (the type you're comparing), and should -// return an error / difference of type V (eg. if T is a vector, V is a scalar). -// For vector types this is just the distance between a and b. -// -// stringify is just a toString() / repr() style function. For PoD types, -// I'd recommend using the c++11 initialization syntax (type { constructor args... }), -// since it's clear and unambiguous. -// -inline float fuzzyCompare (const glm::vec3 & a, const glm::vec3 & b) { - return glm::distance(a, b); -} -inline QTextStream & operator << (QTextStream & stream, const glm::vec3 & v) { - return stream << "glm::vec3 { " << v.x << ", " << v.y << ", " << v.z << " }"; -} - -inline btScalar fuzzyCompare (btScalar a, btScalar b) { - return a - b; -} - -#include "../QTestExtensions.hpp" - - -#endif // hifi_PhysicsTestUtil_h diff --git a/tests/physics/src/ShapeInfoTests.cpp b/tests/physics/src/ShapeInfoTests.cpp index dcda566d58..a34bf97955 100644 --- a/tests/physics/src/ShapeInfoTests.cpp +++ b/tests/physics/src/ShapeInfoTests.cpp @@ -24,6 +24,7 @@ QTEST_MAIN(ShapeInfoTests) void ShapeInfoTests::testHashFunctions() { +#if MANUAL_TEST int maxTests = 10000000; ShapeInfo info; btHashMap hashes; @@ -41,6 +42,7 @@ void ShapeInfoTests::testHashFunctions() { int testCount = 0; int numCollisions = 0; + btClock timer; for (int x = 1; x < numSteps && testCount < maxTests; ++x) { float radiusX = (float)x * deltaLength; @@ -136,6 +138,8 @@ void ShapeInfoTests::testHashFunctions() { for (int i = 0; i < 32; ++i) { std::cout << "bit 0x" << std::hex << masks[i] << std::dec << " = " << bits[i] << std::endl; } + QCOMPARE(numCollisions, 0); +#endif // MANUAL_TEST } void ShapeInfoTests::testBoxShape() { @@ -145,21 +149,24 @@ void ShapeInfoTests::testBoxShape() { DoubleHashKey key = info.getHash(); btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info); - if (!shape) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: NULL Box shape" << std::endl; - } + QCOMPARE(shape != nullptr, true); +// if (!shape) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: NULL Box shape" << std::endl; +// } ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); - if (key.getHash() != otherKey.getHash()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Box shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; - } + QCOMPARE(key.getHash(), otherKey.getHash()); +// if (key.getHash() != otherKey.getHash()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Box shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; +// } - if (key.getHash2() != otherKey.getHash2()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Box shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; - } + QCOMPARE(key.getHash2(), otherKey.getHash2()); +// if (key.getHash2() != otherKey.getHash2()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Box shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; +// } delete shape; } @@ -171,17 +178,20 @@ void ShapeInfoTests::testSphereShape() { DoubleHashKey key = info.getHash(); btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info); + QCOMPARE(shape != nullptr, true); ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); - if (key.getHash() != otherKey.getHash()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Sphere shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; - } - if (key.getHash2() != otherKey.getHash2()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Sphere shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; - } + QCOMPARE(key.getHash(), otherKey.getHash()); +// if (key.getHash() != otherKey.getHash()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Sphere shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; +// } + QCOMPARE(key.getHash2(), otherKey.getHash2()); +// if (key.getHash2() != otherKey.getHash2()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Sphere shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; +// } delete shape; } @@ -195,17 +205,20 @@ void ShapeInfoTests::testCylinderShape() { DoubleHashKey key = info.getHash(); btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info); + QCOMPARE(shape != nullptr, true); ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); - if (key.getHash() != otherKey.getHash()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Cylinder shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; - } - if (key.getHash2() != otherKey.getHash2()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Cylinder shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; - } + QCOMPARE(key.getHash(), otherKey.getHash()); +// if (key.getHash() != otherKey.getHash()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Cylinder shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; +// } + QCOMPARE(key.getHash2(), otherKey.getHash2()); +// if (key.getHash2() != otherKey.getHash2()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Cylinder shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; +// } delete shape; */ @@ -220,17 +233,20 @@ void ShapeInfoTests::testCapsuleShape() { DoubleHashKey key = info.getHash(); btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info); + QCOMPARE(shape != nullptr, true); ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); - if (key.getHash() != otherKey.getHash()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Capsule shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; - } - if (key.getHash2() != otherKey.getHash2()) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected Capsule shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; - } + QCOMPARE(key.getHash(), otherKey.getHash()); +// if (key.getHash() != otherKey.getHash()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Capsule shape hash = " << key.getHash() << " but found hash = " << otherKey.getHash() << std::endl; +// } + QCOMPARE(key.getHash2(), otherKey.getHash2()); +// if (key.getHash2() != otherKey.getHash2()) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected Capsule shape hash2 = " << key.getHash2() << " but found hash2 = " << otherKey.getHash2() << std::endl; +// } delete shape; */ diff --git a/tests/physics/src/ShapeInfoTests.h b/tests/physics/src/ShapeInfoTests.h index baef255ff3..f01997e195 100644 --- a/tests/physics/src/ShapeInfoTests.h +++ b/tests/physics/src/ShapeInfoTests.h @@ -14,9 +14,13 @@ #include -// Add additional qtest functionality (the include order is important!) -#include "BulletTestUtils.h" -#include "../QTestExtensions.hpp" +//// Add additional qtest functionality (the include order is important!) +//#include "BulletTestUtils.h" +//#include "../QTestExtensions.hpp" + +// Enable this to manually run testHashCollisions +// (NOT a regular unit test; takes ~17 secs to run on an i7) +#define MANUAL_TEST false class ShapeInfoTests : public QObject { Q_OBJECT @@ -28,6 +32,4 @@ private slots: void testCapsuleShape(); }; -#include "../QTestExtensions.hpp" - #endif // hifi_ShapeInfoTests_h diff --git a/tests/physics/src/ShapeManagerTests.cpp b/tests/physics/src/ShapeManagerTests.cpp index 807aaef671..3d3a2debcb 100644 --- a/tests/physics/src/ShapeManagerTests.cpp +++ b/tests/physics/src/ShapeManagerTests.cpp @@ -23,37 +23,42 @@ void ShapeManagerTests::testShapeAccounting() { info.setBox(glm::vec3(1.0f, 1.0f, 1.0f)); int numReferences = shapeManager.getNumReferences(info); - if (numReferences != 0) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected ignorant ShapeManager after initialization" << std::endl; - } + QCOMPARE(numReferences, 0); +// if (numReferences != 0) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected ignorant ShapeManager after initialization" << std::endl; +// } // create one shape and verify we get a valid pointer btCollisionShape* shape = shapeManager.getShape(info); - if (!shape) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected shape creation for default parameters" << std::endl; - } + QCOMPARE(shape != nullptr, true); +// if (!shape) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected shape creation for default parameters" << std::endl; +// } // verify number of shapes - if (shapeManager.getNumShapes() != 1) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected one shape" << std::endl; - } + QCOMPARE(shapeManager.getNumShapes(), 1); +// if (shapeManager.getNumShapes() != 1) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected one shape" << std::endl; +// } // reference the shape again and verify that we get the same pointer btCollisionShape* otherShape = shapeManager.getShape(info); - if (otherShape != shape) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected shape* " << (void*)(shape) - << " but found shape* " << (void*)(otherShape) << std::endl; - } + QCOMPARE(otherShape, shape); +// if (otherShape != shape) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected shape* " << (void*)(shape) +// << " but found shape* " << (void*)(otherShape) << std::endl; +// } // verify number of references numReferences = shapeManager.getNumReferences(info); int expectedNumReferences = 2; - if (numReferences != expectedNumReferences) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected " << expectedNumReferences - << " references but found " << numReferences << std::endl; - } + QCOMPARE(numReferences, expectedNumReferences); +// if (numReferences != expectedNumReferences) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected " << expectedNumReferences +// << " references but found " << numReferences << std::endl; +// } // release all references bool released = shapeManager.releaseShape(info); @@ -62,59 +67,68 @@ void ShapeManagerTests::testShapeAccounting() { released = shapeManager.releaseShape(info) && released; numReferences--; } - if (!released) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected shape released" << std::endl; - } + QCOMPARE(released, true); +// if (!released) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected shape released" << std::endl; +// } // verify shape still exists (not yet garbage collected) - if (shapeManager.getNumShapes() != 1) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected one shape after release but before garbage collection" << std::endl; - } + QCOMPARE(shapeManager.getNumShapes(), 1); +// if (shapeManager.getNumShapes() != 1) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected one shape after release but before garbage collection" << std::endl; +// } // verify shape's refcount is zero numReferences = shapeManager.getNumReferences(info); - if (numReferences != 0) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected refcount = 0 for shape but found refcount = " << numReferences << std::endl; - } + QCOMPARE(numReferences, 0); +// if (numReferences != 0) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected refcount = 0 for shape but found refcount = " << numReferences << std::endl; +// } // reference the shape again and verify refcount is updated otherShape = shapeManager.getShape(info); numReferences = shapeManager.getNumReferences(info); - if (numReferences != 1) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected refcount = 1 for shape but found refcount = " << numReferences << std::endl; - } + QCOMPARE(numReferences, 1); +// if (numReferences != 1) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected refcount = 1 for shape but found refcount = " << numReferences << std::endl; +// } // verify that shape is not collected as garbage shapeManager.collectGarbage(); - if (shapeManager.getNumShapes() != 1) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected one shape after release" << std::endl; - } + QCOMPARE(shapeManager.getNumShapes(), 1); +// if (shapeManager.getNumShapes() != 1) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected one shape after release" << std::endl; +// } numReferences = shapeManager.getNumReferences(info); - if (numReferences != 1) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected refcount = 1 for shape but found refcount = " << numReferences << std::endl; - } + QCOMPARE(numReferences, 1); +// if (numReferences != 1) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected refcount = 1 for shape but found refcount = " << numReferences << std::endl; +// } // release reference and verify that it is collected as garbage released = shapeManager.releaseShape(info); shapeManager.collectGarbage(); - if (shapeManager.getNumShapes() != 0) { - std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected zero shapes after release" << std::endl; - } - if (shapeManager.hasShape(shape)) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected ignorant ShapeManager after garbage collection" << std::endl; - } + QCOMPARE(shapeManager.getNumShapes(), 0); +// if (shapeManager.getNumShapes() != 0) { +// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected zero shapes after release" << std::endl; +// } + QCOMPARE(shapeManager.hasShape(shape), false); +// if (shapeManager.hasShape(shape)) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected ignorant ShapeManager after garbage collection" << std::endl; +// } // add the shape again and verify that it gets added again otherShape = shapeManager.getShape(info); numReferences = shapeManager.getNumReferences(info); - if (numReferences != 1) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected refcount = 1 for shape but found refcount = " << numReferences << std::endl; - } + QCOMPARE(numReferences, 1); +// if (numReferences != 1) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected refcount = 1 for shape but found refcount = " << numReferences << std::endl; +// } } void ShapeManagerTests::addManyShapes() { @@ -134,49 +148,54 @@ void ShapeManagerTests::addManyShapes() { info.setBox(0.5f * scale); btCollisionShape* shape = shapeManager.getShape(info); shapes.push_back(shape); - if (!shape) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: i = " << i << " null box shape for scale = " << scale << std::endl; - } + QCOMPARE(shape != nullptr, true); +// if (!shape) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: i = " << i << " null box shape for scale = " << scale << std::endl; +// } // make a box float radius = 0.5f * s; info.setSphere(radius); shape = shapeManager.getShape(info); shapes.push_back(shape); - if (!shape) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: i = " << i << " null sphere shape for radius = " << radius << std::endl; - } + QCOMPARE(shape != nullptr, true); +// if (!shape) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: i = " << i << " null sphere shape for radius = " << radius << std::endl; +// } } // verify shape count int numShapes = shapeManager.getNumShapes(); - if (numShapes != 2 * numSizes) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected numShapes = " << numSizes << " but found numShapes = " << numShapes << std::endl; - } + QCOMPARE(numShapes, 2 * numSizes); +// if (numShapes != 2 * numSizes) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected numShapes = " << numSizes << " but found numShapes = " << numShapes << std::endl; +// } // release each shape by pointer for (int i = 0; i < numShapes; ++i) { btCollisionShape* shape = shapes[i]; bool success = shapeManager.releaseShape(shape); - if (!success) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: failed to release shape index " << i << std::endl; - break; - } + QCOMPARE(success, true); +// if (!success) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: failed to release shape index " << i << std::endl; +// break; +// } } // verify zero references for (int i = 0; i < numShapes; ++i) { btCollisionShape* shape = shapes[i]; int numReferences = shapeManager.getNumReferences(shape); - if (numReferences != 0) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: expected zero references for shape " << i - << " but refCount = " << numReferences << std::endl; - } + QCOMPARE(numReferences, 0); +// if (numReferences != 0) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: expected zero references for shape " << i +// << " but refCount = " << numReferences << std::endl; +// } } } @@ -190,10 +209,11 @@ void ShapeManagerTests::addBoxShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); - if (shape != otherShape) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: Box ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; - } + QCOMPARE(shape, otherShape); +// if (shape != otherShape) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: Box ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; +// } } void ShapeManagerTests::addSphereShape() { @@ -206,10 +226,11 @@ void ShapeManagerTests::addSphereShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); - if (shape != otherShape) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: Sphere ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; - } + QCOMPARE(shape, otherShape); +// if (shape != otherShape) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: Sphere ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; +// } } void ShapeManagerTests::addCylinderShape() { @@ -224,10 +245,11 @@ void ShapeManagerTests::addCylinderShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); - if (shape != otherShape) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: Cylinder ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; - } + QCOMPARE(shape, otherShape); +// if (shape != otherShape) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: Cylinder ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; +// } */ } @@ -243,18 +265,10 @@ void ShapeManagerTests::addCapsuleShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); - if (shape != otherShape) { - std::cout << __FILE__ << ":" << __LINE__ - << " ERROR: Capsule ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; - } + QCOMPARE(shape, otherShape); +// if (shape != otherShape) { +// std::cout << __FILE__ << ":" << __LINE__ +// << " ERROR: Capsule ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; +// } */ } - -//void ShapeManagerTests::runAllTests() { -// testShapeAccounting(); -// addManyShapes(); -// addBoxShape(); -// addSphereShape(); -// addCylinderShape(); -// addCapsuleShape(); -//} diff --git a/tests/physics/src/ShapeManagerTests.h b/tests/physics/src/ShapeManagerTests.h index 885eb2ceb1..a4b7fbecd1 100644 --- a/tests/physics/src/ShapeManagerTests.h +++ b/tests/physics/src/ShapeManagerTests.h @@ -24,7 +24,6 @@ private slots: void addSphereShape(); void addCylinderShape(); void addCapsuleShape(); -// void runAllTests(); }; #endif // hifi_ShapeManagerTests_h