//#define TEST_ARRAYS
//#define TEST_CMDLINE
-#define TEST_DATETIME
+//#define TEST_DATETIME
//#define TEST_DIR
//#define TEST_DLLLOADER
//#define TEST_ENVIRON
//#define TEST_EXECUTE
//#define TEST_FILE
//#define TEST_FILECONF
-//#define TEST_FILENAME
+#define TEST_FILENAME
//#define TEST_FTP
//#define TEST_HASH
//#define TEST_LIST
#include <wx/filename.h>
+static const wxChar *filenames[] =
+{
+ _T("/usr/bin/ls"),
+ _T("/usr/bin/"),
+ _T("~/.zshrc"),
+ _T("../../foo"),
+ _T("~/foo.bar"),
+ _T("/tmp/wxwin.tar.bz"),
+};
+
static void TestFileNameConstruction()
{
puts("*** testing wxFileName construction ***");
- static const wxChar *filenames[] =
- {
- _T("/usr/bin/ls"),
- _T("/usr/bin/"),
- _T("~/.zshrc"),
- _T("../../foo"),
- };
-
for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
{
wxFileName fn(filenames[n], wxPATH_UNIX);
puts("");
}
+static void TestFileNameSplit()
+{
+ puts("*** testing wxFileName splitting ***");
+
+ for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
+ {
+ wxString path, name, ext;
+ wxFileName::SplitPath(filenames[n], &path, &name, &ext);
+ printf("%s -> path = '%s', name = '%s', ext = '%s'\n",
+ filenames[n], path.c_str(), name.c_str(), ext.c_str());
+ }
+
+ puts("");
+}
+
static void TestFileNameComparison()
{
// TODO!
#endif // TEST_FILE
#ifdef TEST_FILENAME
- TestFileNameConstruction();
+ TestFileNameSplit();
if ( 0 )
{
+ TestFileNameConstruction();
TestFileNameCwd();
TestFileNameComparison();
TestFileNameOperations();
if ( pstrName )
{
+ // take all characters starting from the one after the last slash and
+ // up to, but excluding, the last dot
size_t nStart = posLastSlash == wxString::npos ? 0 : posLastSlash + 1;
- size_t count = posLastDot == wxString::npos ? wxString::npos
- : posLastDot - posLastSlash;
+ size_t count = posLastDot == wxString::npos
+ ? wxString::npos
+ : posLastDot - posLastSlash - 1;
*pstrName = fullpath.Mid(nStart, count);
}