Browse Source

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.
pull/175/merge
Vladimír Vondruš 10 years ago
parent
commit
d58d26aeff
  1. 1
      CMakeLists.txt
  2. 10
      doc/building.dox
  3. 52
      src/Magnum/Audio/Test/BufferALTest.cpp
  4. 12
      src/Magnum/Audio/Test/BufferTest.cpp
  5. 13
      src/Magnum/Audio/Test/CMakeLists.txt
  6. 60
      src/Magnum/Audio/Test/ContextALTest.cpp
  7. 21
      src/Magnum/Audio/Test/ContextTest.cpp
  8. 35
      src/Magnum/Audio/Test/ListenerALTest.cpp
  9. 27
      src/Magnum/Audio/Test/PlayableALTest.cpp
  10. 110
      src/Magnum/Audio/Test/RendererALTest.cpp
  11. 71
      src/Magnum/Audio/Test/RendererTest.cpp
  12. 173
      src/Magnum/Audio/Test/SourceALTest.cpp
  13. 126
      src/Magnum/Audio/Test/SourceTest.cpp

1
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_PLUGINS_STATIC "Build static plugins (default are dynamic)" OFF)
option(BUILD_TESTS "Build unit tests" 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_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) if(BUILD_TESTS)
find_package(Corrade REQUIRED TestSuite) find_package(Corrade REQUIRED TestSuite)
if(CORRADE_TARGET_IOS) if(CORRADE_TARGET_IOS)

