+// NOTE: for more info about the specification of wxVsnprintf() behaviour you can
+// refer to the following page of the GNU libc manual:
+// http://www.gnu.org/software/libc/manual/html_node/Formatted-Output.html
+
+
+
+// ----------------------------------------------------------------------------
+// global utilities for testing
+// ----------------------------------------------------------------------------
+
+#define MAX_TEST_LEN 1024
+
+// temporary buffers
+static wxChar buf[MAX_TEST_LEN];
+int r;
+
+// these macros makes it possible to write all tests without repeating a lot
+// of times the wxT() macro
+// NOTE: you should use expected strings with these macros which do not exceed
+// MAX_TEST_LEN as these macro do check if the return value is == (int)wxStrlen(buf)
+
+#define ASSERT_STR_EQUAL( a, b ) \
+ CPPUNIT_ASSERT_EQUAL( wxString(a), wxString(b) );
+
+#define CMP5(expected, x, y, z, w) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z, w); \
+ CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+#define CMP4(expected, x, y, z) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z); \
+ CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+#define CMP3(expected, x, y) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y); \
+ CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+#define CMP2(expected, x) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(x)); \
+ CPPUNIT_ASSERT( r == (int)wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+// NOTE: this macro is used also with too-small buffers (see Miscellaneous())
+// test function, thus the return value can be > size and thus we
+// cannot check if r == (int)wxStrlen(buf)
+#define CMPTOSIZE(buffer, size, expected, fmt, x, y, z, w) \
+ r=wxSnprintf(buffer, size, wxT(fmt), x, y, z, w); \
+ CPPUNIT_ASSERT( r > 0 ); \
+ CPPUNIT_ASSERT_EQUAL( wxString(wxT(expected)).Left(size - 1), \
+ wxString(buffer) )
+
+// this is the same as wxSnprintf() but it passes the format string to
+// wxVsnprintf() without using ATTRIBUTE_PRINTF and thus suppresses the gcc
+// checks (and resulting warnings) for the format string
+//
+// use with extreme care and only when you're really sure the warnings must be
+// suppressed!
+template<typename T>
+static int
+wxUnsafeSnprintf(T *buf, size_t len, const wxChar *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+
+ int rc = wxVsnprintf(buf, len, fmt, args);
+
+ va_end(args);