]> git.saurik.com Git - wxWidgets.git/commitdiff
moved Unicode tests to testsuite (patch 943945)
authorVáclav Slavík <vslavik@fastmail.fm>
Fri, 30 Apr 2004 20:26:14 +0000 (20:26 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Fri, 30 Apr 2004 20:26:14 +0000 (20:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27025 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/console/console.cpp
tests/Makefile.in
tests/makefile.bcc
tests/makefile.gcc
tests/makefile.vc
tests/makefile.wat
tests/strings/unicode.cpp [new file with mode: 0644]
tests/test.bkl
tests/test.dsp
tests/testdata.fc [new file with mode: 0644]

index 964478eb25063fa0f4a00ce7a7a6d9675cedd15f..5611534320c5ce4250db069573ebdd2529b07264 100644 (file)
@@ -84,7 +84,6 @@
     #define TEST_TEXTSTREAM
     #define TEST_THREADS
     #define TEST_TIMER
-    #define TEST_UNICODE
     // #define TEST_VCARD            -- don't enable this (VZ)
 //    #define TEST_VOLUME   --FIXME! (RN)
     #define TEST_WCHAR
@@ -3823,43 +3822,6 @@ static void TestFSVolume()
 // wide char and Unicode support
 // ----------------------------------------------------------------------------
 
-#ifdef TEST_UNICODE
-
-static void TestUnicodeToFromAscii()
-{
-    wxPuts(_T("Testing wxString::To/FromAscii()\n"));
-
-    static const char *msg = "Hello, world!";
-    wxString s = wxString::FromAscii(msg);
-
-    wxPrintf(_T("Message in Unicode: %s\n"), s.c_str());
-    printf("Message in ASCII: %s\n", (const char *)s.ToAscii());
-
-    wxPutchar(_T('\n'));
-}
-
-#include "wx/textfile.h"
-
-static void TestUnicodeTextFileRead()
-{
-    wxPuts(_T("Testing wxTextFile in Unicode build\n"));
-
-    wxTextFile file;
-    if ( file.Open(_T("testdata.fc"), wxConvLocal) )
-    {
-        const size_t count = file.GetLineCount();
-        for ( size_t n = 0; n < count; n++ )
-        {
-            const wxString& s = file[n];
-
-            wxPrintf(_T("Line %u: \"%s\" (len %u, last char = '%c')\n"),
-                     (unsigned)n, s.c_str(), (unsigned)s.length(), s.Last());
-        }
-    }
-}
-
-#endif // TEST_UNICODE
-
 #ifdef TEST_WCHAR
 
 #include "wx/strconv.h"
@@ -5905,13 +5867,6 @@ int main(int argc, char **argv)
     TestFSVolume();
 #endif // TEST_VOLUME
 
-#ifdef TEST_UNICODE
-    TestUnicodeTextFileRead();
-    #if TEST_ALL
-        TestUnicodeToFromAscii();
-    #endif
-#endif // TEST_UNICODE
-
 #ifdef TEST_WCHAR
     TestUtf8();
     TestEncodingConverter();
index c00b28af80d599b6580cbcfe213eaf6c56eea29d..1e985bb72029e7136b51340f7c264d5e9f1fc47a 100644 (file)
@@ -45,6 +45,7 @@ TEST_OBJECTS =  \
        test_arrays.o \
        test_longlong.o \
        test_strings.o \
+       test_unicode.o \
        test_bstream.o \
        test_ffilestream.o \
        test_filestream.o \
@@ -91,7 +92,7 @@ COND_MONOLITHIC_1___WXLIB_MONO_p = \
 
 ### Targets: ###
 
-all: test$(EXEEXT)
+all: test$(EXEEXT) data
 
 install: all
 
@@ -112,6 +113,14 @@ test$(EXEEXT): $(TEST_OBJECTS)
        
        $(__test___mac_setfilecmd) $(SAMPLES_RPATH_POSTLINK)
 
+data: 
+       @mkdir -p .
+       @for f in testdata.fc; do \
+       if test \( ! -s ./$$f \) -o \( $(srcdir)/$$f -nt ./$$f  \) ; then \
+       cp -pRf $(srcdir)/$$f . ; \
+       fi; \
+       done
+
 test_test.o: $(srcdir)/test.cpp
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
 
@@ -139,6 +148,9 @@ test_longlong.o: $(srcdir)/longlong/longlong.cpp
 test_strings.o: $(srcdir)/strings/strings.cpp
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
 
+test_unicode.o: $(srcdir)/strings/unicode.cpp
+       $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
+
 test_bstream.o: $(srcdir)/streams/bstream.cpp
        $(CXXC) -c -o $@ $(TEST_CXXFLAGS) $<
 
@@ -158,4 +170,4 @@ test_zlibstream.o: $(srcdir)/streams/zlibstream.cpp
 # Include dependency info, if present:
 @IF_GNU_MAKE@-include .deps/*.d
 
-.PHONY: all install uninstall clean distclean
+.PHONY: all install uninstall clean distclean data
index 1aaea9790f68b989c0faccddeea64542c6162bb5..e46753a5a50da32f7b25d87fda0b6fe3c40653ee 100644 (file)
@@ -39,6 +39,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_arrays.obj \
        $(OBJS)\test_longlong.obj \
        $(OBJS)\test_strings.obj \
+       $(OBJS)\test_unicode.obj \
        $(OBJS)\test_bstream.obj \
        $(OBJS)\test_ffilestream.obj \
        $(OBJS)\test_filestream.obj \
@@ -146,7 +147,7 @@ $(OBJS):
 
 ### Targets: ###
 
-all: $(OBJS)\test.exe
+all: $(OBJS)\test.exe data
 
 clean: 
        -if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -163,6 +164,10 @@ $(OBJS)\test.exe: $(TEST_OBJECTS)
        c0x32.obj $(TEST_OBJECTS),$@,, $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib  wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib  $(__UNICOWS_LIB_p) ole2w32.lib oleacc.lib odbc32.lib import32.lib cw32mt$(__RUNTIME_LIBS_7).lib,,
 |
 
+data: 
+       if not exist $(OBJS) mkdir $(OBJS)
+       for %f in (testdata.fc) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
+
 $(OBJS)\test_test.obj: .\test.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
@@ -190,6 +195,9 @@ $(OBJS)\test_longlong.obj: .\longlong\longlong.cpp
 $(OBJS)\test_strings.obj: .\strings\strings.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
+$(OBJS)\test_unicode.obj: .\strings\unicode.cpp
+       $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
+
 $(OBJS)\test_bstream.obj: .\streams\bstream.cpp
        $(CXX) -q -c -P -o$@ $(TEST_CXXFLAGS) $**
 
index a47b49d489e64996a1fe82cb6f1b80a5ec9964d9..bd807991eb36b66744d028c886bba887c7efa23f 100644 (file)
@@ -30,6 +30,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_arrays.o \
        $(OBJS)\test_longlong.o \
        $(OBJS)\test_strings.o \
+       $(OBJS)\test_unicode.o \
        $(OBJS)\test_bstream.o \
        $(OBJS)\test_ffilestream.o \
        $(OBJS)\test_filestream.o \
@@ -148,7 +149,7 @@ $(OBJS):
 
 ### Targets: ###
 
-all: $(OBJS)\test.exe
+all: $(OBJS)\test.exe data
 
 clean: 
        -if exist $(OBJS)\*.o del $(OBJS)\*.o
@@ -157,6 +158,10 @@ clean:
 $(OBJS)\test.exe: $(TEST_OBJECTS)
        $(CXX) -o $@ $(TEST_OBJECTS) $(LDFLAGS) $(__DEBUGINFO) -mthreads -L$(LIBDIRNAME)  $(CPPUNIT_LIBS)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) -lwxzlib$(WXDEBUGFLAG)  -lwxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG) -lwxexpat$(WXDEBUGFLAG)  $(__UNICOWS_LIB_p) -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lodbc32
 
+data: 
+       if not exist $(OBJS) mkdir $(OBJS)
+       for %%f in (testdata.fc) do if not exist $(OBJS)\%%f copy .\%%f $(OBJS)
+
 $(OBJS)\test_test.o: ./test.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
@@ -184,6 +189,9 @@ $(OBJS)\test_longlong.o: ./longlong/longlong.cpp
 $(OBJS)\test_strings.o: ./strings/strings.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
+$(OBJS)\test_unicode.o: ./strings/unicode.cpp
+       $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
+
 $(OBJS)\test_bstream.o: ./streams/bstream.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
@@ -199,4 +207,4 @@ $(OBJS)\test_memstream.o: ./streams/memstream.cpp
 $(OBJS)\test_zlibstream.o: ./streams/zlibstream.cpp
        $(CXX) -c -o $@ $(TEST_CXXFLAGS) $<
 
-.PHONY: all clean
+.PHONY: all clean data
index 9cb9c9e2e75f99b0091726be62a3f7101d21fe4a..dec67524b92d0b77a89c67f6c6551695e0fb9821 100644 (file)
@@ -32,6 +32,7 @@ TEST_OBJECTS =  \
        $(OBJS)\test_arrays.obj \
        $(OBJS)\test_longlong.obj \
        $(OBJS)\test_strings.obj \
+       $(OBJS)\test_unicode.obj \
        $(OBJS)\test_bstream.obj \
        $(OBJS)\test_ffilestream.obj \
        $(OBJS)\test_filestream.obj \
@@ -205,7 +206,7 @@ $(OBJS):
 
 ### Targets: ###
 
-all: $(OBJS)\test.exe
+all: $(OBJS)\test.exe data
 
 clean: 
        -if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -219,6 +220,10 @@ $(OBJS)\test.exe: $(TEST_OBJECTS)
        $(TEST_OBJECTS)  $(__WXLIB_BASE_p)  $(__WXLIB_MONO_p) $(__LIB_TIFF_p) $(__LIB_JPEG_p) $(__LIB_PNG_p) wxzlib$(WXDEBUGFLAG).lib  wxregex$(WXUNICODEFLAG)$(WXDEBUGFLAG).lib wxexpat$(WXDEBUGFLAG).lib  $(__UNICOWS_LIB_p) kernel32.lib user32.lib gdi32.lib comdlg32.lib winspool.lib winmm.lib shell32.lib comctl32.lib ole32.lib oleaut32.lib uuid.lib rpcrt4.lib advapi32.lib wsock32.lib oleacc.lib odbc32.lib
 <<
 
+data: 
+       if not exist $(OBJS) mkdir $(OBJS)
+       for %f in (testdata.fc) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
+
 $(OBJS)\test_test.obj: .\test.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
@@ -246,6 +251,9 @@ $(OBJS)\test_longlong.obj: .\longlong\longlong.cpp
 $(OBJS)\test_strings.obj: .\strings\strings.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
+$(OBJS)\test_unicode.obj: .\strings\unicode.cpp
+       $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
+
 $(OBJS)\test_bstream.obj: .\streams\bstream.cpp
        $(CXX) /c /nologo /TP /Fo$@ $(TEST_CXXFLAGS) $**
 
index 2d5cc67571bffd5bcca9c6685ee3e9f105e0a9f4..cb279148053421810bc8943024cffe3c4027e598 100644 (file)
@@ -180,6 +180,7 @@ TEST_OBJECTS =  &
        $(OBJS)\test_arrays.obj &
        $(OBJS)\test_longlong.obj &
        $(OBJS)\test_strings.obj &
+       $(OBJS)\test_unicode.obj &
        $(OBJS)\test_bstream.obj &
        $(OBJS)\test_ffilestream.obj &
        $(OBJS)\test_filestream.obj &
@@ -193,7 +194,7 @@ $(OBJS) :
 
 ### Targets: ###
 
-all : .SYMBOLIC $(OBJS)\test.exe
+all : .SYMBOLIC $(OBJS)\test.exe data
 
 clean : .SYMBOLIC 
        -if exist $(OBJS)\*.obj del $(OBJS)\*.obj
@@ -213,6 +214,10 @@ $(OBJS)\test.exe :  $(TEST_OBJECTS)
        @%append $(OBJS)\test.lbc
        wlink @$(OBJS)\test.lbc
 
+data : .SYMBOLIC 
+       if not exist $(OBJS) mkdir $(OBJS)
+       for %f in (testdata.fc) do if not exist $(OBJS)\%f copy .\%f $(OBJS)
+
 $(OBJS)\test_test.obj :  .AUTODEPEND .\test.cpp
        $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
@@ -240,6 +245,9 @@ $(OBJS)\test_longlong.obj :  .AUTODEPEND .\longlong\longlong.cpp
 $(OBJS)\test_strings.obj :  .AUTODEPEND .\strings\strings.cpp
        $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
+$(OBJS)\test_unicode.obj :  .AUTODEPEND .\strings\unicode.cpp
+       $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
+
 $(OBJS)\test_bstream.obj :  .AUTODEPEND .\streams\bstream.cpp
        $(CXX) -zq -fo=$^@ $(TEST_CXXFLAGS) $<
 
diff --git a/tests/strings/unicode.cpp b/tests/strings/unicode.cpp
new file mode 100644 (file)
index 0000000..bcf6a60
--- /dev/null
@@ -0,0 +1,98 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        tests/strings/unicode.cpp
+// Purpose:     Unicode unit test
+// Author:      Vadim Zeitlin, Wlodzimierz ABX Skiba
+// Created:     2004-04-28
+// RCS-ID:      $Id$
+// Copyright:   (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
+///////////////////////////////////////////////////////////////////////////////
+
+// ----------------------------------------------------------------------------
+// headers
+// ----------------------------------------------------------------------------
+
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+    #pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+    #include "wx/wx.h"
+#endif // WX_PRECOMP
+
+#include "wx/textfile.h"
+
+#include "wx/cppunit.h"
+
+// ----------------------------------------------------------------------------
+// test class
+// ----------------------------------------------------------------------------
+
+class UnicodeTestCase : public CppUnit::TestCase
+{
+public:
+    UnicodeTestCase();
+
+private:
+    CPPUNIT_TEST_SUITE( UnicodeTestCase );
+        CPPUNIT_TEST( ToFromAscii );
+        CPPUNIT_TEST( TextFileRead );
+    CPPUNIT_TEST_SUITE_END();
+
+    void ToFromAscii();
+    void TextFileRead();
+
+    DECLARE_NO_COPY_CLASS(UnicodeTestCase)
+};
+
+// register in the unnamed registry so that these tests are run by default
+CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase );
+
+// also include in it's own registry so that these tests can be run alone
+CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase, "UnicodeTestCase" );
+
+UnicodeTestCase::UnicodeTestCase()
+{
+}
+
+void UnicodeTestCase::ToFromAscii()
+{
+
+#define TEST_TO_FROM_ASCII(txt)                              \
+    {                                                        \
+        static const char *msg = txt;                        \
+        wxString s = wxString::FromAscii(msg);               \
+        CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 );  \
+    }
+
+    TEST_TO_FROM_ASCII( "Hello, world!" );
+    TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" );
+}
+
+void UnicodeTestCase::TextFileRead()
+{
+    wxTextFile file;
+    bool file_opened = file.Open(_T("testdata.fc"), wxConvLocal);
+
+    CPPUNIT_ASSERT( file_opened );
+
+    static const wxChar *lines[6] = { 
+        _T("# this is the test data file for wxFileConfig tests"),
+        _T("value1=one"),
+        _T("# a comment here"),
+        _T("value2=two"),
+        _T("value\\ with\\ spaces\\ inside\\ it=nothing special"),
+        _T("path=$PATH")
+    };
+
+    if( file_opened )
+    {
+        const size_t count = file.GetLineCount();
+        CPPUNIT_ASSERT( count == 6 );
+        for ( size_t n = 0; n < count; n++ )
+        {
+            CPPUNIT_ASSERT( wxStrcmp( file[n].c_str() , lines[n] ) == 0 );
+        }
+    }
+}
index 56e4e9314e5cadd5052e0936582bb653efff9f21..24589e34df43dfba20368d805a3b96e3af2b483e 100644 (file)
@@ -17,6 +17,7 @@
             arrays/arrays.cpp
             longlong/longlong.cpp
             strings/strings.cpp
+            strings/unicode.cpp
             streams/bstream.cpp
             streams/ffilestream.cpp
             streams/filestream.cpp
@@ -26,4 +27,8 @@
         <wx-lib>base</wx-lib>
     </exe>
 
+    <wx-data id="data">
+        <files>testdata.fc</files>
+    </wx-data>
+
 </makefile>
index 6e44c44fbffdd956251e223bf286a76b7c6a083f..3a4c2413dfb5e0d11a6532103af33049bc702c93 100644 (file)
@@ -483,6 +483,10 @@ SOURCE=.\test.cpp
 # End Source File
 # Begin Source File
 
+SOURCE=.\strings\unicode.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\regex\wxregex.cpp
 # End Source File
 # Begin Source File
diff --git a/tests/testdata.fc b/tests/testdata.fc
new file mode 100644 (file)
index 0000000..fd8d907
--- /dev/null
@@ -0,0 +1,6 @@
+# this is the test data file for wxFileConfig tests
+value1=one
+# a comment here
+value2=two
+value\ with\ spaces\ inside\ it=nothing special
+path=$PATH