Setup cmake build files for QtTest-based unit tests.

This commit is contained in:
Seiji Emery 2015-06-19 21:39:34 -07:00
parent 587bf78826
commit 64922ecc62
24 changed files with 247 additions and 181 deletions

View file

@ -3,7 +3,8 @@ file(GLOB TEST_SUBDIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_S
list(REMOVE_ITEM TEST_SUBDIRS "CMakeFiles") list(REMOVE_ITEM TEST_SUBDIRS "CMakeFiles")
foreach(DIR ${TEST_SUBDIRS}) foreach(DIR ${TEST_SUBDIRS})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}") if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}")
set(TEST_PROJ_NAME ${DIR})
message(STATUS "Adding " ${DIR})
add_subdirectory(${DIR}) add_subdirectory(${DIR})
set_target_properties("${DIR}-tests" PROPERTIES FOLDER "Tests")
endif() endif()
endforeach() endforeach()

View file

@ -1,8 +1,12 @@
set(TARGET_NAME audio-tests)
setup_hifi_project() message(STATUS "TEST_PROJ_NAME = " ${TEST_PROJ_NAME})
# link in the shared libraries # Declare dependencies
link_hifi_libraries(shared audio networking) macro (SETUP_TESTCASE_DEPENDENCIES)
# link in the shared libraries
link_hifi_libraries(shared audio networking)
copy_dlls_beside_windows_executable() copy_dlls_beside_windows_executable()
endmacro ()
setup_hifi_testcase()

View file

@ -1,8 +1,10 @@
set(TARGET_NAME jitter-tests)
setup_hifi_project() # Declare dependencies
macro (setup_testcase_dependencies)
# link in the shared libraries
link_hifi_libraries(shared networking)
# link in the shared libraries copy_dlls_beside_windows_executable()
link_hifi_libraries(shared networking) endmacro()
copy_dlls_beside_windows_executable() setup_hifi_testcase()

View file

@ -1,8 +1,10 @@
set(TARGET_NAME networking-tests)
setup_hifi_project() # Declare dependencies
macro (setup_testcase_dependencies)
# link in the shared libraries
link_hifi_libraries(shared networking)
# link in the shared libraries copy_dlls_beside_windows_executable()
link_hifi_libraries(shared networking) endmacro ()
copy_dlls_beside_windows_executable() setup_hifi_testcase()

View file

@ -1,8 +1,10 @@
set(TARGET_NAME octree-tests)
setup_hifi_project(Script Network) # Declare dependencies
macro (setup_testcase_dependencies)
# link in the shared libraries
link_hifi_libraries(shared octree gpu model fbx networking environment entities avatars audio animation script-engine physics)
# link in the shared libraries copy_dlls_beside_windows_executable()
link_hifi_libraries(shared octree gpu model fbx networking environment entities avatars audio animation script-engine physics) endmacro ()
copy_dlls_beside_windows_executable() setup_hifi_testcase(Script Network)

View file

@ -1,17 +1,19 @@
set(TARGET_NAME physics-tests)
setup_hifi_project() # Declare dependencies
macro (ADD_TESTCASE_DEPENDENCIES)
add_dependency_external_projects(glm)
find_package(GLM REQUIRED)
target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
add_dependency_external_projects(bullet)
find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
link_hifi_libraries(shared physics)
copy_dlls_beside_windows_executable()
endmacro ()
add_dependency_external_projects(glm) setup_hifi_testcase(Script)
find_package(GLM REQUIRED)
target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS})
add_dependency_external_projects(bullet)
find_package(Bullet REQUIRED)
target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES})
link_hifi_libraries(shared physics)
copy_dlls_beside_windows_executable()

View file

