From ff490bb3fa3da97ef918e7e13192864508eefd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 6 Apr 2015 01:13:02 +0200 Subject: [PATCH] Add test for file-local ResourceManager instance. To ensure that I didn't accidentaly break anything (linker errors etc.). --- src/Magnum/Test/CMakeLists.txt | 7 +++ .../Test/ResourceManagerLocalInstanceTest.cpp | 54 +++++++++++++++++++ .../ResourceManagerLocalInstanceTestLib.cpp | 43 +++++++++++++++ .../ResourceManagerLocalInstanceTestLib.h | 48 +++++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 src/Magnum/Test/ResourceManagerLocalInstanceTest.cpp create mode 100644 src/Magnum/Test/ResourceManagerLocalInstanceTestLib.cpp create mode 100644 src/Magnum/Test/ResourceManagerLocalInstanceTestLib.h diff --git a/src/Magnum/Test/CMakeLists.txt b/src/Magnum/Test/CMakeLists.txt index 3938ce13f..95db37ec4 100644 --- a/src/Magnum/Test/CMakeLists.txt +++ b/src/Magnum/Test/CMakeLists.txt @@ -40,6 +40,13 @@ corrade_add_test(SamplerTest SamplerTest.cpp LIBRARIES Magnum) corrade_add_test(ShaderTest ShaderTest.cpp LIBRARIES Magnum) corrade_add_test(VersionTest VersionTest.cpp LIBRARIES Magnum) +add_library(ResourceManagerLocalInstanceTestLib ${SHARED_OR_STATIC} ResourceManagerLocalInstanceTestLib.cpp) +target_link_libraries(ResourceManagerLocalInstanceTestLib Magnum) +if(NOT BUILD_STATIC) + set_target_properties(ResourceManagerLocalInstanceTestLib PROPERTIES COMPILE_FLAGS "-DResourceManagerLocalInstanceTestLib_EXPORTS") +endif() +corrade_add_test(ResourceManagerLocalInstanceTest ResourceManagerLocalInstanceTest.cpp LIBRARIES Magnum ResourceManagerLocalInstanceTestLib) + if(BUILD_GL_TESTS) corrade_add_test(AbstractObjectGLTest AbstractObjectGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES}) corrade_add_test(AbstractQueryGLTest AbstractQueryGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES}) diff --git a/src/Magnum/Test/ResourceManagerLocalInstanceTest.cpp b/src/Magnum/Test/ResourceManagerLocalInstanceTest.cpp new file mode 100644 index 000000000..8efa7f191 --- /dev/null +++ b/src/Magnum/Test/ResourceManagerLocalInstanceTest.cpp @@ -0,0 +1,54 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015 + 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 "ResourceManagerLocalInstanceTestLib.h" + +namespace Magnum { namespace Test { + +struct ResourceManagerLocalInstanceTest: TestSuite::Tester { + explicit ResourceManagerLocalInstanceTest(); + + void instance(); + + ResourceManagerWithLocalInstance manager; +}; + +ResourceManagerLocalInstanceTest::ResourceManagerLocalInstanceTest() { + addTests({&ResourceManagerLocalInstanceTest::instance}); +} + +void ResourceManagerLocalInstanceTest::instance() { + ResourceManagerWithLocalInstance::instance().set("another", 13); + + CORRADE_COMPARE(&manager.staticInstance, &manager.instance()); + CORRADE_COMPARE(manager.count(), 2); + CORRADE_COMPARE(manager.state("integer"), ResourceState::Final); +} + +}} + +CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerLocalInstanceTest) diff --git a/src/Magnum/Test/ResourceManagerLocalInstanceTestLib.cpp b/src/Magnum/Test/ResourceManagerLocalInstanceTestLib.cpp new file mode 100644 index 000000000..0b0b73a31 --- /dev/null +++ b/src/Magnum/Test/ResourceManagerLocalInstanceTestLib.cpp @@ -0,0 +1,43 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015 + 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 "ResourceManagerLocalInstanceTestLib.h" + +#include "Magnum/ResourceManager.hpp" + +namespace Magnum { + +namespace Implementation { + template MAGNUM_RESOURCEMANAGERLOCALINSTANCETESTLIB_EXPORT ResourceManager*& ResourceManagerLocalInstanceImplementation::internalInstance(); +} + +namespace Test { + +ResourceManagerWithLocalInstance::ResourceManagerWithLocalInstance(): staticInstance(static_cast(instance())) { + /* Add some stuff */ + set("integer", 42); +} + +}} diff --git a/src/Magnum/Test/ResourceManagerLocalInstanceTestLib.h b/src/Magnum/Test/ResourceManagerLocalInstanceTestLib.h new file mode 100644 index 000000000..8b2570f96 --- /dev/null +++ b/src/Magnum/Test/ResourceManagerLocalInstanceTestLib.h @@ -0,0 +1,48 @@ +#ifndef Magnum_Test_ResourceManagerLocalInstanceTestLib_h +#define Magnum_Test_ResourceManagerLocalInstanceTestLib_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014, 2015 + 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 "Magnum/ResourceManager.h" + +#ifndef MAGNUM_BUILD_STATIC + #if defined(ResourceManagerLocalInstanceTestLib_EXPORTS) + #define MAGNUM_RESOURCEMANAGERLOCALINSTANCETESTLIB_EXPORT CORRADE_VISIBILITY_EXPORT + #else + #define MAGNUM_RESOURCEMANAGERLOCALINSTANCETESTLIB_EXPORT CORRADE_VISIBILITY_IMPORT + #endif +#endif + +namespace Magnum { namespace Test { + +struct MAGNUM_RESOURCEMANAGERLOCALINSTANCETESTLIB_EXPORT ResourceManagerWithLocalInstance: ResourceManager { + explicit ResourceManagerWithLocalInstance(); + + ResourceManagerWithLocalInstance& staticInstance; +}; + +}} + +#endif