]> git.saurik.com Git - wxWidgets.git/commitdiff
better DirTestCase::DirExists test;
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Mon, 21 Jun 2010 19:47:14 +0000 (19:47 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Mon, 21 Jun 2010 19:47:14 +0000 (19:47 +0000)
fix test cases /usr//bin and /usr///bin: they succeed because wxDir::Exists does not care about redundant path separator (and this holds also for non-Unix platforms);
add some more test case

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64678 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/file/dir.cpp

index 66e5bbd64712613d2a2593ad65a62ca86cc89c5d..71e959cc5728e34555ae430fbf41e4cf0e26df58 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "wx/dir.h"
 #include "wx/filename.h"
 
 #include "wx/dir.h"
 #include "wx/filename.h"
+#include "wx/stdpaths.h"
 
 #define DIRTEST_FOLDER      wxString("dirTest_folder")
 #define SEP                 wxFileName::GetPathSeparator()
 
 #define DIRTEST_FOLDER      wxString("dirTest_folder")
 #define SEP                 wxFileName::GetPathSeparator()
@@ -79,7 +80,7 @@ void DirTestCase::setUp()
     wxDir::Make(DIRTEST_FOLDER + SEP + "folder1" + SEP + "subfolder2", wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
     wxDir::Make(DIRTEST_FOLDER + SEP + "folder2", wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
     wxDir::Make(DIRTEST_FOLDER + SEP + "folder3" + SEP + "subfolder1", wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
     wxDir::Make(DIRTEST_FOLDER + SEP + "folder1" + SEP + "subfolder2", wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
     wxDir::Make(DIRTEST_FOLDER + SEP + "folder2", wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
     wxDir::Make(DIRTEST_FOLDER + SEP + "folder3" + SEP + "subfolder1", wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL);
-
+    
     CreateTempFile(DIRTEST_FOLDER + SEP + "folder1" + SEP + "subfolder2" + SEP + "dummy");
     CreateTempFile(DIRTEST_FOLDER + SEP + "dummy");
 }
     CreateTempFile(DIRTEST_FOLDER + SEP + "folder1" + SEP + "subfolder2" + SEP + "dummy");
     CreateTempFile(DIRTEST_FOLDER + SEP + "dummy");
 }
@@ -172,42 +173,45 @@ void DirTestCase::DirExists()
     {
         const char *dirname;
         bool shouldExist;
     {
         const char *dirname;
         bool shouldExist;
-    } testData[] =
+    } testData[] = 
     {
         { ".", true },
         { "..", true },
     {
         { ".", true },
         { "..", true },
+        { "$USER_DOCS_DIR", true },
 #if defined(__WXMSW__)
 #if defined(__WXMSW__)
+        { "$USER_DOCS_DIR\\", true },
+        { "$USER_DOCS_DIR\\\\", true },
         { "..\\..", true },
         { "..\\..", true },
-        { "..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..\\..", true },
         { "c:", true },
         { "c:\\", true },
         { "c:\\\\", true },
         { "c:", true },
         { "c:\\", true },
         { "c:\\\\", true },
-        { "\\\\share\\file", false },
+        { "\\\\non_existent_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 },
         { "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!
+        { "test.exe", false }            // not a directory!
 #elif defined(__UNIX__)
         { "../..", true },
 #elif defined(__UNIX__)
         { "../..", true },
-        { "../../../../../../../../../../../../../../../../../../../..", true },
         { "/", true },
         { "//", true },
         { "/usr/bin", true },
         { "/", 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
     };
 
     for ( size_t n = 0; n < WXSIZEOF(testData); n++ )
     {
 #endif
     };
 
     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());
+        
+        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()) );
     }
 
     CPPUNIT_ASSERT( wxDir::Exists(wxGetCwd()) );