Browse Source

Merge branch 'master' into compatibility

Conflicts:
	src/CMakeLists.txt
	src/Math/Test/CMakeLists.txt
	src/Math/Test/MathTypeTraitsTest.cpp
	src/MeshTools/Test/TipsifyTest.h
	src/Physics/Test/ShapeGroupTest.cpp
Vladimír Vondruš 14 years ago
parent
commit
e1fcfead7d
  1. 6
      CMakeLists.txt
  2. 2
      PKGBUILD
  3. 4
      README.md
  4. 4
      doc/building.dox
  5. 156
      modules/FindCorrade.cmake
  6. 45
      modules/FindMagnum.cmake
  7. 5
      package/archlinux/magnum-git/PKGBUILD
  8. 2
      src/CMakeLists.txt
  9. 4
      src/Math/Geometry/Test/CMakeLists.txt
  10. 26
      src/Math/Geometry/Test/DistanceTest.cpp
  11. 8
      src/Math/Geometry/Test/DistanceTest.h
  12. 20
      src/Math/Geometry/Test/IntersectionTest.cpp
  13. 8
      src/Math/Geometry/Test/IntersectionTest.h
  14. 19
      src/Math/Test/CMakeLists.txt
  15. 26
      src/Math/Test/MathTest.cpp
  16. 8
      src/Math/Test/MathTest.h
  17. 29
      src/Math/Test/MathTypeTraitsTest.cpp
  18. 8
      src/Math/Test/MathTypeTraitsTest.h
  19. 29
      src/Math/Test/Matrix3Test.cpp
  20. 8
      src/Math/Test/Matrix3Test.h
  21. 39
      src/Math/Test/Matrix4Test.cpp
  22. 8
      src/Math/Test/Matrix4Test.h
  23. 84
      src/Math/Test/MatrixTest.cpp
  24. 8
      src/Math/Test/MatrixTest.h
  25. 12
      src/Math/Test/Vector2Test.cpp
  26. 8
      src/Math/Test/Vector2Test.h
  27. 27
      src/Math/Test/Vector3Test.cpp
  28. 8
      src/Math/Test/Vector3Test.h
  29. 22
      src/Math/Test/Vector4Test.cpp
  30. 8
      src/Math/Test/Vector4Test.h
  31. 59
      src/Math/Test/VectorTest.cpp
  32. 8
      src/Math/Test/VectorTest.h
  33. 2
      src/Math/Vector.h
  34. 2
      src/MeshTools/Clean.h
  35. 2
      src/MeshTools/Subdivide.h
  36. 18
      src/MeshTools/Test/CMakeLists.txt
  37. 12
      src/MeshTools/Test/CleanTest.cpp
  38. 8
      src/MeshTools/Test/CleanTest.h
  39. 21
      src/MeshTools/Test/CombineIndexedArraysTest.cpp
  40. 8
      src/MeshTools/Test/CombineIndexedArraysTest.h
  41. 65
      src/MeshTools/Test/CompressIndicesTest.cpp
  42. 8
      src/MeshTools/Test/CompressIndicesTest.h
  43. 22
      src/MeshTools/Test/FlipNormalsTest.cpp
  44. 8
      src/MeshTools/Test/FlipNormalsTest.h
  45. 19
      src/MeshTools/Test/GenerateFlatNormalsTest.cpp
  46. 8
      src/MeshTools/Test/GenerateFlatNormalsTest.h
  47. 29
      src/MeshTools/Test/InterleaveTest.cpp
  48. 8
      src/MeshTools/Test/InterleaveTest.h
  49. 18
      src/MeshTools/Test/SubdivideTest.cpp
  50. 8
      src/MeshTools/Test/SubdivideTest.h
  51. 15
      src/MeshTools/Test/TipsifyTest.cpp
  52. 7
      src/MeshTools/Test/TipsifyTest.h
  53. 20
      src/Physics/Test/AbstractShapeTest.h
  54. 16
      src/Physics/Test/AxisAlignedBoxTest.cpp
  55. 8
      src/Physics/Test/AxisAlignedBoxTest.h
  56. 14
      src/Physics/Test/CMakeLists.txt
  57. 17
      src/Physics/Test/CapsuleTest.cpp
  58. 6
      src/Physics/Test/CapsuleTest.h
  59. 12
      src/Physics/Test/LineTest.cpp
  60. 8
      src/Physics/Test/LineTest.h
  61. 18
      src/Physics/Test/PlaneTest.cpp
  62. 6
      src/Physics/Test/PlaneTest.h
  63. 10
      src/Physics/Test/PointTest.cpp
  64. 8
      src/Physics/Test/PointTest.h
  65. 16
      src/Physics/Test/ShapeGroupTest.cpp
  66. 8
      src/Physics/Test/ShapeGroupTest.h
  67. 23
      src/Physics/Test/SphereTest.cpp
  68. 6
      src/Physics/Test/SphereTest.h
  69. 4
      src/Primitives/Test/CMakeLists.txt
  70. 23
      src/Primitives/Test/CapsuleTest.cpp
  71. 8
      src/Primitives/Test/CapsuleTest.h
  72. 21
      src/Primitives/Test/UVSphereTest.cpp
  73. 8
      src/Primitives/Test/UVSphereTest.h
  74. 2
      src/Shaders/PhongShader.cpp
  75. 6
      src/Test/CMakeLists.txt
  76. 13
      src/Test/CameraTest.cpp
  77. 8
      src/Test/CameraTest.h
  78. 112
      src/Test/ObjectTest.cpp
  79. 8
      src/Test/ObjectTest.h
  80. 19
      src/Test/SceneTest.cpp
  81. 10
      src/Test/SceneTest.h
  82. 3
      src/Trade/AbstractImporter.h

6
CMakeLists.txt

@ -29,12 +29,6 @@ if(WITH_EVERYTHING)
endif() endif()
if(BUILD_TESTS) if(BUILD_TESTS)
find_package(Qt4)
if(NOT QT4_FOUND)
message(FATAL_ERROR "Qt4, required for building unit tests, was not found. Set BUILD_TESTS to OFF to skip building them.")
endif()
enable_testing() enable_testing()
endif() endif()

2
PKGBUILD

@ -7,7 +7,7 @@ arch=('i686' 'x86_64')
url="https://github.com/mosra/magnum" url="https://github.com/mosra/magnum"
license=('LGPLv3') license=('LGPLv3')
depends=('corrade' 'glew') depends=('corrade' 'glew')
makedepends=('cmake' 'qt') makedepends=('cmake')
options=(!strip) options=(!strip)
provides=('magnum-git') provides=('magnum-git')

4
README.md

@ -56,8 +56,8 @@ Building and running unit tests
------------------------------- -------------------------------
If you want to build also unit tests (which are not built by default), pass If you want to build also unit tests (which are not built by default), pass
`-DBUILD_TESTS=True` to CMake. Unit tests use QtTest framework (you need at `-DBUILD_TESTS=True` to CMake. Unit tests use Corrade's TestSuite framework
least **Qt 4.6**) and can be run using and can be run using
ctest -V ctest -V

4
doc/building.dox

@ -78,8 +78,8 @@ None of the context libraries is built by default, regardless to
@subsection building-tests Building and running unit tests @subsection building-tests Building and running unit tests
If you want to build also unit tests (which are not built by default), pass If you want to build also unit tests (which are not built by default), pass
`-DBUILD_TESTS=True` to CMake. Unit tests use QtTest framework (you need at `-DBUILD_TESTS=True` to CMake. Unit tests use Corrade's @ref Corrade::TestSuite
least **Qt 4.6**) and can be run using "TestSuite" framework and can be run using
ctest -V ctest -V

156
modules/FindCorrade.cmake

@ -1,59 +1,123 @@
# Find Corrade - Corrade handling module for CMake # - Find Corrade
# #
# This module defines: # Basic usage:
# find_package(Corrade [REQUIRED])
# This module tries to find Corrade library and then defines:
# CORRADE_FOUND - True if Corrade library is found
# CORRADE_INCLUDE_DIR - Include dir for Corrade
# CORRADE_LIBRARIES - All Corrade libraries
# CORRADE_UTILITY_LIBRARY - Corrade Utility library
# CORRADE_PLUGINMANAGER_LIBRARY - Corrade Plugin manager library
# CORRADE_RC_EXECUTABLE - Corrade resource compiler executable
# If Corrade library is found, these macros and functions are defined:
# #
# CORRADECORE_FOUND - True if Corrade library is found
# #
# CORRADE_INCLUDE_DIR - Include dir for Corrade # Add unit test using Corrade's TestSuite.
# corrade_add_test2(test_name
# sources...
# [LIBRARIES libraries...])
# Test name is also executable name. You can also specify libraries to link
# with instead of using target_link_libraries(). Note that the
# enable_testing() must be called explicitly.
# #
# CORRADE_LIBRARIES - All corrade libraries
# CORRADE_UTILITY_LIBRARY - Corrade Utility library
# CORRADE_PLUGINMANAGER_LIBRARY - Corrade Plugin manager library
# CORRADE_RC_EXECUTABLE - Corrade resource compiler executable
# #
# CORRADE_BINARY_INSTALL_DIR - Binary installation directory # Add QtTest unit test.
# CORRADE_LIBRARY_INSTALL_DIR - Library installation directory # corrade_add_test(test_name moc_header source_file
# CORRADE_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake modules # [libraries...])
# CORRADE_INCLUDE_INSTALL_DIR - Include installation directory for Corrade headers # These tests contain mainly from one source file and one header, which is
# processed by Qt meta-object compiler. The executable is then linked to QtCore
# and QtTest library, more libraries can be specified as another parameters.
# Test name is also executable name. Header file is processed with Qt's moc.
#
# Note: Before using this function you must find package Qt4. The
# enable_testing() function must be also called explicitly.
#
#
# Add QtTest unit test with multiple source files.
# corrade_add_multifile_test(test_name
# moc_header_variable
# source_files_variable)
# Useful when there is need to compile more than one cpp/h file into the test.
#
# Example usage:
# set(test_headers ComplexTest.h MyObject.h)
# set(test_sources ComplexTest.cpp MyObject.cpp)
# corrade_add_test(MyComplexTest test_headers test_sources
# CoreLibrary AnotherLibrary)
#
# Compile data resources into application binary.
# corrade_add_resource(name group_name
# file [ALIAS alias]
# [file1 [ALIAS alias1]...])
# Depends on corrade-rc, which is part of Corrade utilities. This command
# generates resource file with group group_name from given files in current
# build directory. Argument name is name under which the resources can be
# explicitly loaded. Variable 'name' contains compiled resource filename,
# which is then used for compiling library / executable.
#
# Example usage:
# corrade_add_resource(name group_name file1 ALIAS alias1 file2 file3)
# add_executable(app source1 source2 ... ${name})
#
# Add dynamic plugin.
# corrade_add_plugin(plugin_name install_dir metadata_file
# sources...)
# The macro adds preprocessor directive CORRADE_DYNAMIC_PLUGIN. Additional
# libraries can be linked in via target_link_libraries(plugin_name ...). If
# install_dir is set to CMAKE_CURRENT_BINARY_DIR (e.g. for testing purposes),
# the files are copied directly, without need to run 'make install'.
#
#
# Add static plugin.
# corrade_add_static_plugin(static_plugins_variable
# plugin_name metadata_file
# sources...)
# The macro adds preprocessor directive CORRADE_STATIC_PLUGIN. Additional
# libraries can be linked in via target_link_libraries(plugin_name ...).
#
# Plugin library name will be added at the end of static_plugins_variable and
# the variable is meant to be used for linking plugins to main
# executable/library, e.g:
# target_link_libraries(app lib1 lib2 ... ${static_plugins_variable})
#
# This variable is set with parent scope to be available in parent directory.
# If there are more intermediate directories between plugin directory and main
# executable directory, the variable can be propagated to parent scope like
# this:
# set(static_plugins_variable ${static_plugins_variable} PARENT_SCOPE)
#
# Find and install DLLs for bundling with Windows build.
# corrade_bundle_dlls(library_install_dir
# dlls...
# [PATHS paths...])
# It is possible to specify also additional paths for searching. DLL names can
# also contain paths, they will be installed into exact specified path. If an
# DLL is not found, fatal error message is printed.
# #
if (CORRADE_UTILITY_INCLUDE_DIR AND CORRADE_PLUGINMANAGER_INCLUDE_DIR AND CORRADE_UTILITY_LIBRARY AND CORRADE_PLUGINMANAGER_LIBRARY AND CORRADE_RC_EXECUTABLE) # Libraries
find_library(CORRADE_UTILITY_LIBRARY CorradeUtility)
# Already in cache find_library(CORRADE_PLUGINMANAGER_LIBRARY CorradePluginManager)
set(CORRADECORE_FOUND TRUE)
else()
# Libraries
find_library(CORRADE_UTILITY_LIBRARY CorradeUtility)
find_library(CORRADE_PLUGINMANAGER_LIBRARY CorradePluginManager)
# RC executable # RC executable
find_program(CORRADE_RC_EXECUTABLE corrade-rc) find_program(CORRADE_RC_EXECUTABLE corrade-rc)
# Paths # Paths
find_path(CORRADE_INCLUDE_DIR find_path(CORRADE_INCLUDE_DIR
NAMES PluginManager Utility NAMES PluginManager Utility
PATH_SUFFIXES Corrade PATH_SUFFIXES Corrade)
)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args("Corrade" DEFAULT_MSG find_package_handle_standard_args(Corrade DEFAULT_MSG
CORRADE_INCLUDE_DIR CORRADE_INCLUDE_DIR
CORRADE_UTILITY_LIBRARY CORRADE_UTILITY_LIBRARY
CORRADE_PLUGINMANAGER_LIBRARY CORRADE_PLUGINMANAGER_LIBRARY
CORRADE_RC_EXECUTABLE CORRADE_RC_EXECUTABLE)
)
if(NOT CORRADE_FOUND)
return()
endif() endif()
if(CORRADE_FOUND) include(CorradeMacros)
include(CorradeMacros) include(CorradeLibSuffix)
set(CORRADE_LIBRARIES ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY})
include(CorradeLibSuffix)
set_parent_scope(CORRADE_BINARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin)
set_parent_scope(CORRADE_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
set_parent_scope(CORRADE_CMAKE_MODULE_INSTALL_DIR ${CMAKE_ROOT}/Modules)
set_parent_scope(CORRADE_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/Corrade)
set_parent_scope(CORRADE_LIBRARIES ${CORRADE_UTILITY_LIBRARY} ${CORRADE_PLUGINMANAGER_LIBRARY})
endif()

45
modules/FindMagnum.cmake

@ -1,56 +1,51 @@
# - Find Magnum # - Find Magnum
# #
# Basic usage: # Basic usage:
#
# find_package(Magnum [REQUIRED]) # find_package(Magnum [REQUIRED])
#
# This command tries to find Magnum library and then defines: # This command tries to find Magnum library and then defines:
#
# MAGNUM_FOUND - Whether the library was found # MAGNUM_FOUND - Whether the library was found
# MAGNUM_TARGET_GLES - Defined if Magnum was built for OpenGL ES, # MAGNUM_TARGET_GLES - Defined if Magnum was built for OpenGL
# slightly reducing feature count. The same variable is also #defined in # ES, slightly reducing feature count. The same variable is also
# Magnum headers. # #defined in Magnum headers.
# MAGNUM_LIBRARIES - Magnum library and dependent libraries # MAGNUM_LIBRARIES - Magnum library and dependent libraries
# MAGNUM_INCLUDE_DIRS - Root include dir and include dirs of # MAGNUM_INCLUDE_DIRS - Root include dir and include dirs of
# dependencies # dependencies
# MAGNUM_PLUGINS_IMPORTER_DIR - Directory with importer plugins # MAGNUM_PLUGINS_IMPORTER_DIR - Directory with importer plugins
#
# This command will try to find only the base library, not the optional # This command will try to find only the base library, not the optional
# components. The base library depends on Corrade, OpenGL and GLEW libraries. # components. The base library depends on Corrade, OpenGL and GLEW
# Additional dependencies are specified by the components. The optional # libraries. Additional dependencies are specified by the components. The
# components are: # optional components are:
#
# MeshTools - MeshTools library # MeshTools - MeshTools library
# Physics - Physics library # Physics - Physics library
# Primitives - Library with stock geometric primitives (static) # Primitives - Library with stock geometric primitives (static)
# Shaders - Library with stock shaders # Shaders - Library with stock shaders
#
# EglContext - EGL context (depends on EGL and X11 libraries) # EglContext - EGL context (depends on EGL and X11 libraries)
# GlutContext - GLUT context (depends on GLUT library) # GlutContext - GLUT context (depends on GLUT library)
# Sdl2Context - SDL2 context (depends on SDL2 library) # Sdl2Context - SDL2 context (depends on SDL2 library)
#
# Example usage with specifying additional components is: # Example usage with specifying additional components is:
# # find_package(Magnum [REQUIRED|COMPONENTS]
# find_package(Magnum [REQUIRED|COMPONENTS] MeshTools Primitives GlutContext) # MeshTools Primitives GlutContext)
#
# For each component is then defined: # For each component is then defined:
#
# MAGNUM_*_FOUND - Whether the component was found # MAGNUM_*_FOUND - Whether the component was found
# MAGNUM_*_LIBRARIES - Component library and dependent libraries # MAGNUM_*_LIBRARIES - Component library and dependent libraries
# MAGNUM_*_INCLUDE_DIRS - Include dirs of module dependencies # MAGNUM_*_INCLUDE_DIRS - Include dirs of module dependencies
# #
# Additionally these variables are defined for internal usage: # Additionally these variables are defined for internal usage:
# # MAGNUM_INCLUDE_DIR - Root include dir (w/o
# MAGNUM_INCLUDE_DIR - Root include dir (w/o dependencies) # dependencies)
# MAGNUM_LIBRARY - Magnum library (w/o dependencies) # MAGNUM_LIBRARY - Magnum library (w/o
# MAGNUM_*_LIBRARY - Component libraries (w/o dependencies) # dependencies)
# # MAGNUM_*_LIBRARY - Component libraries (w/o
# dependencies)
# MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory # MAGNUM_LIBRARY_INSTALL_DIR - Library installation directory
# MAGNUM_PLUGINS_INSTALL_DIR - Plugin installation directory # MAGNUM_PLUGINS_INSTALL_DIR - Plugin installation directory
# MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR - Importer plugin installation directory # MAGNUM_PLUGINS_IMPORTER_INSTALL_DIR - Importer plugin installation
# MAGNUM_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake modules # directory
# MAGNUM_CMAKE_MODULE_INSTALL_DIR - Installation dir for CMake
# modules
# MAGNUM_INCLUDE_INSTALL_DIR - Header installation directory # MAGNUM_INCLUDE_INSTALL_DIR - Header installation directory
# MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR - Plugin header installation directory # MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR - Plugin header installation
# directory
# #
# Dependencies # Dependencies

5
package/archlinux/magnum-git/PKGBUILD

@ -35,6 +35,11 @@ build() {
make make
} }
check() {
cd "$startdir/build"
ctest --output-on-failure -E Benchmark
}
package() { package() {
cd "$srcdir/build" cd "$srcdir/build"
make DESTDIR="$pkgdir/" install make DESTDIR="$pkgdir/" install

2
src/CMakeLists.txt

@ -1,4 +1,4 @@
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -pedantic -std=c++0x -fvisibility=hidden -fno-exceptions") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wold-style-cast -pedantic -std=c++0x -fvisibility=hidden")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wdouble-promotion")

4
src/Math/Geometry/Test/CMakeLists.txt

@ -1,2 +1,2 @@
corrade_add_test(MathGeometryDistanceTest DistanceTest.h DistanceTest.cpp) corrade_add_test2(MathGeometryDistanceTest DistanceTest.cpp)
corrade_add_test(MathGeometryIntersectionTest IntersectionTest.h IntersectionTest.cpp) corrade_add_test2(MathGeometryIntersectionTest IntersectionTest.cpp)

26
src/Math/Geometry/Test/DistanceTest.cpp

@ -16,12 +16,11 @@
#include "DistanceTest.h" #include "DistanceTest.h"
#include <limits> #include <limits>
#include <QtTest/QTest>
#include "Math.h" #include "Math.h"
#include "Distance.h" #include "Distance.h"
QTEST_APPLESS_MAIN(Magnum::Math::Geometry::Test::DistanceTest) CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::DistanceTest)
using namespace std; using namespace std;
@ -29,17 +28,22 @@ namespace Magnum { namespace Math { namespace Geometry { namespace Test {
typedef Magnum::Math::Vector3<float> Vector3; typedef Magnum::Math::Vector3<float> Vector3;
DistanceTest::DistanceTest() {
addTests(&DistanceTest::linePoint,
&DistanceTest::lineSegmentPoint);
}
void DistanceTest::linePoint() { void DistanceTest::linePoint() {
Vector3 a(0.0f); Vector3 a(0.0f);
Vector3 b(1.0f); Vector3 b(1.0f);
/* Point on the line */ /* Point on the line */
QCOMPARE((Distance::linePoint(a, b, Vector3(0.25f))), 0.0f); CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(0.25f))), 0.0f);
/* The distance should be the same for all equidistant points */ /* The distance should be the same for all equidistant points */
QCOMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f))), CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f))),
Constants<float>::sqrt2()/Constants<float>::sqrt3()); Constants<float>::sqrt2()/Constants<float>::sqrt3());
QCOMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(100.0f))), CORRADE_COMPARE((Distance::linePoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(100.0f))),
Constants<float>::sqrt2()/Constants<float>::sqrt3()); Constants<float>::sqrt2()/Constants<float>::sqrt3());
} }
@ -48,23 +52,23 @@ void DistanceTest::lineSegmentPoint() {
Vector3 b(1.0f); Vector3 b(1.0f);
/* Point on the line segment */ /* Point on the line segment */
QCOMPARE((Distance::lineSegmentPoint(a, b, Vector3(0.25f))), 0.0f); CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(0.25f))), 0.0f);
/* Point on the line, outside the segment, closer to A */ /* Point on the line, outside the segment, closer to A */
QCOMPARE((Distance::lineSegmentPoint(a, b, Vector3(-1.0f))), +Constants<float>::sqrt3()); CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(-1.0f))), +Constants<float>::sqrt3());
/* Point on the line, outside the segment, closer to B */ /* Point on the line, outside the segment, closer to B */
QCOMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f+1.0f/Constants<float>::sqrt3()))), 1.0f); CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f+1.0f/Constants<float>::sqrt3()))), 1.0f);
/* Point next to the line segment */ /* Point next to the line segment */
QCOMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f))), CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f))),
Constants<float>::sqrt2()/Constants<float>::sqrt3()); Constants<float>::sqrt2()/Constants<float>::sqrt3());
/* Point outside the line segment, closer to A */ /* Point outside the line segment, closer to A */
QCOMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f)-Vector3(1.0f))), 1.0f); CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f)-Vector3(1.0f))), 1.0f);
/* Point outside the line segment, closer to B */ /* Point outside the line segment, closer to B */
QCOMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(1.0f))), +Constants<float>::sqrt2()); CORRADE_COMPARE((Distance::lineSegmentPoint(a, b, Vector3(1.0f, 0.0f, 1.0f)+Vector3(1.0f))), +Constants<float>::sqrt2());
} }
}}}} }}}}

