2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_SRC_TEST_SBUFFINDTEST_H
10 #define SQUID_SRC_TEST_SBUFFINDTEST_H
17 /// Generates and executes a [configurable] large number of SBuf::*find()
18 /// test cases using random strings. Reports detected failures.
24 void run(); ///< generates and executes cases using configuration params
26 /* test configuration parameters; can be optionally set before run() */
27 int caseLimit
; ///< approximate caseCount limit
28 int errorLimit
; ///< errorCount limit
29 unsigned int randomSeed
; ///< pseudo-random sequence choice
30 /// whether to report only one failed test case per "category"
32 /// approximate maximum generated hay string length
33 SBuf::size_type maxHayLength
;
35 /// Supported algorithms for placing needle in the hay.
36 typedef enum { placeBeginning
, placeMiddle
, placeEnd
, placeNowhere
,
38 } Placement
; // placeLast marker must terminate
41 static SBuf
RandomSBuf(const int length
);
42 void nextLen(SBuf::size_type
&len
, const SBuf::size_type max
);
43 void placeNeedle(const SBuf
&cleanHay
);
45 void testAllMethods();
50 void testFindCharDefs();
52 void testRFindCharDefs();
54 void testFindFirstOf();
56 std::string
posKey() const;
57 std::string
placementKey() const;
59 bool resultsMatch() const;
60 void checkResults(const char *method
);
61 void handleFailure(const char *method
);
64 /* test case parameters */
65 SBuf theSBufHay
; ///< the string to be searched
66 SBuf theSBufNeedle
; ///< the string to be found
67 SBuf::size_type thePos
; ///< search position limit
68 Placement thePlacement
; ///< where in the hay the needle is placed
69 std::string::size_type theStringPos
; ///< thePos converted to std::string::size_type
70 std::string theStringHay
; ///< theHay converted to std::string
71 std::string theStringNeedle
; ///< theNeedle converted to std::string
73 /// needle pos w/o thePos restrictions; used for case categorization
74 std::string::size_type theBareNeedlePos
;
76 /* test case results */
77 std::string::size_type theFindString
;
78 SBuf::size_type theFindSBuf
;
79 std::string theReportFunc
;
80 std::string theReportNeedle
;
81 std::string theReportPos
;
84 /* test progress indicators */
85 int caseCount
; ///< cases executed so far
86 int errorCount
; ///< total number of failed test cases so far
87 int reportCount
; ///< total number of test cases reported so far
88 std::set
<std::string
> failedCats
; ///< reported failed categories
91 typedef SBufFindTest::Placement Placement
;