]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/vsnprintf.cpp
implement wxTreeCtrl::GetFocusedItem() for wxMSW too (see #10859)
[wxWidgets.git] / tests / strings / vsnprintf.cpp
index 835317830387c24faa9c22be07e2656520ad940e..751f7c5b858816df5833b9fa3bbf94e76e829fdb 100644 (file)
@@ -55,27 +55,27 @@ int r;
 
 #define CMP6(expected, fmt, y, z, w, t)                    \
     r=wxSnprintf(buf, MAX_TEST_LEN, wxT(fmt), y, z, w, t); \
-    CPPUNIT_ASSERT( r == (int)wxStrlen(buf) );             \
+    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( r == (int)wxStrlen(buf) );          \
+    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( r == (int)wxStrlen(buf) );        \
+    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( r == (int)wxStrlen(buf) );        \
+    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( r == (int)wxStrlen(buf) );        \
+    CPPUNIT_ASSERT_EQUAL( r, wxStrlen(buf) );          \
     ASSERT_STR_EQUAL( wxT(expected), buf );
 
 // NOTE: this macro is used also with too-small buffers (see Miscellaneous())
@@ -116,7 +116,9 @@ wxUnsafeSnprintf(T *buf, size_t len, const wxChar *fmt, ...)
 class VsnprintfTestCase : public CppUnit::TestCase
 {
 public:
-    VsnprintfTestCase();
+    VsnprintfTestCase() {}
+
+    virtual void setUp();
 
 private:
     CPPUNIT_TEST_SUITE( VsnprintfTestCase );
@@ -184,11 +186,11 @@ CPPUNIT_TEST_SUITE_REGISTRATION( VsnprintfTestCase );
 // also include in it's own registry so that these tests can be run alone
 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VsnprintfTestCase, "VsnprintfTestCase" );
 
-VsnprintfTestCase::VsnprintfTestCase()
+void VsnprintfTestCase::setUp()
 {
     // this call is required to avoid check failures when running on machines
     // with a locale where the decimal point is not '.'
-    wxSetlocale(LC_NUMERIC, "English");
+    wxSetlocale(LC_ALL, "C");
 }
 
 void VsnprintfTestCase::C()
@@ -233,7 +235,8 @@ void VsnprintfTestCase::P()
     //          printed as '(nil)'.
     //          MSVC always print them as %8X on 32 bit systems and as %16X
     //          on 64 bit systems
-#ifdef __VISUALC__
+    //          mingw32 uses MSVC CRT by default so uses the same rules
+#if defined(__VISUALC__) || (defined(__MINGW32__) && !__USE_MINGW_ANSI_STDIO)
     #if SIZEOF_VOID_P == 4
         CMP3("00ABCDEF", "%p", (void*)0xABCDEF);
         CMP3("00000000", "%p", (void*)NULL);
@@ -241,6 +244,9 @@ void VsnprintfTestCase::P()
         CMP3("0000ABCDEFABCDEF", "%p", (void*)0xABCDEFABCDEF);
         CMP3("0000000000000000", "%p", (void*)NULL);
     #endif
+#elif defined(__MINGW32__) 
+    CMP3("0xabcdef", "%p", (void*)0xABCDEF); 
+    CMP3("0", "%p", (void*)NULL); 
 #elif defined(__GNUG__)
     CMP3("0xabcdef", "%p", (void*)0xABCDEF);
     CMP3("(nil)", "%p", (void*)NULL);
@@ -342,21 +348,27 @@ void VsnprintfTestCase::S()
 #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
 
-#define ALPHA_w     wxT(ALPHA)
-#define ABC_w       wxT(ABC)
-#define ABCDE_w     wxT(ABCDE)
-#define ABCDEFGHI_w wxT(ABCDEFGHI)
-
-    // CMP3 uses wxT() on the first argument so we need to be careful
-    // when using string concatenation that all parts of the string after
-    // the first explicitely use wxT():
-    CMP3("  " ABC_w,     "%5s",  ABC);
-    CMP3("    " ALPHA_w, "%5s",  ALPHA);
-    CMP3(ABCDEFGHI,      "%5s",  ABCDEFGHI);
-    CMP3(ABC L"  ",      "%-5s", ABC);
-    CMP3(ABCDEFGHI,      "%-5s", ABCDEFGHI);
-    CMP3(ABCDE,          "%.5s", ABCDEFGHI);
-#endif
+    // 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"