diff options
| author | Oz Linden <oz@lindenlab.com> | 2010-10-29 16:52:54 -0400 | 
|---|---|---|
| committer | Oz Linden <oz@lindenlab.com> | 2010-10-29 16:52:54 -0400 | 
| commit | 2ab60cd988eba05ad6a3cfadb89c2cc5018f5885 (patch) | |
| tree | 80d61e51f9e9f9fdfc0dc38557fe550a9f3a1195 | |
| parent | a2bb621f3b74bdb49bf8b6fc3eb6141cf0d8b27a (diff) | |
factor directory scanning and results check out, and add some more tests for getNextFileInDir
--HG--
branch : storm-102
| -rw-r--r-- | indra/llvfs/lldir.h | 5 | ||||
| -rw-r--r-- | indra/llvfs/tests/lldir_test.cpp | 183 | 
2 files changed, 84 insertions, 104 deletions
| diff --git a/indra/llvfs/lldir.h b/indra/llvfs/lldir.h index 71743d960c..883e87a8fd 100644 --- a/indra/llvfs/lldir.h +++ b/indra/llvfs/lldir.h @@ -87,7 +87,10 @@ class LLDir       *       * This function may not be used to scan part of a directory, then start a new search of a different       * directory, and then restart the first search where it left off. -     * +     * @bug: this is known to fail at least on MacOS with patterns that have both: +     *       a wildcard left of the . and more than one sequential ? right of the . +     *       the pattern foo.??x appears to work +     *       but *.??x or foo?.??x do not       * @todo this really should be rewritten as an iterator object.       */ diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index dc446ccbe5..d76823b409 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -287,136 +287,113 @@ namespace tut        return uniqueDir + delim; // HACK - apparently, the trailing delimiter is needed...     } -   template<> template<> -   void LLDirTest_object_t::test<5>() -      // getNextFileInDir +   static const char* DirScanFilename[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" }; +    +   void scanTest(const std::string directory, const std::string pattern, bool correctResult[5])     { -      std::string delim = gDirUtilp->getDirDelimiter(); -      std::string dirTemp = LLFile::tmpdir(); -      // Create the same 5 file names of the two directories -      const char* filenames[5] = { "file1.abc", "file2.abc", "file1.xyz", "file2.xyz", "file1.mno" }; -      std::string dir1 = makeTestDir(dirTemp + "getNextFileInDir"); -      std::string dir2 = makeTestDir(dirTemp + "getNextFileInDir"); -      std::string dir1files[5]; -      std::string dir2files[5]; -      for (int i=0; i<5; i++) -      { -         dir1files[i] = makeTestFile(dir1, filenames[i]); -         dir2files[i] = makeTestFile(dir2, filenames[i]); -      } +      // Scan directory and see if any file1.* files are found +      std::string scanResult; +      int   found = 0; +      bool  filesFound[5] = { false, false, false, false, false }; +      std::cerr << "searching '"+directory+"' for '"+pattern+"'\n"; -      // Scan dir1 and see if each of the 5 files is found exactly once -      std::string scan1result; -      int   found1 = 0; -      bool  filesFound1[5] = { false, false, false, false, false }; -      // std::cerr << "searching '"+dir1+"' for *\n"; -      while ( found1 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*", scan1result) ) +      while ( found <= 5 && gDirUtilp->getNextFileInDir(directory, pattern, scanResult) )        { -         found1++; -         // std::cerr << "  found '"+scan1result+"'\n"; +         found++; +         std::cerr << "  found '"+scanResult+"'\n";           int check; -         for (check=0; check < 5 && ! ( scan1result == filenames[check] ); check++) +         for (check=0; check < 5 && ! ( scanResult == DirScanFilename[check] ); check++)           {           }           // check is now either 5 (not found) or the index of the matching name           if (check < 5)           { -            ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound1[check] ); -            filesFound1[check] = true; +            ensure( "found file '"+(std::string)DirScanFilename[check]+"' twice", ! filesFound[check] ); +            filesFound[check] = true;           } -         else +         else // check is 5 - should not happen           { -            ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); +            ensure( "found unknown file '"+(std::string)DirScanFilename[check]+"'", false);           }        } -      ensure("wrong number of files found in '"+dir1+"'", found1 == 5); - -      // Scan dir2 and see if only the 2 *.xyz files are found -      std::string scan2result; -      int   found2 = 0; -      bool  filesFound2[5] = { false, false, false, false, false }; -      // std::cerr << "searching '"+dir2+"' for *.xyz\n"; - -      while ( found2 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.xyz", scan2result) ) +      for (int i=0; i<5; i++)        { -         found2++; -         // std::cerr << "  found '"+scan2result+"'\n"; -         int check; -         for (check=0; check < 5 && ! ( scan2result == filenames[check] ); check++) +         if (correctResult[i])           { +            ensure("scan of '"+directory+"' using '"+pattern+"' did not return '"+DirScanFilename[i]+"'", filesFound[i]);           } -         // check is now either 5 (not found) or the index of the matching name -         if (check < 5) -         { -            ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound2[check] ); -            filesFound2[check] = true; -         } -         else // check is 5 - should not happen +         else           { -            ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); +            ensure("scan of '"+directory+"' using '"+pattern+"' incorrectly returned '"+DirScanFilename[i]+"'", !filesFound[i]);           }        } -      ensure("wrong files found in '"+dir2+"'", -             !filesFound2[0] && !filesFound2[1] && filesFound2[2] && filesFound2[3] && !filesFound2[4] ); - +   } +    +   template<> template<> +   void LLDirTest_object_t::test<5>() +      // getNextFileInDir +   { +      std::string delim = gDirUtilp->getDirDelimiter(); +      std::string dirTemp = LLFile::tmpdir(); -      // Scan dir2 and see if only the 1 *.mno file is found -      std::string scan3result; -      int   found3 = 0; -      bool  filesFound3[5] = { false, false, false, false, false }; -      // std::cerr << "searching '"+dir2+"' for *.mno\n"; +      // Create the same 5 file names of the two directories -      while ( found3 <= 5 && gDirUtilp->getNextFileInDir(dir2, "*.mno", scan3result) ) +      std::string dir1 = makeTestDir(dirTemp + "getNextFileInDir"); +      std::string dir2 = makeTestDir(dirTemp + "getNextFileInDir"); +      std::string dir1files[5]; +      std::string dir2files[5]; +      for (int i=0; i<5; i++)        { -         found3++; -         // std::cerr << "  found '"+scan3result+"'\n"; -         int check; -         for (check=0; check < 5 && ! ( scan3result == filenames[check] ); check++) -         { -         } -         // check is now either 5 (not found) or the index of the matching name -         if (check < 5) -         { -            ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound3[check] ); -            filesFound3[check] = true; -         } -         else // check is 5 - should not happen -         { -            ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); -         } +         dir1files[i] = makeTestFile(dir1, DirScanFilename[i]); +         dir2files[i] = makeTestFile(dir2, DirScanFilename[i]);        } -      ensure("wrong files found in '"+dir2+"'", -             !filesFound3[0] && !filesFound3[1] && !filesFound3[2] && !filesFound3[3] && filesFound3[4] ); +      // Scan dir1 and see if each of the 5 files is found exactly once +      bool expected1[5] = { true, true, true, true, true }; +      scanTest(dir1, "*", expected1); -      // Scan dir1 and see if any *.foo files are found -      std::string scan4result; -      int   found4 = 0; -      bool  filesFound4[5] = { false, false, false, false, false }; -      // std::cerr << "searching '"+dir1+"' for *.foo\n"; +      // Scan dir2 and see if only the 2 *.xyz files are found +      bool  expected2[5] = { false, false, true, true, false }; +      scanTest(dir1, "*.xyz", expected2); -      while ( found4 <= 5 && gDirUtilp->getNextFileInDir(dir1, "*.foo", scan4result) ) -      { -         found4++; -         // std::cerr << "  found '"+scan4result+"'\n"; -         int check; -         for (check=0; check < 5 && ! ( scan4result == filenames[check] ); check++) -         { -         } -         // check is now either 5 (not found) or the index of the matching name -         if (check < 5) -         { -            ensure( "found file '"+(std::string)filenames[check]+"' twice", ! filesFound4[check] ); -            filesFound4[check] = true; -         } -         else // check is 5 - should not happen -         { -            ensure( "found unknown file '"+(std::string)filenames[check]+"'", false); -         } -      } -      ensure("wrong files found in '"+dir1+"'", -             !filesFound4[0] && !filesFound4[1] && !filesFound4[2] && !filesFound4[3] && !filesFound4[4] ); +      // Scan dir2 and see if only the 1 *.mno file is found +      bool  expected3[5] = { false, false, false, false, true }; +      scanTest(dir2, "*.mno", expected3); + +      // Scan dir1 and see if any *.foo files are found +      bool  expected4[5] = { false, false, false, false, false }; +      scanTest(dir1, "*.foo", expected4); + +      // Scan dir1 and see if any file1.* files are found +      bool  expected5[5] = { true, false, true, false, true }; +      scanTest(dir1, "file1.*", expected5); + +      // Scan dir1 and see if any file1.* files are found +      bool  expected6[5] = { true, true, false, false, false }; +      scanTest(dir1, "file?.abc", expected6); + +      // Scan dir2 and see if any file?.x?z files are found +      bool  expected7[5] = { false, false, true, true, false }; +      scanTest(dir2, "file?.x?z", expected7); + +      // Scan dir2 and see if any file?.??c files are found - THESE FAIL AND SO ARE COMMENTED OUT FOR NOW +      //      bool  expected8[5] = { true, true, false, false, false }; +      //      scanTest(dir2, "file?.??c", expected8); +      //      bool  expected8[5] = { true, true, false, false, false }; +      //      scanTest(dir2, "*.??c", expected8); + +      // Scan dir1 and see if any *.?n? files are found +      bool  expected9[5] = { false, false, false, false, true }; +      scanTest(dir1, "*.?n?", expected9); + +      // Scan dir1 and see if any *.???? files are found +      bool  expected10[5] = { false, false, false, false, false }; +      scanTest(dir1, "*.????", expected10); + +      // Scan dir1 and see if any ?????.* files are found +      bool  expected11[5] = { true, true, true, true, true }; +      scanTest(dir1, "?????.*", expected11);        // clean up all test files and directories        for (int i=0; i<5; i++) | 
