X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e7747eb2e0c892abdcea1925dfa71ade77a761a8..9483e1ac7739c2f920067c2a9343f1b158bc975c:/tests/file/dir.cpp diff --git a/tests/file/dir.cpp b/tests/file/dir.cpp index 50b5b71052..81d66ad53e 100644 --- a/tests/file/dir.cpp +++ b/tests/file/dir.cpp @@ -19,6 +19,7 @@ #include "wx/dir.h" #include "wx/filename.h" +#include "wx/stdpaths.h" #define DIRTEST_FOLDER wxString("dirTest_folder") #define SEP wxFileName::GetPathSeparator() @@ -40,11 +41,13 @@ private: CPPUNIT_TEST( DirExists ); CPPUNIT_TEST( Traverse ); CPPUNIT_TEST( Enum ); + CPPUNIT_TEST( GetName ); CPPUNIT_TEST_SUITE_END(); void DirExists(); void Traverse(); void Enum(); + void GetName(); void CreateTempFile(const wxString& path); wxArrayString DirEnumHelper(wxDir& dir, @@ -176,41 +179,69 @@ void DirTestCase::DirExists() { { ".", true }, { "..", true }, -#if defined(__WXMSW__) + { "$USER_DOCS_DIR", true }, +#if defined(__WINDOWS__) + { "$USER_DOCS_DIR\\", true }, + { "$USER_DOCS_DIR\\\\", true }, { "..\\..", true }, - { "..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..", /*false*/ true }, - // FIXME: should fail but it doesn't... looks like a bug in GetFileAttributes() win API - { "c:", true }, - { "c:\\", true }, - { "c:\\\\", true }, - { "\\\\share\\file", false }, - { "c:\\a\\directory\\which\\does\\not\\exist", false }, - { "c:\\a\\directory\\which\\does\\not\\exist\\", false }, - { "c:\\a\\directory\\which\\does\\not\\exist\\\\", false }, - { "test.exe", false } // not a directory! + { "$MSW_DRIVE", true }, + { "$MSW_DRIVE\\", true }, + { "$MSW_DRIVE\\\\", true }, + { "\\\\non_existent_share\\file", false }, + { "$MSW_DRIVE\\a\\directory\\which\\does\\not\\exist", false }, + { "$MSW_DRIVE\\a\\directory\\which\\does\\not\\exist\\", false }, + { "$MSW_DRIVE\\a\\directory\\which\\does\\not\\exist\\\\", false }, + { "test.exe", false } // not a directory! #elif defined(__UNIX__) { "../..", true }, - { "../../../../../../../../../../../../../../../../../../../..", false }, { "/", true }, { "//", true }, { "/usr/bin", true }, - { "/usr//bin", false }, - { "/usr///bin", false } + { "/usr//bin", true }, + { "/usr///bin", true }, + { "/tmp/a/directory/which/does/not/exist", false }, + { "/bin/ls", false } // not a directory! #endif }; +#ifdef __WINDOWS__ + wxString homedrive = wxGetenv("HOMEDRIVE"); + if ( homedrive.empty() ) + homedrive = "c:"; +#endif // __WINDOWS__ + for ( size_t n = 0; n < WXSIZEOF(testData); n++ ) { - wxString errDesc = wxString::Format("failed on directory '%s'", testData[n].dirname); - CPPUNIT_ASSERT_EQUAL_MESSAGE(errDesc.ToStdString(), testData[n].shouldExist, wxDir::Exists(testData[n].dirname)); - - if (!testData[n].shouldExist) - { - wxDir d(testData[n].dirname); - CPPUNIT_ASSERT(!d.IsOpened()); - } + wxString dirname = testData[n].dirname; + dirname.Replace("$USER_DOCS_DIR", wxStandardPaths::Get().GetDocumentsDir()); + +#ifdef __WINDOWS__ + dirname.Replace("$MSW_DRIVE", homedrive); +#endif // __WINDOWS__ + + std::string errDesc = wxString::Format("failed on directory '%s'", dirname).ToStdString(); + CPPUNIT_ASSERT_EQUAL_MESSAGE(errDesc, testData[n].shouldExist, wxDir::Exists(dirname)); + + wxDir d(dirname); + CPPUNIT_ASSERT_EQUAL(testData[n].shouldExist, d.IsOpened()); } CPPUNIT_ASSERT( wxDir::Exists(wxGetCwd()) ); } +void DirTestCase::GetName() +{ + wxDir d; + + CPPUNIT_ASSERT( d.Open(".") ); + CPPUNIT_ASSERT( d.GetName().Last() != wxFILE_SEP_PATH ); + CPPUNIT_ASSERT( d.GetNameWithSep().Last() == wxFILE_SEP_PATH ); + CPPUNIT_ASSERT_EQUAL( d.GetName() + wxFILE_SEP_PATH, + d.GetNameWithSep() ); + +#ifdef __UNIX__ + CPPUNIT_ASSERT( d.Open("/") ); + CPPUNIT_ASSERT_EQUAL( "/", d.GetName() ); + CPPUNIT_ASSERT_EQUAL( "/", d.GetNameWithSep() ); +#endif +}