X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2ca8b884d024b17d59d722e3e8eb2b7b554433a3..790ba06b28f232abc42c4ed784df4b86bfbfe5e6:/samples/console/console.cpp?ds=sidebyside diff --git a/samples/console/console.cpp b/samples/console/console.cpp index 4caca091af..12d8911e08 100644 --- a/samples/console/console.cpp +++ b/samples/console/console.cpp @@ -36,6 +36,7 @@ // what to test (in alphabetic order)? //#define TEST_ARRAYS +#define TEST_CHARSET //#define TEST_CMDLINE //#define TEST_DATETIME //#define TEST_DIR @@ -49,10 +50,12 @@ //#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_REGCONF //#define TEST_REGISTRY //#define TEST_SOCKETS //#define TEST_STREAMS @@ -61,7 +64,7 @@ //#define TEST_TIMER //#define TEST_VCARD -- don't enable this (VZ) //#define TEST_WCHAR -#define TEST_ZIP +//#define TEST_ZIP //#define TEST_ZLIB // ---------------------------------------------------------------------------- @@ -113,6 +116,46 @@ static wxString MakePrintable(const wxChar *s) #endif // MakePrintable() is used +// ---------------------------------------------------------------------------- +// wxFontMapper::CharsetToEncoding +// ---------------------------------------------------------------------------- + +#ifdef TEST_CHARSET + +#include + +static void TestCharset() +{ + static const wxChar *charsets[] = + { + // some vali charsets + _T("us-ascii "), + _T("iso8859-1 "), + _T("iso-8859-12 "), + _T("koi8-r "), + _T("utf-7 "), + _T("cp1250 "), + _T("windows-1252"), + + // and now some bogus ones + _T(" "), + _T("cp1249 "), + _T("iso--8859-1 "), + _T("iso-8859-19 "), + }; + + for ( size_t n = 0; n < WXSIZEOF(charsets); n++ ) + { + wxFontEncoding enc = wxTheFontMapper->CharsetToEncoding(charsets[n]); + wxPrintf(_T("Charset: %s\tEncoding: %s (%s)\n"), + charsets[n], + wxTheFontMapper->GetEncodingName(enc).c_str(), + wxTheFontMapper->GetEncodingDescription(enc).c_str()); + } +} + +#endif // TEST_CHARSET + // ---------------------------------------------------------------------------- // wxCmdLineParser // ---------------------------------------------------------------------------- @@ -802,6 +845,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 // ---------------------------------------------------------------------------- @@ -1305,14 +1635,28 @@ static void TestPathList() #endif // TEST_PATHLIST // ---------------------------------------------------------------------------- -// registry +// registry and related stuff // ---------------------------------------------------------------------------- // this is for MSW only #ifndef __WXMSW__ + #undef TEST_REGCONF #undef TEST_REGISTRY #endif +#ifdef TEST_REGCONF + +#include +#include + +static void TestRegConfWrite() +{ + wxRegConfig regconf(_T("console"), _T("wxwindows")); + regconf.Write(_T("Hello"), wxString(_T("world"))); +} + +#endif // TEST_REGCONF + #ifdef TEST_REGISTRY #include @@ -2416,6 +2760,8 @@ static void TestZlibStreamRead() #ifdef TEST_DATETIME +#include + #include #include @@ -3383,6 +3729,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 @@ -4118,10 +4490,9 @@ int main(int argc, char **argv) fprintf(stderr, "Failed to initialize the wxWindows library, aborting."); } -#ifdef TEST_USLEEP - puts("Sleeping for 3 seconds... z-z-z-z-z..."); - wxUsleep(3000); -#endif // TEST_USLEEP +#ifdef TEST_CHARSET + TestCharset(); +#endif // TEST_CHARSET #ifdef TEST_CMDLINE static const wxCmdLineEntryDesc cmdLineDesc[] = @@ -4253,6 +4624,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++ ) @@ -4356,6 +4731,10 @@ int main(int argc, char **argv) TestPathList(); #endif // TEST_PATHLIST +#ifdef TEST_REGCONF + TestRegConfWrite(); +#endif // TEST_REGCONF + #ifdef TEST_REGISTRY if ( 0 ) TestRegistryRead(); @@ -4402,7 +4781,7 @@ int main(int argc, char **argv) #endif // TEST_TIMER #ifdef TEST_DATETIME - if ( 1 ) + if ( 0 ) { TestTimeSet(); TestTimeStatic(); @@ -4421,10 +4800,16 @@ int main(int argc, char **argv) TestTimeZoneBug(); } + TestTimeSpanFormat(); if ( 0 ) TestDateTimeInteractive(); #endif // TEST_DATETIME +#ifdef TEST_USLEEP + puts("Sleeping for 3 seconds... z-z-z-z-z..."); + wxUsleep(3000); +#endif // TEST_USLEEP + #ifdef TEST_VCARD if ( 0 ) TestVCardRead();