SBufFindTest.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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/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);
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::size_type theStringPos;
69  std::string theStringHay;
70  std::string theStringNeedle;
71 
73  std::string::size_type theBareNeedlePos;
74 
75  /* test case results */
76  std::string::size_type theFindString;
78  std::string theReportFunc;
79  std::string theReportNeedle;
80  std::string theReportPos;
82 
83  /* test progress indicators */
84  int caseCount;
85  int errorCount;
87  std::set<std::string> failedCats;
88 };
89 
91 
92 #endif
93 
std::string theReportPos
Definition: SBufFindTest.h:80
SBuf::size_type thePos
search position limit
Definition: SBufFindTest.h:66
void run()
generates and executes cases using configuration params
Definition: SBufFindTest.cc:46
void handleFailure(const char *method)
called when a test case fails; counts and possibly reports the failure
Placement thePlacement
where in the hay the needle is placed
Definition: SBufFindTest.h:67
void testFindChar()
tests SBuf::find(char needle, pos)
Definition: SBuf.h:87
void testRFindDefs()
tests SBuf::rfind(string needle)
Definition: SBufFindTest.cc:93
void testFind()
tests SBuf::find(string needle, pos)
int reportCount
total number of test cases reported so far
Definition: SBufFindTest.h:86
SBuf theSBufHay
the string to be searched
Definition: SBufFindTest.h:64
std::string::size_type theFindString
Definition: SBufFindTest.h:76
A const & max(A const &lhs, A const &rhs)
void testRFindCharDefs()
tests SBuf::rfind(char needle)
static SBuf RandomSBuf(const int length)
generates a random string of the specified length
std::string placementKey() const
formats placement key (part of the case category string)
Placement
Supported algorithms for placing needle in the hay.
Definition: SBufFindTest.h:35
void testFindCharDefs()
tests SBuf::find(char needle)
SBuf::size_type theFindSBuf
Definition: SBufFindTest.h:77
void testFindDefs()
tests SBuf::find(string needle)
Definition: SBufFindTest.cc:84
std::string::size_type theBareNeedlePos
needle pos w/o thePos restrictions; used for case categorization
Definition: SBufFindTest.h:73
std::set< std::string > failedCats
reported failed categories
Definition: SBufFindTest.h:87
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
int caseLimit
approximate caseCount limit
Definition: SBufFindTest.h:27
std::string theStringHay
theHay converted to std::string
Definition: SBufFindTest.h:69
std::string theReportNeedle
Definition: SBufFindTest.h:79
void testRFind()
tests SBuf::rfind(string needle, pos)
std::string theStringNeedle
theNeedle converted to std::string
Definition: SBufFindTest.h:70
void testFindFirstOf()
tests SBuf::findFirstOf(string needle, pos)
void checkResults(const char *method)
called at the end of test case to update state, detect and report failures
size_t HttpReply *STUB StoreEntry const KeyScope scope const HttpRequestMethod & method
Definition: stub_store.cc:126
SBuf::size_type maxHayLength
approximate maximum generated hay string length
Definition: SBufFindTest.h:32
int errorCount
total number of failed test cases so far
Definition: SBufFindTest.h:85
void testAllMethods()
tests each supported SBuf::*find() method using generated hay, needle, pos
SBufFindTest::Placement Placement
Definition: SBufFindTest.h:90
std::string theReportFunc
Definition: SBufFindTest.h:78
void placeNeedle(const SBuf &cleanHay)
Places the needle into the hay using cleanHay as a starting point.
char theReportQuote
Definition: SBufFindTest.h:81
std::string::size_type theStringPos
thePos converted to std::string::size_type
Definition: SBufFindTest.h:68
void testRFindChar()
tests SBuf::rfind(char needle, pos)
int caseCount
cases executed so far
Definition: SBufFindTest.h:84
MemBlob::size_type size_type
Definition: SBuf.h:90
SBuf theSBufNeedle
the string to be found
Definition: SBufFindTest.h:65
void nextLen(SBuf::size_type &len, const SBuf::size_type max)
std::string posKey() const
formats position key (part of the case category string)
bool hushSimilar
whether to report only one failed test case per "category"
Definition: SBufFindTest.h:30
bool resultsMatch() const
whether the last SBuf and std::string find() results are the same

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors