mirror of
https://github.com/boostorg/core.git
synced 2025-07-29 12:27:42 +02:00
compare pointers as addresses and use BOOST_TEST_CSTR_xx to compare cstrings
This commit is contained in:
@ -119,9 +119,27 @@ template<class T, class U> inline void test_eq_impl( char const * expr1, char co
|
||||
}
|
||||
}
|
||||
|
||||
// overload for const char*
|
||||
inline void test_eq_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, const char* t, const char* u )
|
||||
// overloads for pointers compare and print addresses
|
||||
template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, const T* const t, const U* const u )
|
||||
{
|
||||
if( t == u )
|
||||
{
|
||||
report_errors_remind();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
|
||||
<< "' failed in function '" << function << "': "
|
||||
<< "'" << (const void*)t << "' != '" << (const void*)u << "'" << std::endl;
|
||||
++test_errors();
|
||||
}
|
||||
}
|
||||
|
||||
// impl for cstring
|
||||
inline void test_cstr_eq_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, const char* const t, const char* const u )
|
||||
{
|
||||
if( std::strcmp(t, u) == 0 )
|
||||
{
|
||||
@ -154,9 +172,27 @@ template<class T, class U> inline void test_ne_impl( char const * expr1, char co
|
||||
}
|
||||
}
|
||||
|
||||
// overload for const char*
|
||||
inline void test_ne_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, const char* t, const char* u )
|
||||
// overloads for pointers compare and print addresses
|
||||
template<class T, class U> inline void test_ne_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, const T* const t, const U* const u )
|
||||
{
|
||||
if( t != u )
|
||||
{
|
||||
report_errors_remind();
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOST_LIGHTWEIGHT_TEST_OSTREAM
|
||||
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
|
||||
<< "' failed in function '" << function << "': "
|
||||
<< "'" << (const void*)t << "' == '" << (const void*)u << "'" << std::endl;
|
||||
++test_errors();
|
||||
}
|
||||
}
|
||||
|
||||
// impl for cstring
|
||||
inline void test_cstr_ne_impl( char const * expr1, char const * expr2,
|
||||
char const * file, int line, char const * function, const char* const t, const char* const u )
|
||||
{
|
||||
if( std::strcmp(t, u) != 0 )
|
||||
{
|
||||
@ -214,6 +250,9 @@ inline int report_errors()
|
||||
#define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
#define BOOST_TEST_NE(expr1,expr2) ( ::boost::detail::test_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
|
||||
#define BOOST_TEST_CSTR_EQ(expr1,expr2) ( ::boost::detail::test_cstr_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
#define BOOST_TEST_CSTR_NE(expr1,expr2) ( ::boost::detail::test_cstr_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
|
||||
|
||||
#ifndef BOOST_NO_EXCEPTIONS
|
||||
#define BOOST_TEST_THROWS( EXPR, EXCEP ) \
|
||||
try { \
|
||||
|
@ -64,14 +64,15 @@ int main()
|
||||
|
||||
BOOST_TEST_EQ( ++x, ++y );
|
||||
BOOST_TEST_EQ( x++, y++ );
|
||||
|
||||
BOOST_TEST_EQ("xabc"+1, "yabc"+1); // make sure addresses are different
|
||||
BOOST_TEST_CSTR_EQ("xabc"+1, "yabc"+1); // equal cstrings, different addresses
|
||||
BOOST_TEST_EQ( &y, &y );
|
||||
|
||||
// BOOST_TEST_NE
|
||||
|
||||
BOOST_TEST_NE( ++x, y );
|
||||
BOOST_TEST_NE( &x, &y );
|
||||
BOOST_TEST_NE( "abc", "ABC" );
|
||||
BOOST_TEST_NE("xabc"+1, "yabc"+1); // equal cstrings, different addresses
|
||||
BOOST_TEST_CSTR_NE("x", "y");
|
||||
|
||||
// BOOST_TEST_THROWS
|
||||
|
||||
|
Reference in New Issue
Block a user