X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/505a8c2ced8eec9aa2d4b0856a27c62ff4330e37..d62c1e628d2e36f00dd1c703a41c2d41415c10cc:/tests/strings/tokenizer.cpp?ds=sidebyside diff --git a/tests/strings/tokenizer.cpp b/tests/strings/tokenizer.cpp index 17e9a911ea..c22c5ba3b5 100644 --- a/tests/strings/tokenizer.cpp +++ b/tests/strings/tokenizer.cpp @@ -36,11 +36,15 @@ private: CPPUNIT_TEST_SUITE( TokenizerTestCase ); CPPUNIT_TEST( GetCount ); CPPUNIT_TEST( GetPosition ); + CPPUNIT_TEST( GetString ); + CPPUNIT_TEST( LastDelimiter ); CPPUNIT_TEST( StrtokCompat ); CPPUNIT_TEST_SUITE_END(); void GetCount(); void GetPosition(); + void GetString(); + void LastDelimiter(); void StrtokCompat(); DECLARE_NO_COPY_CLASS(TokenizerTestCase) @@ -119,7 +123,8 @@ gs_testData[] = // fails in the diagnostic message static std::string Nth(size_t n) { - return wxString::Format(_T("for loop index %lu"), (unsigned long)n).mb_str(); + return std::string(wxString::Format(_T("for loop index %lu"), + (unsigned long)n).mb_str()); } // ---------------------------------------------------------------------------- @@ -184,6 +189,60 @@ void TokenizerTestCase::GetPosition() DoTestGetPosition(_T("foo_bar_"), _T("_"), 4, 8, 0); } +// helper for GetString(): the parameters are the same as for DoTestGetPosition +// but it checks GetString() return value instead of GetPosition() +static void +DoTestGetString(const wxChar *s, const wxChar *delims, int pos, ...) +{ + wxStringTokenizer tkz(s, delims); + + CPPUNIT_ASSERT_EQUAL( wxString(s), tkz.GetString() ); + + va_list ap; + va_start(ap, pos); + + for ( ;; ) + { + if ( !pos ) + { + CPPUNIT_ASSERT( tkz.GetString().empty() ) ; + break; + } + + tkz.GetNextToken(); + + CPPUNIT_ASSERT_EQUAL( wxString(s + pos), tkz.GetString() ); + + pos = va_arg(ap, int); + } + + va_end(ap); +} + +void TokenizerTestCase::GetString() +{ + DoTestGetString(_T("foo"), _T("_"), 3, 0); + DoTestGetString(_T("foo_bar"), _T("_"), 4, 7, 0); + DoTestGetString(_T("foo_bar_"), _T("_"), 4, 8, 0); +} + +void TokenizerTestCase::LastDelimiter() +{ + wxStringTokenizer tkz(_T("a+-b=c"), _T("+-=")); + + tkz.GetNextToken(); + CPPUNIT_ASSERT_EQUAL( _T('+'), tkz.GetLastDelimiter() ); + + tkz.GetNextToken(); + CPPUNIT_ASSERT_EQUAL( _T('-'), tkz.GetLastDelimiter() ); + + tkz.GetNextToken(); + CPPUNIT_ASSERT_EQUAL( _T('='), tkz.GetLastDelimiter() ); + + tkz.GetNextToken(); + CPPUNIT_ASSERT_EQUAL( _T('\0'), tkz.GetLastDelimiter() ); +} + void TokenizerTestCase::StrtokCompat() { for ( size_t n = 0; n < WXSIZEOF(gs_testData); n++ )