]> git.ipfire.org Git - thirdparty/squid.git/blob - src/tests/SBufFindTest.h
Simplified MSNT basic auth helper
[thirdparty/squid.git] / src / tests / SBufFindTest.h
1 /*
2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
3 *
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.
7 */
8
9 #ifndef SQUID_SRC_TEST_SBUFFINDTEST_H
10 #define SQUID_SRC_TEST_SBUFFINDTEST_H
11
12 #include "SBuf.h"
13
14 #include <set>
15 #include <string>
16
17 /// Generates and executes a [configurable] large number of SBuf::*find()
18 /// test cases using random strings. Reports detected failures.
19 class SBufFindTest
20 {
21 public:
22 SBufFindTest();
23
24 void run(); ///< generates and executes cases using configuration params
25
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"
31 bool hushSimilar;
32 /// approximate maximum generated hay string length
33 SBuf::size_type maxHayLength;
34
35 /// Supported algorithms for placing needle in the hay.
36 typedef enum { placeBeginning, placeMiddle, placeEnd, placeNowhere,
37 placeEof
38 } Placement; // placeLast marker must terminate
39 protected:
40
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);
44
45 void testAllMethods();
46 void testFindDefs();
47 void testFind();
48 void testRFindDefs();
49 void testRFind();
50 void testFindCharDefs();
51 void testFindChar();
52 void testRFindCharDefs();
53 void testRFindChar();
54 void testFindFirstOf();
55
56 std::string posKey() const;
57 std::string placementKey() const;
58
59 bool resultsMatch() const;
60 void checkResults(const char *method);
61 void handleFailure(const char *method);
62
63 private:
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
72
73 /// needle pos w/o thePos restrictions; used for case categorization
74 std::string::size_type theBareNeedlePos;
75
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;
82 char theReportQuote;
83
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
89 };
90
91 typedef SBufFindTest::Placement Placement;
92
93 #endif
94