]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/console/console.cpp
some little doc tweaks
[wxWidgets.git] / samples / console / console.cpp
index 2a507f9a88f2a4f9f7064f523e977904f9dc5246..f8995d43d9fa6c238cc16be144348fecd5111658 100644 (file)
 //#define TEST_HASH
 //#define TEST_INFO_FUNCTIONS
 //#define TEST_LIST
+#define TEST_LOCALE
 //#define TEST_LOG
 //#define TEST_LONGLONG
 //#define TEST_MIME
-#define TEST_PATHLIST
+//#define TEST_PATHLIST
 //#define TEST_REGISTRY
 //#define TEST_SOCKETS
 //#define TEST_STREAMS
 //#define TEST_ZIP
 //#define TEST_ZLIB
 
+
+#ifdef TEST_DATETIME
+#include <math.h>
+#endif
+
+
 // ----------------------------------------------------------------------------
 // test class for container objects
 // ----------------------------------------------------------------------------
@@ -802,6 +809,293 @@ static void TestListCtor()
 
 #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 char *GetLangName(int lang)
+{
+    static const char *languageNames[] =
+    {
+        "DEFAULT", 
+        "UNKNOWN", 
+        "ABKHAZIAN",
+        "AFAR",
+        "AFRIKAANS",
+        "ALBANIAN",
+        "AMHARIC",
+        "ARABIC",
+        "ARABIC_ALGERIA",
+        "ARABIC_BAHRAIN",
+        "ARABIC_EGYPT",
+        "ARABIC_IRAQ",
+        "ARABIC_JORDAN",
+        "ARABIC_KUWAIT",
+        "ARABIC_LEBANON",
+        "ARABIC_LIBYA",
+        "ARABIC_MOROCCO",
+        "ARABIC_OMAN",
+        "ARABIC_QATAR",
+        "ARABIC_SAUDI_ARABIA",
+        "ARABIC_SUDAN",
+        "ARABIC_SYRIA",
+        "ARABIC_TUNISIA",
+        "ARABIC_UAE",
+        "ARABIC_YEMEN",
+        "ARMENIAN",
+        "ASSAMESE",
+        "AYMARA",
+        "AZERI",
+        "AZERI_CYRILLIC",
+        "AZERI_LATIN",
+        "BASHKIR",
+        "BASQUE",
+        "BELARUSIAN",
+        "BENGALI",
+        "BHUTANI",
+        "BIHARI",
+        "BISLAMA",
+        "BRETON",
+        "BULGARIAN",
+        "BURMESE",
+        "CAMBODIAN",
+        "CATALAN",
+        "CHINESE",
+        "CHINESE_SIMPLIFIED",
+        "CHINESE_TRADITIONAL",
+        "CHINESE_HONGKONG",
+        "CHINESE_MACAU",
+        "CHINESE_SINGAPORE",
+        "CHINESE_TAIWAN",
+        "CORSICAN",
+        "CROATIAN",
+        "CZECH",
+        "DANISH",
+        "DUTCH",
+        "DUTCH_BELGIAN",
+        "ENGLISH",
+        "ENGLISH_UK",
+        "ENGLISH_US",
+        "ENGLISH_AUSTRALIA",
+        "ENGLISH_BELIZE",
+        "ENGLISH_BOTSWANA",
+        "ENGLISH_CANADA",
+        "ENGLISH_CARIBBEAN",
+        "ENGLISH_DENMARK",
+        "ENGLISH_EIRE",
+        "ENGLISH_JAMAICA",
+        "ENGLISH_NEW_ZEALAND",
+        "ENGLISH_PHILIPPINES",
+        "ENGLISH_SOUTH_AFRICA",
+        "ENGLISH_TRINIDAD",
+        "ENGLISH_ZIMBABWE",
+        "ESPERANTO",
+        "ESTONIAN",
+        "FAEROESE",
+        "FARSI",
+        "FIJI",
+        "FINNISH",
+        "FRENCH",
+        "FRENCH_BELGIAN",
+        "FRENCH_CANADIAN",
+        "FRENCH_LUXEMBOURG",
+        "FRENCH_MONACO",
+        "FRENCH_SWISS",
+        "FRISIAN",
+        "GALICIAN",
+        "GEORGIAN",
+        "GERMAN",
+        "GERMAN_AUSTRIAN",
+        "GERMAN_BELGIUM",
+        "GERMAN_LIECHTENSTEIN",
+        "GERMAN_LUXEMBOURG",
+        "GERMAN_SWISS",
+        "GREEK",
+        "GREENLANDIC",
+        "GUARANI",
+        "GUJARATI",
+        "HAUSA",
+        "HEBREW",
+        "HINDI",
+        "HUNGARIAN",
+        "ICELANDIC",
+        "INDONESIAN",
+        "INTERLINGUA",
+        "INTERLINGUE",
+        "INUKTITUT",
+        "INUPIAK",
+        "IRISH",
+        "ITALIAN",
+        "ITALIAN_SWISS",
+        "JAPANESE",
+        "JAVANESE",
+        "KANNADA",
+        "KASHMIRI",
+        "KASHMIRI_INDIA",
+        "KAZAKH",
+        "KERNEWEK",
+        "KINYARWANDA",
+        "KIRGHIZ",
+        "KIRUNDI",
+        "KONKANI",
+        "KOREAN",
+        "KURDISH",
+        "LAOTHIAN",
+        "LATIN",
+        "LATVIAN",
+        "LINGALA",
+        "LITHUANIAN",
+        "MACEDONIAN",
+        "MALAGASY",
+        "MALAY",
+        "MALAYALAM",
+        "MALAY_BRUNEI_DARUSSALAM",
+        "MALAY_MALAYSIA",
+        "MALTESE",
+        "MANIPURI",
+        "MAORI",
+        "MARATHI",
+        "MOLDAVIAN",
+        "MONGOLIAN",
+        "NAURU",
+        "NEPALI",
+        "NEPALI_INDIA",
+        "NORWEGIAN_BOKMAL",
+        "NORWEGIAN_NYNORSK",
+        "OCCITAN",
+        "ORIYA",
+        "OROMO",
+        "PASHTO",
+        "POLISH",
+        "PORTUGUESE",
+        "PORTUGUESE_BRAZILIAN",
+        "PUNJABI",
+        "QUECHUA",
+        "RHAETO_ROMANCE",
+        "ROMANIAN",
+        "RUSSIAN",
+        "RUSSIAN_UKRAINE",
+        "SAMOAN",
+        "SANGHO",
+        "SANSKRIT",
+        "SCOTS_GAELIC",
+        "SERBIAN",
+        "SERBIAN_CYRILLIC",
+        "SERBIAN_LATIN",
+        "SERBO_CROATIAN",
+        "SESOTHO",
+        "SETSWANA",
+        "SHONA",
+        "SINDHI",
+        "SINHALESE",
+        "SISWATI",
+        "SLOVAK",
+        "SLOVENIAN",
+        "SOMALI",
+        "SPANISH",
+        "SPANISH_ARGENTINA",
+        "SPANISH_BOLIVIA",
+        "SPANISH_CHILE",
+        "SPANISH_COLOMBIA",
+        "SPANISH_COSTA_RICA",
+        "SPANISH_DOMINICAN_REPUBLIC",
+        "SPANISH_ECUADOR",
+        "SPANISH_EL_SALVADOR",
+        "SPANISH_GUATEMALA",
+        "SPANISH_HONDURAS",
+        "SPANISH_MEXICAN",
+        "SPANISH_MODERN",
+        "SPANISH_NICARAGUA",
+        "SPANISH_PANAMA",
+        "SPANISH_PARAGUAY",
+        "SPANISH_PERU",
+        "SPANISH_PUERTO_RICO",
+        "SPANISH_URUGUAY",
+        "SPANISH_US",
+        "SPANISH_VENEZUELA",
+        "SUNDANESE",
+        "SWAHILI",
+        "SWEDISH",
+        "SWEDISH_FINLAND",
+        "TAGALOG",
+        "TAJIK",
+        "TAMIL",
+        "TATAR",
+        "TELUGU",
+        "THAI",
+        "TIBETAN",
+        "TIGRINYA",
+        "TONGA",
+        "TSONGA",
+        "TURKISH",
+        "TURKMEN",
+        "TWI",
+        "UIGHUR",
+        "UKRAINIAN",
+        "URDU",
+        "URDU_INDIA",
+        "URDU_PAKISTAN",
+        "UZBEK",
+        "UZBEK_CYRILLIC",
+        "UZBEK_LATIN",
+        "VIETNAMESE",
+        "VOLAPUK",
+        "WELSH",
+        "WOLOF",
+        "XHOSA",
+        "YIDDISH",
+        "YORUBA",
+        "ZHUANG",
+        "ZULU",
+    };
+
+    if ( (size_t)lang < WXSIZEOF(languageNames) )
+        return languageNames[lang];
+    else
+        return "INVALID";
+}
+
+static void TestDefaultLang()
+{
+    puts("*** 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...
+    };
+
+    for ( size_t n = 0; n < WXSIZEOF(langStrings); n++ )
+    {
+        const char *langStr = langStrings[n];
+        if ( langStr )
+            wxSetEnv(_T("LC_ALL"), langStr);
+
+        int lang = gs_localeDefault.GetSystemLanguage();
+        printf("Locale for '%s' is %s.\n",
+               langStr ? langStr : "system default", GetLangName(lang));
+    }
+}
+
+#endif // TEST_LOCALE
+
 // ----------------------------------------------------------------------------
 // MIME types
 // ----------------------------------------------------------------------------