@ -19,10 +19,12 @@
void BulletUtilTests::fromBulletToGLM() { void BulletUtilTests::fromBulletToGLM() {
btVector3 bV(1.23f, 4.56f, 7.89f); btVector3 bV(1.23f, 4.56f, 7.89f);
glm::vec3 gV = bulletToGLM(bV); glm::vec3 gV = bulletToGLM(bV);
if (gV.x != bV.getX()) {
std::cout << __FILE__ << ":" << __LINE__ QCOMPARE(gV.x, bV.getX());
<< " ERROR: x mismatch bullet.x = " << bV.getX() << " != glm.x = " << gV.x << std::endl; // if (gV.x != bV .getX()) {
} // std::cout << __FILE__ << ":" << __LINE__
// << " ERROR: x mismatch bullet.x = " << bV.getX() << " != glm.x = " << gV.x << std::endl;
// }
if (gV.y != bV.getY()) { if (gV.y != bV.getY()) {
std::cout << __FILE__ << ":" << __LINE__ std::cout << __FILE__ << ":" << __LINE__
<< " ERROR: x mismatch bullet.y = " << bV.getY() << " != glm.y = " << gV.y << std::endl; << " ERROR: x mismatch bullet.y = " << bV.getY() << " != glm.y = " << gV.y << std::endl;
@ -96,7 +98,10 @@ void BulletUtilTests::fromGLMToBullet() {
} }
} }
void BulletUtilTests::runAllTests() { QTEST_MAIN(BulletUtilTests)
fromBulletToGLM();
fromGLMToBullet();
} //void BulletUtilTests::runAllTests() {
// fromBulletToGLM();
// fromGLMToBullet();
//}

View file

@ -12,10 +12,15 @@
#ifndef hifi_BulletUtilTests_h #ifndef hifi_BulletUtilTests_h
#define hifi_BulletUtilTests_h #define hifi_BulletUtilTests_h
namespace BulletUtilTests { #include <QtTest/QtTest>
class BulletUtilTests : public QObject {
Q_OBJECT
private slots:
void fromBulletToGLM(); void fromBulletToGLM();
void fromGLMToBullet(); void fromGLMToBullet();
void runAllTests(); // void runAllTests();
} };
#endif // hifi_BulletUtilTests_h #endif // hifi_BulletUtilTests_h

View file

@ -106,7 +106,9 @@ void CollisionInfoTests::translateThenRotate() {
} }
*/ */
void CollisionInfoTests::runAllTests() { QTEST_MAIN(CollisionInfoTests)
//void CollisionInfoTests::runAllTests() {
// CollisionInfoTests::rotateThenTranslate(); // CollisionInfoTests::rotateThenTranslate();
// CollisionInfoTests::translateThenRotate(); // CollisionInfoTests::translateThenRotate();
} //}

View file

@ -12,12 +12,16 @@
#ifndef hifi_CollisionInfoTests_h #ifndef hifi_CollisionInfoTests_h
#define hifi_CollisionInfoTests_h #define hifi_CollisionInfoTests_h
namespace CollisionInfoTests { #include <QtTest/QtTest>
class CollisionInfoTests : public QObject {
Q_OBJECT
private slots:
// void rotateThenTranslate(); // void rotateThenTranslate();
// void translateThenRotate(); // void translateThenRotate();
void runAllTests(); // void runAllTests();
} };
#endif // hifi_CollisionInfoTests_h #endif // hifi_CollisionInfoTests_h

View file

@ -449,11 +449,11 @@ void MeshMassPropertiesTests::testBoxAsMesh() {
#endif // VERBOSE_UNIT_TESTS #endif // VERBOSE_UNIT_TESTS
} }
void MeshMassPropertiesTests::runAllTests() { //void MeshMassPropertiesTests::runAllTests() {
testParallelAxisTheorem(); // testParallelAxisTheorem();
testTetrahedron(); // testTetrahedron();
testOpenTetrahedonMesh(); // testOpenTetrahedonMesh();
testClosedTetrahedronMesh(); // testClosedTetrahedronMesh();
testBoxAsMesh(); // testBoxAsMesh();
//testWithCube(); // //testWithCube();
} //}

