X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3879212eeea0078543086a28304d7eb5c98deae0..a9da8ef41cfb8fba50366ace5f3a9c97d4dec5cb:/tests/strings/vsnprintf.cpp?ds=inline diff --git a/tests/strings/vsnprintf.cpp b/tests/strings/vsnprintf.cpp index da30bb377f..c34f8fa061 100644 --- a/tests/strings/vsnprintf.cpp +++ b/tests/strings/vsnprintf.cpp @@ -55,27 +55,27 @@ int r; #define CMP6(expected, fmt, y, z, w, t) \ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z, w, t); \ - CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \ + CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \ ASSERT_STR_EQUAL( wxT(expected), buf ); #define CMP5(expected, fmt, y, z, w) \ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z, w); \ - CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \ + CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \ ASSERT_STR_EQUAL( wxT(expected), buf ); #define CMP4(expected, fmt, y, z) \ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z); \ - CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \ + CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \ ASSERT_STR_EQUAL( wxT(expected), buf ); #define CMP3(expected, fmt, y) \ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y); \ - CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \ + CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \ ASSERT_STR_EQUAL( wxT(expected), buf ); #define CMP2(expected, fmt) \ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt)); \ - CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \ + CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \ ASSERT_STR_EQUAL( wxT(expected), buf ); // NOTE: this macro is used also with too-small buffers (see Miscellaneous()) @@ -257,7 +257,7 @@ void VsnprintfTestCase::N() { int nchar; - wxSnprintf(buf, MAX_TEST_LEN, _T("%d %s%n\n"), 3, _T("bears"), &nchar); + wxSnprintf(buf, MAX_TEST_LEN, wxT("%d %s%n\n"), 3, wxT("bears"), &nchar); CPPUNIT_ASSERT_EQUAL( 7, nchar ); } @@ -348,21 +348,27 @@ void VsnprintfTestCase::S() #define ABCDEFGHI "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5\xCE\xB6\xCE\xB7\xCE\xB8\xCE\xB9" // alpha+beta+gamma+delta+epsilon+zeta+eta+theta+iota -#define ALPHA_w wxT(ALPHA) -#define ABC_w wxT(ABC) -#define ABCDE_w wxT(ABCDE) -#define ABCDEFGHI_w wxT(ABCDEFGHI) - - // CMP3 uses wxT() on the first argument so we need to be careful - // when using string concatenation that all parts of the string after - // the first explicitely use wxT(): - CMP3(" " ABC_w, "%5s", ABC); - CMP3(" " ALPHA_w, "%5s", ALPHA); - CMP3(ABCDEFGHI, "%5s", ABCDEFGHI); - CMP3(ABC L" ", "%-5s", ABC); - CMP3(ABCDEFGHI, "%-5s", ABCDEFGHI); - CMP3(ABCDE, "%.5s", ABCDEFGHI); -#endif + // the 'expected' and 'arg' parameters of this macro are supposed to be + // UTF-8 strings +#define CMP3_UTF8(expected, fmt, arg) \ + CPPUNIT_ASSERT_EQUAL \ + ( \ + wxString::FromUTF8(expected).length(), \ + wxSnprintf(buf, MAX_TEST_LEN, fmt, wxString::FromUTF8(arg)) \ + ); \ + CPPUNIT_ASSERT_EQUAL \ + ( \ + wxString::FromUTF8(expected), \ + buf \ + ) + + CMP3_UTF8(" " ABC, "%5s", ABC); + CMP3_UTF8(" " ALPHA, "%5s", ALPHA); + CMP3_UTF8(ABCDEFGHI, "%5s", ABCDEFGHI); + CMP3_UTF8(ABC " ", "%-5s", ABC); + CMP3_UTF8(ABCDEFGHI, "%-5s", ABCDEFGHI); + CMP3_UTF8(ABCDE, "%.5s", ABCDEFGHI); +#endif // wxUSE_UNICODE // test a string which has a NULL character after "ab"; // obviously it should be handled exactly like just as "ab" @@ -491,7 +497,7 @@ void VsnprintfTestCase::DoBigToSmallBuffer(T *buffer, int size) // format and gcc would warn about this otherwise r = wxUnsafeSnprintf(buffer, size, - _T("unicode string/char: %ls/%lc -- ansi string/char: %hs/%hc"), + wxT("unicode string/char: %ls/%lc -- ansi string/char: %hs/%hc"), L"unicode", L'U', "ansi", 'A'); wxString expected = wxString(wxT("unicode string/char: unicode/U -- ansi string/char: ansi/A")).Left(size - 1); @@ -550,10 +556,10 @@ void VsnprintfTestCase::DoMisc( // Prepare messages so that it is possible to see from the error which // test was running. wxString errStr, overflowStr; - errStr << _T("No.: ") << ++count << _T(", expected: ") << expectedLen - << _T(" '") << expectedString << _T("', result: "); - overflowStr << errStr << _T("buffer overflow"); - errStr << n << _T(" '") << buf << _T("'"); + errStr << wxT("No.: ") << ++count << wxT(", expected: ") << expectedLen + << wxT(" '") << expectedString << wxT("', result: "); + overflowStr << errStr << wxT("buffer overflow"); + errStr << n << wxT(" '") << buf << wxT("'"); // turn them into std::strings std::string errMsg(errStr.mb_str());