summaryrefslogtreecommitdiff
path: root/pcrecpp_unittest.cc
diff options
context:
space:
mode:
authornigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:41:21 +0000
committernigel <nigel@2f5784b3-3f2a-0410-8824-cb99058d5e15>2007-02-24 21:41:21 +0000
commitced1f145fdf26ec7df4b9048a9da0ef17e9618f2 (patch)
tree371f88a16cfb5ac0a176622bcd424aa6c28c4cc8 /pcrecpp_unittest.cc
parent2550303b1f255c525d802f94d9c4411a0ccc630f (diff)
downloadpcre-ced1f145fdf26ec7df4b9048a9da0ef17e9618f2.tar.gz
Load pcre-6.5 into code/trunk.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@87 2f5784b3-3f2a-0410-8824-cb99058d5e15
Diffstat (limited to 'pcrecpp_unittest.cc')
-rw-r--r--pcrecpp_unittest.cc61
1 files changed, 40 insertions, 21 deletions
diff --git a/pcrecpp_unittest.cc b/pcrecpp_unittest.cc
index 6a03744..ba808bc 100644
--- a/pcrecpp_unittest.cc
+++ b/pcrecpp_unittest.cc
@@ -348,21 +348,46 @@ static void TestMatchNumberPeculiarity() {
CHECK_EQ(a, "");
}
-static void TestRecursion(int size, const char *pattern, int match_limit) {
+static void TestRecursion() {
printf("Testing recursion\n");
- // Fill up a string repeating the pattern given
- string domain;
- domain.resize(size);
- int patlen = strlen(pattern);
- for (int i = 0; i < size; ++i) {
- domain[i] = pattern[i % patlen];
- }
- // Just make sure it doesn't crash due to too much recursion.
- RE_Options options;
- options.set_match_limit(match_limit);
- RE re("([a-zA-Z0-9]|-)+(\\.([a-zA-Z0-9]|-)+)*(\\.)?", options);
- re.FullMatch(domain);
+ // Get one string that passes (sometimes), one that never does.
+ string text_good("abcdefghijk");
+ string text_bad("acdefghijkl");
+
+ // According to pcretest, matching text_good against (\w+)*b
+ // requires match_limit of at least 8192, and match_recursion_limit
+ // of at least 37.
+
+ RE_Options options_ml;
+ options_ml.set_match_limit(8192);
+ RE re("(\\w+)*b", options_ml);
+ CHECK(re.PartialMatch(text_good) == true);
+ CHECK(re.PartialMatch(text_bad) == false);
+ CHECK(re.FullMatch(text_good) == false);
+ CHECK(re.FullMatch(text_bad) == false);
+
+ options_ml.set_match_limit(1024);
+ RE re2("(\\w+)*b", options_ml);
+ CHECK(re2.PartialMatch(text_good) == false); // because of match_limit
+ CHECK(re2.PartialMatch(text_bad) == false);
+ CHECK(re2.FullMatch(text_good) == false);
+ CHECK(re2.FullMatch(text_bad) == false);
+
+ RE_Options options_mlr;
+ options_mlr.set_match_limit_recursion(50);
+ RE re3("(\\w+)*b", options_mlr);
+ CHECK(re3.PartialMatch(text_good) == true);
+ CHECK(re3.PartialMatch(text_bad) == false);
+ CHECK(re3.FullMatch(text_good) == false);
+ CHECK(re3.FullMatch(text_bad) == false);
+
+ options_mlr.set_match_limit_recursion(10);
+ RE re4("(\\w+)*b", options_mlr);
+ CHECK(re4.PartialMatch(text_good) == false);
+ CHECK(re4.PartialMatch(text_bad) == false);
+ CHECK(re4.FullMatch(text_good) == false);
+ CHECK(re4.FullMatch(text_bad) == false);
}
//
@@ -1021,14 +1046,8 @@ int main(int argc, char** argv) {
CHECK(!re.error().empty());
}
- // Test that recursion is stopped: there will be some errors reported
- int matchlimit = 5000;
- int bytes = 15 * 1024; // enough to crash if there was no match limit
- TestRecursion(bytes, ".", matchlimit);
- TestRecursion(bytes, "a", matchlimit);
- TestRecursion(bytes, "a.", matchlimit);
- TestRecursion(bytes, "ab.", matchlimit);
- TestRecursion(bytes, "abc.", matchlimit);
+ // Test that recursion is stopped
+ TestRecursion();
// Test Options
if (getenv("VERBOSE_TEST") != NULL)