diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index e084b35..2608582 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -119,9 +119,27 @@ template 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 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 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 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 { \ diff --git a/test/lightweight_test_test.cpp b/test/lightweight_test_test.cpp index a2c5971..a3b04a9 100644 --- a/test/lightweight_test_test.cpp +++ b/test/lightweight_test_test.cpp @@ -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