Re: [Cppunit-devel] Checking for equality of C strings
Brought to you by:
blep
From: Duane M. <dua...@ma...> - 2003-02-13 23:23:17
|
--- At Thu, 13 Feb 2003 17:12:47 -0600, Dave Glowacki wrote: >If I try to do something like this: > > const char *sample = "Sample String"; > > char copy[16]; > strcpy(copy, sample); > CPPUNIT_ASSERT_EQUAL_MESSAGE("Identical strings are not equal", > (const char *)copy, sample); > >I end up getting an assertion like this: > > charcompare.cpp:15:Assertion > Test name: CharCompare::testCompare > equality assertion failed > - Expected: Sample String > - Actual : Sample String > - Identical strings are not equal > >Is there a variant of CPPUNIT_ASSERT_EQUAL macro which can compare >C strings? Extra points if it can compare a 'char[]' and a 'char *'! You are comparing pointers. The pointers are not equal. Convert them to std::string and compare them. std::string sample = "Sample String"; std::string copy = sample; CPPUNIT_ASSERT_EQUAL_MESSAGE("Identical strings are not equal", copy, sample); Welcome to C++ :-) ...Duane |