]> git.saurik.com Git - wxWidgets.git/commitdiff
really fix VC6 compilation of all testsi (without breaking VC9)
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 3 Nov 2008 00:31:16 +0000 (00:31 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 3 Nov 2008 00:31:16 +0000 (00:31 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56656 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/cppunit.h
tests/filename/filenametest.cpp
tests/net/socket.cpp
tests/strings/crt.cpp
tests/strings/unicode.cpp

index d362155e73a9c138a3293cac5a8a46d1d08cd41b..29161822a2d9aca4cebd2d332f6f564d9373b779 100644 (file)
@@ -105,47 +105,36 @@ assertEquals(const wchar_t *expected,
     assertEquals(wxString(expected), actual, sourceLine, message);
 }
 
+#define WX_CPPUNIT_ASSERT_EQUALS(T1, T2)                                      \
+    inline void                                                               \
+    assertEquals(T1 expected,                                                 \
+                 T2 actual,                                                   \
+                 CppUnit::SourceLine sourceLine,                              \
+                 const std::string& message)                                  \
+    {                                                                         \
+        if ( !assertion_traits<T1>::equal(expected,actual) )                  \
+        {                                                                     \
+            Asserter::failNotEqual( assertion_traits<T1>::toString(expected), \
+                                    assertion_traits<T2>::toString(actual),   \
+                                    sourceLine,                               \
+                                    message );                                \
+        }                                                                     \
+    }
+
 // and another to be able to specify (usually literal) ints as expected values
-// for functions returning any of unsigned {int,long} or size_t
-inline void
-assertEquals(int expected,
-             unsigned actual,
-             CppUnit::SourceLine sourceLine,
-             const std::string& message)
-{
-    assertEquals(unsigned(expected), actual, sourceLine, message);
-}
+// for functions returning size_t
+WX_CPPUNIT_ASSERT_EQUALS(int, size_t);
 
-inline void
-assertEquals(int expected,
-             unsigned long actual,
-             CppUnit::SourceLine sourceLine,
-             const std::string& message)
-{
-    assertEquals((unsigned long)expected, actual, sourceLine, message);
-}
+// special section with VC6 workarounds: due to incorrect resolution of
+// overloaded/template functions in this compiler (it basically doesn't use the
+// template version at all if any overloaded function matches partially even if
+// none of them matches fully) we also need
+#ifdef __VISUALC6__
 
-// we also need this one to resolve ambiguity in the tests comparing unsigned
-// short (e.g. wxDateTime_t returned by several wxDateTime methods) with
-// literal integer constants
-inline void
-assertEquals(int expected,
-             unsigned short actual,
-             CppUnit::SourceLine sourceLine,
-             const std::string& message)
-{
-    assertEquals((unsigned short)expected, actual, sourceLine, message);
-}
+WX_CPPUNIT_ASSERT_EQUALS(int, int);
+WX_CPPUNIT_ASSERT_EQUALS(size_t, size_t);
 
-// this one is useful for wxTextCtrl functions which return longs
-inline void
-assertEquals(int expected,
-             long actual,
-             CppUnit::SourceLine sourceLine,
-             const std::string& message)
-{
-    assertEquals((long)expected, actual, sourceLine, message);
-}
+#endif // VC6
 
 CPPUNIT_NS_END
 
index ff0e75fd1d8279a10acde248be9ee510282cbd4f..9060ce280518070977238eb6887449c34ecf0e47 100644 (file)
@@ -292,9 +292,9 @@ void FileNameTestCase::TestNormalize()
 
     static const struct FileNameTest
     {
-        wxString original;
+        const char *original;
         int flags;
-        wxString expected;
+        const char *expected;
         wxPathFormat fmt;
     } tests[] =
     {
@@ -311,8 +311,8 @@ void FileNameTestCase::TestNormalize()
         // test wxPATH_NORM_TILDE
         // NB: do the tilde expansion also under Windows to test if it works there too
         { "/a/b/~", wxPATH_NORM_TILDE, "/a/b/~", wxPATH_UNIX },
-        { "/~/a/b", wxPATH_NORM_TILDE, home + "a/b", wxPATH_UNIX },
-        { "~/a/b", wxPATH_NORM_TILDE, home + "a/b", wxPATH_UNIX },
+        { "/~/a/b", wxPATH_NORM_TILDE, "HOME/a/b", wxPATH_UNIX },
+        { "~/a/b", wxPATH_NORM_TILDE, "HOME/a/b", wxPATH_UNIX },
 
         // test wxPATH_NORM_CASE
         { "Foo", wxPATH_NORM_CASE, "Foo", wxPATH_UNIX },
@@ -325,8 +325,8 @@ void FileNameTestCase::TestNormalize()
           "c:\\users\\zeitlin", wxPATH_DOS },
 
         // test wxPATH_NORM_ABSOLUTE
-        { "a/b/", wxPATH_NORM_ABSOLUTE, cwd + "a/b/", wxPATH_UNIX },
-        { "a/b/c.ext", wxPATH_NORM_ABSOLUTE, cwd + "a/b/c.ext", wxPATH_UNIX },
+        { "a/b/", wxPATH_NORM_ABSOLUTE, "CWD/a/b/", wxPATH_UNIX },
+        { "a/b/c.ext", wxPATH_NORM_ABSOLUTE, "CWD/a/b/c.ext", wxPATH_UNIX },
         { "/a", wxPATH_NORM_ABSOLUTE, "/a", wxPATH_UNIX },
 
         // test giving no flags at all to Normalize()
@@ -364,6 +364,9 @@ void FileNameTestCase::TestNormalize()
         );
 
         // compare result with expected string
+        wxString expected(tests[i].expected);
+        expected.Replace(_T("HOME/"), home);
+        expected.Replace(_T("CWD/"), cwd);
         CPPUNIT_ASSERT_EQUAL( fnt.expected, fn.GetFullPath(fnt.fmt) );
     }
 }
