fixed wxSplitPath() bug and added tests for it
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9116 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -37,14 +37,14 @@
|
|||||||
|
|
||||||
//#define TEST_ARRAYS
|
//#define TEST_ARRAYS
|
||||||
//#define TEST_CMDLINE
|
//#define TEST_CMDLINE
|
||||||
#define TEST_DATETIME
|
//#define TEST_DATETIME
|
||||||
//#define TEST_DIR
|
//#define TEST_DIR
|
||||||
//#define TEST_DLLLOADER
|
//#define TEST_DLLLOADER
|
||||||
//#define TEST_ENVIRON
|
//#define TEST_ENVIRON
|
||||||
//#define TEST_EXECUTE
|
//#define TEST_EXECUTE
|
||||||
//#define TEST_FILE
|
//#define TEST_FILE
|
||||||
//#define TEST_FILECONF
|
//#define TEST_FILECONF
|
||||||
//#define TEST_FILENAME
|
#define TEST_FILENAME
|
||||||
//#define TEST_FTP
|
//#define TEST_FTP
|
||||||
//#define TEST_HASH
|
//#define TEST_HASH
|
||||||
//#define TEST_LIST
|
//#define TEST_LIST
|
||||||
@@ -596,17 +596,19 @@ static void TestFileConfRead()
|
|||||||
|
|
||||||
#include <wx/filename.h>
|
#include <wx/filename.h>
|
||||||
|
|
||||||
static void TestFileNameConstruction()
|
static const wxChar *filenames[] =
|
||||||
{
|
{
|
||||||
puts("*** testing wxFileName construction ***");
|
|
||||||
|
|
||||||
static const wxChar *filenames[] =
|
|
||||||
{
|
|
||||||
_T("/usr/bin/ls"),
|
_T("/usr/bin/ls"),
|
||||||
_T("/usr/bin/"),
|
_T("/usr/bin/"),
|
||||||
_T("~/.zshrc"),
|
_T("~/.zshrc"),
|
||||||
_T("../../foo"),
|
_T("../../foo"),
|
||||||
};
|
_T("~/foo.bar"),
|
||||||
|
_T("/tmp/wxwin.tar.bz"),
|
||||||
|
};
|
||||||
|
|
||||||
|
static void TestFileNameConstruction()
|
||||||
|
{
|
||||||
|
puts("*** testing wxFileName construction ***");
|
||||||
|
|
||||||
for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
|
for ( size_t n = 0; n < WXSIZEOF(filenames); n++ )
|
||||||
{
|
{
|
||||||
@@ -626,6 +628,21 @@ static void TestFileNameConstruction()
|
|||||||
puts("");
|
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()
|
static void TestFileNameComparison()
|
||||||
{
|
{
|
||||||
// TODO!
|
// TODO!
|
||||||
@@ -4000,9 +4017,10 @@ int main(int argc, char **argv)
|
|||||||
#endif // TEST_FILE
|
#endif // TEST_FILE
|
||||||
|
|
||||||
#ifdef TEST_FILENAME
|
#ifdef TEST_FILENAME
|
||||||
TestFileNameConstruction();
|
TestFileNameSplit();
|
||||||
if ( 0 )
|
if ( 0 )
|
||||||
{
|
{
|
||||||
|
TestFileNameConstruction();
|
||||||
TestFileNameCwd();
|
TestFileNameCwd();
|
||||||
TestFileNameComparison();
|
TestFileNameComparison();
|
||||||
TestFileNameOperations();
|
TestFileNameOperations();
|
||||||
|
@@ -535,9 +535,12 @@ void wxFileName::SplitPath(const wxString& fullpath,
|
|||||||
|
|
||||||
if ( pstrName )
|
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 nStart = posLastSlash == wxString::npos ? 0 : posLastSlash + 1;
|
||||||
size_t count = posLastDot == wxString::npos ? wxString::npos
|
size_t count = posLastDot == wxString::npos
|
||||||
: posLastDot - posLastSlash;
|
? wxString::npos
|
||||||
|
: posLastDot - posLastSlash - 1;
|
||||||
|
|
||||||
*pstrName = fullpath.Mid(nStart, count);
|
*pstrName = fullpath.Mid(nStart, count);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user