8
src/Math/Geometry/Test/DistanceTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Geometry { namespace Test { namespace Magnum { namespace Math { namespace Geometry { namespace Test {
class DistanceTest: public QObject { class DistanceTest: public Corrade::TestSuite::Tester<DistanceTest> {
Q_OBJECT public:
DistanceTest();
private slots:
void linePoint(); void linePoint();
void lineSegmentPoint(); void lineSegmentPoint();
}; };

20
src/Math/Geometry/Test/IntersectionTest.cpp

@ -16,11 +16,10 @@
#include "IntersectionTest.h" #include "IntersectionTest.h"
#include <limits> #include <limits>
#include <QtTest/QTest>
#include "Intersection.h" #include "Intersection.h"
QTEST_APPLESS_MAIN(Magnum::Math::Geometry::Test::IntersectionTest) CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::IntersectionTest)
using namespace std; using namespace std;
@ -28,26 +27,29 @@ namespace Magnum { namespace Math { namespace Geometry { namespace Test {
typedef Magnum::Math::Vector3<float> Vector3; typedef Magnum::Math::Vector3<float> Vector3;
IntersectionTest::IntersectionTest() {
addTests(&IntersectionTest::planeLine);
}
void IntersectionTest::planeLine() { void IntersectionTest::planeLine() {
Vector3 planePosition(-1.0f, 1.0f, 0.5f); Vector3 planePosition(-1.0f, 1.0f, 0.5f);
Vector3 planeNormal(0.0f, 0.0f, 1.0f); Vector3 planeNormal(0.0f, 0.0f, 1.0f);
/* Inside line segment */ /* Inside line segment */
QCOMPARE((Intersection::planeLine(planePosition, planeNormal, CORRADE_COMPARE((Intersection::planeLine(planePosition, planeNormal,
Vector3(0.0f, 0.0f, -1.0f), Vector3(0.0f, 0.0f, 1.0f))), 0.75f); Vector3(0.0f, 0.0f, -1.0f), Vector3(0.0f, 0.0f, 1.0f))), 0.75f);
/* Outside line segment */ /* Outside line segment */
QCOMPARE((Intersection::planeLine(planePosition, planeNormal, CORRADE_COMPARE((Intersection::planeLine(planePosition, planeNormal,
Vector3(0.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 2.0f))), -0.5f); Vector3(0.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 2.0f))), -0.5f);
/* Line lies on the plane */ /* Line lies on the plane */
float nan = Intersection::planeLine(planePosition, planeNormal, CORRADE_COMPARE(Intersection::planeLine(planePosition, planeNormal,
Vector3(1.0f, 0.5f, 0.5f), Vector3(0.0f, 1.0f, 0.5f)); Vector3(1.0f, 0.5f, 0.5f), Vector3(0.0f, 1.0f, 0.5f)), numeric_limits<float>::quiet_NaN());
QVERIFY(nan != nan);
/* Line is parallell to the plane */ /* Line is parallell to the plane */
QCOMPARE((Intersection::planeLine(planePosition, planeNormal, CORRADE_COMPARE((Intersection::planeLine(planePosition, planeNormal,
Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), numeric_limits<float>::infinity()); Vector3(1.0f, 0.0f, 1.0f), Vector3(0.0f, 0.0f, 1.0f))), -numeric_limits<float>::infinity());
} }
}}}} }}}}

8
src/Math/Geometry/Test/IntersectionTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Geometry { namespace Test { namespace Magnum { namespace Math { namespace Geometry { namespace Test {
class IntersectionTest: public QObject { class IntersectionTest: public Corrade::TestSuite::Tester<IntersectionTest> {
Q_OBJECT public:
IntersectionTest();
private slots:
void planeLine(); void planeLine();
}; };

19
src/Math/Test/CMakeLists.txt

@ -1,18 +1,17 @@
corrade_add_test(MathMathTypeTraitsTest MathTypeTraitsTest.h MathTypeTraitsTest.cpp) corrade_add_test2(MathMathTypeTraitsTest MathTypeTraitsTest.cpp)
corrade_add_test(MathVectorTest VectorTest.h VectorTest.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MathVectorTest VectorTest.cpp)
corrade_add_test(MathVector2Test Vector2Test.h Vector2Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MathVector2Test Vector2Test.cpp)
corrade_add_test(MathVector3Test Vector3Test.h Vector3Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MathVector3Test Vector3Test.cpp)
corrade_add_test(MathVector4Test Vector4Test.h Vector4Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MathVector4Test Vector4Test.cpp)
corrade_add_test(MathMatrixTest MatrixTest.h MatrixTest.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MathMatrixTest MatrixTest.cpp)
corrade_add_test(MathMatrix3Test Matrix3Test.h Matrix3Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MathMatrix3Test Matrix3Test.cpp)
corrade_add_test(MathMatrix4Test Matrix4Test.h Matrix4Test.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MathMatrix4Test Matrix4Test.cpp)
set(MathTest_MOC MathTest.h)
if(NOT CMAKE_NO_OBJECT_TARGET) if(NOT CMAKE_NO_OBJECT_TARGET)
set(MathTest_SRCS MathTest.cpp $<TARGET_OBJECTS:MagnumMathObjects>) set(MathTest_SRCS MathTest.cpp $<TARGET_OBJECTS:MagnumMathObjects>)
else() else()
set(MathTest_SRCS MathTest.cpp ${MagnumMath_SRCS}) set(MathTest_SRCS MathTest.cpp ${MagnumMath_SRCS})
endif() endif()
corrade_add_multifile_test(MathTest MathTest_MOC MathTest_SRCS) corrade_add_test2(MathTest ${MathTest_SRCS})

26
src/Math/Test/MathTest.cpp

@ -15,29 +15,33 @@
#include "MathTest.h" #include "MathTest.h"
#include <QtTest/QTest>
#include "Math.h" #include "Math.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::MathTest) CORRADE_TEST_MAIN(Magnum::Math::Test::MathTest)
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
MathTest::MathTest() {
addTests(&MathTest::degrad,
&MathTest::pow,
&MathTest::log);
}
void MathTest::degrad() { void MathTest::degrad() {
QCOMPARE(deg(90.0), Constants<double>::pi()/2); CORRADE_COMPARE(deg(90.0), Constants<double>::pi()/2);
QCOMPARE(deg(90.0f), Constants<float>::pi()/2); CORRADE_COMPARE(deg(90.0f), Constants<float>::pi()/2);
QCOMPARE(rad(Constants<double>::pi()/2), Constants<double>::pi()/2); CORRADE_COMPARE(rad(Constants<double>::pi()/2), Constants<double>::pi()/2);
} }
void MathTest::pow() { void MathTest::pow() {
QCOMPARE(Math::pow<10>(2ul), 1024ul); CORRADE_COMPARE(Math::pow<10>(2ul), 1024ul);
QCOMPARE(Math::pow<0>(3ul), 1ul); CORRADE_COMPARE(Math::pow<0>(3ul), 1ul);
QCOMPARE(Math::pow<2>(2.0f), 4.0f); CORRADE_COMPARE(Math::pow<2>(2.0f), 4.0f);
} }
void MathTest::log() { void MathTest::log() {
QCOMPARE(Math::log(2, 256), 8ul); CORRADE_COMPARE(Math::log(2, 256), 8ul);
QCOMPARE(Math::log(256, 2), 0ul); CORRADE_COMPARE(Math::log(256, 2), 0ul);
} }
}}} }}}

8
src/Math/Test/MathTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class MathTest: public QObject { class MathTest: public Corrade::TestSuite::Tester<MathTest> {
Q_OBJECT public:
MathTest();
private slots:
void degrad(); void degrad();
void pow(); void pow();
void log(); void log();

29
src/Math/Test/MathTypeTraitsTest.cpp

@ -16,14 +16,18 @@
#include "MathTypeTraitsTest.h" #include "MathTypeTraitsTest.h"
#include <limits> #include <limits>
#include <QtTest/QTest>
#include "MathTypeTraits.h" #include "MathTypeTraits.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::MathTypeTraitsTest) CORRADE_TEST_MAIN(Magnum::Math::Test::MathTypeTraitsTest)
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
MathTypeTraitsTest::MathTypeTraitsTest() {
addTests(&MathTypeTraitsTest::equalsIntegral,
&MathTypeTraitsTest::equalsFloatingPoint);
}
void MathTypeTraitsTest::equalsIntegral() { void MathTypeTraitsTest::equalsIntegral() {
_equalsIntegral<unsigned char>(); _equalsIntegral<unsigned char>();
_equalsIntegral<char>(); _equalsIntegral<char>();
@ -43,18 +47,21 @@ void MathTypeTraitsTest::equalsFloatingPoint() {
} }
template<class T> void MathTypeTraitsTest::_equalsIntegral() { template<class T> void MathTypeTraitsTest::_equalsIntegral() {
QVERIFY(!MathTypeTraits<T>::equals(1, 1+MathTypeTraits<T>::epsilon())); CORRADE_VERIFY(!MathTypeTraits<T>::equals(1, 1+MathTypeTraits<T>::epsilon()));
} }
template<class T> void MathTypeTraitsTest::_equalsFloatingPoint() { template<class T> void MathTypeTraitsTest::_equalsFloatingPoint() {
QVERIFY(MathTypeTraits<T>::equals(T(1)+MathTypeTraits<T>::epsilon()/T(2), T(1))); CORRADE_VERIFY(MathTypeTraits<T>::equals(T(1)+MathTypeTraits<T>::epsilon()/T(2), T(1)));
QVERIFY(!MathTypeTraits<T>::equals(T(1)+MathTypeTraits<T>::epsilon()*T(2), T(1))); CORRADE_VERIFY(!MathTypeTraits<T>::equals(T(1)+MathTypeTraits<T>::epsilon()*T(2), T(1)));
QEXPECT_FAIL(0, "Comparing to infinity is broken", Continue); {
QVERIFY(MathTypeTraits<T>::equals(std::numeric_limits<T>::infinity(), CORRADE_EXPECT_FAIL("Comparing to infinity is broken");
std::numeric_limits<T>::infinity())); CORRADE_VERIFY(MathTypeTraits<T>::equals(std::numeric_limits<T>::infinity(),
QVERIFY(!MathTypeTraits<T>::equals(std::numeric_limits<T>::quiet_NaN(), std::numeric_limits<T>::infinity()));
std::numeric_limits<T>::quiet_NaN())); }
CORRADE_VERIFY(!MathTypeTraits<T>::equals(std::numeric_limits<T>::quiet_NaN(),
std::numeric_limits<T>::quiet_NaN()));
} }
}}} }}}

8
src/Math/Test/MathTypeTraitsTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class MathTypeTraitsTest: public QObject { class MathTypeTraitsTest: public Corrade::TestSuite::Tester<MathTypeTraitsTest> {
Q_OBJECT public:
MathTypeTraitsTest();
private slots:
void equalsFloatingPoint(); void equalsFloatingPoint();
void equalsIntegral(); void equalsIntegral();

29
src/Math/Test/Matrix3Test.cpp

@ -16,12 +16,11 @@
#include "Matrix3Test.h" #include "Matrix3Test.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Matrix3.h" #include "Matrix3.h"
#include "Math.h" #include "Math.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::Matrix3Test) CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix3Test)
using namespace std; using namespace std;
using namespace Corrade::Utility; using namespace Corrade::Utility;
@ -30,6 +29,14 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Matrix3<float> Matrix3; typedef Math::Matrix3<float> Matrix3;
Matrix3Test::Matrix3Test() {
addTests(&Matrix3Test::constructIdentity,
&Matrix3Test::translation,
&Matrix3Test::scaling,
&Matrix3Test::rotation,
&Matrix3Test::debug);
}
void Matrix3Test::constructIdentity() { void Matrix3Test::constructIdentity() {
Matrix3 identity; Matrix3 identity;
Matrix3 identity2(Matrix3::Identity); Matrix3 identity2(Matrix3::Identity);
@ -47,9 +54,9 @@ void Matrix3Test::constructIdentity() {
0.0f, 0.0f, 4.0f 0.0f, 0.0f, 4.0f
); );
QVERIFY(identity == identityExpected); CORRADE_COMPARE(identity, identityExpected);
QVERIFY(identity2 == identityExpected); CORRADE_COMPARE(identity2, identityExpected);
QVERIFY(identity3 == identity3Expected); CORRADE_COMPARE(identity3, identity3Expected);
} }
void Matrix3Test::translation() { void Matrix3Test::translation() {
@ -59,7 +66,7 @@ void Matrix3Test::translation() {
3.0f, 1.0f, 1.0f 3.0f, 1.0f, 1.0f
); );
QVERIFY(Matrix3::translation({3.0f, 1.0f}) == matrix); CORRADE_COMPARE(Matrix3::translation({3.0f, 1.0f}), matrix);
} }
void Matrix3Test::scaling() { void Matrix3Test::scaling() {
@ -69,7 +76,7 @@ void Matrix3Test::scaling() {
0.0f, 0.0f, 1.0f 0.0f, 0.0f, 1.0f
); );
QVERIFY(Matrix3::scaling({3.0f, 1.5f}) == matrix); CORRADE_COMPARE(Matrix3::scaling({3.0f, 1.5f}), matrix);
} }
void Matrix3Test::rotation() { void Matrix3Test::rotation() {
@ -79,7 +86,7 @@ void Matrix3Test::rotation() {
0.0f, 0.0f, 1.0f 0.0f, 0.0f, 1.0f
); );
QVERIFY(Matrix3::rotation(deg(15.0f)) == matrix); CORRADE_COMPARE(Matrix3::rotation(deg(15.0f)), matrix);
} }
void Matrix3Test::debug() { void Matrix3Test::debug() {
@ -91,9 +98,9 @@ void Matrix3Test::debug() {
ostringstream o; ostringstream o;
Debug(&o) << m; Debug(&o) << m;
QCOMPARE(QString::fromStdString(o.str()), QString("Matrix(3, 4, 7,\n" CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7,\n"
" 5, 4, -1,\n" " 5, 4, -1,\n"
" 8, 7, 8)\n")); " 8, 7, 8)\n");
} }
}}} }}}

8
src/Math/Test/Matrix3Test.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class Matrix3Test: public QObject { class Matrix3Test: public Corrade::TestSuite::Tester<Matrix3Test> {
Q_OBJECT public:
Matrix3Test();
private slots:
void constructIdentity(); void constructIdentity();
void translation(); void translation();

39
src/Math/Test/Matrix4Test.cpp

@ -16,12 +16,11 @@
#include "Matrix4Test.h" #include "Matrix4Test.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Matrix4.h" #include "Matrix4.h"
#include "Math.h" #include "Math.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::Matrix4Test) CORRADE_TEST_MAIN(Magnum::Math::Test::Matrix4Test)
using namespace std; using namespace std;
using namespace Corrade::Utility; using namespace Corrade::Utility;
@ -31,6 +30,16 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Matrix4<float> Matrix4; typedef Math::Matrix4<float> Matrix4;
typedef Math::Matrix3<float> Matrix3; typedef Math::Matrix3<float> Matrix3;
Matrix4Test::Matrix4Test() {
addTests(&Matrix4Test::constructIdentity,
&Matrix4Test::translation,
&Matrix4Test::scaling,
&Matrix4Test::rotation,
&Matrix4Test::rotationScalingPart,
&Matrix4Test::rotationPart,
&Matrix4Test::debug);
}
void Matrix4Test::constructIdentity() { void Matrix4Test::constructIdentity() {
Matrix4 identity; Matrix4 identity;
Matrix4 identity2(Matrix4::Identity); Matrix4 identity2(Matrix4::Identity);
@ -50,9 +59,9 @@ void Matrix4Test::constructIdentity() {
0.0f, 0.0f, 0.0f, 4.0f 0.0f, 0.0f, 0.0f, 4.0f
); );
QVERIFY(identity == identityExpected); CORRADE_COMPARE(identity, identityExpected);
QVERIFY(identity2 == identityExpected); CORRADE_COMPARE(identity2, identityExpected);
QVERIFY(identity3 == identity3Expected); CORRADE_COMPARE(identity3, identity3Expected);
} }
void Matrix4Test::translation() { void Matrix4Test::translation() {
@ -63,7 +72,7 @@ void Matrix4Test::translation() {
3.0f, 1.0f, 2.0f, 1.0f 3.0f, 1.0f, 2.0f, 1.0f
); );
QVERIFY(Matrix4::translation({3.0f, 1.0f, 2.0f}) == matrix); CORRADE_COMPARE(Matrix4::translation({3.0f, 1.0f, 2.0f}), matrix);
} }
void Matrix4Test::scaling() { void Matrix4Test::scaling() {
@ -74,7 +83,7 @@ void Matrix4Test::scaling() {
0.0f, 0.0f, 0.0f, 1.0f 0.0f, 0.0f, 0.0f, 1.0f
); );
QVERIFY(Matrix4::scaling({3.0f, 1.5f, 2.0f}) == matrix); CORRADE_COMPARE(Matrix4::scaling({3.0f, 1.5f, 2.0f}), matrix);
} }
void Matrix4Test::rotation() { void Matrix4Test::rotation() {
@ -85,7 +94,7 @@ void Matrix4Test::rotation() {
0.0f, 0.0f, 0.0f, 1.0f 0.0f, 0.0f, 0.0f, 1.0f
); );
QVERIFY(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}) == matrix); CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), matrix);
} }
void Matrix4Test::rotationScalingPart() { void Matrix4Test::rotationScalingPart() {
@ -102,7 +111,7 @@ void Matrix4Test::rotationScalingPart() {
7.0f, -1.0f, 8.0f 7.0f, -1.0f, 8.0f
); );
QVERIFY(m.rotationScaling() == expected); CORRADE_COMPARE(m.rotationScaling(), expected);
} }
void Matrix4Test::rotationPart() { void Matrix4Test::rotationPart() {
@ -113,10 +122,10 @@ void Matrix4Test::rotationPart() {
); );
Matrix4 rotation = Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}); Matrix4 rotation = Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f});
QVERIFY(rotation.rotation() == expectedRotationPart); CORRADE_COMPARE(rotation.rotation(), expectedRotationPart);
Matrix4 rotationTransformed = Matrix4::translation({2.0f, 5.0f, -3.0f})*rotation*Matrix4::scaling(Vector3<float>(9.0f)); Matrix4 rotationTransformed = Matrix4::translation({2.0f, 5.0f, -3.0f})*rotation*Matrix4::scaling(Vector3<float>(9.0f));
QVERIFY(rotationTransformed.rotation() == expectedRotationPart); CORRADE_COMPARE(rotationTransformed.rotation(), expectedRotationPart);
} }
void Matrix4Test::debug() { void Matrix4Test::debug() {
@ -129,10 +138,10 @@ void Matrix4Test::debug() {
ostringstream o; ostringstream o;
Debug(&o) << m; Debug(&o) << m;
QCOMPARE(QString::fromStdString(o.str()), QString("Matrix(3, 4, 7, 9,\n" CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7, 9,\n"
" 5, 4, -1, 4,\n" " 5, 4, -1, 4,\n"
" 8, 7, 8, 5,\n" " 8, 7, 8, 5,\n"
" 4, 3, 0, 9)\n")); " 4, 3, 0, 9)\n");
} }
}}} }}}

8
src/Math/Test/Matrix4Test.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class Matrix4Test: public QObject { class Matrix4Test: public Corrade::TestSuite::Tester<Matrix4Test> {
Q_OBJECT public:
Matrix4Test();
private slots:
void constructIdentity(); void constructIdentity();
void translation(); void translation();

84
src/Math/Test/MatrixTest.cpp

@ -16,11 +16,10 @@
#include "MatrixTest.h" #include "MatrixTest.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Matrix.h" #include "Matrix.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::MatrixTest) CORRADE_TEST_MAIN(Magnum::Math::Test::MatrixTest)
using namespace std; using namespace std;
using namespace Corrade::Utility; using namespace Corrade::Utility;
@ -31,6 +30,23 @@ typedef Matrix<4, float> Matrix4;
typedef Matrix<3, float> Matrix3; typedef Matrix<3, float> Matrix3;
typedef Vector<4, float> Vector4; typedef Vector<4, float> Vector4;
MatrixTest::MatrixTest() {
addTests(&MatrixTest::construct,
&MatrixTest::constructFromVectors,
&MatrixTest::constructIdentity,
&MatrixTest::constructZero,
&MatrixTest::data,
&MatrixTest::copy,
&MatrixTest::multiplyIdentity,
&MatrixTest::multiply,
&MatrixTest::multiplyVector,
&MatrixTest::transposed,
&MatrixTest::ij,
&MatrixTest::determinant,
&MatrixTest::inverted,
&MatrixTest::debug);
}
void MatrixTest::construct() { void MatrixTest::construct() {
float m[] = { float m[] = {
3.0f, 5.0f, 8.0f, 4.0f, 3.0f, 5.0f, 8.0f, 4.0f,
@ -46,7 +62,7 @@ void MatrixTest::construct() {
9.0f, 4.0f, 5.0f, 9.0f 9.0f, 4.0f, 5.0f, 9.0f
); );
QVERIFY(Matrix4::from(m) == expected); CORRADE_COMPARE(Matrix4::from(m), expected);
} }
void MatrixTest::constructFromVectors() { void MatrixTest::constructFromVectors() {
@ -60,7 +76,7 @@ void MatrixTest::constructFromVectors() {
9.0f, 10.0f, 11.0f, 12.0f, 9.0f, 10.0f, 11.0f, 12.0f,
13.0f, 14.0f, 15.0f, 16.0f); 13.0f, 14.0f, 15.0f, 16.0f);
QVERIFY(actual == expected); CORRADE_COMPARE(actual, expected);
} }
void MatrixTest::constructIdentity() { void MatrixTest::constructIdentity() {
@ -82,9 +98,9 @@ void MatrixTest::constructIdentity() {
0.0f, 0.0f, 0.0f, 4.0f 0.0f, 0.0f, 0.0f, 4.0f
); );
QVERIFY(identity == identityExpected); CORRADE_COMPARE(identity, identityExpected);
QVERIFY(identity2 == identityExpected); CORRADE_COMPARE(identity2, identityExpected);
QVERIFY(identity3 == identity3Expected); CORRADE_COMPARE(identity3, identity3Expected);
} }
void MatrixTest::constructZero() { void MatrixTest::constructZero() {
@ -97,7 +113,7 @@ void MatrixTest::constructZero() {
0.0f, 0.0f, 0.0f, 0.0f 0.0f, 0.0f, 0.0f, 0.0f
); );
QVERIFY(zero == zeroExpected); CORRADE_COMPARE(zero, zeroExpected);
} }
void MatrixTest::data() { void MatrixTest::data() {
@ -110,8 +126,8 @@ void MatrixTest::data() {
m[1][2] = 1.5f; m[1][2] = 1.5f;
QCOMPARE(m[2][1], 1.0f); CORRADE_COMPARE(m[2][1], 1.0f);
QVERIFY(m[3] == vector); CORRADE_COMPARE(m[3], vector);
Matrix4 expected( Matrix4 expected(
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
@ -120,7 +136,7 @@ void MatrixTest::data() {
4.0f, 5.0f, 6.0f, 7.0f 4.0f, 5.0f, 6.0f, 7.0f
); );
QVERIFY(m == expected); CORRADE_COMPARE(m, expected);
} }
void MatrixTest::copy() { void MatrixTest::copy() {
@ -141,8 +157,8 @@ void MatrixTest::copy() {
Matrix4 original(Matrix4::Zero); Matrix4 original(Matrix4::Zero);
original[2][3] = 1.0f; original[2][3] = 1.0f;
QVERIFY(m2 == original); CORRADE_COMPARE(m2, original);
QVERIFY(m3 == original); CORRADE_COMPARE(m3, original);
} }
void MatrixTest::multiplyIdentity() { void MatrixTest::multiplyIdentity() {
@ -153,8 +169,8 @@ void MatrixTest::multiplyIdentity() {
12.0f, 13.0f, 14.0f, 15.0f 12.0f, 13.0f, 14.0f, 15.0f
); );
QVERIFY(Matrix4()*values == values); CORRADE_COMPARE(Matrix4()*values, values);
QVERIFY(values*Matrix4() == values); CORRADE_COMPARE(values*Matrix4(), values);
} }
void MatrixTest::multiply() { void MatrixTest::multiply() {
@ -182,7 +198,7 @@ void MatrixTest::multiply() {
-12, 8, -20, -26, -2 -12, 8, -20, -26, -2
); );
QVERIFY((left *= right) == expected); CORRADE_COMPARE((left *= right), expected);
} }
void MatrixTest::multiplyVector() { void MatrixTest::multiplyVector() {
@ -194,9 +210,7 @@ void MatrixTest::multiplyVector() {
1, 3, -3, -4, -1 1, 3, -3, -4, -1
); );
bool is = (matrix*Vector<5, int>(0, 5, 3, 4, 4) == Vector<5, int>(-24, -35, -32, -25, 1)); CORRADE_COMPARE((matrix*Vector<5, int>(0, 5, 3, 4, 4)), (Vector<5, int>(-24, -35, -32, -25, 1)));
QVERIFY(is);
} }
void MatrixTest::transposed() { void MatrixTest::transposed() {
@ -214,7 +228,7 @@ void MatrixTest::transposed() {
3.0f, 7.0f, 11.0f, 15.0f 3.0f, 7.0f, 11.0f, 15.0f
); );
QVERIFY(original.transposed() == transposed); CORRADE_COMPARE(original.transposed(), transposed);
} }
void MatrixTest::ij() { void MatrixTest::ij() {
@ -231,7 +245,7 @@ void MatrixTest::ij() {
12.0f, 13.0f, 15.0f 12.0f, 13.0f, 15.0f
); );
QVERIFY(original.ij(1, 2) == skipped); CORRADE_COMPARE(original.ij(1, 2), skipped);
} }
void MatrixTest::determinant() { void MatrixTest::determinant() {
@ -243,7 +257,7 @@ void MatrixTest::determinant() {
3, 1, 0, 1, -2 3, 1, 0, 1, -2
); );
QVERIFY(m.determinant() == -2); CORRADE_COMPARE(m.determinant(), -2);
} }
void MatrixTest::inverted() { void MatrixTest::inverted() {
@ -263,8 +277,8 @@ void MatrixTest::inverted() {
Matrix4 _inverse = m.inverted(); Matrix4 _inverse = m.inverted();
QVERIFY(_inverse == inverse); CORRADE_COMPARE(_inverse, inverse);
QVERIFY(_inverse*m == Matrix4()); CORRADE_COMPARE(_inverse*m, Matrix4());
} }
void MatrixTest::debug() { void MatrixTest::debug() {
@ -277,20 +291,20 @@ void MatrixTest::debug() {
ostringstream o; ostringstream o;
Debug(&o) << m; Debug(&o) << m;
QCOMPARE(QString::fromStdString(o.str()), QString("Matrix(3, 4, 7, 9,\n" CORRADE_COMPARE(o.str(), "Matrix(3, 4, 7, 9,\n"
" 5, 4, -1, 4,\n" " 5, 4, -1, 4,\n"
" 8, 7, 8, 5,\n" " 8, 7, 8, 5,\n"
" 4, 3, 0, 9)\n")); " 4, 3, 0, 9)\n");
o.str(""); o.str("");
Debug(&o) << "a" << Matrix4() << "b" << Matrix4(); Debug(&o) << "a" << Matrix4() << "b" << Matrix4();
QCOMPARE(QString::fromStdString(o.str()), QString("a Matrix(1, 0, 0, 0,\n" CORRADE_COMPARE(o.str(), "a Matrix(1, 0, 0, 0,\n"
" 0, 1, 0, 0,\n" " 0, 1, 0, 0,\n"
" 0, 0, 1, 0,\n" " 0, 0, 1, 0,\n"
" 0, 0, 0, 1) b Matrix(1, 0, 0, 0,\n" " 0, 0, 0, 1) b Matrix(1, 0, 0, 0,\n"
" 0, 1, 0, 0,\n" " 0, 1, 0, 0,\n"
" 0, 0, 1, 0,\n" " 0, 0, 1, 0,\n"
" 0, 0, 0, 1)\n")); " 0, 0, 0, 1)\n");
} }
}}} }}}

8
src/Math/Test/MatrixTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class MatrixTest: public QObject { class MatrixTest: public Corrade::TestSuite::Tester<MatrixTest> {
Q_OBJECT public:
MatrixTest();
private slots:
void construct(); void construct();
void constructFromVectors(); void constructFromVectors();
void constructIdentity(); void constructIdentity();

12
src/Math/Test/Vector2Test.cpp

@ -16,11 +16,10 @@
#include "Vector2Test.h" #include "Vector2Test.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Vector2.h" #include "Vector2.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::Vector2Test) CORRADE_TEST_MAIN(Magnum::Math::Test::Vector2Test)
using namespace std; using namespace std;
using namespace Corrade::Utility; using namespace Corrade::Utility;
@ -29,14 +28,19 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector2<float> Vector2; typedef Math::Vector2<float> Vector2;
Vector2Test::Vector2Test() {
addTests(&Vector2Test::construct,
&Vector2Test::debug);
}
void Vector2Test::construct() { void Vector2Test::construct() {
QVERIFY((Vector2(1, 2) == Vector<2, float>(1.0f, 2.0f))); CORRADE_COMPARE(Vector2(1, 2), (Vector<2, float>(1.0f, 2.0f)));
} }
void Vector2Test::debug() { void Vector2Test::debug() {
ostringstream o; ostringstream o;
Debug(&o) << Vector2(0.5f, 15.0f); Debug(&o) << Vector2(0.5f, 15.0f);
QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15)\n")); CORRADE_COMPARE(o.str(), "Vector(0.5, 15)\n");
} }
}}} }}}

8
src/Math/Test/Vector2Test.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class Vector2Test: public QObject { class Vector2Test: public Corrade::TestSuite::Tester<Vector2Test> {
Q_OBJECT public:
Vector2Test();
private slots:
void construct(); void construct();
void debug(); void debug();
}; };

27
src/Math/Test/Vector3Test.cpp

@ -16,11 +16,10 @@
#include "Vector3Test.h" #include "Vector3Test.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Vector3.h" #include "Vector3.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::Vector3Test) CORRADE_TEST_MAIN(Magnum::Math::Test::Vector3Test)
using namespace std; using namespace std;
using namespace Corrade::Utility; using namespace Corrade::Utility;
@ -30,32 +29,40 @@ namespace Magnum { namespace Math { namespace Test {
typedef Math::Vector3<float> Vector3; typedef Math::Vector3<float> Vector3;
typedef Math::Vector2<float> Vector2; typedef Math::Vector2<float> Vector2;
Vector3Test::Vector3Test() {
addTests(&Vector3Test::construct,
&Vector3Test::cross,
&Vector3Test::axis,
&Vector3Test::twoComponent,
&Vector3Test::debug);
}
void Vector3Test::construct() { void Vector3Test::construct() {
QVERIFY((Vector3(1, 2, 3) == Vector<3, float>(1.0f, 2.0f, 3.0f))); CORRADE_COMPARE(Vector3(1, 2, 3), (Vector<3, float>(1.0f, 2.0f, 3.0f)));
QVERIFY((Vector3(Vector<2, float>(1.0f, 2.0f), 3) == Vector<3, float>(1.0f, 2.0f, 3.0f))); CORRADE_COMPARE(Vector3(Vector<2, float>(1.0f, 2.0f), 3), (Vector<3, float>(1.0f, 2.0f, 3.0f)));
} }
void Vector3Test::cross() { void Vector3Test::cross() {
Vector3 a(1, -1, 1); Vector3 a(1, -1, 1);
Vector3 b(4, 3, 7); Vector3 b(4, 3, 7);
QVERIFY(Vector3::cross(a, b) == Vector3(-10, -3, 7)); CORRADE_COMPARE(Vector3::cross(a, b), Vector3(-10, -3, 7));
} }
void Vector3Test::axis() { void Vector3Test::axis() {
QVERIFY(Vector3::xAxis(5.0f) == Vector3(5.0f, 0.0f, 0.0f)); CORRADE_COMPARE(Vector3::xAxis(5.0f), Vector3(5.0f, 0.0f, 0.0f));
QVERIFY(Vector3::yAxis(6.0f) == Vector3(0.0f, 6.0f, 0.0f)); CORRADE_COMPARE(Vector3::yAxis(6.0f), Vector3(0.0f, 6.0f, 0.0f));
QVERIFY(Vector3::zAxis(7.0f) == Vector3(0.0f, 0.0f, 7.0f)); CORRADE_COMPARE(Vector3::zAxis(7.0f), Vector3(0.0f, 0.0f, 7.0f));
} }
void Vector3Test::twoComponent() { void Vector3Test::twoComponent() {
QVERIFY(Vector3(1.0f, 2.0f, 3.0f).xy() == Vector2(1.0f, 2.0f)); CORRADE_COMPARE(Vector3(1.0f, 2.0f, 3.0f).xy(), Vector2(1.0f, 2.0f));
} }
void Vector3Test::debug() { void Vector3Test::debug() {
ostringstream o; ostringstream o;
Debug(&o) << Vector3(0.5f, 15.0f, 1.0f); Debug(&o) << Vector3(0.5f, 15.0f, 1.0f);
QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15, 1)\n")); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1)\n");
} }
}}} }}}

8
src/Math/Test/Vector3Test.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class Vector3Test: public QObject { class Vector3Test: public Corrade::TestSuite::Tester<Vector3Test> {
Q_OBJECT public:
Vector3Test();
private slots:
void construct(); void construct();
void cross(); void cross();
void axis(); void axis();

22
src/Math/Test/Vector4Test.cpp

@ -16,11 +16,10 @@
#include "Vector4Test.h" #include "Vector4Test.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Vector4.h" #include "Vector4.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::Vector4Test) CORRADE_TEST_MAIN(Magnum::Math::Test::Vector4Test)
using namespace std; using namespace std;
using namespace Corrade::Utility; using namespace Corrade::Utility;
@ -31,24 +30,31 @@ typedef Math::Vector4<float> Vector4;
typedef Math::Vector3<float> Vector3; typedef Math::Vector3<float> Vector3;
typedef Math::Vector2<float> Vector2; typedef Math::Vector2<float> Vector2;
Vector4Test::Vector4Test() {
addTests(&Vector4Test::construct,
&Vector4Test::threeComponent,
&Vector4Test::twoComponent,
&Vector4Test::debug);
}
void Vector4Test::construct() { void Vector4Test::construct() {
QVERIFY(Vector4() == Vector4(0.0f, 0.0f, 0.0f, 1.0f)); CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 1.0f));
QVERIFY((Vector4(1, 2, 3, 4) == Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); CORRADE_COMPARE(Vector4(1, 2, 3, 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
QVERIFY((Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4) == Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f))); CORRADE_COMPARE(Vector4(Vector<3, float>(1.0f, 2.0f, 3.0f), 4), (Vector<4, float>(1.0f, 2.0f, 3.0f, 4.0f)));
} }
void Vector4Test::threeComponent() { void Vector4Test::threeComponent() {
QVERIFY(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xyz() == Vector3(1.0f, 2.0f, 3.0f)); CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xyz(), Vector3(1.0f, 2.0f, 3.0f));
} }
void Vector4Test::twoComponent() { void Vector4Test::twoComponent() {
QVERIFY(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xy() == Vector2(1.0f, 2.0f)); CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).xy(), Vector2(1.0f, 2.0f));
} }
void Vector4Test::debug() { void Vector4Test::debug() {
ostringstream o; ostringstream o;
Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f);
QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15, 1, 1)\n")); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n");
} }
}}} }}}

8
src/Math/Test/Vector4Test.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class Vector4Test: public QObject { class Vector4Test: public Corrade::TestSuite::Tester<Vector4Test> {
Q_OBJECT public:
Vector4Test();
private slots:
void construct(); void construct();
void threeComponent(); void threeComponent();
void twoComponent(); void twoComponent();

59
src/Math/Test/VectorTest.cpp

@ -16,12 +16,11 @@
#include "VectorTest.h" #include "VectorTest.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Vector.h" #include "Vector.h"
#include "Math.h" #include "Math.h"
QTEST_APPLESS_MAIN(Magnum::Math::Test::VectorTest) CORRADE_TEST_MAIN(Magnum::Math::Test::VectorTest)
using namespace std; using namespace std;
using namespace Corrade::Utility; using namespace Corrade::Utility;
@ -31,11 +30,27 @@ namespace Magnum { namespace Math { namespace Test {
typedef Vector<4, float> Vector4; typedef Vector<4, float> Vector4;
typedef Vector<3, float> Vector3; typedef Vector<3, float> Vector3;
VectorTest::VectorTest() {
addTests(&VectorTest::construct,
&VectorTest::data,
&VectorTest::copy,
&VectorTest::dot,
&VectorTest::multiplyDivide,
&VectorTest::addSubstract,
&VectorTest::length,
&VectorTest::lengthSquared,
&VectorTest::normalized,
&VectorTest::product,
&VectorTest::angle,
&VectorTest::negative,
&VectorTest::debug);
}
void VectorTest::construct() { void VectorTest::construct() {
QVERIFY((Vector4() == Vector4(0.0f, 0.0f, 0.0f, 0.0f))); CORRADE_COMPARE(Vector4(), Vector4(0.0f, 0.0f, 0.0f, 0.0f));
float data[] = { 1.0f, 2.0f, 3.0f, 4.0f }; float data[] = { 1.0f, 2.0f, 3.0f, 4.0f };
QVERIFY((Vector4::from(data) == Vector4(1.0f, 2.0f, 3.0f, 4.0f))); CORRADE_COMPARE(Vector4::from(data), Vector4(1.0f, 2.0f, 3.0f, 4.0f));
} }
void VectorTest::data() { void VectorTest::data() {
@ -44,7 +59,7 @@ void VectorTest::data() {
v[0] = 1.0f; v[0] = 1.0f;
QVERIFY(v == Vector4(1.0f, 0.0f, 1.5f, 0.0f)); CORRADE_COMPARE(v, Vector4(1.0f, 0.0f, 1.5f, 0.0f));
} }
void VectorTest::copy() { void VectorTest::copy() {
@ -64,25 +79,25 @@ void VectorTest::copy() {
Vector4 original; Vector4 original;
original[3] = 1.0f; original[3] = 1.0f;
QVERIFY(v2 == original); CORRADE_COMPARE(v2, original);
QVERIFY(v3 == original); CORRADE_COMPARE(v3, original);
} }
void VectorTest::dot() { void VectorTest::dot() {
QCOMPARE(Vector4::dot({1.0f, 0.5f, 0.75f, 1.5f}, {2.0f, 4.0f, 1.0f, 7.0f}), 15.25f); CORRADE_COMPARE(Vector4::dot({1.0f, 0.5f, 0.75f, 1.5f}, {2.0f, 4.0f, 1.0f, 7.0f}), 15.25f);
} }
void VectorTest::multiplyDivide() { void VectorTest::multiplyDivide() {
Vector4 vec(1.0f, 2.0f, 3.0f, 4.0f); Vector4 vec(1.0f, 2.0f, 3.0f, 4.0f);
Vector4 multiplied(-1.5f, -3.0f, -4.5f, -6.0f); Vector4 multiplied(-1.5f, -3.0f, -4.5f, -6.0f);
QVERIFY(vec*-1.5f == multiplied); CORRADE_COMPARE(vec*-1.5f, multiplied);
QVERIFY(multiplied/-1.5f == vec); CORRADE_COMPARE(multiplied/-1.5f, vec);
Math::Vector<1, char> vecChar(32); Math::Vector<1, char> vecChar(32);
Math::Vector<1, char> multipliedChar(-48); Math::Vector<1, char> multipliedChar(-48);
QVERIFY(vecChar*-1.5f == multipliedChar); CORRADE_COMPARE(vecChar*-1.5f, multipliedChar);
QVERIFY(multipliedChar/-1.5f == vecChar); CORRADE_COMPARE(multipliedChar/-1.5f, vecChar);
} }
void VectorTest::addSubstract() { void VectorTest::addSubstract() {
@ -90,42 +105,42 @@ void VectorTest::addSubstract() {
Vector4 b(-0.5, 1.0f, 0.0f, 7.5f); Vector4 b(-0.5, 1.0f, 0.0f, 7.5f);
Vector4 expected(0.0f, -6.5f, 9.0f, -3.5f); Vector4 expected(0.0f, -6.5f, 9.0f, -3.5f);
QVERIFY(a + b == expected); CORRADE_COMPARE(a + b, expected);
QVERIFY(expected - b == a); CORRADE_COMPARE(expected - b, a);
} }
void VectorTest::length() { void VectorTest::length() {
QCOMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).length(), 5.4772256f); CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).length(), 5.4772256f);
} }
void VectorTest::lengthSquared() { void VectorTest::lengthSquared() {
QCOMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).lengthSquared(), 30.0f); CORRADE_COMPARE(Vector4(1.0f, 2.0f, 3.0f, 4.0f).lengthSquared(), 30.0f);
} }
void VectorTest::normalized() { void VectorTest::normalized() {
QVERIFY(Vector4(1.0f, 1.0f, 1.0f, 1.0f).normalized() == Vector4(0.5f, 0.5f, 0.5f, 0.5f)); CORRADE_COMPARE(Vector4(1.0f, 1.0f, 1.0f, 1.0f).normalized(), Vector4(0.5f, 0.5f, 0.5f, 0.5f));
} }
void VectorTest::product() { void VectorTest::product() {
QCOMPARE(Vector3(1.0f, 2.0f, 3.0f).product(), 6.0f); CORRADE_COMPARE(Vector3(1.0f, 2.0f, 3.0f).product(), 6.0f);
} }
void VectorTest::angle() { void VectorTest::angle() {
QCOMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, {1.0f, -2.0f, 3.0f}), rad(1.16251f)); CORRADE_COMPARE(Vector3::angle({2.0f, 3.0f, 4.0f}, {1.0f, -2.0f, 3.0f}), rad(1.162514f));
} }
void VectorTest::negative() { void VectorTest::negative() {
QVERIFY(-Vector4(1.0f, -3.0f, 5.0f, -10.0f) == Vector4(-1.0f, 3.0f, -5.0f, 10.0f)); CORRADE_COMPARE(-Vector4(1.0f, -3.0f, 5.0f, -10.0f), Vector4(-1.0f, 3.0f, -5.0f, 10.0f));
} }
void VectorTest::debug() { void VectorTest::debug() {
ostringstream o; ostringstream o;
Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f); Debug(&o) << Vector4(0.5f, 15.0f, 1.0f, 1.0f);
QCOMPARE(QString::fromStdString(o.str()), QString("Vector(0.5, 15, 1, 1)\n")); CORRADE_COMPARE(o.str(), "Vector(0.5, 15, 1, 1)\n");
o.str(""); o.str("");
Debug(&o) << "a" << Vector4() << "b" << Vector4(); Debug(&o) << "a" << Vector4() << "b" << Vector4();
QCOMPARE(QString::fromStdString(o.str()), QString("a Vector(0, 0, 0, 0) b Vector(0, 0, 0, 0)\n")); CORRADE_COMPARE(o.str(), "a Vector(0, 0, 0, 0) b Vector(0, 0, 0, 0)\n");
} }
}}} }}}

8
src/Math/Test/VectorTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Math { namespace Test { namespace Magnum { namespace Math { namespace Test {
class VectorTest: public QObject { class VectorTest: public Corrade::TestSuite::Tester<VectorTest> {
Q_OBJECT public:
VectorTest();
private slots:
void construct(); void construct();
void data(); void data();
void copy(); void copy();

2
src/Math/Vector.h

@ -20,8 +20,8 @@
*/ */
#include <cmath> #include <cmath>
#include <Utility/Debug.h>
#include "Utility/Debug.h"
#include "MathTypeTraits.h" #include "MathTypeTraits.h"
namespace Magnum { namespace Math { namespace Magnum { namespace Math {

2
src/MeshTools/Clean.h

@ -21,8 +21,8 @@
#include <unordered_map> #include <unordered_map>
#include <limits> #include <limits>
#include <Utility/MurmurHash2.h>
#include "Utility/MurmurHash2.h"
#include "TypeTraits.h" #include "TypeTraits.h"
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {

2
src/MeshTools/Subdivide.h

@ -20,7 +20,7 @@
*/ */
#include <vector> #include <vector>
#include "Utility/Debug.h" #include <Utility/Debug.h>
namespace Magnum { namespace MeshTools { namespace Magnum { namespace MeshTools {

18
src/MeshTools/Test/CMakeLists.txt

@ -1,12 +1,12 @@
corrade_add_test(MeshToolsCleanTest CleanTest.h CleanTest.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MeshToolsCleanTest CleanTest.cpp)
corrade_add_test(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.h CombineIndexedArraysTest.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MeshToolsCombineIndexedArraysTest CombineIndexedArraysTest.cpp)
corrade_add_test(MeshToolsCompressIndicesTest CompressIndicesTest.h CompressIndicesTest.cpp Magnum) corrade_add_test2(MeshToolsCompressIndicesTest CompressIndicesTest.cpp LIBRARIES Magnum)
corrade_add_test(MeshToolsFlipNormalsTest FlipNormalsTest.h FlipNormalsTest.cpp MagnumMeshToolsTestLib) corrade_add_test2(MeshToolsFlipNormalsTest FlipNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib)
corrade_add_test(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.h GenerateFlatNormalsTest.cpp MagnumMeshToolsTestLib) corrade_add_test2(MeshToolsGenerateFlatNormalsTest GenerateFlatNormalsTest.cpp LIBRARIES MagnumMeshToolsTestLib)
corrade_add_test(MeshToolsInterleaveTest InterleaveTest.h InterleaveTest.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MeshToolsInterleaveTest InterleaveTest.cpp)
corrade_add_test(MeshToolsSubdivideTest SubdivideTest.h SubdivideTest.cpp ${CORRADE_UTILITY_LIBRARY}) corrade_add_test2(MeshToolsSubdivideTest SubdivideTest.cpp)
corrade_add_test(MeshToolsSubdivideCleanBenchmark SubdivideCleanBenchmark.h SubdivideCleanBenchmark.cpp MagnumPrimitives) # corrade_add_test(MeshToolsSubdivideCleanBenchmark SubdivideCleanBenchmark.h SubdivideCleanBenchmark.cpp MagnumPrimitives)
corrade_add_test(MeshToolsTipsifyTest TipsifyTest.h TipsifyTest.cpp MagnumMeshTools) corrade_add_test2(MeshToolsTipsifyTest TipsifyTest.cpp LIBRARIES MagnumMeshTools)
# Graceful assert for testing # Graceful assert for testing
set_target_properties(MeshToolsCombineIndexedArraysTest MeshToolsInterleaveTest MeshToolsSubdivideTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) set_target_properties(MeshToolsCombineIndexedArraysTest MeshToolsInterleaveTest MeshToolsSubdivideTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT)

12
src/MeshTools/Test/CleanTest.cpp

@ -15,24 +15,26 @@
#include "CleanTest.h" #include "CleanTest.h"
#include <QtTest/QTest>
#include "MeshTools/Clean.h" #include "MeshTools/Clean.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::CleanTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CleanTest)
using namespace std; using namespace std;
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
CleanTest::CleanTest() {
addTests(&CleanTest::cleanMesh);
}
void CleanTest::cleanMesh() { void CleanTest::cleanMesh() {
vector<Vector1> vertices{1, 2, 1, 4}; vector<Vector1> vertices{1, 2, 1, 4};
vector<unsigned int> indices{0, 1, 2, 1, 2, 3}; vector<unsigned int> indices{0, 1, 2, 1, 2, 3};
MeshTools::clean(indices, vertices); MeshTools::clean(indices, vertices);
/* Verify cleanup */ /* Verify cleanup */
QVERIFY((vertices == vector<Vector1>{1, 2, 4})); CORRADE_VERIFY(vertices == (vector<Vector1>{1, 2, 4}));
QVERIFY((indices == vector<unsigned int>{0, 1, 0, 1, 0, 2})); CORRADE_COMPARE(indices, (vector<unsigned int>{0, 1, 0, 1, 0, 2}));
} }
}}} }}}

8
src/MeshTools/Test/CleanTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class CleanTest: public QObject { class CleanTest: public Corrade::TestSuite::Tester<CleanTest> {
Q_OBJECT public:
CleanTest();
private slots:
void cleanMesh(); void cleanMesh();
private: private:

21
src/MeshTools/Test/CombineIndexedArraysTest.cpp

@ -16,16 +16,20 @@
#include "CombineIndexedArraysTest.h" #include "CombineIndexedArraysTest.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "MeshTools/CombineIndexedArrays.h" #include "MeshTools/CombineIndexedArrays.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::CombineIndexedArraysTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CombineIndexedArraysTest)
using namespace std; using namespace std;
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
CombineIndexedArraysTest::CombineIndexedArraysTest() {
addTests(&CombineIndexedArraysTest::wrongIndexCount,
&CombineIndexedArraysTest::combine);
}
void CombineIndexedArraysTest::wrongIndexCount() { void CombineIndexedArraysTest::wrongIndexCount() {
stringstream ss; stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
@ -34,8 +38,8 @@ void CombineIndexedArraysTest::wrongIndexCount() {
tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{0, 1, 0}, array), tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{0, 1, 0}, array),
tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{3, 4}, array)); tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{3, 4}, array));
QVERIFY(result.size() == 0); CORRADE_COMPARE(result.size(), 0);
QVERIFY(ss.str() == "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n"); CORRADE_COMPARE(ss.str(), "MeshTools::combineIndexedArrays(): index arrays don't have the same length, nothing done.\n");
} }
void CombineIndexedArraysTest::combine() { void CombineIndexedArraysTest::combine() {
@ -48,11 +52,10 @@ void CombineIndexedArraysTest::combine() {
tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{3, 4, 3}, array2), tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{3, 4, 3}, array2),
tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{6, 7, 6}, array3)); tuple<const vector<unsigned int>&, vector<unsigned int>&>(vector<unsigned int>{6, 7, 6}, array3));
QVERIFY((result == vector<unsigned int>{0, 1, 0})); CORRADE_COMPARE(result, (vector<unsigned int>{0, 1, 0}));
QVERIFY((array1 == vector<unsigned int>{0, 1})); CORRADE_COMPARE(array1, (vector<unsigned int>{0, 1}));
QVERIFY((array2 == vector<unsigned int>{3, 4})); CORRADE_COMPARE(array2, (vector<unsigned int>{3, 4}));
QVERIFY((array3 == vector<unsigned int>{6, 7})); CORRADE_COMPARE(array3, (vector<unsigned int>{6, 7}));
} }
}}} }}}

