From a48adf5ce522bf336d2f461a56a1e62553b3fe0f Mon Sep 17 00:00:00 2001 From: Seiji Emery Date: Tue, 30 Jun 2015 14:12:58 -0700 Subject: [PATCH] Cleanup + formatting --- cmake/macros/SetupHFTestCase.cmake | 139 ++++ cmake/macros/SetupHifiTestCase.cmake | 139 ---- tests/CMakeLists.txt | 29 +- tests/QTestExtensions.h | 92 +-- tests/audio/CMakeLists.txt | 6 +- tests/audio/src/AudioRingBufferTests.cpp | 4 +- tests/jitter/CMakeLists.txt | 6 +- tests/jitter/src/JitterTests.h | 8 +- tests/networking/CMakeLists.txt | 6 +- .../src/SequenceNumberStatsTests.cpp | 2 +- .../networking/src/SequenceNumberStatsTests.h | 2 +- tests/octree/CMakeLists.txt | 6 +- tests/octree/src/AABoxCubeTests.h | 1 - tests/octree/src/OctreeTests.cpp | 1 - tests/physics/CMakeLists.txt | 24 +- tests/physics/src/BulletTestUtils.h | 30 +- tests/physics/src/BulletUtilTests.cpp | 9 - tests/physics/src/BulletUtilTests.h | 1 - tests/physics/src/CollisionInfoTests.cpp | 42 -- tests/physics/src/MeshMassPropertiesTests.cpp | 186 +----- tests/physics/src/ShapeColliderTests.cpp | 631 +----------------- tests/physics/src/ShapeInfoTests.cpp | 52 +- tests/physics/src/ShapeManagerTests.cpp | 89 --- tests/shared/CMakeLists.txt | 6 +- tests/shared/src/MovingPercentileTests.cpp | 151 ----- tests/ui/CMakeLists.txt | 8 +- 26 files changed, 268 insertions(+), 1402 deletions(-) create mode 100644 cmake/macros/SetupHFTestCase.cmake delete mode 100644 cmake/macros/SetupHifiTestCase.cmake diff --git a/cmake/macros/SetupHFTestCase.cmake b/cmake/macros/SetupHFTestCase.cmake new file mode 100644 index 0000000000..ce8ec4079f --- /dev/null +++ b/cmake/macros/SetupHFTestCase.cmake @@ -0,0 +1,139 @@ +# +# SetupHFTestCase.cmake +# +# Copyright 2015 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 +# + +# Sets up a hifi testcase using QtTest. +# Can be called with arguments; like setup_hifi_project, the arguments correspond to qt modules, so call it +# via setup_hifi_testcase(Script Network Qml) to build the testcase with Qt5Script, Qt5Network, and Qt5Qml linked, +# for example. + +# One special quirk of this is that because we are creating multiple testcase targets (instead of just one), +# any dependencies and other setup that the testcase has must be declared in a macro, and setup_hifi_testcase() +# must be called *after* this declaration, not before it. + +# Here's a full example: +# tests/my-foo-test/CMakeLists.txt: +# +# # Declare testcase dependencies +# macro (setup_hifi_testcase) +# bunch +# of +# custom +# dependencies... +# +# link_hifi_libraries(shared networking etc) +# +# copy_dlls_beside_windows_executable() +# endmacro() +# +# setup_hifi_testcase(Network etc) +# +# Additionally, all .cpp files in the src dir (eg tests/my-foo-test/src) must: +# - Contain exactly one test class (any supporting code must be either external or inline in a .hpp file) +# - Be built against QtTestLib (test class should be a QObject, with test methods defined as private slots) +# - Contain a QTEST_MAIN declaration at the end of the file (or at least be a standalone executable) +# +# All other testing infrastructure is generated automatically. +# + +macro(SETUP_HIFI_TESTCASE) + if (NOT DEFINED TEST_PROJ_NAME) + message(SEND_ERROR "Missing TEST_PROJ_NAME (setup_hifi_testcase was called incorrectly?)") + elseif (NOT COMMAND SETUP_TESTCASE_DEPENDENCIES) + message(SEND_ERROR "Missing testcase dependencies declaration (SETUP_TESTCASE_DEPENDENCIES)") + elseif (DEFINED ${TEST_PROJ_NAME}_BUILT) + message(WARNING "testcase \"" ${TEST_PROJ_NAME} "\" was already built") + else () + set(${TEST_PROJ_NAME}_BUILT 1) + + file(GLOB TEST_PROJ_SRC_FILES src/*) + file(GLOB TEST_PROJ_SRC_SUBDIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/*) + + foreach (DIR ${TEST_PROJ_SRC_SUBDIRS}) + if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/${DIR}") + file(GLOB DIR_CONTENTS "src/${DIR}/*") + set(TEST_PROJ_SRC_FILES ${TEST_PROJ_SRC_FILES} "${DIR_CONTENTS}") + endif() + endforeach() + + # Find test classes to build into test executables. + # Warn about any .cpp files that are *not* test classes (*Test[s].cpp), since those files will not be used. + foreach (SRC_FILE ${TEST_PROJ_SRC_FILES}) + string(REGEX MATCH ".+Tests?\\.cpp$" TEST_CPP_FILE ${SRC_FILE}) + string(REGEX MATCH ".+\\.cpp$" NON_TEST_CPP_FILE ${SRC_FILE}) + if (TEST_CPP_FILE) + list(APPEND TEST_CASE_FILES ${TEST_CPP_FILE}) + elseif (NON_TEST_CPP_FILE) + message(WARNING "ignoring .cpp file (not a test class -- this will not be linked or compiled!): " ${NON_TEST_CPP_FILE}) + endif () + endforeach () + + if (TEST_CASE_FILES) + set(TEST_PROJ_TARGETS "") + + # Add each test class executable (duplicates functionality in SetupHifiProject.cmake) + # The resulting targets will be buried inside of hidden/test-executables so that they don't clutter up + # the project view in Xcode, Visual Studio, etc. + foreach (TEST_FILE ${TEST_CASE_FILES}) + get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) + set(TARGET_NAME ${TEST_PROJ_NAME}-${TEST_NAME}) + + project(${TARGET_NAME}) + + # grab the implemenation and header files + set(TARGET_SRCS ${TEST_FILE}) # only one source / .cpp file (the test class) + + add_executable(${TARGET_NAME} ${TEST_FILE}) + add_test(${TARGET_NAME}-test ${TARGET_NAME}) + set_target_properties(${TARGET_NAME} PROPERTIES + EXCLUDE_FROM_DEFAULT_BUILD TRUE + EXCLUDE_FROM_ALL TRUE) + + list (APPEND ${TEST_PROJ_NAME}_TARGETS ${TARGET_NAME}) + #list (APPEND ALL_TEST_TARGETS ${TARGET_NAME}) + + set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN}) + + list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core Test) + + # find these Qt modules and link them to our own target + find_package(Qt5 COMPONENTS ${${TARGET_NAME}_DEPENDENCY_QT_MODULES} REQUIRED) + + foreach(QT_MODULE ${${TARGET_NAME}_DEPENDENCY_QT_MODULES}) + target_link_libraries(${TARGET_NAME} Qt5::${QT_MODULE}) + endforeach() + + set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "hidden/test-executables") + + # handle testcase-specific dependencies (this a macro that should be defined in the cmakelists.txt file in each tests subdir) + + SETUP_TESTCASE_DEPENDENCIES () + endforeach () + + set(TEST_TARGET ${TEST_PROJ_NAME}-tests) + + # Add a dummy target so that the project files are visible. + # This target will also build + run the other test targets using ctest when built. + + add_custom_target(${TEST_TARGET} + COMMAND ctest . + SOURCES ${TEST_PROJ_SRC_FILES} # display source files under the testcase target + DEPENDS ${${TEST_PROJ_NAME}_TARGETS}) + set_target_properties(${TEST_TARGET} PROPERTIES + EXCLUDE_FROM_DEFAULT_BUILD TRUE + EXCLUDE_FROM_ALL TRUE) + + set_target_properties(${TEST_TARGET} PROPERTIES FOLDER "Tests") + + list (APPEND ALL_TEST_TARGETS ${TEST_TARGET}) + set(ALL_TEST_TARGETS "${ALL_TEST_TARGETS}" PARENT_SCOPE) + else () + message(WARNING "No testcases in " ${TEST_PROJ_NAME}) + endif () + endif () +endmacro(SETUP_HIFI_TESTCASE) \ No newline at end of file diff --git a/cmake/macros/SetupHifiTestCase.cmake b/cmake/macros/SetupHifiTestCase.cmake deleted file mode 100644 index 867e0d6210..0000000000 --- a/cmake/macros/SetupHifiTestCase.cmake +++ /dev/null @@ -1,139 +0,0 @@ -# -# SetupHifiTestCase.cmake -# -# Copyright 2015 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 -# - -# Sets up a hifi testcase using QtTest. -# Can be called with arguments; like setup_hifi_project, the arguments correspond to qt modules, so call it -# via setup_hifi_testcase(Script Network Qml) to build the testcase with Qt5Script, Qt5Network, and Qt5Qml linked, -# for example. - -# One special quirk of this is that because we are creating multiple testcase targets (instead of just one), -# any dependencies and other setup that the testcase has must be declared in a macro, and setup_hifi_testcase() -# must be called *after* this declaration, not before it. - -# Here's a full example: -# tests/my-foo-test/CMakeLists.txt: -# -# # Declare testcase dependencies -# macro (setup_hifi_testcase) -# bunch -# of -# custom -# dependencies... -# -# link_hifi_libraries(shared networking etc) -# -# copy_dlls_beside_windows_executable() -# endmacro() -# -# setup_hifi_testcase(Network etc) -# -# Additionally, all .cpp files in the src dir (eg tests/my-foo-test/src) must: -# - Contain exactly one test class (any supporting code must be either external or inline in a .hpp file) -# - Be built against QtTestLib (test class should be a QObject, with test methods defined as private slots) -# - Contain a QTEST_MAIN declaration at the end of the file (or at least be a standalone executable) -# -# All other testing infrastructure is generated automatically. -# - -macro(SETUP_HIFI_TESTCASE) - if (NOT DEFINED TEST_PROJ_NAME) - message(SEND_ERROR "Missing TEST_PROJ_NAME (setup_hifi_testcase was called incorrectly?)") - elseif (NOT COMMAND SETUP_TESTCASE_DEPENDENCIES) - message(SEND_ERROR "Missing testcase dependencies declaration (SETUP_TESTCASE_DEPENDENCIES)") - elseif (DEFINED ${TEST_PROJ_NAME}_BUILT) - message(WARNING "testcase \"" ${TEST_PROJ_NAME} "\" was already built") - else () - set(${TEST_PROJ_NAME}_BUILT 1) - - file(GLOB TEST_PROJ_SRC_FILES src/*) - file(GLOB TEST_PROJ_SRC_SUBDIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/src/*) - - foreach (DIR ${TEST_PROJ_SRC_SUBDIRS}) - if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/src/${DIR}") - file(GLOB DIR_CONTENTS "src/${DIR}/*") - set(TEST_PROJ_SRC_FILES ${TEST_PROJ_SRC_FILES} "${DIR_CONTENTS}") - endif() - endforeach() - - # Find test classes to build into test executables. - # Warn about any .cpp files that are *not* test classes (*Test[s].cpp), since those files will not be used. - foreach (SRC_FILE ${TEST_PROJ_SRC_FILES}) - string(REGEX MATCH ".+Tests?\\.cpp$" TEST_CPP_FILE ${SRC_FILE}) - string(REGEX MATCH ".+\\.cpp$" NON_TEST_CPP_FILE ${SRC_FILE}) - if (TEST_CPP_FILE) - list(APPEND TEST_CASE_FILES ${TEST_CPP_FILE}) - elseif (NON_TEST_CPP_FILE) - message(WARNING "ignoring .cpp file (not a test class -- this will not be linked or compiled!): " ${NON_TEST_CPP_FILE}) - endif () - endforeach () - - if (TEST_CASE_FILES) - set(TEST_PROJ_TARGETS "") - - # Add each test class executable (duplicates functionality in SetupHifiProject.cmake) - # The resulting targets will be buried inside of hidden/test-executables so that they don't clutter up - # the project view in Xcode, Visual Studio, etc. - foreach (TEST_FILE ${TEST_CASE_FILES}) - get_filename_component(TEST_NAME ${TEST_FILE} NAME_WE) - set(TARGET_NAME ${TEST_PROJ_NAME}-${TEST_NAME}) - - project(${TARGET_NAME}) - - # grab the implemenation and header files - set(TARGET_SRCS ${TEST_FILE}) # only one source / .cpp file (the test class) - - add_executable(${TARGET_NAME} ${TEST_FILE}) - add_test(${TARGET_NAME}-test ${TARGET_NAME}) - set_target_properties(${TARGET_NAME} PROPERTIES - EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE) - - list (APPEND ${TEST_PROJ_NAME}_TARGETS ${TARGET_NAME}) - #list (APPEND ALL_TEST_TARGETS ${TARGET_NAME}) - - set(${TARGET_NAME}_DEPENDENCY_QT_MODULES ${ARGN}) - - list(APPEND ${TARGET_NAME}_DEPENDENCY_QT_MODULES Core Test) - - # find these Qt modules and link them to our own target - find_package(Qt5 COMPONENTS ${${TARGET_NAME}_DEPENDENCY_QT_MODULES} REQUIRED) - - foreach(QT_MODULE ${${TARGET_NAME}_DEPENDENCY_QT_MODULES}) - target_link_libraries(${TARGET_NAME} Qt5::${QT_MODULE}) - endforeach() - - set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "hidden/test-executables") - - # handle testcase-specific dependencies (this a macro that should be defined in the cmakelists.txt file in each tests subdir) - - SETUP_TESTCASE_DEPENDENCIES () - endforeach () - - set(TEST_TARGET ${TEST_PROJ_NAME}-tests) - - # Add a dummy target so that the project files are visible. - # This target will also build + run the other test targets using ctest when built. - - add_custom_target(${TEST_TARGET} - COMMAND ctest . - SOURCES ${TEST_PROJ_SRC_FILES} # display source files under the testcase target - DEPENDS ${${TEST_PROJ_NAME}_TARGETS}) - set_target_properties(${TEST_TARGET} PROPERTIES - EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE) - - set_target_properties(${TEST_TARGET} PROPERTIES FOLDER "Tests") - - list (APPEND ALL_TEST_TARGETS ${TEST_TARGET}) - set(ALL_TEST_TARGETS "${ALL_TEST_TARGETS}" PARENT_SCOPE) - else () - message(WARNING "No testcases in " ${TEST_PROJ_NAME}) - endif () - endif () -endmacro(SETUP_HIFI_TESTCASE) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index da6d89357b..c352b55515 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,16 +6,16 @@ enable_testing() file(GLOB TEST_SUBDIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/*") list(REMOVE_ITEM TEST_SUBDIRS "CMakeFiles") foreach(DIR ${TEST_SUBDIRS}) - if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}") - set(TEST_PROJ_NAME ${DIR}) - add_subdirectory(${DIR}) # link in the subdir (this reinvokes cmake on the cmakelists.txt file, with its - endif() # own variable scope copied from this scope (the parent scope)). + if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${DIR}") + set(TEST_PROJ_NAME ${DIR}) + add_subdirectory(${DIR}) + endif() endforeach() file(GLOB SHARED_TEST_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") add_custom_target("test-extensions" - SOURCES "${SHARED_TEST_HEADER_FILES}") + SOURCES "${SHARED_TEST_HEADER_FILES}") list(APPEND ALL_TEST_TARGETS "test-extensions") set_target_properties("test-extensions" PROPERTIES FOLDER "Tests") @@ -23,20 +23,15 @@ message(STATUS "ALL_TEST_TARGETS = ${ALL_TEST_TARGETS}") # Create the all-tests build target. # The dependency list (ALL_TEST_TARGETS) is generated from setup_hifi_testcase invocations in the CMakeLists.txt -# files in the test subdirs. Since variables normally do *not* persist into parent scope, we use a hack: +# files in the test subdirs. Note: since variables normally do *not* persist into parent scope, we use a hack: # -# list(APPEND ALL_TEST_TARGETS ${targets_to_add...}) # appends to a local list var (copied from parent scope) -# set (ALL_TEST_TARGETS "${ALL_TEST_TARGETS}" PARENT_SCOPE) # copies this back to parent scope +# list(APPEND ALL_TEST_TARGETS ${targets_to_add...}) # appends to a local list var (copied from parent scope) +# set (ALL_TEST_TARGETS "${ALL_TEST_TARGETS}" PARENT_SCOPE) # copies this back to parent scope # add_custom_target("all-tests" - COMMAND ctest . - DEPENDS "${ALL_TEST_TARGETS}") + COMMAND ctest . + DEPENDS "${ALL_TEST_TARGETS}") set_target_properties("all-tests" PROPERTIES FOLDER "hidden/test-targets") set_target_properties("all-tests" PROPERTIES - EXCLUDE_FROM_DEFAULT_BUILD TRUE - EXCLUDE_FROM_ALL TRUE) - - -# Note: we also do some funky stuff with macros (SETUP_TESTCASE_DEPENDENCIES is redefined in *each* CMakeLists.txt -# file, and then invoked in SetupHifiTestCase.cmake) -- which is necessary since the dependencies must be re-linked -# for each target (instead of just one) \ No newline at end of file + EXCLUDE_FROM_DEFAULT_BUILD TRUE + EXCLUDE_FROM_ALL TRUE) \ No newline at end of file diff --git a/tests/QTestExtensions.h b/tests/QTestExtensions.h index b2b2cd8e00..213fe6d7b5 100644 --- a/tests/QTestExtensions.h +++ b/tests/QTestExtensions.h @@ -47,12 +47,12 @@ // Additional messages (after actual/expected) can be written using the std::function callback. // If these messages span more than one line, wrap them with "\n\t" to get proper indentation / formatting) // -template -inline QString QTest_generateCompareFailureMessage ( - const char * failMessage, - const T & actual, const T & expected, - const char * actual_expr, const char * expected_expr, - std::function writeAdditionalMessages +template inline +QString QTest_generateCompareFailureMessage ( + const char* failMessage, + const T& actual, const T& expected, + const char* actual_expr, const char* expected_expr, + std::function writeAdditionalMessages ) { QString s1 = actual_expr, s2 = expected_expr; int pad1_ = qMax(s2.length() - s1.length(), 0); @@ -79,11 +79,11 @@ inline QString QTest_generateCompareFailureMessage ( // Loc: [()] // (no message callback) // -template -inline QString QTest_generateCompareFailureMessage ( - const char * failMessage, - const T & actual, const T & expected, - const char * actual_expr, const char * expected_expr +template inline +QString QTest_generateCompareFailureMessage ( + const char* failMessage, + const T& actual, const T& expected, + const char* actual_expr, const char* expected_expr ) { QString s1 = actual_expr, s2 = expected_expr; int pad1_ = qMax(s2.length() - s1.length(), 0); @@ -102,15 +102,17 @@ inline QString QTest_generateCompareFailureMessage ( // Hacky function that can assemble a QString from a QTextStream via a callback // (ie. stream operations w/out qDebug()) -inline QString makeMessageFromStream (std::function writeMessage) { +inline +QString makeMessageFromStream (std::function writeMessage) { QString msg; QTextStream stream(&msg); writeMessage(stream); return msg; } -inline void QTest_failWithCustomMessage ( - std::function writeMessage, int line, const char *file +inline +void QTest_failWithCustomMessage ( + std::function writeMessage, int line, const char* file ) { QTest::qFail(qPrintable(makeMessageFromStream(writeMessage)), file, line); } @@ -133,38 +135,44 @@ do { \ // Calls qFail using QTest_generateCompareFailureMessage. // This is (usually) wrapped in macros, but if you call this directly you should return immediately to get QFAIL semantics. -template -inline void QTest_failWithMessage( - const char * failMessage, - const T & actual, const T & expected, - const char * actualExpr, const char * expectedExpr, - int line, const char * file +template inline +void QTest_failWithMessage( + const char* failMessage, + const T& actual, const T& expected, + const char* actualExpr, const char* expectedExpr, + int line, const char* file ) { - QTest::qFail(qPrintable(QTest_generateCompareFailureMessage(failMessage, actual, expected, actualExpr, expectedExpr)), file, line); + QTest::qFail(qPrintable(QTest_generateCompareFailureMessage( + failMessage, actual, expected, actualExpr, expectedExpr)), file, line); } // Calls qFail using QTest_generateCompareFailureMessage. // This is (usually) wrapped in macros, but if you call this directly you should return immediately to get QFAIL semantics. -template -inline void QTest_failWithMessage( - const char * failMessage, - const T & actual, const T & expected, - const char * actualExpr, const char * expectedExpr, - int line, const char * file, - std::function writeAdditionalMessageLines +template inline +void QTest_failWithMessage( + const char* failMessage, + const T& actual, const T& expected, + const char* actualExpr, const char* expectedExpr, + int line, const char* file, + std::function writeAdditionalMessageLines ) { - QTest::qFail(qPrintable(QTest_generateCompareFailureMessage(failMessage, actual, expected, actualExpr, expectedExpr, writeAdditionalMessageLines)), file, line); + QTest::qFail(qPrintable(QTest_generateCompareFailureMessage( + failMessage, actual, expected, actualExpr, expectedExpr, writeAdditionalMessageLines)), file, line); } // Implements QCOMPARE_WITH_ABS_ERROR -template -inline bool QTest_compareWithAbsError(const T & actual, const T & expected, const char * actual_expr, const char * expected_expr, int line, const char * file, const V & epsilon) -{ +template inline +bool QTest_compareWithAbsError( + const T& actual, const T& expected, + const char* actual_expr, const char* expected_expr, + int line, const char* file, + const V& epsilon +) { if (abs(getErrorDifference(actual, expected)) > abs(epsilon)) { QTest_failWithMessage( "Compared values are not the same (fuzzy compare)", actual, expected, actual_expr, expected_expr, line, file, - [&] (QTextStream & stream) -> QTextStream & { + [&] (QTextStream& stream) -> QTextStream& { return stream << "Err tolerance: " << getErrorDifference((actual), (expected)) << " > " << epsilon; }); return false; @@ -187,7 +195,7 @@ inline bool QTest_compareWithAbsError(const T & actual, const T & expected, cons // #define QCOMPARE_WITH_ABS_ERROR(actual, expected, epsilon) \ do { \ - if (!QTest_compareWithAbsError(actual, expected, #actual, #expected, __LINE__, __FILE__, epsilon)) \ + if (!QTest_compareWithAbsError((actual), (expected), #actual, #expected, __LINE__, __FILE__, epsilon)) \ return; \ } while(0) @@ -199,8 +207,8 @@ do { \ // #define QCOMPARE_WITH_FUNCTION(actual, expected, testFunc) \ do { \ - if (!testFunc(actual, expected)) { \ - QTest_failWithMessage("Compared values are not the same", actual, expected, #actual, #expected, __LINE__, __FILE__); \ + if (!(testFunc((actual), (expected)))) { \ + QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \ return; \ } \ } while (0) @@ -217,8 +225,8 @@ do { \ // #define QCOMPARE_WITH_LAMBDA(actual, expected, testClosure) \ do { \ - if (!testClosure()) { \ - QTest_failWithMessage("Compared values are not the same", actual, expected, #actual, #expected, __LINE__, __FILE__); \ + if (!(testClosure())) { \ + QTest_failWithMessage("Compared values are not the same", (actual), (expected), #actual, #expected, __LINE__, __FILE__); \ return; \ } \ } while (0) @@ -226,8 +234,8 @@ do { \ // Same as QCOMPARE_WITH_FUNCTION, but with a custom fail message #define QCOMPARE_WITH_FUNCTION_AND_MESSAGE(actual, expected, testfunc, failMessage) \ do { \ - if (!testFunc(actual, expected)) { \ - QTest_failWithMessage(failMessage, actual, expected, #actual, #expected, __LINE__, __FILE__); \ + if (!(testFunc((actual), (expected)))) { \ + QTest_failWithMessage((failMessage), (actual), (expected), #actual, #expected, __LINE__, __FILE__); \ return; \ } \ } while (0) @@ -235,8 +243,8 @@ do { \ // Same as QCOMPARE_WITH_FUNCTION, but with a custom fail message #define QCOMPARE_WITH_LAMBDA_AND_MESSAGE(actual, expected, testClosure, failMessage) \ do { \ - if (!testClosure()) { \ - QTest_failWithMessage(failMessage, actual, expected, #actual, #expected, __LINE__, __FILE__); \ + if (!(testClosure())) { \ + QTest_failWithMessage((failMessage), (actual), (expected), #actual, #expected, __LINE__, __FILE__); \ return; \ } \ } while (0) diff --git a/tests/audio/CMakeLists.txt b/tests/audio/CMakeLists.txt index 7049ab1b36..8e894e929e 100644 --- a/tests/audio/CMakeLists.txt +++ b/tests/audio/CMakeLists.txt @@ -1,9 +1,9 @@ # Declare dependencies macro (SETUP_TESTCASE_DEPENDENCIES) - # link in the shared libraries - link_hifi_libraries(shared audio networking) + # 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() \ No newline at end of file diff --git a/tests/audio/src/AudioRingBufferTests.cpp b/tests/audio/src/AudioRingBufferTests.cpp index 565e24ec0b..ea384cad61 100644 --- a/tests/audio/src/AudioRingBufferTests.cpp +++ b/tests/audio/src/AudioRingBufferTests.cpp @@ -1,4 +1,4 @@ - // +// // AudioRingBufferTests.cpp // tests/audio/src // @@ -124,6 +124,4 @@ void AudioRingBufferTests::runAllTests() { } assertBufferSize(ringBuffer, 0); } - -// qDebug() << "PASSED"; } diff --git a/tests/jitter/CMakeLists.txt b/tests/jitter/CMakeLists.txt index 76f306a2dc..7b636aa87f 100644 --- a/tests/jitter/CMakeLists.txt +++ b/tests/jitter/CMakeLists.txt @@ -1,10 +1,10 @@ # 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() + copy_dlls_beside_windows_executable() endmacro() setup_hifi_testcase() \ No newline at end of file diff --git a/tests/jitter/src/JitterTests.h b/tests/jitter/src/JitterTests.h index b6ab4562e9..3ad7b91434 100644 --- a/tests/jitter/src/JitterTests.h +++ b/tests/jitter/src/JitterTests.h @@ -1,9 +1,11 @@ // -// JitterTests.h -// hifi +// QTestExtensions.h +// tests/jitter/src // -// Created by Seiji Emery on 6/23/15. +// Copyright 2015 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_JitterTests_h diff --git a/tests/networking/CMakeLists.txt b/tests/networking/CMakeLists.txt index 51fd639672..3be2fff027 100644 --- a/tests/networking/CMakeLists.txt +++ b/tests/networking/CMakeLists.txt @@ -1,10 +1,10 @@ # 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() + copy_dlls_beside_windows_executable() endmacro () setup_hifi_testcase() \ No newline at end of file diff --git a/tests/networking/src/SequenceNumberStatsTests.cpp b/tests/networking/src/SequenceNumberStatsTests.cpp index 08261b806f..aaaeea53fc 100644 --- a/tests/networking/src/SequenceNumberStatsTests.cpp +++ b/tests/networking/src/SequenceNumberStatsTests.cpp @@ -1,5 +1,5 @@ // -// AudioRingBufferTests.cpp +// SequenceNumberStatsTests.cpp // tests/networking/src // // Created by Yixin Wang on 6/24/2014 diff --git a/tests/networking/src/SequenceNumberStatsTests.h b/tests/networking/src/SequenceNumberStatsTests.h index f480f8cdf3..d2fa7af4d5 100644 --- a/tests/networking/src/SequenceNumberStatsTests.h +++ b/tests/networking/src/SequenceNumberStatsTests.h @@ -1,5 +1,5 @@ // -// AudioRingBufferTests.h +// SequenceNumberStatsTests.h // tests/networking/src // // Created by Yixin Wang on 6/24/2014 diff --git a/tests/octree/CMakeLists.txt b/tests/octree/CMakeLists.txt index 178d4911d9..a605a4088b 100644 --- a/tests/octree/CMakeLists.txt +++ b/tests/octree/CMakeLists.txt @@ -1,10 +1,10 @@ # 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() + copy_dlls_beside_windows_executable() endmacro () setup_hifi_testcase(Script Network) \ No newline at end of file diff --git a/tests/octree/src/AABoxCubeTests.h b/tests/octree/src/AABoxCubeTests.h index e58e9749d0..a9519f9fcf 100644 --- a/tests/octree/src/AABoxCubeTests.h +++ b/tests/octree/src/AABoxCubeTests.h @@ -14,7 +14,6 @@ #include - class AABoxCubeTests : public QObject { Q_OBJECT diff --git a/tests/octree/src/OctreeTests.cpp b/tests/octree/src/OctreeTests.cpp index 08db402c03..4601592586 100644 --- a/tests/octree/src/OctreeTests.cpp +++ b/tests/octree/src/OctreeTests.cpp @@ -214,7 +214,6 @@ void OctreeTests::propertyFlagsTests() { // testsFailed++; // qDebug() << "FAILED - Test 3b: remove flag with -= EXAMPLE_PROP_PAUSE_SIMULATION"; // } - } { diff --git a/tests/physics/CMakeLists.txt b/tests/physics/CMakeLists.txt index f752d3b937..6059ca3b19 100644 --- a/tests/physics/CMakeLists.txt +++ b/tests/physics/CMakeLists.txt @@ -1,18 +1,18 @@ # Declare dependencies macro (SETUP_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() + 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 () setup_hifi_testcase(Script) \ No newline at end of file diff --git a/tests/physics/src/BulletTestUtils.h b/tests/physics/src/BulletTestUtils.h index 1c3d0b6610..fee7f9b1bc 100644 --- a/tests/physics/src/BulletTestUtils.h +++ b/tests/physics/src/BulletTestUtils.h @@ -23,19 +23,16 @@ // (used by QCOMPARE_WITH_RELATIVE_ERROR via QCOMPARE_WITH_LAMBDA) // (this is only used by btMatrix3x3 in MeshMassPropertiesTests.cpp, so it's only defined for the Mat3 type) -// -// fuzzy compare (this is a distance function, basically) -// - -inline btScalar getErrorDifference(const btScalar & a, const btScalar & b) { +// Return the error between values a and b; used to implement QCOMPARE_WITH_ABS_ERROR +inline btScalar getErrorDifference(const btScalar& a, const btScalar& b) { return fabs(a - b); } -inline btScalar getErrorDifference(const btVector3 & a, const btVector3 & b) -{ +// Return the error between values a and b; used to implement QCOMPARE_WITH_ABS_ERROR +inline btScalar getErrorDifference(const btVector3& a, const btVector3& b) { return (a - b).length(); } // Matrices are compared element-wise -- if the error value for any element > epsilon, then fail -inline btScalar getErrorDifference (const btMatrix3x3 & a, const btMatrix3x3 & b) { +inline btScalar getErrorDifference (const btMatrix3x3& a, const btMatrix3x3& b) { btScalar maxDiff = 0; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { @@ -51,7 +48,7 @@ inline btScalar getErrorDifference (const btMatrix3x3 & a, const btMatrix3x3 & b // // btMatrix3x3 stream printing (not advised to use this outside of the test macros, due to formatting) -inline QTextStream & operator << (QTextStream & stream, const btMatrix3x3 & matrix) { +inline QTextStream& operator << (QTextStream& stream, const btMatrix3x3& matrix) { stream << "[\n\t\t"; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { @@ -62,7 +59,7 @@ inline QTextStream & operator << (QTextStream & stream, const btMatrix3x3 & matr stream << "]\n\t"; // hacky as hell, but this should work... return stream; } -inline QTextStream & operator << (QTextStream & stream, const btVector3 & v) { +inline QTextStream& operator << (QTextStream& stream, const btVector3& v) { return stream << "btVector3 { " << v.x() << ", " << v.y() << ", " << v.z() << " }"; } // btScalar operator<< is already implemented (as it's just a typedef-ed float/double) @@ -71,8 +68,9 @@ inline QTextStream & operator << (QTextStream & stream, const btVector3 & v) { // errorTest (actual, expected, acceptableRelativeError) -> callback closure // -// Produces a relative error test for btMatrix3x3 usable with QCOMPARE_WITH_LAMBDA -inline auto errorTest (const btMatrix3x3 & actual, const btMatrix3x3 & expected, const btScalar acceptableRelativeError) +// Produces a relative error test for btMatrix3x3 usable with QCOMPARE_WITH_LAMBDA. +// (used in a *few* physics tests that define QCOMPARE_WITH_RELATIVE_ERROR) +inline auto errorTest (const btMatrix3x3& actual, const btMatrix3x3& expected, const btScalar acceptableRelativeError) -> std::function { return [&actual, &expected, acceptableRelativeError] () { @@ -83,9 +81,11 @@ inline auto errorTest (const btMatrix3x3 & actual, const btMatrix3x3 & expected, if (fabsf(err) > acceptableRelativeError) return false; } else { - // handle zero-case by also calling QCOMPARE_WITH_ABS_ERROR - // (this function implements QCOMPARE_WITH_RELATIVE_ERROR, so call both - // to test matrices) + // The zero-case (where expected[i][j] == 0) is covered by the QCOMPARE_WITH_ABS_ERROR impl + // (ie. getErrorDifference (const btMatrix3x3& a, const btMatrix3x3& b). + // Since the zero-case uses a different error value (abs error) vs the non-zero case (relative err), + // it made sense to separate these two cases. To do a full check, call QCOMPARE_WITH_RELATIVE_ERROR + // followed by QCOMPARE_WITH_ABS_ERROR (or vice versa). } } } diff --git a/tests/physics/src/BulletUtilTests.cpp b/tests/physics/src/BulletUtilTests.cpp index d325e4c27c..bbd88f88b7 100644 --- a/tests/physics/src/BulletUtilTests.cpp +++ b/tests/physics/src/BulletUtilTests.cpp @@ -65,12 +65,3 @@ void BulletUtilTests::fromGLMToBullet() { QCOMPARE(gQ.z, bQ.getZ()); QCOMPARE(gQ.w, bQ.getW()); } - -//void BulletUtilTests::fooTest () { -// -// glm::vec3 a { 1, 0, 3 }; -// glm::vec3 b { 2, 0, 5 }; -// -//// QCOMPARE(10, 22); -// QCOMPARE_WITH_ABS_ERROR(a, b, 1.0f); -//} diff --git a/tests/physics/src/BulletUtilTests.h b/tests/physics/src/BulletUtilTests.h index ffba14723d..fd4fe13d09 100644 --- a/tests/physics/src/BulletUtilTests.h +++ b/tests/physics/src/BulletUtilTests.h @@ -23,7 +23,6 @@ class BulletUtilTests : public QObject { private slots: void fromBulletToGLM(); void fromGLMToBullet(); -// void fooTest (); }; #endif // hifi_BulletUtilTests_h diff --git a/tests/physics/src/CollisionInfoTests.cpp b/tests/physics/src/CollisionInfoTests.cpp index ca9c54e15a..70e2e14bb0 100644 --- a/tests/physics/src/CollisionInfoTests.cpp +++ b/tests/physics/src/CollisionInfoTests.cpp @@ -40,33 +40,12 @@ void CollisionInfoTests::rotateThenTranslate() { collision.rotateThenTranslate(rotation, translation); QCOMPARE(collision._penetration, xYxis); -// float error = glm::distance(collision._penetration, xYxis); -// if (error > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: collision._penetration = " << collision._penetration -// << " but we expected " << xYxis -// << std::endl; -// } glm::vec3 expectedContactPoint = -xAxis + translation; QCOMPARE(collision._contactPoint, expectedContactPoint); -// error = glm::distance(collision._contactPoint, expectedContactPoint); -// if (error > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: collision._contactPoint = " << collision._contactPoint -// << " but we expected " << expectedContactPoint -// << std::endl; -// } glm::vec3 expectedAddedVelocity = xYxis - xAxis + xZxis; QCOMPARE(collision._addedVelocity, expectedAddedVelocity); -// error = glm::distance(collision._addedVelocity, expectedAddedVelocity); -// if (error > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: collision._addedVelocity = " << collision._contactPoint -// << " but we expected " << expectedAddedVelocity -// << std::endl; -// } } void CollisionInfoTests::translateThenRotate() { @@ -81,32 +60,11 @@ void CollisionInfoTests::translateThenRotate() { collision.translateThenRotate(translation, rotation); QCOMPARE(collision._penetration, -xYxis); -// float error = glm::distance(collision._penetration, -xYxis); -// if (error > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: collision._penetration = " << collision._penetration -// << " but we expected " << -yAxis -// << std::endl; -// } glm::vec3 expectedContactPoint = (1.0f + distance) * xAxis; QCOMPARE(collision._contactPoint, expectedContactPoint); -// error = glm::distance(collision._contactPoint, expectedContactPoint); -// if (error > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: collision._contactPoint = " << collision._contactPoint -// << " but we expected " << expectedContactPoint -// << std::endl; -// } glm::vec3 expectedAddedVelocity = - xYxis + xAxis + xYxis; QCOMPARE(collision._addedVelocity, expectedAddedVelocity); -// error = glm::distance(collision._addedVelocity, expectedAddedVelocity); -// if (error > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: collision._addedVelocity = " << collision._contactPoint -// << " but we expected " << expectedAddedVelocity -// << std::endl; -// } }*/ diff --git a/tests/physics/src/MeshMassPropertiesTests.cpp b/tests/physics/src/MeshMassPropertiesTests.cpp index 8195c636b7..839b7624a7 100644 --- a/tests/physics/src/MeshMassPropertiesTests.cpp +++ b/tests/physics/src/MeshMassPropertiesTests.cpp @@ -15,24 +15,11 @@ #include "MeshMassPropertiesTests.h" -#define VERBOSE_UNIT_TESTS - const btScalar acceptableRelativeError(1.0e-5f); const btScalar acceptableAbsoluteError(1.0e-4f); QTEST_MAIN(MeshMassPropertiesTests) -void printMatrix(const std::string& name, const btMatrix3x3& matrix) { - std::cout << name << " = [" << std::endl; - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) { - std::cout << " " << matrix[i][j]; - } - std::cout << std::endl; - } - std::cout << "]" << std::endl; -} - void pushTriangle(VectorOfIndices& indices, uint32_t a, uint32_t b, uint32_t c) { indices.push_back(a); indices.push_back(b); @@ -40,14 +27,10 @@ void pushTriangle(VectorOfIndices& indices, uint32_t a, uint32_t b, uint32_t c) } void MeshMassPropertiesTests::testParallelAxisTheorem() { -//#ifdef EXPOSE_HELPER_FUNCTIONS_FOR_UNIT_TEST // verity we can compute the inertia tensor of a box in two different ways: // (a) as one box // (b) as a combination of two partial boxes. -//#ifdef VERBOSE_UNIT_TESTS -// std::cout << "\n" << __FUNCTION__ << std::endl; -//#endif // VERBOSE_UNIT_TESTS - + btScalar bigBoxX = 7.0f; btScalar bigBoxY = 9.0f; btScalar bigBoxZ = 11.0f; @@ -90,12 +73,6 @@ void MeshMassPropertiesTests::testParallelAxisTheorem() { // This now does the same as the above (using the maxDiff getErrorDifference impl for two btMatrices) QCOMPARE_WITH_ABS_ERROR(bitBoxInertia, twoSmallBoxesInertia, acceptableAbsoluteError); - -//#ifdef VERBOSE_UNIT_TESTS -// printMatrix("expected inertia", bitBoxInertia); -// printMatrix("computed inertia", twoSmallBoxesInertia); -//#endif // VERBOSE_UNIT_TESTS -//#endif // EXPOSE_HELPER_FUNCTIONS_FOR_UNIT_TEST } void MeshMassPropertiesTests::testTetrahedron(){ @@ -140,58 +117,14 @@ void MeshMassPropertiesTests::testTetrahedron(){ btMatrix3x3 inertia; computeTetrahedronInertia(volume, points, inertia); - // if error = (volume - expectedVolume) / expectedVolume - // then fabsf(error) > acceptableRelativeError == fabsf(volume - expectedVolume) > err - // where err = acceptableRelativeError * expectedVolume - QCOMPARE_WITH_ABS_ERROR(volume, expectedVolume, acceptableRelativeError * volume); - // pseudo-hack -- error value is calculated per-element, so QCOMPARE_WITH_ABS_ERROR will not work. - // QCOMPARE_WITH_FUNCTION and QCOMPARE_WITH_LAMBDA lets you get around this by writing - // a custom function to do the actual comparison; printing, etc is done automatically. - auto testFunc = [&inertia, &expectedInertia] () { - for (int i = 0; i < 3; ++i) { - for (int j = 0; j < 3; ++j) { - auto error = (inertia[i][j] - expectedInertia[i][j]) / expectedInertia[i][j]; - if (fabsf(error) > acceptableRelativeError) - return false; - } - } - return true; - }; - QCOMPARE_WITH_LAMBDA(inertia, expectedInertia, testFunc); - QCOMPARE_WITH_RELATIVE_ERROR(inertia, expectedInertia, acceptableRelativeError); -// // verify -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 3; ++j) { -// error = (inertia[i][j] - expectedInertia[i][j]) / expectedInertia[i][j]; -// if (fabsf(error) > acceptableRelativeError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : inertia[" << i << "][" << j << "] off by " -// << error << std::endl; -// } -// } -// } - -//#ifdef VERBOSE_UNIT_TESTS -// std::cout << "expected volume = " << expectedVolume << std::endl; -// std::cout << "measured volume = " << volume << std::endl; -// printMatrix("expected inertia", expectedInertia); -// printMatrix("computed inertia", inertia); -// -// // when building VERBOSE you might be instrested in the results from the brute force method: -// btMatrix3x3 bruteInertia; -// computeTetrahedronInertiaByBruteForce(points, bruteInertia); -// printMatrix("brute inertia", bruteInertia); -//#endif // VERBOSE_UNIT_TESTS } void MeshMassPropertiesTests::testOpenTetrahedonMesh() { // given the simplest possible mesh (open, with one triangle) // verify MeshMassProperties computes the right nubers -//#ifdef VERBOSE_UNIT_TESTS -// std::cout << "\n" << __FUNCTION__ << std::endl; -//#endif // VERBOSE_UNIT_TESTS // these numbers from the Tonon paper: VectorOfPoints points; @@ -229,51 +162,14 @@ void MeshMassPropertiesTests::testOpenTetrahedonMesh() { // verify // (expected - actual) / expected > e ==> expected - actual > e * expected QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); - - - -// btScalar error = (mesh._volume - expectedVolume) / expectedVolume; -// if (fabsf(error) > acceptableRelativeError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : volume of tetrahedron off by = " -// << error << std::endl; -// } - - QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); - -// error = (mesh._centerOfMass - expectedCenterOfMass).length(); -// if (fabsf(error) > acceptableAbsoluteError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : centerOfMass of tetrahedron off by = " -// << error << std::endl; -// } - QCOMPARE_WITH_RELATIVE_ERROR(mesh._inertia, expectedInertia, acceptableRelativeError); - -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 3; ++j) { -// error = (mesh._inertia[i][j] - expectedInertia[i][j]) / expectedInertia[i][j]; -// if (fabsf(error) > acceptableRelativeError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : inertia[" << i << "][" << j << "] off by " -// << error << std::endl; -// } -// } -// } - -//#ifdef VERBOSE_UNIT_TESTS -// std::cout << "expected volume = " << expectedVolume << std::endl; -// std::cout << "measured volume = " << mesh._volume << std::endl; -// printMatrix("expected inertia", expectedInertia); -// printMatrix("computed inertia", mesh._inertia); -//#endif // VERBOSE_UNIT_TESTS } void MeshMassPropertiesTests::testClosedTetrahedronMesh() { // given a tetrahedron as a closed mesh of four tiangles // verify MeshMassProperties computes the right nubers -#ifdef VERBOSE_UNIT_TESTS - std::cout << "\n" << __FUNCTION__ << std::endl; -#endif // VERBOSE_UNIT_TESTS - + // these numbers from the Tonon paper: VectorOfPoints points; points.push_back(btVector3(8.33220f, -11.86875f, 0.93355f)); @@ -307,39 +203,8 @@ void MeshMassPropertiesTests::testClosedTetrahedronMesh() { // verify QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); -// btScalar error; -// error = (mesh._volume - expectedVolume) / expectedVolume; -// if (fabsf(error) > acceptableRelativeError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : volume of tetrahedron off by = " -// << error << std::endl; -// } - - QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); -// error = (mesh._centerOfMass - expectedCenterOfMass).length(); -// if (fabsf(error) > acceptableAbsoluteError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : centerOfMass of tetrahedron off by = " -// << error << std::endl; -// } - QCOMPARE_WITH_RELATIVE_ERROR(mesh._inertia, expectedInertia, acceptableRelativeError); -// for (int i = 0; i < 3; ++i) { -// for (int j = 0; j < 3; ++j) { -// error = (mesh._inertia[i][j] - expectedInertia[i][j]) / expectedInertia[i][j]; -// if (fabsf(error) > acceptableRelativeError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : inertia[" << i << "][" << j << "] off by " -// << error << std::endl; -// } -// } -// } - -//#ifdef VERBOSE_UNIT_TESTS -// std::cout << "(a) tetrahedron as mesh" << std::endl; -// std::cout << "expected volume = " << expectedVolume << std::endl; -// std::cout << "measured volume = " << mesh._volume << std::endl; -// printMatrix("expected inertia", expectedInertia); -// printMatrix("computed inertia", mesh._inertia); -//#endif // VERBOSE_UNIT_TESTS // test again, but this time shift the points so that the origin is definitely OUTSIDE the mesh btVector3 shift = points[0] + expectedCenterOfMass; @@ -353,37 +218,8 @@ void MeshMassPropertiesTests::testClosedTetrahedronMesh() { // verify // QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); -//// error = (mesh._volume - expectedVolume) / expectedVolume; -//// if (fabsf(error) > acceptableRelativeError) { -//// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : volume of tetrahedron off by = " -//// << error << std::endl; -//// } -// // QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); -//// error = (mesh._centerOfMass - expectedCenterOfMass).length(); -//// if (fabsf(error) > acceptableAbsoluteError) { -//// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : centerOfMass of tetrahedron off by = " -//// << error << std::endl; -//// } -// // QCOMPARE_WITH_RELATIVE_ERROR(mesh._inertia, expectedInertia, acceptableRelativeError); -//// for (int i = 0; i < 3; ++i) { -//// for (int j = 0; j < 3; ++j) { -//// error = (mesh._inertia[i][j] - expectedInertia[i][j]) / expectedInertia[i][j]; -//// if (fabsf(error) > acceptableRelativeError) { -//// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : inertia[" << i << "][" << j << "] off by " -//// << error << std::endl; -//// } -//// } -//// } - -//#ifdef VERBOSE_UNIT_TESTS -// std::cout << "(b) shifted tetrahedron as mesh" << std::endl; -// std::cout << "expected volume = " << expectedVolume << std::endl; -// std::cout << "measured volume = " << mesh._volume << std::endl; -// printMatrix("expected inertia", expectedInertia); -// printMatrix("computed inertia", mesh._inertia); -//#endif // VERBOSE_UNIT_TESTS } void MeshMassPropertiesTests::testBoxAsMesh() { @@ -445,25 +281,13 @@ void MeshMassPropertiesTests::testBoxAsMesh() { // verify QCOMPARE_WITH_ABS_ERROR(mesh._volume, expectedVolume, acceptableRelativeError * expectedVolume); -// btScalar error; -// error = (mesh._volume - expectedVolume) / expectedVolume; -// if (fabsf(error) > acceptableRelativeError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : volume of tetrahedron off by = " -// << error << std::endl; -// } - QCOMPARE_WITH_ABS_ERROR(mesh._centerOfMass, expectedCenterOfMass, acceptableAbsoluteError); -// error = (mesh._centerOfMass - expectedCenterOfMass).length(); -// if (fabsf(error) > acceptableAbsoluteError) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR : centerOfMass of tetrahedron off by = " -// << error << std::endl; -// } - - // do this twice to avoid divide-by-zero? + // test this twice: _RELATIVE_ERROR doesn't test zero cases (to avoid divide-by-zero); _ABS_ERROR does. QCOMPARE_WITH_ABS_ERROR(mesh._inertia, expectedInertia, acceptableAbsoluteError); QCOMPARE_WITH_RELATIVE_ERROR(mesh._inertia, expectedInertia, acceptableRelativeError); -// float error; + + // These two macros impl this: // for (int i = 0; i < 3; ++i) { // for (int j = 0; j < 3; ++j) { // if (expectedInertia [i][j] == btScalar(0.0f)) { diff --git a/tests/physics/src/ShapeColliderTests.cpp b/tests/physics/src/ShapeColliderTests.cpp index 340cbde5a5..cb42f534cb 100644 --- a/tests/physics/src/ShapeColliderTests.cpp +++ b/tests/physics/src/ShapeColliderTests.cpp @@ -224,12 +224,6 @@ void ShapeColliderTests::sphereTouchesCapsule() { glm::vec3 expectedContactPoint = sphereA.getTranslation() - radiusA * yAxis; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint << std::endl; -// } // capsuleB collides with sphereA if (!ShapeCollider::collideShapes(&capsuleB, &sphereA, collisions)) @@ -248,12 +242,6 @@ void ShapeColliderTests::sphereTouchesCapsule() { expectedPenetration *= -1.0f; } QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration << std::endl; -// } // contactPoint is on surface of capsuleB glm::vec3 endPoint; @@ -265,12 +253,6 @@ void ShapeColliderTests::sphereTouchesCapsule() { } QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint << std::endl; -// } } { // sphereA hits start cap at axis glm::vec3 axialOffset = - (halfHeightB + alpha * radiusA + beta * radiusB) * yAxis; @@ -289,22 +271,10 @@ void ShapeColliderTests::sphereTouchesCapsule() { glm::vec3 expectedPenetration = ((1.0f - alpha) * radiusA + (1.0f - beta) * radiusB) * yAxis; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration << std::endl; -// } // contactPoint is on surface of sphereA glm::vec3 expectedContactPoint = sphereA.getTranslation() + radiusA * yAxis; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint << std::endl; -// } // capsuleB collides with sphereA if (!ShapeCollider::collideShapes(&capsuleB, &sphereA, collisions)) @@ -323,12 +293,6 @@ void ShapeColliderTests::sphereTouchesCapsule() { expectedPenetration *= -1.0f; } QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration << std::endl; -// } // contactPoint is on surface of capsuleB glm::vec3 startPoint; @@ -339,12 +303,6 @@ void ShapeColliderTests::sphereTouchesCapsule() { expectedContactPoint = axialOffset + radiusA * yAxis; } QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint << std::endl; -// } } if (collisions.size() != numCollisions) { std::cout << __FILE__ << ":" << __LINE__ @@ -372,31 +330,11 @@ void ShapeColliderTests::capsuleMissesCapsule() { capsuleB.setTranslation((1.01f * totalRadius) * xAxis); QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), false); QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions), false); -// if (ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should NOT touch" << std::endl; -// } -// if (ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should NOT touch" << std::endl; -// } // end to end capsuleB.setTranslation((1.01f * totalHalfLength) * xAxis); QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), false); QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions), false); -// if (ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should NOT touch" << std::endl; -// } -// if (ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should NOT touch" << std::endl; -// } // rotate B and move it to the side glm::quat rotation = glm::angleAxis(PI_OVER_TWO, zAxis); @@ -405,22 +343,8 @@ void ShapeColliderTests::capsuleMissesCapsule() { QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), false); QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions), false); -// if (ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should NOT touch" << std::endl; -// } -// if (ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should NOT touch" << std::endl; -// } QCOMPARE(collisions.size(), 0); -// if (collisions.size() > 0) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: expected empty collision list but size is " << collisions.size() << std::endl; -// } } void ShapeColliderTests::capsuleTouchesCapsule() { @@ -444,20 +368,6 @@ void ShapeColliderTests::capsuleTouchesCapsule() { QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), true); QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions), true); numCollisions += 2; -// if (!ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } -// if (!ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } } { // end to end @@ -466,20 +376,6 @@ void ShapeColliderTests::capsuleTouchesCapsule() { QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), true); QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions), true); numCollisions += 2; -// if (!ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } -// if (!ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } } { // rotate B and move it to the side @@ -490,20 +386,6 @@ void ShapeColliderTests::capsuleTouchesCapsule() { QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), true); QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions), true); numCollisions += 2; -// if (!ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } -// if (!ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } } { // again, but this time check collision details @@ -516,62 +398,25 @@ void ShapeColliderTests::capsuleTouchesCapsule() { // capsuleA vs capsuleB QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), true); ++numCollisions; -// if (!ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } CollisionInfo* collision = collisions.getCollision(numCollisions - 1); glm::vec3 expectedPenetration = overlap * xAxis; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration << std::endl; -// } glm::vec3 expectedContactPoint = capsuleA.getTranslation() + radiusA * xAxis; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint << std::endl; -// } // capsuleB vs capsuleA QCOMPARE(ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions), true); ++numCollisions; -// if (!ShapeCollider::collideShapes(&capsuleB, &capsuleA, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } + collision = collisions.getCollision(numCollisions - 1); expectedPenetration = - overlap * xAxis; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration << std::endl; -// } expectedContactPoint = capsuleB.getTranslation() - (radiusB + halfHeightB) * xAxis; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint << std::endl; -// } } { // collide cylinder wall against cylinder wall @@ -585,33 +430,14 @@ void ShapeColliderTests::capsuleTouchesCapsule() { // capsuleA vs capsuleB QCOMPARE(ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions), true); ++numCollisions; -// if (!ShapeCollider::collideShapes(&capsuleA, &capsuleB, collisions)) -// { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule and capsule should touch" << std::endl; -// } else { -// ++numCollisions; -// } CollisionInfo* collision = collisions.getCollision(numCollisions - 1); glm::vec3 expectedPenetration = overlap * zAxis; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration << std::endl; -// } glm::vec3 expectedContactPoint = capsuleA.getTranslation() + radiusA * zAxis + shift * yAxis; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, EPSILON); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint << std::endl; -// } } } @@ -681,12 +507,9 @@ void ShapeColliderTests::sphereMissesAACube() { CollisionInfo* collision = ShapeCollider::sphereVsAACubeHelper(sphereCenter, sphereRadius, cubeCenter, cubeSide, collisions); - if (collision) { QFAIL_WITH_MESSAGE("sphere should NOT collide with cube edge.\n\t\t" << "edgeNormal = " << edgeNormal); -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube edge." -// << " edgeNormal = " << edgeNormal << std::endl; } } @@ -726,8 +549,6 @@ void ShapeColliderTests::sphereMissesAACube() { QFAIL_WITH_MESSAGE("sphere should NOT collide with cube corner\n\t\t" << "cornerNormal = " << cornerNormal); -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should NOT collide with cube corner." -// << "cornerNormal = " << cornerNormal << std::endl; break; } } @@ -777,34 +598,15 @@ void ShapeColliderTests::sphereTouchesAACubeFaces() { QFAIL_WITH_MESSAGE("sphere should collide outside cube face\n\t\t" << "faceNormal = " << faceNormal); -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should collide outside cube face." -// << " faceNormal = " << faceNormal -// << std::endl; break; } QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration -// << " expected " << expectedPenetration << " faceNormal = " << faceNormal << std::endl; -// } - glm::vec3 expectedContact = sphereCenter - sphereRadius * faceNormal; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); -// if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint -// << " expected " << expectedContact << " faceNormal = " << faceNormal << std::endl; -// } - QCOMPARE(collision->getShapeA(), (Shape*)nullptr); -// if (collision->getShapeA()) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: collision->_shapeA should be NULL" << std::endl; -// } QCOMPARE(collision->getShapeB(), (Shape*)nullptr); -// if (collision->getShapeB()) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: collision->_shapeB should be NULL" << std::endl; -// } } } @@ -821,24 +623,14 @@ void ShapeColliderTests::sphereTouchesAACubeFaces() { if (!collision) { QFAIL_WITH_MESSAGE("sphere should collide inside cube face.\n\t\t" << "faceNormal = " << faceNormal); -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should collide inside cube face." -// << " faceNormal = " << faceNormal << std::endl; break; } glm::vec3 expectedPenetration = - overlap * faceNormal; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration -// << " expected " << expectedPenetration << " faceNormal = " << faceNormal << std::endl; -// } - + glm::vec3 expectedContact = sphereCenter - sphereRadius * faceNormal; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); -// if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint -// << " expected " << expectedContact << " faceNormal = " << faceNormal << std::endl; -// } } } } @@ -891,26 +683,15 @@ void ShapeColliderTests::sphereTouchesAACubeEdges() { CollisionInfo* collision = ShapeCollider::sphereVsAACubeHelper(sphereCenter, sphereRadius, cubeCenter, cubeSide, collisions); - if (!collision) { QFAIL_WITH_MESSAGE("sphere should collide with cube edge.\n\t\t" << "edgeNormal = " << edgeNormal); -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: sphere should collide with cube edge." -// << " edgeNormal = " << edgeNormal << std::endl; break; } QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration -// << " expected " << expectedPenetration << " edgeNormal = " << edgeNormal << std::endl; -// } glm::vec3 expectedContact = sphereCenter - sphereRadius * edgeNormal; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); -// if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint -// << " expected " << expectedContact << " edgeNormal = " << edgeNormal << std::endl; -// } } } } @@ -966,17 +747,9 @@ void ShapeColliderTests::sphereTouchesAACubeCorners() { glm::vec3 expectedPenetration = - overlap * offsetAxis; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, EPSILON); -// if (glm::distance(expectedPenetration, collision->_penetration) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: penetration = " << collision->_penetration -// << " expected " << expectedPenetration << " cornerNormal = " << cornerNormal << std::endl; -// } glm::vec3 expectedContact = sphereCenter - sphereRadius * offsetAxis; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContact, EPSILON); -// if (glm::distance(expectedContact, collision->_contactPoint) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: contactaPoint = " << collision->_contactPoint -// << " expected " << expectedContact << " cornerNormal = " << cornerNormal << std::endl; -// } } } } @@ -1026,10 +799,6 @@ void ShapeColliderTests::capsuleMissesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), false); -// if (ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should NOT collide with cube face." -// << " faceNormal = " << faceNormal << std::endl; -// } } } @@ -1076,10 +845,6 @@ void ShapeColliderTests::capsuleMissesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), false); -// if (hit) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should NOT collide with cube face." -// << " edgeNormal = " << edgeNormal << std::endl; -// } } } } @@ -1118,10 +883,6 @@ void ShapeColliderTests::capsuleMissesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), false); -// if (ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should NOT collide with cube face." -// << " cornerNormal = " << cornerNormal << std::endl; -// } } } } @@ -1174,10 +935,6 @@ void ShapeColliderTests::capsuleMissesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), false); -// if (ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should NOT collide with cube" -// << " edgeNormal = " << edgeNormal << std::endl; -// } } } } @@ -1224,10 +981,6 @@ void ShapeColliderTests::capsuleMissesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), false); -// if (ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should NOT collide with cube" -// << " cornerNormal = " << cornerNormal << std::endl; -// } } } } @@ -1261,11 +1014,6 @@ void ShapeColliderTests::capsuleMissesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), false); -// if (ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should NOT collide with cube" -// << " faceNormal = " << faceNormal << std::endl; -// break; -// } } } } @@ -1318,43 +1066,16 @@ void ShapeColliderTests::capsuleTouchesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), true); -// if (!ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should collide with cube" -// << " faceNormal = " << faceNormal << std::endl; -// break; -// } CollisionInfo* collision = collisions.getLastCollision(); - QCOMPARE(collision != nullptr, true); -// if (!collision) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: null collision with faceNormal = " << faceNormal << std::endl; -// return; -// } // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * faceNormal; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration -// << " faceNormal = " << faceNormal -// << std::endl; -// } // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint - capsuleRadius * faceNormal; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint -// << " faceNormal = " << faceNormal -// << std::endl; -// } } } @@ -1402,42 +1123,17 @@ void ShapeColliderTests::capsuleTouchesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), true); -// if (!ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should collide with cube" -// << " edgeNormal = " << edgeNormal << std::endl; -// } CollisionInfo* collision = collisions.getLastCollision(); QCOMPARE(collision != nullptr, true); -// if (!collision) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: null collision with edgeNormal = " << edgeNormal << std::endl; -// return; -// } // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * edgeNormal; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration -// << " edgeNormal = " << edgeNormal -// << std::endl; -// } // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint - capsuleRadius * edgeNormal; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint -// << " edgeNormal = " << edgeNormal -// << std::endl; -// } } } } @@ -1477,42 +1173,17 @@ void ShapeColliderTests::capsuleTouchesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), true); -// if (!ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should collide with cube" -// << " cornerNormal = " << cornerNormal << std::endl; -// } CollisionInfo* collision = collisions.getLastCollision(); QCOMPARE(collision != nullptr, true); -// if (!collision) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: null collision with cornerNormal = " << cornerNormal << std::endl; -// return; -// } // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * cornerNormal; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration -// << " cornerNormal = " << cornerNormal -// << std::endl; -// } // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint - capsuleRadius * cornerNormal; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint -// << " cornerNormal = " << cornerNormal -// << std::endl; -// } } } } @@ -1565,43 +1236,17 @@ void ShapeColliderTests::capsuleTouchesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), true); -// if (!ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should collide with cube" -// << " edgeNormal = " << edgeNormal << std::endl; -// } CollisionInfo* collision = collisions.getLastCollision(); QCOMPARE(collision != nullptr, true); -// if (!collision) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: null collision with edgeNormal = " << edgeNormal << std::endl; -// return; -// } // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * deflectedNormal; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > allowableError / capsuleLength) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration -// << " edgeNormal = " << edgeNormal -// << std::endl; -// } // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = axisPoint - capsuleRadius * deflectedNormal; - QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > allowableError / capsuleLength) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint -// << " edgeNormal = " << edgeNormal -// << std::endl; -// } - } + QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); } } } } @@ -1648,42 +1293,17 @@ void ShapeColliderTests::capsuleTouchesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), true); -// if (!ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should collide with cube" -// << " cornerNormal = " << cornerNormal << std::endl; -// } CollisionInfo* collision = collisions.getLastCollision(); QCOMPARE(collision != nullptr, true); -// if (!collision) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: null collision with cornerNormal = " << cornerNormal << std::endl; -// return; -// } // penetration points from capsule into cube glm::vec3 expectedPenetration = overlap * penetrationNormal; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration -// << " cornerNormal = " << cornerNormal -// << std::endl; -// } // contactPoint is on surface of capsule glm::vec3 expectedContactPoint = collidingPoint + capsuleRadius * penetrationNormal; QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); -// inaccuracy = glm::length(collision->_contactPoint - expectedContactPoint); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contactPoint: expected = " << expectedContactPoint -// << " actual = " << collision->_contactPoint -// << " cornerNormal = " << cornerNormal -// << std::endl; -// } } } } @@ -1717,21 +1337,7 @@ void ShapeColliderTests::capsuleTouchesAACube() { // collide capsule with cube QCOMPARE(ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions), true); -// if (!ShapeCollider::capsuleVsAACube(&capsule, &cube, collisions)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: capsule should collide with cube" -// << " faceNormal = " << faceNormal << std::endl; -// break; -// } - QCOMPARE(collisions.size(), 2); -// int numCollisions = collisions.size(); -// if (numCollisions != 2) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: capsule should hit cube face at two spots." -// << " Expected collisions size of 2 but is actually " << numCollisions -// << ". faceNormal = " << faceNormal << std::endl; -// break; -// } // compute the expected contact points // NOTE: whether the startPoint or endPoint are expected to collide depends the relative values @@ -1757,14 +1363,6 @@ void ShapeColliderTests::capsuleTouchesAACube() { // penetration points from capsule into cube glm::vec3 expectedPenetration = - overlap * faceNormal; QCOMPARE_WITH_ABS_ERROR(collision->_penetration, expectedPenetration, allowableError); -// float inaccuracy = glm::length(collision->_penetration - expectedPenetration); -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad penetration: expected = " << expectedPenetration -// << " actual = " << collision->_penetration -// << " faceNormal = " << faceNormal -// << std::endl; -// } // the order of the final contact points is undefined, so we // figure out which expected contact point is the closest to the real one @@ -1774,14 +1372,6 @@ void ShapeColliderTests::capsuleTouchesAACube() { glm::vec3 expectedContactPoint = (length0 < length1) ? expectedContactPoints[0] : expectedContactPoints[1]; // contactPoint is on surface of capsule QCOMPARE_WITH_ABS_ERROR(collision->_contactPoint, expectedContactPoint, allowableError); -// inaccuracy = (length0 < length1) ? length0 : length1; -// if (fabsf(inaccuracy) > allowableError) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: bad contact: expectedContactPoint[" << k << "] = " << expectedContactPoint -// << " actual = " << collision->_contactPoint -// << " faceNormal = " << faceNormal -// << std::endl; -// } } } } @@ -1803,21 +1393,10 @@ void ShapeColliderTests::rayHitsSphere() { intersection._rayDirection = xAxis; QCOMPARE(sphere.findRayIntersection(intersection), true); -// if (!sphere.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should intersect sphere" << std::endl; -// } float expectedDistance = startDistance - radius; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " << relativeError << std::endl; -// } QCOMPARE(intersection._hitShape, &sphere); -// if (intersection._hitShape != &sphere) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should point at sphere" -// << std::endl; -// } } // ray along a diagonal axis @@ -1826,16 +1405,9 @@ void ShapeColliderTests::rayHitsSphere() { intersection._rayStart = glm::vec3(startDistance, startDistance, 0.0f); intersection._rayDirection = - glm::normalize(intersection._rayStart); QCOMPARE(sphere.findRayIntersection(intersection), true); -// if (!sphere.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should intersect sphere" << std::endl; -// } float expectedDistance = SQUARE_ROOT_OF_2 * startDistance - radius; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " << relativeError << std::endl; -// } } // rotated and displaced ray and sphere @@ -1858,17 +1430,8 @@ void ShapeColliderTests::rayHitsSphere() { sphere.setTranslation(rotation * translation); QCOMPARE(sphere.findRayIntersection(intersection), true); -// if (!sphere.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should intersect sphere" << std::endl; -// } - float expectedDistance = startDistance - radius; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray sphere intersection distance error = " -// << relativeError << std::endl; -// } } } @@ -1887,14 +1450,7 @@ void ShapeColliderTests::rayBarelyHitsSphere() { // very simple ray along xAxis QCOMPARE(sphere.findRayIntersection(intersection), true); -// if (!sphere.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely hit sphere" << std::endl; -// } QCOMPARE(intersection._hitShape, &sphere); -// if (intersection._hitShape != &sphere) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should point at sphere" -// << std::endl; -// } } { @@ -1911,9 +1467,6 @@ void ShapeColliderTests::rayBarelyHitsSphere() { // ...and test again QCOMPARE(sphere.findRayIntersection(intersection), true); -// if (!sphere.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely hit sphere" << std::endl; -// } } } @@ -1932,17 +1485,9 @@ void ShapeColliderTests::rayBarelyMissesSphere() { intersection._rayStart = glm::vec3(-startDistance, radius + delta, 0.0f); intersection._rayDirection = xAxis; - // FIXME: FAILED TEST // very simple ray along xAxis QCOMPARE(sphere.findRayIntersection(intersection), false); -// if (sphere.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely miss sphere" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } } { @@ -1959,18 +1504,8 @@ void ShapeColliderTests::rayBarelyMissesSphere() { // ...and test again QCOMPARE(sphere.findRayIntersection(intersection), false); -// if (sphere.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should just barely miss sphere" << std::endl; -// } QCOMPARE(intersection._hitDistance == FLT_MAX, true); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } QCOMPARE(intersection._hitShape == nullptr, true); -// if (intersection._hitShape != NULL) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should be NULL" << std::endl; -// } } } @@ -1987,21 +1522,9 @@ void ShapeColliderTests::rayHitsCapsule() { intersection._rayStart = glm::vec3(startDistance, 0.0f, 0.0f); intersection._rayDirection = - xAxis; QCOMPARE(capsule.findRayIntersection(intersection), true); -// if (!capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; -// } float expectedDistance = startDistance - radius; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " -// << relativeError << std::endl; -// } QCOMPARE(intersection._hitShape, &capsule); -// if (intersection._hitShape != &capsule) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should point at capsule" -// << std::endl; -// } } { // toward top of cylindrical wall @@ -2009,16 +1532,8 @@ void ShapeColliderTests::rayHitsCapsule() { intersection._rayStart = glm::vec3(startDistance, halfHeight, 0.0f); intersection._rayDirection = - xAxis; QCOMPARE(capsule.findRayIntersection(intersection), true); -// if (!capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; -// } float expectedDistance = startDistance - radius; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " -// << relativeError << std::endl; -// } } float delta = 2.0f * EPSILON; @@ -2027,16 +1542,8 @@ void ShapeColliderTests::rayHitsCapsule() { intersection._rayStart = glm::vec3(startDistance, halfHeight + delta, 0.0f); intersection._rayDirection = - xAxis; QCOMPARE(capsule.findRayIntersection(intersection), true); -// if (!capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; -// } float expectedDistance = startDistance - radius; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " -// << relativeError << std::endl; -// } } const float EDGE_CASE_SLOP_FACTOR = 20.0f; @@ -2045,17 +1552,10 @@ void ShapeColliderTests::rayHitsCapsule() { intersection._rayStart = glm::vec3(startDistance, halfHeight + radius - delta, 0.0f); intersection._rayDirection = - xAxis; QCOMPARE(capsule.findRayIntersection(intersection), true); -// if (!capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; -// } float expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // for edge cases we allow a LOT of error QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EDGE_CASE_SLOP_FACTOR * EPSILON); -// if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " -// << relativeError << std::endl; -// } } { // toward tip of bottom cap @@ -2063,17 +1563,10 @@ void ShapeColliderTests::rayHitsCapsule() { intersection._rayStart = glm::vec3(startDistance, - halfHeight - radius + delta, 0.0f); intersection._rayDirection = - xAxis; QCOMPARE(capsule.findRayIntersection(intersection), true); -// if (!capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; -// } float expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine // float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // for edge cases we allow a LOT of error QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON * EDGE_CASE_SLOP_FACTOR); -// if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " -// << relativeError << std::endl; -// } } { // toward edge of capsule cylindrical face @@ -2081,17 +1574,10 @@ void ShapeColliderTests::rayHitsCapsule() { intersection._rayStart = glm::vec3(startDistance, 0.0f, radius - delta); intersection._rayDirection = - xAxis; QCOMPARE(capsule.findRayIntersection(intersection), true); -// if (!capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit capsule" << std::endl; -// } float expectedDistance = startDistance - radius * sqrtf(2.0f * delta); // using small angle approximation of cosine float relativeError = fabsf(intersection._hitDistance - expectedDistance) / startDistance; // for edge cases we allow a LOT of error QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, startDistance * EPSILON * EDGE_CASE_SLOP_FACTOR); -// if (relativeError > EDGE_CASE_SLOP_FACTOR * EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray capsule intersection distance error = " -// << relativeError << std::endl; -// } } // TODO: test at steep angles near cylinder/cap junction } @@ -2115,45 +1601,21 @@ void ShapeColliderTests::rayMissesCapsule() { intersection._rayStart.y = halfHeight + radius + delta; intersection._hitDistance = FLT_MAX; QCOMPARE(capsule.findRayIntersection(intersection), false); -// if (capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss capsule" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } // below bottom cap intersection._rayStart.y = - halfHeight - radius - delta; intersection._hitDistance = FLT_MAX; QCOMPARE(capsule.findRayIntersection(intersection), false); -// if (capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss capsule" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } // past edge of capsule cylindrical face intersection._rayStart.y = 0.0f; intersection._rayStart.z = radius + delta; intersection._hitDistance = FLT_MAX; QCOMPARE(capsule.findRayIntersection(intersection), false); -// if (capsule.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss capsule" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } QCOMPARE(intersection._hitShape, (Shape*)nullptr); -// if (intersection._hitShape != NULL) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should be NULL" << std::endl; -// } } // TODO: test at steep angles near edge } @@ -2174,23 +1636,10 @@ void ShapeColliderTests::rayHitsPlane() { intersection._rayDirection = glm::normalize(glm::vec3(1.0f, 1.0f, 1.0f)); QCOMPARE(plane.findRayIntersection(intersection), true); -// if (!plane.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit plane" << std::endl; -// } - float expectedDistance = SQUARE_ROOT_OF_3 * planeDistanceFromOrigin; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, planeDistanceFromOrigin * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / planeDistanceFromOrigin; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray plane intersection distance error = " -// << relativeError << std::endl; -// } QCOMPARE(intersection._hitShape, &plane); -// if (intersection._hitShape != &plane) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should point at plane" -// << std::endl; -// } } { // rotate the whole system and try again @@ -2205,17 +1654,9 @@ void ShapeColliderTests::rayHitsPlane() { intersection._rayDirection = rotation * glm::normalize(glm::vec3(1.0f, 1.0f, 1.0f)); QCOMPARE(plane.findRayIntersection(intersection), true); -// if (!plane.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit plane" << std::endl; -// } float expectedDistance = SQUARE_ROOT_OF_3 * planeDistanceFromOrigin; QCOMPARE_WITH_ABS_ERROR(intersection._hitDistance, expectedDistance, planeDistanceFromOrigin * EPSILON); -// float relativeError = fabsf(intersection._hitDistance - expectedDistance) / planeDistanceFromOrigin; -// if (relativeError > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray plane intersection distance error = " -// << relativeError << std::endl; -// } } } @@ -2233,15 +1674,8 @@ void ShapeColliderTests::rayMissesPlane() { intersection._rayDirection = glm::normalize(glm::vec3(-1.0f, 0.0f, -1.0f)); QCOMPARE(plane.findRayIntersection(intersection), false); -// if (plane.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } - + // rotate the whole system and try again float angle = 37.8f; glm::vec3 axis = glm::normalize( glm::vec3(-7.0f, 2.8f, 9.3f) ); @@ -2255,18 +1689,8 @@ void ShapeColliderTests::rayMissesPlane() { intersection._hitDistance = FLT_MAX; QCOMPARE(plane.findRayIntersection(intersection), false); -// if (plane.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } QCOMPARE(intersection._hitShape, (Shape*)nullptr); -// if (intersection._hitShape != NULL) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should be NULL" << std::endl; -// } } { // make a simple ray that points away from plane @@ -2278,14 +1702,7 @@ void ShapeColliderTests::rayMissesPlane() { intersection._hitDistance = FLT_MAX; QCOMPARE(plane.findRayIntersection(intersection), false); -// if (plane.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } // rotate the whole system and try again float angle = 37.8f; @@ -2300,14 +1717,7 @@ void ShapeColliderTests::rayMissesPlane() { intersection._hitDistance = FLT_MAX; QCOMPARE(plane.findRayIntersection(intersection), false); -// if (plane.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should miss plane" << std::endl; -// } QCOMPARE(intersection._hitDistance, FLT_MAX); -// if (intersection._hitDistance != FLT_MAX) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: distance should be unchanged after intersection miss" -// << std::endl; -// } } } @@ -2353,28 +1763,9 @@ void ShapeColliderTests::rayHitsAACube() { // validate QCOMPARE(cube.findRayIntersection(intersection), true); -// if (!hit) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should hit cube face" << std::endl; -// break; -// } QCOMPARE_WITH_ABS_ERROR(glm::dot(faceNormal, intersection._hitNormal), 1.0f, EPSILON); -// if (glm::abs(1.0f - glm::dot(faceNormal, intersection._hitNormal)) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: ray should hit cube face with normal " << faceNormal -// << " but found different normal " << intersection._hitNormal << std::endl; -// } QCOMPARE_WITH_ABS_ERROR(facePoint, intersection.getIntersectionPoint(), EPSILON); -// if (glm::distance(facePoint, intersection.getIntersectionPoint()) > EPSILON) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: ray should hit cube face at " << facePoint -// << " but actually hit at " << intersection.getIntersectionPoint() -// << std::endl; -// } QCOMPARE(intersection._hitShape, &cube); -// if (intersection._hitShape != &cube) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray intersection._hitShape should point at cube" -// << std::endl; -// } } } } @@ -2424,10 +1815,6 @@ void ShapeColliderTests::rayMissesAACube() { // cast the ray QCOMPARE(cube.findRayIntersection(intersection), false); -// if (cube.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should NOT hit cube face " -// << faceNormal << std::endl; -// } } } } @@ -2467,10 +1854,6 @@ void ShapeColliderTests::rayMissesAACube() { // cast the ray QCOMPARE(cube.findRayIntersection(intersection), false); -// if (cube.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should NOT hit cube face " -// << faceNormal << std::endl; -// } } } } @@ -2511,10 +1894,6 @@ void ShapeColliderTests::rayMissesAACube() { // cast the ray QCOMPARE(cube.findRayIntersection(intersection), false); -// if (cube.findRayIntersection(intersection)) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: ray should NOT hit cube face " -// << faceNormal << std::endl; -// } } } } @@ -2524,7 +1903,7 @@ void ShapeColliderTests::rayMissesAACube() { void ShapeColliderTests::measureTimeOfCollisionDispatch() { - // use QBENCHMARK for this + // TODO: use QBENCHMARK for this /* KEEP for future manual testing // create two non-colliding spheres diff --git a/tests/physics/src/ShapeInfoTests.cpp b/tests/physics/src/ShapeInfoTests.cpp index a34bf97955..01f5c4e511 100644 --- a/tests/physics/src/ShapeInfoTests.cpp +++ b/tests/physics/src/ShapeInfoTests.cpp @@ -150,23 +150,11 @@ void ShapeInfoTests::testBoxShape() { btCollisionShape* shape = ShapeFactory::createShapeFromInfo(info); QCOMPARE(shape != nullptr, true); -// if (!shape) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: NULL Box shape" << std::endl; -// } - + ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); 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; -// } - 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; } @@ -183,15 +171,7 @@ void ShapeInfoTests::testSphereShape() { ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); 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; } @@ -210,15 +190,7 @@ void ShapeInfoTests::testCylinderShape() { ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); 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; -// } + QCOMPARE(key.getHash2(), otherKey.getHash2()); delete shape; */ @@ -238,27 +210,9 @@ void ShapeInfoTests::testCapsuleShape() { ShapeInfo otherInfo = info; DoubleHashKey otherKey = otherInfo.getHash(); 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; -// } + QCOMPARE(key.getHash2(), otherKey.getHash2()); delete shape; */ } -//void ShapeInfoTests::runAllTests() { -////#define MANUAL_TEST -//#ifdef MANUAL_TEST -// testHashFunctions(); -//#endif // MANUAL_TEST -// testBoxShape(); -// testSphereShape(); -// testCylinderShape(); -// testCapsuleShape(); -//} diff --git a/tests/physics/src/ShapeManagerTests.cpp b/tests/physics/src/ShapeManagerTests.cpp index 3d3a2debcb..1ee7cd561e 100644 --- a/tests/physics/src/ShapeManagerTests.cpp +++ b/tests/physics/src/ShapeManagerTests.cpp @@ -24,41 +24,22 @@ void ShapeManagerTests::testShapeAccounting() { int numReferences = shapeManager.getNumReferences(info); 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); QCOMPARE(shape != nullptr, true); -// if (!shape) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: expected shape creation for default parameters" << std::endl; -// } // verify number of shapes 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); 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; 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); @@ -68,67 +49,35 @@ void ShapeManagerTests::testShapeAccounting() { numReferences--; } QCOMPARE(released, true); -// if (!released) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected shape released" << std::endl; -// } // verify shape still exists (not yet garbage collected) 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); 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); 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(); QCOMPARE(shapeManager.getNumShapes(), 1); -// if (shapeManager.getNumShapes() != 1) { -// std::cout << __FILE__ << ":" << __LINE__ << " ERROR: expected one shape after release" << std::endl; -// } numReferences = shapeManager.getNumReferences(info); 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(); 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); 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() { @@ -149,10 +98,6 @@ void ShapeManagerTests::addManyShapes() { btCollisionShape* shape = shapeManager.getShape(info); shapes.push_back(shape); 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; @@ -160,30 +105,17 @@ void ShapeManagerTests::addManyShapes() { shape = shapeManager.getShape(info); shapes.push_back(shape); 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(); 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); QCOMPARE(success, true); -// if (!success) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: failed to release shape index " << i << std::endl; -// break; -// } } // verify zero references @@ -191,11 +123,6 @@ void ShapeManagerTests::addManyShapes() { btCollisionShape* shape = shapes[i]; int numReferences = shapeManager.getNumReferences(shape); QCOMPARE(numReferences, 0); -// if (numReferences != 0) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: expected zero references for shape " << i -// << " but refCount = " << numReferences << std::endl; -// } } } @@ -210,10 +137,6 @@ void ShapeManagerTests::addBoxShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); QCOMPARE(shape, otherShape); -// if (shape != otherShape) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: Box ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; -// } } void ShapeManagerTests::addSphereShape() { @@ -227,10 +150,6 @@ void ShapeManagerTests::addSphereShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); QCOMPARE(shape, otherShape); -// if (shape != otherShape) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: Sphere ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; -// } } void ShapeManagerTests::addCylinderShape() { @@ -246,10 +165,6 @@ void ShapeManagerTests::addCylinderShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); QCOMPARE(shape, otherShape); -// if (shape != otherShape) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: Cylinder ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; -// } */ } @@ -266,9 +181,5 @@ void ShapeManagerTests::addCapsuleShape() { ShapeInfo otherInfo = info; btCollisionShape* otherShape = shapeManager.getShape(otherInfo); QCOMPARE(shape, otherShape); -// if (shape != otherShape) { -// std::cout << __FILE__ << ":" << __LINE__ -// << " ERROR: Capsule ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl; -// } */ } diff --git a/tests/shared/CMakeLists.txt b/tests/shared/CMakeLists.txt index 2fca6ea754..bc6eab0212 100644 --- a/tests/shared/CMakeLists.txt +++ b/tests/shared/CMakeLists.txt @@ -2,10 +2,10 @@ # 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() \ No newline at end of file diff --git a/tests/shared/src/MovingPercentileTests.cpp b/tests/shared/src/MovingPercentileTests.cpp index 5fc39c1daf..af97f09e29 100644 --- a/tests/shared/src/MovingPercentileTests.cpp +++ b/tests/shared/src/MovingPercentileTests.cpp @@ -147,154 +147,3 @@ void MovingPercentileTests::testRunningMedianForN (int n) { } } -// -// NOT THIS: -// - -//void MovingPercentileTests::runAllTests() { -// -// QVector valuesForN; -// -// valuesForN.append(1); -// valuesForN.append(2); -// valuesForN.append(3); -// valuesForN.append(4); -// valuesForN.append(5); -// valuesForN.append(10); -// valuesForN.append(100); -// -// -// QQueue lastNSamples; -// -// for (int i=0; i N) { -// lastNSamples.pop_front(); -// } -// -// movingMin.updatePercentile(sample); -// -// float experimentMin = movingMin.getValueAtPercentile(); -// -// float actualMin = lastNSamples[0]; -// for (int j = 0; j < lastNSamples.size(); j++) { -// if (lastNSamples.at(j) < actualMin) { -// actualMin = lastNSamples.at(j); -// } -// } -// -// if (experimentMin != actualMin) { -// qDebug() << "\t\t FAIL at sample" << s; -// fail = true; -// break; -// } -// } -// if (!fail) { -// qDebug() << "\t\t PASS"; -// } -// } -// -// -// { -// bool fail = false; -// -// qDebug() << "\t testing running max..."; -// -// lastNSamples.clear(); -// MovingPercentile movingMax(N, 1.0f); -// -// for (int s = 0; s < 10000; s++) { -// -// float sample = random(); -// -// lastNSamples.push_back(sample); -// if (lastNSamples.size() > N) { -// lastNSamples.pop_front(); -// } -// -// movingMax.updatePercentile(sample); -// -// float experimentMax = movingMax.getValueAtPercentile(); -// -// float actualMax = lastNSamples[0]; -// for (int j = 0; j < lastNSamples.size(); j++) { -// if (lastNSamples.at(j) > actualMax) { -// actualMax = lastNSamples.at(j); -// } -// } -// -// if (experimentMax != actualMax) { -// qDebug() << "\t\t FAIL at sample" << s; -// fail = true; -// break; -// } -// } -// if (!fail) { -// qDebug() << "\t\t PASS"; -// } -// } -// -// -// { -// bool fail = false; -// -// qDebug() << "\t testing running median..."; -// -// lastNSamples.clear(); -// MovingPercentile movingMedian(N, 0.5f); -// -// for (int s = 0; s < 10000; s++) { -// -// float sample = random(); -// -// lastNSamples.push_back(sample); -// if (lastNSamples.size() > N) { -// lastNSamples.pop_front(); -// } -// -// movingMedian.updatePercentile(sample); -// -// float experimentMedian = movingMedian.getValueAtPercentile(); -// -// int samplesLessThan = 0; -// int samplesMoreThan = 0; -// -// for (int j=0; j experimentMedian) { -// samplesMoreThan++; -// } -// } -// -// -// if (!(samplesLessThan <= N/2 && samplesMoreThan <= N-1/2)) { -// qDebug() << "\t\t FAIL at sample" << s; -// fail = true; -// break; -// } -// } -// if (!fail) { -// qDebug() << "\t\t PASS"; -// } -// } -// } -//} - diff --git a/tests/ui/CMakeLists.txt b/tests/ui/CMakeLists.txt index 45a04c671e..aa942f916d 100644 --- a/tests/ui/CMakeLists.txt +++ b/tests/ui/CMakeLists.txt @@ -7,10 +7,10 @@ setup_hifi_project(Widgets OpenGL Network Qml Quick Script) set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") 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) + 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