Go to the documentation of this file.
13 #include <cppunit/extensions/HelperMacros.h>
14 #include <cppunit/Message.h>
25 caseLimit(std::numeric_limits<
int>::
max()),
26 errorLimit(std::numeric_limits<
int>::
max()),
30 thePlacement(placeEof),
73 std::cerr <<
"Generated SBuf test cases: " <<
caseCount << std::endl;
74 std::cerr <<
"\tfailed cases: " <<
errorCount << std::endl;
75 std::cerr <<
"\treported cases: " <<
reportCount << std::endl;
76 std::cerr <<
"Asserting because some cases failed..." << std::endl;
196 template<
typename Type>
198 AnyToString(
const Type &value)
200 std::stringstream sbuf;
207 PosToString(
const std::string::size_type pos)
209 return pos == std::string::npos ? std::string(
"npos") : AnyToString(pos);
219 const std::string reportPos = PosToString(
thePos);
253 lengthKey(
const std::string &str)
255 if (str.length() == 0)
257 if (str.length() == 1)
268 return std::string();
300 return std::string();
315 std::cerr << std::endl;
320 std::cerr <<
"Will stop generating SBuf test cases because the " <<
321 "number of failed ones is over the limit: " <<
errorCount <<
322 " (after " <<
caseCount <<
" test cases)" << std::endl;
329 std::string category =
"hay" + lengthKey(
theStringHay) +
346 if (!reportPos.empty())
347 reportPos =
", " + reportPos;
349 std::cerr <<
"case" <<
caseCount <<
": " <<
352 reportPos <<
") returns " << PosToString(
theFindSBuf) <<
355 " std::string(\"" <<
theStringHay <<
"\")." << method <<
359 " category: " << category << std::endl;
368 static const char characters[] =
370 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
371 "abcdefghijklomnpqrstuvwxyz";
373 static std::mt19937 mt(time(0));
378 static xuniform_int_distribution<uint8_t> dist(0,
sizeof(characters)-2);
382 for (
int i = 0; i < length; ++i)
383 buf.
append(characters[dist(mt)]);
398 else if (len >=
max - 10)
bool hushSimilar
whether to report only one failed test case per "category"
int errorCount
total number of failed test cases so far
std::string::size_type theFindString
size_type find(char c, size_type startPos=0) const
SBuf & assign(const SBuf &S)
Placement thePlacement
where in the hay the needle is placed
void run()
generates and executes cases using configuration params
SBuf theSBufHay
the string to be searched
static SBuf RandomSBuf(const int length)
void nextLen(SBuf::size_type &len, const SBuf::size_type max)
std::string::size_type theBareNeedlePos
needle pos w/o thePos restrictions; used for case categorization
Placement
Supported algorithms for placing needle in the hay.
int caseCount
cases executed so far
std::string theStringHay
theHay converted to std::string
SBuf::size_type thePos
search position limit
std::string placementKey() const
SBuf substr(size_type pos, size_type n=npos) const
A const & max(A const &lhs, A const &rhs)
std::string posKey() const
size_type rfind(char c, size_type endPos=npos) const
int reportCount
total number of test cases reported so far
const char * rawContent() const
MemBlob::size_type size_type
std::string theStringNeedle
theNeedle converted to std::string
std::string theReportNeedle
SBuf::size_type theFindSBuf
void checkResults(const char *method)
size_type length() const
Returns the number of bytes stored in SBuf.
void placeNeedle(const SBuf &cleanHay)
SBuf & append(const SBuf &S)
static const size_type npos
int caseLimit
approximate caseCount limit
bool resultsMatch() const
void reserveCapacity(size_type minCapacity)
void handleFailure(const char *method)
std::set< std::string > failedCats
reported failed categories
optimized set of C chars, with quick membership test and merge support
SBuf::size_type maxHayLength
approximate maximum generated hay string length
size_type findFirstOf(const CharacterSet &set, size_type startPos=0) const
SBuf theSBufNeedle
the string to be found