8
src/MeshTools/Test/CombineIndexedArraysTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class CombineIndexedArraysTest: public QObject { class CombineIndexedArraysTest: public Corrade::TestSuite::Tester<CombineIndexedArraysTest> {
Q_OBJECT public:
CombineIndexedArraysTest();
private slots:
void wrongIndexCount(); void wrongIndexCount();
void combine(); void combine();
}; };

65
src/MeshTools/Test/CompressIndicesTest.cpp

@ -15,18 +15,23 @@
#include "CompressIndicesTest.h" #include "CompressIndicesTest.h"
#include <QtTest/QTest> #include <Utility/Endianness.h>
#include "Utility/Endianness.h"
#include "MeshTools/CompressIndices.h" #include "MeshTools/CompressIndices.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::CompressIndicesTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::CompressIndicesTest)
using namespace std; using namespace std;
using Corrade::Utility::Endianness; using Corrade::Utility::Endianness;
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
CompressIndicesTest::CompressIndicesTest() {
addTests(&CompressIndicesTest::compressChar,
&CompressIndicesTest::compressShort,
&CompressIndicesTest::compressInt);
}
void CompressIndicesTest::compressChar() { void CompressIndicesTest::compressChar() {
size_t indexCount; size_t indexCount;
Type indexType; Type indexType;
@ -34,10 +39,10 @@ void CompressIndicesTest::compressChar() {
tie(indexCount, indexType, data) = MeshTools::compressIndices( tie(indexCount, indexType, data) = MeshTools::compressIndices(
vector<unsigned int>{1, 2, 3, 0, 4}); vector<unsigned int>{1, 2, 3, 0, 4});
QVERIFY(indexCount == 5); CORRADE_COMPARE(indexCount, 5);
QVERIFY(indexType == Type::UnsignedByte); CORRADE_VERIFY(indexType == Type::UnsignedByte);
QVERIFY((vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)) == CORRADE_COMPARE(vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)),
vector<char>{ 0x01, 0x02, 0x03, 0x00, 0x04 })); (vector<char>{ 0x01, 0x02, 0x03, 0x00, 0x04 }));
delete[] data; delete[] data;
} }
@ -49,20 +54,20 @@ void CompressIndicesTest::compressShort() {
tie(indexCount, indexType, data) = MeshTools::compressIndices( tie(indexCount, indexType, data) = MeshTools::compressIndices(
vector<unsigned int>{1, 256, 0, 5}); vector<unsigned int>{1, 256, 0, 5});
QVERIFY(indexCount == 4); CORRADE_COMPARE(indexCount, 4);
QVERIFY(indexType == Type::UnsignedShort); CORRADE_VERIFY(indexType == Type::UnsignedShort);
if(!Endianness::isBigEndian()) { if(!Endianness::isBigEndian()) {
QVERIFY((vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)) == CORRADE_COMPARE(vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)),
vector<char>{ 0x01, 0x00, (vector<char>{ 0x01, 0x00,
0x00, 0x01, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x05, 0x00 })); 0x05, 0x00 }));
} else { } else {
QVERIFY((vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)) == CORRADE_COMPARE(vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)),
vector<char>{ 0x00, 0x01, (vector<char>{ 0x00, 0x01,
0x01, 0x00, 0x01, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x05 })); 0x00, 0x05 }));
} }
delete[] data; delete[] data;
@ -75,21 +80,19 @@ void CompressIndicesTest::compressInt() {
tie(indexCount, indexType, data) = MeshTools::compressIndices( tie(indexCount, indexType, data) = MeshTools::compressIndices(
vector<unsigned int>{65536, 3, 2}); vector<unsigned int>{65536, 3, 2});
QVERIFY(indexCount == 3); CORRADE_COMPARE(indexCount, 3);
QVERIFY(indexType == Type::UnsignedInt); CORRADE_VERIFY(indexType == Type::UnsignedInt);
if(!Endianness::isBigEndian()) { if(!Endianness::isBigEndian()) {
QVERIFY((vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)) == CORRADE_COMPARE(vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)),
vector<char>{ 0x00, 0x00, 0x01, 0x00, (vector<char>{ 0x00, 0x00, 0x01, 0x00,
0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00 0x02, 0x00, 0x00, 0x00 }));
}));
} else { } else {
QVERIFY((vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)) == CORRADE_COMPARE(vector<char>(data, data+indexCount*TypeInfo::sizeOf(indexType)),
vector<char>{ 0x00, 0x01, 0x00, 0x00, (vector<char>{ 0x00, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03,
0x00, 0x00, 0x00, 0x02 0x00, 0x00, 0x00, 0x02 }));
}));
} }
delete[] data; delete[] data;

8
src/MeshTools/Test/CompressIndicesTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class CompressIndicesTest: public QObject { class CompressIndicesTest: public Corrade::TestSuite::Tester<CompressIndicesTest> {
Q_OBJECT public:
CompressIndicesTest();
private slots:
void compressChar(); void compressChar();
void compressShort(); void compressShort();
void compressInt(); void compressInt();

22
src/MeshTools/Test/FlipNormalsTest.cpp

@ -16,15 +16,21 @@
#include "FlipNormalsTest.h" #include "FlipNormalsTest.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "MeshTools/FlipNormals.h" #include "MeshTools/FlipNormals.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::FlipNormalsTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::FlipNormalsTest)
using namespace std; using namespace std;
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
FlipNormalsTest::FlipNormalsTest() {
addTests(&FlipNormalsTest::wrongIndexCount,
&FlipNormalsTest::flipFaceWinding,
&FlipNormalsTest::flipNormals);
}
void FlipNormalsTest::wrongIndexCount() { void FlipNormalsTest::wrongIndexCount() {
stringstream ss; stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
@ -32,7 +38,7 @@ void FlipNormalsTest::wrongIndexCount() {
vector<unsigned int> indices{0, 1}; vector<unsigned int> indices{0, 1};
MeshTools::flipFaceWinding(indices); MeshTools::flipFaceWinding(indices);
QVERIFY(ss.str() == "MeshTools::flipNormals(): index count is not divisible by 3!\n"); CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n");
} }
void FlipNormalsTest::flipFaceWinding() { void FlipNormalsTest::flipFaceWinding() {
@ -40,8 +46,8 @@ void FlipNormalsTest::flipFaceWinding() {
3, 4, 5}; 3, 4, 5};
MeshTools::flipFaceWinding(indices); MeshTools::flipFaceWinding(indices);
QVERIFY((indices == vector<unsigned int>{0, 2, 1, CORRADE_COMPARE(indices, (vector<unsigned int>{0, 2, 1,
3, 5, 4})); 3, 5, 4}));
} }
void FlipNormalsTest::flipNormals() { void FlipNormalsTest::flipNormals() {
@ -50,9 +56,9 @@ void FlipNormalsTest::flipNormals() {
Vector3::zAxis()}; Vector3::zAxis()};
MeshTools::flipNormals(normals); MeshTools::flipNormals(normals);
QVERIFY((normals == vector<Vector3>{-Vector3::xAxis(), CORRADE_COMPARE(normals, (vector<Vector3>{-Vector3::xAxis(),
-Vector3::yAxis(), -Vector3::yAxis(),
-Vector3::zAxis()})); -Vector3::zAxis()}));
} }
}}} }}}

8
src/MeshTools/Test/FlipNormalsTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class FlipNormalsTest: public QObject { class FlipNormalsTest: public Corrade::TestSuite::Tester<FlipNormalsTest> {
Q_OBJECT public:
FlipNormalsTest();
private slots:
void wrongIndexCount(); void wrongIndexCount();
void flipFaceWinding(); void flipFaceWinding();
void flipNormals(); void flipNormals();

19
src/MeshTools/Test/GenerateFlatNormalsTest.cpp

@ -16,15 +16,20 @@
#include "GenerateFlatNormalsTest.h" #include "GenerateFlatNormalsTest.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "MeshTools/GenerateFlatNormals.h" #include "MeshTools/GenerateFlatNormals.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::GenerateFlatNormalsTest)
using namespace std; using namespace std;
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
GenerateFlatNormalsTest::GenerateFlatNormalsTest() {
addTests(&GenerateFlatNormalsTest::wrongIndexCount,
&GenerateFlatNormalsTest::generate);
}
void GenerateFlatNormalsTest::wrongIndexCount() { void GenerateFlatNormalsTest::wrongIndexCount() {
stringstream ss; stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
@ -34,9 +39,9 @@ void GenerateFlatNormalsTest::wrongIndexCount() {
0, 1 0, 1
}, {}); }, {});
QVERIFY(indices.size() == 0); CORRADE_COMPARE(indices.size(), 0);
QVERIFY(normals.size() == 0); CORRADE_COMPARE(normals.size(), 0);
QVERIFY(ss.str() == "MeshTools::generateFlatNormals(): index count is not divisible by 3!\n"); CORRADE_COMPARE(ss.str(), "MeshTools::generateFlatNormals(): index count is not divisible by 3!\n");
} }
void GenerateFlatNormalsTest::generate() { void GenerateFlatNormalsTest::generate() {
@ -55,11 +60,11 @@ void GenerateFlatNormalsTest::generate() {
}, vertices); }, vertices);
QVERIFY((indices == vector<unsigned int>{ CORRADE_COMPARE(indices, (vector<unsigned int>{
0, 0, 0, 0, 0, 0,
1, 1, 1 1, 1, 1
})); }));
QVERIFY((normals == vector<Vector3>{ CORRADE_COMPARE(normals, (vector<Vector3>{
Vector3::zAxis(), Vector3::zAxis(),
-Vector3::zAxis() -Vector3::zAxis()
})); }));

8
src/MeshTools/Test/GenerateFlatNormalsTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class GenerateFlatNormalsTest: public QObject { class GenerateFlatNormalsTest: public Corrade::TestSuite::Tester<GenerateFlatNormalsTest> {
Q_OBJECT public:
GenerateFlatNormalsTest();
private slots:
void wrongIndexCount(); void wrongIndexCount();
void generate(); void generate();
}; };

29
src/MeshTools/Test/InterleaveTest.cpp

@ -16,34 +16,39 @@
#include "InterleaveTest.h" #include "InterleaveTest.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "Utility/Endianness.h" #include "Utility/Endianness.h"
#include "Utility/Debug.h" #include "Utility/Debug.h"
#include "MeshTools/Interleave.h" #include "MeshTools/Interleave.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::InterleaveTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::InterleaveTest)
using namespace std; using namespace std;
using Corrade::Utility::Endianness; using Corrade::Utility::Endianness;
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
InterleaveTest::InterleaveTest() {
addTests(&InterleaveTest::attributeCount,
&InterleaveTest::stride,
&InterleaveTest::write);
}
void InterleaveTest::attributeCount() { void InterleaveTest::attributeCount() {
stringstream ss; stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
QCOMPARE((Implementation::Interleave::attributeCount(vector<char>{0, 1, 2}, CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector<char>{0, 1, 2},
vector<char>{0, 1, 2, 3, 4, 5})), size_t(0)); vector<char>{0, 1, 2, 3, 4, 5})), size_t(0));
QVERIFY(ss.str() == "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n"); CORRADE_COMPARE(ss.str(), "MeshTools::interleave(): attribute arrays don't have the same length, nothing done.\n");
QCOMPARE((Implementation::Interleave::attributeCount(vector<char>{0, 1, 2}, CORRADE_COMPARE((Implementation::Interleave::attributeCount(vector<char>{0, 1, 2},
vector<char>{3, 4, 5})), size_t(3)); vector<char>{3, 4, 5})), size_t(3));
} }
void InterleaveTest::stride() { void InterleaveTest::stride() {
QCOMPARE(Implementation::Interleave::stride(vector<char>()), size_t(1)); CORRADE_COMPARE(Implementation::Interleave::stride(vector<char>()), size_t(1));
QCOMPARE(Implementation::Interleave::stride(vector<int>()), size_t(4)); CORRADE_COMPARE(Implementation::Interleave::stride(vector<int>()), size_t(4));
QCOMPARE((Implementation::Interleave::stride(vector<char>(), vector<int>())), size_t(5)); CORRADE_COMPARE((Implementation::Interleave::stride(vector<char>(), vector<int>())), size_t(5));
} }
void InterleaveTest::write() { void InterleaveTest::write() {
@ -55,17 +60,17 @@ void InterleaveTest::write() {
vector<int>{3, 4, 5}, vector<int>{3, 4, 5},
vector<short>{6, 7, 8}); vector<short>{6, 7, 8});
QCOMPARE(attributeCount, size_t(3)); CORRADE_COMPARE(attributeCount, size_t(3));
QCOMPARE(stride, size_t(7)); CORRADE_COMPARE(stride, size_t(7));
size_t size = attributeCount*stride; size_t size = attributeCount*stride;
if(!Endianness::isBigEndian()) { if(!Endianness::isBigEndian()) {
QVERIFY((vector<char>(data, data+size) == vector<char>{ CORRADE_COMPARE(vector<char>(data, data+size), (vector<char>{
0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x06, 0x00,
0x01, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00, 0x01, 0x04, 0x00, 0x00, 0x00, 0x07, 0x00,
0x02, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00 0x02, 0x05, 0x00, 0x00, 0x00, 0x08, 0x00
})); }));
} else { } else {
QVERIFY((vector<char>(data, data+size) == vector<char>{ CORRADE_COMPARE(vector<char>(data, data+size), (vector<char>{
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x06,
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x07,
0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08 0x02, 0x00, 0x00, 0x00, 0x05, 0x00, 0x08

8
src/MeshTools/Test/InterleaveTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class InterleaveTest: public QObject { class InterleaveTest: public Corrade::TestSuite::Tester<InterleaveTest> {
Q_OBJECT public:
InterleaveTest();
private slots:
void attributeCount(); void attributeCount();
void stride(); void stride();
void write(); void write();

18
src/MeshTools/Test/SubdivideTest.cpp

@ -16,17 +16,21 @@
#include "SubdivideTest.h" #include "SubdivideTest.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
#include "MeshTools/Clean.h" #include "MeshTools/Clean.h"
#include "MeshTools/Subdivide.h" #include "MeshTools/Subdivide.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::SubdivideTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::SubdivideTest)
using namespace std; using namespace std;
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
SubdivideTest::SubdivideTest() {
addTests(&SubdivideTest::wrongIndexCount,
&SubdivideTest::subdivide);
}
void SubdivideTest::wrongIndexCount() { void SubdivideTest::wrongIndexCount() {
stringstream ss; stringstream ss;
Error::setOutput(&ss); Error::setOutput(&ss);
@ -34,7 +38,7 @@ void SubdivideTest::wrongIndexCount() {
vector<Vector1> vertices; vector<Vector1> vertices;
vector<unsigned int> indices{0, 1}; vector<unsigned int> indices{0, 1};
MeshTools::subdivide(indices, vertices, interpolator); MeshTools::subdivide(indices, vertices, interpolator);
QVERIFY(ss.str() == "MeshTools::subdivide(): index count is not divisible by 3!\n"); CORRADE_COMPARE(ss.str(), "MeshTools::subdivide(): index count is not divisible by 3!\n");
} }
void SubdivideTest::subdivide() { void SubdivideTest::subdivide() {
@ -42,15 +46,15 @@ void SubdivideTest::subdivide() {
vector<unsigned int> indices{0, 1, 2, 1, 2, 3}; vector<unsigned int> indices{0, 1, 2, 1, 2, 3};
MeshTools::subdivide(indices, vertices, interpolator); MeshTools::subdivide(indices, vertices, interpolator);
QVERIFY(indices.size() == 24); CORRADE_COMPARE(indices.size(), 24);
QVERIFY((vertices == vector<Vector1>{0, 2, 6, 8, 1, 4, 3, 4, 7, 5})); CORRADE_VERIFY(vertices == (vector<Vector1>{0, 2, 6, 8, 1, 4, 3, 4, 7, 5}));
QVERIFY((indices == vector<unsigned int>{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3})); CORRADE_COMPARE(indices, (vector<unsigned int>{4, 5, 6, 7, 8, 9, 0, 4, 6, 4, 1, 5, 6, 5, 2, 1, 7, 9, 7, 2, 8, 9, 8, 3}));
MeshTools::clean(indices, vertices); MeshTools::clean(indices, vertices);
/* Vertices 0, 1, 2, 3, 4, 5, 6, 7, 8 */ /* Vertices 0, 1, 2, 3, 4, 5, 6, 7, 8 */
QVERIFY(vertices.size() == 9); CORRADE_COMPARE(vertices.size(), 9);
} }
}}} }}}

8
src/MeshTools/Test/SubdivideTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class SubdivideTest: public QObject { class SubdivideTest: public Corrade::TestSuite::Tester<SubdivideTest> {
Q_OBJECT public:
SubdivideTest();
private slots:
void wrongIndexCount(); void wrongIndexCount();
void subdivide(); void subdivide();

15
src/MeshTools/Test/TipsifyTest.cpp

@ -19,7 +19,7 @@
#include "MeshTools/Tipsify.h" #include "MeshTools/Tipsify.h"
QTEST_APPLESS_MAIN(Magnum::MeshTools::Test::TipsifyTest) CORRADE_TEST_MAIN(Magnum::MeshTools::Test::TipsifyTest)
using namespace std; using namespace std;
@ -63,13 +63,16 @@ TipsifyTest::TipsifyTest(): indices{
14, 11, 10, 14, 11, 10,
16, 17, 18 16, 17, 18
}, vertexCount(19) {} }, vertexCount(19) {
addTests(&TipsifyTest::buildAdjacency,
&TipsifyTest::tipsify);
}
void TipsifyTest::buildAdjacency() { void TipsifyTest::buildAdjacency() {
vector<unsigned int> liveTriangleCount, neighborOffset, neighbors; vector<unsigned int> liveTriangleCount, neighborOffset, neighbors;
Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors); Implementation::Tipsify(indices, vertexCount).buildAdjacency(liveTriangleCount, neighborOffset, neighbors);
QVERIFY((liveTriangleCount == vector<unsigned int>{ CORRADE_COMPARE(liveTriangleCount, (vector<unsigned int>{
1, 3, 3, 2, 1, 3, 3, 2,
4, 6, 6, 2, 4, 6, 6, 2,
2, 6, 6, 4, 2, 6, 6, 4,
@ -77,7 +80,7 @@ void TipsifyTest::buildAdjacency() {
1, 1, 1 1, 1, 1
})); }));
QVERIFY((neighborOffset == vector<unsigned int>{ CORRADE_COMPARE(neighborOffset, (vector<unsigned int>{
0, 1, 4, 7, 0, 1, 4, 7,
9, 13, 19, 25, 9, 13, 19, 25,
27, 29, 35, 41, 27, 29, 35, 41,
@ -85,7 +88,7 @@ void TipsifyTest::buildAdjacency() {
54, 55, 56, 57 54, 55, 56, 57
})); }));
QVERIFY((neighbors == vector<unsigned int>{ CORRADE_COMPARE(neighbors, (vector<unsigned int>{
0, 0,
0, 7, 11, 0, 7, 11,
2, 7, 13, 2, 7, 13,
@ -113,7 +116,7 @@ void TipsifyTest::buildAdjacency() {
void TipsifyTest::tipsify() { void TipsifyTest::tipsify() {
MeshTools::tipsify(indices, vertexCount, 3); MeshTools::tipsify(indices, vertexCount, 3);
QVERIFY((indices == vector<unsigned int>{ CORRADE_COMPARE(indices, (vector<unsigned int>{
4, 1, 0, 4, 1, 0,
9, 5, 4, 9, 5, 4,
1, 4, 5, 1, 4, 5,

7
src/MeshTools/Test/TipsifyTest.h

@ -16,17 +16,14 @@
*/ */
#include <vector> #include <vector>
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace MeshTools { namespace Test { namespace Magnum { namespace MeshTools { namespace Test {
class TipsifyTest: public QObject { class TipsifyTest: public Corrade::TestSuite::Tester<TipsifyTest> {
Q_OBJECT
public: public:
TipsifyTest(); TipsifyTest();
private slots:
void buildAdjacency(); void buildAdjacency();
void tipsify(); void tipsify();

20
src/Physics/Test/AbstractShapeTest.h

@ -15,13 +15,13 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtTest/QTest> #include <TestSuite/Tester.h>
#include "Magnum.h" #include "Magnum.h"
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class AbstractShapeTest: public QObject { class AbstractShapeTest {
protected: protected:
template<class T> void randomTransformation(T& shape) { template<class T> void randomTransformation(T& shape) {
shape.applyTransformation(Matrix4::translation(Vector3(7.0f, 8.0f, -9.0f))); shape.applyTransformation(Matrix4::translation(Vector3(7.0f, 8.0f, -9.0f)));
@ -29,16 +29,16 @@ class AbstractShapeTest: public QObject {
}; };
#define VERIFY_COLLIDES(a, b) \ #define VERIFY_COLLIDES(a, b) \
QVERIFY(a % b); \ CORRADE_VERIFY(a % b); \
QVERIFY(b % a); \ CORRADE_VERIFY(b % a); \
QVERIFY(a.collides(&b)); \ CORRADE_VERIFY(a.collides(&b)); \
QVERIFY(b.collides(&a)); CORRADE_VERIFY(b.collides(&a));
#define VERIFY_NOT_COLLIDES(a, b) \ #define VERIFY_NOT_COLLIDES(a, b) \
QVERIFY(!(a % b)); \ CORRADE_VERIFY(!(a % b)); \
QVERIFY(!(b % a)); \ CORRADE_VERIFY(!(b % a)); \
QVERIFY(!(a.collides(&b))); \ CORRADE_VERIFY(!(a.collides(&b))); \
QVERIFY(!(b.collides(&a))); CORRADE_VERIFY(!(b.collides(&a)));
}}} }}}

16
src/Physics/Test/AxisAlignedBoxTest.cpp

@ -15,24 +15,26 @@
#include "AxisAlignedBoxTest.h" #include "AxisAlignedBoxTest.h"
#include <QtTest/QTest>
#include "Physics/AxisAlignedBox.h" #include "Physics/AxisAlignedBox.h"
QTEST_APPLESS_MAIN(Magnum::Physics::Test::AxisAlignedBoxTest) CORRADE_TEST_MAIN(Magnum::Physics::Test::AxisAlignedBoxTest)
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
AxisAlignedBoxTest::AxisAlignedBoxTest() {
addTests(&AxisAlignedBoxTest::applyTransformation);
}
void AxisAlignedBoxTest::applyTransformation() { void AxisAlignedBoxTest::applyTransformation() {
Physics::AxisAlignedBox box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f}); Physics::AxisAlignedBox box({-1.0f, -2.0f, -3.0f}, {1.0f, 2.0f, 3.0f});
box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f})); box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f}));
QVERIFY((box.transformedPosition() == Vector3(-2.0f, 2.0f, -4.5f))); CORRADE_COMPARE(box.transformedPosition(), Vector3(-2.0f, 2.0f, -4.5f));
QVERIFY((box.transformedSize() == Vector3(2.0f, -2.0f, 4.5f))); CORRADE_COMPARE(box.transformedSize(), Vector3(2.0f, -2.0f, 4.5f));
box.applyTransformation(Matrix4::translation(Vector3(1.0f))*Matrix4::rotation(deg(90.0f), Vector3::xAxis())); box.applyTransformation(Matrix4::translation(Vector3(1.0f))*Matrix4::rotation(deg(90.0f), Vector3::xAxis()));
QVERIFY((box.transformedPosition() == Vector3(0.0f, 4.0f, -1.0f))); CORRADE_COMPARE(box.transformedPosition(), Vector3(0.0f, 4.0f, -1.0f));
QVERIFY((box.transformedSize() == Vector3(1.0f, -3.0f, 2.0f))); CORRADE_COMPARE(box.transformedSize(), Vector3(1.0f, -3.0f, 2.0f));
} }
}}} }}}

8
src/Physics/Test/AxisAlignedBoxTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class AxisAlignedBoxTest: public QObject { class AxisAlignedBoxTest: public Corrade::TestSuite::Tester<AxisAlignedBoxTest> {
Q_OBJECT public:
AxisAlignedBoxTest();
private slots:
void applyTransformation(); void applyTransformation();
}; };

14
src/Physics/Test/CMakeLists.txt

@ -1,7 +1,7 @@
corrade_add_test(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.h AxisAlignedBoxTest.cpp MagnumPhysics) corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test(PhysicsCapsuleTest CapsuleTest.h CapsuleTest.cpp MagnumPhysics) corrade_add_test2(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test(PhysicsLineTest LineTest.h LineTest.cpp MagnumPhysics) corrade_add_test2(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test(PhysicsPlaneTest PlaneTest.h PlaneTest.cpp MagnumPhysics) corrade_add_test2(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test(PhysicsPointTest PointTest.h PointTest.cpp MagnumPhysics) corrade_add_test2(PhysicsPointTest PointTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test(PhysicsShapeGroupTest ShapeGroupTest.h ShapeGroupTest.cpp MagnumPhysics) corrade_add_test2(PhysicsShapeGroupTest ShapeGroupTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test(PhysicsSphereTest SphereTest.h SphereTest.cpp MagnumPhysics) corrade_add_test2(PhysicsSphereTest SphereTest.cpp LIBRARIES MagnumPhysics)

17
src/Physics/Test/CapsuleTest.cpp

@ -15,25 +15,28 @@
#include "CapsuleTest.h" #include "CapsuleTest.h"
#include <QtTest/QTest>
#include "Physics/Capsule.h" #include "Physics/Capsule.h"
QTEST_APPLESS_MAIN(Magnum::Physics::Test::CapsuleTest) CORRADE_TEST_MAIN(Magnum::Physics::Test::CapsuleTest)
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
CapsuleTest::CapsuleTest() {
addTests(&CapsuleTest::applyTransformation,
&CapsuleTest::collisionPoint);
}
void CapsuleTest::applyTransformation() { void CapsuleTest::applyTransformation() {
Physics::Capsule capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); Physics::Capsule capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f);
capsule.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); capsule.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::zAxis()));
QVERIFY((capsule.transformedA() == Vector3(-2.0f, 1.0f, 3.0f))); CORRADE_COMPARE(capsule.transformedA(), Vector3(-2.0f, 1.0f, 3.0f));
QVERIFY((capsule.transformedB() == Vector3(2.0f, -1.0f, -3.0f))); CORRADE_COMPARE(capsule.transformedB(), Vector3(2.0f, -1.0f, -3.0f));
QCOMPARE(capsule.radius(), 7.0f); CORRADE_COMPARE(capsule.radius(), 7.0f);
/* Apply average scaling to radius */ /* Apply average scaling to radius */
capsule.applyTransformation(Matrix4::scaling({Math::Constants<GLfloat>::sqrt3(), -Math::Constants<GLfloat>::sqrt2(), 2.0f})); capsule.applyTransformation(Matrix4::scaling({Math::Constants<GLfloat>::sqrt3(), -Math::Constants<GLfloat>::sqrt2(), 2.0f}));
QCOMPARE(capsule.transformedRadius(), Math::Constants<GLfloat>::sqrt3()*7.0f); CORRADE_COMPARE(capsule.transformedRadius(), Math::Constants<GLfloat>::sqrt3()*7.0f);
} }
void CapsuleTest::collisionPoint() { void CapsuleTest::collisionPoint() {

6
src/Physics/Test/CapsuleTest.h

@ -19,10 +19,10 @@
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class CapsuleTest: public AbstractShapeTest { class CapsuleTest: public Corrade::TestSuite::Tester<CapsuleTest>, AbstractShapeTest {
Q_OBJECT public:
CapsuleTest();
private slots:
void applyTransformation(); void applyTransformation();
void collisionPoint(); void collisionPoint();
void collisionSphere(); void collisionSphere();

12
src/Physics/Test/LineTest.cpp

@ -15,19 +15,21 @@
#include "LineTest.h" #include "LineTest.h"
#include <QtTest/QTest>
#include "Physics/Line.h" #include "Physics/Line.h"
QTEST_APPLESS_MAIN(Magnum::Physics::Test::LineTest) CORRADE_TEST_MAIN(Magnum::Physics::Test::LineTest)
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
LineTest::LineTest() {
addTests(&LineTest::applyTransformation);
}
void LineTest::applyTransformation() { void LineTest::applyTransformation() {
Physics::Line line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}); Physics::Line line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f});
line.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); line.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::zAxis()));
QVERIFY((line.transformedA() == Vector3(-2.0f, 1.0f, 3.0f))); CORRADE_COMPARE(line.transformedA(), Vector3(-2.0f, 1.0f, 3.0f));
QVERIFY((line.transformedB() == Vector3(2.0f, -1.0f, -3.0f))); CORRADE_COMPARE(line.transformedB(), Vector3(2.0f, -1.0f, -3.0f));
} }
}}} }}}

8
src/Physics/Test/LineTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class LineTest: public QObject { class LineTest: public Corrade::TestSuite::Tester<LineTest> {
Q_OBJECT public:
LineTest();
private slots:
void applyTransformation(); void applyTransformation();
}; };

18
src/Physics/Test/PlaneTest.cpp

@ -15,25 +15,29 @@
#include "PlaneTest.h" #include "PlaneTest.h"
#include <QtTest/QTest>
#include "Physics/Plane.h" #include "Physics/Plane.h"
QTEST_APPLESS_MAIN(Magnum::Physics::Test::PlaneTest) CORRADE_TEST_MAIN(Magnum::Physics::Test::PlaneTest)
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
PlaneTest::PlaneTest() {
addTests(&PlaneTest::applyTransformation,
&PlaneTest::collisionLine,
&PlaneTest::collisionLineSegment);
}
void PlaneTest::applyTransformation() { void PlaneTest::applyTransformation() {
Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Math::Constants<float>::sqrt2(), -Math::Constants<float>::sqrt2(), 0}); Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Math::Constants<float>::sqrt2(), -Math::Constants<float>::sqrt2(), 0});
plane.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::xAxis())); plane.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::xAxis()));
QVERIFY(plane.transformedPosition() == Vector3(1.0f, -3.0f, 2.0f)); CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.0f, -3.0f, 2.0f));
QVERIFY(plane.transformedNormal() == Vector3(Math::Constants<float>::sqrt2(), 0, -Math::Constants<float>::sqrt2())); CORRADE_COMPARE(plane.transformedNormal(), Vector3(Math::Constants<float>::sqrt2(), 0, -Math::Constants<float>::sqrt2()));
/* The normal should stay normalized */ /* The normal should stay normalized */
plane.applyTransformation(Matrix4::scaling({1.5f, 2.0f, 3.0f})); plane.applyTransformation(Matrix4::scaling({1.5f, 2.0f, 3.0f}));
QVERIFY(plane.transformedPosition() == Vector3(1.5f, 4.0f, 9.0f)); CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.5f, 4.0f, 9.0f));
QVERIFY(plane.transformedNormal() == Vector3(Math::Constants<float>::sqrt2(), -Math::Constants<float>::sqrt2(), 0)); CORRADE_COMPARE(plane.transformedNormal(), Vector3(Math::Constants<float>::sqrt2(), -Math::Constants<float>::sqrt2(), 0));
} }
void PlaneTest::collisionLine() { void PlaneTest::collisionLine() {

6
src/Physics/Test/PlaneTest.h

@ -19,10 +19,10 @@
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class PlaneTest: public AbstractShapeTest { class PlaneTest: public Corrade::TestSuite::Tester<PlaneTest>, AbstractShapeTest {
Q_OBJECT public:
PlaneTest();
private slots:
void applyTransformation(); void applyTransformation();
void collisionLine(); void collisionLine();
void collisionLineSegment(); void collisionLineSegment();

10
src/Physics/Test/PointTest.cpp

@ -15,18 +15,20 @@
#include "PointTest.h" #include "PointTest.h"
#include <QtTest/QTest>
#include "Physics/Point.h" #include "Physics/Point.h"
QTEST_APPLESS_MAIN(Magnum::Physics::Test::PointTest) CORRADE_TEST_MAIN(Magnum::Physics::Test::PointTest)
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
PointTest::PointTest() {
addTests(&PointTest::applyTransformation);
}
void PointTest::applyTransformation() { void PointTest::applyTransformation() {
Physics::Point point({1.0f, 2.0f, 3.0f}); Physics::Point point({1.0f, 2.0f, 3.0f});
point.applyTransformation(Matrix4::translation({5.0f, 6.0f, 7.0f})); point.applyTransformation(Matrix4::translation({5.0f, 6.0f, 7.0f}));
QVERIFY((point.transformedPosition() == Vector3(6.0f, 8.0f, 10.0f))); CORRADE_COMPARE(point.transformedPosition(), Vector3(6.0f, 8.0f, 10.0f));
} }
}}} }}}

