]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/console/console.cpp
fixed bug with the caret positioning after SetValue() introduced by the last commit
[wxWidgets.git] / samples / console / console.cpp
index 91d9b70f85e51a1976af24de81c59ec90a5cf678..c727d7ffe96f93f6581401faa7d62bce8dc1ee54 100644 (file)
@@ -740,6 +740,17 @@ static void TestFileConfRead()
 
 #include "wx/filename.h"
 
+static void DumpFileName(const wxFileName& fn)
+{
+    wxString full = fn.GetFullPath();
+
+    wxString vol, path, name, ext;
+    wxFileName::SplitPath(full, &vol, &path, &name, &ext);
+
+    wxPrintf(_T("Filename '%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());
+}
+
 static struct FileNameInfo
 {
     const wxChar *fullname;
@@ -844,6 +855,77 @@ static void TestFileNameSplit()
     }
 }
 
+static void TestFileNameTemp()
+{
+    puts("*** testing wxFileName temp file creation ***");
+
+    static const char *tmpprefixes[] =
+    {
+        "foo",
+        "/tmp/foo",
+        "..",
+        "../bar",
+        "/tmp/foo/bar", // this one must be an error
+    };
+
+    for ( size_t n = 0; n < WXSIZEOF(tmpprefixes); n++ )
+    {
+        wxString path = wxFileName::CreateTempFileName(tmpprefixes[n]);
+        if ( !path.empty() )
+        {
+            printf("Prefix '%s'\t-> temp file '%s'\n",
+                   tmpprefixes[n], path.c_str());
+
+            if ( !wxRemoveFile(path) )
+            {
+                wxLogWarning("Failed to remove temp file '%s'", path.c_str());
+            }
+        }
+    }
+}
+
+static void TestFileNameMakeRelative()
+{
+    puts("*** 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 = "/usr/bin/";
+                break;
+
+            case wxPATH_DOS:
+                base = "c:\\";
+                break;
+
+            case wxPATH_MAC:
+            case wxPATH_VMS:
+                // TODO: I don't know how this is supposed to work there
+                continue;
+        }
+
+        printf("'%s' relative to '%s': ",
+               fn.GetFullPath(fni.format).c_str(), base.c_str());
+
+        if ( !fn.MakeRelativeTo(base, fni.format) )
+        {
+            puts("unchanged");
+        }
+        else
+        {
+            printf("'%s'\n", fn.GetFullPath(fni.format).c_str());
+        }
+    }
+}
+
 static void TestFileNameComparison()
 {
     // TODO!
@@ -5187,10 +5269,20 @@ int main(int argc, char **argv)
 #endif // TEST_FILE
 
 #ifdef TEST_FILENAME
-    TestFileNameConstruction();
-    TestFileNameSplit();
     if ( 0 )
     {
+        wxFileName fn;
+        fn.Assign("c:\\foo", "bar.baz");
+
+        DumpFileName(fn);
+    }
+
+    TestFileNameMakeRelative();
+    if ( 0 )
+    {
+    TestFileNameConstruction();
+    TestFileNameSplit();
+    TestFileNameTemp();
         TestFileNameCwd();
         TestFileNameComparison();
         TestFileNameOperations();