]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/console/console.cpp
Unicode compilation fix
[wxWidgets.git] / samples / console / console.cpp
index 8c748f841cc356b869c04adbb38e405fa42ed290..51338a569063143b4e5ae92b8667c46fab024a90 100644 (file)
@@ -1,6 +1,6 @@
 /////////////////////////////////////////////////////////////////////////////
 // Name:        samples/console/console.cpp
 /////////////////////////////////////////////////////////////////////////////
 // Name:        samples/console/console.cpp
-// Purpose:     a sample console (as opposed to GUI) progam using wxWidgets
+// Purpose:     A sample console (as opposed to GUI) program using wxWidgets
 // Author:      Vadim Zeitlin
 // Modified by:
 // Created:     04.10.99
 // Author:      Vadim Zeitlin
 // Modified by:
 // Created:     04.10.99
@@ -53,7 +53,7 @@
     #define TEST_CMDLINE
     #define TEST_DATETIME
     #define TEST_DIR
     #define TEST_CMDLINE
     #define TEST_DATETIME
     #define TEST_DIR
-    #define TEST_DLLLOADER
+    #define TEST_DYNLIB
     #define TEST_ENVIRON
     #define TEST_EXECUTE
     #define TEST_FILE
     #define TEST_ENVIRON
     #define TEST_EXECUTE
     #define TEST_FILE
@@ -74,6 +74,7 @@
     #define TEST_SCOPEGUARD
     #define TEST_SNGLINST
 //    #define TEST_SOCKETS  --FIXME! (RN)
     #define TEST_SCOPEGUARD
     #define TEST_SNGLINST
 //    #define TEST_SOCKETS  --FIXME! (RN)
+    #define TEST_STACKWALKER
     #define TEST_STDPATHS
     #define TEST_STREAMS
     #define TEST_TEXTSTREAM
     #define TEST_STDPATHS
     #define TEST_STREAMS
     #define TEST_TEXTSTREAM
@@ -84,7 +85,7 @@
     #define TEST_WCHAR
     #define TEST_ZIP
 #else // #if TEST_ALL
     #define TEST_WCHAR
     #define TEST_ZIP
 #else // #if TEST_ALL
-    #define TEST_STDPATHS
+    #define TEST_DIR
 #endif
 
 // some tests are interactive, define this to run them
 #endif
 
 // some tests are interactive, define this to run them
@@ -200,7 +201,7 @@ static void TestCmdLineConvert()
 #ifdef __UNIX__
     static const wxChar *ROOTDIR = _T("/");
     static const wxChar *TESTDIR = _T("/usr/local/share");
 #ifdef __UNIX__
     static const wxChar *ROOTDIR = _T("/");
     static const wxChar *TESTDIR = _T("/usr/local/share");
-#elif defined(__WXMSW__)
+#elif defined(__WXMSW__) || defined(__DOS__)
     static const wxChar *ROOTDIR = _T("c:\\");
     static const wxChar *TESTDIR = _T("d:\\");
 #else
     static const wxChar *ROOTDIR = _T("c:\\");
     static const wxChar *TESTDIR = _T("d:\\");
 #else
@@ -371,7 +372,7 @@ static void TestDirExists()
 // wxDllLoader
 // ----------------------------------------------------------------------------
 
 // wxDllLoader
 // ----------------------------------------------------------------------------
 
-#ifdef TEST_DLLLOADER
+#ifdef TEST_DYNLIB
 
 #include "wx/dynlib.h"
 
 
 #include "wx/dynlib.h"
 
@@ -382,13 +383,13 @@ static void TestDllLoad()
     static const wxChar *FUNC_NAME = _T("lstrlenA");
 #elif defined(__UNIX__)
     // weird: using just libc.so does *not* work!
     static const wxChar *FUNC_NAME = _T("lstrlenA");
 #elif defined(__UNIX__)
     // weird: using just libc.so does *not* work!
-    static const wxChar *LIB_NAME = _T("/lib/libc-2.0.7.so");
+    static const wxChar *LIB_NAME = _T("/lib/libc.so.6");
     static const wxChar *FUNC_NAME = _T("strlen");
 #else
     #error "don't know how to test wxDllLoader on this platform"
 #endif
 
     static const wxChar *FUNC_NAME = _T("strlen");
 #else
     #error "don't know how to test wxDllLoader on this platform"
 #endif
 
