+ CMP3(" abc", "%5s", wxT("abc"));
+ CMP3(" a", "%5s", wxT("a"));
+ CMP3("abcdefghi", "%5s", wxT("abcdefghi"));
+ CMP3("abc ", "%-5s", wxT("abc"));
+ CMP3("abcdefghi", "%-5s", wxT("abcdefghi"));
+
+ CMP3("abcde", "%.5s", wxT("abcdefghi"));
+
+ // do the same tests but with Unicode characters:
+#if wxUSE_UNICODE
+
+ // Unicode code points from U+03B1 to U+03B9 are the greek letters alpha-iota;
+ // UTF8 encoding of such code points is 0xCEB1 to 0xCEB9
+
+#define ALPHA "\xCE\xB1"
+ // alpha
+#define ABC "\xCE\xB1\xCE\xB2\xCE\xB3"
+ // alpha+beta+gamma
+#define ABCDE "\xCE\xB1\xCE\xB2\xCE\xB3\xCE\xB4\xCE\xB5"
+ // alpha+beta+gamma+delta+epsilon
+#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
+
+ // 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"
+ CMP3(" ab", "%5s", wxT("ab\0cdefghi"));
+}
+
+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);
+
+ CMP4(" a", "%*c", 8, 'a');
+ CMP4(" four", "%*s", 8, "four");
+ CMP6(" four four", "%*s %*s", 8, "four", 6, "four");
+}
+
+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
+ // you write %%% as argument of some *printf function !)
+ // Compare(wxT("%"), wxT("%%%"));
+}
+
+#ifdef wxLongLong_t
+void VsnprintfTestCase::LongLong()
+{
+ CMP3("123456789", "%lld", (wxLongLong_t)123456789);
+ CMP3("-123456789", "%lld", (wxLongLong_t)-123456789);
+
+ CMP3("123456789", "%llu", (wxULongLong_t)123456789);
+
+#ifdef __WINDOWS__
+ CMP3("123456789", "%I64d", (wxLongLong_t)123456789);
+ CMP3("123456789abcdef", "%I64x", wxLL(0x123456789abcdef));
+#endif
+}
+#endif
+
+void VsnprintfTestCase::WrongFormatStrings()
+{
+ // test how wxVsnprintf() behaves with wrong format string:
+
+#if 0
+ // NB: the next 2 tests currently return an error but it would be nice
+ // if they didn't (see ticket #9367)