- 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
-// ----------------------------------------------------------------------------
-
-// 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"
-
-static void TestRegConfWrite()
-{
- wxRegConfig regconf(_T("console"), _T("wxwindows"));
- regconf.Write(_T("Hello"), wxString(_T("world")));
-}
-
-#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());
- }
-
- putchar('\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("HKEY_CLASSES_ROOT\\.ddf" );
- key.Create();
- key = "ddxf_auto_file" ;
- key.SetName("HKEY_CLASSES_ROOT\\.flo" );
- key.Create();
- key = "ddxf_auto_file" ;
- key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
- key.Create();
- key = "program,0" ;
- key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\shell\\open\\command");
- key.Create();
- key = "program \"%1\"" ;
-
- key.SetName("HKEY_CLASSES_ROOT\\.ddf" );
- key.DeleteSelf();
- key.SetName("HKEY_CLASSES_ROOT\\.flo" );
- key.DeleteSelf();
- key.SetName("HKEY_CLASSES_ROOT\\ddxf_auto_file\\DefaultIcon");
- key.DeleteSelf();
- key.SetName("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()
-{
- ON_BLOCK_EXIT0(function0);
- ON_BLOCK_EXIT1(function1, 17);
- ON_BLOCK_EXIT2(function2, 3.14, 'p');
-
- Object obj;
- ON_BLOCK_EXIT_OBJ0(obj, &Object::method0);
- ON_BLOCK_EXIT_OBJ1(obj, &Object::method1, 7);
- ON_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.wxwindows.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.wxwindows.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());
- }
-
- 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("STAT") != '2' )
- {
- wxPuts(_T("ERROR: STAT failed"));
- }
- else
- {
- wxPrintf(_T("STAT returned:\n\n%s\n"), ftp.GetLastResult().c_str());
- }
-
- if ( ftp.SendCommand("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 == "LIST" || start == "NLST" )
- {
- wxString wildcard;
- if ( wxStrlen(buf) > 4 )
- wildcard = buf + 5;
-
- wxArrayString files;
- if ( !ftp.GetList(files, wildcard, start == "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("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
-
-// ----------------------------------------------------------------------------
-// streams
-// ----------------------------------------------------------------------------
-
-#ifdef TEST_STREAMS
-
-#include "wx/wfstream.h"
-#include "wx/mstream.h"
-
-static void TestFileStream()
-{
- wxPuts(_T("*** Testing wxFileInputStream ***"));
-
- static const wxChar *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() )
- {
- putchar(fsIn.GetC());
- }
-
- if ( !wxRemoveFile(filename) )
- {
- wxPrintf(_T("ERROR: failed to remove the file '%s'.\n"), filename);
- }
-
- 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() )
- {
- putchar(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!"));
- }
- }
-
- putchar('.');
- 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());
- putchar('\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("wxWindows", "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"));
- }