]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/filename/filenametest.cpp
[ 1505048 ] wxHtml rendering of underlined text
[wxWidgets.git] / tests / filename / filenametest.cpp
index f91ab53ee4414cdbc56cce2944bc86d35a70887c..969b34d8d38d8fa0fb9a6cc28337e6ac9fc0d65f 100644 (file)
@@ -11,7 +11,7 @@
 // headers
 // ----------------------------------------------------------------------------
 
 // headers
 // ----------------------------------------------------------------------------
 
-#include "wx/wxprec.h"
+#include "testprec.h"
 
 #ifdef __BORLANDC__
     #pragma hdrstop
 
 #ifdef __BORLANDC__
     #pragma hdrstop
@@ -21,8 +21,7 @@
 #endif // WX_PRECOMP
 
 #include "wx/filename.h"
 #endif // WX_PRECOMP
 
 #include "wx/filename.h"
-
-#include "wx/cppunit.h"
+#include "wx/filefn.h"
 
 // ----------------------------------------------------------------------------
 // test data
 
 // ----------------------------------------------------------------------------
 // test data
@@ -87,13 +86,23 @@ public:
 private:
     CPPUNIT_TEST_SUITE( FileNameTestCase );
         CPPUNIT_TEST( TestConstruction );
 private:
     CPPUNIT_TEST_SUITE( FileNameTestCase );
         CPPUNIT_TEST( TestConstruction );
+        CPPUNIT_TEST( TestComparison );
         CPPUNIT_TEST( TestSplit );
         CPPUNIT_TEST( TestSetPath );
         CPPUNIT_TEST( TestSplit );
         CPPUNIT_TEST( TestSetPath );
+        CPPUNIT_TEST( TestStrip );
+#ifdef __WINDOWS__
+        CPPUNIT_TEST( TestShortLongPath );
+#endif // __WINDOWS__
     CPPUNIT_TEST_SUITE_END();
 
     void TestConstruction();
     CPPUNIT_TEST_SUITE_END();
 
     void TestConstruction();
+    void TestComparison();
     void TestSplit();
     void TestSetPath();
     void TestSplit();
     void TestSetPath();
+    void TestStrip();
+#ifdef __WINDOWS__
+    void TestShortLongPath();
+#endif // __WINDOWS__
 
     DECLARE_NO_COPY_CLASS(FileNameTestCase)
 };
 
     DECLARE_NO_COPY_CLASS(FileNameTestCase)
 };
@@ -116,9 +125,33 @@ void FileNameTestCase::TestConstruction()
         CPPUNIT_ASSERT( fullname == fni.fullname );
 
         CPPUNIT_ASSERT( fn.Normalize(wxPATH_NORM_ALL, _T(""), fni.format) );
         CPPUNIT_ASSERT( fullname == fni.fullname );
 
         CPPUNIT_ASSERT( fn.Normalize(wxPATH_NORM_ALL, _T(""), fni.format) );
+
+        if ( *fni.volume && *fni.path )
+        {
+            // check that specifying the volume separately or as part of the
+            // path doesn't make any difference
+            wxString pathWithVolume = fni.volume;
+            pathWithVolume += wxFileName::GetVolumeSeparator(fni.format);
+            pathWithVolume += fni.path;
+
+            CPPUNIT_ASSERT( fn == wxFileName(pathWithVolume,
+                                             fni.name,
+                                             fni.ext,
+                                             fni.format) );
+        }
     }
 }
 
     }
 }
 
+void FileNameTestCase::TestComparison()
+{
+    wxFileName fn1(wxT("/tmp/file1"));
+    wxFileName fn2(wxT("/tmp/dir2/../file2"));
+    fn1.Normalize();
+    fn2.Normalize();
+    CPPUNIT_ASSERT(fn1.GetPath() == fn2.GetPath());
+
+}
+
 void FileNameTestCase::TestSplit()
 {
     for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
 void FileNameTestCase::TestSplit()
 {
     for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
@@ -133,6 +166,10 @@ void FileNameTestCase::TestSplit()
         CPPUNIT_ASSERT( name == fni.name );
         CPPUNIT_ASSERT( ext == fni.ext );
     }
         CPPUNIT_ASSERT( name == fni.name );
         CPPUNIT_ASSERT( ext == fni.ext );
     }
+
+    // special case of empty extension
+    wxFileName fn(_T("foo."));
+    CPPUNIT_ASSERT( fn.GetFullPath() == _T("foo.") );
 }
 
 void FileNameTestCase::TestSetPath()
 }
 
 void FileNameTestCase::TestSetPath()
@@ -146,3 +183,34 @@ void FileNameTestCase::TestSetPath()
     CPPUNIT_ASSERT( fn.SameAs(wxFileName(_T("/usr/local/bin/ls"), wxPATH_UNIX)) );
 }
 
     CPPUNIT_ASSERT( fn.SameAs(wxFileName(_T("/usr/local/bin/ls"), wxPATH_UNIX)) );
 }
 
+wxString wxTestStripExtension(wxString szFile)
+{
+    wxStripExtension(szFile);
+    return szFile;
+}
+
+void FileNameTestCase::TestStrip()
+{
+    //test a crash
+    CPPUNIT_ASSERT( wxTestStripExtension( _T("") ) == _T("") );
+
+    //others
+    CPPUNIT_ASSERT( wxTestStripExtension( _T(".") ) == _T("") );
+    CPPUNIT_ASSERT( wxTestStripExtension( _T(".wav") ) == _T("") );
+    CPPUNIT_ASSERT( wxTestStripExtension( _T("good.wav") ) == _T("good") );
+    CPPUNIT_ASSERT( wxTestStripExtension( _T("good.wav.wav") ) == _T("good.wav") );
+}
+
+#ifdef __WINDOWS__
+
+void FileNameTestCase::TestShortLongPath()
+{
+    wxFileName fn(_T("C:\\Program Files\\Windows NT\\Accessories\\wordpad.exe"));
+
+    // incredibly enough, GetLongPath() used to return different results during
+    // the first and subsequent runs, test for this
+    CPPUNIT_ASSERT_EQUAL( fn.GetLongPath(), fn.GetLongPath() );
+    CPPUNIT_ASSERT_EQUAL( fn.GetShortPath(), fn.GetShortPath() );
+}
+
+#endif // __WINDOWS__