X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/52de37c78f31bc03f8b96090932c7ce8c3907d29..4f2511d706e5274a34e1521e11c1b95fed735b42:/tests/strings/crt.cpp diff --git a/tests/strings/crt.cpp b/tests/strings/crt.cpp index ee9c19d92b..70ad0d9fed 100644 --- a/tests/strings/crt.cpp +++ b/tests/strings/crt.cpp @@ -24,6 +24,14 @@ #include "wx/textfile.h" +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +static const char *strMB = "hello, world"; +static const wchar_t *strWC = L"hello, world"; +static const wxString strWX("hello, world"); + // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- @@ -39,12 +47,14 @@ private: CPPUNIT_TEST( Strcmp ); CPPUNIT_TEST( Strspn ); CPPUNIT_TEST( Strcspn ); + CPPUNIT_TEST( Strpbrk ); CPPUNIT_TEST_SUITE_END(); void SetGetEnv(); void Strcmp(); void Strspn(); void Strcspn(); + void Strpbrk(); DECLARE_NO_COPY_CLASS(CrtTestCase) }; @@ -130,49 +140,72 @@ void CrtTestCase::Strcmp() void CrtTestCase::Strspn() { - const char *strMB = "hello, world"; - const char *strWC = "hello, world"; - const wxString strWX("hello, world"); - - CPPUNIT_ASSERT( wxStrspn(strMB, "xyz") == 0 ); - CPPUNIT_ASSERT( wxStrspn(strWC, "xyz") == 0 ); - CPPUNIT_ASSERT( wxStrspn(strWX, "xyz") == 0 ); - CPPUNIT_ASSERT( wxStrspn(strMB, L"xyz") == 0 ); - CPPUNIT_ASSERT( wxStrspn(strWC, L"xyz") == 0 ); - CPPUNIT_ASSERT( wxStrspn(strWX, L"xyz") == 0 ); - - CPPUNIT_ASSERT( wxStrspn(strMB, "hleo") == 5 ); - CPPUNIT_ASSERT( wxStrspn(strWC, "hleo") == 5 ); - CPPUNIT_ASSERT( wxStrspn(strWX, "hleo") == 5 ); - - CPPUNIT_ASSERT( wxStrspn(strMB, "ld") == 0 ); - CPPUNIT_ASSERT( wxStrspn(strWC, "ld") == 0 ); - CPPUNIT_ASSERT( wxStrspn(strWX, "ld") == 0 ); - - CPPUNIT_ASSERT( wxStrspn(strMB, strWC) == strWX.length() ); - CPPUNIT_ASSERT( wxStrspn(strWC, strWX) == strWX.length() ); - CPPUNIT_ASSERT( wxStrspn(strWX, strMB) == strWX.length() ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strMB, "xyz") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strWC, "xyz") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strWX, "xyz") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strMB, L"xyz") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strWC, L"xyz") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strWX, L"xyz") ); + + CPPUNIT_ASSERT_EQUAL( (size_t)5, wxStrspn(strMB, "hleo") ); + CPPUNIT_ASSERT_EQUAL( (size_t)5, wxStrspn(strWC, "hleo") ); + CPPUNIT_ASSERT_EQUAL( (size_t)5, wxStrspn(strWX, "hleo") ); + + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strMB, "ld") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strWC, "ld") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrspn(strWX, "ld") ); + + CPPUNIT_ASSERT_EQUAL( strWX.length(), wxStrspn(strMB, strWC) ); + CPPUNIT_ASSERT_EQUAL( strWX.length(), wxStrspn(strWC, strWX) ); + CPPUNIT_ASSERT_EQUAL( strWX.length(), wxStrspn(strWX, strMB) ); } void CrtTestCase::Strcspn() { - const char *strMB = "hello, world"; - const char *strWC = "hello, world"; - const wxString strWX("hello, world"); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrcspn(strMB, strWX) ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrcspn(strWC, strMB) ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrcspn(strWX, strWC) ); - CPPUNIT_ASSERT( wxStrcspn(strMB, strWX) == 0 ); - CPPUNIT_ASSERT( wxStrcspn(strWC, strMB) == 0 ); - CPPUNIT_ASSERT( wxStrcspn(strWX, strWC) == 0 ); + CPPUNIT_ASSERT_EQUAL( (size_t)5, wxStrcspn(strMB, ", ") ); + CPPUNIT_ASSERT_EQUAL( (size_t)5, wxStrcspn(strWC, ", ") ); + CPPUNIT_ASSERT_EQUAL( (size_t)5, wxStrcspn(strWX, ", ") ); - CPPUNIT_ASSERT( wxStrcspn(strMB, ", ") == 5 ); - CPPUNIT_ASSERT( wxStrcspn(strWC, ", ") == 5 ); - CPPUNIT_ASSERT( wxStrcspn(strWX, ", ") == 5 ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrcspn(strMB, "hel") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrcspn(strWC, "hel") ); + CPPUNIT_ASSERT_EQUAL( (size_t)0, wxStrcspn(strWX, "hel") ); - CPPUNIT_ASSERT( wxStrcspn(strMB, "hel") == 0 ); - CPPUNIT_ASSERT( wxStrcspn(strWC, "hel") == 0 ); - CPPUNIT_ASSERT( wxStrcspn(strWX, "hel") == 0 ); + CPPUNIT_ASSERT_EQUAL( strWX.length(), wxStrcspn(strMB, "xy") ); + CPPUNIT_ASSERT_EQUAL( strWX.length(), wxStrcspn(strWC, "xy") ); + CPPUNIT_ASSERT_EQUAL( strWX.length(), wxStrcspn(strWX, "xy") ); +} - CPPUNIT_ASSERT( wxStrcspn(strMB, "xy") == strWX.length() ); - CPPUNIT_ASSERT( wxStrcspn(strWC, "xy") == strWX.length() ); - CPPUNIT_ASSERT( wxStrcspn(strWX, "xy") == strWX.length() ); +void CrtTestCase::Strpbrk() +{ + const wxString s(", "); + + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strMB, ", ") ); + CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWC, L", ") ); + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strWX, ", ") ); + CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWX, L", ") ); + + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strMB, s) ); + CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWC, s) ); + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strWX, s) ); + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strWX.c_str(), s) ); + + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strMB, s.c_str()) ); + CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWC, s.c_str()) ); + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strWX, s.c_str()) ); + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strWX.c_str(), s.c_str()) ); + + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strMB, s.mb_str()) ); + CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWC, s.wc_str()) ); + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strWX, s.mb_str()) ); + CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWX, s.wc_str()) ); + CPPUNIT_ASSERT_EQUAL( ',', *wxStrpbrk(strWX.c_str(), s.mb_str()) ); + CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWX.c_str(), s.wc_str()) ); + + CPPUNIT_ASSERT_EQUAL( (const char *)NULL, wxStrpbrk(strWX, "xyz") ); + CPPUNIT_ASSERT_EQUAL( (const wchar_t *)NULL, wxStrpbrk(strWX.c_str(), L"xyz") ); } +