1 #ifndef SQUID_SRC_TEST_SBUFFINDTEST_H
2 #define SQUID_SRC_TEST_SBUFFINDTEST_H
9 /// Generates and executes a [configurable] large number of SBuf::*find()
10 /// test cases using random strings. Reports detected failures.
16 void run(); ///< generates and executes cases using configuration params
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"
24 /// approximate maximum generated hay string length
25 SBuf::size_type maxHayLength
;
27 /// Supported algorithms for placing needle in the hay.
28 typedef enum { placeBeginning
, placeMiddle
, placeEnd
, placeNowhere
,
30 } Placement
; // placeLast marker must terminate
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
);
37 void testAllMethods();
42 void testFindCharDefs();
44 void testRFindCharDefs();
46 void testFindFirstOf();
48 std::string
posKey() const;
49 std::string
placementKey() const;
51 bool resultsMatch() const;
52 void checkResults(const char *method
);
53 void handleFailure(const char *method
);
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
65 /// needle pos w/o thePos restrictions; used for case categorization
66 std::string::size_type theBareNeedlePos
;
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
;
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
83 typedef SBufFindTest::Placement Placement
;