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