]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/SBufFindTest.h
merge from trunk
[thirdparty/squid.git] / src / tests / SBufFindTest.h
1 #ifndef SQUID_SRC_TEST_SBUFFINDTEST_H
2 #define SQUID_SRC_TEST_SBUFFINDTEST_H
3
4 #include "SBuf.h"
5
6 #include <set>
7 #include <string>
8
9 /// Generates and executes a [configurable] large number of SBuf::*find()
10 /// test cases using random strings. Reports detected failures.
11 class SBufFindTest
12 {
13 public:
14 SBufFindTest();
15
16 void run(); ///< generates and executes cases using configuration params
17
18 /* test configuration parameters; can be optionally set before run() */
19 int caseLimit; ///< approximate caseCount limit
20 int errorLimit; ///< errorCount limit
21 unsigned int randomSeed; ///< pseudo-random sequence choice
22 /// whether to report only one failed test case per "category"
23 bool hushSimilar;
24 /// approximate maximum generated hay string length
25 SBuf::size_type maxHayLength;
26
27 /// Supported algorithms for placing needle in the hay.
28 typedef enum { placeBeginning, placeMiddle, placeEnd, placeNowhere,
29 placeEof
30 } Placement; // placeLast marker must terminate
31 protected:
32
33 static SBuf RandomSBuf(const int length);
34 void nextLen(SBuf::size_type &len, const SBuf::size_type max);
35 void placeNeedle(const SBuf &cleanHay);
36
37 void testAllMethods();
38 void testFindDefs();
39 void testFind();
40 void testRFindDefs();
41 void testRFind();
42 void testFindCharDefs();
43 void testFindChar();
44 void testRFindCharDefs();
45 void testRFindChar();
46 void testFindFirstOf();
47
48 std::string posKey() const;
49 std::string placementKey() const;
50
51 bool resultsMatch() const;
52 void checkResults(const char *method);
53 void handleFailure(const char *method);
54
55 private:
56 /* test case parameters */
57 SBuf theSBufHay; ///< the string to be searched
58 SBuf theSBufNeedle; ///< the string to be found
59 SBuf::size_type thePos; ///< search position limit
60 Placement thePlacement; ///< where in the hay the needle is placed
61 std::string::size_type theStringPos; ///< thePos converted to std::string::size_type
62 std::string theStringHay; ///< theHay converted to std::string
63 std::string theStringNeedle; ///< theNeedle converted to std::string
64
65 /// needle pos w/o thePos restrictions; used for case categorization
66 std::string::size_type theBareNeedlePos;
67
68 /* test case results */
69 std::string::size_type theFindString;
70 SBuf::size_type theFindSBuf;
71 std::string theReportFunc;
72 std::string theReportNeedle;
73 std::string theReportPos;
74 char theReportQuote;
75
76 /* test progress indicators */
77 int caseCount; ///< cases executed so far
78 int errorCount; ///< total number of failed test cases so far
79 int reportCount; ///< total number of test cases reported so far
80 std::set<std::string> failedCats; ///< reported failed categories
81 };
82
83 typedef SBufFindTest::Placement Placement;
84
85 #endif