2 * Copyright (C) 1996-2017 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
12 #include "sbuf/SBuf.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 /// whether to report only one failed test case per "category"
31 /// approximate maximum generated hay string length
32 SBuf::size_type maxHayLength
;
34 /// Supported algorithms for placing needle in the hay.
35 typedef enum { placeBeginning
, placeMiddle
, placeEnd
, placeNowhere
,
37 } Placement
; // placeLast marker must terminate
40 static SBuf
RandomSBuf(const int length
);
41 void nextLen(SBuf::size_type
&len
, const SBuf::size_type max
);
42 void placeNeedle(const SBuf
&cleanHay
);
44 void testAllMethods();
49 void testFindCharDefs();
51 void testRFindCharDefs();
53 void testFindFirstOf();
55 std::string
posKey() const;
56 std::string
placementKey() const;
58 bool resultsMatch() const;
59 void checkResults(const char *method
);
60 void handleFailure(const char *method
);
63 /* test case parameters */
64 SBuf theSBufHay
; ///< the string to be searched
65 SBuf theSBufNeedle
; ///< the string to be found
66 SBuf::size_type thePos
; ///< search position limit
67 Placement thePlacement
; ///< where in the hay the needle is placed
68 std::string::size_type theStringPos
; ///< thePos converted to std::string::size_type
69 std::string theStringHay
; ///< theHay converted to std::string
70 std::string theStringNeedle
; ///< theNeedle converted to std::string
72 /// needle pos w/o thePos restrictions; used for case categorization
73 std::string::size_type theBareNeedlePos
;
75 /* test case results */
76 std::string::size_type theFindString
;
77 SBuf::size_type theFindSBuf
;
78 std::string theReportFunc
;
79 std::string theReportNeedle
;
80 std::string theReportPos
;
83 /* test progress indicators */
84 int caseCount
; ///< cases executed so far
85 int errorCount
; ///< total number of failed test cases so far
86 int reportCount
; ///< total number of test cases reported so far
87 std::set
<std::string
> failedCats
; ///< reported failed categories
90 typedef SBufFindTest::Placement Placement
;