+ 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 __WXMSW__
+ CMP3("123456789", "%I64d", (wxLongLong_t)123456789);
+ CMP3("123456789abcdef", "%I64x", wxLL(0x123456789abcdef));
+#endif
+}
+#endif
+
+// this test is only for our own implementation, the system implementation
+// doesn't always give errors for invalid format strings (e.g. glibc doesn't)
+// and as it's not required too (the behaviour is "undefined" according to the
+// spec), there is really no sense in testing for it
+#if wxUSE_WXVSNPRINTF
+
+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)
+
+ // two positionals with the same index:
+ r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$s %1$s"), "hello");
+ CPPUNIT_ASSERT(r != -1);
+
+ // three positionals with the same index mixed with other pos args:
+ r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%4$d %2$f %1$s %2$s %3$d"), "hello", "world", 3, 4);
+ CPPUNIT_ASSERT(r != -1);
+#endif
+
+ // a missing positional arg: this should result in an error but not all
+ // implementations detect it (e.g. glibc doesn't)
+ r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$d %3$d"), 1, 2, 3);
+ CPPUNIT_ASSERT_EQUAL(-1, r);
+
+ // positional and non-positionals in the same format string:
+ r = wxSnprintf(buf, MAX_TEST_LEN, wxT("%1$d %d %3$d"), 1, 2, 3);
+ CPPUNIT_ASSERT_EQUAL(-1, r);
+}
+
+#endif // wxUSE_WXVSNPRINTF
+
+// BigToSmallBuffer() test case helper:
+template<typename T>
+void VsnprintfTestCase::DoBigToSmallBuffer(T *buffer, int size)
+{
+ // Remember that wx*printf could be mapped either to system
+ // implementation or to wx implementation.
+ // In the first case, when the output buffer is too small, the returned
+ // value can be the number of characters required for the output buffer
+ // (conforming to ISO C99; implemented in e.g. GNU libc >= 2.1), or
+ // just a negative number, usually -1; (this is how e.g. MSVC's
+ // *printf() behaves). Luckily, in all implementations, when the
+ // output buffer is too small, it's nonetheless filled up to its max size.
+ //
+ // Note that in the second case (i.e. when we're using our own implementation),
+ // wxVsnprintf() will return the number of characters written in the standard
+ // output or
+ // -1 if there was an error in the format string
+ // maxSize+1 if the output buffer is too small
+
+ wxString errStr;
+ errStr << "The size of the buffer was " << size;
+ std::string errMsg(errStr.mb_str());