X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/50ded68d3807afc8e44bafaadb09dc1b6ce2486a..f3030ba726c107e6bfe3bc236a79849141bf610a:/samples/console/console.cpp diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 634f988399..f2c4785572 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -48,7 +48,7 @@ */ // what to test (in alphabetic order)? uncomment the line below to do all tests -#define TEST_ALL +//#define TEST_ALL #ifdef TEST_ALL #define TEST_ARRAYS #define TEST_CHARSET @@ -73,6 +73,7 @@ #define TEST_MIME #define TEST_PATHLIST #define TEST_ODBC + #define TEST_PRINTF #define TEST_REGCONF #define TEST_REGEX #define TEST_REGISTRY @@ -80,6 +81,7 @@ #define TEST_SOCKETS #define TEST_STREAMS #define TEST_STRINGS + #define TEST_TEXTSTREAM #define TEST_THREADS #define TEST_TIMER #define TEST_UNICODE @@ -92,7 +94,7 @@ #undef TEST_ALL static const bool TEST_ALL = TRUE; #else - #define TEST_EXECUTE + #define TEST_TEXTSTREAM static const bool TEST_ALL = FALSE; #endif @@ -316,7 +318,7 @@ static void TestDirEnum() return; } - wxDir dir(_T("s:/tmp/foo")); + wxDir dir(cwd); if ( !dir.IsOpened() ) { wxPrintf(_T("ERROR: failed to open current directory '%s'.\n"), cwd.c_str()); @@ -330,7 +332,7 @@ static void TestDirEnum() TestDirEnumHelper(dir, wxDIR_DEFAULT | wxDIR_DOTDOT); wxPuts(_T("Enumerating object files in current directory:")); - TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o"); + TestDirEnumHelper(dir, wxDIR_DEFAULT, "*.o*"); wxPuts(_T("Enumerating directories in current directory:")); TestDirEnumHelper(dir, wxDIR_DIRS); @@ -1764,8 +1766,10 @@ static void TestMimeFilename() if ( !ft->GetOpenCommand(&cmd, wxFileType::MessageParameters(fname, _T(""))) ) cmd = _T(""); + else + cmd = wxString(_T('"')) + cmd + _T('"'); - wxPrintf(_T("To open %s (%s) do '%s'.\n"), + wxPrintf(_T("To open %s (%s) do %s.\n"), fname.c_str(), desc.c_str(), cmd.c_str()); delete ft; @@ -2166,9 +2170,9 @@ static void TestLongLongComparison() #endif // wxUSE_LONGLONG_WX } -static void TestLongLongPrint() +static void TestLongLongToString() { - wxPuts(_T("*** Testing wxLongLong printing ***\n")); + wxPuts(_T("*** Testing wxLongLong::ToString() ***\n")); for ( size_t n = 0; n < WXSIZEOF(testLongs); n++ ) { @@ -2183,6 +2187,20 @@ static void TestLongLongPrint() wxPrintf(_T("-0x1234567887654321 = %s\n"), ll.ToString().c_str()); } +static void TestLongLongPrintf() +{ + wxPuts(_T("*** Testing wxLongLong printing ***\n")); + +#ifdef wxLongLongFmtSpec + wxLongLong ll = wxLL(0x1234567890abcdef); + wxString s = wxString::Format(_T("%") wxLongLongFmtSpec _T("x"), ll); + wxPrintf(_T("0x1234567890abcdef -> %s (%s)\n"), + s.c_str(), s == _T("1234567890abcdef") ? _T("ok") : _T("ERROR")); +#else // !wxLongLongFmtSpec + #error "wxLongLongFmtSpec not defined for this compiler/platform" +#endif +} + #undef MAKE_LL #undef RAND_LL @@ -2194,13 +2212,19 @@ static void TestLongLongPrint() #ifdef TEST_PATHLIST +#ifdef __UNIX__ + #define CMD_IN_PATH _T("ls") +#else + #define CMD_IN_PATH _T("command.com") +#endif + static void TestPathList() { wxPuts(_T("*** Testing wxPathList ***\n")); wxPathList pathlist; - pathlist.AddEnvList("PATH"); - wxString path = pathlist.FindValidPath("ls"); + pathlist.AddEnvList(_T("PATH")); + wxString path = pathlist.FindValidPath(CMD_IN_PATH); if ( path.empty() ) { wxPrintf(_T("ERROR: command not found in the path.\n")); @@ -2454,6 +2478,360 @@ static void TestDbOpen() #endif // TEST_ODBC +// ---------------------------------------------------------------------------- +// printf() tests +// ---------------------------------------------------------------------------- + +/* + NB: this stuff was taken from the glibc test suite and modified to build + in wxWindows: if I read the copyright below properly, this shouldn't + be a problem + */ + +#ifdef TEST_PRINTF + +#ifdef wxTEST_PRINTF + // use our functions from wxchar.cpp + #undef wxPrintf + #undef wxSprintf + + // NB: do _not_ use ATTRIBUTE_PRINTF here, we have some invalid formats + // in the tests below + int wxPrintf( const wxChar *format, ... ); + int wxSprintf( wxChar *str, const wxChar *format, ... ); +#endif + +#include "wx/longlong.h" + +#include + +static void rfg1 (void); +static void rfg2 (void); + + +static void +fmtchk (const wxChar *fmt) +{ + (void) wxPrintf(_T("%s:\t`"), fmt); + (void) wxPrintf(fmt, 0x12); + (void) wxPrintf(_T("'\n")); +} + +static void +fmtst1chk (const wxChar *fmt) +{ + (void) wxPrintf(_T("%s:\t`"), fmt); + (void) wxPrintf(fmt, 4, 0x12); + (void) wxPrintf(_T("'\n")); +} + +static void +fmtst2chk (const wxChar *fmt) +{ + (void) wxPrintf(_T("%s:\t`"), fmt); + (void) wxPrintf(fmt, 4, 4, 0x12); + (void) wxPrintf(_T("'\n")); +} + +/* This page is covered by the following copyright: */ + +/* (C) Copyright C E Chew + * + * Feel free to copy, use and distribute this software provided: + * + * 1. you do not pretend that you wrote it + * 2. you leave this copyright notice intact. + */ + +/* + * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans. + */ + +#define DEC -123 +#define INT 255 +#define UNS (~0) + +/* Formatted Output Test + * + * This exercises the output formatting code. + */ + +static void +fp_test (void) +{ + int i, j, k, l; + wxChar buf[7]; + wxChar *prefix = buf; + wxChar tp[20]; + + wxPuts(_T("\nFormatted output test")); + wxPrintf(_T("prefix 6d 6o 6x 6X 6u\n")); + wxStrcpy(prefix, _T("%")); + for (i = 0; i < 2; i++) { + for (j = 0; j < 2; j++) { + for (k = 0; k < 2; k++) { + for (l = 0; l < 2; l++) { + wxStrcpy(prefix, _T("%")); + if (i == 0) wxStrcat(prefix, _T("-")); + if (j == 0) wxStrcat(prefix, _T("+")); + if (k == 0) wxStrcat(prefix, _T("#")); + if (l == 0) wxStrcat(prefix, _T("0")); + wxPrintf(_T("%5s |"), prefix); + wxStrcpy(tp, prefix); + wxStrcat(tp, _T("6d |")); + wxPrintf(tp, DEC); + wxStrcpy(tp, prefix); + wxStrcat(tp, _T("6o |")); + wxPrintf(tp, INT); + wxStrcpy(tp, prefix); + wxStrcat(tp, _T("6x |")); + wxPrintf(tp, INT); + wxStrcpy(tp, prefix); + wxStrcat(tp, _T("6X |")); + wxPrintf(tp, INT); + wxStrcpy(tp, prefix); + wxStrcat(tp, _T("6u |")); + wxPrintf(tp, UNS); + wxPrintf(_T("\n")); + } + } + } + } + wxPrintf(_T("%10s\n"), (wxChar *) NULL); + wxPrintf(_T("%-10s\n"), (wxChar *) NULL); +} + +static void TestPrintf() +{ + static wxChar shortstr[] = _T("Hi, Z."); + static wxChar longstr[] = _T("Good morning, Doctor Chandra. This is Hal. \ +I am ready for my first lesson today."); + int result = 0; + + fmtchk(_T("%.4x")); + fmtchk(_T("%04x")); + fmtchk(_T("%4.4x")); + fmtchk(_T("%04.4x")); + fmtchk(_T("%4.3x")); + fmtchk(_T("%04.3x")); + + fmtst1chk(_T("%.*x")); + fmtst1chk(_T("%0*x")); + fmtst2chk(_T("%*.*x")); + fmtst2chk(_T("%0*.*x")); + + wxPrintf(_T("bad format:\t\"%b\"\n")); + wxPrintf(_T("nil pointer (padded):\t\"%10p\"\n"), (void *) NULL); + + wxPrintf(_T("decimal negative:\t\"%d\"\n"), -2345); + wxPrintf(_T("octal negative:\t\"%o\"\n"), -2345); + wxPrintf(_T("hex negative:\t\"%x\"\n"), -2345); + wxPrintf(_T("long decimal number:\t\"%ld\"\n"), -123456L); + wxPrintf(_T("long octal negative:\t\"%lo\"\n"), -2345L); + wxPrintf(_T("long unsigned decimal number:\t\"%lu\"\n"), -123456L); + wxPrintf(_T("zero-padded LDN:\t\"%010ld\"\n"), -123456L); + wxPrintf(_T("left-adjusted ZLDN:\t\"%-010ld\"\n"), -123456); + wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L); + wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L); + + wxPrintf(_T("zero-padded string:\t\"%010s\"\n"), shortstr); + wxPrintf(_T("left-adjusted Z string:\t\"%-010s\"\n"), shortstr); + wxPrintf(_T("space-padded string:\t\"%10s\"\n"), shortstr); + wxPrintf(_T("left-adjusted S string:\t\"%-10s\"\n"), shortstr); + wxPrintf(_T("null string:\t\"%s\"\n"), (wxChar *)NULL); + wxPrintf(_T("limited string:\t\"%.22s\"\n"), longstr); + + wxPrintf(_T("e-style >= 1:\t\"%e\"\n"), 12.34); + wxPrintf(_T("e-style >= .1:\t\"%e\"\n"), 0.1234); + wxPrintf(_T("e-style < .1:\t\"%e\"\n"), 0.001234); + wxPrintf(_T("e-style big:\t\"%.60e\"\n"), 1e20); + wxPrintf(_T("e-style == .1:\t\"%e\"\n"), 0.1); + wxPrintf(_T("f-style >= 1:\t\"%f\"\n"), 12.34); + wxPrintf(_T("f-style >= .1:\t\"%f\"\n"), 0.1234); + wxPrintf(_T("f-style < .1:\t\"%f\"\n"), 0.001234); + wxPrintf(_T("g-style >= 1:\t\"%g\"\n"), 12.34); + wxPrintf(_T("g-style >= .1:\t\"%g\"\n"), 0.1234); + wxPrintf(_T("g-style < .1:\t\"%g\"\n"), 0.001234); + wxPrintf(_T("g-style big:\t\"%.60g\"\n"), 1e20); + + wxPrintf (_T(" %6.5f\n"), .099999999860301614); + wxPrintf (_T(" %6.5f\n"), .1); + wxPrintf (_T("x%5.4fx\n"), .5); + + wxPrintf (_T("%#03x\n"), 1); + + //wxPrintf (_T("something really insane: %.10000f\n"), 1.0); + + { + double d = FLT_MIN; + int niter = 17; + + while (niter-- != 0) + wxPrintf (_T("%.17e\n"), d / 2); + fflush (stdout); + } + + wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324); + +#define FORMAT _T("|%12.4f|%12.4e|%12.4g|\n") + wxPrintf (FORMAT, 0.0, 0.0, 0.0); + wxPrintf (FORMAT, 1.0, 1.0, 1.0); + wxPrintf (FORMAT, -1.0, -1.0, -1.0); + wxPrintf (FORMAT, 100.0, 100.0, 100.0); + wxPrintf (FORMAT, 1000.0, 1000.0, 1000.0); + wxPrintf (FORMAT, 10000.0, 10000.0, 10000.0); + wxPrintf (FORMAT, 12345.0, 12345.0, 12345.0); + wxPrintf (FORMAT, 100000.0, 100000.0, 100000.0); + wxPrintf (FORMAT, 123456.0, 123456.0, 123456.0); +#undef FORMAT + + { + wxChar buf[20]; + int rc = wxSnprintf (buf, WXSIZEOF(buf), _T("%30s"), _T("foo")); + + wxPrintf(_T("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n"), + rc, WXSIZEOF(buf), buf); +#if 0 + wxChar buf2[512]; + wxPrintf ("snprintf (\"%%.999999u\", 10)\n", + wxSnprintf(buf2, WXSIZEOFbuf2), "%.999999u", 10)); +#endif + } + + fp_test (); + + wxPrintf (_T("%e should be 1.234568e+06\n"), 1234567.8); + wxPrintf (_T("%f should be 1234567.800000\n"), 1234567.8); + wxPrintf (_T("%g should be 1.23457e+06\n"), 1234567.8); + wxPrintf (_T("%g should be 123.456\n"), 123.456); + wxPrintf (_T("%g should be 1e+06\n"), 1000000.0); + wxPrintf (_T("%g should be 10\n"), 10.0); + wxPrintf (_T("%g should be 0.02\n"), 0.02); + + { + double x=1.0; + wxPrintf(_T("%.17f\n"),(1.0/x/10.0+1.0)*x-x); + } + + { + wxChar buf[200]; + + wxSprintf(buf,_T("%*s%*s%*s"),-1,_T("one"),-20,_T("two"),-30,_T("three")); + + result |= wxStrcmp (buf, + _T("onetwo three ")); + + wxPuts (result != 0 ? _T("Test failed!") : _T("Test ok.")); + } + +#ifdef wxLongLong_t + { + wxChar buf[200]; + + wxSprintf(buf, _T("%07") wxLongLongFmtSpec _T("o"), wxLL(040000000000)); + wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf); + + if (wxStrcmp (buf, _T("40000000000")) != 0) + { + result = 1; + wxPuts (_T("\tFAILED")); + } + wxPuts (_T("")); + } +#endif // wxLongLong_t + + wxPrintf (_T("printf (\"%%hhu\", %u) = %hhu\n"), UCHAR_MAX + 2, UCHAR_MAX + 2); + wxPrintf (_T("printf (\"%%hu\", %u) = %hu\n"), USHRT_MAX + 2, USHRT_MAX + 2); + + wxPuts (_T("--- Should be no further output. ---")); + rfg1 (); + rfg2 (); + +#if 0 + { + wxChar bytes[7]; + wxChar buf[20]; + + memset (bytes, '\xff', sizeof bytes); + wxSprintf (buf, _T("foo%hhn\n"), &bytes[3]); + if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff' + || bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff') + { + wxPuts (_T("%hhn overwrite more bytes")); + result = 1; + } + if (bytes[3] != 3) + { + wxPuts (_T("%hhn wrote incorrect value")); + result = 1; + } + } +#endif +} + +static void +rfg1 (void) +{ + wxChar buf[100]; + + wxSprintf (buf, _T("%5.s"), _T("xyz")); + if (wxStrcmp (buf, _T(" ")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" ")); + wxSprintf (buf, _T("%5.f"), 33.3); + if (wxStrcmp (buf, _T(" 33")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 33")); + wxSprintf (buf, _T("%8.e"), 33.3e7); + if (wxStrcmp (buf, _T(" 3e+08")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3e+08")); + wxSprintf (buf, _T("%8.E"), 33.3e7); + if (wxStrcmp (buf, _T(" 3E+08")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3E+08")); + wxSprintf (buf, _T("%.g"), 33.3); + if (wxStrcmp (buf, _T("3e+01")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3e+01")); + wxSprintf (buf, _T("%.G"), 33.3); + if (wxStrcmp (buf, _T("3E+01")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3E+01")); +} + +static void +rfg2 (void) +{ + int prec; + wxChar buf[100]; + + prec = 0; + wxSprintf (buf, _T("%.*g"), prec, 3.3); + if (wxStrcmp (buf, _T("3")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3")); + prec = 0; + wxSprintf (buf, _T("%.*G"), prec, 3.3); + if (wxStrcmp (buf, _T("3")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T("3")); + prec = 0; + wxSprintf (buf, _T("%7.*G"), prec, 3.33); + if (wxStrcmp (buf, _T(" 3")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 3")); + prec = 3; + wxSprintf (buf, _T("%04.*o"), prec, 33); + if (wxStrcmp (buf, _T(" 041")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 041")); + prec = 7; + wxSprintf (buf, _T("%09.*u"), prec, 33); + if (wxStrcmp (buf, _T(" 0000033")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 0000033")); + prec = 3; + wxSprintf (buf, _T("%04.*x"), prec, 33); + if (wxStrcmp (buf, _T(" 021")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021")); + prec = 3; + wxSprintf (buf, _T("%04.*X"), prec, 33); + if (wxStrcmp (buf, _T(" 021")) != 0) + wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021")); +} + +#endif // TEST_PRINTF + // ---------------------------------------------------------------------------- // registry and related stuff // ---------------------------------------------------------------------------- @@ -2793,7 +3171,7 @@ static void TestFtpWuFtpd() } else { - size_t size = in->StreamSize(); + size_t size = in->GetSize(); wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size); wxChar *data = new wxChar[size]; @@ -2876,7 +3254,7 @@ static void TestFtpDownload() } else { - size_t size = in->StreamSize(); + size_t size = in->GetSize(); wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size); fflush(stdout); @@ -3481,7 +3859,7 @@ static void TestUnicodeToFromAscii() wxString s = wxString::FromAscii(msg); wxPrintf(_T("Message in Unicode: %s\n"), s.c_str()); - wxPrintf(_T("Message in ASCII: %s\n"), s.ToAscii()); + printf("Message in ASCII: %s\n", (const char *)s.ToAscii()); wxPutchar(_T('\n')); } @@ -3495,7 +3873,7 @@ static void TestUnicodeToFromAscii() #include "wx/encconv.h" #include "wx/buffer.h" -static const unsigned char textInUtf8_[] = +static const unsigned char utf8koi8r[] = { 208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176, 208, 189, 208, 189, 208, 190, 32, 208, 191, 208, 190, 209, 128, 208, @@ -3506,7 +3884,36 @@ static const unsigned char textInUtf8_[] = 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0 }; -#define textInUtf8 ((const char *)textInUtf8_) +static const unsigned char utf8iso8859_1[] = +{ + 0x53, 0x79, 0x73, 0x74, 0xc3, 0xa8, 0x6d, 0x65, 0x73, 0x20, 0x49, 0x6e, + 0x74, 0xc3, 0xa9, 0x67, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x73, 0x20, 0x65, + 0x6e, 0x20, 0x4d, 0xc3, 0xa9, 0x63, 0x61, 0x6e, 0x69, 0x71, 0x75, 0x65, + 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x69, 0x71, 0x75, 0x65, 0x20, 0x65, + 0x74, 0x20, 0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x71, 0x75, 0x65, 0 +}; + +static const unsigned char utf8Invalid[] = +{ + 0x3c, 0x64, 0x69, 0x73, 0x70, 0x6c, 0x61, 0x79, 0x3e, 0x32, 0x30, 0x30, + 0x32, 0xe5, 0xb9, 0xb4, 0x30, 0x39, 0xe6, 0x9c, 0x88, 0x32, 0x35, 0xe6, + 0x97, 0xa5, 0x20, 0x30, 0x37, 0xe6, 0x99, 0x82, 0x33, 0x39, 0xe5, 0x88, + 0x86, 0x35, 0x37, 0xe7, 0xa7, 0x92, 0x3c, 0x2f, 0x64, 0x69, 0x73, 0x70, + 0x6c, 0x61, 0x79, 0 +}; + +static const struct Utf8Data +{ + const unsigned char *text; + size_t len; + const wxChar *charset; + wxFontEncoding encoding; +} utf8data[] = +{ + { utf8Invalid, WXSIZEOF(utf8Invalid), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 }, + { utf8koi8r, WXSIZEOF(utf8koi8r), _T("koi8-r"), wxFONTENCODING_KOI8 }, + { utf8iso8859_1, WXSIZEOF(utf8iso8859_1), _T("iso8859-1"), wxFONTENCODING_ISO8859_1 }, +}; static void TestUtf8() { @@ -3514,30 +3921,33 @@ static void TestUtf8() char buf[1024]; wchar_t wbuf[1024]; - if ( wxConvUTF8.MB2WC(wbuf, textInUtf8, WXSIZEOF(textInUtf8)) <= 0 ) - { - wxPuts(_T("ERROR: UTF-8 decoding failed.")); - } - else + + for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ ) { - wxCSConv conv(_T("koi8-r")); - if ( conv.WC2MB(buf, wbuf, 0 /* not needed wcslen(wbuf) */) <= 0 ) + const Utf8Data& u8d = utf8data[n]; + if ( wxConvUTF8.MB2WC(wbuf, (const char *)u8d.text, + WXSIZEOF(wbuf)) == (size_t)-1 ) { - wxPuts(_T("ERROR: conversion to KOI8-R failed.")); + wxPuts(_T("ERROR: UTF-8 decoding failed.")); } else { - wxPrintf(_T("The resulting string (in KOI8-R): %s\n"), buf); + wxCSConv conv(u8d.charset); + if ( conv.WC2MB(buf, wbuf, WXSIZEOF(buf)) == (size_t)-1 ) + { + wxPrintf(_T("ERROR: conversion to %s failed.\n"), u8d.charset); + } + else + { + wxPrintf(_T("String in %s: %s\n"), u8d.charset, buf); + } } - } - if ( wxConvUTF8.WC2MB(buf, L"à la", WXSIZEOF(buf)) <= 0 ) - { - wxPuts(_T("ERROR: conversion to UTF-8 failed.")); - } - else - { - wxPrintf(_T("The string in UTF-8: %s\n"), buf); + wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text), *wxConvCurrent); + if ( s.empty() ) + s = _T("<< conversion failed >>"); + wxPrintf(_T("String in current cset: %s\n"), s.c_str()); + } wxPuts(_T("")); @@ -3550,7 +3960,8 @@ static void TestEncodingConverter() // using wxEncodingConverter should give the same result as above char buf[1024]; wchar_t wbuf[1024]; - if ( wxConvUTF8.MB2WC(wbuf, textInUtf8, WXSIZEOF(textInUtf8)) <= 0 ) + if ( wxConvUTF8.MB2WC(wbuf, (const char *)utf8koi8r, + WXSIZEOF(utf8koi8r)) == (size_t)-1 ) { wxPuts(_T("ERROR: UTF-8 decoding failed.")); } @@ -3559,7 +3970,7 @@ static void TestEncodingConverter() wxEncodingConverter ec; ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8); ec.Convert(wbuf, buf); - wxPrintf(_T("The same string obtained using wxEC: %s\n"), buf); + wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf); } wxPuts(_T("")); @@ -4226,12 +4637,8 @@ for n in range(20): wxPrintf(_T(" (ERROR: should be %d)"), wn.dnum); } - wxPrintf(_T(", week in month is %d"), wmon); - if ( wmon == wn.wmon ) - { - wxPrintf(_T(" (ok)")); - } - else + wxPrintf(_T(", week in month = %d"), wmon); + if ( wmon != wn.wmon ) { wxPrintf(_T(" (ERROR: should be %d)"), wn.wmon); } @@ -4246,14 +4653,22 @@ for n in range(20): wxPrintf(_T(" (ERROR: should be %d)"), wn.wmon2); } - wxPrintf(_T(", week in year is %d"), week); - if ( week == wn.week ) + wxPrintf(_T(", week in year = %d"), week); + if ( week != wn.week ) { - wxPuts(_T(" (ok)")); + wxPrintf(_T(" (ERROR: should be %d)"), wn.week); } - else + + wxPutchar(_T('\n')); + + wxDateTime dt2(1, wxDateTime::Jan, d.year); + dt2.SetToTheWeek(wn.week, dt.GetWeekDay()); + if ( dt2 != dt ) { - wxPrintf(_T(" (ERROR: should be %d)\n"), wn.week); + Date d2; + d2.Init(dt2.GetTm()); + wxPrintf(_T("ERROR: SetToTheWeek() returned %s\n"), + d2.FormatDate().c_str()); } } } @@ -4367,7 +4782,7 @@ static void TestTimeFormat() { CompareBoth, _T("Date is %x, time is %X") }, { CompareTime, _T("Time is %H:%M:%S or %I:%M:%S %p") }, { CompareNone, _T("The day of year: %j, the week of year: %W") }, - { CompareDate, _T("ISO date without separators: %4Y%2m%2d") }, + { CompareDate, _T("ISO date without separators: %Y%m%d") }, }; static const Date formatTestDates[] = @@ -4742,6 +5157,45 @@ static void TestTimeCompatibility() #endif // TEST_DATETIME +// ---------------------------------------------------------------------------- +// wxTextInput/OutputStream +// ---------------------------------------------------------------------------- + +#ifdef TEST_TEXTSTREAM + +#include "wx/txtstrm.h" +#include "wx/wfstream.h" + +static void TestTextInputStream() +{ + wxPuts(_T("\n*** wxTextInputStream test ***")); + + wxFileInputStream fsIn(_T("testdata.fc")); + if ( !fsIn.Ok() ) + { + wxPuts(_T("ERROR: couldn't open file.")); + } + else + { + wxTextInputStream tis(fsIn); + + size_t line = 1; + for ( ;; ) + { + const wxString s = tis.ReadLine(); + + // line could be non empty if the last line of the file isn't + // terminated with EOL + if ( fsIn.Eof() && s.empty() ) + break; + + wxPrintf(_T("Line %d: %s\n"), line++, s.c_str()); + } + } +} + +#endif // TEST_TEXTSTREAM + // ---------------------------------------------------------------------------- // threads // ---------------------------------------------------------------------------- @@ -6028,7 +6482,8 @@ int main(int argc, char **argv) TestLongLongConversion(); TestBitOperations(); TestLongLongComparison(); - TestLongLongPrint(); + TestLongLongToString(); + TestLongLongPrintf(); } #endif // TEST_LONGLONG @@ -6070,6 +6525,10 @@ int main(int argc, char **argv) TestDbOpen(); #endif // TEST_ODBC +#ifdef TEST_PRINTF + TestPrintf(); +#endif // TEST_PRINTF + #ifdef TEST_REGCONF TestRegConfWrite(); #endif // TEST_REGCONF @@ -6106,23 +6565,26 @@ int main(int argc, char **argv) TestMemoryStream(); #endif // TEST_STREAMS +#ifdef TEST_TEXTSTREAM + TestTextInputStream(); +#endif // TEST_TEXTSTREAM + #ifdef TEST_THREADS int nCPUs = wxThread::GetCPUCount(); wxPrintf(_T("This system has %d CPUs\n"), nCPUs); if ( nCPUs != -1 ) wxThread::SetConcurrency(nCPUs); + TestDetachedThreads(); if ( TEST_ALL ) { - TestDetachedThreads(); TestJoinableThreads(); TestThreadSuspend(); TestThreadDelete(); TestThreadConditions(); TestThreadExec(); + TestSemaphore(); } - - TestSemaphore(); #endif // TEST_THREADS #ifdef TEST_TIMER @@ -6151,6 +6613,8 @@ int main(int argc, char **argv) TestTimeZoneBug(); } + TestTimeWNumber(); + if ( TEST_INTERACTIVE ) TestDateTimeInteractive(); #endif // TEST_DATETIME