8
src/Physics/Test/PointTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class PointTest: public QObject { class PointTest: public Corrade::TestSuite::Tester<PointTest> {
Q_OBJECT public:
PointTest();
private slots:
void applyTransformation(); void applyTransformation();
}; };

16
src/Physics/Test/ShapeGroupTest.cpp

@ -16,18 +16,22 @@
#include "ShapeGroupTest.h" #include "ShapeGroupTest.h"
#include <functional> #include <functional>
#include <QtTest/QTest>
#include "Physics/Point.h" #include "Physics/Point.h"
#include "Physics/Sphere.h" #include "Physics/Sphere.h"
#include "Physics/ShapeGroup.h" #include "Physics/ShapeGroup.h"
QTEST_APPLESS_MAIN(Magnum::Physics::Test::ShapeGroupTest)
using namespace std; using namespace std;
CORRADE_TEST_MAIN(Magnum::Physics::Test::ShapeGroupTest)
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
ShapeGroupTest::ShapeGroupTest() {
addTests(&ShapeGroupTest::copy,
&ShapeGroupTest::reference);
}
void ShapeGroupTest::copy() { void ShapeGroupTest::copy() {
ShapeGroup group; ShapeGroup group;
{ {
@ -39,6 +43,8 @@ void ShapeGroupTest::copy() {
/* Just to test that it doesn't crash */ /* Just to test that it doesn't crash */
group.applyTransformation(Matrix4::translation(Vector3::xAxis(1.0f))); group.applyTransformation(Matrix4::translation(Vector3::xAxis(1.0f)));
CORRADE_VERIFY(true);
} }
void ShapeGroupTest::reference() { void ShapeGroupTest::reference() {
@ -49,8 +55,8 @@ void ShapeGroupTest::reference() {
group.applyTransformation(Matrix4::translation(Vector3(1.0f))); group.applyTransformation(Matrix4::translation(Vector3(1.0f)));
QVERIFY((point.transformedPosition() == Vector3(2.0f, 3.0f, 4.0f))); CORRADE_VERIFY((point.transformedPosition() == Vector3(2.0f, 3.0f, 4.0f)));
QVERIFY((sphere.transformedPosition() == Vector3(3.0f, 2.0f, 31.0f))); CORRADE_VERIFY((sphere.transformedPosition() == Vector3(3.0f, 2.0f, 31.0f)));
} }
}}} }}}

8
src/Physics/Test/ShapeGroupTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class ShapeGroupTest: public QObject { class ShapeGroupTest: public Corrade::TestSuite::Tester<ShapeGroupTest> {
Q_OBJECT public:
ShapeGroupTest();
private slots:
void copy(); void copy();
void reference(); void reference();
}; };

23
src/Physics/Test/SphereTest.cpp

