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

CFIXCC_ASSERT_EQUALS

CFIXCC_ASSERT_EQUALS

Synopsis

CFIXCC_ASSERT_EQUALS allows typesafe comparison of values. Failed comparisons are treated as a failure, i.e. in the same manner as a failed CFIX_ASSERT. The benefit over using CFIX_ASSERT( Expected == Actual ) is that the expected and actual value will be visible in the failure report.

Declaration
void CFIXCC_ASSERT_EQUALS( 
	__in T Expected, 
	__in T Actual 
	);
				

T can be any type, but the types of both values must be compatible. See discussion below.

Parameters

[in] Expected: The expected value.

[in] Actual: The actual value that is to be checked.

Remarks

The way the comparison is conducted depends on the type of the two values.

  • Primitive integer objects are compared using the builtin == operator.
  • Comparisons of float and double values do not check for exact equality but allow a deviation of 10 units in the last place (ULP). The default value of 10 ULP may be overridden by defining CFIXCC_FLOAT_COMPARE_MAX_ULPS with a custom ULP-value.
  • Pointers are checked for address equality. An exception to this are C strings (char*, const char*, wchar_t*, const wchar_t*). Such strings will be wrapped by std::string and std::wstring objects respectively, and operator== of std::string or std::wstring will be invoked. That is, a value-comparison is conducted.
  • For non-primitive, non-pointer types, i.e. objects of a custom class, operator== of the respective class is invoked.

Usage example
class SomeClass
{
private:
	int value;
public:
	bool operator == ( const SomeClass& other ) const
	{
		return this->value == other.value;
	}

	...
};
...

//
// These tests will succeed:
//
CFIXCC_ASSERT_EQUALS( SomeClass( 1 ), SomeClass( 1 ) );
CFIXCC_ASSERT_EQUALS( L"test", L"test" );
CFIXCC_ASSERT_EQUALS( 1.9999999f, 2.0f );	// See remarks on ULPs.

//
// These will fail:
//
SomeClass* a = new SomeClass( 1 );
SomeClass* b = new SomeClass( 1 );

CFIXCC_ASSERT_EQUALS( a, b );	// Values equal, but pointers are not.
CFIXCC_ASSERT_EQUALS( L"test", L"" );
				
Requirements

Table 7.27. 

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