Refactor wxFileName existence checking code.
Merge FileExists() and DirExists() together in a single wxFileSystemObjectExists() helper in preparation for adding a function checking for the existence of any kind of file system object. There should be no changes for MSW/Unix but OS/2 file detection was changed slightly to always use DosQueryPathInfo() instead of using it only for the directories and stat() for files. Not sure if this is the right thing to do there but it seems like the code should work. Also add a simple unit test for these functions. See #953. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70599 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -134,6 +134,7 @@ private:
|
||||
CPPUNIT_TEST( TestVolumeUniqueName );
|
||||
CPPUNIT_TEST( TestCreateTempFileName );
|
||||
CPPUNIT_TEST( TestGetTimes );
|
||||
CPPUNIT_TEST( TestExists );
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
void TestConstruction();
|
||||
@@ -151,6 +152,7 @@ private:
|
||||
void TestVolumeUniqueName();
|
||||
void TestCreateTempFileName();
|
||||
void TestGetTimes();
|
||||
void TestExists();
|
||||
|
||||
DECLARE_NO_COPY_CLASS(FileNameTestCase)
|
||||
};
|
||||
@@ -647,3 +649,21 @@ void FileNameTestCase::TestGetTimes()
|
||||
CPPUNIT_ASSERT(dtMod.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
||||
CPPUNIT_ASSERT(dtAccess.IsEqualUpTo(wxDateTime::Now(), wxTimeSpan(0,1)));
|
||||
}
|
||||
|
||||
void FileNameTestCase::TestExists()
|
||||
{
|
||||
wxFileName fn(wxFileName::CreateTempFileName("filenametest"));
|
||||
CPPUNIT_ASSERT( fn.IsOk() );
|
||||
|
||||
CPPUNIT_ASSERT( fn.FileExists() );
|
||||
CPPUNIT_ASSERT( !wxFileName::DirExists(fn.GetFullPath()) );
|
||||
|
||||
wxFileName dirTemp(wxFileName::DirName(wxFileName::GetTempDir()));
|
||||
CPPUNIT_ASSERT( !dirTemp.FileExists() );
|
||||
CPPUNIT_ASSERT( dirTemp.DirExists() );
|
||||
|
||||
#ifdef __UNIX__
|
||||
CPPUNIT_ASSERT( !wxFileName::FileExists("/dev/null") );
|
||||
CPPUNIT_ASSERT( !wxFileName::DirExists("/dev/null") );
|
||||
#endif // __UNIX__
|
||||
}
|
||||
|
Reference in New Issue
Block a user