View file

@ -11,12 +11,18 @@
#ifndef hifi_MeshMassPropertiesTests_h #ifndef hifi_MeshMassPropertiesTests_h
#define hifi_MeshMassPropertiesTests_h #define hifi_MeshMassPropertiesTests_h
namespace MeshMassPropertiesTests{
#include <QtTest/QtTest>
class MeshMassPropertiesTests : public QObject {
Q_OBJECT
private slots:
void testParallelAxisTheorem(); void testParallelAxisTheorem();
void testTetrahedron(); void testTetrahedron();
void testOpenTetrahedonMesh(); void testOpenTetrahedonMesh();
void testClosedTetrahedronMesh(); void testClosedTetrahedronMesh();
void testBoxAsMesh(); void testBoxAsMesh();
void runAllTests(); // void runAllTests();
} };
#endif // hifi_MeshMassPropertiesTests_h #endif // hifi_MeshMassPropertiesTests_h

View file

@ -1,22 +0,0 @@
//
// PhysicsTestUtil.cpp
// 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
//
#include <glm/gtc/type_ptr.hpp>
#include "PhysicsTestUtil.h"
#include "StreamUtils.h"
std::ostream& operator<<(std::ostream& s, const CollisionInfo& c) {
s << "[penetration=" << c._penetration
<< ", contactPoint=" << c._contactPoint
<< ", addedVelocity=" << c._addedVelocity;
return s;
}

View file

@ -21,6 +21,11 @@ const glm::vec3 xAxis(1.0f, 0.0f, 0.0f);
const glm::vec3 yAxis(0.0f, 1.0f, 0.0f); const glm::vec3 yAxis(0.0f, 1.0f, 0.0f);
const glm::vec3 zAxis(0.0f, 0.0f, 1.0f); const glm::vec3 zAxis(0.0f, 0.0f, 1.0f);
std::ostream& operator<<(std::ostream& s, const CollisionInfo& c); inline std::ostream& operator<<(std::ostream& s, const CollisionInfo& c) {
return s << "[penetration=" << c._penetration
<< ", contactPoint=" << c._contactPoint
<< ", addedVelocity=" << c._addedVelocity
<< "]";
}
#endif // hifi_PhysicsTestUtil_h #endif // hifi_PhysicsTestUtil_h

View file

@ -2507,36 +2507,36 @@ void ShapeColliderTests::measureTimeOfCollisionDispatch() {
*/ */
} }
void ShapeColliderTests::runAllTests() { //void ShapeColliderTests::runAllTests() {
ShapeCollider::initDispatchTable(); // ShapeCollider::initDispatchTable();
//
//measureTimeOfCollisionDispatch(); // //measureTimeOfCollisionDispatch();
//
sphereMissesSphere(); // sphereMissesSphere();
sphereTouchesSphere(); // sphereTouchesSphere();
//
sphereMissesCapsule(); // sphereMissesCapsule();
sphereTouchesCapsule(); // sphereTouchesCapsule();
//
capsuleMissesCapsule(); // capsuleMissesCapsule();
capsuleTouchesCapsule(); // capsuleTouchesCapsule();
//
sphereMissesAACube(); // sphereMissesAACube();
sphereTouchesAACubeFaces(); // sphereTouchesAACubeFaces();
sphereTouchesAACubeEdges(); // sphereTouchesAACubeEdges();
sphereTouchesAACubeCorners(); // sphereTouchesAACubeCorners();
//
capsuleMissesAACube(); // capsuleMissesAACube();
capsuleTouchesAACube(); // capsuleTouchesAACube();
//
rayHitsSphere(); // rayHitsSphere();
rayBarelyHitsSphere(); // rayBarelyHitsSphere();
rayBarelyMissesSphere(); // rayBarelyMissesSphere();
rayHitsCapsule(); // rayHitsCapsule();
rayMissesCapsule(); // rayMissesCapsule();
rayHitsPlane(); // rayHitsPlane();
rayMissesPlane(); // rayMissesPlane();
//
rayHitsAACube(); // rayHitsAACube();
rayMissesAACube(); // rayMissesAACube();
} //}

