]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/filename/filenametest.cpp
Use UTF16 for text data object on Mac. Fixes #10902
[wxWidgets.git] / tests / filename / filenametest.cpp
index 9132c0e3eaaa5d26251cb876c417175a23fe3a95..711233d85d3c020c12df05e98e9e13b306e08e98 100644 (file)
 #include "wx/filename.h"
 #include "wx/filefn.h"
 
+#ifdef __WXMSW__
+    #include "wx/msw/registry.h"
+#endif // __WXMSW__
+
 // ----------------------------------------------------------------------------
 // local functions
 // ----------------------------------------------------------------------------
@@ -120,9 +124,7 @@ private:
         CPPUNIT_TEST( TestComparison );
         CPPUNIT_TEST( TestSplit );
         CPPUNIT_TEST( TestSetPath );
-#if WXWIN_COMPATIBILITY_2_8
         CPPUNIT_TEST( TestStrip );
-#endif
         CPPUNIT_TEST( TestNormalize );
         CPPUNIT_TEST( TestReplace );
 #ifdef __WINDOWS__
@@ -134,9 +136,7 @@ private:
     void TestComparison();
     void TestSplit();
     void TestSetPath();
-#if WXWIN_COMPATIBILITY_2_8
     void TestStrip();
-#endif
     void TestNormalize();
     void TestReplace();
 #ifdef __WINDOWS__
@@ -349,9 +349,6 @@ void FileNameTestCase::TestNormalize()
         { ".\\foo", wxPATH_NORM_LONG, ".\\foo", wxPATH_DOS },
         { "..\\Makefile.in", wxPATH_NORM_LONG, "..\\Makefile.in", wxPATH_DOS },
         { "..\\foo", wxPATH_NORM_LONG, "..\\foo", wxPATH_DOS },
-#ifdef __WXMSW__
-        { "..\\MKINST~1", wxPATH_NORM_LONG, "..\\mkinstalldirs", wxPATH_DOS },
-#endif
     };
 
     // set the env var ABCDEF
@@ -379,6 +376,29 @@ void FileNameTestCase::TestNormalize()
             expected, fn.GetFullPath(fnt.fmt)
         );
     }
+
+    // MSW-only test for wxPATH_NORM_LONG: notice that we only run it if short
+    // names generation is not disabled for this system as otherwise the file
+    // MKINST~1 doesn't exist at all and normalizing it fails (it's possible
+    // that we're on a FAT partition in which case the test would still succeed
+    // and also that the registry key was changed recently and didn't take
+    // effect yet but these are marginal cases which we consciously choose to
+    // ignore for now)
+#ifdef __WXMSW__
+    long shortNamesDisabled;
+    if ( wxRegKey
+         (
+            wxRegKey::HKLM,
+            "SYSTEM\\CurrentControlSet\\Control\\FileSystem"
+         ).QueryValue("NtfsDisable8dot3NameCreation", &shortNamesDisabled) &&
+            !shortNamesDisabled )
+    {
+        wxFileName fn("..\\MKINST~1");
+        CPPUNIT_ASSERT( fn.Normalize(wxPATH_NORM_LONG, cwd) );
+        CPPUNIT_ASSERT_EQUAL( "..\\mkinstalldirs", fn.GetFullPath() );
+    }
+    //else: when in doubt, don't run the test
+#endif // __WXMSW__
 }
 
 void FileNameTestCase::TestReplace()
@@ -454,35 +474,15 @@ void FileNameTestCase::TestReplace()
                           fn.GetFullPath(wxPATH_UNIX) );
 }
 
-#if WXWIN_COMPATIBILITY_2_8
-
-#ifdef __VISUALC__
-    // disable warning about using deprecated wxStripExtension()
-    #pragma warning(disable:4996)
-#endif
-
-wxString wxTestStripExtension(wxString szFile)
-{
-    wxStripExtension(szFile);
-    return szFile;
-}
-
-#ifdef __VISUALC__
-    #pragma warning(default:4996)
-#endif
-
 void FileNameTestCase::TestStrip()
 {
-    //test a crash
-    CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T("")) );
-
-    //others
-    CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".")) );
-    CPPUNIT_ASSERT_EQUAL( wxString(_T("")), wxTestStripExtension(_T(".wav")) );
-    CPPUNIT_ASSERT_EQUAL( wxString(_T("good")), wxTestStripExtension(_T("good.wav")) );
-    CPPUNIT_ASSERT_EQUAL( wxString(_T("good.wav")), wxTestStripExtension(_T("good.wav.wav")) );
+    CPPUNIT_ASSERT_EQUAL( "", wxFileName::StripExtension(_T("")) );
+    CPPUNIT_ASSERT_EQUAL( ".", wxFileName::StripExtension(_T(".")) );
+    CPPUNIT_ASSERT_EQUAL( ".vimrc", wxFileName::StripExtension(_T(".vimrc")) );
+    CPPUNIT_ASSERT_EQUAL( "bad", wxFileName::StripExtension(_T("bad")) );
+    CPPUNIT_ASSERT_EQUAL( "good", wxFileName::StripExtension(_T("good.wav")) );
+    CPPUNIT_ASSERT_EQUAL( "good.wav", wxFileName::StripExtension(_T("good.wav.wav")) );
 }
-#endif // WXWIN_COMPATIBILITY_2_8
 
 #ifdef __WINDOWS__