bloaty/third_party/re2/re2/testing/exhaustive_tester.h
Go to the documentation of this file.
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.
4 
5 #ifndef RE2_TESTING_EXHAUSTIVE_TESTER_H_
6 #define RE2_TESTING_EXHAUSTIVE_TESTER_H_
7 
8 #include <stdint.h>
9 #include <string>
10 #include <vector>
11 
12 #include "util/util.h"
13 #include "re2/testing/regexp_generator.h"
14 #include "re2/testing/string_generator.h"
15 
16 namespace re2 {
17 
18 // Doing this simplifies the logic below.
19 #ifndef __has_feature
20 #define __has_feature(x) 0
21 #endif
22 
23 #if !defined(NDEBUG)
24 // We are in a debug build.
25 const bool RE2_DEBUG_MODE = true;
26 #elif __has_feature(address_sanitizer) || __has_feature(memory_sanitizer) || __has_feature(thread_sanitizer)
27 // Not a debug build, but still under sanitizers.
28 const bool RE2_DEBUG_MODE = true;
29 #else
30 const bool RE2_DEBUG_MODE = false;
31 #endif
32 
33 // Exhaustive regular expression test: generate all regexps within parameters,
34 // then generate all strings of a given length over a given alphabet,
35 // then check that NFA, DFA, and PCRE agree about whether each regexp matches
36 // each possible string, and if so, where the match is.
37 //
38 // Can also be used in a "random" mode that generates a given number
39 // of random regexp and strings, allowing testing of larger expressions
40 // and inputs.
42  public:
43  ExhaustiveTester(int maxatoms,
44  int maxops,
45  const std::vector<std::string>& alphabet,
46  const std::vector<std::string>& ops,
47  int maxstrlen,
48  const std::vector<std::string>& stralphabet,
49  const std::string& wrapper,
50  const std::string& topwrapper)
51  : RegexpGenerator(maxatoms, maxops, alphabet, ops),
52  strgen_(maxstrlen, stralphabet),
54  topwrapper_(topwrapper),
55  regexps_(0), tests_(0), failures_(0),
57 
58  int regexps() { return regexps_; }
59  int tests() { return tests_; }
60  int failures() { return failures_; }
61 
62  // Needed for RegexpGenerator interface.
63  void HandleRegexp(const std::string& regexp);
64 
65  // Causes testing to generate random input strings.
67  randomstrings_ = true;
68  stringseed_ = seed;
70  }
71 
72  private:
74  std::string wrapper_; // Regexp wrapper - either empty or has one %s.
75  std::string topwrapper_; // Regexp top-level wrapper.
76  int regexps_; // Number of HandleRegexp calls
77  int tests_; // Number of regexp tests.
78  int failures_; // Number of tests failed.
79 
80  bool randomstrings_; // Whether to use random strings
81  int32_t stringseed_; // If so, the seed.
82  int stringcount_; // If so, how many to generate.
83 
84  ExhaustiveTester(const ExhaustiveTester&) = delete;
86 };
87 
88 // Runs an exhaustive test on the given parameters.
89 void ExhaustiveTest(int maxatoms, int maxops,
90  const std::vector<std::string>& alphabet,
91  const std::vector<std::string>& ops,
92  int maxstrlen,
93  const std::vector<std::string>& stralphabet,
94  const std::string& wrapper,
95  const std::string& topwrapper);
96 
97 // Runs an exhaustive test using the given parameters and
98 // the basic egrep operators.
99 void EgrepTest(int maxatoms, int maxops, const std::string& alphabet,
100  int maxstrlen, const std::string& stralphabet,
101  const std::string& wrapper);
102 
103 } // namespace re2
104 
105 #endif // RE2_TESTING_EXHAUSTIVE_TESTER_H_
re2::ExhaustiveTester::tests_
int tests_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:77
re2::ExhaustiveTester::strgen_
StringGenerator strgen_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:73
seed
static const uint8_t seed[20]
Definition: dsa_test.cc:79
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
re2::ExhaustiveTester::stringseed_
int32_t stringseed_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:81
re2::ExhaustiveTest
void ExhaustiveTest(int maxatoms, int maxops, const std::vector< std::string > &alphabet, const std::vector< std::string > &ops, int maxstrlen, const std::vector< std::string > &stralphabet, const std::string &wrapper, const std::string &topwrapper)
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.cc:144
re2
Definition: bloaty/third_party/re2/re2/bitmap256.h:17
alphabet
static const char alphabet[]
Definition: bin_encoder.cc:30
re2::ExhaustiveTester::regexps
int regexps()
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:58
re2::ExhaustiveTester::ExhaustiveTester
ExhaustiveTester(int maxatoms, int maxops, const std::vector< std::string > &alphabet, const std::vector< std::string > &ops, int maxstrlen, const std::vector< std::string > &stralphabet, const std::string &wrapper, const std::string &topwrapper)
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:43
re2::ExhaustiveTester::operator=
ExhaustiveTester & operator=(const ExhaustiveTester &)=delete
re2::ExhaustiveTester::regexps_
int regexps_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:76
re2::EgrepTest
void EgrepTest(int maxatoms, int maxops, const std::string &alphabet, int maxstrlen, const std::string &stralphabet, const std::string &wrapper)
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.cc:172
wrapper
grpc_channel_wrapper * wrapper
Definition: src/php/ext/grpc/channel.h:48
re2::ExhaustiveTester::failures
int failures()
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:60
stdint.h
re2::RE2_DEBUG_MODE
const bool RE2_DEBUG_MODE
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:25
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
re2::ExhaustiveTester::HandleRegexp
void HandleRegexp(const std::string &regexp)
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.cc:76
re2::ExhaustiveTester::tests
int tests()
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:59
re2::RegexpGenerator
Definition: bloaty/third_party/re2/re2/testing/regexp_generator.h:30
re2::ExhaustiveTester
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:41
re2::ExhaustiveTester::stringcount_
int stringcount_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:82
re2::ExhaustiveTester::RandomStrings
void RandomStrings(int32_t seed, int32_t count)
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:66
int32_t
signed int int32_t
Definition: stdint-msvc2008.h:77
re2::ExhaustiveTester::randomstrings_
bool randomstrings_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:80
ops
static grpc_op ops[6]
Definition: test/core/fling/client.cc:39
re2::ExhaustiveTester::wrapper_
std::string wrapper_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:74
re2::ExhaustiveTester::topwrapper_
std::string topwrapper_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:75
re2::ExhaustiveTester::failures_
int failures_
Definition: bloaty/third_party/re2/re2/testing/exhaustive_tester.h:78
re2::StringGenerator
Definition: bloaty/third_party/re2/re2/testing/string_generator.h:22


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:20