summaryrefslogtreecommitdiffstats
path: root/tests/BoundingBox
diff options
context:
space:
mode:
Diffstat (limited to 'tests/BoundingBox')
-rw-r--r--tests/BoundingBox/BoundingBoxTest.cpp77
-rw-r--r--tests/BoundingBox/CMakeLists.txt47
2 files changed, 124 insertions, 0 deletions
diff --git a/tests/BoundingBox/BoundingBoxTest.cpp b/tests/BoundingBox/BoundingBoxTest.cpp
new file mode 100644
index 000000000..e3df95efa
--- /dev/null
+++ b/tests/BoundingBox/BoundingBoxTest.cpp
@@ -0,0 +1,77 @@
+
+// ByteBufferTest.cpp
+
+// Implements the main app entrypoint for the cByteBuffer class test
+
+#include "Globals.h"
+#include "BoundingBox.h"
+
+
+
+
+
+/** Runs the tests, returns the number of failed tests. */
+static int Test(void)
+{
+ int NumFailed = 0;
+ Vector3d Min(1, 1, 1);
+ Vector3d Max(2, 2, 2);
+ Vector3d LineDefs[] =
+ {
+ Vector3d(1.5, 4, 1.5), Vector3d(1.5, 3, 1.5), // Should intersect at 2, face 1 (YP)
+ Vector3d(1.5, 0, 1.5), Vector3d(1.5, 4, 1.5), // Should intersect at 0.25, face 0 (YM)
+ Vector3d(0, 0, 0), Vector3d(2, 2, 2), // Should intersect at 0.5, face 0, 3 or 5 (anyM)
+ Vector3d(0.999, 0, 1.5), Vector3d(0.999, 4, 1.5), // Should not intersect
+ Vector3d(1.999, 0, 1.5), Vector3d(1.999, 4, 1.5), // Should intersect at 0.25, face 0 (YM)
+ Vector3d(2.001, 0, 1.5), Vector3d(2.001, 4, 1.5), // Should not intersect
+ } ;
+ bool Results[] = {true, true, true, false, true, false};
+ double LineCoeffs[] = {2, 0.25, 0.5, 0, 0.25, 0};
+
+ for (size_t i = 0; i < ARRAYCOUNT(LineDefs) / 2; i++)
+ {
+ double LineCoeff;
+ eBlockFace Face;
+ Vector3d Line1 = LineDefs[2 * i];
+ Vector3d Line2 = LineDefs[2 * i + 1];
+ bool res = cBoundingBox::CalcLineIntersection(Min, Max, Line1, Line2, LineCoeff, Face);
+ if (res != Results[i])
+ {
+ LOGERROR("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d",
+ Line1.x, Line1.y, Line1.z,
+ Line2.x, Line2.y, Line2.z,
+ res ? 1 : 0, LineCoeff, Face
+ );
+ NumFailed += 1;
+ }
+ if (res)
+ {
+ if (LineCoeff != LineCoeffs[i])
+ {
+ LOGERROR("LineIntersection({%.02f, %.02f, %.02f}, {%.02f, %.02f, %.02f}) -> %d, %.05f, %d",
+ Line1.x, Line1.y, Line1.z,
+ Line2.x, Line2.y, Line2.z,
+ res ? 1 : 0, LineCoeff, Face
+ );
+ NumFailed += 1;
+ }
+ }
+ } // for i - LineDefs[]
+ return 0;
+}
+
+
+
+
+
+int main(int argc, char * argv[])
+{
+ auto NumFailed = Test();
+ LOG("BoundingBox test finished, number of failed tests: %d", NumFailed);
+ return NumFailed;
+}
+
+
+
+
+
diff --git a/tests/BoundingBox/CMakeLists.txt b/tests/BoundingBox/CMakeLists.txt
new file mode 100644
index 000000000..30cacc447
--- /dev/null
+++ b/tests/BoundingBox/CMakeLists.txt
@@ -0,0 +1,47 @@
+cmake_minimum_required (VERSION 2.6)
+
+enable_testing()
+add_definitions(-DTEST_GLOBALS=1)
+
+include_directories(${CMAKE_SOURCE_DIR}/src/)
+
+add_definitions(-DTEST_GLOBALS=1)
+
+set (SHARED_SRCS
+ ${CMAKE_SOURCE_DIR}/src/BoundingBox.cpp
+ ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp
+)
+
+set (SHARED_HDRS
+ ${CMAKE_SOURCE_DIR}/src/BoundingBox.h
+ ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h
+)
+
+set (SRCS
+ BoundingBoxTest.cpp
+)
+
+if (MSVC)
+ # Add the MSVC-specific LeakFinder / StackTracer sources:
+ list (APPEND SHARED_SRCS ${CMAKE_SOURCE_DIR}/src/LeakFinder.cpp ${CMAKE_SOURCE_DIR}/src/StackWalker.cpp)
+ list (APPEND SHARED_HDRS ${CMAKE_SOURCE_DIR}/src/LeakFinder.h ${CMAKE_SOURCE_DIR}/src/StackWalker.h)
+endif()
+
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
+ add_flags_cxx("-Wno-error=float-equal")
+endif()
+
+source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
+source_group("Sources" FILES ${SRCS})
+add_executable(BoundingBox-exe ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS})
+add_test(NAME BoundingBox-test COMMAND BoundingBox-exe)
+
+
+
+
+
+# Put the projects into solution folders (MSVC):
+set_target_properties(
+ BoundingBox-exe
+ PROPERTIES FOLDER Tests
+)