index 2f152c8360a05bf73177875ff890569df86c94f2..332b3976e120724c9618ba34bb50166272d06b4e 100644 (file)
@@ -79,7 +79,7 @@ wxSockAddressPtr SocketTestCase::GetServer() const
         addr->Hostname(gs_serverHost);
         addr->Service("www");
 
-        ptr.reset(addr);
+        ptr = wxSockAddressPtr(addr);
     }
 
     return ptr;
@@ -104,7 +104,7 @@ wxSocketClientPtr SocketTestCase::GetHTTPSocket(int flags) const
 
     sock->Write(httpGetRoot.ToAscii(), httpGetRoot.length());
 
-    ptr.reset(sock);
+    ptr = wxSocketClientPtr(sock);
     return ptr;
 }
 
index 70ad0d9fed68de66f7a4affba73d93103d3320c7..150ae7cab193123523c8bc574d96e7b8bef1b420 100644 (file)
@@ -205,7 +205,7 @@ void CrtTestCase::Strpbrk()
     CPPUNIT_ASSERT_EQUAL(  ',', *wxStrpbrk(strWX.c_str(), s.mb_str()) );
     CPPUNIT_ASSERT_EQUAL( L',', *wxStrpbrk(strWX.c_str(), s.wc_str()) );
 
-    CPPUNIT_ASSERT_EQUAL( (const char *)NULL, wxStrpbrk(strWX, "xyz") );
-    CPPUNIT_ASSERT_EQUAL( (const wchar_t *)NULL, wxStrpbrk(strWX.c_str(), L"xyz") );
+    CPPUNIT_ASSERT_EQUAL( (char *)NULL, wxStrpbrk(strWX, "xyz") );
+    CPPUNIT_ASSERT_EQUAL( (wchar_t *)NULL, wxStrpbrk(strWX.c_str(), L"xyz") );
 }
 
