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
,
31 placeEof
} Placement
; // placeLast marker must terminate
34 static SBuf
RandomSBuf(const int length
);
35 void nextLen(int &len
, const int max
);
36 void placeNeedle(const SBuf
&cleanHay
);
38 void testAllMethods();
43 void testFindCharDefs();
45 void testRFindCharDefs();
47 void testFindFirstOf();
49 std::string
posKey() const;
50 std::string
placementKey() const;
52 bool resultsMatch() const;
53 void checkResults(const char *method
);
54 void handleFailure(const char *method
);
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
66 /// needle pos w/o thePos restrictions; used for case categorization
67 std::string::size_type theBareNeedlePos
;
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
;
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
84 typedef SBufFindTest::Placement Placement
;