+ wxPuts(_T("ERROR: failed to copy file"));
+ }
+ else
+ {
+ wxFFile f1(filename1, _T("rb")),
+ f2(filename2, _T("rb"));
+
+ if ( !f1.IsOpened() || !f2.IsOpened() )
+ {
+ wxPuts(_T("ERROR: failed to open file(s)"));
+ }
+ else
+ {
+ wxString s1, s2;
+ if ( !f1.ReadAll(&s1) || !f2.ReadAll(&s2) )
+ {
+ wxPuts(_T("ERROR: failed to read file(s)"));
+ }
+ else
+ {
+ if ( (s1.length() != s2.length()) ||
+ (memcmp(s1.c_str(), s2.c_str(), s1.length()) != 0) )
+ {
+ wxPuts(_T("ERROR: copy error!"));
+ }
+ else
+ {
+ wxPuts(_T("File was copied ok."));
+ }
+ }
+ }
+ }
+
+ if ( !wxRemoveFile(filename2) )
+ {
+ wxPuts(_T("ERROR: failed to remove the file"));
+ }
+
+ wxPuts(wxEmptyString);
+}
+
+#endif // TEST_FILE
+
+// ----------------------------------------------------------------------------
+// wxFileConfig
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_FILECONF
+
+#include "wx/confbase.h"
+#include "wx/fileconf.h"
+
+static const struct FileConfTestData
+{
+ const wxChar *name; // value name
+ const wxChar *value; // the value from the file
+} fcTestData[] =
+{
+ { _T("value1"), _T("one") },
+ { _T("value2"), _T("two") },
+ { _T("novalue"), _T("default") },
+};
+
+static void TestFileConfRead()
+{
+ wxPuts(_T("*** testing wxFileConfig loading/reading ***"));
+
+ wxFileConfig fileconf(_T("test"), wxEmptyString,
+ _T("testdata.fc"), wxEmptyString,
+ wxCONFIG_USE_RELATIVE_PATH);
+
+ // test simple reading
+ wxPuts(_T("\nReading config file:"));
+ wxString defValue(_T("default")), value;
+ for ( size_t n = 0; n < WXSIZEOF(fcTestData); n++ )
+ {
+ const FileConfTestData& data = fcTestData[n];
+ value = fileconf.Read(data.name, defValue);
+ wxPrintf(_T("\t%s = %s "), data.name, value.c_str());
+ if ( value == data.value )
+ {
+ wxPuts(_T("(ok)"));
+ }
+ else
+ {
+ wxPrintf(_T("(ERROR: should be %s)\n"), data.value);
+ }
+ }
+
+ // test enumerating the entries
+ wxPuts(_T("\nEnumerating all root entries:"));
+ long dummy;
+ wxString name;
+ bool cont = fileconf.GetFirstEntry(name, dummy);
+ while ( cont )
+ {
+ wxPrintf(_T("\t%s = %s\n"),
+ name.c_str(),
+ fileconf.Read(name.c_str(), _T("ERROR")).c_str());
+
+ cont = fileconf.GetNextEntry(name, dummy);
+ }
+
+ static const wxChar *testEntry = _T("TestEntry");
+ wxPrintf(_T("\nTesting deletion of newly created \"Test\" entry: "));
+ fileconf.Write(testEntry, _T("A value"));
+ fileconf.DeleteEntry(testEntry);
+ wxPrintf(fileconf.HasEntry(testEntry) ? _T("ERROR\n") : _T("ok\n"));
+}
+
+#endif // TEST_FILECONF
+
+// ----------------------------------------------------------------------------
+// wxFileName
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_FILENAME
+
+#include "wx/filename.h"
+
+#if 0
+static void DumpFileName(const wxChar *desc, const wxFileName& fn)
+{
+ wxPuts(desc);
+
+ wxString full = fn.GetFullPath();
+
+ wxString vol, path, name, ext;
+ wxFileName::SplitPath(full, &vol, &path, &name, &ext);
+
+ wxPrintf(_T("'%s'-> vol '%s', path '%s', name '%s', ext '%s'\n"),
+ full.c_str(), vol.c_str(), path.c_str(), name.c_str(), ext.c_str());
+
+ wxFileName::SplitPath(full, &path, &name, &ext);
+ wxPrintf(_T("or\t\t-> path '%s', name '%s', ext '%s'\n"),
+ path.c_str(), name.c_str(), ext.c_str());
+
+ wxPrintf(_T("path is also:\t'%s'\n"), fn.GetPath().c_str());
+ wxPrintf(_T("with volume: \t'%s'\n"),
+ fn.GetPath(wxPATH_GET_VOLUME).c_str());
+ wxPrintf(_T("with separator:\t'%s'\n"),
+ fn.GetPath(wxPATH_GET_SEPARATOR).c_str());
+ wxPrintf(_T("with both: \t'%s'\n"),
+ fn.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).c_str());
+
+ wxPuts(_T("The directories in the path are:"));
+ wxArrayString dirs = fn.GetDirs();
+ size_t count = dirs.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxPrintf(_T("\t%u: %s\n"), n, dirs[n].c_str());
+ }
+}
+#endif
+
+static void TestFileNameTemp()
+{
+ wxPuts(_T("*** testing wxFileName temp file creation ***"));
+
+ static const wxChar *tmpprefixes[] =
+ {
+ _T(""),
+ _T("foo"),
+ _T(".."),
+ _T("../bar"),
+#ifdef __UNIX__
+ _T("/tmp/foo"),
+ _T("/tmp/foo/bar"), // this one must be an error
+#endif // __UNIX__
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
+ {
+ wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
+ if ( path.empty() )
+ {
+ // "error" is not in upper case because it may be ok
+ wxPrintf(_T("Prefix '%s'\t-> error\n"), tmpprefixes[n]);
+ }
+ else
+ {
+ wxPrintf(_T("Prefix '%s'\t-> temp file '%s'\n"),
+ tmpprefixes[n], path.c_str());
+
+ if ( !wxRemoveFile(path) )
+ {
+ wxLogWarning(_T("Failed to remove temp file '%s'"),
+ path.c_str());
+ }
+ }
+ }
+}
+
+static void TestFileNameMakeRelative()
+{
+ wxPuts(_T("*** testing wxFileName::MakeRelativeTo() ***"));
+
+ for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
+ {
+ const FileNameInfo& fni = filenames[n];
+
+ wxFileName fn(fni.fullname, fni.format);
+
+ // choose the base dir of the same format
+ wxString base;
+ switch ( fni.format )
+ {
+ case wxPATH_UNIX:
+ base = _T("/usr/bin/");
+ break;
+
+ case wxPATH_DOS:
+ base = _T("c:\\");
+ break;
+
+ case wxPATH_MAC:
+ case wxPATH_VMS:
+ // TODO: I don't know how this is supposed to work there
+ continue;
+
+ case wxPATH_NATIVE: // make gcc happy
+ default:
+ wxFAIL_MSG( _T("unexpected path format") );
+ }
+
+ wxPrintf(_T("'%s' relative to '%s': "),
+ fn.GetFullPath(fni.format).c_str(), base.c_str());
+
+ if ( !fn.MakeRelativeTo(base, fni.format) )
+ {
+ wxPuts(_T("unchanged"));
+ }
+ else
+ {
+ wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str());
+ }
+ }
+}
+
+static void TestFileNameMakeAbsolute()
+{
+ wxPuts(_T("*** testing wxFileName::MakeAbsolute() ***"));
+
+ for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
+ {
+ const FileNameInfo& fni = filenames[n];
+ wxFileName fn(fni.fullname, fni.format);
+
+ wxPrintf(_T("'%s' absolutized: "),
+ fn.GetFullPath(fni.format).c_str());
+ fn.MakeAbsolute();
+ wxPrintf(_T("'%s'\n"), fn.GetFullPath(fni.format).c_str());
+ }
+
+ wxPuts(wxEmptyString);
+}
+
+static void TestFileNameDirManip()
+{
+ // TODO: test AppendDir(), RemoveDir(), ...
+}
+
+static void TestFileNameComparison()
+{
+ // TODO!
+}
+
+static void TestFileNameOperations()
+{
+ // TODO!
+}
+
+static void TestFileNameCwd()
+{
+ // TODO!
+}
+
+#endif // TEST_FILENAME
+
+// ----------------------------------------------------------------------------
+// wxFileName time functions
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_FILETIME
+
+#include <wx/filename.h>
+#include <wx/datetime.h>
+
+static void TestFileGetTimes()
+{
+ wxFileName fn(_T("testdata.fc"));
+
+ wxDateTime dtAccess, dtMod, dtCreate;
+ if ( !fn.GetTimes(&dtAccess, &dtMod, &dtCreate) )
+ {
+ wxPrintf(_T("ERROR: GetTimes() failed.\n"));
+ }
+ else
+ {
+ static const wxChar *fmt = _T("%Y-%b-%d %H:%M:%S");
+
+ wxPrintf(_T("File times for '%s':\n"), fn.GetFullPath().c_str());
+ wxPrintf(_T("Creation: \t%s\n"), dtCreate.Format(fmt).c_str());
+ wxPrintf(_T("Last read: \t%s\n"), dtAccess.Format(fmt).c_str());
+ wxPrintf(_T("Last write: \t%s\n"), dtMod.Format(fmt).c_str());
+ }
+}
+
+#if 0
+static void TestFileSetTimes()
+{
+ wxFileName fn(_T("testdata.fc"));
+
+ if ( !fn.Touch() )
+ {
+ wxPrintf(_T("ERROR: Touch() failed.\n"));
+ }
+}
+#endif
+
+#endif // TEST_FILETIME
+
+// ----------------------------------------------------------------------------
+// wxHashMap
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_HASHMAP
+
+#include "wx/hashmap.h"
+
+// test compilation of basic map types
+WX_DECLARE_HASH_MAP( int*, int*, wxPointerHash, wxPointerEqual, myPtrHashMap );
+WX_DECLARE_HASH_MAP( long, long, wxIntegerHash, wxIntegerEqual, myLongHashMap );
+WX_DECLARE_HASH_MAP( unsigned long, unsigned, wxIntegerHash, wxIntegerEqual,
+ myUnsignedHashMap );
+WX_DECLARE_HASH_MAP( unsigned int, unsigned, wxIntegerHash, wxIntegerEqual,
+ myTestHashMap1 );
+WX_DECLARE_HASH_MAP( int, unsigned, wxIntegerHash, wxIntegerEqual,
+ myTestHashMap2 );
+WX_DECLARE_HASH_MAP( short, unsigned, wxIntegerHash, wxIntegerEqual,
+ myTestHashMap3 );
+WX_DECLARE_HASH_MAP( unsigned short, unsigned, wxIntegerHash, wxIntegerEqual,
+ myTestHashMap4 );
+
+// same as:
+// WX_DECLARE_HASH_MAP( wxString, wxString, wxStringHash, wxStringEqual,
+// myStringHashMap );
+WX_DECLARE_STRING_HASH_MAP(wxString, myStringHashMap);
+
+typedef myStringHashMap::iterator Itor;
+
+static void TestHashMap()
+{
+ wxPuts(_T("*** Testing wxHashMap ***\n"));
+ myStringHashMap sh(0); // as small as possible
+ wxString buf;
+ size_t i;
+ const size_t count = 10000;
+
+ // init with some data
+ for( i = 0; i < count; ++i )
+ {
+ buf.Printf(wxT("%d"), i );
+ sh[buf] = wxT("A") + buf + wxT("C");
+ }
+
+ // test that insertion worked
+ if( sh.size() != count )
+ {
+ wxPrintf(_T("*** ERROR: %u ELEMENTS, SHOULD BE %u ***\n"), sh.size(), count);
+ }
+
+ for( i = 0; i < count; ++i )
+ {
+ buf.Printf(wxT("%d"), i );
+ if( sh[buf] != wxT("A") + buf + wxT("C") )
+ {
+ wxPrintf(_T("*** ERROR INSERTION BROKEN! STOPPING NOW! ***\n"));
+ return;
+ }
+ }
+
+ // check that iterators work
+ Itor it;
+ for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
+ {
+ if( i == count )
+ {
+ wxPrintf(_T("*** ERROR ITERATORS DO NOT TERMINATE! STOPPING NOW! ***\n"));
+ return;
+ }
+
+ if( it->second != sh[it->first] )
+ {
+ wxPrintf(_T("*** ERROR ITERATORS BROKEN! STOPPING NOW! ***\n"));
+ return;
+ }
+ }
+
+ if( sh.size() != i )
+ {
+ wxPrintf(_T("*** ERROR: %u ELEMENTS ITERATED, SHOULD BE %u ***\n"), i, count);
+ }
+
+ // test copy ctor, assignment operator
+ myStringHashMap h1( sh ), h2( 0 );
+ h2 = sh;
+
+ for( i = 0, it = sh.begin(); it != sh.end(); ++it, ++i )
+ {
+ if( h1[it->first] != it->second )
+ {
+ wxPrintf(_T("*** ERROR: COPY CTOR BROKEN %s ***\n"), it->first.c_str());
+ }
+
+ if( h2[it->first] != it->second )
+ {
+ wxPrintf(_T("*** ERROR: OPERATOR= BROKEN %s ***\n"), it->first.c_str());
+ }
+ }
+
+ // other tests
+ for( i = 0; i < count; ++i )
+ {
+ buf.Printf(wxT("%d"), i );
+ size_t sz = sh.size();
+
+ // test find() and erase(it)
+ if( i < 100 )
+ {
+ it = sh.find( buf );
+ if( it != sh.end() )
+ {
+ sh.erase( it );
+
+ if( sh.find( buf ) != sh.end() )
+ {
+ wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i);
+ }
+ }
+ else
+ wxPrintf(_T("*** ERROR: CANT FIND ELEMENT %u ***\n"), i);
+ }
+ else
+ // test erase(key)
+ {
+ size_t c = sh.erase( buf );
+ if( c != 1 )
+ wxPrintf(_T("*** ERROR: SHOULD RETURN 1 ***\n"));
+
+ if( sh.find( buf ) != sh.end() )
+ {
+ wxPrintf(_T("*** ERROR: FOUND DELETED ELEMENT %u ***\n"), i);
+ }
+ }
+
+ // count should decrease
+ if( sh.size() != sz - 1 )
+ {
+ wxPrintf(_T("*** ERROR: COUNT DID NOT DECREASE ***\n"));
+ }
+ }
+
+ wxPrintf(_T("*** Finished testing wxHashMap ***\n"));
+}
+
+#endif // TEST_HASHMAP
+
+// ----------------------------------------------------------------------------
+// wxHashSet
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_HASHSET
+
+#include "wx/hashset.h"
+
+// test compilation of basic map types
+WX_DECLARE_HASH_SET( int*, wxPointerHash, wxPointerEqual, myPtrHashSet );
+WX_DECLARE_HASH_SET( long, wxIntegerHash, wxIntegerEqual, myLongHashSet );
+WX_DECLARE_HASH_SET( unsigned long, wxIntegerHash, wxIntegerEqual,
+ myUnsignedHashSet );
+WX_DECLARE_HASH_SET( unsigned int, wxIntegerHash, wxIntegerEqual,
+ myTestHashSet1 );
+WX_DECLARE_HASH_SET( int, wxIntegerHash, wxIntegerEqual,
+ myTestHashSet2 );
+WX_DECLARE_HASH_SET( short, wxIntegerHash, wxIntegerEqual,
+ myTestHashSet3 );
+WX_DECLARE_HASH_SET( unsigned short, wxIntegerHash, wxIntegerEqual,
+ myTestHashSet4 );
+WX_DECLARE_HASH_SET( wxString, wxStringHash, wxStringEqual,
+ myTestHashSet5 );
+
+struct MyStruct
+{
+ int* ptr;
+ wxString str;
+};
+
+class MyHash
+{
+public:
+ unsigned long operator()(const MyStruct& s) const
+ { return m_dummy(s.ptr); }
+ MyHash& operator=(const MyHash&) { return *this; }
+private:
+ wxPointerHash m_dummy;
+};
+
+class MyEqual
+{
+public:
+ bool operator()(const MyStruct& s1, const MyStruct& s2) const
+ { return s1.ptr == s2.ptr; }
+ MyEqual& operator=(const MyEqual&) { return *this; }
+};
+
+WX_DECLARE_HASH_SET( MyStruct, MyHash, MyEqual, mySet );
+
+typedef myTestHashSet5 wxStringHashSet;
+
+static void TestHashSet()
+{
+ wxPrintf(_T("*** Testing wxHashSet ***\n"));
+
+ wxStringHashSet set1;
+
+ set1.insert( _T("abc") );
+ set1.insert( _T("bbc") );
+ set1.insert( _T("cbc") );
+ set1.insert( _T("abc") );
+
+ if( set1.size() != 3 )
+ wxPrintf(_T("*** ERROR IN INSERT ***\n"));
+
+ mySet set2;
+ int dummy;
+ MyStruct tmp;
+
+ tmp.ptr = &dummy; tmp.str = _T("ABC");
+ set2.insert( tmp );
+ tmp.ptr = &dummy + 1;
+ set2.insert( tmp );
+ tmp.ptr = &dummy; tmp.str = _T("CDE");
+ set2.insert( tmp );
+
+ if( set2.size() != 2 )
+ wxPrintf(_T("*** ERROR IN INSERT - 2 ***\n"));
+
+ mySet::iterator it = set2.find( tmp );
+
+ if( it == set2.end() )
+ wxPrintf(_T("*** ERROR IN FIND - 1 ***\n"));
+ if( it->ptr != &dummy )
+ wxPrintf(_T("*** ERROR IN FIND - 2 ***\n"));
+ if( it->str != _T("ABC") )
+ wxPrintf(_T("*** ERROR IN INSERT - 3 ***\n"));
+
+ wxPrintf(_T("*** Finished testing wxHashSet ***\n"));
+}
+
+#endif // TEST_HASHSET
+
+// ----------------------------------------------------------------------------
+// wxList
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_LIST
+
+#include "wx/list.h"
+
+WX_DECLARE_LIST(Bar, wxListBars);
+#include "wx/listimpl.cpp"
+WX_DEFINE_LIST(wxListBars);
+
+WX_DECLARE_LIST(int, wxListInt);
+WX_DEFINE_LIST(wxListInt);
+
+static void TestList()
+{
+ wxPuts(_T("*** Testing wxList operations ***\n"));
+ {
+ wxListInt list1;
+ int dummy[5];
+ int i;
+
+ for ( i = 0; i < 5; ++i )
+ list1.Append(dummy + i);
+
+ if ( list1.GetCount() != 5 )
+ wxPuts(_T("Wrong number of items in list\n"));
+
+ if ( list1.Item(3)->GetData() != dummy + 3 )
+ wxPuts(_T("Error in Item()\n"));
+
+ if ( !list1.Find(dummy + 4) )
+ wxPuts(_T("Error in Find()\n"));
+
+ wxListInt::compatibility_iterator node = list1.GetFirst();
+ i = 0;
+
+ while (node)
+ {
+ if ( node->GetData() != dummy + i )
+ wxPuts(_T("Error in compatibility_iterator\n"));
+ node = node->GetNext();
+ ++i;
+ }
+
+ if ( size_t(i) != list1.GetCount() )
+ wxPuts(_T("Error in compatibility_iterator\n"));
+
+ list1.Insert(dummy + 0);
+ list1.Insert(1, dummy + 1);
+ list1.Insert(list1.GetFirst()->GetNext()->GetNext(), dummy + 2);
+
+ node = list1.GetFirst();
+ i = 0;
+
+ while (i < 3)
+ {
+ int* t = node->GetData();
+ if ( t != dummy + i )
+ wxPuts(_T("Error in Insert\n"));
+ node = node->GetNext();
+ ++i;
+ }
+ }
+
+ wxPuts(_T("*** Testing wxList operations finished ***\n"));
+
+ wxPuts(_T("*** Testing std::list operations ***\n"));
+
+ {
+ wxListInt list1;
+ wxListInt::iterator it, en;
+ wxListInt::reverse_iterator rit, ren;
+ int i;
+ for ( i = 0; i < 5; ++i )
+ list1.push_back(i + &i);
+
+ for ( it = list1.begin(), en = list1.end(), i = 0;
+ it != en; ++it, ++i )
+ if ( *it != i + &i )
+ wxPuts(_T("Error in iterator\n"));
+
+ for ( rit = list1.rbegin(), ren = list1.rend(), i = 4;
+ rit != ren; ++rit, --i )
+ if ( *rit != i + &i )
+ wxPuts(_T("Error in reverse_iterator\n"));
+
+ if ( *list1.rbegin() != *--list1.end() ||
+ *list1.begin() != *--list1.rend() )
+ wxPuts(_T("Error in iterator/reverse_iterator\n"));
+ if ( *list1.begin() != *--++list1.begin() ||
+ *list1.rbegin() != *--++list1.rbegin() )
+ wxPuts(_T("Error in iterator/reverse_iterator\n"));
+
+ if ( list1.front() != &i || list1.back() != &i + 4 )
+ wxPuts(_T("Error in front()/back()\n"));
+
+ list1.erase(list1.begin());
+ list1.erase(--list1.end());
+
+ for ( it = list1.begin(), en = list1.end(), i = 1;
+ it != en; ++it, ++i )
+ if ( *it != i + &i )
+ wxPuts(_T("Error in erase()\n"));
+ }
+
+ wxPuts(_T("*** Testing std::list operations finished ***\n"));
+}
+
+static void TestListCtor()
+{
+ wxPuts(_T("*** Testing wxList construction ***\n"));
+
+ {
+ wxListBars list1;
+ list1.Append(new Bar(_T("first")));
+ list1.Append(new Bar(_T("second")));
+
+ wxPrintf(_T("After 1st list creation: %u objects in the list, %u objects total.\n"),
+ list1.GetCount(), Bar::GetNumber());
+
+ wxListBars list2;
+ list2 = list1;
+
+ wxPrintf(_T("After 2nd list creation: %u and %u objects in the lists, %u objects total.\n"),
+ list1.GetCount(), list2.GetCount(), Bar::GetNumber());
+
+#if !wxUSE_STL
+ list1.DeleteContents(true);
+#else
+ WX_CLEAR_LIST(wxListBars, list1);
+#endif
+ }
+
+ wxPrintf(_T("After list destruction: %u objects left.\n"), Bar::GetNumber());
+}
+
+#endif // TEST_LIST
+
+// ----------------------------------------------------------------------------
+// wxLocale
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_LOCALE
+
+#include "wx/intl.h"
+#include "wx/utils.h" // for wxSetEnv
+
+static wxLocale gs_localeDefault(wxLANGUAGE_ENGLISH);
+
+// find the name of the language from its value
+static const wxChar *GetLangName(int lang)
+{
+ static const wxChar *languageNames[] =
+ {
+ _T("DEFAULT"),
+ _T("UNKNOWN"),
+ _T("ABKHAZIAN"),
+ _T("AFAR"),
+ _T("AFRIKAANS"),
+ _T("ALBANIAN"),
+ _T("AMHARIC"),
+ _T("ARABIC"),
+ _T("ARABIC_ALGERIA"),
+ _T("ARABIC_BAHRAIN"),
+ _T("ARABIC_EGYPT"),
+ _T("ARABIC_IRAQ"),
+ _T("ARABIC_JORDAN"),
+ _T("ARABIC_KUWAIT"),
+ _T("ARABIC_LEBANON"),
+ _T("ARABIC_LIBYA"),
+ _T("ARABIC_MOROCCO"),
+ _T("ARABIC_OMAN"),
+ _T("ARABIC_QATAR"),
+ _T("ARABIC_SAUDI_ARABIA"),
+ _T("ARABIC_SUDAN"),
+ _T("ARABIC_SYRIA"),
+ _T("ARABIC_TUNISIA"),
+ _T("ARABIC_UAE"),
+ _T("ARABIC_YEMEN"),
+ _T("ARMENIAN"),
+ _T("ASSAMESE"),
+ _T("AYMARA"),
+ _T("AZERI"),
+ _T("AZERI_CYRILLIC"),
+ _T("AZERI_LATIN"),
+ _T("BASHKIR"),
+ _T("BASQUE"),
+ _T("BELARUSIAN"),
+ _T("BENGALI"),
+ _T("BHUTANI"),
+ _T("BIHARI"),
+ _T("BISLAMA"),
+ _T("BRETON"),
+ _T("BULGARIAN"),
+ _T("BURMESE"),
+ _T("CAMBODIAN"),
+ _T("CATALAN"),
+ _T("CHINESE"),
+ _T("CHINESE_SIMPLIFIED"),
+ _T("CHINESE_TRADITIONAL"),
+ _T("CHINESE_HONGKONG"),
+ _T("CHINESE_MACAU"),
+ _T("CHINESE_SINGAPORE"),
+ _T("CHINESE_TAIWAN"),
+ _T("CORSICAN"),
+ _T("CROATIAN"),
+ _T("CZECH"),
+ _T("DANISH"),
+ _T("DUTCH"),
+ _T("DUTCH_BELGIAN"),
+ _T("ENGLISH"),
+ _T("ENGLISH_UK"),
+ _T("ENGLISH_US"),
+ _T("ENGLISH_AUSTRALIA"),
+ _T("ENGLISH_BELIZE"),
+ _T("ENGLISH_BOTSWANA"),
+ _T("ENGLISH_CANADA"),
+ _T("ENGLISH_CARIBBEAN"),
+ _T("ENGLISH_DENMARK"),
+ _T("ENGLISH_EIRE"),
+ _T("ENGLISH_JAMAICA"),
+ _T("ENGLISH_NEW_ZEALAND"),
+ _T("ENGLISH_PHILIPPINES"),
+ _T("ENGLISH_SOUTH_AFRICA"),
+ _T("ENGLISH_TRINIDAD"),
+ _T("ENGLISH_ZIMBABWE"),
+ _T("ESPERANTO"),
+ _T("ESTONIAN"),
+ _T("FAEROESE"),
+ _T("FARSI"),
+ _T("FIJI"),
+ _T("FINNISH"),
+ _T("FRENCH"),
+ _T("FRENCH_BELGIAN"),
+ _T("FRENCH_CANADIAN"),
+ _T("FRENCH_LUXEMBOURG"),
+ _T("FRENCH_MONACO"),
+ _T("FRENCH_SWISS"),
+ _T("FRISIAN"),
+ _T("GALICIAN"),
+ _T("GEORGIAN"),
+ _T("GERMAN"),
+ _T("GERMAN_AUSTRIAN"),
+ _T("GERMAN_BELGIUM"),
+ _T("GERMAN_LIECHTENSTEIN"),
+ _T("GERMAN_LUXEMBOURG"),
+ _T("GERMAN_SWISS"),
+ _T("GREEK"),
+ _T("GREENLANDIC"),
+ _T("GUARANI"),
+ _T("GUJARATI"),
+ _T("HAUSA"),
+ _T("HEBREW"),
+ _T("HINDI"),
+ _T("HUNGARIAN"),
+ _T("ICELANDIC"),
+ _T("INDONESIAN"),
+ _T("INTERLINGUA"),
+ _T("INTERLINGUE"),
+ _T("INUKTITUT"),
+ _T("INUPIAK"),
+ _T("IRISH"),
+ _T("ITALIAN"),
+ _T("ITALIAN_SWISS"),
+ _T("JAPANESE"),
+ _T("JAVANESE"),
+ _T("KANNADA"),
+ _T("KASHMIRI"),
+ _T("KASHMIRI_INDIA"),
+ _T("KAZAKH"),
+ _T("KERNEWEK"),
+ _T("KINYARWANDA"),
+ _T("KIRGHIZ"),
+ _T("KIRUNDI"),
+ _T("KONKANI"),
+ _T("KOREAN"),
+ _T("KURDISH"),
+ _T("LAOTHIAN"),
+ _T("LATIN"),
+ _T("LATVIAN"),
+ _T("LINGALA"),
+ _T("LITHUANIAN"),
+ _T("MACEDONIAN"),
+ _T("MALAGASY"),
+ _T("MALAY"),
+ _T("MALAYALAM"),
+ _T("MALAY_BRUNEI_DARUSSALAM"),
+ _T("MALAY_MALAYSIA"),
+ _T("MALTESE"),
+ _T("MANIPURI"),
+ _T("MAORI"),
+ _T("MARATHI"),
+ _T("MOLDAVIAN"),
+ _T("MONGOLIAN"),
+ _T("NAURU"),
+ _T("NEPALI"),
+ _T("NEPALI_INDIA"),
+ _T("NORWEGIAN_BOKMAL"),
+ _T("NORWEGIAN_NYNORSK"),
+ _T("OCCITAN"),
+ _T("ORIYA"),
+ _T("OROMO"),
+ _T("PASHTO"),
+ _T("POLISH"),
+ _T("PORTUGUESE"),
+ _T("PORTUGUESE_BRAZILIAN"),
+ _T("PUNJABI"),
+ _T("QUECHUA"),
+ _T("RHAETO_ROMANCE"),
+ _T("ROMANIAN"),
+ _T("RUSSIAN"),
+ _T("RUSSIAN_UKRAINE"),
+ _T("SAMOAN"),
+ _T("SANGHO"),
+ _T("SANSKRIT"),
+ _T("SCOTS_GAELIC"),
+ _T("SERBIAN"),
+ _T("SERBIAN_CYRILLIC"),
+ _T("SERBIAN_LATIN"),
+ _T("SERBO_CROATIAN"),
+ _T("SESOTHO"),
+ _T("SETSWANA"),
+ _T("SHONA"),
+ _T("SINDHI"),
+ _T("SINHALESE"),
+ _T("SISWATI"),
+ _T("SLOVAK"),
+ _T("SLOVENIAN"),
+ _T("SOMALI"),
+ _T("SPANISH"),
+ _T("SPANISH_ARGENTINA"),
+ _T("SPANISH_BOLIVIA"),
+ _T("SPANISH_CHILE"),
+ _T("SPANISH_COLOMBIA"),
+ _T("SPANISH_COSTA_RICA"),
+ _T("SPANISH_DOMINICAN_REPUBLIC"),
+ _T("SPANISH_ECUADOR"),
+ _T("SPANISH_EL_SALVADOR"),
+ _T("SPANISH_GUATEMALA"),
+ _T("SPANISH_HONDURAS"),
+ _T("SPANISH_MEXICAN"),
+ _T("SPANISH_MODERN"),
+ _T("SPANISH_NICARAGUA"),
+ _T("SPANISH_PANAMA"),
+ _T("SPANISH_PARAGUAY"),
+ _T("SPANISH_PERU"),
+ _T("SPANISH_PUERTO_RICO"),
+ _T("SPANISH_URUGUAY"),
+ _T("SPANISH_US"),
+ _T("SPANISH_VENEZUELA"),
+ _T("SUNDANESE"),
+ _T("SWAHILI"),
+ _T("SWEDISH"),
+ _T("SWEDISH_FINLAND"),
+ _T("TAGALOG"),
+ _T("TAJIK"),
+ _T("TAMIL"),
+ _T("TATAR"),
+ _T("TELUGU"),
+ _T("THAI"),
+ _T("TIBETAN"),
+ _T("TIGRINYA"),
+ _T("TONGA"),
+ _T("TSONGA"),
+ _T("TURKISH"),
+ _T("TURKMEN"),
+ _T("TWI"),
+ _T("UIGHUR"),
+ _T("UKRAINIAN"),
+ _T("URDU"),
+ _T("URDU_INDIA"),
+ _T("URDU_PAKISTAN"),
+ _T("UZBEK"),
+ _T("UZBEK_CYRILLIC"),
+ _T("UZBEK_LATIN"),
+ _T("VIETNAMESE"),
+ _T("VOLAPUK"),
+ _T("WELSH"),
+ _T("WOLOF"),
+ _T("XHOSA"),
+ _T("YIDDISH"),
+ _T("YORUBA"),
+ _T("ZHUANG"),
+ _T("ZULU"),
+ };
+
+ if ( (size_t)lang < WXSIZEOF(languageNames) )
+ return languageNames[lang];
+ else
+ return _T("INVALID");
+}
+
+static void TestDefaultLang()
+{
+ wxPuts(_T("*** Testing wxLocale::GetSystemLanguage ***"));
+
+ static const wxChar *langStrings[] =
+ {
+ NULL, // system default
+ _T("C"),
+ _T("fr"),
+ _T("fr_FR"),
+ _T("en"),
+ _T("en_GB"),
+ _T("en_US"),
+ _T("de_DE.iso88591"),
+ _T("german"),
+ _T("?"), // invalid lang spec
+ _T("klingonese"), // I bet on some systems it does exist...
+ };
+
+ wxPrintf(_T("The default system encoding is %s (%d)\n"),
+ wxLocale::GetSystemEncodingName().c_str(),
+ wxLocale::GetSystemEncoding());
+
+ for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
+ {
+ const wxChar *langStr = langStrings[n];
+ if ( langStr )
+ {
+ // FIXME: this doesn't do anything at all under Windows, we need
+ // to create a new wxLocale!
+ wxSetEnv(_T("LC_ALL"), langStr);
+ }
+
+ int lang = gs_localeDefault.GetSystemLanguage();
+ wxPrintf(_T("Locale for '%s' is %s.\n"),
+ langStr ? langStr : _T("system default"), GetLangName(lang));
+ }
+}
+
+#endif // TEST_LOCALE
+
+// ----------------------------------------------------------------------------
+// MIME types
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_MIME
+
+#include "wx/mimetype.h"
+
+static void TestMimeEnum()
+{
+ wxPuts(_T("*** Testing wxMimeTypesManager::EnumAllFileTypes() ***\n"));
+
+ wxArrayString mimetypes;
+
+ size_t count = wxTheMimeTypesManager->EnumAllFileTypes(mimetypes);
+
+ wxPrintf(_T("*** All %u known filetypes: ***\n"), count);
+
+ wxArrayString exts;
+ wxString desc;
+
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxFileType *filetype =
+ wxTheMimeTypesManager->GetFileTypeFromMimeType(mimetypes[n]);
+ if ( !filetype )
+ {
+ wxPrintf(_T("nothing known about the filetype '%s'!\n"),
+ mimetypes[n].c_str());
+ continue;
+ }
+
+ filetype->GetDescription(&desc);
+ filetype->GetExtensions(exts);
+
+ filetype->GetIcon(NULL);
+
+ wxString extsAll;
+ for ( size_t e = 0; e < exts.GetCount(); e++ )
+ {
+ if ( e > 0 )
+ extsAll << _T(", ");
+ extsAll += exts[e];
+ }
+
+ wxPrintf(_T("\t%s: %s (%s)\n"),
+ mimetypes[n].c_str(), desc.c_str(), extsAll.c_str());
+ }
+
+ wxPuts(wxEmptyString);
+}
+
+static void TestMimeOverride()
+{
+ wxPuts(_T("*** Testing wxMimeTypesManager additional files loading ***\n"));
+
+ static const wxChar *mailcap = _T("/tmp/mailcap");
+ static const wxChar *mimetypes = _T("/tmp/mime.types");
+
+ if ( wxFile::Exists(mailcap) )
+ wxPrintf(_T("Loading mailcap from '%s': %s\n"),
+ mailcap,
+ wxTheMimeTypesManager->ReadMailcap(mailcap) ? _T("ok") : _T("ERROR"));
+ else
+ wxPrintf(_T("WARN: mailcap file '%s' doesn't exist, not loaded.\n"),
+ mailcap);
+
+ if ( wxFile::Exists(mimetypes) )
+ wxPrintf(_T("Loading mime.types from '%s': %s\n"),
+ mimetypes,
+ wxTheMimeTypesManager->ReadMimeTypes(mimetypes) ? _T("ok") : _T("ERROR"));
+ else
+ wxPrintf(_T("WARN: mime.types file '%s' doesn't exist, not loaded.\n"),
+ mimetypes);
+
+ wxPuts(wxEmptyString);
+}
+
+static void TestMimeFilename()
+{
+ wxPuts(_T("*** Testing MIME type from filename query ***\n"));
+
+ static const wxChar *filenames[] =
+ {
+ _T("readme.txt"),
+ _T("document.pdf"),
+ _T("image.gif"),
+ _T("picture.jpeg"),
+ };
+
+ for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
+ {
+ const wxString fname = filenames[n];
+ wxString ext = fname.AfterLast(_T('.'));
+ wxFileType *ft = wxTheMimeTypesManager->GetFileTypeFromExtension(ext);
+ if ( !ft )
+ {
+ wxPrintf(_T("WARNING: extension '%s' is unknown.\n"), ext.c_str());
+ }
+ else
+ {
+ wxString desc;
+ if ( !ft->GetDescription(&desc) )
+ desc = _T("<no description>");
+
+ wxString cmd;
+ if ( !ft->GetOpenCommand(&cmd,
+ wxFileType::MessageParameters(fname, wxEmptyString)) )
+ cmd = _T("<no command available>");
+ else
+ cmd = wxString(_T('"')) + cmd + _T('"');
+
+ wxPrintf(_T("To open %s (%s) do %s.\n"),
+ fname.c_str(), desc.c_str(), cmd.c_str());
+
+ delete ft;
+ }
+ }
+
+ wxPuts(wxEmptyString);
+}
+
+static void TestMimeAssociate()
+{
+ wxPuts(_T("*** Testing creation of filetype association ***\n"));
+
+ wxFileTypeInfo ftInfo(
+ _T("application/x-xyz"),
+ _T("xyzview '%s'"), // open cmd
+ _T(""), // print cmd
+ _T("XYZ File"), // description
+ _T(".xyz"), // extensions
+ NULL // end of extensions
+ );
+ ftInfo.SetShortDesc(_T("XYZFile")); // used under Win32 only
+
+ wxFileType *ft = wxTheMimeTypesManager->Associate(ftInfo);
+ if ( !ft )
+ {
+ wxPuts(_T("ERROR: failed to create association!"));
+ }
+ else
+ {
+ // TODO: read it back
+ delete ft;
+ }
+
+ wxPuts(wxEmptyString);
+}
+
+#endif // TEST_MIME
+
+// ----------------------------------------------------------------------------
+// misc information functions
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_INFO_FUNCTIONS
+
+#include "wx/utils.h"
+
+static void TestDiskInfo()
+{
+ wxPuts(_T("*** Testing wxGetDiskSpace() ***"));
+
+ for ( ;; )
+ {
+ wxChar pathname[128];
+ wxPrintf(_T("\nEnter a directory name: "));
+ if ( !wxFgets(pathname, WXSIZEOF(pathname), stdin) )
+ break;
+
+ // kill the last '\n'
+ pathname[wxStrlen(pathname) - 1] = 0;
+
+ wxLongLong total, free;
+ if ( !wxGetDiskSpace(pathname, &total, &free) )
+ {
+ wxPuts(_T("ERROR: wxGetDiskSpace failed."));
+ }
+ else
+ {
+ wxPrintf(_T("%sKb total, %sKb free on '%s'.\n"),
+ (total / 1024).ToString().c_str(),
+ (free / 1024).ToString().c_str(),
+ pathname);
+ }
+ }
+}
+
+static void TestOsInfo()
+{
+ wxPuts(_T("*** Testing OS info functions ***\n"));
+
+ int major, minor;
+ wxGetOsVersion(&major, &minor);
+ wxPrintf(_T("Running under: %s, version %d.%d\n"),
+ wxGetOsDescription().c_str(), major, minor);
+
+ wxPrintf(_T("%ld free bytes of memory left.\n"), wxGetFreeMemory());
+
+ wxPrintf(_T("Host name is %s (%s).\n"),
+ wxGetHostName().c_str(), wxGetFullHostName().c_str());
+
+ wxPuts(wxEmptyString);
+}
+
+static void TestUserInfo()
+{
+ wxPuts(_T("*** Testing user info functions ***\n"));
+
+ wxPrintf(_T("User id is:\t%s\n"), wxGetUserId().c_str());
+ wxPrintf(_T("User name is:\t%s\n"), wxGetUserName().c_str());
+ wxPrintf(_T("Home dir is:\t%s\n"), wxGetHomeDir().c_str());
+ wxPrintf(_T("Email address:\t%s\n"), wxGetEmailAddress().c_str());
+
+ wxPuts(wxEmptyString);
+}
+
+#endif // TEST_INFO_FUNCTIONS
+
+// ----------------------------------------------------------------------------
+// path list
+// ----------------------------------------------------------------------------
+
+#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(_T("PATH"));
+ wxString path = pathlist.FindValidPath(CMD_IN_PATH);
+ if ( path.empty() )
+ {
+ wxPrintf(_T("ERROR: command not found in the path.\n"));
+ }
+ else
+ {
+ wxPrintf(_T("Command found in the path as '%s'.\n"), path.c_str());
+ }
+}
+
+#endif // TEST_PATHLIST
+
+// ----------------------------------------------------------------------------
+// regular expressions
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_REGEX
+
+#include "wx/regex.h"
+
+static void TestRegExInteractive()
+{
+ wxPuts(_T("*** Testing RE interactively ***"));
+
+ for ( ;; )
+ {
+ wxChar pattern[128];
+ wxPrintf(_T("\nEnter a pattern: "));
+ if ( !wxFgets(pattern, WXSIZEOF(pattern), stdin) )
+ break;
+
+ // kill the last '\n'
+ pattern[wxStrlen(pattern) - 1] = 0;
+
+ wxRegEx re;
+ if ( !re.Compile(pattern) )
+ {
+ continue;
+ }
+
+ wxChar text[128];
+ for ( ;; )
+ {
+ wxPrintf(_T("Enter text to match: "));
+ if ( !wxFgets(text, WXSIZEOF(text), stdin) )
+ break;
+
+ // kill the last '\n'
+ text[wxStrlen(text) - 1] = 0;
+
+ if ( !re.Matches(text) )
+ {
+ wxPrintf(_T("No match.\n"));
+ }
+ else
+ {
+ wxPrintf(_T("Pattern matches at '%s'\n"), re.GetMatch(text).c_str());
+
+ size_t start, len;
+ for ( size_t n = 1; ; n++ )
+ {
+ if ( !re.GetMatch(&start, &len, n) )
+ {
+ break;
+ }
+
+ wxPrintf(_T("Subexpr %u matched '%s'\n"),
+ n, wxString(text + start, len).c_str());
+ }
+ }
+ }
+ }
+}
+
+#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"));