+ // VC6 can't compile this code
+#if !defined(__VISUALC__) || (__VISUALC__ >= 1310)
+#if wxUSE_UNICODE
+ wchar_t bufw[1024], bufw2[16], bufw3[4], bufw4;
+ DoBigToSmallBuffer(bufw, 1024);
+ DoBigToSmallBuffer(bufw2, 16);
+ DoBigToSmallBuffer(bufw3, 4);
+ DoBigToSmallBuffer(&bufw4, 1);
+#endif // wxUSE_UNICODE
+
+ char bufa[1024], bufa2[16], bufa3[4], bufa4;
+ DoBigToSmallBuffer(bufa, 1024);
+ DoBigToSmallBuffer(bufa2, 16);
+ DoBigToSmallBuffer(bufa3, 4);
+ DoBigToSmallBuffer(&bufa4, 1);
+#endif // !VC6
+}
+
+// Miscellaneous() test case helper:
+void VsnprintfTestCase::DoMisc(
+ int expectedLen,
+ const wxString& expectedString,
+ size_t max,
+ const wxChar *format, ...)
+{
+ const size_t BUFSIZE = MAX_TEST_LEN - 1;
+ size_t i;
+ static int count = 0;
+
+ wxASSERT(max <= BUFSIZE);
+
+ for (i = 0; i < BUFSIZE; i++)
+ buf[i] = '*';
+ buf[BUFSIZE] = 0;
+
+ va_list ap;
+ va_start(ap, format);
+
+ int n = wxVsnprintf(buf, max, format, ap);
+
+ va_end(ap);
+
+ // Prepare messages so that it is possible to see from the error which
+ // test was running.
+ wxString errStr, overflowStr;
+ 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());
+ std::string overflowMsg(overflowStr.mb_str());
+
+ CPPUNIT_ASSERT_MESSAGE(errMsg,
+ (expectedLen == -1 && size_t(n) >= max) || expectedLen == n);
+
+ CPPUNIT_ASSERT_MESSAGE(errMsg, expectedString == buf);
+
+ for (i = max; i < BUFSIZE; i++)
+ CPPUNIT_ASSERT_MESSAGE(overflowMsg, buf[i] == '*');
+}
+
+void VsnprintfTestCase::Miscellaneous()
+{
+ // expectedLen, expectedString, max, format, ...
+ DoMisc(5, wxT("-1234"), 8, wxT("%d"), -1234);
+ DoMisc(7, wxT("1234567"), 8, wxT("%d"), 1234567);
+ DoMisc(-1, wxT("1234567"), 8, wxT("%d"), 12345678);
+ DoMisc(-1, wxT("-123456"), 8, wxT("%d"), -1234567890);
+
+ DoMisc(6, wxT("123456"), 8, wxT("123456"));
+ DoMisc(7, wxT("1234567"), 8, wxT("1234567"));
+ DoMisc(-1, wxT("1234567"), 8, wxT("12345678"));
+
+ DoMisc(6, wxT("123450"), 8, wxT("12345%d"), 0);
+ DoMisc(7, wxT("1234560"), 8, wxT("123456%d"), 0);
+ DoMisc(-1, wxT("1234567"), 8, wxT("1234567%d"), 0);
+ DoMisc(-1, wxT("1234567"), 8, wxT("12345678%d"), 0);
+
+ DoMisc(6, wxT("12%45%"), 8, wxT("12%%45%%"));
+ DoMisc(7, wxT("12%45%7"), 8, wxT("12%%45%%7"));
+ DoMisc(-1, wxT("12%45%7"), 8, wxT("12%%45%%78"));
+
+ DoMisc(5, wxT("%%%%%"), 6, wxT("%%%%%%%%%%"));
+ DoMisc(6, wxT("%%%%12"), 7, wxT("%%%%%%%%%d"), 12);
+}
+
+
+/* (C) Copyright C E Chew
+*
+* Feel free to copy, use and distribute this software provided:
+*
+* 1. you do not pretend that you wrote it
+* 2. you leave this copyright notice intact.
+*/
+
+void VsnprintfTestCase::GlibcMisc1()
+{
+ CMP3(" ", "%5.s", "xyz");
+ CMP3(" 33", "%5.f", 33.3);
+#ifdef wxUSING_VC_CRT_IO
+ // see the previous notes about the minimum width of mantissa:
+ CMP3(" 3e+008", "%8.e", 33.3e7);
+ CMP3(" 3E+008", "%8.E", 33.3e7);
+ CMP3("3e+001", "%.g", 33.3);
+ CMP3("3E+001", "%.G", 33.3);
+#else
+ CMP3(" 3e+08", "%8.e", 33.3e7);
+ CMP3(" 3E+08", "%8.E", 33.3e7);
+ CMP3("3e+01", "%.g", 33.3);
+ CMP3("3E+01", "%.G", 33.3);
+#endif
+}
+
+void VsnprintfTestCase::GlibcMisc2()
+{
+ int prec;
+ wxString test_format;
+
+ prec = 0;
+ CMP4("3", "%.*g", prec, 3.3);
+
+ prec = 0;
+ CMP4("3", "%.*G", prec, 3.3);
+
+ prec = 0;
+ CMP4(" 3", "%7.*G", prec, 3.33);
+
+ prec = 3;
+ CMP4(" 041", "%04.*o", prec, 33);