Visual Assert – The Unit Testing Add-In for Visual C++
cfix – C/C++ Unit Testing for Win32 and NT
 
 

WinUnit::ToString

WinUnit::ToString

Synopsis

Template for which an explicit specialization may be provided in order to enable cfix to obtain a string representation of an object for use in assertion messages.

Declaration
namespace WinUnit
{
  template< typename T >
  inline const TCHAR* ToString(
    __in const T& Object,
    __inout_ecount( BufferCch ) PTSTR Buffer,
    __in size_t BufferCch
    )
}
			
Parameters

[in] Object: The object for which the string representation is to be created.

[in] Buffer: Buffer that may be used as storage for the string representation.

[in] BufferCch: Size of the buffer, in TCHARs.

Return Value

The string representation. The pointer returned must either point to static storage or to the buffer passed as second parameter.

Remarks

When WIN_ASSERT_EQUAL is used to compare two non-prmitive objects and the check fails, cfix generates an appropriate error message. To have this error message include a proper string representation of the objects being compared, you can -- optionally -- provide an appropriate explicit template specialization of WinUnit::ToString.

Note that this differs from the cfic C++ API, which invokes operator<< on an object to obtain its string representation.

Usage example
class Foo
{
  ...
};

template<>
const TCHAR* WinUnit::ToString(
  __in const Foo& Object,
  __inout_ecount( BufferCch ) PTSTR Buffer,
  __in size_t BufferCch
  )
{
  StringCchPrintf( Buffer, BufferCch, ... );
  return Buffer;
}
			
Requirements

Table 7.53. 

 User ModeKernel Mode
Available since1.3N/A
HeaderDeclared in winunit.hN/A
LibraryLink to cfix.libN/A
DLLcfix.dllN/A
IRQLN/AN/A