SBufFindTest.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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_TESTS_SBUFFINDTEST_H
10 #define SQUID_SRC_TESTS_SBUFFINDTEST_H
11 
12 #include "sbuf/SBuf.h"
13 
14 #include <set>
15 #include <string>
16 
20 {
21 public:
22  SBufFindTest();
23 
24  void run();
25 
26  /* test configuration parameters; can be optionally set before run() */
27  int caseLimit;
28  int errorLimit;
29  bool hushSimilar;
33 
37  } Placement; // placeLast marker must terminate
38 protected:
39 
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);
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 
62 private:
63  /* test case parameters */
68  std::string theStringHay;
69  std::string theStringNeedle;
70 
72  std::string::size_type theBareNeedlePos;
73 
74  /* test case results */
75  std::string::size_type theFindString;
77  std::string theReportFunc;
78  std::string theReportNeedle;
79  std::string theReportPos;
81 
82  /* test progress indicators */
83  int caseCount;
84  int errorCount;
86  std::set<std::string> failedCats;
87 };
88 
90 
91 #endif /* SQUID_SRC_TESTS_SBUFFINDTEST_H */
92 
bool hushSimilar
whether to report only one failed test case per "category"
Definition: SBufFindTest.h:30
int errorCount
total number of failed test cases so far
Definition: SBufFindTest.h:84
std::string::size_type theFindString
Definition: SBufFindTest.h:75
void testRFindCharDefs()
void testAllMethods()
Placement thePlacement
where in the hay the needle is placed
Definition: SBufFindTest.h:67
void run()
generates and executes cases using configuration params
SBuf theSBufHay
the string to be searched
Definition: SBufFindTest.h:64
char theReportQuote
Definition: SBufFindTest.h:80
void testFindCharDefs()
static SBuf RandomSBuf(const int length)
void testFindChar()
void nextLen(SBuf::size_type &len, const SBuf::size_type max)
Definition: SBuf.h:93
std::string::size_type theBareNeedlePos
needle pos w/o thePos restrictions; used for case categorization
Definition: SBufFindTest.h:72
const A & max(A const &lhs, A const &rhs)
Placement
Supported algorithms for placing needle in the hay.
Definition: SBufFindTest.h:35
int caseCount
cases executed so far
Definition: SBufFindTest.h:83
std::string theStringHay
theHay converted to std::string
Definition: SBufFindTest.h:68
SBuf::size_type thePos
search position limit
Definition: SBufFindTest.h:66
std::string placementKey() const
void testFindDefs()
std::string posKey() const
std::string theReportPos
Definition: SBufFindTest.h:79
int reportCount
total number of test cases reported so far
Definition: SBufFindTest.h:85
void testRFindDefs()
MemBlob::size_type size_type
Definition: SBuf.h:96
std::string theStringNeedle
theNeedle converted to std::string
Definition: SBufFindTest.h:69
std::string theReportNeedle
Definition: SBufFindTest.h:78
SBuf::size_type theFindSBuf
Definition: SBufFindTest.h:76
std::string theReportFunc
Definition: SBufFindTest.h:77
void checkResults(const char *method)
void placeNeedle(const SBuf &cleanHay)
int caseLimit
approximate caseCount limit
Definition: SBufFindTest.h:27
void testFindFirstOf()
bool resultsMatch() const
void handleFailure(const char *method)
std::set< std::string > failedCats
reported failed categories
Definition: SBufFindTest.h:86
void testRFindChar()
void testRFind()
SBuf::size_type maxHayLength
approximate maximum generated hay string length
Definition: SBufFindTest.h:32
SBufFindTest::Placement Placement
Definition: SBufFindTest.h:89
void testFind()
SBuf theSBufNeedle
the string to be found
Definition: SBufFindTest.h:65

 

Introduction

Documentation

Support

Miscellaneous