-    wxPuts(_T("*** testing wxDllLoader ***\n"));
+    wxPuts(_T("*** testing basic wxDynamicLibrary functions ***\n"));
 
     wxDynamicLibrary lib(LIB_NAME);
     if ( !lib.IsLoaded() )
 
     wxDynamicLibrary lib(LIB_NAME);
     if ( !lib.IsLoaded() )
@@ -397,7 +398,7 @@ static void TestDllLoad()
     }
     else
     {
     }
     else
     {
-        typedef int (*wxStrlenType)(const char *);
+        typedef int (wxSTDCALL *wxStrlenType)(const char *);
         wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
         if ( !pfnStrlen )
         {
         wxStrlenType pfnStrlen = (wxStrlenType)lib.GetSymbol(FUNC_NAME);
         if ( !pfnStrlen )
         {
@@ -406,6 +407,9 @@ static void TestDllLoad()
         }
         else
         {
         }
         else
         {
+            wxPrintf(_T("Calling %s dynamically loaded from %s "),
+                     FUNC_NAME, LIB_NAME);
+
             if ( pfnStrlen("foo") != 3 )
             {
                 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
             if ( pfnStrlen("foo") != 3 )
             {
                 wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
@@ -415,10 +419,58 @@ static void TestDllLoad()
                 wxPuts(_T("... ok"));
             }
         }
                 wxPuts(_T("... ok"));
             }
         }
+
+#ifdef __WXMSW__
+        static const wxChar *FUNC_NAME_AW = _T("lstrlen");
+
+        typedef int (wxSTDCALL *wxStrlenTypeAorW)(const wxChar *);
+        wxStrlenTypeAorW
+            pfnStrlenAorW = (wxStrlenTypeAorW)lib.GetSymbolAorW(FUNC_NAME_AW);
+        if ( !pfnStrlenAorW )
+        {
+            wxPrintf(_T("ERROR: function '%s' wasn't found in '%s'.\n"),
+                     FUNC_NAME_AW, LIB_NAME);
+        }
+        else
+        {
+            if ( pfnStrlenAorW(_T("foobar")) != 6 )
+            {
+                wxPrintf(_T("ERROR: loaded function is not wxStrlen()!\n"));
+            }
+        }
+#endif // __WXMSW__
+    }
+}
+
+#if defined(__WXMSW__) || defined(__UNIX__)
+
+static void TestDllListLoaded()
+{
+    wxPuts(_T("*** testing wxDynamicLibrary::ListLoaded() ***\n"));
+
+    puts("\nLoaded modules:");
+    wxDynamicLibraryDetailsArray dlls = wxDynamicLibrary::ListLoaded();
+    const size_t count = dlls.GetCount();
+    for ( size_t n = 0; n < count; ++n )
+    {
+        const wxDynamicLibraryDetails& details = dlls[n];
+        printf("%-45s", details.GetPath().mb_str());
+
+        void *addr;
+        size_t len;
+        if ( details.GetAddress(&addr, &len) )
+        {
+            printf(" %08lx:%08lx",
+                   (unsigned long)addr, (unsigned long)((char *)addr + len));
+        }
+
+        printf(" %s\n", details.GetVersion().mb_str());
     }
 }
 
     }
 }
 
-#endif // TEST_DLLLOADER
+#endif
+
+#endif // TEST_DYNLIB
 
 // ----------------------------------------------------------------------------
 // wxGet/SetEnv
 
 // ----------------------------------------------------------------------------
 // wxGet/SetEnv
@@ -809,70 +861,6 @@ static void TestFileNameTemp()
     }
 }
 
     }
 }
 
