Menu

#147 assertion_traits<T>::equal fails for arguments of type char*

1.10.2
open
5
2005-11-27
2005-08-25
Anonymous
No

This fails in 1.11.0 as well.

I don't know if this is a bug or a case of "just don't use it
that way".

I found this while writing some unit tests for a corba
apllication. Corba has its own type to represent string
data. When verifying the corba string return value from a
server call, I converted the corba string and the expected
std::string to const char* and used
CPPUNIT_ASSERT_EQUAL. The strings matched but
the assertion failed. I ending up adding the following
code to the .cpp file of my test class to fix the problem.

template <>
struct assertion_traits<const char*>
{
static bool equal(const char* x, const char* y)
{
return !strcmp(x, y);
}

static std::string toString(const char *x)
{
return x;
}
};

A Test class for this is attached.

my email is cflowe@weather.com

Discussion

  • Nobody/Anonymous

    Test class and fix for the issue

     
  • Baptiste Lepilleur

    • assigned_to: nobody --> blep
     
  • Baptiste Lepilleur

    Logged In: YES
    user_id=196852

    This is the expected behavior. There is no guaranty of what
    a const char * pointer represents (could be binary data).

    If this is an issue, a CPPUNIT_ASSERT_STRING_EQUAL could be
    introduced (just like in CppUnit 2).

    Baptiste.

     

Log in to post a comment.