X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fvchar.cc;h=4af110b40e800988eeac7854204f64eb0650d582;hb=4c1122cf139f7b073807f0a9187306518988a08f;hp=68646083377c1d739c49545181004203b352029e;hpb=381d409b224ca3b4510e770a98bc960084cdf2c4;p=awesomized%2Flibmemcached diff --git a/libtest/vchar.cc b/libtest/vchar.cc index 68646083..4af110b4 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -37,8 +37,24 @@ #include "libtest/yatlcon.h" #include +/* Use this for string generation */ +static const char ALPHANUMERICS[]= + "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz"; + +#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1) + +static size_t get_alpha_num(void) +{ + return (size_t)random() % ALPHANUMERICS_SIZE; +} + namespace libtest { +int random_alpha_num(void) +{ + return ALPHANUMERICS[get_alpha_num()]; +} + static std::string printer(const char *str, size_t length) { std::ostringstream buf; @@ -82,9 +98,24 @@ void make(libtest::vchar_t& arg) void make(libtest::vchar_t& arg, size_t length) { arg.reserve(length); - for (uint32_t x= 0; x < length; x++) + for (uint32_t x= 0; x < length; ++x) { - arg.push_back(char(x % 127)); + arg.push_back(ALPHANUMERICS[get_alpha_num()]); + } +} + +void chomp(libtest::vchar_t& arg) +{ + while(arg.size()) + { + if (arg.back() == 0) + { + arg.pop_back(); + } + else + { + break; + } } } @@ -95,12 +126,30 @@ void append(libtest::vchar_ptr_t& arg, const char* ptr) char* new_ptr= strdup(ptr); if (new_ptr == NULL) { - fatal_message("UNABLE to allocate %s(%p)", ptr, ptr); + FATAL("UNABLE to allocate %s(%p)", ptr, ptr); } + arg.push_back(new_ptr); } } +void append(libtest::vchar_t& arg, const char* ptr) +{ + if (ptr) + { + size_t length= strlen(ptr); + ASSERT_TRUE(length); + arg.reserve(length); + do + { + arg.push_back(*ptr); + ++ptr; + } while (*ptr); + + arg.push_back(0); + } +} + } // namespace vchar void make_vector(libtest::vchar_t& arg, const char *str, size_t length)