14#include <cppunit/extensions/HelperMacros.h>
15#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;
196template<
typename Type>
198AnyToString(
const Type &value)
200 std::stringstream sbuf;
207PosToString(
const std::string::size_type pos)
209 return pos == std::string::npos ? std::string(
"npos") : AnyToString(pos);
219 const std::string reportPos = PosToString(
thePos);
253lengthKey(
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";
378 static std::uniform_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)
std::mt19937::result_type RandomSeed32()
optimized set of C chars, with quick membership test and merge support
int caseLimit
approximate caseCount limit
void handleFailure(const char *method)
std::string theStringHay
theHay converted to std::string
Placement
Supported algorithms for placing needle in the hay.
SBuf::size_type thePos
search position limit
int caseCount
cases executed so far
void checkResults(const char *method)
Placement thePlacement
where in the hay the needle is placed
std::string placementKey() const
std::string::size_type theBareNeedlePos
needle pos w/o thePos restrictions; used for case categorization
SBuf theSBufNeedle
the string to be found
void placeNeedle(const SBuf &cleanHay)
bool hushSimilar
whether to report only one failed test case per "category"
int errorCount
total number of failed test cases so far
std::string theReportNeedle
void nextLen(SBuf::size_type &len, const SBuf::size_type max)
SBuf::size_type theFindSBuf
std::string theStringNeedle
theNeedle converted to std::string
bool resultsMatch() const
std::string posKey() const
std::string::size_type theFindString
int reportCount
total number of test cases reported so far
void run()
generates and executes cases using configuration params
SBuf theSBufHay
the string to be searched
std::set< std::string > failedCats
reported failed categories
SBuf::size_type maxHayLength
approximate maximum generated hay string length
static SBuf RandomSBuf(const int length)
const char * rawContent() const
static const size_type npos
void reserveCapacity(size_type minCapacity)
size_type length() const
Returns the number of bytes stored in SBuf.
size_type rfind(char c, size_type endPos=npos) const
size_type find(char c, size_type startPos=0) const
size_type findFirstOf(const CharacterSet &set, size_type startPos=0) const
SBuf & append(const SBuf &S)
SBuf substr(size_type pos, size_type n=npos) const
MemBlob::size_type size_type
SBuf & assign(const SBuf &S)
A const & max(A const &lhs, A const &rhs)