]>
git.saurik.com Git - wxWidgets.git/blob - tests/filename/filename.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/filename/filename.cpp
3 // Purpose: wxFileName unit test
4 // Author: Vadim Zeitlin
7 // Copyright: (c) 2004 Vadim Zeitlin
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
14 #include "wx/wxprec.h"
23 #include "wx/filename.h"
25 #include "wx/cppunit.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 static struct FileNameInfo
33 const wxChar
*fullname
;
43 { _T("/usr/bin/ls"), _T(""), _T("/usr/bin"), _T("ls"), _T(""), true, wxPATH_UNIX
},
44 { _T("/usr/bin/"), _T(""), _T("/usr/bin"), _T(""), _T(""), true, wxPATH_UNIX
},
45 { _T("~/.zshrc"), _T(""), _T("~"), _T(".zshrc"), _T(""), true, wxPATH_UNIX
},
46 { _T("../../foo"), _T(""), _T("../.."), _T("foo"), _T(""), false, wxPATH_UNIX
},
47 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
48 { _T("~/foo.bar"), _T(""), _T("~"), _T("foo"), _T("bar"), true, wxPATH_UNIX
},
49 { _T("/foo"), _T(""), _T("/"), _T("foo"), _T(""), true, wxPATH_UNIX
},
50 { _T("Mahogany-0.60/foo.bar"), _T(""), _T("Mahogany-0.60"), _T("foo"), _T("bar"), false, wxPATH_UNIX
},
51 { _T("/tmp/wxwin.tar.bz"), _T(""), _T("/tmp"), _T("wxwin.tar"), _T("bz"), true, wxPATH_UNIX
},
54 { _T("foo.bar"), _T(""), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
55 { _T("\\foo.bar"), _T(""), _T("\\"), _T("foo"), _T("bar"), false, wxPATH_DOS
},
56 { _T("c:foo.bar"), _T("c"), _T(""), _T("foo"), _T("bar"), false, wxPATH_DOS
},
57 { _T("c:\\foo.bar"), _T("c"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
58 { _T("c:\\Windows\\command.com"), _T("c"), _T("\\Windows"), _T("command"), _T("com"), true, wxPATH_DOS
},
59 { _T("\\\\server\\foo.bar"), _T("server"), _T("\\"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
60 { _T("\\\\server\\dir\\foo.bar"), _T("server"), _T("\\dir"), _T("foo"), _T("bar"), true, wxPATH_DOS
},
62 // wxFileName support for Mac file names is broken currently
65 { _T("Volume:Dir:File"), _T("Volume"), _T("Dir"), _T("File"), _T(""), true, wxPATH_MAC
},
66 { _T("Volume:Dir:Subdir:File"), _T("Volume"), _T("Dir:Subdir"), _T("File"), _T(""), true, wxPATH_MAC
},
67 { _T("Volume:"), _T("Volume"), _T(""), _T(""), _T(""), true, wxPATH_MAC
},
68 { _T(":Dir:File"), _T(""), _T("Dir"), _T("File"), _T(""), false, wxPATH_MAC
},
69 { _T(":File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
70 { _T("File.Ext"), _T(""), _T(""), _T("File"), _T(".Ext"), false, wxPATH_MAC
},
74 { _T("device:[dir1.dir2.dir3]file.txt"), _T("device"), _T("dir1.dir2.dir3"), _T("file"), _T("txt"), true, wxPATH_VMS
},
75 { _T("file.txt"), _T(""), _T(""), _T("file"), _T("txt"), false, wxPATH_VMS
},
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 class FileNameTestCase
: public CppUnit::TestCase
85 FileNameTestCase() { }
88 CPPUNIT_TEST_SUITE( FileNameTestCase
);
89 CPPUNIT_TEST( TestConstruction
);
90 CPPUNIT_TEST( TestSplit
);
91 CPPUNIT_TEST( TestSetPath
);
92 CPPUNIT_TEST_SUITE_END();
94 void TestConstruction();
98 DECLARE_NO_COPY_CLASS(FileNameTestCase
)
101 // register in the unnamed registry so that these tests are run by default
102 CPPUNIT_TEST_SUITE_REGISTRATION( FileNameTestCase
);
104 // also include in it's own registry so that these tests can be run alone
105 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FileNameTestCase
, "FileNameTestCase" );
107 void FileNameTestCase::TestConstruction()
109 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
111 const FileNameInfo
& fni
= filenames
[n
];
113 wxFileName
fn(fni
.fullname
, fni
.format
);
115 wxString fullname
= fn
.GetFullPath(fni
.format
);
116 CPPUNIT_ASSERT( fullname
== fni
.fullname
);
118 CPPUNIT_ASSERT( fn
.Normalize(wxPATH_NORM_ALL
, _T(""), fni
.format
) );
122 void FileNameTestCase::TestSplit()
124 for ( size_t n
= 0; n
< WXSIZEOF(filenames
); n
++ )
126 const FileNameInfo
& fni
= filenames
[n
];
127 wxString volume
, path
, name
, ext
;
128 wxFileName::SplitPath(fni
.fullname
,
129 &volume
, &path
, &name
, &ext
, fni
.format
);
131 CPPUNIT_ASSERT( volume
== fni
.volume
);
132 CPPUNIT_ASSERT( path
== fni
.path
);
133 CPPUNIT_ASSERT( name
== fni
.name
);
134 CPPUNIT_ASSERT( ext
== fni
.ext
);
138 void FileNameTestCase::TestSetPath()
140 wxFileName
fn(_T("d:\\test\\foo.bar"), wxPATH_DOS
);
141 fn
.SetPath(_T("c:\\temp"));
142 CPPUNIT_ASSERT( fn
== _T("c:\\temp\\foo.bar") );
144 fn
= _T("/usr/bin/ls");
145 fn
.SetPath(_T("/usr/local/bin"));
146 CPPUNIT_ASSERT( fn
== _T("/usr/local/bin/ls") );