Browse Source

Make Debug printer for ResourceKey more distinct.

Printing ResourceKey(0xabcd) instead of just abcd to make it clear what
it is.
mousecapture
Vladimír Vondruš 6 years ago
parent
commit
169378eb7d
  1. 4
      src/Magnum/Resource.cpp
  2. 4
      src/Magnum/Resource.h
  3. 14
      src/Magnum/Test/ResourceManagerTest.cpp

4
src/Magnum/Resource.cpp

@ -48,6 +48,10 @@ Debug& operator<<(Debug& debug, const ResourceState value) {
return debug << "(" << Debug::nospace << reinterpret_cast<void*>(UnsignedByte(value)) << Debug::nospace << ")";
}
Debug& operator<<(Debug& debug, const ResourceKey& value) {
return debug << "ResourceKey(0x" << Debug::nospace << static_cast<const Utility::HashDigest<sizeof(std::size_t)>&>(value) << Debug::nospace << ")";
}
#endif
}

4
src/Magnum/Resource.h

@ -101,9 +101,7 @@ class ResourceKey: public Utility::MurmurHash2::Digest {
};
/** @debugoperator{ResourceKey} */
inline Debug& operator<<(Debug& debug, const ResourceKey& value) {
return debug << static_cast<const Utility::HashDigest<sizeof(std::size_t)>&>(value);
}
MAGNUM_EXPORT Debug& operator<<(Debug& debug, const ResourceKey& value);
namespace Implementation {
template<class> class ResourceManagerData;

14
src/Magnum/Test/ResourceManagerTest.cpp

@ -27,6 +27,7 @@
#include <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
#include <Corrade/Utility/FormatStl.h>
#include "Magnum/AbstractResourceLoader.h"
#include "Magnum/ResourceManager.h"
@ -57,6 +58,7 @@ struct ResourceManagerTest: TestSuite::Tester {
void loaderSetNullptr();
void debugResourceState();
void debugResourceKey();
};
struct Data {
@ -91,7 +93,8 @@ ResourceManagerTest::ResourceManagerTest() {
&ResourceManagerTest::loader,
&ResourceManagerTest::loaderSetNullptr,
&ResourceManagerTest::debugResourceState});
&ResourceManagerTest::debugResourceState,
&ResourceManagerTest::debugResourceKey});
}
void ResourceManagerTest::constructResource() {
@ -283,7 +286,7 @@ void ResourceManagerTest::basic() {
int a = 43; /* Done this way to prevent a memory leak on assert (yes, the code is bad) */
rm.set(answerKey, &a, ResourceDataState::Mutable, ResourcePolicy::Resident);
CORRADE_COMPARE(*theAnswer, 42);
CORRADE_COMPARE(out.str(), "ResourceManager::set(): cannot change already final resource " + answerKey.hexString() + '\n');
CORRADE_COMPARE(out.str(), Utility::formatString("ResourceManager::set(): cannot change already final resource ResourceKey(0x{})\n", answerKey.hexString()));
/* But non-final can be changed */
rm.set(questionKey, 20, ResourceDataState::Final, ResourcePolicy::Resident);
@ -503,6 +506,13 @@ void ResourceManagerTest::debugResourceState() {
CORRADE_COMPARE(out.str(), "ResourceState::Loading ResourceState(0xbe)\n");
}
void ResourceManagerTest::debugResourceKey() {
std::ostringstream out;
ResourceKey hello = "hello";
Debug{&out} << hello;
CORRADE_COMPARE(out.str(), Utility::formatString("ResourceKey(0x{})\n", hello.hexString()));
}
}}}
CORRADE_TEST_MAIN(Magnum::Test::ResourceManagerTest)

Loading…
Cancel
Save