1 #ifndef SQUID_SRC_TEST_SBUFFINDTEST_H
2 #define SQUID_SRC_TEST_SBUFFINDTEST_H
11 /// Generates and executes a [configurable] large number of SBuf::*find()
12 /// test cases using random strings. Reports detected failures.
18 void run(); ///< generates and executes cases using configuration params
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"
26 /// approximate maximum generated hay string length
27 SBuf::size_type maxHayLength
;
29 /// Supported algorithms for placing needle in the hay.
30 typedef enum { placeBeginning
, placeMiddle
, placeEnd
, placeNowhere
,
32 } Placement
; // placeLast marker must terminate
35 static SBuf
RandomSBuf(const int length
);
36 void nextLen(int &len
, const int max
);
37 void placeNeedle(const SBuf
&cleanHay
);
39 void testAllMethods();
44 void testFindCharDefs();
46 void testRFindCharDefs();
48 void testFindFirstOf();
50 std::string
posKey() const;
51 std::string
placementKey() const;
53 bool resultsMatch() const;
54 void checkResults(const char *method
);
55 void handleFailure(const char *method
);
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
67 /// needle pos w/o thePos restrictions; used for case categorization
68 std::string::size_type theBareNeedlePos
;
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
;
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
85 typedef SBufFindTest::Placement Placement
;