]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/SBufFindTest.h
Merged changes since Apr 2013 review
[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
32 } Placement; // placeLast marker must terminate
33 protected:
34
35 static SBuf RandomSBuf(const int length);
36 void nextLen(int &len, const int max);
37 void placeNeedle(const SBuf &cleanHay);
38
39 void testAllMethods();
40 void testFindDefs();
41 void testFind();
42 void testRFindDefs();
43 void testRFind();
44 void testFindCharDefs();
45 void testFindChar();
46 void testRFindCharDefs();
47 void testRFindChar();
48 void testFindFirstOf();
49
50 std::string posKey() const;
51 std::string placementKey() const;
52
53 bool resultsMatch() const;
54 void checkResults(const char *method);
55 void handleFailure(const char *method);
56
57 private:
58 /* test case parameters */
59 SBuf theSBufHay; ///< the string to be searched
60 SBuf theSBufNeedle; ///< the string to be found
61 SBuf::size_type thePos; ///< search position limit
62 Placement thePlacement; ///< where in the hay the needle is placed
63 std::string::size_type theStringPos; ///< thePos converted to std::string::size_type
64 std::string theStringHay; ///< theHay converted to std::string
65 std::string theStringNeedle; ///< theNeedle converted to std::string
66
67 /// needle pos w/o thePos restrictions; used for case categorization
68 std::string::size_type theBareNeedlePos;
69
70 /* test case results */
71 std::string::size_type theFindString;
72 SBuf::size_type theFindSBuf;
73 std::string theReportFunc;
74 std::string theReportNeedle;
75 std::string theReportPos;
76 char theReportQuote;
77
78 /* test progress indicators */
79 int caseCount; ///< cases executed so far
80 int errorCount; ///< total number of failed test cases so far
81 int reportCount; ///< total number of test cases reported so far
82 std::set<std::string> failedCats; ///< reported failed categories
83 };
84
85 typedef SBufFindTest::Placement Placement;
86
87 #endif