diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index 84569f043f..69a77329ea 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -20,104 +20,10 @@ #include "wx/private/localeset.h" // ---------------------------------------------------------------------------- -// test class +// tests // ---------------------------------------------------------------------------- -class StringTestCase : public CppUnit::TestCase -{ -public: - StringTestCase(); - -private: - CPPUNIT_TEST_SUITE( StringTestCase ); - CPPUNIT_TEST( String ); - CPPUNIT_TEST( PChar ); - CPPUNIT_TEST( Format ); - CPPUNIT_TEST( FormatUnicode ); - CPPUNIT_TEST( Constructors ); - CPPUNIT_TEST( StaticConstructors ); - CPPUNIT_TEST( Extraction ); - CPPUNIT_TEST( Trim ); - CPPUNIT_TEST( Find ); - CPPUNIT_TEST( Replace ); - CPPUNIT_TEST( Match ); - CPPUNIT_TEST( CaseChanges ); - CPPUNIT_TEST( Compare ); - CPPUNIT_TEST( CompareNoCase ); - CPPUNIT_TEST( Contains ); - CPPUNIT_TEST( ToInt ); - CPPUNIT_TEST( ToUInt ); - CPPUNIT_TEST( ToLong ); - CPPUNIT_TEST( ToULong ); -#ifdef wxLongLong_t - CPPUNIT_TEST( ToLongLong ); - CPPUNIT_TEST( ToULongLong ); -#endif // wxLongLong_t - CPPUNIT_TEST( ToDouble ); - CPPUNIT_TEST( FromDouble ); - CPPUNIT_TEST( StringBuf ); - CPPUNIT_TEST( UTF8Buf ); - CPPUNIT_TEST( CStrDataTernaryOperator ); - CPPUNIT_TEST( CStrDataOperators ); - CPPUNIT_TEST( CStrDataImplicitConversion ); - CPPUNIT_TEST( ExplicitConversion ); - CPPUNIT_TEST( IndexedAccess ); - CPPUNIT_TEST( BeforeAndAfter ); - CPPUNIT_TEST( ScopedBuffers ); - CPPUNIT_TEST( SupplementaryUniChar ); - CPPUNIT_TEST_SUITE_END(); - - void String(); - void PChar(); - void Format(); - void FormatUnicode(); - void Constructors(); - void StaticConstructors(); - void Extraction(); - void Trim(); - void Find(); - void Replace(); - void Match(); - void CaseChanges(); - void Compare(); - void CompareNoCase(); - void Contains(); - void ToInt(); - void ToUInt(); - void ToLong(); - void ToULong(); -#ifdef wxLongLong_t - void ToLongLong(); - void ToULongLong(); -#endif // wxLongLong_t - void ToDouble(); - void FromDouble(); - void StringBuf(); - void UTF8Buf(); - void CStrDataTernaryOperator(); - void DoCStrDataTernaryOperator(bool cond); - void CStrDataOperators(); - void CStrDataImplicitConversion(); - void ExplicitConversion(); - void IndexedAccess(); - void BeforeAndAfter(); - void ScopedBuffers(); - void SupplementaryUniChar(); - - wxDECLARE_NO_COPY_CLASS(StringTestCase); -}; - -// register in the unnamed registry so that these tests are run by default -CPPUNIT_TEST_SUITE_REGISTRATION( StringTestCase ); - -// also include in its own registry so that these tests can be run alone -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTestCase, "StringTestCase" ); - -StringTestCase::StringTestCase() -{ -} - -void StringTestCase::String() +TEST_CASE("StringAssign", "[wxString]") { wxString a, b, c; @@ -133,11 +39,11 @@ void StringTestCase::String() a += b; a += c; c = wxT("Hello world! What's up?"); - CPPUNIT_ASSERT( c != a ); + CHECK( c != a ); } } -void StringTestCase::PChar() +TEST_CASE("StringPChar", "[wxString]") { wxChar a [128]; wxChar b [128]; @@ -151,17 +57,17 @@ void StringTestCase::PChar() wxStrcat (a, b); wxStrcat (a, c); wxStrcpy (c, wxT("Hello world! What's up?")); - CPPUNIT_ASSERT( wxStrcmp (c, a) != 0 ); + CHECK( wxStrcmp (c, a) != 0 ); } } -void StringTestCase::Format() +TEST_CASE("StringFormat", "[wxString]") { wxString s1,s2; s1.Printf(wxT("%03d"), 18); - CPPUNIT_ASSERT( s1 == wxString::Format(wxT("%03d"), 18) ); + CHECK( s1 == wxString::Format(wxT("%03d"), 18) ); s2.Printf(wxT("Number 18: %s\n"), s1.c_str()); - CPPUNIT_ASSERT( s2 == wxString::Format(wxT("Number 18: %s\n"), s1.c_str()) ); + CHECK( s2 == wxString::Format(wxT("Number 18: %s\n"), s1.c_str()) ); static const size_t lengths[] = { 1, 512, 1024, 1025, 2048, 4096, 4097 }; for ( size_t n = 0; n < WXSIZEOF(lengths); n++ ) @@ -169,37 +75,24 @@ void StringTestCase::Format() const size_t len = lengths[n]; wxString s(wxT('Z'), len); - CPPUNIT_ASSERT_EQUAL( len, wxString::Format(wxT("%s"), s.c_str()).length()); + CHECK( wxString::Format(wxT("%s"), s.c_str()).length() == len ); } // wxString::Format() should not modify errno errno = 1234; wxString::Format("abc %d %d", 1, 1); - CPPUNIT_ASSERT_EQUAL(1234, errno); + CHECK( errno == 1234 ); // Positional parameters tests: - CPPUNIT_ASSERT_EQUAL - ( - "two one", - wxString::Format(wxT("%2$s %1$s"), wxT("one"), wxT("two")) - ); - - CPPUNIT_ASSERT_EQUAL - ( - "hello hello", - wxString::Format("%1$s %1$s", "hello") - ); - - CPPUNIT_ASSERT_EQUAL - ( - "4 world hello world 3", - wxString::Format("%4$d %2$s %1$s %2$s %3$d", "hello", "world", 3, 4) - ); + CHECK(wxString::Format(wxT("%2$s %1$s"), wxT("one"), wxT("two")) == "two one"); + CHECK(wxString::Format("%1$s %1$s", "hello") == "hello hello"); + CHECK(wxString::Format("%4$d %2$s %1$s %2$s %3$d", "hello", "world", 3, 4) + == "4 world hello world 3"); CHECK( wxString::Format("%1$o %1$d %1$x", 20) == "24 20 14" ); } -void StringTestCase::FormatUnicode() +TEST_CASE("StringFormatUnicode", "[wxString]") { // At least under FreeBSD vsnprintf(), used by wxString::Format(), doesn't // work with Unicode strings unless a UTF-8 locale is used, so set it. @@ -212,24 +105,24 @@ void StringTestCase::FormatUnicode() wxString s = wxString::Format(fmt, 1, 1); wxString expected(fmt); expected.Replace("%i", "1"); - CPPUNIT_ASSERT_EQUAL( expected, s ); + CHECK( s == expected ); } -void StringTestCase::Constructors() +TEST_CASE("StringConstructors", "[wxString]") { - CPPUNIT_ASSERT_EQUAL( "", wxString('Z', 0) ); - CPPUNIT_ASSERT_EQUAL( "Z", wxString('Z') ); - CPPUNIT_ASSERT_EQUAL( "ZZZZ", wxString('Z', 4) ); - CPPUNIT_ASSERT_EQUAL( "Hell", wxString("Hello", 4) ); - CPPUNIT_ASSERT_EQUAL( "Hello", wxString("Hello", 5) ); + CHECK( wxString('Z', 0) == "" ); + CHECK( wxString('Z') == "Z" ); + CHECK( wxString('Z', 4) == "ZZZZ" ); + CHECK( wxString("Hello", 4) == "Hell" ); + CHECK( wxString("Hello", 5) == "Hello" ); - CPPUNIT_ASSERT_EQUAL( L"", wxString(L'Z', 0) ); - CPPUNIT_ASSERT_EQUAL( L"Z", wxString(L'Z') ); - CPPUNIT_ASSERT_EQUAL( L"ZZZZ", wxString(L'Z', 4) ); - CPPUNIT_ASSERT_EQUAL( L"Hell", wxString(L"Hello", 4) ); - CPPUNIT_ASSERT_EQUAL( L"Hello", wxString(L"Hello", 5) ); + CHECK( wxString(L'Z', 0) == L"" ); + CHECK( wxString(L'Z') == L"Z" ); + CHECK( wxString(L'Z', 4) == L"ZZZZ" ); + CHECK( wxString(L"Hello", 4) == L"Hell" ); + CHECK( wxString(L"Hello", 5) == L"Hello" ); - CPPUNIT_ASSERT_EQUAL( 0, wxString(wxString(), 17).length() ); + CHECK( wxString(wxString(), 17).length() == 0 ); #if wxUSE_UNICODE_UTF8 // This string has 3 characters (, and ), not 4 when using UTF-8 @@ -237,8 +130,8 @@ void StringTestCase::Constructors() if ( wxConvLibc.IsUTF8() ) { wxString s3("h\xc3\xa9llo", 4); - CPPUNIT_ASSERT_EQUAL( 3, s3.length() ); - CPPUNIT_ASSERT_EQUAL( 'l', (char)s3[2] ); + CHECK( s3.length() == 3 ); + CHECK( (char)s3[2] == 'l' ); } #endif // wxUSE_UNICODE_UTF8 @@ -246,60 +139,60 @@ void StringTestCase::Constructors() static const char *s = "?really!"; const char *start = wxStrchr(s, 'r'); const char *end = wxStrchr(s, '!'); - CPPUNIT_ASSERT_EQUAL( "really", wxString(start, end) ); + CHECK( wxString(start, end) == "really" ); // test if creating string from null C pointer works: - CPPUNIT_ASSERT_EQUAL( "", wxString((const char *)nullptr) ); + CHECK( wxString((const char *)nullptr) == "" ); } -void StringTestCase::StaticConstructors() +TEST_CASE("StringStaticConstructors", "[wxString]") { - CPPUNIT_ASSERT_EQUAL( "", wxString::FromAscii("") ); - CPPUNIT_ASSERT_EQUAL( "", wxString::FromAscii("Hello", 0) ); - CPPUNIT_ASSERT_EQUAL( "Hell", wxString::FromAscii("Hello", 4) ); - CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromAscii("Hello", 5) ); - CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromAscii("Hello") ); + CHECK( wxString::FromAscii("") == "" ); + CHECK( wxString::FromAscii("Hello", 0) == "" ); + CHECK( wxString::FromAscii("Hello", 4) == "Hell" ); + CHECK( wxString::FromAscii("Hello", 5) == "Hello" ); + CHECK( wxString::FromAscii("Hello") == "Hello" ); // FIXME: this doesn't work currently but should! - //CPPUNIT_ASSERT_EQUAL( 1, wxString::FromAscii("", 1).length() ); + //CHECK( wxString::FromAscii("", 1).length() == 1 ); - CPPUNIT_ASSERT_EQUAL( "", wxString::FromUTF8("") ); - CPPUNIT_ASSERT_EQUAL( "", wxString::FromUTF8("Hello", 0) ); - CPPUNIT_ASSERT_EQUAL( "Hell", wxString::FromUTF8("Hello", 4) ); - CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromUTF8("Hello", 5) ); - CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromUTF8("Hello") ); + CHECK( wxString::FromUTF8("") == "" ); + CHECK( wxString::FromUTF8("Hello", 0) == "" ); + CHECK( wxString::FromUTF8("Hello", 4) == "Hell" ); + CHECK( wxString::FromUTF8("Hello", 5) == "Hello" ); + CHECK( wxString::FromUTF8("Hello") == "Hello" ); - CPPUNIT_ASSERT_EQUAL( 2, wxString::FromUTF8("h\xc3\xa9llo", 3).length() ); + CHECK( wxString::FromUTF8("h\xc3\xa9llo", 3).length() == 2 ); - //CPPUNIT_ASSERT_EQUAL( 1, wxString::FromUTF8("", 1).length() ); + //CHECK( wxString::FromUTF8("", 1).length() == 1 ); } -void StringTestCase::Extraction() +TEST_CASE("StringExtraction", "[wxString]") { wxString s(wxT("Hello, world!")); - CPPUNIT_ASSERT( wxStrcmp( s.c_str() , wxT("Hello, world!") ) == 0 ); - CPPUNIT_ASSERT( wxStrcmp( s.Left(5).c_str() , wxT("Hello") ) == 0 ); - CPPUNIT_ASSERT( wxStrcmp( s.Right(6).c_str() , wxT("world!") ) == 0 ); - CPPUNIT_ASSERT( wxStrcmp( s(3, 5).c_str() , wxT("lo, w") ) == 0 ); - CPPUNIT_ASSERT( wxStrcmp( s.Mid(3).c_str() , wxT("lo, world!") ) == 0 ); - CPPUNIT_ASSERT( wxStrcmp( s.substr(3, 5).c_str() , wxT("lo, w") ) == 0 ); - CPPUNIT_ASSERT( wxStrcmp( s.substr(3).c_str() , wxT("lo, world!") ) == 0 ); + CHECK( wxStrcmp( s.c_str() , wxT("Hello, world!") ) == 0 ); + CHECK( wxStrcmp( s.Left(5).c_str() , wxT("Hello") ) == 0 ); + CHECK( wxStrcmp( s.Right(6).c_str() , wxT("world!") ) == 0 ); + CHECK( wxStrcmp( s(3, 5).c_str() , wxT("lo, w") ) == 0 ); + CHECK( wxStrcmp( s.Mid(3).c_str() , wxT("lo, world!") ) == 0 ); + CHECK( wxStrcmp( s.substr(3, 5).c_str() , wxT("lo, w") ) == 0 ); + CHECK( wxStrcmp( s.substr(3).c_str() , wxT("lo, world!") ) == 0 ); static const char *germanUTF8 = "Oberfl\303\244che"; wxString strUnicode(wxString::FromUTF8(germanUTF8)); - CPPUNIT_ASSERT( strUnicode.Mid(0, 10) == strUnicode ); - CPPUNIT_ASSERT( strUnicode.Mid(7, 2) == "ch" ); + CHECK( strUnicode.Mid(0, 10) == strUnicode ); + CHECK( strUnicode.Mid(7, 2) == "ch" ); wxString rest; #define TEST_STARTS_WITH(prefix, correct_rest, result) \ - CPPUNIT_ASSERT_EQUAL(result, s.StartsWith(prefix, &rest)); \ + CHECK(s.StartsWith(prefix, &rest) == result); \ if ( result ) \ - CPPUNIT_ASSERT_EQUAL(correct_rest, rest) + CHECK(rest == correct_rest) TEST_STARTS_WITH( wxT("Hello"), wxT(", world!"), true ); TEST_STARTS_WITH( wxT("Hello, "), wxT("world!"), true ); @@ -312,13 +205,13 @@ void StringTestCase::Extraction() #undef TEST_STARTS_WITH rest = "Hello world"; - CPPUNIT_ASSERT( rest.StartsWith("Hello ", &rest) ); - CPPUNIT_ASSERT_EQUAL("world", rest); + CHECK( rest.StartsWith("Hello ", &rest) ); + CHECK( rest == "world" ); #define TEST_ENDS_WITH(suffix, correct_rest, result) \ - CPPUNIT_ASSERT_EQUAL(result, s.EndsWith(suffix, &rest)); \ + CHECK(s.EndsWith(suffix, &rest) == result); \ if ( result ) \ - CPPUNIT_ASSERT_EQUAL(correct_rest, rest) + CHECK(rest == correct_rest) TEST_ENDS_WITH( wxT(""), wxT("Hello, world!"), true ); TEST_ENDS_WITH( wxT("!"), wxT("Hello, world"), true ); @@ -333,10 +226,10 @@ void StringTestCase::Extraction() #undef TEST_ENDS_WITH } -void StringTestCase::Trim() +TEST_CASE("StringTrim", "[wxString]") { #define TEST_TRIM( str , dir , result ) \ - CPPUNIT_ASSERT( wxString(str).Trim(dir) == result ) + CHECK( wxString(str).Trim(dir) == result ) TEST_TRIM( wxT(" Test "), true, wxT(" Test") ); TEST_TRIM( wxT(" "), true, wxT("") ); @@ -351,10 +244,10 @@ void StringTestCase::Trim() #undef TEST_TRIM } -void StringTestCase::Find() +TEST_CASE("StringFind", "[wxString]") { #define TEST_FIND( str , start , result ) \ - CPPUNIT_ASSERT( wxString(str).find(wxT("ell"), start) == result ); + CHECK( wxString(str).find(wxT("ell"), start) == result ); TEST_FIND( wxT("Well, hello world"), 0, 1 ); TEST_FIND( wxT("Well, hello world"), 6, 7 ); @@ -363,13 +256,13 @@ void StringTestCase::Find() #undef TEST_FIND } -void StringTestCase::Replace() +TEST_CASE("StringReplace", "[wxString]") { #define TEST_REPLACE( original , pos , len , replacement , result ) \ { \ wxString s = original; \ s.replace( pos , len , replacement ); \ - CPPUNIT_ASSERT_EQUAL( result, s ); \ + CHECK( s == result ); \ } TEST_REPLACE( wxT("012-AWORD-XYZ"), 4, 5, wxT("BWORD"), wxT("012-BWORD-XYZ") ); @@ -383,7 +276,7 @@ void StringTestCase::Replace() { \ wxString s(o,olen); \ s.replace( pos , len , replacement ); \ - CPPUNIT_ASSERT_EQUAL( wxString(r,rlen), s ); \ + CHECK( s == wxString(r, rlen) ); \ } TEST_NULLCHARREPLACE( wxT("null\0char"), 9, 5, 1, wxT("d"), @@ -393,7 +286,7 @@ void StringTestCase::Replace() { \ wxString s(o,olen); \ s.Replace( olds, news, all ); \ - CPPUNIT_ASSERT_EQUAL( wxString(r,rlen), s ); \ + CHECK( s == wxString(r, rlen) ); \ } TEST_WXREPLACE( wxT("null\0char"), 9, wxT("c"), wxT("de"), true, @@ -413,10 +306,10 @@ void StringTestCase::Replace() #undef TEST_REPLACE } -void StringTestCase::Match() +TEST_CASE("StringMatch", "[wxString]") { #define TEST_MATCH( s1 , s2 , result ) \ - CPPUNIT_ASSERT( wxString(s1).Matches(s2) == result ) + CHECK( wxString(s1).Matches(s2) == result ) TEST_MATCH( "foobar", "foo*", true ); TEST_MATCH( "foobar", "*oo*", true ); @@ -434,7 +327,7 @@ void StringTestCase::Match() } -void StringTestCase::CaseChanges() +TEST_CASE("StringCaseChanges", "[wxString]") { wxString s1(wxT("Hello!")); wxString s1u(s1); @@ -442,28 +335,28 @@ void StringTestCase::CaseChanges() s1u.MakeUpper(); s1l.MakeLower(); - CPPUNIT_ASSERT_EQUAL( wxT("HELLO!"), s1u ); - CPPUNIT_ASSERT_EQUAL( wxT("hello!"), s1l ); + CHECK( s1u == wxT("HELLO!") ); + CHECK( s1l == wxT("hello!") ); wxString s2u, s2l; s2u.MakeUpper(); s2l.MakeLower(); - CPPUNIT_ASSERT_EQUAL( "", s2u ); - CPPUNIT_ASSERT_EQUAL( "", s2l ); + CHECK( s2u == "" ); + CHECK( s2l == "" ); wxString s3("good bye"); - CPPUNIT_ASSERT_EQUAL( "Good bye", s3.Capitalize() ); + CHECK( s3.Capitalize() == "Good bye" ); s3.MakeCapitalized(); - CPPUNIT_ASSERT_EQUAL( "Good bye", s3 ); + CHECK( s3 == "Good bye" ); - CPPUNIT_ASSERT_EQUAL( "Abc", wxString("ABC").Capitalize() ); + CHECK( wxString("ABC").Capitalize() == "Abc" ); - CPPUNIT_ASSERT_EQUAL( "", wxString().Capitalize() ); + CHECK( wxString().Capitalize() == "" ); } -void StringTestCase::Compare() +TEST_CASE("StringCompare", "[wxString]") { wxString s1 = wxT("AHH"); wxString eq = wxT("AHH"); @@ -472,31 +365,31 @@ void StringTestCase::Compare() wxString neq3 = wxT("AHHH"); wxString neq4 = wxT("AhH"); - CPPUNIT_ASSERT( s1 == eq ); - CPPUNIT_ASSERT( s1 != neq1 ); - CPPUNIT_ASSERT( s1 != neq2 ); - CPPUNIT_ASSERT( s1 != neq3 ); - CPPUNIT_ASSERT( s1 != neq4 ); + CHECK( s1 == eq ); + CHECK( s1 != neq1 ); + CHECK( s1 != neq2 ); + CHECK( s1 != neq3 ); + CHECK( s1 != neq4 ); - CPPUNIT_ASSERT( s1 == wxT("AHH") ); - CPPUNIT_ASSERT( s1 != wxT("no") ); - CPPUNIT_ASSERT( s1 < wxT("AZ") ); - CPPUNIT_ASSERT( s1 <= wxT("AZ") ); - CPPUNIT_ASSERT( s1 <= wxT("AHH") ); - CPPUNIT_ASSERT( s1 > wxT("AA") ); - CPPUNIT_ASSERT( s1 >= wxT("AA") ); - CPPUNIT_ASSERT( s1 >= wxT("AHH") ); + CHECK( s1 == wxT("AHH") ); + CHECK( s1 != wxT("no") ); + CHECK( s1 < wxT("AZ") ); + CHECK( s1 <= wxT("AZ") ); + CHECK( s1 <= wxT("AHH") ); + CHECK( s1 > wxT("AA") ); + CHECK( s1 >= wxT("AA") ); + CHECK( s1 >= wxT("AHH") ); // test comparison with C strings in Unicode build (must work in ANSI as // well, of course): - CPPUNIT_ASSERT( s1 == "AHH" ); - CPPUNIT_ASSERT( s1 != "no" ); - CPPUNIT_ASSERT( s1 < "AZ" ); - CPPUNIT_ASSERT( s1 <= "AZ" ); - CPPUNIT_ASSERT( s1 <= "AHH" ); - CPPUNIT_ASSERT( s1 > "AA" ); - CPPUNIT_ASSERT( s1 >= "AA" ); - CPPUNIT_ASSERT( s1 >= "AHH" ); + CHECK( s1 == "AHH" ); + CHECK( s1 != "no" ); + CHECK( s1 < "AZ" ); + CHECK( s1 <= "AZ" ); + CHECK( s1 <= "AHH" ); + CHECK( s1 > "AA" ); + CHECK( s1 >= "AA" ); + CHECK( s1 >= "AHH" ); // wxString _s1 = wxT("A\0HH"); // wxString _eq = wxT("A\0HH"); @@ -511,18 +404,18 @@ void StringTestCase::Compare() neq3.insert(1,1,'\0'); neq4.insert(1,1,'\0'); - CPPUNIT_ASSERT( s1 == eq ); - CPPUNIT_ASSERT( s1 != neq1 ); - CPPUNIT_ASSERT( s1 != neq2 ); - CPPUNIT_ASSERT( s1 != neq3 ); - CPPUNIT_ASSERT( s1 != neq4 ); + CHECK( s1 == eq ); + CHECK( s1 != neq1 ); + CHECK( s1 != neq2 ); + CHECK( s1 != neq3 ); + CHECK( s1 != neq4 ); - CPPUNIT_ASSERT( wxString("\n").Cmp(" ") < 0 ); - CPPUNIT_ASSERT( wxString("'").Cmp("!") > 0 ); - CPPUNIT_ASSERT( wxString("!").Cmp("z") < 0 ); + CHECK( wxString("\n").Cmp(" ") < 0 ); + CHECK( wxString("'").Cmp("!") > 0 ); + CHECK( wxString("!").Cmp("z") < 0 ); } -void StringTestCase::CompareNoCase() +TEST_CASE("StringCompareNoCase", "[wxString]") { wxString s1 = wxT("AHH"); wxString eq = wxT("AHH"); @@ -532,16 +425,16 @@ void StringTestCase::CompareNoCase() wxString neq2 = wxT("AH"); wxString neq3 = wxT("AHHH"); - #define CPPUNIT_CNCEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) == 0) - #define CPPUNIT_CNCNEQ_ASSERT(s1, s2) CPPUNIT_ASSERT( s1.CmpNoCase(s2) != 0) + #define CHECK_EQ_NO_CASE(s1, s2) CHECK( s1.CmpNoCase(s2) == 0) + #define CHECK_NEQ_NO_CASE(s1, s2) CHECK( s1.CmpNoCase(s2) != 0) - CPPUNIT_CNCEQ_ASSERT( s1, eq ); - CPPUNIT_CNCEQ_ASSERT( s1, eq2 ); - CPPUNIT_CNCEQ_ASSERT( s1, eq3 ); + CHECK_EQ_NO_CASE( s1, eq ); + CHECK_EQ_NO_CASE( s1, eq2 ); + CHECK_EQ_NO_CASE( s1, eq3 ); - CPPUNIT_CNCNEQ_ASSERT( s1, neq ); - CPPUNIT_CNCNEQ_ASSERT( s1, neq2 ); - CPPUNIT_CNCNEQ_ASSERT( s1, neq3 ); + CHECK_NEQ_NO_CASE( s1, neq ); + CHECK_NEQ_NO_CASE( s1, neq2 ); + CHECK_NEQ_NO_CASE( s1, neq3 ); // wxString _s1 = wxT("A\0HH"); @@ -560,20 +453,20 @@ void StringTestCase::CompareNoCase() neq2.insert(1,1,'\0'); neq3.insert(1,1,'\0'); - CPPUNIT_CNCEQ_ASSERT( s1, eq ); - CPPUNIT_CNCEQ_ASSERT( s1, eq2 ); - CPPUNIT_CNCEQ_ASSERT( s1, eq3 ); + CHECK_EQ_NO_CASE( s1, eq ); + CHECK_EQ_NO_CASE( s1, eq2 ); + CHECK_EQ_NO_CASE( s1, eq3 ); - CPPUNIT_CNCNEQ_ASSERT( s1, neq ); - CPPUNIT_CNCNEQ_ASSERT( s1, neq2 ); - CPPUNIT_CNCNEQ_ASSERT( s1, neq3 ); + CHECK_NEQ_NO_CASE( s1, neq ); + CHECK_NEQ_NO_CASE( s1, neq2 ); + CHECK_NEQ_NO_CASE( s1, neq3 ); - CPPUNIT_ASSERT( wxString("\n").CmpNoCase(" ") < 0 ); - CPPUNIT_ASSERT( wxString("'").CmpNoCase("!") > 0); - CPPUNIT_ASSERT( wxString("!").Cmp("Z") < 0 ); + CHECK( wxString("\n").CmpNoCase(" ") < 0 ); + CHECK( wxString("'").CmpNoCase("!") > 0); + CHECK( wxString("!").Cmp("Z") < 0 ); } -void StringTestCase::Contains() +TEST_CASE("StringContains", "[wxString]") { static const struct ContainsData { @@ -596,7 +489,7 @@ void StringTestCase::Contains() for ( size_t n = 0; n < WXSIZEOF(containsData); n++ ) { const ContainsData& cd = containsData[n]; - CPPUNIT_ASSERT_EQUAL( cd.contains, wxString(cd.hay).Contains(cd.needle) ); + CHECK( wxString(cd.hay).Contains(cd.needle) == cd.contains ); } } @@ -709,7 +602,7 @@ static const struct ToLongData wxGCC_WARNING_RESTORE(missing-field-initializers) -void StringTestCase::ToInt() +TEST_CASE("StringToInt", "[wxString]") { int i; for (size_t n = 0; n < WXSIZEOF(intData); n++) @@ -719,26 +612,25 @@ void StringTestCase::ToInt() if (id.flags & (Number_Unsigned)) continue; - CPPUNIT_ASSERT_EQUAL(id.IsOk(), - wxString(id.str).ToInt(&i, id.base)); + CHECK(id.IsOk() == wxString(id.str).ToInt(&i, id.base)); if (id.IsOk()) - CPPUNIT_ASSERT_EQUAL(id.IValue(), i); + CHECK( i == id.IValue() ); } // special case: check that the output is not modified if the parsing // failed completely i = 17; - CPPUNIT_ASSERT(!wxString("foo").ToInt(&i)); - CPPUNIT_ASSERT_EQUAL(17, i); + CHECK(!wxString("foo").ToInt(&i)); + CHECK( i == 17 ); // also check that it is modified if we did parse something successfully in // the beginning of the string - CPPUNIT_ASSERT(!wxString("9 cats").ToInt(&i)); - CPPUNIT_ASSERT_EQUAL(9, i); + CHECK(!wxString("9 cats").ToInt(&i)); + CHECK( i == 9 ); } -void StringTestCase::ToUInt() +TEST_CASE("StringToUInt", "[wxString]") { unsigned int i; for (size_t n = 0; n < WXSIZEOF(intData); n++) @@ -748,26 +640,25 @@ void StringTestCase::ToUInt() if (id.flags & (Number_Signed)) continue; - CPPUNIT_ASSERT_EQUAL(id.IsOk(), - wxString(id.str).ToUInt(&i, id.base)); + CHECK(id.IsOk() == wxString(id.str).ToUInt(&i, id.base)); if (id.IsOk()) - CPPUNIT_ASSERT_EQUAL(id.UIValue(), i); + CHECK( i == id.UIValue() ); } // special case: check that the output is not modified if the parsing // failed completely i = 17; - CPPUNIT_ASSERT(!wxString("foo").ToUInt(&i)); - CPPUNIT_ASSERT_EQUAL(17, i); + CHECK(!wxString("foo").ToUInt(&i)); + CHECK( i == 17 ); // also check that it is modified if we did parse something successfully in // the beginning of the string - CPPUNIT_ASSERT(!wxString("9 cats").ToUInt(&i)); - CPPUNIT_ASSERT_EQUAL(9, i); + CHECK(!wxString("9 cats").ToUInt(&i)); + CHECK( i == 9 ); } -void StringTestCase::ToLong() +TEST_CASE("StringToLong", "[wxString]") { long l; for ( size_t n = 0; n < WXSIZEOF(longData); n++ ) @@ -780,30 +671,28 @@ void StringTestCase::ToLong() // NOTE: unless you're using some exotic locale, ToCLong and ToLong // should behave the same for our test data set: - CPPUNIT_ASSERT_EQUAL( ld.IsOk(), - wxString(ld.str).ToCLong(&l, ld.base) ); + CHECK( ld.IsOk() == wxString(ld.str).ToCLong(&l, ld.base) ); if ( ld.IsOk() ) - CPPUNIT_ASSERT_EQUAL( ld.LValue(), l ); + CHECK( l == ld.LValue() ); - CPPUNIT_ASSERT_EQUAL( ld.IsOk(), - wxString(ld.str).ToLong(&l, ld.base) ); + CHECK( ld.IsOk() == wxString(ld.str).ToLong(&l, ld.base) ); if ( ld.IsOk() ) - CPPUNIT_ASSERT_EQUAL( ld.LValue(), l ); + CHECK( l == ld.LValue() ); } // special case: check that the output is not modified if the parsing // failed completely l = 17; - CPPUNIT_ASSERT( !wxString("foo").ToLong(&l) ); - CPPUNIT_ASSERT_EQUAL( 17, l ); + CHECK( !wxString("foo").ToLong(&l) ); + CHECK( l == 17 ); // also check that it is modified if we did parse something successfully in // the beginning of the string - CPPUNIT_ASSERT( !wxString("9 cats").ToLong(&l) ); - CPPUNIT_ASSERT_EQUAL( 9, l ); + CHECK( !wxString("9 cats").ToLong(&l) ); + CHECK( l == 9 ); } -void StringTestCase::ToULong() +TEST_CASE("StringToULong", "[wxString]") { unsigned long ul; for ( size_t n = 0; n < WXSIZEOF(longData); n++ ) @@ -816,21 +705,19 @@ void StringTestCase::ToULong() // NOTE: unless you're using some exotic locale, ToCLong and ToLong // should behave the same for our test data set: - CPPUNIT_ASSERT_EQUAL( ld.IsOk(), - wxString(ld.str).ToCULong(&ul, ld.base) ); + CHECK( ld.IsOk() == wxString(ld.str).ToCULong(&ul, ld.base) ); if ( ld.IsOk() ) - CPPUNIT_ASSERT_EQUAL( ld.ULValue(), ul ); + CHECK( ul == ld.ULValue() ); - CPPUNIT_ASSERT_EQUAL( ld.IsOk(), - wxString(ld.str).ToULong(&ul, ld.base) ); + CHECK( ld.IsOk() == wxString(ld.str).ToULong(&ul, ld.base) ); if ( ld.IsOk() ) - CPPUNIT_ASSERT_EQUAL( ld.ULValue(), ul ); + CHECK( ul == ld.ULValue() ); } } #ifdef wxLongLong_t -void StringTestCase::ToLongLong() +TEST_CASE("StringToLongLong", "[wxString]") { wxLongLong_t l; for ( size_t n = 0; n < WXSIZEOF(longData); n++ ) @@ -840,14 +727,13 @@ void StringTestCase::ToLongLong() if ( ld.flags & (Number_Long | Number_Unsigned) ) continue; - CPPUNIT_ASSERT_EQUAL( ld.IsOk(), - wxString(ld.str).ToLongLong(&l, ld.base) ); + CHECK( ld.IsOk() == wxString(ld.str).ToLongLong(&l, ld.base) ); if ( ld.IsOk() ) - CPPUNIT_ASSERT_EQUAL( ld.LLValue(), l ); + CHECK( l == ld.LLValue() ); } } -void StringTestCase::ToULongLong() +TEST_CASE("StringToULongLong", "[wxString]") { wxULongLong_t ul; for ( size_t n = 0; n < WXSIZEOF(longData); n++ ) @@ -857,16 +743,15 @@ void StringTestCase::ToULongLong() if ( ld.flags & (Number_Long | Number_Signed) ) continue; - CPPUNIT_ASSERT_EQUAL( ld.IsOk(), - wxString(ld.str).ToULongLong(&ul, ld.base) ); + CHECK( ld.IsOk() == wxString(ld.str).ToULongLong(&ul, ld.base) ); if ( ld.IsOk() ) - CPPUNIT_ASSERT_EQUAL( ld.ULLValue(), ul ); + CHECK( ul == ld.ULLValue() ); } } #endif // wxLongLong_t -void StringTestCase::ToDouble() +TEST_CASE("StringToDouble", "[wxString]") { double d; static const struct ToDoubleData @@ -896,9 +781,9 @@ void StringTestCase::ToDouble() for ( n = 0; n < WXSIZEOF(doubleData); n++ ) { const ToDoubleData& ld = doubleData[n]; - CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToCDouble(&d) ); + CHECK( wxString(ld.str).ToCDouble(&d) == ld.ok ); if ( ld.ok ) - CPPUNIT_ASSERT_EQUAL( ld.value, d ); + CHECK( d == ld.value ); } @@ -912,7 +797,7 @@ void StringTestCase::ToDouble() wxLocale locale; // don't load default catalog, it may be unavailable: - CPPUNIT_ASSERT( locale.Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT) ); + CHECK( locale.Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT) ); static const struct ToDoubleData doubleData2[] = { @@ -933,13 +818,13 @@ void StringTestCase::ToDouble() for ( n = 0; n < WXSIZEOF(doubleData2); n++ ) { const ToDoubleData& ld = doubleData2[n]; - CPPUNIT_ASSERT_EQUAL( ld.ok, wxString(ld.str).ToDouble(&d) ); + CHECK( wxString(ld.str).ToDouble(&d) == ld.ok ); if ( ld.ok ) - CPPUNIT_ASSERT_EQUAL( ld.value, d ); + CHECK( d == ld.value ); } } -void StringTestCase::FromDouble() +TEST_CASE("StringFromDouble", "[wxString]") { static const struct FromDoubleTestData { @@ -964,14 +849,14 @@ void StringTestCase::FromDouble() for ( unsigned n = 0; n < WXSIZEOF(testData); n++ ) { const FromDoubleTestData& td = testData[n]; - CPPUNIT_ASSERT_EQUAL( td.str, wxString::FromCDouble(td.value, td.prec) ); + CHECK( wxString::FromCDouble(td.value, td.prec) == td.str ); } if ( !wxLocale::IsAvailable(wxLANGUAGE_FRENCH) ) return; wxLocale locale; - CPPUNIT_ASSERT( locale.Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT) ); + CHECK( locale.Init(wxLANGUAGE_FRENCH, wxLOCALE_DONT_LOAD_DEFAULT) ); for ( unsigned m = 0; m < WXSIZEOF(testData); m++ ) { @@ -979,37 +864,37 @@ void StringTestCase::FromDouble() wxString str(td.str); str.Replace(".", ","); - CPPUNIT_ASSERT_EQUAL( str, wxString::FromDouble(td.value, td.prec) ); + CHECK( wxString::FromDouble(td.value, td.prec) == str ); } } -void StringTestCase::StringBuf() +TEST_CASE("StringStringBuf", "[wxString]") { // check that buffer can be used to write into the string wxString s; wxStrcpy(wxStringBuffer(s, 10), wxT("foo")); - CPPUNIT_ASSERT_EQUAL(3, s.length()); - CPPUNIT_ASSERT(wxT('f') == s[0u]); - CPPUNIT_ASSERT(wxT('o') == s[1]); - CPPUNIT_ASSERT(wxT('o') == s[2]); + CHECK( s.length() == 3 ); + CHECK(wxT('f') == s[0u]); + CHECK(wxT('o') == s[1]); + CHECK(wxT('o') == s[2]); { // also check that the buffer initially contains the original string // contents wxStringBuffer buf(s, 10); - CPPUNIT_ASSERT_EQUAL( wxT('f'), buf[0] ); - CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[1] ); - CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[2] ); - CPPUNIT_ASSERT_EQUAL( wxT('\0'), buf[3] ); + CHECK( buf[0] == wxT('f') ); + CHECK( buf[1] == wxT('o') ); + CHECK( buf[2] == wxT('o') ); + CHECK( buf[3] == wxT('\0') ); } { wxStringBufferLength buf(s, 10); - CPPUNIT_ASSERT_EQUAL( wxT('f'), buf[0] ); - CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[1] ); - CPPUNIT_ASSERT_EQUAL( wxT('o'), buf[2] ); - CPPUNIT_ASSERT_EQUAL( wxT('\0'), buf[3] ); + CHECK( buf[0] == wxT('f') ); + CHECK( buf[1] == wxT('o') ); + CHECK( buf[2] == wxT('o') ); + CHECK( buf[3] == wxT('\0') ); // and check that it can be used to write only the specified number of // characters to the string @@ -1017,11 +902,11 @@ void StringTestCase::StringBuf() buf.SetLength(4); } - CPPUNIT_ASSERT_EQUAL(4, s.length()); - CPPUNIT_ASSERT(wxT('b') == s[0u]); - CPPUNIT_ASSERT(wxT('a') == s[1]); - CPPUNIT_ASSERT(wxT('r') == s[2]); - CPPUNIT_ASSERT(wxT('r') == s[3]); + CHECK( s.length() == 4 ); + CHECK(wxT('b') == s[0u]); + CHECK(wxT('a') == s[1]); + CHECK(wxT('r') == s[2]); + CHECK(wxT('r') == s[3]); // check that creating buffer of length smaller than string works, i.e. at // least doesn't crash (it would if we naively copied the entire original @@ -1029,7 +914,7 @@ void StringTestCase::StringBuf() *wxStringBuffer(s, 1) = '!'; } -void StringTestCase::UTF8Buf() +TEST_CASE("StringUTF8Buf", "[wxString]") { // "czech" in Czech ("cestina"): static const char *textUTF8 = "\304\215e\305\241tina"; @@ -1037,30 +922,23 @@ void StringTestCase::UTF8Buf() wxString s; wxStrcpy(wxUTF8StringBuffer(s, 9), textUTF8); - CPPUNIT_ASSERT(s == textUTF16); + CHECK(s == textUTF16); { wxUTF8StringBufferLength buf(s, 20); wxStrcpy(buf, textUTF8); buf.SetLength(5); } - CPPUNIT_ASSERT(s == wxString(textUTF16, 0, 3)); + CHECK(s == wxString(textUTF16, 0, 3)); } - -void StringTestCase::CStrDataTernaryOperator() -{ - DoCStrDataTernaryOperator(true); - DoCStrDataTernaryOperator(false); -} - template bool CheckStr(const wxString& expected, T s) { return expected == wxString(s); } -void StringTestCase::DoCStrDataTernaryOperator(bool cond) +void DoCStrDataTernaryOperator(bool cond) { // test compilation of wxCStrData when used with operator?: (the asserts // are not very important, we're testing if the code compiles at all): @@ -1074,39 +952,46 @@ void StringTestCase::DoCStrDataTernaryOperator(bool cond) wxCLANG_WARNING_SUPPRESS(c++11-compat-deprecated-writable-strings) const wchar_t *wcStr = L"foo"; - CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : wcStr)) ); - CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : L"foo")) ); - CPPUNIT_ASSERT( CheckStr(s, (cond ? wcStr : s.c_str())) ); - CPPUNIT_ASSERT( CheckStr(s, (cond ? L"foo" : s.c_str())) ); + CHECK( CheckStr(s, (cond ? s.c_str() : wcStr)) ); + CHECK( CheckStr(s, (cond ? s.c_str() : L"foo")) ); + CHECK( CheckStr(s, (cond ? wcStr : s.c_str())) ); + CHECK( CheckStr(s, (cond ? L"foo" : s.c_str())) ); const char *mbStr = "foo"; - CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : mbStr)) ); - CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : "foo")) ); - CPPUNIT_ASSERT( CheckStr(s, (cond ? mbStr : s.c_str())) ); - CPPUNIT_ASSERT( CheckStr(s, (cond ? "foo" : s.c_str())) ); + CHECK( CheckStr(s, (cond ? s.c_str() : mbStr)) ); + CHECK( CheckStr(s, (cond ? s.c_str() : "foo")) ); + CHECK( CheckStr(s, (cond ? mbStr : s.c_str())) ); + CHECK( CheckStr(s, (cond ? "foo" : s.c_str())) ); wxGCC_WARNING_RESTORE(write-strings) wxCLANG_WARNING_RESTORE(c++11-compat-deprecated-writable-strings) wxString empty(""); - CPPUNIT_ASSERT( CheckStr(empty, (cond ? empty.c_str() : wxEmptyString)) ); - CPPUNIT_ASSERT( CheckStr(empty, (cond ? wxEmptyString : empty.c_str())) ); + CHECK( CheckStr(empty, (cond ? empty.c_str() : wxEmptyString)) ); + CHECK( CheckStr(empty, (cond ? wxEmptyString : empty.c_str())) ); } -void StringTestCase::CStrDataOperators() +TEST_CASE("StringCStrDataTernaryOperator", "[wxString]") +{ + DoCStrDataTernaryOperator(true); + DoCStrDataTernaryOperator(false); +} + + +TEST_CASE("StringCStrDataOperators", "[wxString]") { wxString s("hello"); - CPPUNIT_ASSERT( s.c_str()[0] == 'h' ); - CPPUNIT_ASSERT( s.c_str()[1] == 'e' ); + CHECK( s.c_str()[0] == 'h' ); + CHECK( s.c_str()[1] == 'e' ); // IMPORTANT: at least with the CRT coming with MSVC++ 2008 trying to access // the final character results in an assert failure (with debug CRT) - //CPPUNIT_ASSERT( s.c_str()[5] == '\0' ); + //CHECK( s.c_str()[5] == '\0' ); - CPPUNIT_ASSERT( *s.c_str() == 'h' ); - CPPUNIT_ASSERT( *(s.c_str() + 2) == 'l' ); - //CPPUNIT_ASSERT( *(s.c_str() + 5) == '\0' ); + CHECK( *s.c_str() == 'h' ); + CHECK( *(s.c_str() + 2) == 'l' ); + //CHECK( *(s.c_str() + 5) == '\0' ); } bool CheckStrChar(const wxString& expected, char *s) @@ -1118,48 +1003,48 @@ bool CheckStrConstChar(const wxString& expected, const char *s) bool CheckStrConstWChar(const wxString& expected, const wchar_t *s) { return CheckStr(expected, s); } -void StringTestCase::CStrDataImplicitConversion() +TEST_CASE("StringCStrDataImplicitConversion", "[wxString]") { wxString s("foo"); - CPPUNIT_ASSERT( CheckStrConstWChar(s, s.c_str()) ); - CPPUNIT_ASSERT( CheckStrConstChar(s, s.c_str()) ); + CHECK( CheckStrConstWChar(s, s.c_str()) ); + CHECK( CheckStrConstChar(s, s.c_str()) ); // implicit conversion of wxString is not available in STL build #if !wxUSE_STL - CPPUNIT_ASSERT( CheckStrConstWChar(s, s) ); + CHECK( CheckStrConstWChar(s, s) ); #if wxUSE_UNSAFE_WXSTRING_CONV - CPPUNIT_ASSERT( CheckStrConstChar(s, s) ); + CHECK( CheckStrConstChar(s, s) ); #endif #endif } -void StringTestCase::ExplicitConversion() +TEST_CASE("StringExplicitConversion", "[wxString]") { wxString s("foo"); - CPPUNIT_ASSERT( CheckStr(s, s.mb_str()) ); - CPPUNIT_ASSERT( CheckStrConstChar(s, s.mb_str()) ); - CPPUNIT_ASSERT( CheckStrChar(s, s.char_str()) ); + CHECK( CheckStr(s, s.mb_str()) ); + CHECK( CheckStrConstChar(s, s.mb_str()) ); + CHECK( CheckStrChar(s, s.char_str()) ); - CPPUNIT_ASSERT( CheckStr(s, s.wc_str()) ); - CPPUNIT_ASSERT( CheckStrConstWChar(s, s.wc_str()) ); - CPPUNIT_ASSERT( CheckStrWChar(s, s.wchar_str()) ); + CHECK( CheckStr(s, s.wc_str()) ); + CHECK( CheckStrConstWChar(s, s.wc_str()) ); + CHECK( CheckStrWChar(s, s.wchar_str()) ); } -void StringTestCase::IndexedAccess() +TEST_CASE("StringIndexedAccess", "[wxString]") { wxString s("bar"); - CPPUNIT_ASSERT_EQUAL( 'r', (char)s[2] ); + CHECK( (char)s[2] == 'r' ); // this tests for a possible bug in UTF-8 based wxString implementation: // the 3rd character of the underlying byte string is going to change, but // the 3rd character of wxString should remain the same s[0] = L'\xe9'; - CPPUNIT_ASSERT_EQUAL( 'r', (char)s[2] ); + CHECK( (char)s[2] == 'r' ); } -void StringTestCase::BeforeAndAfter() +TEST_CASE("StringBeforeAndAfter", "[wxString]") { // Construct a string with 2 equal signs in it by concatenating its three // parts: before the first "=", in between the two "="s and after the last @@ -1173,33 +1058,33 @@ void StringTestCase::BeforeAndAfter() wxString r; - CPPUNIT_ASSERT_EQUAL( FIRST_PART, s.BeforeFirst('=', &r) ); - CPPUNIT_ASSERT_EQUAL( MIDDLE_PART wxT("=") LAST_PART, r ); + CHECK( s.BeforeFirst('=', &r) == FIRST_PART ); + CHECK( r == MIDDLE_PART wxT("=") LAST_PART ); - CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!', &r) ); - CPPUNIT_ASSERT_EQUAL( "", r ); + CHECK( s.BeforeFirst('!', &r) == s ); + CHECK( r == "" ); - CPPUNIT_ASSERT_EQUAL( FIRST_PART wxT("=") MIDDLE_PART, s.BeforeLast('=', &r) ); - CPPUNIT_ASSERT_EQUAL( LAST_PART, r ); + CHECK( s.BeforeLast('=', &r) == FIRST_PART wxT("=") MIDDLE_PART ); + CHECK( r == LAST_PART ); - CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!', &r) ); - CPPUNIT_ASSERT_EQUAL( s, r ); + CHECK( s.BeforeLast('!', &r) == "" ); + CHECK( r == s ); - CPPUNIT_ASSERT_EQUAL( MIDDLE_PART wxT("=") LAST_PART, s.AfterFirst('=') ); - CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') ); + CHECK( s.AfterFirst('=') == MIDDLE_PART wxT("=") LAST_PART ); + CHECK( s.AfterFirst('!') == "" ); - CPPUNIT_ASSERT_EQUAL( LAST_PART, s.AfterLast('=') ); - CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') ); + CHECK( s.AfterLast('=') == LAST_PART ); + CHECK( s.AfterLast('!') == s ); #undef LAST_PART #undef MIDDLE_PART #undef FIRST_PART } -void StringTestCase::ScopedBuffers() +TEST_CASE("StringScopedBuffers", "[wxString]") { // wxString relies on efficient buffers, verify they work as they should @@ -1207,49 +1092,49 @@ void StringTestCase::ScopedBuffers() // non-owned buffer points to the string passed to it wxScopedCharBuffer sbuf = wxScopedCharBuffer::CreateNonOwned(literal); - CPPUNIT_ASSERT( sbuf.data() == literal ); + CHECK( sbuf.data() == literal ); // a copy of scoped non-owned buffer still points to the same string wxScopedCharBuffer sbuf2(sbuf); - CPPUNIT_ASSERT( sbuf.data() == sbuf2.data() ); + CHECK( sbuf.data() == sbuf2.data() ); // but assigning it to wxCharBuffer makes a full copy wxCharBuffer buf(sbuf); - CPPUNIT_ASSERT( buf.data() != literal ); - CPPUNIT_ASSERT_EQUAL( std::string(literal), buf.data() ); + CHECK( buf.data() != literal ); + CHECK( buf.data() == std::string(literal) ); wxCharBuffer buf2 = sbuf; - CPPUNIT_ASSERT( buf2.data() != literal ); - CPPUNIT_ASSERT_EQUAL( std::string(literal), buf.data() ); + CHECK( buf2.data() != literal ); + CHECK( buf.data() == std::string(literal) ); // Check that extending the buffer keeps it NUL-terminated. size_t len = 10; wxCharBuffer buf3(len); - CPPUNIT_ASSERT_EQUAL('\0', buf3.data()[len]); + CHECK( buf3.data()[len] == '\0' ); wxCharBuffer buf4; buf4.extend(len); - CPPUNIT_ASSERT_EQUAL('\0', buf4.data()[len]); + CHECK( buf4.data()[len] == '\0' ); wxCharBuffer buf5(5); buf5.extend(len); - CPPUNIT_ASSERT_EQUAL('\0', buf5.data()[len]); + CHECK( buf5.data()[len] == '\0' ); } -void StringTestCase::SupplementaryUniChar() +TEST_CASE("StringSupplementaryUniChar", "[wxString]") { // Test wxString(wxUniChar ch, size_t nRepeat = 1), // which is implemented upon assign(size_t n, wxUniChar ch). { wxString s(wxUniChar(0x12345)); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(2, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD808, s[0].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDF45, s[1].GetValue()); + CHECK( s.length() == 2 ); + CHECK( s[0].GetValue() == 0xD808 ); + CHECK( s[1].GetValue() == 0xDF45 ); #else - CPPUNIT_ASSERT_EQUAL(1, s.length()); - CPPUNIT_ASSERT_EQUAL(0x12345, s[0].GetValue()); + CHECK( s.length() == 1 ); + CHECK( s[0].GetValue() == 0x12345 ); #endif } @@ -1258,12 +1143,12 @@ void StringTestCase::SupplementaryUniChar() wxString s; s = wxUniChar(0x23456); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(2, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD84D, s[0].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDC56, s[1].GetValue()); + CHECK( s.length() == 2 ); + CHECK( s[0].GetValue() == 0xD84D ); + CHECK( s[1].GetValue() == 0xDC56 ); #else - CPPUNIT_ASSERT_EQUAL(1, s.length()); - CPPUNIT_ASSERT_EQUAL(0x23456, s[0].GetValue()); + CHECK( s.length() == 1 ); + CHECK( s[0].GetValue() == 0x23456 ); #endif } @@ -1272,12 +1157,12 @@ void StringTestCase::SupplementaryUniChar() wxString s = "A"; s += wxUniChar(0x34567); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(3, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD891, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDD67, s[2].GetValue()); + CHECK( s.length() == 3 ); + CHECK( s[1].GetValue() == 0xD891 ); + CHECK( s[2].GetValue() == 0xDD67 ); #else - CPPUNIT_ASSERT_EQUAL(2, s.length()); - CPPUNIT_ASSERT_EQUAL(0x34567, s[1].GetValue()); + CHECK( s.length() == 2 ); + CHECK( s[1].GetValue() == 0x34567 ); #endif } @@ -1287,12 +1172,12 @@ void StringTestCase::SupplementaryUniChar() wxString s = "A"; s << wxUniChar(0x45678); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(3, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD8D5, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDE78, s[2].GetValue()); + CHECK( s.length() == 3 ); + CHECK( s[1].GetValue() == 0xD8D5 ); + CHECK( s[2].GetValue() == 0xDE78 ); #else - CPPUNIT_ASSERT_EQUAL(2, s.length()); - CPPUNIT_ASSERT_EQUAL(0x45678, s[1].GetValue()); + CHECK( s.length() == 2 ); + CHECK( s[1].GetValue() == 0x45678 ); #endif } @@ -1301,15 +1186,15 @@ void StringTestCase::SupplementaryUniChar() wxString s = L"\x3042\x208\x3059"; s.insert(1, 2, wxUniChar(0x12345)); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(7, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD808, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDF45, s[2].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xD808, s[3].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDF45, s[4].GetValue()); + CHECK( s.length() == 7 ); + CHECK( s[1].GetValue() == 0xD808 ); + CHECK( s[2].GetValue() == 0xDF45 ); + CHECK( s[3].GetValue() == 0xD808 ); + CHECK( s[4].GetValue() == 0xDF45 ); #else - CPPUNIT_ASSERT_EQUAL(5, s.length()); - CPPUNIT_ASSERT_EQUAL(0x12345, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0x12345, s[2].GetValue()); + CHECK( s.length() == 5 ); + CHECK( s[1].GetValue() == 0x12345 ); + CHECK( s[2].GetValue() == 0x12345 ); #endif } @@ -1318,12 +1203,12 @@ void StringTestCase::SupplementaryUniChar() wxString s = L"\x3042\x208\x3059"; s.insert(s.begin() + 1, wxUniChar(0x23456)); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(5, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD84D, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDC56, s[2].GetValue()); + CHECK( s.length() == 5 ); + CHECK( s[1].GetValue() == 0xD84D ); + CHECK( s[2].GetValue() == 0xDC56 ); #else - CPPUNIT_ASSERT_EQUAL(4, s.length()); - CPPUNIT_ASSERT_EQUAL(0x23456, s[1].GetValue()); + CHECK( s.length() == 4 ); + CHECK( s[1].GetValue() == 0x23456 ); #endif } @@ -1332,12 +1217,12 @@ void StringTestCase::SupplementaryUniChar() wxString s = L"\x3042\x208\x3059"; s.insert(s.begin() + 1, 2, wxUniChar(0x34567)); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(7, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD891, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDD67, s[2].GetValue()); + CHECK( s.length() == 7 ); + CHECK( s[1].GetValue() == 0xD891 ); + CHECK( s[2].GetValue() == 0xDD67 ); #else - CPPUNIT_ASSERT_EQUAL(5, s.length()); - CPPUNIT_ASSERT_EQUAL(0x34567, s[1].GetValue()); + CHECK( s.length() == 5 ); + CHECK( s[1].GetValue() == 0x34567 ); #endif } @@ -1346,15 +1231,15 @@ void StringTestCase::SupplementaryUniChar() wxString s = L"\x3042\x208\x3059"; s.replace(1, 2, 2, wxUniChar(0x45678)); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(5, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD8D5, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDE78, s[2].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xD8D5, s[3].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDE78, s[4].GetValue()); + CHECK( s.length() == 5 ); + CHECK( s[1].GetValue() == 0xD8D5 ); + CHECK( s[2].GetValue() == 0xDE78 ); + CHECK( s[3].GetValue() == 0xD8D5 ); + CHECK( s[4].GetValue() == 0xDE78 ); #else - CPPUNIT_ASSERT_EQUAL(3, s.length()); - CPPUNIT_ASSERT_EQUAL(0x45678, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0x45678, s[2].GetValue()); + CHECK( s.length() == 3 ); + CHECK( s[1].GetValue() == 0x45678 ); + CHECK( s[2].GetValue() == 0x45678 ); #endif } @@ -1363,15 +1248,15 @@ void StringTestCase::SupplementaryUniChar() wxString s = L"\x3042\x208\x3059"; s.replace(s.begin() + 1, s.end(), 2, wxUniChar(0x34567)); #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(5, s.length()); - CPPUNIT_ASSERT_EQUAL(0xD891, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDD67, s[2].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xD891, s[3].GetValue()); - CPPUNIT_ASSERT_EQUAL(0xDD67, s[4].GetValue()); + CHECK( s.length() == 5 ); + CHECK( s[1].GetValue() == 0xD891 ); + CHECK( s[2].GetValue() == 0xDD67 ); + CHECK( s[3].GetValue() == 0xD891 ); + CHECK( s[4].GetValue() == 0xDD67 ); #else - CPPUNIT_ASSERT_EQUAL(3, s.length()); - CPPUNIT_ASSERT_EQUAL(0x34567, s[1].GetValue()); - CPPUNIT_ASSERT_EQUAL(0x34567, s[2].GetValue()); + CHECK( s.length() == 3 ); + CHECK( s[1].GetValue() == 0x34567 ); + CHECK( s[2].GetValue() == 0x34567 ); #endif } @@ -1384,17 +1269,17 @@ void StringTestCase::SupplementaryUniChar() s += wxUniChar(0x12345); s += "y"; #if wxUSE_UNICODE_UTF16 - CPPUNIT_ASSERT_EQUAL(8, s.length()); - CPPUNIT_ASSERT_EQUAL(2, s.find(wxUniChar(0x12345))); - CPPUNIT_ASSERT_EQUAL(5, s.find(wxUniChar(0x12345), 3)); - CPPUNIT_ASSERT_EQUAL(5, s.rfind(wxUniChar(0x12345))); - CPPUNIT_ASSERT_EQUAL(2, s.rfind(wxUniChar(0x12345), 4)); + CHECK( s.length() == 8 ); + CHECK( s.find(wxUniChar(0x12345)) == 2 ); + CHECK( s.find(wxUniChar(0x12345), 3) == 5 ); + CHECK( s.rfind(wxUniChar(0x12345)) == 5 ); + CHECK( s.rfind(wxUniChar(0x12345), 4) == 2 ); #else - CPPUNIT_ASSERT_EQUAL(6, s.length()); - CPPUNIT_ASSERT_EQUAL(2, s.find(wxUniChar(0x12345))); - CPPUNIT_ASSERT_EQUAL(4, s.find(wxUniChar(0x12345), 3)); - CPPUNIT_ASSERT_EQUAL(4, s.rfind(wxUniChar(0x12345))); - CPPUNIT_ASSERT_EQUAL(2, s.rfind(wxUniChar(0x12345), 3)); + CHECK( s.length() == 6 ); + CHECK( s.find(wxUniChar(0x12345)) == 2 ); + CHECK( s.find(wxUniChar(0x12345), 3) == 4 ); + CHECK( s.rfind(wxUniChar(0x12345)) == 4 ); + CHECK( s.rfind(wxUniChar(0x12345), 3) == 2 ); #endif }