]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/console/console.cpp
applied patch 430452 (mingw32 compilation fixes)
[wxWidgets.git] / samples / console / console.cpp
index f8995d43d9fa6c238cc16be144348fecd5111658..6af976b9fe26e537371642b77e3fb40bb71d33e9 100644 (file)
@@ -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
@@ -54,6 +55,7 @@
 //#define TEST_LONGLONG
 //#define TEST_MIME
 //#define TEST_PATHLIST
+//#define TEST_REGCONF
 //#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
 // ----------------------------------------------------------------------------
@@ -120,6 +116,46 @@ static wxString MakePrintable(const wxChar *s)
 
 #endif // MakePrintable() is used
 
+// ----------------------------------------------------------------------------
+// wxFontMapper::CharsetToEncoding
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_CHARSET
+
+#include <wx/fontmap.h>
+
+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
 // ----------------------------------------------------------------------------
@@ -170,6 +206,16 @@ static void ShowCmdLine(const wxCmdLineParser& parser)
 
 #include <wx/dir.h>
 
+#ifdef __UNIX__
+    static const wxChar *ROOTDIR = _T("/");
+    static const wxChar *TESTDIR = _T("/usr");
+#elif defined(__WXMSW__)
+    static const wxChar *ROOTDIR = _T("c:\\");
+    static const wxChar *TESTDIR = _T("d:\\");
+#else
+    #error "don't know where the root directory is"
+#endif
+
 static void TestDirEnumHelper(wxDir& dir,
                               int flags = wxDIR_DEFAULT,
                               const wxString& filespec = wxEmptyString)
@@ -192,6 +238,8 @@ static void TestDirEnumHelper(wxDir& dir,
 
 static void TestDirEnum()
 {
+    puts("*** Testing wxDir::GetFirst/GetNext ***");
+
     wxDir dir(wxGetCwd());
 
     puts("Enumerating everything in current directory:");
@@ -212,13 +260,7 @@ static void TestDirEnum()
     puts("Enumerating files including hidden in current directory:");
     TestDirEnumHelper(dir, wxDIR_FILES | wxDIR_HIDDEN);
 
-#ifdef __UNIX__
-    dir.Open("/");
-#elif defined(__WXMSW__)
-    dir.Open("c:\\");
-#else
-    #error "don't know where the root directory is"
-#endif
+    dir.Open(ROOTDIR);
 
     puts("Enumerating everything in root directory:");
     TestDirEnumHelper(dir, wxDIR_DEFAULT);
@@ -237,6 +279,55 @@ static void TestDirEnum()
     TestDirEnumHelper(dirNo);
 }
 
+class DirPrintTraverser : public wxDirTraverser
+{
+public:
+    virtual wxDirTraverseResult OnFile(const wxString& filename)
+    {
+        return wxDIR_CONTINUE;
+    }
+
+    virtual wxDirTraverseResult OnDir(const wxString& dirname)
+    {
+        wxString path, name, ext;
+        wxSplitPath(dirname, &path, &name, &ext);
+
+        if ( !ext.empty() )
+            name << _T('.') << ext;
+
+        wxString indent;
+        for ( const wxChar *p = path.c_str(); *p; p++ )
+        {
+            if ( wxIsPathSeparator(*p) )
+                indent += _T("    ");
+        }
+
+        printf("%s%s\n", indent.c_str(), name.c_str());
+
+        return wxDIR_CONTINUE;
+    }
+};
+
+static void TestDirTraverse()
+{
+    puts("*** Testing wxDir::Traverse() ***");
+
+    // enum all files
+    wxArrayString files;
+    size_t n = wxDir::GetAllFiles(TESTDIR, &files);
+    printf("There are %u files under '%s'\n", n, TESTDIR);
+    if ( n > 1 )
+    {
+        printf("First one is '%s'\n", files[0u]);
+        printf(" last one is '%s'\n", files[n - 1]);
+    }
+
+    // enum again with custom traverser
+    wxDir dir(TESTDIR);
+    DirPrintTraverser traverser;
+    dir.Traverse(traverser, _T(""), wxDIR_DIRS | wxDIR_HIDDEN);
+}
+
 #endif // TEST_DIR
 
 // ----------------------------------------------------------------------------
@@ -1082,11 +1173,19 @@ static void TestDefaultLang()
         _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 char *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();
         printf("Locale for '%s' is %s.\n",
@@ -1599,14 +1698,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 <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>
@@ -2710,6 +2823,8 @@ static void TestZlibStreamRead()
 
 #ifdef TEST_DATETIME
 
+#include <math.h>
+
 #include <wx/date.h>
 
 #include <wx/datetime.h>
@@ -4438,10 +4553,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[] =
@@ -4550,7 +4664,9 @@ int main(int argc, char **argv)
 #endif // TEST_ARRAYS
 
 #ifdef TEST_DIR
-    TestDirEnum();
+    if ( 0 )
+        TestDirEnum();
+    TestDirTraverse();
 #endif // TEST_DIR
 
 #ifdef TEST_DLLLOADER
@@ -4680,6 +4796,10 @@ int main(int argc, char **argv)
     TestPathList();
 #endif // TEST_PATHLIST
 
+#ifdef TEST_REGCONF
+    TestRegConfWrite();
+#endif // TEST_REGCONF
+
 #ifdef TEST_REGISTRY
     if ( 0 )
         TestRegistryRead();
@@ -4750,6 +4870,11 @@ int main(int argc, char **argv)
         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();