From d58d26aefffc88c29bd4cdec02dbb0498a1f0606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Sun, 4 Sep 2016 18:23:23 +0200 Subject: [PATCH] Audio: ability to run tests requiring OpenAL context separately. Added a new enabled-by-default BUILD_AL_TESTS CMake option. The test cases that actually require OpenAL context were split to new tests with `*ALTest` suffix so they can be executed selectively. --- CMakeLists.txt | 1 + doc/building.dox | 10 + src/Magnum/Audio/Test/BufferALTest.cpp | 52 ++++++ src/Magnum/Audio/Test/BufferTest.cpp | 12 +- src/Magnum/Audio/Test/CMakeLists.txt | 13 +- src/Magnum/Audio/Test/ContextALTest.cpp | 60 ++++++ src/Magnum/Audio/Test/ContextTest.cpp | 21 +-- .../{ListenerTest.cpp => ListenerALTest.cpp} | 35 ++-- .../{PlayableTest.cpp => PlayableALTest.cpp} | 27 ++- src/Magnum/Audio/Test/RendererALTest.cpp | 110 +++++++++++ src/Magnum/Audio/Test/RendererTest.cpp | 71 +------ src/Magnum/Audio/Test/SourceALTest.cpp | 173 ++++++++++++++++++ src/Magnum/Audio/Test/SourceTest.cpp | 126 +------------ 13 files changed, 450 insertions(+), 261 deletions(-) create mode 100644 src/Magnum/Audio/Test/BufferALTest.cpp create mode 100644 src/Magnum/Audio/Test/ContextALTest.cpp rename src/Magnum/Audio/Test/{ListenerTest.cpp => ListenerALTest.cpp} (81%) rename src/Magnum/Audio/Test/{PlayableTest.cpp => PlayableALTest.cpp} (84%) create mode 100644 src/Magnum/Audio/Test/RendererALTest.cpp create mode 100644 src/Magnum/Audio/Test/SourceALTest.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f6433a857..e6cc02b4f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,6 +148,7 @@ option(BUILD_STATIC_PIC "Build static libraries and plugins with position-indepe option(BUILD_PLUGINS_STATIC "Build static plugins (default are dynamic)" OFF) option(BUILD_TESTS "Build unit tests" OFF) cmake_dependent_option(BUILD_GL_TESTS "Build unit tests for OpenGL code" OFF "BUILD_TESTS" OFF) +cmake_dependent_option(BUILD_AL_TESTS "Build unit tests for OpenAL code" ON "BUILD_TESTS" OFF) if(BUILD_TESTS) find_package(Corrade REQUIRED TestSuite) if(CORRADE_TARGET_IOS) diff --git a/doc/building.dox b/doc/building.dox index 158271a16..31f576d6b 100644 --- a/doc/building.dox +++ b/doc/building.dox @@ -282,6 +282,16 @@ in build directory. On Windows the tests require the library to be installed with DLLs accessible through `PATH`. See @ref building-windows "above Windows documentation" for more information. +The @ref Audio library has tests which require OpenAL to be able to create a +context. That is the case on most platforms, so they are enabled by default. +In case it's not possible to have OpenAL context (such as when running +@ref CORRADE_TARGET_EMSCRIPTEN "Emscripten" tests under Node.js), you can +disable building of them with `BUILD_AL_TESTS`. The tests are suffixed with +`ALTest` so they can be also selectively included/excluded when running CTest, +e.g.: + + ctest -E ALTest # run everything except tests requiring OpenAL context + Platforms which have windowless GL context creation implemented (currently all platforms except @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten", @ref CORRADE_TARGET_NACL "NaCl", @ref CORRADE_TARGET_WINDOWS_RT "Windows RT" diff --git a/src/Magnum/Audio/Test/BufferALTest.cpp b/src/Magnum/Audio/Test/BufferALTest.cpp new file mode 100644 index 000000000..298ae9c18 --- /dev/null +++ b/src/Magnum/Audio/Test/BufferALTest.cpp @@ -0,0 +1,52 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Audio/Buffer.h" +#include "Magnum/Audio/Context.h" + +namespace Magnum { namespace Audio { namespace Test { + +struct BufferALTest: TestSuite::Tester { + explicit BufferALTest(); + + void construct(); + + Context _context; +}; + +BufferALTest::BufferALTest() { + addTests({&BufferALTest::construct}); +} + +void BufferALTest::construct() { + Buffer buf; + CORRADE_VERIFY(buf.id() != 0); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Audio::Test::BufferALTest) diff --git a/src/Magnum/Audio/Test/BufferTest.cpp b/src/Magnum/Audio/Test/BufferTest.cpp index 1522d1558..76bb55625 100644 --- a/src/Magnum/Audio/Test/BufferTest.cpp +++ b/src/Magnum/Audio/Test/BufferTest.cpp @@ -27,27 +27,17 @@ #include #include "Magnum/Audio/Buffer.h" -#include "Magnum/Audio/Context.h" namespace Magnum { namespace Audio { namespace Test { struct BufferTest: TestSuite::Tester { explicit BufferTest(); - void construct(); void debugFormat(); - - Context _context; }; BufferTest::BufferTest() { - addTests({&BufferTest::construct, - &BufferTest::debugFormat}); -} - -void BufferTest::construct() { - Buffer buf; - CORRADE_VERIFY(buf.id() != 0); + addTests({&BufferTest::debugFormat}); } void BufferTest::debugFormat() { diff --git a/src/Magnum/Audio/Test/CMakeLists.txt b/src/Magnum/Audio/Test/CMakeLists.txt index 3b3ca4791..83a33b70f 100644 --- a/src/Magnum/Audio/Test/CMakeLists.txt +++ b/src/Magnum/Audio/Test/CMakeLists.txt @@ -40,9 +40,16 @@ corrade_add_test(AudioContextTest ContextTest.cpp LIBRARIES MagnumAudio) corrade_add_test(AudioRendererTest RendererTest.cpp LIBRARIES MagnumAudio) corrade_add_test(AudioSourceTest SourceTest.cpp LIBRARIES MagnumAudio) -if(WITH_SCENEGRAPH) - corrade_add_test(AudioListenerTest ListenerTest.cpp LIBRARIES MagnumSceneGraph MagnumAudio) - corrade_add_test(AudioPlayableTest PlayableTest.cpp LIBRARIES MagnumSceneGraph MagnumAudio) +if(BUILD_AL_TESTS) + corrade_add_test(AudioBufferALTest BufferALTest.cpp LIBRARIES MagnumAudio) + corrade_add_test(AudioContextALTest ContextALTest.cpp LIBRARIES MagnumAudio) + corrade_add_test(AudioRendererALTest RendererALTest.cpp LIBRARIES MagnumAudio) + corrade_add_test(AudioSourceALTest SourceALTest.cpp LIBRARIES MagnumAudio) + + if(WITH_SCENEGRAPH) + corrade_add_test(AudioListenerALTest ListenerALTest.cpp LIBRARIES MagnumSceneGraph MagnumAudio) + corrade_add_test(AudioPlayableALTest PlayableALTest.cpp LIBRARIES MagnumSceneGraph MagnumAudio) + endif() endif() if(CORRADE_TARGET_EMSCRIPTEN) diff --git a/src/Magnum/Audio/Test/ContextALTest.cpp b/src/Magnum/Audio/Test/ContextALTest.cpp new file mode 100644 index 000000000..095c8e3f8 --- /dev/null +++ b/src/Magnum/Audio/Test/ContextALTest.cpp @@ -0,0 +1,60 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + Copyright © 2015 Jonathan Hale + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Audio/Extensions.h" +#include "Magnum/Audio/Context.h" + +namespace Magnum { namespace Audio { namespace Test { + +struct ContextALTest: TestSuite::Tester { + explicit ContextALTest(); + + void extensionsString(); + void isExtensionEnabled(); + + Context _context; +}; + +ContextALTest::ContextALTest() { + addTests({&ContextALTest::extensionsString, + &ContextALTest::isExtensionEnabled}); +} + +void ContextALTest::extensionsString() { + std::vector extensions = _context.extensionStrings(); + + CORRADE_VERIFY(extensions.size() > 0); +} + +void ContextALTest::isExtensionEnabled() { + CORRADE_VERIFY(Context::current().isExtensionSupported()); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Audio::Test::ContextALTest) diff --git a/src/Magnum/Audio/Test/ContextTest.cpp b/src/Magnum/Audio/Test/ContextTest.cpp index 452ac51d8..5a0b1dbf5 100644 --- a/src/Magnum/Audio/Test/ContextTest.cpp +++ b/src/Magnum/Audio/Test/ContextTest.cpp @@ -27,7 +27,6 @@ #include #include -#include "Magnum/Audio/Extensions.h" #include "Magnum/Audio/Context.h" namespace Magnum { namespace Audio { namespace Test { @@ -35,29 +34,11 @@ namespace Magnum { namespace Audio { namespace Test { struct ContextTest: TestSuite::Tester { explicit ContextTest(); - void extensionsString(); - void isExtensionEnabled(); - void debugHrtfStatus(); - - Context _context; }; ContextTest::ContextTest() { - addTests({&ContextTest::extensionsString, - &ContextTest::isExtensionEnabled, - - &ContextTest::debugHrtfStatus}); -} - -void ContextTest::extensionsString() { - std::vector extensions = _context.extensionStrings(); - - CORRADE_VERIFY(extensions.size() > 0); -} - -void ContextTest::isExtensionEnabled() { - CORRADE_VERIFY(Context::current().isExtensionSupported()); + addTests({&ContextTest::debugHrtfStatus}); } void ContextTest::debugHrtfStatus() { diff --git a/src/Magnum/Audio/Test/ListenerTest.cpp b/src/Magnum/Audio/Test/ListenerALTest.cpp similarity index 81% rename from src/Magnum/Audio/Test/ListenerTest.cpp rename to src/Magnum/Audio/Test/ListenerALTest.cpp index 2e22aa32c..dea7ce4b2 100644 --- a/src/Magnum/Audio/Test/ListenerTest.cpp +++ b/src/Magnum/Audio/Test/ListenerALTest.cpp @@ -26,15 +26,14 @@ #include -#include -#include -#include -#include - #include "Magnum/Audio/Playable.h" #include "Magnum/Audio/Context.h" #include "Magnum/Audio/Listener.h" #include "Magnum/Audio/PlayableGroup.h" +#include "Magnum/SceneGraph/Scene.h" +#include "Magnum/SceneGraph/Object.h" +#include "Magnum/SceneGraph/MatrixTransformation2D.h" +#include "Magnum/SceneGraph/MatrixTransformation3D.h" namespace Magnum { namespace Audio { namespace Test { @@ -44,23 +43,23 @@ typedef SceneGraph::Object Object2D; typedef SceneGraph::Scene Scene3D; typedef SceneGraph::Object Object3D; -struct ListenerTest: TestSuite::Tester { - explicit ListenerTest(); +struct ListenerALTest: TestSuite::Tester { + explicit ListenerALTest(); - void testFeature2D(); - void testFeature3D(); - void testUpdateGroups(); + void feature2D(); + void feature3D(); + void updateGroups(); Context _context; }; -ListenerTest::ListenerTest(): _context() { - addTests({&ListenerTest::testFeature2D, - &ListenerTest::testFeature3D, - &ListenerTest::testUpdateGroups}); +ListenerALTest::ListenerALTest() { + addTests({&ListenerALTest::feature2D, + &ListenerALTest::feature3D, + &ListenerALTest::updateGroups}); } -void ListenerTest::testFeature2D() { +void ListenerALTest::feature2D() { Scene2D scene; Object2D object{&scene}; Listener2D listener{object}; @@ -72,7 +71,7 @@ void ListenerTest::testFeature2D() { CORRADE_COMPARE(Renderer::listenerPosition(), offset); } -void ListenerTest::testFeature3D() { +void ListenerALTest::feature3D() { Scene3D scene; Object3D object{&scene}; Listener3D listener{object}; @@ -84,7 +83,7 @@ void ListenerTest::testFeature3D() { CORRADE_COMPARE(Renderer::listenerPosition(), offset); } -void ListenerTest::testUpdateGroups() { +void ListenerALTest::updateGroups() { Scene3D scene; Object3D sourceObject{&scene}; Object3D object{&scene}; @@ -108,4 +107,4 @@ void ListenerTest::testUpdateGroups() { }}} -CORRADE_TEST_MAIN(Magnum::Audio::Test::ListenerTest) +CORRADE_TEST_MAIN(Magnum::Audio::Test::ListenerALTest) diff --git a/src/Magnum/Audio/Test/PlayableTest.cpp b/src/Magnum/Audio/Test/PlayableALTest.cpp similarity index 84% rename from src/Magnum/Audio/Test/PlayableTest.cpp rename to src/Magnum/Audio/Test/PlayableALTest.cpp index 3a185d18a..567b342cc 100644 --- a/src/Magnum/Audio/Test/PlayableTest.cpp +++ b/src/Magnum/Audio/Test/PlayableALTest.cpp @@ -26,33 +26,32 @@ #include -#include -#include -#include - #include "Magnum/Audio/Context.h" #include "Magnum/Audio/Playable.h" +#include "Magnum/SceneGraph/Scene.h" +#include "Magnum/SceneGraph/Object.h" +#include "Magnum/SceneGraph/MatrixTransformation3D.h" namespace Magnum { namespace Audio { namespace Test { typedef SceneGraph::Scene Scene3D; typedef SceneGraph::Object Object3D; -struct PlayableTest: TestSuite::Tester { - explicit PlayableTest(); +struct PlayableALTest: TestSuite::Tester { + explicit PlayableALTest(); - void testFeature(); - void testGroup(); + void feature(); + void group(); Context _context; }; -PlayableTest::PlayableTest() { - addTests({&PlayableTest::testFeature, - &PlayableTest::testGroup}); +PlayableALTest::PlayableALTest() { + addTests({&PlayableALTest::feature, + &PlayableALTest::group}); } -void PlayableTest::testFeature() { +void PlayableALTest::feature() { Scene3D scene; Object3D object{&scene}; Source source; @@ -65,7 +64,7 @@ void PlayableTest::testFeature() { CORRADE_COMPARE(playable.source().position(), offset); } -void PlayableTest::testGroup() { +void PlayableALTest::group() { Scene3D scene; Object3D object{&scene}; Source source; @@ -94,4 +93,4 @@ void PlayableTest::testGroup() { }}} -CORRADE_TEST_MAIN(Magnum::Audio::Test::PlayableTest) +CORRADE_TEST_MAIN(Magnum::Audio::Test::PlayableALTest) diff --git a/src/Magnum/Audio/Test/RendererALTest.cpp b/src/Magnum/Audio/Test/RendererALTest.cpp new file mode 100644 index 000000000..04671df93 --- /dev/null +++ b/src/Magnum/Audio/Test/RendererALTest.cpp @@ -0,0 +1,110 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Audio/Context.h" +#include "Magnum/Audio/Renderer.h" + +namespace Magnum { namespace Audio { namespace Test { + +struct RendererALTest: TestSuite::Tester { + explicit RendererALTest(); + + void listenerOrientation(); + void listenerPosition(); + void listenerVelocity(); + void listenerGain(); + void speedOfSound(); + void dopplerFactor(); + void distanceModel(); + + Context _context; +}; + +RendererALTest::RendererALTest() { + addTests({&RendererALTest::listenerOrientation, + &RendererALTest::listenerPosition, + &RendererALTest::listenerVelocity, + &RendererALTest::listenerGain, + &RendererALTest::speedOfSound, + &RendererALTest::dopplerFactor, + &RendererALTest::distanceModel}); +} + +void RendererALTest::listenerOrientation() { + constexpr Vector3 up{1.0f, 2.0f, 3.0f}, fwd{3.0f, 2.0f, 1.0f}; + Renderer::setListenerOrientation(fwd, up); + std::array orientation = Renderer::listenerOrientation(); + + CORRADE_COMPARE(orientation[0], fwd); + CORRADE_COMPARE(orientation[1], up); +} + +void RendererALTest::listenerPosition() { + constexpr Vector3 pos{1.0f, 3.0f, 2.0f}; + Renderer::setListenerPosition(pos); + + CORRADE_COMPARE(Renderer::listenerPosition(), pos); +} + +void RendererALTest::listenerVelocity() { + constexpr Vector3 vel{1.0f, 3.0f, 2.0f}; + Renderer::setListenerVelocity(vel); + + CORRADE_COMPARE(Renderer::listenerVelocity(), vel); +} + +void RendererALTest::listenerGain() { + constexpr Float gain = 0.512f; + Renderer::setListenerGain(gain); + + CORRADE_COMPARE(Renderer::listenerGain(), gain); +} + +void RendererALTest::speedOfSound() { + constexpr Float speed = 1.25f; + Renderer::setSpeedOfSound(speed); + + CORRADE_COMPARE(Renderer::speedOfSound(), speed); +} + +void RendererALTest::dopplerFactor() { + constexpr Float factor = 0.3335f; + Renderer::setDopplerFactor(factor); + + CORRADE_COMPARE(Renderer::dopplerFactor(), factor); +} + +void RendererALTest::distanceModel() { + constexpr Renderer::DistanceModel model = Renderer::DistanceModel::InverseClamped; + Renderer::setDistanceModel(model); + + CORRADE_COMPARE(Renderer::distanceModel(), model); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Audio::Test::RendererALTest) diff --git a/src/Magnum/Audio/Test/RendererTest.cpp b/src/Magnum/Audio/Test/RendererTest.cpp index 123e07371..ea6b7ef32 100644 --- a/src/Magnum/Audio/Test/RendererTest.cpp +++ b/src/Magnum/Audio/Test/RendererTest.cpp @@ -27,91 +27,22 @@ #include #include "Magnum/Magnum.h" -#include "Magnum/Audio/Context.h" #include "Magnum/Audio/Renderer.h" namespace Magnum { namespace Audio { namespace Test { struct RendererTest: TestSuite::Tester { explicit RendererTest(); - void listenerOrientation(); - void listenerPosition(); - void listenerVelocity(); - void listenerGain(); - void speedOfSound(); - void dopplerFactor(); - void distanceModel(); void debugError(); void debugDistanceModel(); - - Context _context; }; RendererTest::RendererTest() { - addTests({&RendererTest::listenerOrientation, - &RendererTest::listenerPosition, - &RendererTest::listenerVelocity, - &RendererTest::listenerGain, - &RendererTest::speedOfSound, - &RendererTest::dopplerFactor, - &RendererTest::distanceModel, - - &RendererTest::debugError, + addTests({&RendererTest::debugError, &RendererTest::debugDistanceModel}); } -void RendererTest::listenerOrientation() { - constexpr Vector3 up{1.0f, 2.0f, 3.0f}, fwd{3.0f, 2.0f, 1.0f}; - Renderer::setListenerOrientation(fwd, up); - std::array orientation = Renderer::listenerOrientation(); - - CORRADE_COMPARE(orientation[0], fwd); - CORRADE_COMPARE(orientation[1], up); -} - -void RendererTest::listenerPosition() { - constexpr Vector3 pos{1.0f, 3.0f, 2.0f}; - Renderer::setListenerPosition(pos); - - CORRADE_COMPARE(Renderer::listenerPosition(), pos); -} - -void RendererTest::listenerVelocity() { - constexpr Vector3 vel{1.0f, 3.0f, 2.0f}; - Renderer::setListenerVelocity(vel); - - CORRADE_COMPARE(Renderer::listenerVelocity(), vel); -} - -void RendererTest::listenerGain() { - constexpr Float gain = 0.512f; - Renderer::setListenerGain(gain); - - CORRADE_COMPARE(Renderer::listenerGain(), gain); -} - -void RendererTest::speedOfSound() { - constexpr Float speed = 1.25f; - Renderer::setSpeedOfSound(speed); - - CORRADE_COMPARE(Renderer::speedOfSound(), speed); -} - -void RendererTest::dopplerFactor() { - constexpr Float factor = 0.3335f; - Renderer::setDopplerFactor(factor); - - CORRADE_COMPARE(Renderer::dopplerFactor(), factor); -} - -void RendererTest::distanceModel() { - constexpr Renderer::DistanceModel model = Renderer::DistanceModel::InverseClamped; - Renderer::setDistanceModel(model); - - CORRADE_COMPARE(Renderer::distanceModel(), model); -} - void RendererTest::debugError() { std::ostringstream out; Debug(&out) << Renderer::Error::InvalidOperation << Renderer::Error(0xdead); diff --git a/src/Magnum/Audio/Test/SourceALTest.cpp b/src/Magnum/Audio/Test/SourceALTest.cpp new file mode 100644 index 000000000..7dfa190c8 --- /dev/null +++ b/src/Magnum/Audio/Test/SourceALTest.cpp @@ -0,0 +1,173 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include + +#include "Magnum/Audio/Context.h" +#include "Magnum/Audio/Source.h" + +namespace Magnum { namespace Audio { namespace Test { + +struct SourceALTest: TestSuite::Tester { + explicit SourceALTest(); + + void construct(); + + void position(); + void direction(); + void velocity(); + void gain(); + void looping(); + void relative(); + void maxDistance(); + void maxGain(); + void minGain(); + void coneAnglesAndGain(); + void rolloffFactor(); + + Context _context; +}; + +SourceALTest::SourceALTest() { + addTests({&SourceALTest::construct, + + &SourceALTest::position, + &SourceALTest::direction, + &SourceALTest::velocity, + &SourceALTest::gain, + &SourceALTest::looping, + &SourceALTest::relative, + &SourceALTest::maxDistance, + &SourceALTest::maxGain, + &SourceALTest::minGain, + &SourceALTest::coneAnglesAndGain, + &SourceALTest::rolloffFactor}); +} + +void SourceALTest::construct() { + Source source; + CORRADE_VERIFY(source.id() != 0); +} + +void SourceALTest::position() { + Source source; + constexpr Vector3 pos{3.0f, 5.0f, 6.0f}; + source.setPosition(pos); + + CORRADE_COMPARE(source.position(), pos); +} + +void SourceALTest::direction() { + Source source; + constexpr Vector3 dir{3.0f, 1.0f, 2.0f}; + source.setDirection(dir); + + CORRADE_COMPARE(source.direction(), dir); +} + +void SourceALTest::velocity() { + Source source; + constexpr Vector3 vel{-3.0f, 5.0f, -6.0f}; + source.setVelocity(vel); + + CORRADE_COMPARE(source.velocity(), vel); +} + +void SourceALTest::gain() { + Source source; + constexpr Float gain = 0.1234f; + source.setGain(gain); + + CORRADE_COMPARE(source.gain(), gain); +} + +void SourceALTest::looping() { + Source source; + source.setLooping(true); + CORRADE_VERIFY(source.isLooping()); + source.setLooping(false); + CORRADE_VERIFY(!source.isLooping()); +} + +void SourceALTest::relative() { + Source source; + source.setRelative(true); + CORRADE_VERIFY(source.isRelative()); + source.setRelative(false); + CORRADE_VERIFY(!source.isRelative()); +} + +void SourceALTest::maxDistance() { + Source source; + constexpr Float dist = 0.222f; + source.setMaxDistance(dist); + + CORRADE_COMPARE(source.maxDistance(), dist); +} + +void SourceALTest::maxGain() { + Source source; + constexpr Float gain = 0.3131f; + source.setMaxGain(gain); + + CORRADE_COMPARE(source.maxGain(), gain); +} + +void SourceALTest::minGain() { + Source source; + constexpr Float gain = 0.4144f; + source.setMinGain(gain); + + CORRADE_COMPARE(source.minGain(), gain); +} + +void SourceALTest::coneAnglesAndGain() { + using namespace Math::Literals; + + Source source; + constexpr auto outerAngle = 12.0_degf; + constexpr auto innerAngle = 21.0_degf; + constexpr Float outerGain = 0.05f; + + source.setInnerConeAngle(innerAngle); + source.setOuterConeAngle(outerAngle); + source.setOuterConeGain(outerGain); + + CORRADE_COMPARE(source.outerConeAngle(), outerAngle); + CORRADE_COMPARE(source.innerConeAngle(), innerAngle); + CORRADE_COMPARE(source.outerConeGain(), outerGain); +} + +void SourceALTest::rolloffFactor() { + Source source; + constexpr Float fact = 42.0f; + source.setRolloffFactor(fact); + + CORRADE_COMPARE(source.rolloffFactor(), fact); +} + +}}} + +CORRADE_TEST_MAIN(Magnum::Audio::Test::SourceALTest) diff --git a/src/Magnum/Audio/Test/SourceTest.cpp b/src/Magnum/Audio/Test/SourceTest.cpp index 7b8dbb033..521a04a3a 100644 --- a/src/Magnum/Audio/Test/SourceTest.cpp +++ b/src/Magnum/Audio/Test/SourceTest.cpp @@ -26,7 +26,6 @@ #include #include -#include "Magnum/Audio/Context.h" #include "Magnum/Audio/Source.h" namespace Magnum { namespace Audio { namespace Test { @@ -34,134 +33,11 @@ namespace Magnum { namespace Audio { namespace Test { struct SourceTest: TestSuite::Tester { explicit SourceTest(); - void position(); - void direction(); - void velocity(); - void gain(); - void looping(); - void relative(); - void maxDistance(); - void maxGain(); - void minGain(); - void coneAnglesAndGain(); - void rolloffFactor(); - void debugState(); - - Context _context; }; SourceTest::SourceTest() { - addTests({&SourceTest::position, - &SourceTest::direction, - &SourceTest::velocity, - &SourceTest::gain, - &SourceTest::looping, - &SourceTest::relative, - &SourceTest::maxDistance, - &SourceTest::maxGain, - &SourceTest::minGain, - &SourceTest::coneAnglesAndGain, - &SourceTest::rolloffFactor, - - &SourceTest::debugState}); -} - -void SourceTest::position() { - Source source; - constexpr Vector3 pos{3.0f, 5.0f, 6.0f}; - source.setPosition(pos); - - CORRADE_COMPARE(source.position(), pos); -} - -void SourceTest::direction() { - Source source; - constexpr Vector3 dir{3.0f, 1.0f, 2.0f}; - source.setDirection(dir); - - CORRADE_COMPARE(source.direction(), dir); -} - -void SourceTest::velocity() { - Source source; - constexpr Vector3 vel{-3.0f, 5.0f, -6.0f}; - source.setVelocity(vel); - - CORRADE_COMPARE(source.velocity(), vel); -} - -void SourceTest::gain() { - Source source; - constexpr Float gain = 0.1234f; - source.setGain(gain); - - CORRADE_COMPARE(source.gain(), gain); -} - -void SourceTest::looping() { - Source source; - source.setLooping(true); - CORRADE_VERIFY(source.isLooping()); - source.setLooping(false); - CORRADE_VERIFY(!source.isLooping()); -} - -void SourceTest::relative() { - Source source; - source.setRelative(true); - CORRADE_VERIFY(source.isRelative()); - source.setRelative(false); - CORRADE_VERIFY(!source.isRelative()); -} - -void SourceTest::maxDistance() { - Source source; - constexpr Float dist = 0.222f; - source.setMaxDistance(dist); - - CORRADE_COMPARE(source.maxDistance(), dist); -} - -void SourceTest::maxGain() { - Source source; - constexpr Float gain = 0.3131f; - source.setMaxGain(gain); - - CORRADE_COMPARE(source.maxGain(), gain); -} - -void SourceTest::minGain() { - Source source; - constexpr Float gain = 0.4144f; - source.setMinGain(gain); - - CORRADE_COMPARE(source.minGain(), gain); -} - -void SourceTest::coneAnglesAndGain() { - using namespace Math::Literals; - - Source source; - constexpr auto outerAngle = 12.0_degf; - constexpr auto innerAngle = 21.0_degf; - constexpr Float outerGain = 0.05f; - - source.setInnerConeAngle(innerAngle); - source.setOuterConeAngle(outerAngle); - source.setOuterConeGain(outerGain); - - CORRADE_COMPARE(source.outerConeAngle(), outerAngle); - CORRADE_COMPARE(source.innerConeAngle(), innerAngle); - CORRADE_COMPARE(source.outerConeGain(), outerGain); -} - -void SourceTest::rolloffFactor() { - Source source; - constexpr Float fact = 42.0f; - source.setRolloffFactor(fact); - - CORRADE_COMPARE(source.rolloffFactor(), fact); + addTests({&SourceTest::debugState}); } void SourceTest::debugState() {