From 662bc0803cc9306062a0106467fd8b83290b4bcf Mon Sep 17 00:00:00 2001 From: Seth ProductEngine Date: Wed, 11 May 2011 18:12:48 +0300 Subject: STORM-477 Restored the backed out changeset: c9cc202293b7 --- indra/llvfs/tests/lldir_test.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'indra/llvfs/tests') diff --git a/indra/llvfs/tests/lldir_test.cpp b/indra/llvfs/tests/lldir_test.cpp index 8788bd63e8..ea321c5ae9 100644 --- a/indra/llvfs/tests/lldir_test.cpp +++ b/indra/llvfs/tests/lldir_test.cpp @@ -28,6 +28,7 @@ #include "linden_common.h" #include "../lldir.h" +#include "../lldiriterator.h" #include "../test/lltut.h" @@ -259,13 +260,12 @@ namespace tut std::string makeTestFile( const std::string& dir, const std::string& file ) { - std::string delim = gDirUtilp->getDirDelimiter(); - std::string path = dir + delim + file; + std::string path = dir + file; LLFILE* handle = LLFile::fopen( path, "w" ); ensure("failed to open test file '"+path+"'", handle != NULL ); // Harbison & Steele, 4th ed., p. 366: "If an error occurs, fputs // returns EOF; otherwise, it returns some other, nonnegative value." - ensure("failed to write to test file '"+path+"'", fputs("test file", handle) >= 0); + ensure("failed to write to test file '"+path+"'", EOF != fputs("test file", handle) ); fclose(handle); return path; } @@ -290,7 +290,7 @@ namespace tut } 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]) { @@ -300,7 +300,8 @@ namespace tut bool filesFound[5] = { false, false, false, false, false }; //std::cerr << "searching '"+directory+"' for '"+pattern+"'\n"; - while ( found <= 5 && gDirUtilp->getNextFileInDir(directory, pattern, scanResult) ) + LLDirIterator iter(directory, pattern); + while ( found <= 5 && iter.next(scanResult) ) { found++; //std::cerr << " found '"+scanResult+"'\n"; @@ -334,15 +335,15 @@ namespace tut template<> template<> void LLDirTest_object_t::test<5>() - // getNextFileInDir + // LLDirIterator::next { std::string delim = gDirUtilp->getDirDelimiter(); std::string dirTemp = LLFile::tmpdir(); // Create the same 5 file names of the two directories - std::string dir1 = makeTestDir(dirTemp + "getNextFileInDir"); - std::string dir2 = makeTestDir(dirTemp + "getNextFileInDir"); + std::string dir1 = makeTestDir(dirTemp + "LLDirIterator"); + std::string dir2 = makeTestDir(dirTemp + "LLDirIterator"); std::string dir1files[5]; std::string dir2files[5]; for (int i=0; i<5; i++) @@ -380,19 +381,17 @@ namespace tut scanTest(dir2, "file?.x?z", expected7); // Scan dir2 and see if any file?.??c files are found - // THESE FAIL ON Mac and Windows, SO ARE COMMENTED OUT FOR NOW - // bool expected8[5] = { true, true, false, false, false }; - // scanTest(dir2, "file?.??c", expected8); - // scanTest(dir2, "*.??c", expected8); + bool expected8[5] = { true, true, false, false, false }; + scanTest(dir2, "file?.??c", expected8); + 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 - // THIS ONE FAILS ON WINDOWS (returns three charater suffixes) SO IS COMMENTED OUT FOR NOW - // bool expected10[5] = { false, false, false, false, false }; - // scanTest(dir1, "*.????", expected10); + 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 }; @@ -402,6 +401,15 @@ namespace tut bool expected12[5] = { false, false, true, true, false }; scanTest(dir1, "??l??.xyz", expected12); + bool expected13[5] = { true, false, true, false, false }; + scanTest(dir1, "file1.{abc,xyz}", expected13); + + bool expected14[5] = { true, true, false, false, false }; + scanTest(dir1, "file[0-9].abc", expected14); + + bool expected15[5] = { true, true, false, false, false }; + scanTest(dir1, "file[!a-z].abc", expected15); + // clean up all test files and directories for (int i=0; i<5; i++) { -- cgit v1.2.3 From f86a488231dc9a629d44a9f6aa6bfc9aa0eb57b4 Mon Sep 17 00:00:00 2001 From: Squire Date: Fri, 17 Jun 2011 11:05:31 -0700 Subject: CHOP-662 - initial fix to problems with regex characters in Group names causing the LLDirIterator to crash the viewer when opening chat logs --- indra/llvfs/tests/lldiriterator_test.cpp | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 indra/llvfs/tests/lldiriterator_test.cpp (limited to 'indra/llvfs/tests') diff --git a/indra/llvfs/tests/lldiriterator_test.cpp b/indra/llvfs/tests/lldiriterator_test.cpp new file mode 100644 index 0000000000..7c2cd49e41 --- /dev/null +++ b/indra/llvfs/tests/lldiriterator_test.cpp @@ -0,0 +1,62 @@ +/** + * @file lldiriterator_test.cpp + * @date 2011-06 + * @brief LLDirIterator test cases. + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only., + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "linden_common.h" +#include "lltut.h" +#include "../lldiriterator.h" + + +namespace tut +{ + + struct LLDirIteratorFixture + { + LLDirIteratorFixture() + { + } + }; + typedef test_group LLDirIteratorTest_factory; + typedef LLDirIteratorTest_factory::object LLDirIteratorTest_t; + LLDirIteratorTest_factory tf("LLDirIterator"); + + /* + CHOP-662 was originally introduced to deal with crashes deleting files from + a directory (VWR-25500). However, this introduced a crash looking for + old chat logs as the glob_to_regex function in lldiriterator wasn't escaping lots of regexp characters + */ + void test_chop_662(void) + { + LLDirIterator iter(".","+bad-group-name]+??-??.*"); + } + + template<> template<> + void LLDirIteratorTest_t::test<1>() + { + test_chop_662(); + } + +} \ No newline at end of file -- cgit v1.2.3 From 29f1b466e66fd5a98926ac7318287c22f74e32bf Mon Sep 17 00:00:00 2001 From: Squire Date: Fri, 17 Jun 2011 14:13:01 -0700 Subject: COP-662 Added newline at end of file for Linux build --- indra/llvfs/tests/lldiriterator_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llvfs/tests') diff --git a/indra/llvfs/tests/lldiriterator_test.cpp b/indra/llvfs/tests/lldiriterator_test.cpp index 7c2cd49e41..0e7017f59f 100644 --- a/indra/llvfs/tests/lldiriterator_test.cpp +++ b/indra/llvfs/tests/lldiriterator_test.cpp @@ -59,4 +59,4 @@ namespace tut test_chop_662(); } -} \ No newline at end of file +} -- cgit v1.2.3 From 306759835d8aed3a041a59dafaa20a8c708e2dd4 Mon Sep 17 00:00:00 2001 From: Squire Date: Mon, 20 Jun 2011 11:07:17 -0700 Subject: Added more tests to cover the common examples in the crash logs --- indra/llvfs/tests/lldiriterator_test.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'indra/llvfs/tests') diff --git a/indra/llvfs/tests/lldiriterator_test.cpp b/indra/llvfs/tests/lldiriterator_test.cpp index 0e7017f59f..aacc5a616a 100644 --- a/indra/llvfs/tests/lldiriterator_test.cpp +++ b/indra/llvfs/tests/lldiriterator_test.cpp @@ -50,7 +50,10 @@ namespace tut */ void test_chop_662(void) { + // Check a selection of bad group names from the crash reports LLDirIterator iter(".","+bad-group-name]+??-??.*"); + LLDirIterator iter(".","))--@---bad-group-name2((??-??.*\.txt"); + LLDirIterator iter(".","__^v--x)Cuide d sua vida(x--v^__??-??.*"); } template<> template<> -- cgit v1.2.3 From f02dc7e1b6c26d897628617a870f250004febee0 Mon Sep 17 00:00:00 2001 From: Squire Date: Mon, 20 Jun 2011 12:17:25 -0700 Subject: CHOP-662 Coupl of fixes to extended unit-test --- indra/llvfs/tests/lldiriterator_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llvfs/tests') diff --git a/indra/llvfs/tests/lldiriterator_test.cpp b/indra/llvfs/tests/lldiriterator_test.cpp index aacc5a616a..505d86faa7 100644 --- a/indra/llvfs/tests/lldiriterator_test.cpp +++ b/indra/llvfs/tests/lldiriterator_test.cpp @@ -52,8 +52,8 @@ namespace tut { // Check a selection of bad group names from the crash reports LLDirIterator iter(".","+bad-group-name]+??-??.*"); - LLDirIterator iter(".","))--@---bad-group-name2((??-??.*\.txt"); - LLDirIterator iter(".","__^v--x)Cuide d sua vida(x--v^__??-??.*"); + LLDirIterator iter1(".","))--@---bad-group-name2((??-??.*\\.txt"); + LLDirIterator iter2(".","__^v--x)Cuide d sua vida(x--v^__??-??.*"); } template<> template<> -- cgit v1.2.3