X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fvchar.cc;h=4af110b40e800988eeac7854204f64eb0650d582;hb=00ce081cdb5bcb602d6303dcf691d981ec8926e0;hp=fde0127f8d0da8fe2054e5eaf023383f60f1c893;hpb=47f45992107361ad58c170bdf78fdc92523fab06;p=awesomized%2Flibmemcached diff --git a/libtest/vchar.cc b/libtest/vchar.cc index fde0127f..4af110b4 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -34,11 +34,27 @@ * */ -#include +#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; @@ -81,9 +97,56 @@ void make(libtest::vchar_t& arg) void make(libtest::vchar_t& arg, size_t length) { - for (uint32_t x= 0; x < length; x++) + arg.reserve(length); + 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; + } + } +} + +void append(libtest::vchar_ptr_t& arg, const char* ptr) +{ + if (ptr) + { + char* new_ptr= strdup(ptr); + if (new_ptr == NULL) + { + 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); } }