From 387f829ed187830439084c9559dfc3036f9bf352 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Fri, 30 Apr 2004 20:26:14 +0000 Subject: [PATCH] moved Unicode tests to testsuite (patch 943945) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27025 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/console/console.cpp | 45 ----------------- tests/Makefile.in | 16 +++++- tests/makefile.bcc | 10 +++- tests/makefile.gcc | 12 ++++- tests/makefile.vc | 10 +++- tests/makefile.wat | 10 +++- tests/strings/unicode.cpp | 98 +++++++++++++++++++++++++++++++++++++ tests/test.bkl | 5 ++ tests/test.dsp | 4 ++ tests/testdata.fc | 6 +++ 10 files changed, 164 insertions(+), 52 deletions(-) create mode 100644 tests/strings/unicode.cpp create mode 100644 tests/testdata.fc diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 964478eb25..5611534320 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -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(); diff --git a/tests/Makefile.in b/tests/Makefile.in index c00b28af80..1e985bb720 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -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 diff --git a/tests/makefile.bcc b/tests/makefile.bcc index 1aaea9790f..e46753a5a5 100644 --- a/tests/makefile.bcc +++ b/tests/makefile.bcc @@ -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) $** diff --git a/tests/makefile.gcc b/tests/makefile.gcc index a47b49d489..bd807991eb 100644 --- a/tests/makefile.gcc +++ b/tests/makefile.gcc @@ -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 diff --git a/tests/makefile.vc b/tests/makefile.vc index 9cb9c9e2e7..dec67524b9 100644 --- a/tests/makefile.vc +++ b/tests/makefile.vc @@ -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) $** diff --git a/tests/makefile.wat b/tests/makefile.wat index 2d5cc67571..cb27914805 100644 --- a/tests/makefile.wat +++ b/tests/makefile.wat @@ -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 index 0000000000..bcf6a6060a --- /dev/null +++ b/tests/strings/unicode.cpp @@ -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 ); + } + } +} diff --git a/tests/test.bkl b/tests/test.bkl index 56e4e9314e..24589e34df 100644 --- a/tests/test.bkl +++ b/tests/test.bkl @@ -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 @@ base + + testdata.fc + + diff --git a/tests/test.dsp b/tests/test.dsp index 6e44c44fbf..3a4c2413df 100644 --- a/tests/test.dsp +++ b/tests/test.dsp @@ -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 index 0000000000..fd8d907f79 --- /dev/null +++ b/tests/testdata.fc @@ -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