diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c9460aeca..26601309b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,7 @@ set(Magnum_SRCS Profiler.cpp Query.cpp Renderbuffer.cpp + Resource.cpp Shader.cpp SizeTraits.cpp Timeline.cpp diff --git a/src/Resource.cpp b/src/Resource.cpp new file mode 100644 index 000000000..6093091d4 --- /dev/null +++ b/src/Resource.cpp @@ -0,0 +1,39 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Resource.h" + +namespace Magnum { + +#ifndef DOXYGEN_GENERATING_OUTPUT +Debug MAGNUM_EXPORT operator<<(Debug debug, ResourceState value) { + switch(value) { + #define _c(value) case ResourceState::value: return debug << "ResourceState::" #value; + _c(NotLoaded) + _c(NotLoadedFallback) + _c(Loading) + _c(LoadingFallback) + _c(NotFound) + _c(NotFoundFallback) + _c(Mutable) + _c(Final) + #undef _c + } + + return debug << "ResourceState::(invalid)"; +} +#endif + +} diff --git a/src/Resource.h b/src/Resource.h index 9b90cf41e..484036726 100644 --- a/src/Resource.h +++ b/src/Resource.h @@ -23,6 +23,8 @@ #include "Magnum.h" +#include "magnumVisibility.h" + namespace Magnum { /** @relates Resource @@ -44,6 +46,9 @@ enum class ResourceState: std::uint8_t { Final }; +/** @debugoperator{Magnum::Resource} */ +Debug MAGNUM_EXPORT operator<<(Debug debug, ResourceState value); + /** @brief Key for accessing resource diff --git a/src/Test/CMakeLists.txt b/src/Test/CMakeLists.txt index 2a2c2ebc8..e7950f7f4 100644 --- a/src/Test/CMakeLists.txt +++ b/src/Test/CMakeLists.txt @@ -1,5 +1,5 @@ corrade_add_test2(ColorTest ColorTest.cpp LIBRARIES MagnumMathTestLib) -corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp) +corrade_add_test2(ResourceManagerTest ResourceManagerTest.cpp LIBRARIES MagnumTestLib) corrade_add_test2(SwizzleTest SwizzleTest.cpp LIBRARIES MagnumMathTestLib) set_target_properties(ResourceManagerTest PROPERTIES COMPILE_FLAGS -DCORRADE_GRACEFUL_ASSERT) diff --git a/src/Test/ResourceManagerTest.cpp b/src/Test/ResourceManagerTest.cpp index 57e7490aa..9c50d214b 100644 --- a/src/Test/ResourceManagerTest.cpp +++ b/src/Test/ResourceManagerTest.cpp @@ -51,14 +51,14 @@ void ResourceManagerTest::state() { ResourceKey questionKey("the-question"); rm.set(questionKey, new int32_t(10), ResourceDataState::Mutable, ResourcePolicy::Resident); Resource theQuestion = rm.get(questionKey); - CORRADE_VERIFY(theQuestion.state() == ResourceState::Mutable); + CORRADE_COMPARE(theQuestion.state(), ResourceState::Mutable); CORRADE_COMPARE(*theQuestion, 10); /* Check that hash function is working properly */ ResourceKey answerKey("the-answer"); rm.set(answerKey, new int32_t(42), ResourceDataState::Final, ResourcePolicy::Resident); Resource theAnswer = rm.get(answerKey); - CORRADE_VERIFY(theAnswer.state() == ResourceState::Final); + CORRADE_COMPARE(theAnswer.state(), ResourceState::Final); CORRADE_COMPARE(*theAnswer, 42); CORRADE_COMPARE(rm.count(), 2); @@ -72,7 +72,7 @@ void ResourceManagerTest::state() { /* Check non-final resource changes */ rm.set(questionKey, new int32_t(20), ResourceDataState::Final, ResourcePolicy::Resident); - CORRADE_VERIFY(theQuestion.state() == ResourceState::Final); + CORRADE_COMPARE(theQuestion.state(), ResourceState::Final); CORRADE_COMPARE(*theQuestion, 20); } @@ -99,14 +99,14 @@ void ResourceManagerTest::referenceCountedPolicy() { rm.set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); CORRADE_COMPARE(rm.count(), 0); Resource data = rm.get(dataRefCountKey); - CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); + CORRADE_COMPARE(data.state(), ResourceState::NotLoaded); CORRADE_COMPARE(Data::count, 0); } { Resource data = rm.get(dataRefCountKey); CORRADE_COMPARE(rm.count(), 1); - CORRADE_VERIFY(data.state() == ResourceState::NotLoaded); + CORRADE_COMPARE(data.state(), ResourceState::NotLoaded); rm.set(dataRefCountKey, new Data(), ResourceDataState::Final, ResourcePolicy::ReferenceCounted); - CORRADE_VERIFY(data.state() == ResourceState::Final); + CORRADE_COMPARE(data.state(), ResourceState::Final); CORRADE_COMPARE(Data::count, 1); }