-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 TestFileNameDirManip()
 {
     // TODO: test AppendDir(), RemoveDir(), ...
@@ -2598,6 +2586,75 @@ static void TestFtpUpload()
 
 #endif // TEST_FTP
 
 
 #endif // TEST_FTP
 
+// ----------------------------------------------------------------------------
+// stack backtrace
+// ----------------------------------------------------------------------------
+
+#ifdef TEST_STACKWALKER
+
+#if wxUSE_STACKWALKER
+
+#include "wx/stackwalk.h"
+
+class StackDump : public wxStackWalker
+{
+public:
+    StackDump(const char *argv0)
+        : wxStackWalker(argv0)
+    {
+    }
+
+    virtual void Walk(size_t skip = 1)
+    {
+        wxPuts(_T("Stack dump:"));
+
+        wxStackWalker::Walk(skip);
+    }
+
+protected:
+    virtual void OnStackFrame(const wxStackFrame& frame)
+    {
+        printf("[%2d] ", frame.GetLevel());
+
+        wxString name = frame.GetName();
+        if ( !name.empty() )
+        {
+            printf("%-20.40s", name.mb_str());
+        }
+        else
+        {
+            printf("0x%08lx", (unsigned long)frame.GetAddress());
+        }
+
+        if ( frame.HasSourceLocation() )
+        {
+            printf("\t%s:%d",
+                   frame.GetFileName().mb_str(),
+                   frame.GetLine());
+        }
+
+        puts("");
+
+        wxString type, val;
+        for ( size_t n = 0; frame.GetParam(n, &type, &name, &val); n++ )
+        {
+            printf("\t%s %s = %s\n", type.mb_str(), name.mb_str(), val.mb_str());
+        }
+    }
+};
+
+static void TestStackWalk(const char *argv0)
+{
+    wxPuts(_T("*** Testing wxStackWalker ***\n"));
+
+    StackDump dump(argv0);
+    dump.Walk();
+}
+
+#endif // wxUSE_STACKWALKER
+
+#endif // TEST_STACKWALKER
+
 // ----------------------------------------------------------------------------
 // standard paths
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // standard paths
 // ----------------------------------------------------------------------------
@@ -2612,7 +2669,7 @@ static void TestStandardPaths()
 
     wxTheApp->SetAppName(_T("console"));
 
 
     wxTheApp->SetAppName(_T("console"));
 
-    wxStandardPaths& stdp = wxStandardPaths::Get();
+    wxStandardPathsBase& stdp = wxStandardPaths::Get();
     wxPrintf(_T("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str());
     wxPrintf(_T("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str());
     wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str());
     wxPrintf(_T("Config dir (sys):\t%s\n"), stdp.GetConfigDir().c_str());
     wxPrintf(_T("Config dir (user):\t%s\n"), stdp.GetUserConfigDir().c_str());
     wxPrintf(_T("Data dir (sys):\t\t%s\n"), stdp.GetDataDir().c_str());
@@ -2697,7 +2754,7 @@ static void TestMemoryStream()
 
 #ifdef TEST_TIMER
 
 
 #ifdef TEST_TIMER
 
-#include "wx/timer.h"
+#include "wx/stopwatch.h"
 #include "wx/utils.h"
 
 static void TestStopWatch()
 #include "wx/utils.h"
 
 static void TestStopWatch()
@@ -2958,7 +3015,7 @@ static void TestVCardRead()
 
         wxPrintf(_T("Full name from wxVCard API: %s\n"), value.c_str());
 
 
         wxPrintf(_T("Full name from wxVCard API: %s\n"), value.c_str());
 
-        // now show how to deal with multiply occuring properties
+        // now show how to deal with multiply occurring properties
         DumpVCardAddresses(vcard);
         DumpVCardPhoneNumbers(vcard);
 
         DumpVCardAddresses(vcard);
         DumpVCardPhoneNumbers(vcard);
 
@@ -3977,6 +4034,24 @@ static void TestSemaphore()
 
 int main(int argc, char **argv)
 {
 
 int main(int argc, char **argv)
 {
+#if wxUSE_UNICODE
+    wxChar **wxArgv = new wxChar *[argc + 1];
+
+    {
+        int n;
+
+        for (n = 0; n < argc; n++ )
+        {
+            wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
+            wxArgv[n] = wxStrdup(warg);
+        }
+
+        wxArgv[n] = NULL;
+    }
+#else // !wxUSE_UNICODE
+    #define wxArgv argv
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+
     wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
 
     wxInitializer initializer;
     wxApp::CheckBuildOptions(WX_BUILD_OPTIONS_SIGNATURE, "program");
 
     wxInitializer initializer;
@@ -4032,34 +4107,7 @@ int main(int argc, char **argv)
         { wxCMD_LINE_NONE }
     };
 
         { wxCMD_LINE_NONE }
     };
 
-#if wxUSE_UNICODE
-    wxChar **wargv = new wxChar *[argc + 1];
-
-    {
-        int n;
-
-        for (n = 0; n < argc; n++ )
-        {
-            wxMB2WXbuf warg = wxConvertMB2WX(argv[n]);
-            wargv[n] = wxStrdup(warg);
-        }
-
-        wargv[n] = NULL;
-    }
-
-    #define argv wargv
-#endif // wxUSE_UNICODE
-
-    wxCmdLineParser parser(cmdLineDesc, argc, argv);
-
-#if wxUSE_UNICODE
-    {
-        for ( int n = 0; n < argc; n++ )
-            free(wargv[n]);
-
-        delete [] wargv;
-    }
-#endif // wxUSE_UNICODE
+    wxCmdLineParser parser(cmdLineDesc, argc, wxArgv);
 
     parser.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
                      wxCMD_LINE_VAL_STRING,
 
     parser.AddOption(_T("project_name"), _T(""), _T("full path to project file"),
                      wxCMD_LINE_VAL_STRING,
@@ -4091,9 +4139,10 @@ int main(int argc, char **argv)
     TestDirTraverse();
 #endif // TEST_DIR
 
     TestDirTraverse();
 #endif // TEST_DIR
 
-#ifdef TEST_DLLLOADER
+#ifdef TEST_DYNLIB
     TestDllLoad();
     TestDllLoad();
-#endif // TEST_DLLLOADER
+    TestDllListLoaded();
+#endif // TEST_DYNLIB
 
 #ifdef TEST_ENVIRON
     TestEnvironment();
 
 #ifdef TEST_ENVIRON
     TestEnvironment();
@@ -4142,10 +4191,6 @@ int main(int argc, char **argv)
 #endif // TEST_FILE
 
 #ifdef TEST_FILENAME
 #endif // TEST_FILE
 
 #ifdef TEST_FILENAME
-    TestFileNameConstruction();
-    TestFileNameMakeRelative();
-    TestFileNameMakeAbsolute();
-    TestFileNameSplit();
     TestFileNameTemp();
     TestFileNameCwd();
     TestFileNameDirManip();
     TestFileNameTemp();
     TestFileNameCwd();
     TestFileNameDirManip();
@@ -4273,17 +4318,10 @@ int main(int argc, char **argv)
 
 #ifdef TEST_DATETIME
     #if TEST_ALL
 
 #ifdef TEST_DATETIME
     #if TEST_ALL
-        TestTimeSet();
         TestTimeStatic();
         TestTimeRange();
         TestTimeZones();
         TestTimeStatic();
         TestTimeRange();
         TestTimeZones();
-        TestTimeTicks();
-        TestTimeJDN();
         TestTimeDST();
         TestTimeDST();
-        TestTimeWDays();
-        TestTimeWNumber();
-        TestTimeParse();
-        TestTimeArithmetics();
         TestTimeHolidays();
         TestTimeSpanFormat();
         TestTimeMS();
         TestTimeHolidays();
         TestTimeSpanFormat();
         TestTimeMS();
@@ -4300,6 +4338,12 @@ int main(int argc, char **argv)
     TestScopeGuard();
 #endif
 
     TestScopeGuard();
 #endif
 
+#ifdef TEST_STACKWALKER
+#if wxUSE_STACKWALKER
+    TestStackWalk(argv[0]);
+#endif
+#endif // TEST_STACKWALKER
+
 #ifdef TEST_STDPATHS
     TestStandardPaths();
 #endif
 #ifdef TEST_STDPATHS
     TestStandardPaths();
 #endif
@@ -4328,6 +4372,15 @@ int main(int argc, char **argv)
     TestZipFileSystem();
 #endif // TEST_ZIP
 
     TestZipFileSystem();
 #endif // TEST_ZIP
 
+#if wxUSE_UNICODE
+    {
+        for ( int n = 0; n < argc; n++ )
+            free(wxArgv[n]);
+
+        delete [] wxArgv;
+    }
+#endif // wxUSE_UNICODE
+
     wxUnusedVar(argc);
     wxUnusedVar(argv);
     return 0;
     wxUnusedVar(argc);
     wxUnusedVar(argv);
     return 0;