10
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 with DLLs accessible through `PATH`. See
@ref building-windows "above Windows documentation" for more information. @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 which have windowless GL context creation implemented (currently all
platforms except @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten", platforms except @ref CORRADE_TARGET_EMSCRIPTEN "Emscripten",
@ref CORRADE_TARGET_NACL "NaCl", @ref CORRADE_TARGET_WINDOWS_RT "Windows RT" @ref CORRADE_TARGET_NACL "NaCl", @ref CORRADE_TARGET_WINDOWS_RT "Windows RT"

52
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š <mosra@centrum.cz>
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 <Corrade/TestSuite/Tester.h>
#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)

12
src/Magnum/Audio/Test/BufferTest.cpp

@ -27,27 +27,17 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include "Magnum/Audio/Buffer.h" #include "Magnum/Audio/Buffer.h"
#include "Magnum/Audio/Context.h"
namespace Magnum { namespace Audio { namespace Test { namespace Magnum { namespace Audio { namespace Test {
struct BufferTest: TestSuite::Tester { struct BufferTest: TestSuite::Tester {
explicit BufferTest(); explicit BufferTest();
void construct();
void debugFormat(); void debugFormat();
Context _context;
}; };
BufferTest::BufferTest() { BufferTest::BufferTest() {
addTests({&BufferTest::construct, addTests({&BufferTest::debugFormat});
&BufferTest::debugFormat});
}
void BufferTest::construct() {
Buffer buf;
CORRADE_VERIFY(buf.id() != 0);
} }
void BufferTest::debugFormat() { void BufferTest::debugFormat() {

13
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(AudioRendererTest RendererTest.cpp LIBRARIES MagnumAudio)
corrade_add_test(AudioSourceTest SourceTest.cpp LIBRARIES MagnumAudio) corrade_add_test(AudioSourceTest SourceTest.cpp LIBRARIES MagnumAudio)
if(WITH_SCENEGRAPH) if(BUILD_AL_TESTS)
corrade_add_test(AudioListenerTest ListenerTest.cpp LIBRARIES MagnumSceneGraph MagnumAudio) corrade_add_test(AudioBufferALTest BufferALTest.cpp LIBRARIES MagnumAudio)
corrade_add_test(AudioPlayableTest PlayableTest.cpp LIBRARIES MagnumSceneGraph 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() endif()
if(CORRADE_TARGET_EMSCRIPTEN) if(CORRADE_TARGET_EMSCRIPTEN)

60
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š <mosra@centrum.cz>
Copyright © 2015 Jonathan Hale <squareys@googlemail.com>
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 <Corrade/TestSuite/Tester.h>
#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<std::string> extensions = _context.extensionStrings();
CORRADE_VERIFY(extensions.size() > 0);
}
void ContextALTest::isExtensionEnabled() {
CORRADE_VERIFY(Context::current().isExtensionSupported<Extensions::ALC::EXT::ENUMERATION>());
}
}}}
CORRADE_TEST_MAIN(Magnum::Audio::Test::ContextALTest)

21
src/Magnum/Audio/Test/ContextTest.cpp

@ -27,7 +27,6 @@
#include <sstream> #include <sstream>
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include "Magnum/Audio/Extensions.h"
#include "Magnum/Audio/Context.h" #include "Magnum/Audio/Context.h"
namespace Magnum { namespace Audio { namespace Test { namespace Magnum { namespace Audio { namespace Test {
@ -35,29 +34,11 @@ namespace Magnum { namespace Audio { namespace Test {
struct ContextTest: TestSuite::Tester { struct ContextTest: TestSuite::Tester {
explicit ContextTest(); explicit ContextTest();
void extensionsString();
void isExtensionEnabled();
void debugHrtfStatus(); void debugHrtfStatus();
Context _context;
}; };
ContextTest::ContextTest() { ContextTest::ContextTest() {
addTests({&ContextTest::extensionsString, addTests({&ContextTest::debugHrtfStatus});
&ContextTest::isExtensionEnabled,
&ContextTest::debugHrtfStatus});
}
void ContextTest::extensionsString() {
std::vector<std::string> extensions = _context.extensionStrings();
CORRADE_VERIFY(extensions.size() > 0);
}
void ContextTest::isExtensionEnabled() {
CORRADE_VERIFY(Context::current().isExtensionSupported<Extensions::ALC::EXT::ENUMERATION>());
} }
void ContextTest::debugHrtfStatus() { void ContextTest::debugHrtfStatus() {

35
src/Magnum/Audio/Test/ListenerTest.cpp → src/Magnum/Audio/Test/ListenerALTest.cpp

@ -26,15 +26,14 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Magnum/SceneGraph/Scene.h>
#include <Magnum/SceneGraph/Object.h>
#include <Magnum/SceneGraph/MatrixTransformation2D.h>
#include <Magnum/SceneGraph/MatrixTransformation3D.h>
#include "Magnum/Audio/Playable.h" #include "Magnum/Audio/Playable.h"
#include "Magnum/Audio/Context.h" #include "Magnum/Audio/Context.h"
#include "Magnum/Audio/Listener.h" #include "Magnum/Audio/Listener.h"
#include "Magnum/Audio/PlayableGroup.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 { namespace Magnum { namespace Audio { namespace Test {
@ -44,23 +43,23 @@ typedef SceneGraph::Object<SceneGraph::MatrixTransformation2D> Object2D;
typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D> Scene3D; typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D> Scene3D;
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D; typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D;
struct ListenerTest: TestSuite::Tester { struct ListenerALTest: TestSuite::Tester {
explicit ListenerTest(); explicit ListenerALTest();
void testFeature2D(); void feature2D();
void testFeature3D(); void feature3D();
void testUpdateGroups(); void updateGroups();
Context _context; Context _context;
}; };
ListenerTest::ListenerTest(): _context() { ListenerALTest::ListenerALTest() {
addTests({&ListenerTest::testFeature2D, addTests({&ListenerALTest::feature2D,
&ListenerTest::testFeature3D, &ListenerALTest::feature3D,
&ListenerTest::testUpdateGroups}); &ListenerALTest::updateGroups});
} }
void ListenerTest::testFeature2D() { void ListenerALTest::feature2D() {
Scene2D scene; Scene2D scene;
Object2D object{&scene}; Object2D object{&scene};
Listener2D listener{object}; Listener2D listener{object};
@ -72,7 +71,7 @@ void ListenerTest::testFeature2D() {
CORRADE_COMPARE(Renderer::listenerPosition(), offset); CORRADE_COMPARE(Renderer::listenerPosition(), offset);
} }
void ListenerTest::testFeature3D() { void ListenerALTest::feature3D() {
Scene3D scene; Scene3D scene;
Object3D object{&scene}; Object3D object{&scene};
Listener3D listener{object}; Listener3D listener{object};
@ -84,7 +83,7 @@ void ListenerTest::testFeature3D() {
CORRADE_COMPARE(Renderer::listenerPosition(), offset); CORRADE_COMPARE(Renderer::listenerPosition(), offset);
} }
void ListenerTest::testUpdateGroups() { void ListenerALTest::updateGroups() {
Scene3D scene; Scene3D scene;
Object3D sourceObject{&scene}; Object3D sourceObject{&scene};
Object3D object{&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)

27
src/Magnum/Audio/Test/PlayableTest.cpp → src/Magnum/Audio/Test/PlayableALTest.cpp

@ -26,33 +26,32 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include <Magnum/SceneGraph/Scene.h>
#include <Magnum/SceneGraph/Object.h>
#include <Magnum/SceneGraph/MatrixTransformation3D.h>
#include "Magnum/Audio/Context.h" #include "Magnum/Audio/Context.h"
#include "Magnum/Audio/Playable.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 { namespace Magnum { namespace Audio { namespace Test {
typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D> Scene3D; typedef SceneGraph::Scene<SceneGraph::MatrixTransformation3D> Scene3D;
typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D; typedef SceneGraph::Object<SceneGraph::MatrixTransformation3D> Object3D;
struct PlayableTest: TestSuite::Tester { struct PlayableALTest: TestSuite::Tester {
explicit PlayableTest(); explicit PlayableALTest();
void testFeature(); void feature();
void testGroup(); void group();
Context _context; Context _context;
}; };
PlayableTest::PlayableTest() { PlayableALTest::PlayableALTest() {
addTests({&PlayableTest::testFeature, addTests({&PlayableALTest::feature,
&PlayableTest::testGroup}); &PlayableALTest::group});
} }
void PlayableTest::testFeature() { void PlayableALTest::feature() {
Scene3D scene; Scene3D scene;
Object3D object{&scene}; Object3D object{&scene};
Source source; Source source;
@ -65,7 +64,7 @@ void PlayableTest::testFeature() {
CORRADE_COMPARE(playable.source().position(), offset); CORRADE_COMPARE(playable.source().position(), offset);
} }
void PlayableTest::testGroup() { void PlayableALTest::group() {
Scene3D scene; Scene3D scene;
Object3D object{&scene}; Object3D object{&scene};
Source source; Source source;
@ -94,4 +93,4 @@ void PlayableTest::testGroup() {
}}} }}}
CORRADE_TEST_MAIN(Magnum::Audio::Test::PlayableTest) CORRADE_TEST_MAIN(Magnum::Audio::Test::PlayableALTest)

110
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š <mosra@centrum.cz>
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 <Corrade/TestSuite/Tester.h>
#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<Vector3, 2> 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)

71
src/Magnum/Audio/Test/RendererTest.cpp

@ -27,91 +27,22 @@
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include "Magnum/Magnum.h" #include "Magnum/Magnum.h"
#include "Magnum/Audio/Context.h"
#include "Magnum/Audio/Renderer.h" #include "Magnum/Audio/Renderer.h"
namespace Magnum { namespace Audio { namespace Test { namespace Magnum { namespace Audio { namespace Test {
struct RendererTest: TestSuite::Tester { struct RendererTest: TestSuite::Tester {
explicit RendererTest(); explicit RendererTest();
void listenerOrientation();
void listenerPosition();
void listenerVelocity();
void listenerGain();
void speedOfSound();
void dopplerFactor();
void distanceModel();
void debugError(); void debugError();
void debugDistanceModel(); void debugDistanceModel();
Context _context;
}; };
RendererTest::RendererTest() { RendererTest::RendererTest() {
addTests({&RendererTest::listenerOrientation, addTests({&RendererTest::debugError,
&RendererTest::listenerPosition,
&RendererTest::listenerVelocity,
&RendererTest::listenerGain,
&RendererTest::speedOfSound,
&RendererTest::dopplerFactor,
&RendererTest::distanceModel,
&RendererTest::debugError,
&RendererTest::debugDistanceModel}); &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<Vector3, 2> 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() { void RendererTest::debugError() {
std::ostringstream out; std::ostringstream out;
Debug(&out) << Renderer::Error::InvalidOperation << Renderer::Error(0xdead); Debug(&out) << Renderer::Error::InvalidOperation << Renderer::Error(0xdead);

173
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š <mosra@centrum.cz>
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 <Corrade/TestSuite/Tester.h>
#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)

126
src/Magnum/Audio/Test/SourceTest.cpp

@ -26,7 +26,6 @@
#include <sstream> #include <sstream>
#include <Corrade/TestSuite/Tester.h> #include <Corrade/TestSuite/Tester.h>
#include "Magnum/Audio/Context.h"
#include "Magnum/Audio/Source.h" #include "Magnum/Audio/Source.h"
namespace Magnum { namespace Audio { namespace Test { namespace Magnum { namespace Audio { namespace Test {
@ -34,134 +33,11 @@ namespace Magnum { namespace Audio { namespace Test {
struct SourceTest: TestSuite::Tester { struct SourceTest: TestSuite::Tester {
explicit SourceTest(); 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(); void debugState();
Context _context;
}; };
SourceTest::SourceTest() { SourceTest::SourceTest() {
addTests({&SourceTest::position, addTests({&SourceTest::debugState});
&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);
} }
void SourceTest::debugState() { void SourceTest::debugState() {

Loading…
Cancel
Save