@ -15,30 +15,35 @@
#include "SphereTest.h" #include "SphereTest.h"
#include <QtTest/QTest>
#include "Utility/Debug.h"
#include "Physics/Sphere.h" #include "Physics/Sphere.h"
QTEST_APPLESS_MAIN(Magnum::Physics::Test::SphereTest) CORRADE_TEST_MAIN(Magnum::Physics::Test::SphereTest)
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
SphereTest::SphereTest() {
addTests(&SphereTest::applyTransformation,
&SphereTest::collisionPoint,
&SphereTest::collisionLine,
&SphereTest::collisionLineSegment,
&SphereTest::collisionSphere);
}
void SphereTest::applyTransformation() { void SphereTest::applyTransformation() {
Physics::Sphere sphere({1.0f, 2.0f, 3.0f}, 7.0f); Physics::Sphere sphere({1.0f, 2.0f, 3.0f}, 7.0f);
sphere.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::yAxis())); sphere.applyTransformation(Matrix4::rotation(deg(90.0f), Vector3::yAxis()));
QVERIFY((sphere.transformedPosition() == Vector3(3.0f, 2.0f, -1.0f))); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(3.0f, 2.0f, -1.0f));
QCOMPARE(sphere.transformedRadius(), 7.0f); CORRADE_COMPARE(sphere.transformedRadius(), 7.0f);
/* Symmetric scaling */ /* Symmetric scaling */
sphere.applyTransformation(Matrix4::scaling(Vector3(2.0f))); sphere.applyTransformation(Matrix4::scaling(Vector3(2.0f)));
QVERIFY((sphere.transformedPosition() == Vector3(2.0f, 4.0f, 6.0f))); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(2.0f, 4.0f, 6.0f));
QCOMPARE(sphere.transformedRadius(), 14.0f); CORRADE_COMPARE(sphere.transformedRadius(), 14.0f);
/* Apply average scaling to radius */ /* Apply average scaling to radius */
sphere.applyTransformation(Matrix4::scaling({Math::Constants<GLfloat>::sqrt3(), -Math::Constants<GLfloat>::sqrt2(), 2.0f})); sphere.applyTransformation(Matrix4::scaling({Math::Constants<GLfloat>::sqrt3(), -Math::Constants<GLfloat>::sqrt2(), 2.0f}));
QCOMPARE(sphere.transformedRadius(), Math::Constants<GLfloat>::sqrt3()*7.0f); CORRADE_COMPARE(sphere.transformedRadius(), Math::Constants<GLfloat>::sqrt3()*7.0f);
} }
void SphereTest::collisionPoint() { void SphereTest::collisionPoint() {

6
src/Physics/Test/SphereTest.h

@ -19,10 +19,10 @@
namespace Magnum { namespace Physics { namespace Test { namespace Magnum { namespace Physics { namespace Test {
class SphereTest: public AbstractShapeTest { class SphereTest: public Corrade::TestSuite::Tester<SphereTest>, AbstractShapeTest {
Q_OBJECT public:
SphereTest();
private slots:
void applyTransformation(); void applyTransformation();
void collisionPoint(); void collisionPoint();
void collisionLine(); void collisionLine();

4
src/Primitives/Test/CMakeLists.txt

@ -1,2 +1,2 @@
corrade_add_test(PrimitivesCapsuleTest CapsuleTest.h CapsuleTest.cpp MagnumPrimitives) corrade_add_test2(PrimitivesCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPrimitives)
corrade_add_test(PrimitivesUVSphereTest UVSphereTest.h UVSphereTest.cpp MagnumPrimitives) corrade_add_test2(PrimitivesUVSphereTest UVSphereTest.cpp LIBRARIES MagnumPrimitives)

23
src/Primitives/Test/CapsuleTest.cpp

@ -18,20 +18,23 @@
#include "CapsuleTest.h" #include "CapsuleTest.h"
#include <QtTest/QTest>
QTEST_APPLESS_MAIN(Magnum::Primitives::Test::CapsuleTest)
#include "Primitives/Capsule.h" #include "Primitives/Capsule.h"
using namespace std; using namespace std;
CORRADE_TEST_MAIN(Magnum::Primitives::Test::CapsuleTest)
namespace Magnum { namespace Primitives { namespace Test { namespace Magnum { namespace Primitives { namespace Test {
CapsuleTest::CapsuleTest() {
addTests(&CapsuleTest::withoutTextureCoords,
&CapsuleTest::withTextureCoords);
}
void CapsuleTest::withoutTextureCoords() { void CapsuleTest::withoutTextureCoords() {
Capsule capsule(2, 3, 1.0f); Capsule capsule(2, 3, 1.0f);
QVERIFY((*capsule.vertices(0) == vector<Vector4>{ CORRADE_COMPARE(*capsule.vertices(0), (vector<Vector4>{
Vector4(0.0f, -1.5f, 0.0f), Vector4(0.0f, -1.5f, 0.0f),
Vector4(0.0f, -1.20711f, 0.707107f), Vector4(0.0f, -1.20711f, 0.707107f),
@ -53,7 +56,7 @@ void CapsuleTest::withoutTextureCoords() {
Vector4(0.0f, 1.5f, 0.0f) Vector4(0.0f, 1.5f, 0.0f)
})); }));
QVERIFY((*capsule.normals(0) == vector<Vector3>{ CORRADE_COMPARE(*capsule.normals(0), (vector<Vector3>{
Vector3(0.0f, -1.0f, 0.0f), Vector3(0.0f, -1.0f, 0.0f),
Vector3(0.0f, -0.707107f, 0.707107f), Vector3(0.0f, -0.707107f, 0.707107f),
@ -75,7 +78,7 @@ void CapsuleTest::withoutTextureCoords() {
Vector3(0.0f, 1.0f, 0.0f) Vector3(0.0f, 1.0f, 0.0f)
})); }));
QVERIFY((*capsule.indices() == vector<unsigned int>{ CORRADE_COMPARE(*capsule.indices(), (vector<unsigned int>{
0, 2, 1, 0, 3, 2, 0, 1, 3, 0, 2, 1, 0, 3, 2, 0, 1, 3,
1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6,
4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9, 4, 5, 8, 4, 8, 7, 5, 6, 9, 5, 9, 8, 6, 4, 7, 6, 7, 9,
@ -87,7 +90,7 @@ void CapsuleTest::withoutTextureCoords() {
void CapsuleTest::withTextureCoords() { void CapsuleTest::withTextureCoords() {
Capsule capsule(2, 3, 1.0f, Capsule::TextureCoords::Generate); Capsule capsule(2, 3, 1.0f, Capsule::TextureCoords::Generate);
QVERIFY((*capsule.vertices(0) == vector<Vector4>{ CORRADE_COMPARE(*capsule.vertices(0), (vector<Vector4>{
Vector4(0.0f, -1.5f, 0.0f), Vector4(0.0f, -1.5f, 0.0f),
Vector4(0.0f, -1.20711f, 0.707107f), Vector4(0.0f, -1.20711f, 0.707107f),
@ -113,7 +116,7 @@ void CapsuleTest::withTextureCoords() {
Vector4(0.0f, 1.5f, 0.0f) Vector4(0.0f, 1.5f, 0.0f)
})); }));
QVERIFY((*capsule.textureCoords2D(0) == vector<Vector2>{ CORRADE_COMPARE(*capsule.textureCoords2D(0), (vector<Vector2>{
Vector2(0.5f, 0.0f), Vector2(0.5f, 0.0f),
Vector2(0.0f, 0.166667f), Vector2(0.0f, 0.166667f),
@ -139,7 +142,7 @@ void CapsuleTest::withTextureCoords() {
Vector2(0.5f, 1.0f) Vector2(0.5f, 1.0f)
})); }));
QVERIFY((*capsule.indices() == vector<unsigned int>{ CORRADE_COMPARE(*capsule.indices(), (vector<unsigned int>{
0, 2, 1, 0, 3, 2, 0, 4, 3, 0, 2, 1, 0, 3, 2, 0, 4, 3,
1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11, 5, 6, 10, 5, 10, 9, 6, 7, 11, 6, 11, 10, 7, 8, 12, 7, 12, 11,

8
src/Primitives/Test/CapsuleTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Primitives { namespace Test { namespace Magnum { namespace Primitives { namespace Test {
class CapsuleTest: public QObject { class CapsuleTest: public Corrade::TestSuite::Tester<CapsuleTest> {
Q_OBJECT public:
CapsuleTest();
private slots:
void withoutTextureCoords(); void withoutTextureCoords();
void withTextureCoords(); void withTextureCoords();
}; };

21
src/Primitives/Test/UVSphereTest.cpp

@ -15,20 +15,23 @@
#include "UVSphereTest.h" #include "UVSphereTest.h"
#include <QtTest/QTest>
#include "Primitives/UVSphere.h" #include "Primitives/UVSphere.h"
using namespace std; using namespace std;
QTEST_APPLESS_MAIN(Magnum::Primitives::Test::UVSphereTest) CORRADE_TEST_MAIN(Magnum::Primitives::Test::UVSphereTest)
namespace Magnum { namespace Primitives { namespace Test { namespace Magnum { namespace Primitives { namespace Test {
UVSphereTest::UVSphereTest() {
addTests(&UVSphereTest::withoutTextureCoords,
&UVSphereTest::withTextureCoords);
}
void UVSphereTest::withoutTextureCoords() { void UVSphereTest::withoutTextureCoords() {
UVSphere sphere(3, 3); UVSphere sphere(3, 3);
QVERIFY((*sphere.vertices(0) == vector<Vector4>{ CORRADE_COMPARE(*sphere.vertices(0), (vector<Vector4>{
Vector4(0.0f, -1.0f, 0.0f), Vector4(0.0f, -1.0f, 0.0f),
Vector4(0.0f, -0.5f, 0.866025f), Vector4(0.0f, -0.5f, 0.866025f),
@ -42,7 +45,7 @@ void UVSphereTest::withoutTextureCoords() {
Vector4(0.0f, 1.0f, 0.0f) Vector4(0.0f, 1.0f, 0.0f)
})); }));
QVERIFY((*sphere.normals(0) == vector<Vector3>{ CORRADE_COMPARE(*sphere.normals(0), (vector<Vector3>{
Vector3(0.0f, -1.0f, 0.0f), Vector3(0.0f, -1.0f, 0.0f),
Vector3(0.0f, -0.5f, 0.866025f), Vector3(0.0f, -0.5f, 0.866025f),
@ -56,7 +59,7 @@ void UVSphereTest::withoutTextureCoords() {
Vector3(0.0f, 1.0f, 0.0f) Vector3(0.0f, 1.0f, 0.0f)
})); }));
QVERIFY((*sphere.indices() == vector<unsigned int>{ CORRADE_COMPARE(*sphere.indices(), (vector<unsigned int>{
0, 2, 1, 0, 3, 2, 0, 1, 3, 0, 2, 1, 0, 3, 2, 0, 1, 3,
1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6, 1, 2, 5, 1, 5, 4, 2, 3, 6, 2, 6, 5, 3, 1, 4, 3, 4, 6,
4, 5, 7, 5, 6, 7, 6, 4, 7 4, 5, 7, 5, 6, 7, 6, 4, 7
@ -66,7 +69,7 @@ void UVSphereTest::withoutTextureCoords() {
void UVSphereTest::withTextureCoords() { void UVSphereTest::withTextureCoords() {
UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate); UVSphere sphere(3, 3, UVSphere::TextureCoords::Generate);
QVERIFY((*sphere.vertices(0) == vector<Vector4>{ CORRADE_COMPARE(*sphere.vertices(0), (vector<Vector4>{
Vector4(0.0f, -1.0f, 0.0f), Vector4(0.0f, -1.0f, 0.0f),
Vector4(0.0f, -0.5f, 0.866025f), Vector4(0.0f, -0.5f, 0.866025f),
@ -82,7 +85,7 @@ void UVSphereTest::withTextureCoords() {
Vector4(0.0f, 1.0f, 0.0f) Vector4(0.0f, 1.0f, 0.0f)
})); }));
QVERIFY((*sphere.textureCoords2D(0) == vector<Vector2>{ CORRADE_COMPARE(*sphere.textureCoords2D(0), (vector<Vector2>{
Vector2(0.5f, 0.0f), Vector2(0.5f, 0.0f),
Vector2(0.0f, 0.333333f), Vector2(0.0f, 0.333333f),
@ -98,7 +101,7 @@ void UVSphereTest::withTextureCoords() {
Vector2(0.5f, 1.0f) Vector2(0.5f, 1.0f)
})); }));
QVERIFY((*sphere.indices() == vector<unsigned int>{ CORRADE_COMPARE(*sphere.indices(), (vector<unsigned int>{
0, 2, 1, 0, 3, 2, 0, 4, 3, 0, 2, 1, 0, 3, 2, 0, 4, 3,
1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7, 1, 2, 6, 1, 6, 5, 2, 3, 7, 2, 7, 6, 3, 4, 8, 3, 8, 7,
5, 6, 9, 6, 7, 9, 7, 8, 9 5, 6, 9, 6, 7, 9, 7, 8, 9

8
src/Primitives/Test/UVSphereTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Primitives { namespace Test { namespace Magnum { namespace Primitives { namespace Test {
class UVSphereTest: public QObject { class UVSphereTest: public Corrade::TestSuite::Tester<UVSphereTest> {
Q_OBJECT public:
UVSphereTest();
private slots:
void withoutTextureCoords(); void withoutTextureCoords();
void withTextureCoords(); void withTextureCoords();
}; };

2
src/Shaders/PhongShader.cpp

@ -15,7 +15,7 @@
#include "PhongShader.h" #include "PhongShader.h"
#include "Utility/Resource.h" #include <Utility/Resource.h>
namespace Magnum { namespace Shaders { namespace Magnum { namespace Shaders {

6
src/Test/CMakeLists.txt

@ -1,3 +1,3 @@
corrade_add_test(ObjectTest ObjectTest.h ObjectTest.cpp MagnumTestLib) corrade_add_test2(ObjectTest ObjectTest.cpp LIBRARIES MagnumTestLib)
corrade_add_test(CameraTest CameraTest.h CameraTest.cpp Magnum) corrade_add_test2(CameraTest CameraTest.cpp LIBRARIES Magnum)
corrade_add_test(SceneTest SceneTest.h SceneTest.cpp Magnum) corrade_add_test2(SceneTest SceneTest.cpp LIBRARIES Magnum)

13
src/Test/CameraTest.cpp

@ -15,15 +15,18 @@
#include "CameraTest.h" #include "CameraTest.h"
#include <QtTest/QTest>
#include "Camera.h" #include "Camera.h"
#include "Scene.h" #include "Scene.h"
QTEST_APPLESS_MAIN(Magnum::Test::CameraTest) CORRADE_TEST_MAIN(Magnum::Test::CameraTest)
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
CameraTest::CameraTest() {
addTests(&CameraTest::orthographic,
&CameraTest::perspective);
}
void CameraTest::orthographic() { void CameraTest::orthographic() {
Camera camera; Camera camera;
camera.setOrthographic(5, 1, 9); camera.setOrthographic(5, 1, 9);
@ -33,7 +36,7 @@ void CameraTest::orthographic() {
0.0f, 0.0f, -0.25f, 0.0f, 0.0f, 0.0f, -0.25f, 0.0f,
0.0f, 0.0f, -1.25f, 1.0f); 0.0f, 0.0f, -1.25f, 1.0f);
QVERIFY(camera.projectionMatrix() == a); CORRADE_COMPARE(camera.projectionMatrix(), a);
} }
void CameraTest::perspective() { void CameraTest::perspective() {
@ -45,7 +48,7 @@ void CameraTest::perspective() {
0.0f, 0.0f, -1.9411764f, -1.0f, 0.0f, 0.0f, -1.9411764f, -1.0f,
0.0f, 0.0f, -94.1176452f, 0.0f); 0.0f, 0.0f, -94.1176452f, 0.0f);
QVERIFY(camera.projectionMatrix() == a); CORRADE_COMPARE(camera.projectionMatrix(), a);
} }
}} }}

8
src/Test/CameraTest.h

@ -15,14 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
class CameraTest: public QObject { class CameraTest: public Corrade::TestSuite::Tester<CameraTest> {
Q_OBJECT public:
CameraTest();
private slots:
void orthographic(); void orthographic();
void perspective(); void perspective();
}; };

112
src/Test/ObjectTest.cpp

@ -18,39 +18,47 @@
#include "Camera.h" #include "Camera.h"
#include <sstream> #include <sstream>
#include <QtTest/QTest>
using namespace std; using namespace std;
QTEST_APPLESS_MAIN(Magnum::Test::ObjectTest) CORRADE_TEST_MAIN(Magnum::Test::ObjectTest)
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
ObjectTest::ObjectTest() {
addTests(&ObjectTest::parenting,
&ObjectTest::transformation,
&ObjectTest::absoluteTransformationWrongCamera,
&ObjectTest::absoluteTransformation,
&ObjectTest::scene,
&ObjectTest::dirty);
}
void ObjectTest::parenting() { void ObjectTest::parenting() {
Object root; Object root;
Object* childOne = new Object(&root); Object* childOne = new Object(&root);
Object* childTwo = new Object(&root); Object* childTwo = new Object(&root);
QVERIFY(childOne->parent() == &root); CORRADE_VERIFY(childOne->parent() == &root);
QVERIFY(root.children().size() == 2); CORRADE_COMPARE(root.children().size(), 2);
/* A object cannot be parent of itself */ /* A object cannot be parent of itself */
childOne->setParent(childOne); childOne->setParent(childOne);
QVERIFY(childOne->parent() == &root); CORRADE_VERIFY(childOne->parent() == &root);
/* In fact, cyclic dependencies are not allowed at all */ /* In fact, cyclic dependencies are not allowed at all */
root.setParent(childTwo); root.setParent(childTwo);
QVERIFY(root.parent() == nullptr); CORRADE_VERIFY(root.parent() == nullptr);
/* Reparent to another */ /* Reparent to another */
childTwo->setParent(childOne); childTwo->setParent(childOne);
QVERIFY(root.children().size() == 1 && *root.children().begin() == childOne); CORRADE_VERIFY(root.children().size() == 1 && *root.children().begin() == childOne);
QVERIFY(childOne->children().size() == 1 && *childOne->children().begin() == childTwo); CORRADE_VERIFY(childOne->children().size() == 1 && *childOne->children().begin() == childTwo);
/* Delete child */ /* Delete child */
delete childTwo; delete childTwo;
QVERIFY(childOne->children().size() == 0); CORRADE_VERIFY(childOne->children().empty());
} }
void ObjectTest::transformation() { void ObjectTest::transformation() {
@ -62,16 +70,16 @@ void ObjectTest::transformation() {
o.multiplyTransformation(Matrix4::rotation(deg(35.0f), Vector3::zAxis())); o.multiplyTransformation(Matrix4::rotation(deg(35.0f), Vector3::zAxis()));
o2.rotate(deg(35.0f), Vector3::zAxis()); o2.rotate(deg(35.0f), Vector3::zAxis());
QVERIFY(o.transformation() == Matrix4::rotation(deg(35.0f), Vector3::zAxis())* CORRADE_COMPARE(o.transformation(), Matrix4::rotation(deg(35.0f), Vector3::zAxis())*
Matrix4::translation(Vector3::xAxis(1.0f))); Matrix4::translation(Vector3::xAxis(1.0f)));
QVERIFY(o2.transformation() == o.transformation()); CORRADE_COMPARE(o2.transformation(), o.transformation());
o.multiplyTransformation(Matrix4::scaling(Vector3(2.0f)), Object::Transformation::Local); o.multiplyTransformation(Matrix4::scaling(Vector3(2.0f)), Object::Transformation::Local);
o2.scale(Vector3(2.0f), Object::Transformation::Local); o2.scale(Vector3(2.0f), Object::Transformation::Local);
QVERIFY(o.transformation() == Matrix4::rotation(deg(35.0f), Vector3::zAxis())* CORRADE_COMPARE(o.transformation(), Matrix4::rotation(deg(35.0f), Vector3::zAxis())*
Matrix4::translation(Vector3::xAxis(1.0f))* Matrix4::translation(Vector3::xAxis(1.0f))*
Matrix4::scaling(Vector3(2.0f))); Matrix4::scaling(Vector3(2.0f)));
QVERIFY(o2.transformation() == o.transformation()); CORRADE_COMPARE(o2.transformation(), o.transformation());
} }
void ObjectTest::absoluteTransformationWrongCamera() { void ObjectTest::absoluteTransformationWrongCamera() {
@ -82,35 +90,35 @@ void ObjectTest::absoluteTransformationWrongCamera() {
Object o(&s); Object o(&s);
o.translate(Vector3::yAxis()); o.translate(Vector3::yAxis());
Camera c; Camera c;
QVERIFY(o.absoluteTransformation(&c) == Matrix4::translation(Vector3::yAxis())); CORRADE_COMPARE(o.absoluteTransformation(&c), Matrix4::translation(Vector3::yAxis()));
QVERIFY(ss.str() == "Object::absoluteTransformation(): the camera is not part of the same scene as object!\n"); CORRADE_COMPARE(ss.str(), "Object::absoluteTransformation(): the camera is not part of the same scene as object!\n");
ss.str(""); ss.str("");
Object o2; Object o2;
o2.translate(Vector3::xAxis()); o2.translate(Vector3::xAxis());
QVERIFY(o2.absoluteTransformation(&c) == Matrix4::translation(Vector3::xAxis())); CORRADE_COMPARE(o2.absoluteTransformation(&c), Matrix4::translation(Vector3::xAxis()));
QVERIFY(ss.str() == "Object::absoluteTransformation(): the object is not part of camera scene!\n"); CORRADE_COMPARE(ss.str(), "Object::absoluteTransformation(): the object is not part of camera scene!\n");
} }
void ObjectTest::absoluteTransformation() { void ObjectTest::absoluteTransformation() {
Scene s; Scene s;
Camera c(&s); Camera c(&s);
c.translate(Vector3::zAxis(2.0f)); c.translate(Vector3::zAxis(2.0f));
QVERIFY(s.absoluteTransformation() == Matrix4()); CORRADE_COMPARE(s.absoluteTransformation(), Matrix4());
QVERIFY(c.absoluteTransformation(&c) == Matrix4()); CORRADE_COMPARE(c.absoluteTransformation(&c), Matrix4());
Object o(&s); Object o(&s);
o.scale(Vector3(2.0f)); o.scale(Vector3(2.0f));
Object o2(&o); Object o2(&o);
o.rotate(deg(90.0f), Vector3::yAxis()); o.rotate(deg(90.0f), Vector3::yAxis());
QVERIFY((o2.absoluteTransformation() == CORRADE_COMPARE(o2.absoluteTransformation(),
Matrix4::scaling(Vector3(2.0f))*Matrix4::rotation(deg(90.0f), Vector3::yAxis()))); Matrix4::scaling(Vector3(2.0f))*Matrix4::rotation(deg(90.0f), Vector3::yAxis()));
QVERIFY((o2.absoluteTransformation(&c) == CORRADE_COMPARE(o2.absoluteTransformation(&c),
(Matrix4::translation(Vector3::zAxis(2.0f)).inverted())*Matrix4::scaling(Vector3(2.0f))*Matrix4::rotation(deg(90.0f), Vector3::yAxis()))); (Matrix4::translation(Vector3::zAxis(2.0f)).inverted())*Matrix4::scaling(Vector3(2.0f))*Matrix4::rotation(deg(90.0f), Vector3::yAxis()));
Object o3; Object o3;
o3.translate({1.0f, 2.0f, 3.0f}); o3.translate({1.0f, 2.0f, 3.0f});
QVERIFY(o3.absoluteTransformation() == Matrix4::translation({1.0f, 2.0f, 3.0f})); CORRADE_COMPARE(o3.absoluteTransformation(), Matrix4::translation({1.0f, 2.0f, 3.0f}));
} }
void ObjectTest::scene() { void ObjectTest::scene() {
@ -122,8 +130,8 @@ void ObjectTest::scene() {
Object orphan; Object orphan;
Object* childOfOrphan = new Object(&orphan); Object* childOfOrphan = new Object(&orphan);
QVERIFY(childTwo->scene() == &scene); CORRADE_VERIFY(childTwo->scene() == &scene);
QVERIFY(childOfOrphan->scene() == nullptr); CORRADE_VERIFY(childOfOrphan->scene() == nullptr);
} }
void ObjectTest::dirty() { void ObjectTest::dirty() {
@ -137,54 +145,54 @@ void ObjectTest::dirty() {
childThree->rotate(deg(90.0f), Vector3::yAxis()); childThree->rotate(deg(90.0f), Vector3::yAxis());
/* Object is dirty at the beginning */ /* Object is dirty at the beginning */
QVERIFY(scene.isDirty()); CORRADE_VERIFY(scene.isDirty());
QVERIFY(childOne->isDirty()); CORRADE_VERIFY(childOne->isDirty());
/* Clean the object and all its dirty parents (but not children) */ /* Clean the object and all its dirty parents (but not children) */
childOne->setClean(); childOne->setClean();
QVERIFY(childOne->cleanedAbsoluteTransformation == childOne->absoluteTransformation()); CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, childOne->absoluteTransformation());
QVERIFY(!scene.isDirty()); CORRADE_VERIFY(!scene.isDirty());
QVERIFY(!childOne->isDirty()); CORRADE_VERIFY(!childOne->isDirty());
QVERIFY(childTwo->isDirty()); CORRADE_VERIFY(childTwo->isDirty());
QVERIFY(childThree->isDirty()); CORRADE_VERIFY(childThree->isDirty());
/* If the object itself is already clean, it shouldn't clean it again */ /* If the object itself is already clean, it shouldn't clean it again */
childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero); childOne->cleanedAbsoluteTransformation = Matrix4(Matrix4::Zero);
childOne->setClean(); childOne->setClean();
QVERIFY(childOne->cleanedAbsoluteTransformation == Matrix4(Matrix4::Zero)); CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
/* If any object in the hierarchy is already clean, it shouldn't clean it again */ /* If any object in the hierarchy is already clean, it shouldn't clean it again */
childTwo->setClean(); childTwo->setClean();
QVERIFY(childOne->cleanedAbsoluteTransformation == Matrix4(Matrix4::Zero)); CORRADE_COMPARE(childOne->cleanedAbsoluteTransformation, Matrix4(Matrix4::Zero));
QVERIFY(childTwo->cleanedAbsoluteTransformation == childTwo->absoluteTransformation()); CORRADE_COMPARE(childTwo->cleanedAbsoluteTransformation, childTwo->absoluteTransformation());
QVERIFY(!childOne->isDirty()); CORRADE_VERIFY(!childOne->isDirty());
QVERIFY(!childTwo->isDirty()); CORRADE_VERIFY(!childTwo->isDirty());
QVERIFY(childThree->isDirty()); CORRADE_VERIFY(childThree->isDirty());
/* Mark object and all its children as dirty (but not parents) */ /* Mark object and all its children as dirty (but not parents) */
childTwo->setDirty(); childTwo->setDirty();
QVERIFY(!scene.isDirty()); CORRADE_VERIFY(!scene.isDirty());
QVERIFY(!childOne->isDirty()); CORRADE_VERIFY(!childOne->isDirty());
QVERIFY(childTwo->isDirty()); CORRADE_VERIFY(childTwo->isDirty());
QVERIFY(childThree->isDirty()); CORRADE_VERIFY(childThree->isDirty());
/* Reparent object => make it and its children dirty (but not parents) */ /* Reparent object => make it and its children dirty (but not parents) */
childThree->setClean(); childThree->setClean();
QVERIFY(childThree->cleanedAbsoluteTransformation == childThree->absoluteTransformation()); CORRADE_COMPARE(childThree->cleanedAbsoluteTransformation, childThree->absoluteTransformation());
childTwo->setParent(nullptr); childTwo->setParent(nullptr);
QVERIFY(childTwo->isDirty()); CORRADE_VERIFY(childTwo->isDirty());
QVERIFY(!childOne->isDirty()); CORRADE_VERIFY(!childOne->isDirty());
childTwo->setParent(&scene); childTwo->setParent(&scene);
QVERIFY(!scene.isDirty()); CORRADE_VERIFY(!scene.isDirty());
QVERIFY(childTwo->isDirty()); CORRADE_VERIFY(childTwo->isDirty());
QVERIFY(childThree->isDirty()); CORRADE_VERIFY(childThree->isDirty());
/* Set object transformation => make it and its children dirty (but not parents) */ /* Set object transformation => make it and its children dirty (but not parents) */
childThree->setClean(); childThree->setClean();
childTwo->setTransformation(Matrix4::translation(Vector3::xAxis(1.0f))); childTwo->setTransformation(Matrix4::translation(Vector3::xAxis(1.0f)));
QVERIFY(!scene.isDirty()); CORRADE_VERIFY(!scene.isDirty());
QVERIFY(childTwo->isDirty()); CORRADE_VERIFY(childTwo->isDirty());
QVERIFY(childThree->isDirty()); CORRADE_VERIFY(childThree->isDirty());
} }
}} }}

8
src/Test/ObjectTest.h

@ -15,16 +15,16 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
#include "Object.h" #include "Object.h"
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
class ObjectTest: public QObject { class ObjectTest: public Corrade::TestSuite::Tester<ObjectTest> {
Q_OBJECT public:
ObjectTest();
private slots:
void parenting(); void parenting();
void transformation(); void transformation();
void absoluteTransformationWrongCamera(); void absoluteTransformationWrongCamera();

19
src/Test/SceneTest.cpp

@ -15,34 +15,37 @@
#include "SceneTest.h" #include "SceneTest.h"
#include <QtTest/QTest>
#include "Scene.h" #include "Scene.h"
QTEST_APPLESS_MAIN(Magnum::Test::SceneTest) CORRADE_TEST_MAIN(Magnum::Test::SceneTest)
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
SceneTest::SceneTest() {
addTests(&SceneTest::transformation,
&SceneTest::parent);
}
void SceneTest::transformation() { void SceneTest::transformation() {
Scene scene; Scene scene;
Object* scenePointer = &scene; Object* scenePointer = &scene;
scenePointer->setTransformation(Matrix4::translation({1.0f, 1.0f, 1.0f})); scenePointer->setTransformation(Matrix4::translation({1.0f, 1.0f, 1.0f}));
QVERIFY(scene.transformation() == Matrix4()); CORRADE_COMPARE(scene.transformation(), Matrix4());
} }
void SceneTest::parent() { void SceneTest::parent() {
Scene scene; Scene scene;
QVERIFY(scene.parent() == &scene); CORRADE_VERIFY(scene.parent() == &scene);
/* Scene parent cannot be changed */ /* Scene parent cannot be changed */
Object* scenePointer = &scene; Object* scenePointer = &scene;
Object object; Object object;
scenePointer->setParent(&object); scenePointer->setParent(&object);
QVERIFY(scene.parent() == &scene); CORRADE_VERIFY(scene.parent() == &scene);
QVERIFY(scene.children().empty()); CORRADE_VERIFY(scene.children().empty());
QVERIFY(object.children().empty()); CORRADE_VERIFY(object.children().empty());
} }
}} }}

10
src/Test/SceneTest.h

@ -15,16 +15,14 @@
GNU Lesser General Public License version 3 for more details. GNU Lesser General Public License version 3 for more details.
*/ */
#include <QtCore/QObject> #include <TestSuite/Tester.h>
#include "Object.h"
namespace Magnum { namespace Test { namespace Magnum { namespace Test {
class SceneTest: public QObject { class SceneTest: public Corrade::TestSuite::Tester<SceneTest> {
Q_OBJECT public:
SceneTest();
private slots:
void transformation(); void transformation();
void parent(); void parent();
}; };

3
src/Trade/AbstractImporter.h

@ -19,7 +19,8 @@
* @brief Class Magnum::Trade::AbstractImporter * @brief Class Magnum::Trade::AbstractImporter
*/ */
#include "PluginManager/Plugin.h" #include <PluginManager/Plugin.h>
#include "ImageData.h" #include "ImageData.h"
#include "Set.h" #include "Set.h"

Loading…
Cancel
Save