]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/filename/filenametest.cpp
name change to correctly reflect the autorelease nature of the methods, removing...
[wxWidgets.git] / tests / filename / filenametest.cpp
index ce964f54b9f3b53ae9cec67b43ddf529f7421c6b..a9fab6197cc3338f5b822b72cf2dbf792d387c28 100644 (file)
     #include "wx/msw/registry.h"
 #endif // __WXMSW__
 
-// ----------------------------------------------------------------------------
-// local functions
-// ----------------------------------------------------------------------------
-
-// define stream inserter for wxFileName to use it in CPPUNIT_ASSERT_EQUAL()
-inline std::ostream& operator<<(std::ostream& o, const wxFileName& fn)
-{
-    return o << fn.GetFullPath();
-}
+#include "testfile.h"
 
 // ----------------------------------------------------------------------------
 // test data
@@ -77,6 +69,10 @@ static struct TestFileNameInfo
     { "c:foo.bar", "c", "", "foo", "bar", false, wxPATH_DOS },
     { "c:\\foo.bar", "c", "\\", "foo", "bar", true, wxPATH_DOS },
     { "c:\\Windows\\command.com", "c", "\\Windows", "command", "com", true, wxPATH_DOS },
+    { "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
+      "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}", "\\", "", "", true, wxPATH_DOS },
+    { "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\Program Files\\setup.exe",
+      "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}", "\\Program Files", "setup", "exe", true, wxPATH_DOS },
 
 #if 0
     // NB: when using the wxFileName::GetLongPath() function on these two
@@ -129,9 +125,12 @@ private:
         CPPUNIT_TEST( TestStrip );
         CPPUNIT_TEST( TestNormalize );
         CPPUNIT_TEST( TestReplace );
+        CPPUNIT_TEST( TestGetHumanReadable );
 #ifdef __WINDOWS__
         CPPUNIT_TEST( TestShortLongPath );
 #endif // __WINDOWS__
+        CPPUNIT_TEST( TestUNC );
+        CPPUNIT_TEST( TestVolumeUniqueName );
     CPPUNIT_TEST_SUITE_END();
 
     void TestConstruction();
@@ -141,9 +140,12 @@ private:
     void TestStrip();
     void TestNormalize();
     void TestReplace();
+    void TestGetHumanReadable();
 #ifdef __WINDOWS__
     void TestShortLongPath();
 #endif // __WINDOWS__
+    void TestUNC();
+    void TestVolumeUniqueName();
 
     DECLARE_NO_COPY_CLASS(FileNameTestCase)
 };
@@ -315,6 +317,8 @@ void FileNameTestCase::TestNormalize()
 
         // test wxPATH_NORM_DOTS
         { "a/.././b/c/../../", wxPATH_NORM_DOTS, "", wxPATH_UNIX },
+        { "./", wxPATH_NORM_DOTS, "", wxPATH_UNIX },
+        { "b/../", wxPATH_NORM_DOTS, "", wxPATH_UNIX },
 
         // test wxPATH_NORM_TILDE: notice that ~ is only interpreted specially
         // when it is the first character in the file name
@@ -476,6 +480,39 @@ void FileNameTestCase::TestReplace()
                           fn.GetFullPath(wxPATH_UNIX) );
 }
 
+void FileNameTestCase::TestGetHumanReadable()
+{
+    static const struct TestData
+    {
+        const char *result;
+        int size;
+        int prec;
+        wxSizeConvention conv;
+    } testData[] =
+    {
+        { "NA",             0, 1, wxSIZE_CONV_TRADITIONAL },
+        { "2.0 KB",      2000, 1, wxSIZE_CONV_TRADITIONAL },
+        { "1.953 KiB",   2000, 3, wxSIZE_CONV_IEC         },
+        { "2.000 KB",    2000, 3, wxSIZE_CONV_SI          },
+        { "297 KB",    304351, 0, wxSIZE_CONV_TRADITIONAL },
+        { "304 KB",    304351, 0, wxSIZE_CONV_SI          },
+    };
+
+    for ( unsigned n = 0; n < WXSIZEOF(testData); n++ )
+    {
+        const TestData& td = testData[n];
+
+        CPPUNIT_ASSERT_EQUAL
+        (
+            td.result,
+            wxFileName::GetHumanReadableSize(td.size, "NA", td.prec, td.conv)
+        );
+    }
+
+    // also test the default convention value
+    CPPUNIT_ASSERT_EQUAL( "1.4 MB", wxFileName::GetHumanReadableSize(1512993, "") );
+}
+
 void FileNameTestCase::TestStrip()
 {
     CPPUNIT_ASSERT_EQUAL( "", wxFileName::StripExtension("") );
@@ -499,3 +536,35 @@ void FileNameTestCase::TestShortLongPath()
 }
 
 #endif // __WINDOWS__
+
+void FileNameTestCase::TestUNC()
+{
+    wxFileName fn("//share/path/name.ext", wxPATH_DOS);
+    CPPUNIT_ASSERT_EQUAL( "share", fn.GetVolume() );
+    CPPUNIT_ASSERT_EQUAL( "\\path", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
+
+    fn.Assign("\\\\share2\\path2\\name.ext", wxPATH_DOS);
+    CPPUNIT_ASSERT_EQUAL( "share2", fn.GetVolume() );
+    CPPUNIT_ASSERT_EQUAL( "\\path2", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
+}
+
+void FileNameTestCase::TestVolumeUniqueName()
+{
+    wxFileName fn("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
+                  wxPATH_DOS);
+    CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}",
+                          fn.GetVolume() );
+    CPPUNIT_ASSERT_EQUAL( "\\", fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
+    CPPUNIT_ASSERT_EQUAL( "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\",
+                          fn.GetFullPath(wxPATH_DOS) );
+
+    fn.Assign("\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\"
+              "Program Files\\setup.exe", wxPATH_DOS);
+    CPPUNIT_ASSERT_EQUAL( "Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}",
+                          fn.GetVolume() );
+    CPPUNIT_ASSERT_EQUAL( "\\Program Files",
+                          fn.GetPath(wxPATH_NO_SEPARATOR, wxPATH_DOS) );
+    CPPUNIT_ASSERT_EQUAL( "\\\\?\\Volume{8089d7d7-d0ac-11db-9dd0-806d6172696f}\\"
+                          "Program Files\\setup.exe",
+                          fn.GetFullPath(wxPATH_DOS) );
+}