1
0
forked from boostorg/core

fix for trac issue #12814, including a new test for the issue

This commit is contained in:
hans.dembinski@gmail.com
2017-02-05 19:06:21 +00:00
parent e647763fb0
commit cdee8e76c5
2 changed files with 42 additions and 0 deletions

View File

@@ -23,6 +23,7 @@
#include <boost/current_function.hpp>
#include <boost/core/no_exceptions_support.hpp>
#include <iostream>
#include <cstring>
// IDE's like Visual Studio perform better if output goes to std::cout or
// some other stream, so allow user to configure output stream:
@@ -118,6 +119,24 @@ 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 )
{
if( std::strcmp(t, u) == 0 )
{
report_errors_remind();
}
else
{
BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
<< "' failed in function '" << function << "': "
<< "'" << t << "' != '" << u << "'" << std::endl;
++test_errors();
}
}
template<class T, class U> inline void test_ne_impl( char const * expr1, char const * expr2,
char const * file, int line, char const * function, T const & t, U const & u )
{
@@ -135,6 +154,24 @@ 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 )
{
if( std::strcmp(t, u) != 0 )
{
report_errors_remind();
}
else
{
BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< file << "(" << line << "): test '" << expr1 << " == " << expr2
<< "' failed in function '" << function << "': "
<< "'" << t << "' == '" << u << "'" << std::endl;
++test_errors();
}
}
#if defined(_MSC_VER)
# pragma warning(pop)
#elif defined(__clang__) && defined(__has_warning)

View File

@@ -65,10 +65,15 @@ int main()
BOOST_TEST_EQ( ++x, ++y );
BOOST_TEST_EQ( x++, y++ );
const char* s1 = "abc"; // make sure addresses are different
const char* s2 = "abc"; // make sure addresses are different
BOOST_TEST_EQ(s1, s2);
// BOOST_TEST_NE
BOOST_TEST_NE( ++x, y );
BOOST_TEST_NE( &x, &y );
BOOST_TEST_NE( "abc", "ABC" );
// BOOST_TEST_THROWS