@@ -2279,16 +2573,21 @@ static void TestUtf8()
 
 #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()
 {
     puts("*** Testing ZIP reading ***\n");
 
-    wxZipInputStream istr(_T("idx.zip"), _T("IDX.txt"));
+    static const wxChar *filename = _T("foo");
+    wxZipInputStream istr(TESTFILE_ZIP, filename);
     printf("Archive size: %u\n", istr.GetSize());
 
-    puts("Dumping the file:");
+    printf("Dumping the file '%s':\n", filename);
     while ( !istr.Eof() )
     {
         putchar(istr.GetC());
@@ -2298,6 +2597,59 @@ static void TestZipStreamRead()
     puts("\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()
+{
+    puts("*** 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
 
 // ----------------------------------------------------------------------------
@@ -3325,6 +3677,32 @@ static void TestTimeZoneBug()
     puts("");
 }
 
+static void TestTimeSpanFormat()
+{
+    puts("\n*** wxTimeSpan tests ***");
+
+    static const char *formats[] =
+    {
+        _T("(default) %H:%M:%S"),
+        _T("%E weeks and %D days"),
+        _T("%l milliseconds"),
+        _T("(with ms) %H:%M:%S:%l"),
+        _T("100%% of minutes is %M"),       // test "%%"
+        _T("%D days and %H hours"),
+    };
+
+    wxTimeSpan ts1(1, 2, 3, 4),
+                ts2(111, 222, 333);
+    for ( size_t n = 0; n < WXSIZEOF(formats); n++ )
+    {
+        printf("ts1 = %s\tts2 = %s\n",
+               ts1.Format(formats[n]).c_str(),
+               ts2.Format(formats[n]).c_str());
+    }
+
+    puts("");
+}
+
 #if 0
 
 // test compatibility with the old wxDate/wxTime classes
@@ -4195,6 +4573,10 @@ int main(int argc, char **argv)
     TestListCtor();
 #endif // TEST_LIST
 
+#ifdef TEST_LOCALE
+    TestDefaultLang();
+#endif // TEST_LOCALE
+
 #ifdef TEST_LOG
     wxString s;
     for ( size_t n = 0; n < 8000; n++ )
@@ -4344,7 +4726,7 @@ int main(int argc, char **argv)
 #endif // TEST_TIMER
 
 #ifdef TEST_DATETIME
-    if ( 1 )
+    if ( 0 )
     {
         TestTimeSet();
         TestTimeStatic();
@@ -4363,6 +4745,7 @@ int main(int argc, char **argv)
 
         TestTimeZoneBug();
     }
+    TestTimeSpanFormat();
     if ( 0 )
         TestDateTimeInteractive();
 #endif // TEST_DATETIME
@@ -4378,7 +4761,9 @@ int main(int argc, char **argv)
 #endif // TEST_WCHAR
 
 #ifdef TEST_ZIP
-    TestZipStreamRead();
+    if ( 0 )
+        TestZipStreamRead();
+    TestZipFileSystem();
 #endif // TEST_ZIP
 
 #ifdef TEST_ZLIB