+// ----------------------------------------------------------------------------
+// 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 )
+ {
+ printf("%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 )
+ printf(" = %s", value.c_str());
+ putchar('\n');
+
+ DumpVObject(level + 1, *vcObj);
+
+ delete vcObj;
+ vcObj = vcard.GetNextProp(&cookie);
+ }
+}
+
+static void DumpVCardAddresses(const wxVCard& vcard)
+{
+ puts("\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 ");
+ }
+
+ printf("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)
+{
+ puts("\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 ");
+ }
+
+ printf("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()
+{
+ puts("*** Testing wxVCard reading ***\n");
+
+ wxVCard vcard(_T("vcard.vcf"));
+ if ( !vcard.IsOk() )
+ {
+ puts("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>");
+ }
+
+ printf("Full name retrieved directly: %s\n", value.c_str());
+
+
+ if ( !vcard.GetFullName(&value) )
+ {
+ value = _T("<none>");
+ }
+
+ printf("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
+ puts("\nNow dumping the entire vCard:\n"
+ "-----------------------------\n");
+
+ DumpVObject(0, vcard);
+ }
+}
+
+static void TestVCardWrite()
+{
+ puts("*** Testing wxVCard writing ***\n");
+
+ wxVCard vcard;
+ if ( !vcard.IsOk() )
+ {
+ puts("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
+ puts("Entire vCard follows:\n");
+ puts(vcard.Write());
+ }
+}
+
+#endif // TEST_VCARD
+
+// ----------------------------------------------------------------------------
+// wide char (Unicode) support
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_WCHAR
+
+#include <wx/strconv.h>
+#include <wx/buffer.h>
+
+static void TestUtf8()
+{
+ puts("*** Testing UTF8 support ***\n");
+
+ wxString testString = "français";
+#if 0
+"************ French - Français ****************"
+"Juste un petit exemple pour dire que les français aussi"
+"ont à cœur de pouvoir utiliser tous leurs caractères ! :)";
+#endif
+
+ wxWCharBuffer wchBuf = testString.wc_str(wxConvUTF8);
+ const wchar_t *pwz = (const wchar_t *)wchBuf;
+ wxString testString2(pwz, wxConvLocal);
+
+ printf("Decoding '%s' => '%s'\n", testString.c_str(), testString2.c_str());
+
+ char *psz = "fran" "\xe7" "ais";
+ size_t len = strlen(psz);
+ wchar_t *pwz2 = new wchar_t[len + 1];
+ for ( size_t n = 0; n <= len; n++ )
+ {
+ pwz2[n] = (wchar_t)(unsigned char)psz[n];
+ }
+
+ wxString testString3(pwz2, wxConvUTF8);
+ delete [] pwz2;
+
+ printf("Encoding '%s' -> '%s'\n", psz, testString3.c_str());
+}
+
+#endif // TEST_WCHAR
+
+// ----------------------------------------------------------------------------
+// ZIP stream
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_ZIP
+
+#include "wx/zipstrm.h"
+
+static void TestZipStreamRead()
+{
+ puts("*** Testing ZIP reading ***\n");
+
+ wxZipInputStream istr(_T("idx.zip"), _T("IDX.txt"));
+ printf("Archive size: %u\n", istr.GetSize());
+
+ puts("Dumping the file:");
+ while ( !istr.Eof() )
+ {
+ putchar(istr.GetC());
+ fflush(stdout);
+ }
+
+ puts("\n----- done ------");
+}
+
+#endif // TEST_ZIP
+
+// ----------------------------------------------------------------------------
+// ZLIB stream
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_ZLIB
+
+#include <wx/zstream.h>
+#include <wx/wfstream.h>
+
+static const wxChar *FILENAME_GZ = _T("test.gz");
+static const char *TEST_DATA = "hello and hello again";
+
+static void TestZlibStreamWrite()
+{
+ puts("*** Testing Zlib stream reading ***\n");
+
+ wxFileOutputStream fileOutStream(FILENAME_GZ);
+ wxZlibOutputStream ostr(fileOutStream, 0);
+ printf("Compressing the test string... ");
+ ostr.Write(TEST_DATA, sizeof(TEST_DATA));
+ if ( !ostr )
+ {
+ puts("(ERROR: failed)");
+ }
+ else
+ {
+ puts("(ok)");
+ }
+
+ puts("\n----- done ------");
+}
+
+static void TestZlibStreamRead()
+{
+ puts("*** Testing Zlib stream reading ***\n");
+
+ wxFileInputStream fileInStream(FILENAME_GZ);
+ wxZlibInputStream istr(fileInStream);
+ printf("Archive size: %u\n", istr.GetSize());
+
+ puts("Dumping the file:");
+ while ( !istr.Eof() )
+ {
+ putchar(istr.GetC());
+ fflush(stdout);
+ }
+
+ puts("\n----- done ------");
+}
+
+#endif // TEST_ZLIB
+