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")
foreach(DIR ${TEST_SUBDIRS})
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}")
set(TEST_PROJ_NAME ${DIR})
message(STATUS "Adding " ${DIR})
add_subdirectory(${DIR})
set_target_properties("${DIR}-tests" PROPERTIES FOLDER "Tests")
endif()
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
link_hifi_libraries(shared audio networking)
# Declare dependencies
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
link_hifi_libraries(shared networking)
copy_dlls_beside_windows_executable()
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
link_hifi_libraries(shared networking)
copy_dlls_beside_windows_executable()
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
link_hifi_libraries(shared octree gpu model fbx networking environment entities avatars audio animation script-engine physics)
copy_dlls_beside_windows_executable()
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)
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()
setup_hifi_testcase(Script)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,14 +12,19 @@
#ifndef hifi_ShapeManagerTests_h
#define hifi_ShapeManagerTests_h
namespace ShapeManagerTests {
#include <QtTest/QtTest>
class ShapeManagerTests : public QObject {
Q_OBJECT
private slots:
void testShapeAccounting();
void addManyShapes();
void addBoxShape();
void addSphereShape();
void addCylinderShape();
void addCapsuleShape();
void runAllTests();
}
// void runAllTests();
};
#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
//
#include "ShapeColliderTests.h"
#include <QtTest/QtTest>
//#include <QtConcurrent>
//#include "ShapeColliderTests.h"
#include "ShapeInfoTests.h"
#include "ShapeManagerTests.h"
#include "BulletUtilTests.h"
//#include "BulletUtilTests.h"
#include "MeshMassPropertiesTests.h"
int main(int argc, char** argv) {
ShapeColliderTests::runAllTests();
ShapeInfoTests::runAllTests();
ShapeManagerTests::runAllTests();
BulletUtilTests::runAllTests();
MeshMassPropertiesTests::runAllTests();
return 0;
}
//int main(int argc, char** argv) {
// ShapeColliderTests::runAllTests();
// ShapeInfoTests::runAllTests();
// ShapeManagerTests::runAllTests();
// BulletUtilTests::runAllTests();
// MeshMassPropertiesTests::runAllTests();
// 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_hifi_libraries(render-utils gpu shared)
# link in the shared libraries
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_hifi_libraries(shared)
# link in the shared libraries
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)
add_dependency_external_projects(glew)
find_package(GLEW REQUIRED)
target_include_directories(${TARGET_NAME} PRIVATE ${GLEW_INCLUDE_DIRS})
target_link_libraries(${TARGET_NAME} ${GLEW_LIBRARIES} wsock32.lib opengl32.lib Winmm.lib)
endif()
# Declare testcase dependencies
macro (setup_testcase_dependencies)
if (WIN32)
add_dependency_external_projects(glew)
find_package(GLEW REQUIRED)
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
link_hifi_libraries(ui render-utils gpu shared)
copy_dlls_beside_windows_executable()
setup_hifi_testcase(Widgets OpenGL Network Qml Quick Script)