mirror of
https://github.com/catchorg/Catch2.git
synced 2025-05-25 05:59:24 +00:00
Fixes toString() for function pointers and added support for member function pointers.
- thanks to Malcolm Noyes for supplying sample code on which the solution here was based
This commit is contained in:
parent
440a47011f
commit
e091018514
7 changed files with 82 additions and 12 deletions
|
@ -79,6 +79,25 @@ namespace Detail {
|
|||
}
|
||||
};
|
||||
|
||||
// For display purposes only.
|
||||
// Does not consider endian-ness
|
||||
template<typename T>
|
||||
std::string rawMemoryToString( T value ) {
|
||||
union
|
||||
{
|
||||
T value;
|
||||
unsigned char bytes[sizeof(T)];
|
||||
} valueAsBuffer;
|
||||
|
||||
valueAsBuffer.value = value;
|
||||
|
||||
std::ostringstream oss;
|
||||
oss << "0x";
|
||||
for( unsigned char* cp = valueAsBuffer.bytes; cp < valueAsBuffer.bytes+sizeof(T); ++cp )
|
||||
oss << std::hex << std::setw(2) << std::setfill('0') << (unsigned int)*cp;
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
} // end namespace Detail
|
||||
|
||||
template<typename T>
|
||||
|
@ -94,9 +113,18 @@ struct StringMaker<T*> {
|
|||
static std::string convert( U* p ) {
|
||||
if( !p )
|
||||
return INTERNAL_CATCH_STRINGIFY( NULL );
|
||||
std::ostringstream oss;
|
||||
oss << "0x" << std::hex << reinterpret_cast<unsigned long>( p );
|
||||
return oss.str();
|
||||
else
|
||||
return Detail::rawMemoryToString( p );
|
||||
}
|
||||
};
|
||||
|
||||
template<typename R, typename C>
|
||||
struct StringMaker<R C::*> {
|
||||
static std::string convert( R C::* p ) {
|
||||
if( !p )
|
||||
return INTERNAL_CATCH_STRINGIFY( NULL );
|
||||
else
|
||||
return Detail::rawMemoryToString( p );
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue