1
// Copyright 2009 The RE2 Authors. All Rights Reserved.
2
// Use of this source code is governed by a BSD-style
3
// license that can be found in the LICENSE file.
5
#ifndef RE2_TESTING_EXHAUSTIVE_TESTER_H__
6
#define RE2_TESTING_EXHAUSTIVE_TESTER_H__
10
#include "util/util.h"
11
#include "re2/testing/regexp_generator.h"
12
#include "re2/testing/string_generator.h"
16
// Exhaustive regular expression test: generate all regexps within parameters,
17
// then generate all strings of a given length over a given alphabet,
18
// then check that NFA, DFA, and PCRE agree about whether each regexp matches
19
// each possible string, and if so, where the match is.
21
// Can also be used in a "random" mode that generates a given number
22
// of random regexp and strings, allowing testing of larger expressions
24
class ExhaustiveTester : public RegexpGenerator {
26
ExhaustiveTester(int maxatoms,
28
const vector<string>& alphabet,
29
const vector<string>& ops,
31
const vector<string>& stralphabet,
32
const string& wrapper,
33
const string& topwrapper)
34
: RegexpGenerator(maxatoms, maxops, alphabet, ops),
35
strgen_(maxstrlen, stralphabet),
37
topwrapper_(topwrapper),
38
regexps_(0), tests_(0), failures_(0),
39
randomstrings_(0), stringseed_(0), stringcount_(0) { }
41
int regexps() { return regexps_; }
42
int tests() { return tests_; }
43
int failures() { return failures_; }
45
// Needed for RegexpGenerator interface.
46
void HandleRegexp(const string& regexp);
48
// Causes testing to generate random input strings.
49
void RandomStrings(int32 seed, int32 count) {
50
randomstrings_ = true;
56
StringGenerator strgen_;
57
string wrapper_; // Regexp wrapper - either empty or has one %s.
58
string topwrapper_; // Regexp top-level wrapper.
59
int regexps_; // Number of HandleRegexp calls
60
int tests_; // Number of regexp tests.
61
int failures_; // Number of tests failed.
63
bool randomstrings_; // Whether to use random strings
64
int32 stringseed_; // If so, the seed.
65
int stringcount_; // If so, how many to generate.
66
DISALLOW_EVIL_CONSTRUCTORS(ExhaustiveTester);
69
// Runs an exhaustive test on the given parameters.
70
void ExhaustiveTest(int maxatoms, int maxops,
71
const vector<string>& alphabet,
72
const vector<string>& ops,
73
int maxstrlen, const vector<string>& stralphabet,
74
const string& wrapper,
75
const string& topwrapper);
77
// Runs an exhaustive test using the given parameters and
78
// the basic egrep operators.
79
void EgrepTest(int maxatoms, int maxops, const string& alphabet,
80
int maxstrlen, const string& stralphabet,
81
const string& wrapper);
85
#endif // RE2_TESTING_EXHAUSTIVE_TESTER_H__