index 6211e9e489bfea653b3b5f45ac8cc12df589a12f..b79c987438976b9adcea7e2da87ae0ea9ca23659 100644 (file)
 // to it should fail
 struct StringConversionData
 {
-    const char *str;
-    const wchar_t *wcs;
+    StringConversionData(const char *str_, const wchar_t *wcs_, int flags_ = 0)
+        : str(str_), wcs(wcs_), flags(flags_)
+    {
+    }
+
+    const char * const str;
+    const wchar_t * const wcs;
 
     enum
     {
@@ -36,7 +41,7 @@ struct StringConversionData
         ONLY_MB2WC = 1  // only test str -> wcs conversion
     };
 
-    int flags;
+    const int flags;
 
     // test that the conversion between str and wcs (subject to flags) succeeds
     //
@@ -281,21 +286,22 @@ void UnicodeTestCase::ConversionUTF7()
     static const StringConversionData utf7data[] =
     {
         // normal fragments
-        { "+AKM-", L"\xa3" },
-        { "+AOk-t+AOk-", L"\xe9t\xe9" },
+        StringConversionData("+AKM-", L"\xa3"),
+        StringConversionData("+AOk-t+AOk-", L"\xe9t\xe9"),
 
         // this one is an alternative valid encoding of the same string
-        { "+AOk-t+AOk", L"\xe9t\xe9", StringConversionData::ONLY_MB2WC },
+        StringConversionData("+AOk-t+AOk", L"\xe9t\xe9",
+                             StringConversionData::ONLY_MB2WC),
 
         // some special cases
-        { "+-", L"+" },
-        { "+--", L"+-" },
+        StringConversionData("+-", L"+"),
+        StringConversionData("+--", L"+-"),
 
         // the following are invalid UTF-7 sequences
-        { "\xa3", NULL },
-        { "+", NULL },
-        { "+~", NULL },
-        { "a+", NULL },
+        StringConversionData("\xa3", NULL),
+        StringConversionData("+", NULL),
+        StringConversionData("+~", NULL),
+        StringConversionData("a+", NULL),
     };
 
     for ( size_t n = 0; n < WXSIZEOF(utf7data); n++ )
@@ -322,9 +328,9 @@ void UnicodeTestCase::ConversionUTF8()
     static const StringConversionData utf8data[] =
     {
 #ifdef wxHAVE_U_ESCAPE
-        { "\xc2\xa3", L"\u00a3" },
+        StringConversionData("\xc2\xa3", L"\u00a3"),
 #endif
-        { "\xc2", NULL },
+        StringConversionData("\xc2", NULL),
     };
 
     wxCSConv conv(_T("utf-8"));
@@ -341,11 +347,14 @@ void UnicodeTestCase::ConversionUTF16()
     static const StringConversionData utf16data[] =
     {
 #ifdef wxHAVE_U_ESCAPE
-        { "\x04\x1f\x04\x40\x04\x38\x04\x32\x04\x35\x04\x42\0\0",
-          L"\u041f\u0440\u0438\u0432\u0435\u0442" },
-        { "\x01\0\0b\x01\0\0a\x01\0\0r\0\0", L"\u0100b\u0100a\u0100r" },
+        StringConversionData(
+            "\x04\x1f\x04\x40\x04\x38\x04\x32\x04\x35\x04\x42\0\0",
+            L"\u041f\u0440\u0438\u0432\u0435\u0442"),
+        StringConversionData(
+            "\x01\0\0b\x01\0\0a\x01\0\0r\0\0",
+            L"\u0100b\u0100a\u0100r"),
 #endif
-        { "\0f\0o\0o\0\0", L"foo" },
+        StringConversionData("\0f\0o\0o\0\0", L"foo"),
     };
 
     wxCSConv conv(wxFONTENCODING_UTF16BE);
@@ -368,11 +377,11 @@ void UnicodeTestCase::ConversionUTF32()
     static const StringConversionData utf32data[] =
     {
 #ifdef wxHAVE_U_ESCAPE
-        {
+        StringConversionData(
             "\0\0\x04\x1f\0\0\x04\x40\0\0\x04\x38\0\0\x04\x32\0\0\x04\x35\0\0\x04\x42\0\0\0\0",
-          L"\u041f\u0440\u0438\u0432\u0435\u0442" },
+          L"\u041f\u0440\u0438\u0432\u0435\u0442"),
 #endif
-        { "\0\0\0f\0\0\0o\0\0\0o\0\0\0\0", L"foo" },
+        StringConversionData("\0\0\0f\0\0\0o\0\0\0o\0\0\0\0", L"foo"),
     };
 
     wxCSConv conv(wxFONTENCODING_UTF32BE);