X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fvchar.cc;h=9d2244b3c32c3646bf56d02893c3a42c135c8f14;hb=91ea3455ccf0cebaecbb2c0ee4ead073b6d86354;hp=fde0127f8d0da8fe2054e5eaf023383f60f1c893;hpb=47f45992107361ad58c170bdf78fdc92523fab06;p=awesomized%2Flibmemcached diff --git a/libtest/vchar.cc b/libtest/vchar.cc index fde0127f..9d2244b3 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -34,9 +34,20 @@ * */ -#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 { static std::string printer(const char *str, size_t length) @@ -81,9 +92,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(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) { - arg.push_back(char(x % 127)); + 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); } }