X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Fvchar.cc;h=a4bddfdeda098eb8aa9d0523b90b3ad1f65114a0;hb=b220134a312e2a488810abfef510f5dbf59078a4;hp=1473509fa1383abd3bf996a7c5db46a86633953e;hpb=ad5cb8f903869065c72bb18bf98af6909189a5a9;p=awesomized%2Flibmemcached diff --git a/libtest/vchar.cc b/libtest/vchar.cc index 1473509f..a4bddfde 100644 --- a/libtest/vchar.cc +++ b/libtest/vchar.cc @@ -34,11 +34,27 @@ * */ -#include "mem_config.h" +#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,55 @@ 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; + } + } +} + +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); } } @@ -98,7 +160,7 @@ void make_vector(libtest::vchar_t& arg, const char *str, size_t length) std::ostream& operator<<(std::ostream& output, const libtest::vchar_t& arg) { - std::string tmp= libtest::printer(&arg[0], arg.size()); + std::string tmp= libtest::printer(arg.data(), arg.size()); output << tmp << "[" << arg.size() << "]"; return output;