View file

@ -12,8 +12,12 @@
#ifndef hifi_ShapeColliderTests_h #ifndef hifi_ShapeColliderTests_h
#define hifi_ShapeColliderTests_h #define hifi_ShapeColliderTests_h
namespace ShapeColliderTests { #include <QtTest/QtTest>
class ShapeColliderTests : public QObject {
Q_OBJECT
private slots:
void sphereMissesSphere(); void sphereMissesSphere();
void sphereTouchesSphere(); void sphereTouchesSphere();
@ -43,7 +47,7 @@ namespace ShapeColliderTests {
void measureTimeOfCollisionDispatch(); void measureTimeOfCollisionDispatch();
void runAllTests(); // void runAllTests();
} };
#endif // hifi_ShapeColliderTests_h #endif // hifi_ShapeColliderTests_h

View file

@ -234,13 +234,13 @@ void ShapeInfoTests::testCapsuleShape() {
*/ */
} }
void ShapeInfoTests::runAllTests() { //void ShapeInfoTests::runAllTests() {
//#define MANUAL_TEST ////#define MANUAL_TEST
#ifdef MANUAL_TEST //#ifdef MANUAL_TEST
testHashFunctions(); // testHashFunctions();
#endif // MANUAL_TEST //#endif // MANUAL_TEST
testBoxShape(); // testBoxShape();
testSphereShape(); // testSphereShape();
testCylinderShape(); // testCylinderShape();
testCapsuleShape(); // testCapsuleShape();
} //}

View file

@ -12,13 +12,17 @@
#ifndef hifi_ShapeInfoTests_h #ifndef hifi_ShapeInfoTests_h
#define hifi_ShapeInfoTests_h #define hifi_ShapeInfoTests_h
namespace ShapeInfoTests { #include <QtTest/QtTest>
class ShapeInfoTests : public QObject {
Q_OBJECT
private slots:
void testHashFunctions(); void testHashFunctions();
void testBoxShape(); void testBoxShape();
void testSphereShape(); void testSphereShape();
void testCylinderShape(); void testCylinderShape();
void testCapsuleShape(); void testCapsuleShape();
void runAllTests(); // void runAllTests();
} };
#endif // hifi_ShapeInfoTests_h #endif // hifi_ShapeInfoTests_h

View file

@ -248,11 +248,11 @@ void ShapeManagerTests::addCapsuleShape() {
*/ */
} }
void ShapeManagerTests::runAllTests() { //void ShapeManagerTests::runAllTests() {
testShapeAccounting(); // testShapeAccounting();
addManyShapes(); // addManyShapes();
addBoxShape(); // addBoxShape();
addSphereShape(); // addSphereShape();
addCylinderShape(); // addCylinderShape();
addCapsuleShape(); // addCapsuleShape();
} //}

View file

@ -12,14 +12,19 @@
#ifndef hifi_ShapeManagerTests_h #ifndef hifi_ShapeManagerTests_h
#define hifi_ShapeManagerTests_h #define hifi_ShapeManagerTests_h
namespace ShapeManagerTests { #include <QtTest/QtTest>
class ShapeManagerTests : public QObject {
Q_OBJECT
private slots:
void testShapeAccounting(); void testShapeAccounting();
void addManyShapes(); void addManyShapes();
void addBoxShape(); void addBoxShape();
void addSphereShape(); void addSphereShape();
void addCylinderShape(); void addCylinderShape();
void addCapsuleShape(); void addCapsuleShape();
void runAllTests(); // void runAllTests();
} };
#endif // hifi_ShapeManagerTests_h #endif // hifi_ShapeManagerTests_h

