Browse Source

Add test for file-local ResourceManager instance.

To ensure that I didn't accidentaly break anything (linker errors etc.).
pull/94/head
Vladimír Vondruš 11 years ago
parent
commit
ff490bb3fa
  1. 7
      src/Magnum/Test/CMakeLists.txt
  2. 54
      src/Magnum/Test/ResourceManagerLocalInstanceTest.cpp
  3. 43
      src/Magnum/Test/ResourceManagerLocalInstanceTestLib.cpp
  4. 48
      src/Magnum/Test/ResourceManagerLocalInstanceTestLib.h

7
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})

54
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š <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 "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<Int>(), 2);
CORRADE_COMPARE(manager.state<Int>("integer"), ResourceState::Final);
}
}}
CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerLocalInstanceTest)

43
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š <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 "ResourceManagerLocalInstanceTestLib.h"
#include "Magnum/ResourceManager.hpp"
namespace Magnum {
namespace Implementation {
template MAGNUM_RESOURCEMANAGERLOCALINSTANCETESTLIB_EXPORT ResourceManager<ResourceManagerLocalInstance, Int>*& ResourceManagerLocalInstanceImplementation<ResourceManagerLocalInstance, Int>::internalInstance();
}
namespace Test {
ResourceManagerWithLocalInstance::ResourceManagerWithLocalInstance(): staticInstance(static_cast<ResourceManagerWithLocalInstance&>(instance())) {
/* Add some stuff */
set("integer", 42);
}
}}

48
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š <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 "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<Implementation::ResourceManagerLocalInstance, Int> {
explicit ResourceManagerWithLocalInstance();
ResourceManagerWithLocalInstance& staticInstance;
};
}}
#endif
Loading…
Cancel
Save