moved Unicode tests to testsuite (patch 943945)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27025 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík 2004-04-30 20:26:14 +00:00
parent 8ef11eb628
commit 387f829ed1
10 changed files with 164 additions and 52 deletions

View 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();

View 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

View 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) $**

View 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

View 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) $**

View 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) $<

98
tests/strings/unicode.cpp Normal file
View File

@ -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 );
}
}
}

View 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>

View 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

6
tests/testdata.fc Normal file
View File

@ -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