+ }
+ }
+ }
+}
+
+#endif // TEST_REGEX
+
+// ----------------------------------------------------------------------------
+// database
+// ----------------------------------------------------------------------------
+
+#if !wxUSE_ODBC
+ #undef TEST_ODBC
+#endif
+
+#ifdef TEST_ODBC
+
+#include <wx/db.h>
+
+static void TestDbOpen()
+{
+ HENV henv;
+ wxDb db(henv);
+}
+
+#endif // TEST_ODBC
+
+// ----------------------------------------------------------------------------
+// printf() tests
+// ----------------------------------------------------------------------------
+
+/*
+ NB: this stuff was taken from the glibc test suite and modified to build
+ in wxWidgets: 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 <float.h>
+
+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.
+ */
+
+wxChar *PointerNull = NULL;
+
+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"), PointerNull);
+ wxPrintf(_T("%-10s\n"), PointerNull);
+}
+
+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;
+ wxString test_format;
+
+ 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"));
+
+ wxString bad_format = _T("bad format:\t\"%b\"\n");
+ wxPrintf(bad_format.c_str());
+ 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);
+ test_format = _T("left-adjusted ZLDN:\t\"%-010ld\"\n");
+ wxPrintf(test_format.c_str(), -123456);
+ wxPrintf(_T("space-padded LDN:\t\"%10ld\"\n"), -123456L);
+ wxPrintf(_T("left-adjusted SLDN:\t\"%-10ld\"\n"), -123456L);
+
+ test_format = _T("zero-padded string:\t\"%010s\"\n");
+ wxPrintf(test_format.c_str(), shortstr);
+ test_format = _T("left-adjusted Z string:\t\"%-010s\"\n");
+ wxPrintf(test_format.c_str(), 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"), PointerNull);
+ 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);
+ }
+
+#ifndef __WATCOMC__
+ // Open Watcom cause compiler error here
+ // Error! E173: col(24) floating-point constant too small to represent
+ wxPrintf (_T("%15.5e\n"), 4.9406564584124654e-324);
+#endif
+
+#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));
+ #if 0
+ // for some reason below line fails under Borland
+ wxPrintf (_T("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s"), buf);
+ #endif
+
+ if (wxStrcmp (buf, _T("40000000000")) != 0)
+ {
+ result = 1;
+ wxPuts (_T("\tFAILED"));
+ }
+ wxUnusedVar(result);
+ wxPuts (wxEmptyString);
+ }
+#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];
+ wxString test_format;
+
+ 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;
+ test_format = _T("%04.*o");
+ wxSprintf (buf, test_format.c_str(), prec, 33);
+ if (wxStrcmp (buf, _T(" 041")) != 0)
+ wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 041"));
+ prec = 7;
+ test_format = _T("%09.*u");
+ wxSprintf (buf, test_format.c_str(), prec, 33);
+ if (wxStrcmp (buf, _T(" 0000033")) != 0)
+ wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 0000033"));
+ prec = 3;
+ test_format = _T("%04.*x");
+ wxSprintf (buf, test_format.c_str(), prec, 33);
+ if (wxStrcmp (buf, _T(" 021")) != 0)
+ wxPrintf (_T("got: '%s', expected: '%s'\n"), buf, _T(" 021"));
+ prec = 3;
+ test_format = _T("%04.*X");
+ wxSprintf (buf, test_format.c_str(), 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
+// ----------------------------------------------------------------------------
+
+// this is for MSW only
+#ifndef __WXMSW__
+ #undef TEST_REGCONF
+ #undef TEST_REGISTRY
+#endif
+
+#ifdef TEST_REGCONF
+
+#include "wx/confbase.h"
+#include "wx/msw/regconf.h"
+
+#if 0
+static void TestRegConfWrite()
+{
+ wxConfig *config = new wxConfig(_T("myapp"));
+ config->SetPath(_T("/group1"));
+ config->Write(_T("entry1"), _T("foo"));
+ config->SetPath(_T("/group2"));
+ config->Write(_T("entry1"), _T("bar"));
+}
+#endif
+
+static void TestRegConfRead()
+{
+ wxConfig *config = new wxConfig(_T("myapp"));
+
+ wxString str;
+ long dummy;
+ config->SetPath(_T("/"));
+ wxPuts(_T("Enumerating / subgroups:"));
+ bool bCont = config->GetFirstGroup(str, dummy);
+ while(bCont)
+ {
+ wxPuts(str);
+ bCont = config->GetNextGroup(str, dummy);
+ }
+}
+
+#endif // TEST_REGCONF
+
+#ifdef TEST_REGISTRY
+
+#include "wx/msw/registry.h"
+
+// I chose this one because I liked its name, but it probably only exists under
+// NT
+static const wxChar *TESTKEY =
+ _T("HKEY_LOCAL_MACHINE\\SYSTEM\\ControlSet001\\Control\\CrashControl");
+
+static void TestRegistryRead()
+{
+ wxPuts(_T("*** testing registry reading ***"));
+
+ wxRegKey key(TESTKEY);
+ wxPrintf(_T("The test key name is '%s'.\n"), key.GetName().c_str());
+ if ( !key.Open() )
+ {
+ wxPuts(_T("ERROR: test key can't be opened, aborting test."));
+
+ return;
+ }
+
+ size_t nSubKeys, nValues;
+ if ( key.GetKeyInfo(&nSubKeys, NULL, &nValues, NULL) )
+ {
+ wxPrintf(_T("It has %u subkeys and %u values.\n"), nSubKeys, nValues);
+ }
+
+ wxPrintf(_T("Enumerating values:\n"));
+
+ long dummy;
+ wxString value;
+ bool cont = key.GetFirstValue(value, dummy);
+ while ( cont )
+ {
+ wxPrintf(_T("Value '%s': type "), value.c_str());
+ switch ( key.GetValueType(value) )
+ {
+ case wxRegKey::Type_None: wxPrintf(_T("ERROR (none)")); break;
+ case wxRegKey::Type_String: wxPrintf(_T("SZ")); break;
+ case wxRegKey::Type_Expand_String: wxPrintf(_T("EXPAND_SZ")); break;
+ case wxRegKey::Type_Binary: wxPrintf(_T("BINARY")); break;
+ case wxRegKey::Type_Dword: wxPrintf(_T("DWORD")); break;
+ case wxRegKey::Type_Multi_String: wxPrintf(_T("MULTI_SZ")); break;
+ default: wxPrintf(_T("other (unknown)")); break;
+ }
+
+ wxPrintf(_T(", value = "));
+ if ( key.IsNumericValue(value) )
+ {
+ long val;
+ key.QueryValue(value, &val);
+ wxPrintf(_T("%ld"), val);
+ }
+ else // string
+ {
+ wxString val;
+ key.QueryValue(value, val);
+ wxPrintf(_T("'%s'"), val.c_str());
+
+ key.QueryRawValue(value, val);
+ wxPrintf(_T(" (raw value '%s')"), val.c_str());
+ }
+
+ wxPutchar('\n');
+
+ cont = key.GetNextValue(value, dummy);
+ }
+}
+
+static void TestRegistryAssociation()
+{
+ /*
+ The second call to deleteself genertaes an error message, with a
+ messagebox saying .flo is crucial to system operation, while the .ddf
+ call also fails, but with no error message
+ */
+
+ wxRegKey key;
+
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
+ key.Create();
+ key = _T("ddxf_auto_file") ;
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
+ key.Create();
+ key = _T("ddxf_auto_file") ;
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
+ key.Create();
+ key = _T("program,0") ;
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
+ key.Create();
+ key = _T("program \"%1\"") ;
+
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.ddf") );
+ key.DeleteSelf();
+ key.SetName(_T("HKEY_CLASSES_ROOT\\.flo") );
+ key.DeleteSelf();
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon"));
+ key.DeleteSelf();
+ key.SetName(_T("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command"));
+ key.DeleteSelf();
+}
+
+#endif // TEST_REGISTRY
+
+// ----------------------------------------------------------------------------
+// scope guard
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_SCOPEGUARD
+
+#include "wx/scopeguard.h"
+
+static void function0() { puts("function0()"); }
+static void function1(int n) { printf("function1(%d)\n", n); }
+static void function2(double x, char c) { printf("function2(%g, %c)\n", x, c); }
+
+struct Object
+{
+ void method0() { printf("method0()\n"); }
+ void method1(int n) { printf("method1(%d)\n", n); }
+ void method2(double x, char c) { printf("method2(%g, %c)\n", x, c); }
+};
+
+static void TestScopeGuard()
+{
+ wxON_BLOCK_EXIT0(function0);
+ wxON_BLOCK_EXIT1(function1, 17);
+ wxON_BLOCK_EXIT2(function2, 3.14, 'p');
+
+ Object obj;
+ wxON_BLOCK_EXIT_OBJ0(obj, &Object::method0);
+ wxON_BLOCK_EXIT_OBJ1(obj, &Object::method1, 7);
+ wxON_BLOCK_EXIT_OBJ2(obj, &Object::method2, 2.71, 'e');
+
+ wxScopeGuard dismissed = wxMakeGuard(function0);
+ dismissed.Dismiss();
+}
+
+#endif
+
+// ----------------------------------------------------------------------------
+// sockets
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_SOCKETS
+
+#include "wx/socket.h"
+#include "wx/protocol/protocol.h"
+#include "wx/protocol/http.h"
+
+static void TestSocketServer()
+{
+ wxPuts(_T("*** Testing wxSocketServer ***\n"));
+
+ static const int PORT = 3000;
+
+ wxIPV4address addr;
+ addr.Service(PORT);
+
+ wxSocketServer *server = new wxSocketServer(addr);
+ if ( !server->Ok() )
+ {
+ wxPuts(_T("ERROR: failed to bind"));
+
+ return;
+ }
+
+ bool quit = false;
+ while ( !quit )
+ {
+ wxPrintf(_T("Server: waiting for connection on port %d...\n"), PORT);
+
+ wxSocketBase *socket = server->Accept();
+ if ( !socket )
+ {
+ wxPuts(_T("ERROR: wxSocketServer::Accept() failed."));
+ break;
+ }
+
+ wxPuts(_T("Server: got a client."));
+
+ server->SetTimeout(60); // 1 min
+
+ bool close = false;
+ while ( !close && socket->IsConnected() )
+ {
+ wxString s;
+ wxChar ch = _T('\0');
+ for ( ;; )
+ {
+ if ( socket->Read(&ch, sizeof(ch)).Error() )
+ {
+ // don't log error if the client just close the connection
+ if ( socket->IsConnected() )
+ {
+ wxPuts(_T("ERROR: in wxSocket::Read."));
+ }
+
+ break;
+ }
+
+ if ( ch == '\r' )
+ continue;
+
+ if ( ch == '\n' )
+ break;
+
+ s += ch;
+ }
+
+ if ( ch != '\n' )
+ {
+ break;
+ }
+
+ wxPrintf(_T("Server: got '%s'.\n"), s.c_str());
+ if ( s == _T("close") )
+ {
+ wxPuts(_T("Closing connection"));
+
+ close = true;
+ }
+ else if ( s == _T("quit") )
+ {
+ close =
+ quit = true;
+
+ wxPuts(_T("Shutting down the server"));
+ }
+ else // not a special command
+ {
+ socket->Write(s.MakeUpper().c_str(), s.length());
+ socket->Write("\r\n", 2);
+ wxPrintf(_T("Server: wrote '%s'.\n"), s.c_str());
+ }
+ }
+
+ if ( !close )
+ {
+ wxPuts(_T("Server: lost a client unexpectedly."));
+ }
+
+ socket->Destroy();
+ }
+
+ // same as "delete server" but is consistent with GUI programs
+ server->Destroy();
+}
+
+static void TestSocketClient()
+{
+ wxPuts(_T("*** Testing wxSocketClient ***\n"));
+
+ static const wxChar *hostname = _T("www.wxwidgets.org");
+
+ wxIPV4address addr;
+ addr.Hostname(hostname);
+ addr.Service(80);
+
+ wxPrintf(_T("--- Attempting to connect to %s:80...\n"), hostname);
+
+ wxSocketClient client;
+ if ( !client.Connect(addr) )
+ {
+ wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
+ }
+ else
+ {
+ wxPrintf(_T("--- Connected to %s:%u...\n"),
+ addr.Hostname().c_str(), addr.Service());
+
+ wxChar buf[8192];
+
+ // could use simply "GET" here I suppose
+ wxString cmdGet =
+ wxString::Format(_T("GET http://%s/\r\n"), hostname);
+ client.Write(cmdGet, cmdGet.length());
+ wxPrintf(_T("--- Sent command '%s' to the server\n"),
+ MakePrintable(cmdGet).c_str());
+ client.Read(buf, WXSIZEOF(buf));
+ wxPrintf(_T("--- Server replied:\n%s"), buf);
+ }
+}
+
+#endif // TEST_SOCKETS
+
+// ----------------------------------------------------------------------------
+// FTP
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_FTP
+
+#include "wx/protocol/ftp.h"
+
+static wxFTP ftp;
+
+#define FTP_ANONYMOUS
+
+#ifdef FTP_ANONYMOUS
+ static const wxChar *directory = _T("/pub");
+ static const wxChar *filename = _T("welcome.msg");
+#else
+ static const wxChar *directory = _T("/etc");
+ static const wxChar *filename = _T("issue");
+#endif
+
+static bool TestFtpConnect()
+{
+ wxPuts(_T("*** Testing FTP connect ***"));
+
+#ifdef FTP_ANONYMOUS
+ static const wxChar *hostname = _T("ftp.wxwidgets.org");
+
+ wxPrintf(_T("--- Attempting to connect to %s:21 anonymously...\n"), hostname);
+#else // !FTP_ANONYMOUS
+ static const wxChar *hostname = "localhost";
+
+ wxChar user[256];
+ wxFgets(user, WXSIZEOF(user), stdin);
+ user[wxStrlen(user) - 1] = '\0'; // chop off '\n'
+ ftp.SetUser(user);
+
+ wxChar password[256];
+ wxPrintf(_T("Password for %s: "), password);
+ wxFgets(password, WXSIZEOF(password), stdin);
+ password[wxStrlen(password) - 1] = '\0'; // chop off '\n'
+ ftp.SetPassword(password);
+
+ wxPrintf(_T("--- Attempting to connect to %s:21 as %s...\n"), hostname, user);
+#endif // FTP_ANONYMOUS/!FTP_ANONYMOUS
+
+ if ( !ftp.Connect(hostname) )
+ {
+ wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
+
+ return false;
+ }
+ else
+ {
+ wxPrintf(_T("--- Connected to %s, current directory is '%s'\n"),
+ hostname, ftp.Pwd().c_str());
+ ftp.Close();
+ }
+
+ return true;
+}
+
+// test (fixed?) wxFTP bug with wu-ftpd >= 2.6.0?
+static void TestFtpWuFtpd()
+{
+ wxFTP ftp;
+ static const wxChar *hostname = _T("ftp.eudora.com");
+ if ( !ftp.Connect(hostname) )
+ {
+ wxPrintf(_T("ERROR: failed to connect to %s\n"), hostname);
+ }
+ else
+ {
+ static const wxChar *filename = _T("eudora/pubs/draft-gellens-submit-09.txt");
+ wxInputStream *in = ftp.GetInputStream(filename);
+ if ( !in )
+ {
+ wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename);
+ }
+ else
+ {
+ size_t size = in->GetSize();
+ wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size);
+
+ wxChar *data = new wxChar[size];
+ if ( !in->Read(data, size) )
+ {
+ wxPuts(_T("ERROR: read error"));
+ }
+ else
+ {
+ wxPrintf(_T("Successfully retrieved the file.\n"));
+ }
+
+ delete [] data;
+ delete in;
+ }
+ }
+}
+
+static void TestFtpList()
+{
+ wxPuts(_T("*** Testing wxFTP file listing ***\n"));
+
+ // test CWD
+ if ( !ftp.ChDir(directory) )
+ {
+ wxPrintf(_T("ERROR: failed to cd to %s\n"), directory);
+ }
+
+ wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
+
+ // test NLIST and LIST
+ wxArrayString files;
+ if ( !ftp.GetFilesList(files) )
+ {
+ wxPuts(_T("ERROR: failed to get NLIST of files"));
+ }
+ else
+ {
+ wxPrintf(_T("Brief list of files under '%s':\n"), ftp.Pwd().c_str());
+ size_t count = files.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxPrintf(_T("\t%s\n"), files[n].c_str());
+ }
+ wxPuts(_T("End of the file list"));
+ }
+
+ if ( !ftp.GetDirList(files) )
+ {
+ wxPuts(_T("ERROR: failed to get LIST of files"));
+ }
+ else
+ {
+ wxPrintf(_T("Detailed list of files under '%s':\n"), ftp.Pwd().c_str());
+ size_t count = files.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxPrintf(_T("\t%s\n"), files[n].c_str());
+ }
+ wxPuts(_T("End of the file list"));
+ }
+
+ if ( !ftp.ChDir(_T("..")) )
+ {
+ wxPuts(_T("ERROR: failed to cd to .."));
+ }
+
+ wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
+}
+
+static void TestFtpDownload()
+{
+ wxPuts(_T("*** Testing wxFTP download ***\n"));
+
+ // test RETR
+ wxInputStream *in = ftp.GetInputStream(filename);
+ if ( !in )
+ {
+ wxPrintf(_T("ERROR: couldn't get input stream for %s\n"), filename);
+ }
+ else
+ {
+ size_t size = in->GetSize();
+ wxPrintf(_T("Reading file %s (%u bytes)..."), filename, size);
+ fflush(stdout);
+
+ wxChar *data = new wxChar[size];
+ if ( !in->Read(data, size) )
+ {
+ wxPuts(_T("ERROR: read error"));
+ }
+ else
+ {
+ wxPrintf(_T("\nContents of %s:\n%s\n"), filename, data);
+ }
+
+ delete [] data;
+ delete in;
+ }
+}
+
+static void TestFtpFileSize()
+{
+ wxPuts(_T("*** Testing FTP SIZE command ***"));
+
+ if ( !ftp.ChDir(directory) )
+ {
+ wxPrintf(_T("ERROR: failed to cd to %s\n"), directory);
+ }
+
+ wxPrintf(_T("Current directory is '%s'\n"), ftp.Pwd().c_str());
+
+ if ( ftp.FileExists(filename) )
+ {
+ int size = ftp.GetFileSize(filename);
+ if ( size == -1 )
+ wxPrintf(_T("ERROR: couldn't get size of '%s'\n"), filename);
+ else
+ wxPrintf(_T("Size of '%s' is %d bytes.\n"), filename, size);
+ }
+ else
+ {
+ wxPrintf(_T("ERROR: '%s' doesn't exist\n"), filename);
+ }
+}
+
+static void TestFtpMisc()
+{
+ wxPuts(_T("*** Testing miscellaneous wxFTP functions ***"));
+
+ if ( ftp.SendCommand(_T("STAT")) != '2' )
+ {
+ wxPuts(_T("ERROR: STAT failed"));
+ }
+ else
+ {
+ wxPrintf(_T("STAT returned:\n\n%s\n"), ftp.GetLastResult().c_str());
+ }
+
+ if ( ftp.SendCommand(_T("HELP SITE")) != '2' )
+ {
+ wxPuts(_T("ERROR: HELP SITE failed"));
+ }
+ else
+ {
+ wxPrintf(_T("The list of site-specific commands:\n\n%s\n"),
+ ftp.GetLastResult().c_str());
+ }
+}
+
+static void TestFtpInteractive()
+{
+ wxPuts(_T("\n*** Interactive wxFTP test ***"));
+
+ wxChar buf[128];
+
+ for ( ;; )
+ {
+ wxPrintf(_T("Enter FTP command: "));
+ if ( !wxFgets(buf, WXSIZEOF(buf), stdin) )
+ break;
+
+ // kill the last '\n'
+ buf[wxStrlen(buf) - 1] = 0;
+
+ // special handling of LIST and NLST as they require data connection
+ wxString start(buf, 4);
+ start.MakeUpper();
+ if ( start == _T("LIST") || start == _T("NLST") )
+ {
+ wxString wildcard;
+ if ( wxStrlen(buf) > 4 )
+ wildcard = buf + 5;
+
+ wxArrayString files;
+ if ( !ftp.GetList(files, wildcard, start == _T("LIST")) )
+ {
+ wxPrintf(_T("ERROR: failed to get %s of files\n"), start.c_str());
+ }
+ else
+ {
+ wxPrintf(_T("--- %s of '%s' under '%s':\n"),
+ start.c_str(), wildcard.c_str(), ftp.Pwd().c_str());
+ size_t count = files.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxPrintf(_T("\t%s\n"), files[n].c_str());
+ }
+ wxPuts(_T("--- End of the file list"));
+ }
+ }
+ else // !list
+ {
+ wxChar ch = ftp.SendCommand(buf);
+ wxPrintf(_T("Command %s"), ch ? _T("succeeded") : _T("failed"));
+ if ( ch )
+ {
+ wxPrintf(_T(" (return code %c)"), ch);
+ }
+
+ wxPrintf(_T(", server reply:\n%s\n\n"), ftp.GetLastResult().c_str());
+ }
+ }
+
+ wxPuts(_T("\n*** done ***"));
+}
+
+static void TestFtpUpload()
+{
+ wxPuts(_T("*** Testing wxFTP uploading ***\n"));
+
+ // upload a file
+ static const wxChar *file1 = _T("test1");
+ static const wxChar *file2 = _T("test2");
+ wxOutputStream *out = ftp.GetOutputStream(file1);
+ if ( out )
+ {
+ wxPrintf(_T("--- Uploading to %s ---\n"), file1);
+ out->Write("First hello", 11);
+ delete out;
+ }
+
+ // send a command to check the remote file
+ if ( ftp.SendCommand(wxString(_T("STAT ")) + file1) != '2' )
+ {
+ wxPrintf(_T("ERROR: STAT %s failed\n"), file1);
+ }
+ else
+ {
+ wxPrintf(_T("STAT %s returned:\n\n%s\n"),
+ file1, ftp.GetLastResult().c_str());
+ }
+
+ out = ftp.GetOutputStream(file2);
+ if ( out )
+ {
+ wxPrintf(_T("--- Uploading to %s ---\n"), file1);
+ out->Write("Second hello", 12);
+ delete out;
+ }
+}
+
+#endif // TEST_FTP
+
+// ----------------------------------------------------------------------------
+// stack backtrace
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_STACKWALKER
+
+#include "wx/stackwalk.h"
+
+class StackDump : public wxStackWalker
+{
+public:
+ StackDump(const char *argv0)
+ : wxStackWalker(argv0)
+ {
+ }
+
+ virtual void Walk()
+ {
+ wxPuts(_T("Stack dump:"));
+
+ wxStackWalker::Walk();
+ }
+
+protected:
+ virtual void OnStackFrame(const wxStackFrame& frame)
+ {
+ printf("[%2d] ", frame.GetLevel());
+
+ wxString name = frame.GetName();
+ if ( !name.empty() )
+ {
+ printf("%-20.40s", name.mb_str());
+ }
+ else
+ {
+ printf("0x%08lx", (unsigned long)frame.GetAddress());
+ }
+
+ if ( frame.HasSourceLocation() )
+ {
+ printf("\t%s:%d",
+ frame.GetFileName().mb_str(),
+ frame.GetLine());
+ }
+
+ puts("");
+
+ wxString type, val;
+ for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ )
+ {
+ printf("\t%s %s = %s\n", type.mb_str(), name.mb_str(), val.mb_str());
+ }
+ }
+};
+
+static void TestStackWalk(const char *argv0)
+{
+ wxPuts(_T("*** Testing wxStackWalker ***\n"));
+
+ StackDump dump(argv0);
+ dump.Walk();
+}
+
+#endif // TEST_STACKWALKER
+
+// ----------------------------------------------------------------------------
+// standard paths
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_STDPATHS
+
+#include "wx/stdpaths.h"
+
+static void TestStandardPaths()
+{
+ wxPuts(_T("*** Testing wxStandardPaths ***\n"));
+
+ wxTheApp->SetAppName(_T("console"));
+
+ wxStandardPaths& stdp = wxStandardPaths::Get();
+ wxPrintf(_T("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str());
+ wxPrintf(_T("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str());
+ wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str());
+ wxPrintf(_T("Data dir (sys local):\t%s\n"), stdp.GetLocalDataDir().c_str());
+ wxPrintf(_T("Data dir (user):\t%s\n"), stdp.GetUserDataDir().c_str());
+ wxPrintf(_T("Data dir (user local):\t%s\n"), stdp.GetUserLocalDataDir().c_str());
+ wxPrintf(_T("Plugins dir:\t\t%s\n"), stdp.GetPluginsDir().c_str());
+}
+
+#endif // TEST_STDPATHS
+
+// ----------------------------------------------------------------------------
+// streams
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_STREAMS
+
+#include "wx/wfstream.h"
+#include "wx/mstream.h"
+
+static void TestFileStream()
+{
+ wxPuts(_T("*** Testing wxFileInputStream ***"));
+
+ static const wxString filename = _T("testdata.fs");
+ {
+ wxFileOutputStream fsOut(filename);
+ fsOut.Write("foo", 3);
+ }
+
+ wxFileInputStream fsIn(filename);
+ wxPrintf(_T("File stream size: %u\n"), fsIn.GetSize());
+ while ( !fsIn.Eof() )
+ {
+ wxPutchar(fsIn.GetC());
+ }
+
+ if ( !wxRemoveFile(filename) )
+ {
+ wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename.c_str());
+ }
+
+ wxPuts(_T("\n*** wxFileInputStream test done ***"));
+}
+
+static void TestMemoryStream()
+{
+ wxPuts(_T("*** Testing wxMemoryOutputStream ***"));
+
+ wxMemoryOutputStream memOutStream;
+ wxPrintf(_T("Initially out stream offset: %lu\n"),
+ (unsigned long)memOutStream.TellO());
+
+ for ( const wxChar *p = _T("Hello, stream!"); *p; p++ )
+ {
+ memOutStream.PutC(*p);
+ }
+
+ wxPrintf(_T("Final out stream offset: %lu\n"),
+ (unsigned long)memOutStream.TellO());
+
+ wxPuts(_T("*** Testing wxMemoryInputStream ***"));
+
+ wxChar buf[1024];
+ size_t len = memOutStream.CopyTo(buf, WXSIZEOF(buf));
+
+ wxMemoryInputStream memInpStream(buf, len);
+ wxPrintf(_T("Memory stream size: %u\n"), memInpStream.GetSize());
+ while ( !memInpStream.Eof() )
+ {
+ wxPutchar(memInpStream.GetC());
+ }
+
+ wxPuts(_T("\n*** wxMemoryInputStream test done ***"));
+}
+
+#endif // TEST_STREAMS
+
+// ----------------------------------------------------------------------------
+// timers
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_TIMER
+
+#include "wx/timer.h"
+#include "wx/utils.h"
+
+static void TestStopWatch()
+{
+ wxPuts(_T("*** Testing wxStopWatch ***\n"));
+
+ wxStopWatch sw;
+ sw.Pause();
+ wxPrintf(_T("Initially paused, after 2 seconds time is..."));
+ fflush(stdout);
+ wxSleep(2);
+ wxPrintf(_T("\t%ldms\n"), sw.Time());
+
+ wxPrintf(_T("Resuming stopwatch and sleeping 3 seconds..."));
+ fflush(stdout);
+ sw.Resume();
+ wxSleep(3);
+ wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
+
+ sw.Pause();
+ wxPrintf(_T("Pausing agan and sleeping 2 more seconds..."));
+ fflush(stdout);
+ wxSleep(2);
+ wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
+
+ sw.Resume();
+ wxPrintf(_T("Finally resuming and sleeping 2 more seconds..."));
+ fflush(stdout);
+ wxSleep(2);
+ wxPrintf(_T("\telapsed time: %ldms\n"), sw.Time());
+
+ wxStopWatch sw2;
+ wxPuts(_T("\nChecking for 'backwards clock' bug..."));
+ for ( size_t n = 0; n < 70; n++ )
+ {
+ sw2.Start();
+
+ for ( size_t m = 0; m < 100000; m++ )
+ {
+ if ( sw.Time() < 0 || sw2.Time() < 0 )
+ {
+ wxPuts(_T("\ntime is negative - ERROR!"));
+ }
+ }
+
+ wxPutchar('.');
+ fflush(stdout);
+ }
+
+ wxPuts(_T(", ok."));
+}
+
+#endif // TEST_TIMER
+
+// ----------------------------------------------------------------------------
+// vCard support
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_VCARD
+
+#include "wx/vcard.h"
+
+static void DumpVObject(size_t level, const wxVCardObject& vcard)
+{
+ void *cookie;
+ wxVCardObject *vcObj = vcard.GetFirstProp(&cookie);
+ while ( vcObj )
+ {
+ wxPrintf(_T("%s%s"),
+ wxString(_T('\t'), level).c_str(),
+ vcObj->GetName().c_str());
+
+ wxString value;
+ switch ( vcObj->GetType() )
+ {
+ case wxVCardObject::String:
+ case wxVCardObject::UString:
+ {
+ wxString val;
+ vcObj->GetValue(&val);
+ value << _T('"') << val << _T('"');
+ }
+ break;
+
+ case wxVCardObject::Int:
+ {
+ unsigned int i;
+ vcObj->GetValue(&i);
+ value.Printf(_T("%u"), i);
+ }
+ break;
+
+ case wxVCardObject::Long:
+ {
+ unsigned long l;
+ vcObj->GetValue(&l);
+ value.Printf(_T("%lu"), l);
+ }
+ break;
+
+ case wxVCardObject::None:
+ break;
+
+ case wxVCardObject::Object:
+ value = _T("<node>");
+ break;
+
+ default:
+ value = _T("<unknown value type>");
+ }
+
+ if ( !!value )
+ wxPrintf(_T(" = %s"), value.c_str());
+ wxPutchar('\n');
+
+ DumpVObject(level + 1, *vcObj);
+
+ delete vcObj;
+ vcObj = vcard.GetNextProp(&cookie);
+ }
+}
+
+static void DumpVCardAddresses(const wxVCard& vcard)
+{
+ wxPuts(_T("\nShowing all addresses from vCard:\n"));
+
+ size_t nAdr = 0;
+ void *cookie;
+ wxVCardAddress *addr = vcard.GetFirstAddress(&cookie);
+ while ( addr )
+ {
+ wxString flagsStr;
+ int flags = addr->GetFlags();
+ if ( flags & wxVCardAddress::Domestic )
+ {
+ flagsStr << _T("domestic ");
+ }
+ if ( flags & wxVCardAddress::Intl )
+ {
+ flagsStr << _T("international ");
+ }
+ if ( flags & wxVCardAddress::Postal )
+ {
+ flagsStr << _T("postal ");
+ }
+ if ( flags & wxVCardAddress::Parcel )
+ {
+ flagsStr << _T("parcel ");
+ }
+ if ( flags & wxVCardAddress::Home )
+ {
+ flagsStr << _T("home ");
+ }
+ if ( flags & wxVCardAddress::Work )
+ {
+ flagsStr << _T("work ");
+ }
+
+ wxPrintf(_T("Address %u:\n")
+ "\tflags = %s\n"
+ "\tvalue = %s;%s;%s;%s;%s;%s;%s\n",
+ ++nAdr,
+ flagsStr.c_str(),
+ addr->GetPostOffice().c_str(),
+ addr->GetExtAddress().c_str(),
+ addr->GetStreet().c_str(),
+ addr->GetLocality().c_str(),
+ addr->GetRegion().c_str(),
+ addr->GetPostalCode().c_str(),
+ addr->GetCountry().c_str()
+ );
+
+ delete addr;
+ addr = vcard.GetNextAddress(&cookie);
+ }
+}
+
+static void DumpVCardPhoneNumbers(const wxVCard& vcard)
+{
+ wxPuts(_T("\nShowing all phone numbers from vCard:\n"));
+
+ size_t nPhone = 0;
+ void *cookie;
+ wxVCardPhoneNumber *phone = vcard.GetFirstPhoneNumber(&cookie);
+ while ( phone )
+ {
+ wxString flagsStr;
+ int flags = phone->GetFlags();
+ if ( flags & wxVCardPhoneNumber::Voice )
+ {
+ flagsStr << _T("voice ");
+ }
+ if ( flags & wxVCardPhoneNumber::Fax )
+ {
+ flagsStr << _T("fax ");
+ }
+ if ( flags & wxVCardPhoneNumber::Cellular )
+ {
+ flagsStr << _T("cellular ");
+ }
+ if ( flags & wxVCardPhoneNumber::Modem )
+ {
+ flagsStr << _T("modem ");
+ }
+ if ( flags & wxVCardPhoneNumber::Home )
+ {
+ flagsStr << _T("home ");
+ }
+ if ( flags & wxVCardPhoneNumber::Work )
+ {
+ flagsStr << _T("work ");
+ }
+
+ wxPrintf(_T("Phone number %u:\n")
+ "\tflags = %s\n"
+ "\tvalue = %s\n",
+ ++nPhone,
+ flagsStr.c_str(),
+ phone->GetNumber().c_str()
+ );
+
+ delete phone;
+ phone = vcard.GetNextPhoneNumber(&cookie);
+ }
+}
+
+static void TestVCardRead()
+{
+ wxPuts(_T("*** Testing wxVCard reading ***\n"));
+
+ wxVCard vcard(_T("vcard.vcf"));
+ if ( !vcard.IsOk() )
+ {
+ wxPuts(_T("ERROR: couldn't load vCard."));
+ }
+ else
+ {
+ // read individual vCard properties
+ wxVCardObject *vcObj = vcard.GetProperty("FN");
+ wxString value;
+ if ( vcObj )
+ {
+ vcObj->GetValue(&value);
+ delete vcObj;
+ }
+ else
+ {
+ value = _T("<none>");
+ }
+
+ wxPrintf(_T("Full name retrieved directly: %s\n"), value.c_str());
+
+
+ if ( !vcard.GetFullName(&value) )
+ {
+ value = _T("<none>");
+ }
+
+ wxPrintf(_T("Full name from wxVCard API: %s\n"), value.c_str());
+
+ // now show how to deal with multiply occuring properties
+ DumpVCardAddresses(vcard);
+ DumpVCardPhoneNumbers(vcard);
+
+ // and finally show all
+ wxPuts(_T("\nNow dumping the entire vCard:\n")
+ "-----------------------------\n");
+
+ DumpVObject(0, vcard);
+ }
+}
+
+static void TestVCardWrite()
+{
+ wxPuts(_T("*** Testing wxVCard writing ***\n"));
+
+ wxVCard vcard;
+ if ( !vcard.IsOk() )
+ {
+ wxPuts(_T("ERROR: couldn't create vCard."));
+ }
+ else
+ {
+ // set some fields
+ vcard.SetName("Zeitlin", "Vadim");
+ vcard.SetFullName("Vadim Zeitlin");
+ vcard.SetOrganization("wxWidgets", "R&D");
+
+ // just dump the vCard back
+ wxPuts(_T("Entire vCard follows:\n"));
+ wxPuts(vcard.Write());
+ }
+}
+
+#endif // TEST_VCARD
+
+// ----------------------------------------------------------------------------
+// wxVolume tests
+// ----------------------------------------------------------------------------
+
+#if !defined(__WIN32__) || !wxUSE_FSVOLUME
+ #undef TEST_VOLUME
+#endif
+
+#ifdef TEST_VOLUME
+
+#include "wx/volume.h"
+
+static const wxChar *volumeKinds[] =
+{
+ _T("floppy"),
+ _T("hard disk"),
+ _T("CD-ROM"),
+ _T("DVD-ROM"),
+ _T("network volume"),
+ _T("other volume"),
+};
+
+static void TestFSVolume()
+{
+ wxPuts(_T("*** Testing wxFSVolume class ***"));
+
+ wxArrayString volumes = wxFSVolume::GetVolumes();
+ size_t count = volumes.GetCount();
+
+ if ( !count )
+ {
+ wxPuts(_T("ERROR: no mounted volumes?"));
+ return;
+ }
+
+ wxPrintf(_T("%u mounted volumes found:\n"), count);
+
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxFSVolume vol(volumes[n]);
+ if ( !vol.IsOk() )
+ {
+ wxPuts(_T("ERROR: couldn't create volume"));
+ continue;
+ }
+
+ wxPrintf(_T("%u: %s (%s), %s, %s, %s\n"),
+ n + 1,
+ vol.GetDisplayName().c_str(),
+ vol.GetName().c_str(),
+ volumeKinds[vol.GetKind()],
+ vol.IsWritable() ? _T("rw") : _T("ro"),
+ vol.GetFlags() & wxFS_VOL_REMOVABLE ? _T("removable")
+ : _T("fixed"));
+ }
+}
+
+#endif // TEST_VOLUME
+
+// ----------------------------------------------------------------------------
+// wide char and Unicode support
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_WCHAR
+
+#include "wx/strconv.h"
+#include "wx/fontenc.h"
+#include "wx/encconv.h"
+#include "wx/buffer.h"
+
+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,
+ 176, 208, 180, 208, 190, 208, 178, 208, 176, 208, 187, 32, 208, 188,
+ 208, 181, 208, 189, 209, 143, 32, 209, 129, 208, 178, 208, 190, 208,
+ 181, 208, 185, 32, 208, 186, 209, 128, 209, 131, 209, 130, 208, 181,
+ 208, 185, 209, 136, 208, 181, 208, 185, 32, 208, 189, 208, 190, 208,
+ 178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
+};
+
+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()
+{
+ wxPuts(_T("*** Testing UTF8 support ***\n"));
+
+ char buf[1024];
+ wchar_t wbuf[1024];
+
+ for ( size_t n = 0; n < WXSIZEOF(utf8data); n++ )
+ {
+ const Utf8Data& u8d = utf8data[n];
+ if ( wxConvUTF8.MB2WC(wbuf, (const char *)u8d.text,
+ WXSIZEOF(wbuf)) == (size_t)-1 )
+ {
+ wxPuts(_T("ERROR: UTF-8 decoding failed."));
+ }
+ else
+ {
+ 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);
+ }
+ }
+
+ wxString s(wxConvUTF8.cMB2WC((const char *)u8d.text));
+ if ( s.empty() )
+ s = _T("<< conversion failed >>");
+ wxPrintf(_T("String in current cset: %s\n"), s.c_str());
+
+ }
+
+ wxPuts(wxEmptyString);
+}
+
+static void TestEncodingConverter()
+{
+ wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
+
+ // using wxEncodingConverter should give the same result as above
+ char buf[1024];
+ wchar_t wbuf[1024];
+ if ( wxConvUTF8.MB2WC(wbuf, (const char *)utf8koi8r,
+ WXSIZEOF(utf8koi8r)) == (size_t)-1 )
+ {
+ wxPuts(_T("ERROR: UTF-8 decoding failed."));
+ }
+ else
+ {
+ wxEncodingConverter ec;
+ ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
+ ec.Convert(wbuf, buf);
+ wxPrintf(_T("The same KOI8-R string using wxEC: %s\n"), buf);
+ }
+
+ wxPuts(wxEmptyString);
+}
+
+#endif // TEST_WCHAR
+
+// ----------------------------------------------------------------------------
+// ZIP stream
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_ZIP
+
+#include "wx/filesys.h"
+#include "wx/fs_zip.h"
+#include "wx/zipstrm.h"
+
+static const wxChar *TESTFILE_ZIP = _T("testdata.zip");
+
+static void TestZipStreamRead()
+{
+ wxPuts(_T("*** Testing ZIP reading ***\n"));
+
+ static const wxString filename = _T("foo");
+ wxZipInputStream istr(TESTFILE_ZIP, filename);
+ wxPrintf(_T("Archive size: %u\n"), istr.GetSize());
+
+ wxPrintf(_T("Dumping the file '%s':\n"), filename.c_str());
+ while ( !istr.Eof() )
+ {
+ wxPutchar(istr.GetC());
+ fflush(stdout);
+ }
+
+ wxPuts(_T("\n----- done ------"));
+}
+
+static void DumpZipDirectory(wxFileSystem& fs,
+ const wxString& dir,
+ const wxString& indent)
+{
+ wxString prefix = wxString::Format(_T("%s#zip:%s"),
+ TESTFILE_ZIP, dir.c_str());
+ wxString wildcard = prefix + _T("/*");
+
+ wxString dirname = fs.FindFirst(wildcard, wxDIR);
+ while ( !dirname.empty() )
+ {
+ if ( !dirname.StartsWith(prefix + _T('/'), &dirname) )
+ {
+ wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
+
+ break;
+ }
+
+ wxPrintf(_T("%s%s\n"), indent.c_str(), dirname.c_str());
+
+ DumpZipDirectory(fs, dirname,
+ indent + wxString(_T(' '), 4));
+
+ dirname = fs.FindNext();
+ }
+
+ wxString filename = fs.FindFirst(wildcard, wxFILE);
+ while ( !filename.empty() )
+ {
+ if ( !filename.StartsWith(prefix, &filename) )
+ {
+ wxPrintf(_T("ERROR: unexpected wxFileSystem::FindNext result\n"));
+
+ break;
+ }
+
+ wxPrintf(_T("%s%s\n"), indent.c_str(), filename.c_str());
+
+ filename = fs.FindNext();
+ }
+}
+
+static void TestZipFileSystem()
+{
+ wxPuts(_T("*** Testing ZIP file system ***\n"));
+
+ wxFileSystem::AddHandler(new wxZipFSHandler);
+ wxFileSystem fs;
+ wxPrintf(_T("Dumping all files in the archive %s:\n"), TESTFILE_ZIP);
+
+ DumpZipDirectory(fs, _T(""), wxString(_T(' '), 4));
+}
+
+#endif // TEST_ZIP
+
+// ----------------------------------------------------------------------------
+// date time
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_DATETIME
+
+#include "wx/math.h"
+#include "wx/datetime.h"
+
+// this test miscellaneous static wxDateTime functions
+
+#if TEST_ALL
+
+static void TestTimeStatic()
+{
+ wxPuts(_T("\n*** wxDateTime static methods test ***"));
+
+ // some info about the current date
+ int year = wxDateTime::GetCurrentYear();
+ wxPrintf(_T("Current year %d is %sa leap one and has %d days.\n"),
+ year,
+ wxDateTime::IsLeapYear(year) ? "" : "not ",
+ wxDateTime::GetNumberOfDays(year));
+
+ wxDateTime::Month month = wxDateTime::GetCurrentMonth();
+ wxPrintf(_T("Current month is '%s' ('%s') and it has %d days\n"),
+ wxDateTime::GetMonthName(month, wxDateTime::Name_Abbr).c_str(),
+ wxDateTime::GetMonthName(month).c_str(),
+ wxDateTime::GetNumberOfDays(month));
+}
+
+// test time zones stuff
+static void TestTimeZones()
+{
+ wxPuts(_T("\n*** wxDateTime timezone test ***"));
+
+ wxDateTime now = wxDateTime::Now();
+
+ wxPrintf(_T("Current GMT time:\t%s\n"), now.Format(_T("%c"), wxDateTime::GMT0).c_str());
+ wxPrintf(_T("Unix epoch (GMT):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::GMT0).c_str());
+ wxPrintf(_T("Unix epoch (EST):\t%s\n"), wxDateTime((time_t)0).Format(_T("%c"), wxDateTime::EST).c_str());
+ wxPrintf(_T("Current time in Paris:\t%s\n"), now.Format(_T("%c"), wxDateTime::CET).c_str());
+ wxPrintf(_T(" Moscow:\t%s\n"), now.Format(_T("%c"), wxDateTime::MSK).c_str());
+ wxPrintf(_T(" New York:\t%s\n"), now.Format(_T("%c"), wxDateTime::EST).c_str());