Skip to content

Commit

Permalink
Audio: add debug operator for Source::Type.
Browse files Browse the repository at this point in the history
  • Loading branch information
mosra committed May 25, 2019
1 parent b9fb03a commit c442c07
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Magnum/Audio/Source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,18 @@ Debug& operator<<(Debug& debug, const Source::State value) {
return debug << "Audio::Source::State(" << Debug::nospace << reinterpret_cast<void*>(ALint(value)) << Debug::nospace << ")";
}

Debug& operator<<(Debug& debug, const Source::Type value) {
switch(value) {
/* LCOV_EXCL_START */
#define _c(value) case Source::Type::value: return debug << "Audio::Source::Type::" #value;
_c(Undetermined)
_c(Static)
_c(Streaming)
#undef _c
/* LCOV_EXCL_STOP */
}

return debug << "Audio::Source::Type(" << Debug::nospace << reinterpret_cast<void*>(ALint(value)) << Debug::nospace << ")";
}

}}
3 changes: 3 additions & 0 deletions src/Magnum/Audio/Source.h
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,9 @@ class MAGNUM_AUDIO_EXPORT Source {
/** @debugoperatorclassenum{Source,Source::State} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Source::State value);

/** @debugoperatorclassenum{Source,Source::Type} */
MAGNUM_AUDIO_EXPORT Debug& operator<<(Debug& debug, Source::Type value);

inline Source::Source(Source&& other): _id(other._id) {
other._id = 0;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Magnum/Audio/Test/SourceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ struct SourceTest: TestSuite::Tester {
explicit SourceTest();

void debugState();
void debugType();
};

SourceTest::SourceTest() {
addTests({&SourceTest::debugState});
addTests({&SourceTest::debugState,
&SourceTest::debugType});
}

void SourceTest::debugState() {
Expand All @@ -47,6 +49,12 @@ void SourceTest::debugState() {
CORRADE_COMPARE(out.str(), "Audio::Source::State::Playing Audio::Source::State(0xdead)\n");
}

void SourceTest::debugType() {
std::ostringstream out;
Debug(&out) << Source::Type::Streaming << Source::Type(0xdead);
CORRADE_COMPARE(out.str(), "Audio::Source::Type::Streaming Audio::Source::Type(0xdead)\n");
}

}}}}

CORRADE_TEST_MAIN(Magnum::Audio::Test::SourceTest)

0 comments on commit c442c07

Please sign in to comment.