X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/10b7d13cdb173dae4988987b73fa9194bf6bf7ab..2fa7c075dab9bd49105e1e078ac58354b0189aee:/tests/strings/vsnprintf.cpp diff --git a/tests/strings/vsnprintf.cpp b/tests/strings/vsnprintf.cpp index a0e073be70..d8e96f2811 100644 --- a/tests/strings/vsnprintf.cpp +++ b/tests/strings/vsnprintf.cpp @@ -35,7 +35,7 @@ static wxChar buf[MAX_TEST_LEN]; // these macros makes it possible to write all tests without repeating a lot of times wxT() macro #define ASSERT_STR_EQUAL( a, b ) \ - CPPUNIT_ASSERT( wxString(a) == wxString(b) ); + CPPUNIT_ASSERT_EQUAL( wxString(a), wxString(b) ); #define CMP5(expected, x, y, z, w) \ wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z, w); \ @@ -57,10 +57,11 @@ static wxChar buf[MAX_TEST_LEN]; \ ASSERT_STR_EQUAL( wxT(expected), buf ); -#define CMPTOSIZE(buffer, size, expected, fmt, x, y, z, w) \ - wxSnprintf(buffer, size, wxT(fmt), x, y, z, w); \ - \ - CPPUNIT_ASSERT( wxString(wxT(expected)).Left(size - 1) == buffer ) +#define CMPTOSIZE(buffer, size, expected, fmt, x, y, z, w) \ + wxSnprintf(buffer, size, wxT(fmt), x, y, z, w); \ + \ + CPPUNIT_ASSERT_EQUAL( wxString(wxT(expected)).Left(size - 1), \ + wxString(buffer) ) @@ -80,6 +81,8 @@ private: CPPUNIT_TEST( G ); CPPUNIT_TEST( S ); CPPUNIT_TEST( Asterisk ); + CPPUNIT_TEST( Percent ); + CPPUNIT_TEST( LongLong ); CPPUNIT_TEST( BigToSmallBuffer ); CPPUNIT_TEST_SUITE_END(); @@ -89,6 +92,9 @@ private: void G(); void S(); void Asterisk(); + void Percent(); + void LongLong(); + void Unicode(); void BigToSmallBuffer(); void Misc(wxChar *buffer, int size); @@ -178,10 +184,50 @@ void VsnprintfTestCase::S() CMP3("abcde", "%.5s", wxT("abcdefghi")); + // do the same tests but with Unicode characters: +#if wxUSE_UNICODE + #define ALPHA "\x3B1" + #define BETA "\x3B2" + #define GAMMA "\x3B3" + #define DELTA "\x3B4" + #define EPSILON "\x3B5" + #define ZETA "\x3B6" + #define ETA "\x3B7" + #define THETA "\x3B8" + #define IOTA "\x3B9" + + #define ABC ALPHA BETA GAMMA + #define ABCDE ALPHA BETA GAMMA DELTA EPSILON + #define ABCDEFGHI ALPHA BETA GAMMA DELTA EPSILON ZETA ETA THETA IOTA + + CMP3(" " ABC, "%5s", wxT(ABC)); + CMP3(" " ALPHA, "%5s", wxT(ALPHA)); + CMP3(ABCDEFGHI, "%5s", wxT(ABCDEFGHI)); + CMP3(ABC " ", "%-5s", wxT(ABC)); + CMP3(ABCDEFGHI, "%-5s", wxT(ABCDEFGHI)); + + CMP3(ABCDE, "%.5s", wxT(ABCDEFGHI)); +#endif +} + +void VsnprintfTestCase::Asterisk() +{ + CMP5(" 0.1", "%*.*f", 10, 1, 0.123); + CMP5(" 0.1230", "%*.*f", 10, 4, 0.123); + CMP5("0.1", "%*.*f", 3, 1, 0.123); + + CMP4("%0.002", "%%%.*f", 3, 0.0023456789); +} + +void VsnprintfTestCase::Percent() +{ // some tests without any argument passed through ... CMP2("%", "%%"); CMP2("%%%", "%%%%%%"); + CMP3("% abc", "%%%5s", wxT("abc")); + CMP3("% abc%", "%%%5s%%", wxT("abc")); + // do not test odd number of '%' symbols as different implementations // of snprintf() give different outputs as this situation is not considered // by any standard (in fact, GCC will also warn you about a spurious % if @@ -189,13 +235,12 @@ void VsnprintfTestCase::S() // Compare(wxT("%"), wxT("%%%")); } -void VsnprintfTestCase::Asterisk() +void VsnprintfTestCase::LongLong() { - CMP5(" 0.1", "%*.*f", 10, 1, 0.123); - CMP5(" 0.1230", "%*.*f", 10, 4, 0.123); - CMP5("0.1", "%*.*f", 3, 1, 0.123); + CMP3("123456789", "%lld", (long long int)123456789); + CMP3("-123456789", "%lld", (long long int)-123456789); - CMP4("%0.002", "%%%.*f", 3, 0.0023456789); + CMP3("123456789", "%llu", (unsigned long long int)123456789); } void VsnprintfTestCase::Misc(wxChar *buffer, int size)