]> git.ipfire.org Git - thirdparty/squid.git/blame - src/tests/SBufFindTest.h
Maintenance: automate header guards 2/3 (#1655)
[thirdparty/squid.git] / src / tests / SBufFindTest.h
CommitLineData
4e0938ef 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
4e0938ef
AJ
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
ff9d9458
FC
9#ifndef SQUID_SRC_TESTS_SBUFFINDTEST_H
10#define SQUID_SRC_TESTS_SBUFFINDTEST_H
412da427 11
65e41a45 12#include "sbuf/SBuf.h"
412da427 13
412da427 14#include <set>
074d6a40 15#include <string>
412da427
FC
16
17/// Generates and executes a [configurable] large number of SBuf::*find()
18/// test cases using random strings. Reports detected failures.
19class SBufFindTest
20{
21public:
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
412da427
FC
29 /// whether to report only one failed test case per "category"
30 bool hushSimilar;
31 /// approximate maximum generated hay string length
62842d40 32 SBuf::size_type maxHayLength;
412da427
FC
33
34 /// Supported algorithms for placing needle in the hay.
35 typedef enum { placeBeginning, placeMiddle, placeEnd, placeNowhere,
62842d40
FC
36 placeEof
37 } Placement; // placeLast marker must terminate
412da427
FC
38protected:
39
40 static SBuf RandomSBuf(const int length);
50827187 41 void nextLen(SBuf::size_type &len, const SBuf::size_type max);
412da427
FC
42 void placeNeedle(const SBuf &cleanHay);
43
44 void testAllMethods();
45 void testFindDefs();
46 void testFind();
47 void testRFindDefs();
48 void testRFind();
49 void testFindCharDefs();
50 void testFindChar();
51 void testRFindCharDefs();
52 void testRFindChar();
53 void testFindFirstOf();
54
55 std::string posKey() const;
56 std::string placementKey() const;
57
58 bool resultsMatch() const;
59 void checkResults(const char *method);
60 void handleFailure(const char *method);
61
62private:
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
412da427
FC
68 std::string theStringHay; ///< theHay converted to std::string
69 std::string theStringNeedle; ///< theNeedle converted to std::string
70
71 /// needle pos w/o thePos restrictions; used for case categorization
72 std::string::size_type theBareNeedlePos;
73
74 /* test case results */
75 std::string::size_type theFindString;
76 SBuf::size_type theFindSBuf;
77 std::string theReportFunc;
78 std::string theReportNeedle;
79 std::string theReportPos;
80 char theReportQuote;
81
82 /* test progress indicators */
83 int caseCount; ///< cases executed so far
84 int errorCount; ///< total number of failed test cases so far
85 int reportCount; ///< total number of test cases reported so far
86 std::set<std::string> failedCats; ///< reported failed categories
87};
88
89typedef SBufFindTest::Placement Placement;
90
ff9d9458 91#endif /* SQUID_SRC_TESTS_SBUFFINDTEST_H */
f53969cc 92