View file

@ -8,17 +8,45 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "ShapeColliderTests.h" #include <QtTest/QtTest>
//#include <QtConcurrent>
//#include "ShapeColliderTests.h"
#include "ShapeInfoTests.h" #include "ShapeInfoTests.h"
#include "ShapeManagerTests.h" #include "ShapeManagerTests.h"
#include "BulletUtilTests.h" //#include "BulletUtilTests.h"
#include "MeshMassPropertiesTests.h" #include "MeshMassPropertiesTests.h"
int main(int argc, char** argv) { //int main(int argc, char** argv) {
ShapeColliderTests::runAllTests(); // ShapeColliderTests::runAllTests();
ShapeInfoTests::runAllTests(); // ShapeInfoTests::runAllTests();
ShapeManagerTests::runAllTests(); // ShapeManagerTests::runAllTests();
BulletUtilTests::runAllTests(); // BulletUtilTests::runAllTests();
MeshMassPropertiesTests::runAllTests(); // MeshMassPropertiesTests::runAllTests();
return 0; // return 0;
} //}
//QTEST_MAIN(BulletUtilTests)
// Custom main function to run multiple unit tests. Just copy + paste this into future tests.
//#define RUN_TEST(Test) { Test test; runTest(test); }
#define RUN_TEST(Test) { runTest(new Test()); }
int main (int argc, const char ** argv) {
QStringList args;
for (int i = 0; i < argc; ++i)
args.append(QString { argv[i] });
int status = 0;
auto runTest = [&status, args] (QObject * test) {
status |= QTest::qExec(test, args);
};
// Run test classes
// RUN_TEST(ShapeColliderTests)
RUN_TEST(ShapeInfoTests)
RUN_TEST(ShapeManagerTests)
// RUN_TEST(BulletUtilTests)
RUN_TEST(MeshMassPropertiesTests)
return status;
}

View file

@ -1,10 +1,12 @@
set(TARGET_NAME render-utils-tests)
setup_hifi_project(Quick Gui OpenGL)
#include_oglplus() # Declare dependencies
macro (setup_testcase_dependencies)
#include_oglplus()
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(render-utils gpu shared) link_hifi_libraries(render-utils gpu shared)
copy_dlls_beside_windows_executable() copy_dlls_beside_windows_executable()
endmacro ()
setup_hifi_testcase(Quick Gui OpenGL)

View file

@ -1,8 +1,11 @@
set(TARGET_NAME shared-tests)
setup_hifi_project() # Declare dependencies
macro (setup_testcase_dependencies)
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(shared) link_hifi_libraries(shared)
copy_dlls_beside_windows_executable() copy_dlls_beside_windows_executable()
endmacro ()
setup_hifi_testcase()

View file

@ -1,15 +1,17 @@
set(TARGET_NAME ui-tests)
setup_hifi_project(Widgets OpenGL Network Qml Quick Script)
if (WIN32) # Declare testcase dependencies
add_dependency_external_projects(glew) macro (setup_testcase_dependencies)
find_package(GLEW REQUIRED) if (WIN32)
target_include_directories(${TARGET_NAME} PRIVATE ${GLEW_INCLUDE_DIRS}) add_dependency_external_projects(glew)
target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARIES} wsock32.lib opengl32.lib Winmm.lib) find_package(GLEW REQUIRED)
endif() target_include_directories(${TARGET_NAME} PRIVATE ${GLEW_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARIES} wsock32.lib opengl32.lib Winmm.lib)
endif()
# link in the shared libraries
link_hifi_libraries(ui render-utils gpu shared)
copy_dlls_beside_windows_executable()
endmacro()
# link in the shared libraries setup_hifi_testcase(Widgets OpenGL Network Qml Quick Script)
link_hifi_libraries(ui render-utils gpu shared)
copy_dlls_beside_windows_executable()