+ 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
+
+#if wxUSE_STACKWALKER
+
+#include "wx/stackwalk.h"
+
+class StackDump : public wxStackWalker
+{
+public:
+ StackDump(const char *argv0)
+ : wxStackWalker(argv0)
+ {
+ }
+
+ virtual void Walk(size_t skip = 1)
+ {
+ wxPuts(_T("Stack dump:"));
+
+ wxStackWalker::Walk(skip);
+ }
+
+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 // wxUSE_STACKWALKER
+
+#endif // TEST_STACKWALKER
+
+// ----------------------------------------------------------------------------
+// standard paths
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_STDPATHS
+
+#include "wx/stdpaths.h"
+
+static void TestStandardPaths()
+{
+ wxPuts(_T("*** Testing wxStandardPaths ***\n"));
+
+ wxTheApp->SetAppName(_T("console"));
+
+ wxStandardPathsBase& 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/stopwatch.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)