-static wxChar buf[MAX_TEST_LEN], buf2[MAX_TEST_LEN];
-
-
-// these macros makes it possible to write all tests without repeating a lot of times wxT() macro
-
-#define CMP5(expected, x, y, z, w) \
- wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z, w); \
- snprintf(buf2, MAX_TEST_LEN, wxT(x), y, z, w); \
- \
- CPPUNIT_ASSERT_STR_EQUAL( buf2, buf ); \
- CPPUNIT_ASSERT_STR_EQUAL( expected, buf );
-
-#define CMP4(expected, x, y, z) \
- wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y, z); \
- snprintf(buf2, MAX_TEST_LEN, wxT(x), y, z); \
- \
- CPPUNIT_ASSERT_STR_EQUAL( buf2, buf ); \
- CPPUNIT_ASSERT_STR_EQUAL( expected, buf );
-
-#define CMP3(expected, x, y) \
- wxSnprintf(buf, MAX_TEST_LEN, wxT(x), y); \
- snprintf(buf2, MAX_TEST_LEN, wxT(x), y); \
- \
- CPPUNIT_ASSERT_STR_EQUAL( buf2, buf ); \
- CPPUNIT_ASSERT_STR_EQUAL( expected, buf );
-
-#define CMP2(expected, x) \
- wxSnprintf(buf, MAX_TEST_LEN, wxT(x)); \
- snprintf(buf2, MAX_TEST_LEN, wxT(x)); \
- \
- CPPUNIT_ASSERT_STR_EQUAL( buf2, buf ); \
- CPPUNIT_ASSERT_STR_EQUAL( expected, buf );
-
-#define CMPTOSIZE(buffer, size, fmt, x, y, z, w) \
- wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), x, y, z, w); \
- snprintf(buf2, MAX_TEST_LEN, wxT(fmt), x, y, z, w); \
- \
- CPPUNIT_ASSERT_EQUAL( wxString(buf2, size), wxString(buf, size) );
+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 CMP6(expected, fmt, y, z, w, t) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z, w, t); \
+ CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+#define CMP5(expected, fmt, y, z, w) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z, w); \
+ CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+#define CMP4(expected, fmt, y, z) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z); \
+ CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+#define CMP3(expected, fmt, y) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y); \
+ CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) ); \
+ ASSERT_STR_EQUAL( wxT(expected), buf );
+
+#define CMP2(expected, fmt) \
+ r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt)); \
+ CPPUNIT_ASSERT_EQUAL( r, 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, failuremsg, expected, fmt, x, y, z, w) \
+ r=wxSnprintf(buffer, size, wxT(fmt), x, y, z, w); \
+ CPPUNIT_ASSERT( r > 0 ); \
+ CPPUNIT_ASSERT_EQUAL_MESSAGE( \
+ failuremsg, \
+ wxString(wxT(expected)).Left(size - 1), \
+ wxString(buffer))
+
+// this is the same as wxSnprintf() but it passes the format string to
+// wxVsnprintf() without using WX_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);