Update all of libtest around runner.
[m6w6/libmemcached] / tests / libmemcached-1.0 / mem_functions.cc
index 7f8342da029b31f4e8dacacba883d4a5fcf8c34a..5c0ada030325a56324fa00811b8d9e5f12d5d276 100644 (file)
@@ -52,7 +52,6 @@
 
 #include <libhashkit-1.0/hashkit.h>
 
-#include <cassert>
 #include <cerrno>
 #include <memory>
 #include <pthread.h>
@@ -88,123 +87,22 @@ using namespace libtest;
 
 #define UUID_STRING_MAXLENGTH 36
 
-struct keys_st {
-public:
-  keys_st(size_t arg)
-  {
-    init(arg, UUID_STRING_MAXLENGTH);
-  }
-
-  keys_st(size_t arg, size_t padding)
-  {
-    init(arg, padding);
-  }
-
-  void init(size_t arg, size_t padding)
-  {
-    _lengths.resize(arg);
-    _keys.resize(arg);
-
-    for (size_t x= 0; x < _keys.size(); x++)
-    {
-      libtest::vchar_t key_buffer;
-      key_buffer.resize(padding +1);
-      memset(&key_buffer[0], 'x', padding);
-
-      if (HAVE_LIBUUID)
-      {
-#if defined(HAVE_LIBUUID) && HAVE_LIBUUID
-        uuid_t out;
-        uuid_generate(out);
+#include "tests/keys.hpp"
 
-        uuid_unparse(out, &key_buffer[0]);
-        _keys[x]= strdup(&key_buffer[0]);
-        (_keys[x])[UUID_STRING_MAXLENGTH]= 'x';
-#endif
-      }
-      else // We just use a number and pad the string if UUID is not available
-      {
-        char int_buffer[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
-        int key_length= snprintf(int_buffer, sizeof(int_buffer), "%u", uint32_t(x));
-        memcpy(&key_buffer[0], int_buffer, key_length);
-        _keys[x]= strdup(&key_buffer[0]);
-      }
-      _lengths[x]= padding;
-    }
-  }
-
-  ~keys_st()
+static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options)
+{
+  /*
+    If no options are given, copy over at least the binary flag.
+  */
+  char options_buffer[1024]= { 0 };
+  if (options == NULL)
   {
-    for (libtest::vchar_ptr_t::iterator iter= _keys.begin();
-         iter != _keys.end();
-         iter++)
+    if (memcached_is_binary(original_memc))
     {
-      ::free(*iter);
+      snprintf(options_buffer, sizeof(options_buffer), "--BINARY");
     }
   }
 
-  libtest::vchar_ptr_t::iterator begin()
-  {
-    return _keys.begin();
-  }
-
-  libtest::vchar_ptr_t::iterator end()
-  {
-    return _keys.end();
-  }
-
-  size_t size() const
-  {
-    return _keys.size();
-  }
-
-  std::vector<size_t>& lengths()
-  {
-    return _lengths;
-  }
-
-  libtest::vchar_ptr_t& keys()
-  {
-    return _keys;
-  }
-
-  size_t* lengths_ptr()
-  {
-    return &_lengths[0];
-  }
-
-  char** keys_ptr()
-  {
-    return &_keys[0];
-  }
-
-  char* key_at(size_t arg)
-  {
-    return _keys[arg];
-  }
-
-  size_t length_at(size_t arg)
-  {
-    return _lengths[arg];
-  }
-
-private:
-    libtest::vchar_ptr_t _keys;
-    std::vector<size_t> _lengths;
-};
-
-static memcached_return_t return_value_based_on_buffering(memcached_st *memc)
-{
-  if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS))
-  {
-    return MEMCACHED_BUFFERED;
-  }
-
-  return MEMCACHED_SUCCESS;
-}
-
-static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options)
-{
   /*
    * I only want to hit _one_ server so I know the number of requests I'm
    * sending in the pipeline.
@@ -246,10 +144,10 @@ static memcached_st * create_single_instance_memcached(const memcached_st *origi
     return NULL;
   }
 
-  char buffer[1024];
-  if (memcached_failed(libmemcached_check_configuration(server_string, server_string_length, buffer, sizeof(buffer))))
+  char errror_buffer[1024];
+  if (memcached_failed(libmemcached_check_configuration(server_string, server_string_length, errror_buffer, sizeof(errror_buffer))))
   {
-    Error << "Failed to parse (" << server_string << ") " << buffer;
+    Error << "Failed to parse (" << server_string << ") " << errror_buffer;
     return NULL;
   }
 
@@ -278,7 +176,7 @@ static memcached_return_t server_display_function(const memcached_st *ptr,
   /* Do Nothing */
   size_t bigger= *((size_t *)(context));
   (void)ptr;
-  assert(bigger <= memcached_server_port(server));
+  fatal_assert(bigger <= memcached_server_port(server));
   *((size_t *)(context))= memcached_server_port(server);
 
   return MEMCACHED_SUCCESS;
@@ -619,7 +517,7 @@ test_return_t set_test(memcached_st *memc)
                                        test_literal_param("foo"),
                                        test_literal_param("when we sanitize"),
                                        time_t(0), (uint32_t)0);
-  test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc));
+  test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_last_error_message(memc));
 
   return TEST_SUCCESS;
 }
@@ -714,11 +612,12 @@ test_return_t memcached_mget_mixed_memcached_get_TEST(memcached_st *memc)
        iter != keys.end(); 
        iter++)
   {
-    test_compare(MEMCACHED_SUCCESS,
-                 memcached_set(memc,
-                               (*iter), 36,
-                               NULL, 0,
-                               time_t(0), uint32_t(0)));
+    test_compare_hint(MEMCACHED_SUCCESS,
+                      memcached_set(memc,
+                                    (*iter), 36,
+                                    NULL, 0,
+                                    time_t(0), uint32_t(0)),
+                      memcached_last_error_message(memc));
   }
 
   for (ptrdiff_t loop= 0; loop < 20; loop++)
@@ -737,7 +636,7 @@ test_return_t memcached_mget_mixed_memcached_get_TEST(memcached_st *memc)
       {
         result_count++;
       }
-      test_compare(keys.size(), result_count);
+      test_true(keys.size() >= result_count);
     }
     else
     {
@@ -747,7 +646,12 @@ test_return_t memcached_mget_mixed_memcached_get_TEST(memcached_st *memc)
       memcached_return_t rc;
       char *out_value= memcached_get(memc, keys.key_at(which_key), keys.length_at(which_key),
                                      &value_length, &flags, &rc);
-      test_compare(MEMCACHED_SUCCESS, rc);
+      if (rc == MEMCACHED_NOTFOUND)
+      { } // It is possible that the value has been purged.
+      else
+      {
+        test_compare_hint(MEMCACHED_SUCCESS, rc, memcached_last_error_message(memc));
+      }
       test_null(out_value);
       test_zero(value_length);
       test_zero(flags);
@@ -946,28 +850,31 @@ test_return_t add_wrapper(memcached_st *memc)
 
 test_return_t replace_test(memcached_st *memc)
 {
-  test_compare(return_value_based_on_buffering(memc),
-               memcached_set(memc,
-                             test_literal_param(__func__),
-                             test_literal_param("when we sanitize"),
-                             time_t(0), uint32_t(0)));
+  test_compare_hint(return_value_based_on_buffering(memc),
+                    memcached_set(memc,
+                                  test_literal_param(__func__),
+                                  test_literal_param("when we sanitize"),
+                                  time_t(0), uint32_t(0)),
+                    memcached_last_error_message(memc));
 
-  test_compare(MEMCACHED_SUCCESS,
-               memcached_replace(memc,
-                                 test_literal_param(__func__),
-                                 test_literal_param("first we insert some data"),
-                                 time_t(0), uint32_t(0)));
+  test_compare_hint(MEMCACHED_SUCCESS,
+                    memcached_replace(memc,
+                                      test_literal_param(__func__),
+                                      test_literal_param("first we insert some data"),
+                                      time_t(0), uint32_t(0)),
+                    memcached_last_error_message(memc));
 
   return TEST_SUCCESS;
 }
 
 test_return_t delete_test(memcached_st *memc)
 {
-  test_compare(return_value_based_on_buffering(memc), 
-               memcached_set(memc, 
-                             test_literal_param(__func__),
-                             test_literal_param("when we sanitize"),
-                             time_t(0), uint32_t(0)));
+  test_compare_hint(return_value_based_on_buffering(memc), 
+                    memcached_set(memc, 
+                                  test_literal_param(__func__),
+                                  test_literal_param("when we sanitize"),
+                                  time_t(0), uint32_t(0)),
+                    memcached_last_error_message(memc));
 
   test_compare_hint(return_value_based_on_buffering(memc),
                     memcached_delete(memc, 
@@ -1124,7 +1031,7 @@ static memcached_return_t read_through_trigger(memcached_st *memc,
                                                size_t key_length,
                                                memcached_result_st *result)
 {
-   (void)memc;(void)key;(void)key_length;
+  (void)memc;(void)key;(void)key_length;
   return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE));
 }
 
@@ -1174,74 +1081,16 @@ test_return_t read_through(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-test_return_t get_test(memcached_st *memc)
-{
-  memcached_return_t rc;
-  char *string;
-  size_t string_length;
-  uint32_t flags;
-
-  uint64_t query_id= memcached_query_id(memc);
-  rc= memcached_delete(memc,
-                       test_literal_param(__func__),
-                       time_t(0));
-  test_true_got(rc == MEMCACHED_BUFFERED or rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc));
-  test_compare(query_id +1, memcached_query_id(memc));
-
-  string= memcached_get(memc,
-                        test_literal_param(__func__),
-                        &string_length, &flags, &rc);
-
-  test_compare_got(MEMCACHED_NOTFOUND, rc, memcached_strerror(NULL, rc));
-  test_false(string_length);
-  test_false(string);
-
-  return TEST_SUCCESS;
-}
-
-test_return_t get_test2(memcached_st *memc)
-{
-  const char *value= "when we sanitize";
-
-  uint64_t query_id= memcached_query_id(memc);
-  test_compare(return_value_based_on_buffering(memc),
-               memcached_set(memc,
-                             test_literal_param(__func__),
-                             value, strlen(value),
-                             time_t(0), uint32_t(0)));
-  test_compare(query_id +1, memcached_query_id(memc));
-
-  query_id= memcached_query_id(memc);
-  test_true(query_id);
-
-  uint32_t flags;
-  size_t string_length;
-  memcached_return_t rc;
-  char *string= memcached_get(memc,
-                              test_literal_param(__func__),
-                              &string_length, &flags, &rc);
-  test_compare(query_id +1, memcached_query_id(memc));
-
-  test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
-  test_compare_got(MEMCACHED_SUCCESS, memcached_last_error(memc), memcached_last_error_message(memc));
-  test_true(string);
-  test_compare(strlen(value), string_length);
-  test_memcmp(string, value, string_length);
-
-  free(string);
-
-  return TEST_SUCCESS;
-}
-
 test_return_t set_test2(memcached_st *memc)
 {
   for (uint32_t x= 0; x < 10; x++)
   {
-    test_compare(return_value_based_on_buffering(memc),
-                 memcached_set(memc,
-                               test_literal_param("foo"),
-                               test_literal_param("train in the brain"),
-                               time_t(0), uint32_t(0)));
+    test_compare_hint(return_value_based_on_buffering(memc),
+                      memcached_set(memc,
+                                    test_literal_param("foo"),
+                                    test_literal_param("train in the brain"),
+                                    time_t(0), uint32_t(0)),
+                      memcached_last_error_message(memc));
   }
 
   return TEST_SUCCESS;
@@ -1277,126 +1126,6 @@ test_return_t set_test3(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-test_return_t get_test3(memcached_st *memc)
-{
-  size_t value_length= 8191;
-
-  libtest::vchar_t value;
-  value.reserve(value_length);
-  for (uint32_t x= 0; x < value_length; x++)
-  {
-    value.push_back(char(x % 127));
-  }
-
-  test_compare_hint(return_value_based_on_buffering(memc),
-                    memcached_set(memc,
-                                  test_literal_param(__func__),
-                                  &value[0], value.size(),
-                                  time_t(0), uint32_t(0)),
-                    memcached_last_error_message(memc));
-
-  size_t string_length;
-  uint32_t flags;
-  memcached_return_t rc;
-  char *string= memcached_get(memc,
-                              test_literal_param(__func__),
-                              &string_length, &flags, &rc);
-
-  test_compare(MEMCACHED_SUCCESS, rc);
-  test_true(string);
-  test_compare(value.size(), string_length);
-  test_memcmp(string, &value[0], string_length);
-
-  free(string);
-
-  return TEST_SUCCESS;
-}
-
-test_return_t get_test4(memcached_st *memc)
-{
-  size_t value_length= 8191;
-
-  libtest::vchar_t value;
-  value.reserve(value_length);
-  for (uint32_t x= 0; x < value_length; x++)
-  {
-    value.push_back(char(x % 127));
-  }
-
-  test_compare_hint(return_value_based_on_buffering(memc),
-                    memcached_set(memc,
-                                  test_literal_param(__func__),
-                                  &value[0], value.size(),
-                                  time_t(0), uint32_t(0)),
-                    memcached_last_error_message(memc));
-
-  for (uint32_t x= 0; x < 10; x++)
-  {
-    uint32_t flags;
-    size_t string_length;
-    memcached_return_t rc;
-    char *string= memcached_get(memc,
-                                test_literal_param(__func__),
-                                &string_length, &flags, &rc);
-
-    test_compare(MEMCACHED_SUCCESS, rc);
-    test_true(string);
-    test_compare(value.size(), string_length);
-    test_memcmp(string, &value[0], string_length);
-    free(string);
-  }
-
-  return TEST_SUCCESS;
-}
-
-/*
- * This test verifies that memcached_read_one_response doesn't try to
- * dereference a NIL-pointer if you issue a multi-get and don't read out all
- * responses before you execute a storage command.
- */
-test_return_t get_test5(memcached_st *memc)
-{
-  /*
-  ** Request the same key twice, to ensure that we hash to the same server
-  ** (so that we have multiple response values queued up) ;-)
-  */
-  const char *keys[]= { "key", "key" };
-  size_t lengths[]= { 3, 3 };
-  uint32_t flags;
-  size_t rlen;
-
-  test_compare_hint(return_value_based_on_buffering(memc),
-                    memcached_set(memc, keys[0], lengths[0],
-                                  keys[0], lengths[0],
-                                  time_t(0), uint32_t(0)),
-                    memcached_last_error_message(memc));
-  test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, lengths, test_array_length(keys)));
-
-  memcached_result_st results_obj;
-  memcached_result_st *results= memcached_result_create(memc, &results_obj);
-  test_true(results);
-
-  memcached_return_t rc;
-  results= memcached_fetch_result(memc, &results_obj, &rc);
-  test_true(results);
-
-  memcached_result_free(&results_obj);
-
-  /* Don't read out the second result, but issue a set instead.. */
-  test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[0], lengths[0], keys[0], lengths[0], 0, 0));
-
-  char *val= memcached_get_by_key(memc, keys[0], lengths[0], "yek", 3,
-                                  &rlen, &flags, &rc);
-  test_false(val);
-  test_compare(MEMCACHED_NOTFOUND, rc);
-  val= memcached_get(memc, keys[0], lengths[0], &rlen, &flags, &rc);
-  test_true(val);
-  test_compare(MEMCACHED_SUCCESS, rc);
-  free(val);
-
-  return TEST_SUCCESS;
-}
-
 test_return_t mget_end(memcached_st *memc)
 {
   const char *keys[]= { "foo", "foo2" };
@@ -1716,18 +1445,20 @@ test_return_t quit_test(memcached_st *memc)
 {
   const char *value= "sanford and sun";
 
-  test_compare(return_value_based_on_buffering(memc),
-               memcached_set(memc,
-                             test_literal_param(__func__),
-                             value, strlen(value),
-                             (time_t)10, (uint32_t)3));
+  test_compare_hint(return_value_based_on_buffering(memc),
+                    memcached_set(memc,
+                                  test_literal_param(__func__),
+                                  value, strlen(value),
+                                  (time_t)10, (uint32_t)3),
+                    memcached_last_error_message(memc));
   memcached_quit(memc);
 
-  test_compare(return_value_based_on_buffering(memc),
-               memcached_set(memc,
-                             test_literal_param(__func__),
-                             value, strlen(value),
-                             (time_t)50, (uint32_t)9));
+  test_compare_hint(return_value_based_on_buffering(memc),
+                    memcached_set(memc,
+                                  test_literal_param(__func__),
+                                  value, strlen(value),
+                                  (time_t)50, (uint32_t)9),
+                    memcached_last_error_message(memc));
 
   return TEST_SUCCESS;
 }
@@ -1940,7 +1671,7 @@ test_return_t mget_execute(memcached_st *original_memc)
                                          blob, sizeof(blob),
                                          0, 0);
     test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED,
-                  memcached_strerror(NULL, rc));
+                  memcached_last_error_message(memc));
     test_compare(query_id +1, memcached_query_id(memc));
   }
 
@@ -1968,7 +1699,7 @@ test_return_t mget_execute(memcached_st *original_memc)
 }
 
 #define REGRESSION_BINARY_VS_BLOCK_COUNT  20480
-static pairs_st *global_pairs;
+static pairs_st *global_pairs= NULL;
 
 test_return_t key_setup(memcached_st *memc)
 {
@@ -1982,6 +1713,7 @@ test_return_t key_setup(memcached_st *memc)
 test_return_t key_teardown(memcached_st *)
 {
   pairs_free(global_pairs);
+  global_pairs= NULL;
 
   return TEST_SUCCESS;
 }
@@ -1991,9 +1723,14 @@ test_return_t block_add_regression(memcached_st *memc)
   /* First add all of the items.. */
   for (ptrdiff_t x= 0; x < REGRESSION_BINARY_VS_BLOCK_COUNT; ++x)
   {
-    char blob[1024] = {0};
+    libtest::vchar_t blob;
+    libtest::vchar::make(blob, 1024);
 
-    memcached_return_t rc= memcached_add_by_key(memc, "bob", 3, global_pairs[x].key, global_pairs[x].key_length, blob, sizeof(blob), 0, 0);
+    memcached_return_t rc= memcached_add_by_key(memc,
+                                                test_literal_param("bob"),
+                                                global_pairs[x].key, global_pairs[x].key_length,
+                                                &blob[0], blob.size(),
+                                                time_t(0), uint32_t(0));
     test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE, memcached_strerror(NULL, rc));
   }
 
@@ -2706,7 +2443,7 @@ test_return_t user_supplied_bug14(memcached_st *memc)
     value.push_back((char) (x % 127));
   }
 
-  for (size_t current_length= 0; current_length < value.size(); current_length++)
+  for (size_t current_length= 1; current_length < value.size(); current_length++)
   {
     memcached_return_t rc= memcached_set(memc, test_literal_param("foo"),
                                          &value[0], current_length,
@@ -2720,7 +2457,9 @@ test_return_t user_supplied_bug14(memcached_st *memc)
 
     test_compare(MEMCACHED_SUCCESS, rc);
     test_compare(string_length, current_length);
-    test_memcmp(string, &value[0], string_length);
+    char buffer[1024];
+    snprintf(buffer, sizeof(buffer), "%u", uint32_t(string_length));
+    test_memcmp_hint(string, &value[0], string_length, buffer);
 
     free(string);
   }
@@ -2873,7 +2612,7 @@ test_return_t user_supplied_bug20(memcached_st *memc)
 /* sighandler_t function that always asserts false */
 static void fail(int)
 {
-  assert(0);
+  fatal_assert(0);
 }
 
 
@@ -3473,7 +3212,12 @@ test_return_t noreply_test(memcached_st *memc)
       uint32_t flags;
       char* value=memcached_get(memc, key, strlen(key),
                                 &length, &flags, &ret);
-      test_true_got(ret == MEMCACHED_SUCCESS && value != NULL, memcached_strerror(NULL, ret));
+      // For the moment we will just go to the next key
+      if (MEMCACHED_TIMEOUT == ret)
+      {
+        continue;
+      }
+      test_true_hint(ret == MEMCACHED_SUCCESS and value != NULL, memcached_last_error_message(memc));
       switch (count)
       {
       case 0: /* FALLTHROUGH */
@@ -3953,7 +3697,6 @@ test_return_t memcached_get_hashkit_test (memcached_st *)
 */
 test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *)
 {
-  const char *key= "MemcachedLives";
   size_t len;
   uint32_t flags;
   memcached_return rc;
@@ -3962,7 +3705,9 @@ test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *)
   memcached_st *tl_memc_h= memcached(test_literal_param("--server=localhost:9898 --server=localhost:9899")); // This server should not exist
 
   // See if memcached is reachable.
-  char *value= memcached_get(tl_memc_h, key, strlen(key), &len, &flags, &rc);
+  char *value= memcached_get(tl_memc_h, 
+                             test_literal_param(__func__),
+                             &len, &flags, &rc);
 
   test_false(value);
   test_zero(len);
@@ -3978,13 +3723,14 @@ test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *)
 */
 test_return_t memcached_get_MEMCACHED_NOTFOUND(memcached_st *memc)
 {
-  const char *key= "MemcachedKeyNotEXIST";
   size_t len;
   uint32_t flags;
   memcached_return rc;
 
   // See if memcached is reachable.
-  char *value= memcached_get(memc, key, strlen(key), &len, &flags, &rc);
+  char *value= memcached_get(memc,
+                             test_literal_param(__func__),
+                             &len, &flags, &rc);
 
   test_false(value);
   test_zero(len);
@@ -3999,26 +3745,23 @@ test_return_t memcached_get_MEMCACHED_NOTFOUND(memcached_st *memc)
   We are testing the error condition when we connect to a server via memcached_get_by_key()
   but find that the server is not available.
 */
-test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *memc)
+test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *)
 {
-  (void)memc;
-  memcached_st *tl_memc_h;
-  memcached_server_st *servers;
-
-  const char *key= "MemcachedLives";
   size_t len;
   uint32_t flags;
   memcached_return rc;
-  char *value;
 
   // Create a handle.
-  tl_memc_h= memcached_create(NULL);
-  servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
+  memcached_st *tl_memc_h= memcached_create(NULL);
+  memcached_server_st *servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
   memcached_server_push(tl_memc_h, servers);
   memcached_server_list_free(servers);
 
   // See if memcached is reachable.
-  value= memcached_get_by_key(tl_memc_h, key, strlen(key), key, strlen(key), &len, &flags, &rc);
+  char *value= memcached_get_by_key(tl_memc_h, 
+                                    test_literal_param(__func__), // Key
+                                    test_literal_param(__func__), // Value
+                                    &len, &flags, &rc);
 
   test_false(value);
   test_zero(len);
@@ -4034,14 +3777,15 @@ test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *memc)
 */
 test_return_t memcached_get_by_key_MEMCACHED_NOTFOUND(memcached_st *memc)
 {
-  const char *key= "MemcachedKeyNotEXIST";
   size_t len;
   uint32_t flags;
   memcached_return rc;
-  char *value;
 
   // See if memcached is reachable.
-  value= memcached_get_by_key(memc, key, strlen(key), key, strlen(key), &len, &flags, &rc);
+  char *value= memcached_get_by_key(memc, 
+                                    test_literal_param(__func__), // Key
+                                    test_literal_param(__func__), // Value
+                                    &len, &flags, &rc);
 
   test_false(value);
   test_zero(len);
@@ -4054,18 +3798,18 @@ test_return_t regression_bug_434484(memcached_st *memc)
 {
   test_skip(TEST_SUCCESS, pre_binary(memc));
 
-  const char *key= "regression_bug_434484";
-  size_t keylen= strlen(key);
-
-  memcached_return_t ret= memcached_append(memc, key, keylen, key, keylen, 0, 0);
-  test_compare(MEMCACHED_NOTSTORED, ret);
+  test_compare(MEMCACHED_NOTSTORED, 
+               memcached_append(memc, 
+                                test_literal_param(__func__), // Key
+                                test_literal_param(__func__), // Value
+                                0, 0));
 
-  size_t size= 2048 * 1024;
-  char *data= (char*)calloc(1, size);
-  test_true(data);
+  libtest::vchar_t data;
+  data.resize(2048 * 1024);
   test_compare(MEMCACHED_E2BIG,
-               memcached_set(memc, key, keylen, data, size, 0, 0));
-  free(data);
+               memcached_set(memc, 
+                             test_literal_param(__func__), // Key
+                             &data[0], data.size(), 0, 0));
 
   return TEST_SUCCESS;
 }
@@ -4086,27 +3830,16 @@ test_return_t regression_bug_434843(memcached_st *original_memc)
  */
   memcached_st *memc= create_single_instance_memcached(original_memc, "--BINARY-PROTOCOL");
 
-  const size_t max_keys= 1024;
-  char **keys= (char**)calloc(max_keys, sizeof(char*));
-  size_t *key_length= (size_t *)calloc(max_keys, sizeof(size_t));
-
-  for (size_t x= 0; x < max_keys; ++x)
-  {
-    char k[251];
-
-    key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%lu", (unsigned long)x);
-    keys[x]= strdup(k);
-    test_true(keys[x]);
-  }
+  keys_st keys(1024);
 
   /*
    * Run two times.. the first time we should have 100% cache miss,
    * and the second time we should have 100% cache hits
  */
-  for (size_t y= 0; y < 2; y++)
+  for (ptrdiff_t y= 0; y < 2; y++)
   {
     test_compare(MEMCACHED_SUCCESS,
-                 memcached_mget(memc, (const char**)keys, key_length, max_keys));
+                 memcached_mget(memc, keys.keys_ptr(), keys.lengths_ptr(), keys.size()));
 
     // One the first run we should get a NOT_FOUND, but on the second some data
     // should be returned.
@@ -4120,9 +3853,10 @@ test_return_t regression_bug_434843(memcached_st *original_memc)
 
       test_false(counter);
 
-      for (size_t x= 0; x < max_keys; ++x)
+      for (size_t x= 0; x < keys.size(); ++x)
       {
-        rc= memcached_add(memc, keys[x], key_length[x],
+        rc= memcached_add(memc, 
+                          keys.key_at(x), keys.length_at(x),
                           blob, sizeof(blob), 0, 0);
         test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
       }
@@ -4130,18 +3864,10 @@ test_return_t regression_bug_434843(memcached_st *original_memc)
     else
     {
       /* Verify that we received all of the key/value pairs */
-      test_compare(counter, max_keys);
+      test_compare(counter, keys.size());
     }
   }
 
-  /* Release allocated resources */
-  for (size_t x= 0; x < max_keys; ++x)
-  {
-    free(keys[x]);
-  }
-  free(keys);
-  free(key_length);
-
   memcached_free(memc);
 
   return TEST_SUCCESS;
@@ -4149,9 +3875,7 @@ test_return_t regression_bug_434843(memcached_st *original_memc)
 
 test_return_t regression_bug_434843_buffered(memcached_st *memc)
 {
-  memcached_return_t rc;
-  rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
-  test_compare(MEMCACHED_SUCCESS, rc);
+  test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true));
 
   return regression_bug_434843(memc);
 }
@@ -4202,42 +3926,40 @@ test_return_t regression_bug_421108(memcached_st *memc)
  * delete command or the watermarks, we need to update this
  * test....
  */
-test_return_t regression_bug_442914(memcached_st *memc)
+test_return_t regression_bug_442914(memcached_st *original_memc)
 {
-  test_skip(MEMCACHED_SUCCESS,  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1));
-  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
+  test_skip(original_memc->servers[0].type, MEMCACHED_CONNECTION_TCP);
 
-  uint32_t number_of_hosts= memcached_server_count(memc);
-  memc->number_of_hosts= 1;
-
-  char k[250];
-  size_t len;
+  memcached_st* memc= create_single_instance_memcached(original_memc, "--NOREPLY --TCP-NODELAY");
 
   for (uint32_t x= 0; x < 250; ++x)
   {
-    len= (size_t)snprintf(k, sizeof(k), "%0250u", x);
-    memcached_return_t rc= memcached_delete(memc, k, len, 0);
-    test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_last_error_message(memc));
+    char key[250];
+    size_t len= (size_t)snprintf(key, sizeof(key), "%0250u", x);
+    memcached_return_t rc= memcached_delete(memc, key, len, 0);
+    char error_buffer[2048]= { 0 };
+    snprintf(error_buffer, sizeof(error_buffer), "%s key: %s", memcached_last_error_message(memc), key);
+    test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, error_buffer);
   }
 
-  len= snprintf(k, sizeof(k), "%037u", 251U);
-
-  memcached_return_t rc= memcached_delete(memc, k, len, 0);
-  test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+  // Delete, and then delete again to look for not found
+  {
+    char key[250];
+    size_t len= snprintf(key, sizeof(key), "%037u", 251U);
+    memcached_return_t rc= memcached_delete(memc, key, len, 0);
+    test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
 
-  test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0));
-  test_compare(MEMCACHED_NOTFOUND, memcached_delete(memc, k, len, 0));
+    test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, false));
+    test_compare(MEMCACHED_NOTFOUND, memcached_delete(memc, key, len, 0));
+  }
 
-  memc->number_of_hosts= number_of_hosts;
+  memcached_free(memc);
 
   return TEST_SUCCESS;
 }
 
 test_return_t regression_bug_447342(memcached_st *memc)
 {
-  memcached_server_instance_st instance_one;
-  memcached_server_instance_st instance_two;
-
   if (memcached_server_count(memc) < 3 or pre_replication(memc) != TEST_SUCCESS)
   {
     return TEST_SKIPPED;
@@ -4246,19 +3968,15 @@ test_return_t regression_bug_447342(memcached_st *memc)
   test_compare(MEMCACHED_SUCCESS,
                memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 2));
 
-  const unsigned int max_keys= 100;
-  char **keys= (char**)calloc(max_keys, sizeof(char*));
-  size_t *key_length= (size_t *)calloc(max_keys, sizeof(size_t));
+  keys_st keys(100);
 
-  for (unsigned int x= 0; x < max_keys; ++x)
+  for (size_t x= 0; x < keys.size(); ++x)
   {
-    char k[251];
-
-    key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%lu", (unsigned long)x);
-    keys[x]= strdup(k);
-    test_true(keys[x]);
     test_compare(MEMCACHED_SUCCESS,
-                 memcached_set(memc, k, key_length[x], k, key_length[x], 0, 0));
+                 memcached_set(memc, 
+                               keys.key_at(x), keys.length_at(x), // Keys
+                               keys.key_at(x), keys.length_at(x), // Values
+                               0, 0));
   }
 
   /*
@@ -4280,7 +3998,8 @@ test_return_t regression_bug_447342(memcached_st *memc)
    * into the servers
  */
   test_compare(MEMCACHED_SUCCESS,
-               memcached_mget(memc, (const char* const *)keys, key_length, max_keys));
+               memcached_mget(memc, 
+                              keys.keys_ptr(), keys.lengths_ptr(), keys.size()));
 
   unsigned int counter= 0;
   memcached_execute_fn callbacks[]= { &callback_counter };
@@ -4288,7 +4007,7 @@ test_return_t regression_bug_447342(memcached_st *memc)
                memcached_fetch_execute(memc, callbacks, (void *)&counter, 1));
 
   /* Verify that we received all of the key/value pairs */
-  test_compare(counter, max_keys);
+  test_compare(counter, keys.size());
 
   memcached_quit(memc);
   /*
@@ -4297,8 +4016,8 @@ test_return_t regression_bug_447342(memcached_st *memc)
    * This is to verify correct behavior in the library. Fake that two servers
    * are dead..
  */
-  instance_one= memcached_server_instance_by_position(memc, 0);
-  instance_two= memcached_server_instance_by_position(memc, 2);
+  memcached_server_instance_st instance_one= memcached_server_instance_by_position(memc, 0);
+  memcached_server_instance_st instance_two= memcached_server_instance_by_position(memc, 2);
   in_port_t port0= instance_one->port;
   in_port_t port2= instance_two->port;
 
@@ -4306,12 +4025,13 @@ test_return_t regression_bug_447342(memcached_st *memc)
   ((memcached_server_write_instance_st)instance_two)->port= 0;
 
   test_compare(MEMCACHED_SUCCESS,
-               memcached_mget(memc, (const char* const *)keys, key_length, max_keys));
+               memcached_mget(memc, 
+                              keys.keys_ptr(), keys.lengths_ptr(), keys.size()));
 
   counter= 0;
   test_compare(MEMCACHED_SUCCESS, 
                memcached_fetch_execute(memc, callbacks, (void *)&counter, 1));
-  test_compare(counter, (unsigned int)max_keys);
+  test_compare(counter, keys.size());
 
   /* restore the memc handle */
   ((memcached_server_write_instance_st)instance_one)->port= port0;
@@ -4320,12 +4040,12 @@ test_return_t regression_bug_447342(memcached_st *memc)
   memcached_quit(memc);
 
   /* Remove half of the objects */
-  for (size_t x= 0; x < max_keys; ++x)
+  for (size_t x= 0; x < keys.size(); ++x)
   {
     if (x & 1)
     {
       test_compare(MEMCACHED_SUCCESS,
-                   memcached_delete(memc, keys[x], key_length[x], 0));
+                   memcached_delete(memc, keys.key_at(x), keys.length_at(x), 0));
     }
   }
 
@@ -4335,20 +4055,13 @@ test_return_t regression_bug_447342(memcached_st *memc)
 
   /* now retry the command, this time we should have cache misses */
   test_compare(MEMCACHED_SUCCESS,
-               memcached_mget(memc, (const char* const *)keys, key_length, max_keys));
+               memcached_mget(memc,
+                              keys.keys_ptr(), keys.lengths_ptr(), keys.size()));
 
   counter= 0;
   test_compare(MEMCACHED_SUCCESS, 
                memcached_fetch_execute(memc, callbacks, (void *)&counter, 1));
-  test_compare(counter, (unsigned int)(max_keys >> 1));
-
-  /* Release allocated resources */
-  for (size_t x= 0; x < max_keys; ++x)
-  {
-    free(keys[x]);
-  }
-  free(keys);
-  free(key_length);
+  test_compare(counter, (unsigned int)(keys.size() >> 1));
 
   /* restore the memc handle */
   ((memcached_server_write_instance_st)instance_one)->port= port0;
@@ -4559,31 +4272,20 @@ test_return_t memcached_stat_execute_test(memcached_st *memc)
  * This test ensures that the failure counter isn't incremented during
  * normal termination of the memcached instance.
  */
-test_return_t wrong_failure_counter_test(memcached_st *memc)
+test_return_t wrong_failure_counter_test(memcached_st *original_memc)
 {
-  memcached_return_t rc;
-  memcached_server_instance_st instance;
-
-  /* Set value to force connection to the server */
-  const char *key= "marmotte";
-  const char *value= "milka";
-
-  /*
-   * Please note that I'm abusing the internal structures in libmemcached
-   * in a non-portable way and you shouldn't be doing this. I'm only
-   * doing this in order to verify that the library works the way it should
- */
-  uint32_t number_of_hosts= memcached_server_count(memc);
-  memc->number_of_hosts= 1;
+  memcached_st* memc= create_single_instance_memcached(original_memc, NULL);
 
   /* Ensure that we are connected to the server by setting a value */
-  rc= memcached_set(memc, key, strlen(key),
-                    value, strlen(value),
-                    (time_t)0, (uint32_t)0);
+  memcached_return_t rc= memcached_set(memc,
+                                       test_literal_param(__func__), // Key
+                                       test_literal_param(__func__), // Value
+                                       time_t(0), uint32_t(0));
   test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED);
 
 
-  instance= memcached_server_instance_by_position(memc, 0);
+  memcached_server_instance_st instance= memcached_server_instance_by_position(memc, 0);
+
   /* The test is to see that the memcached_quit doesn't increase the
    * the server failure conter, so let's ensure that it is zero
    * before sending quit
@@ -4598,8 +4300,7 @@ test_return_t wrong_failure_counter_test(memcached_st *memc)
  */
   test_zero(instance->server_failure_counter);
 
-  /* restore the instance */
-  memc->number_of_hosts= number_of_hosts;
+  memcached_free(memc);
 
   return TEST_SUCCESS;
 }
@@ -4668,20 +4369,15 @@ test_return_t regression_bug_490486(memcached_st *original_memc)
   memcached_st *memc= create_single_instance_memcached(original_memc, "--BINARY-PROTOCOL --POLL-TIMEOUT=1000 --REMOVE-FAILED-SERVERS=1 --RETRY-TIMEOUT=3600");
   test_true(memc);
 
-  size_t max_keys= 20480;
-
-  char **keys= (char **)calloc(max_keys, sizeof(char*));
-  size_t *key_length= (size_t *)calloc(max_keys, sizeof(size_t));
+  keys_st keys(20480);
 
   /* First add all of the items.. */
   char blob[1024]= { 0 };
-  for (size_t x= 0; x < max_keys; ++x)
+  for (size_t x= 0; x < keys.size(); ++x)
   {
-    char k[251];
-    key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%lu", (unsigned long)x);
-    keys[x]= strdup(k);
-    test_true(keys[x]);
-    memcached_return rc= memcached_set(memc, keys[x], key_length[x], blob, sizeof(blob), 0, 0);
+    memcached_return rc= memcached_set(memc,
+                                       keys.key_at(x), keys.length_at(x),
+                                       blob, sizeof(blob), 0, 0);
     test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); // MEMCACHED_TIMEOUT <-- hash been observed on OSX
   }
 
@@ -4690,8 +4386,9 @@ test_return_t regression_bug_490486(memcached_st *original_memc)
     /* Try to get all of them with a large multiget */
     size_t counter= 0;
     memcached_execute_function callbacks[]= { &callback_counter };
-    memcached_return_t rc= memcached_mget_execute(memc, (const char**)keys, key_length,
-                                                  (size_t)max_keys, callbacks, &counter, 1);
+    memcached_return_t rc= memcached_mget_execute(memc,
+                                                  keys.keys_ptr(), keys.lengths_ptr(), keys.size(),
+                                                  callbacks, &counter, 1);
     test_compare(MEMCACHED_SUCCESS, rc);
 
     char* the_value= NULL;
@@ -4715,17 +4412,9 @@ test_return_t regression_bug_490486(memcached_st *original_memc)
     test_compare(MEMCACHED_END, rc);
 
     /* Verify that we got all of the items */
-    test_compare(counter, max_keys);
+    test_compare(counter, keys.size());
   }
 
-  /* Release all allocated resources */
-  for (size_t x= 0; x < max_keys; ++x)
-  {
-    free(keys[x]);
-  }
-  free(keys);
-  free(key_length);
-
   memcached_free(memc);
 
   return TEST_SUCCESS;
@@ -4790,22 +4479,24 @@ test_return_t regression_bug_655423(memcached_st *memc)
 
   memset(payload, int('x'), sizeof(payload));
 
-  for (uint32_t x= 0; x < regression_bug_655423_COUNT; x++)
-  {
-    char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
-    snprintf(key, sizeof(key), "%u", x);
+  keys_st keys(regression_bug_655423_COUNT);
 
-    test_compare(MEMCACHED_SUCCESS, memcached_set(clone, key, strlen(key), payload, sizeof(payload), 0, 0));
+  for (size_t x= 0; x < keys.size(); x++)
+  {
+    test_compare(MEMCACHED_SUCCESS, memcached_set(clone, 
+                                                  keys.key_at(x),
+                                                  keys.length_at(x),
+                                                  payload, sizeof(payload), 0, 0));
   }
 
-  for (uint32_t x= 0; x < regression_bug_655423_COUNT; x++)
+  for (size_t x= 0; x < keys.size(); x++)
   {
-    char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
-    snprintf(key, sizeof(key), "%u", x);
-
     size_t value_length;
     memcached_return_t rc;
-    char *value= memcached_get(clone, key, strlen(key), &value_length, NULL, &rc);
+    char *value= memcached_get(clone,
+                               keys.key_at(x),
+                               keys.length_at(x),
+                               &value_length, NULL, &rc);
 
     if (rc == MEMCACHED_NOTFOUND)
     {
@@ -4820,21 +4511,10 @@ test_return_t regression_bug_655423(memcached_st *memc)
     free(value);
   }
 
-  char **keys= (char**)calloc(regression_bug_655423_COUNT, sizeof(char*));
-  size_t *key_length= (size_t *)calloc(regression_bug_655423_COUNT, sizeof(size_t));
-  for (uint32_t x= 0; x < regression_bug_655423_COUNT; x++)
-  {
-    char key[MEMCACHED_MAXIMUM_INTEGER_DISPLAY_LENGTH +1];
-    snprintf(key, sizeof(key), "%u", x);
-
-    keys[x]= strdup(key);
-    test_true(keys[x]);
-    key_length[x]= strlen(key);
-    test_true(key_length[x]);
-  }
-
   test_compare(MEMCACHED_SUCCESS,
-               memcached_mget(clone, (const char* const *)keys, key_length, regression_bug_655423_COUNT));
+               memcached_mget(clone,
+                              keys.keys_ptr(), keys.lengths_ptr(),
+                              keys.size()));
 
   uint32_t count= 0;
   memcached_result_st *result= NULL;
@@ -4846,15 +4526,6 @@ test_return_t regression_bug_655423(memcached_st *memc)
 
   test_true(count > 100); // If we don't get back atleast this, something is up
 
-  /* Release all allocated resources */
-  for (size_t x= 0; x < regression_bug_655423_COUNT; ++x)
-  {
-    free(keys[x]);
-  }
-  free(keys);
-  free(key_length);
-
-
   memcached_free(clone);
 
   return TEST_SUCCESS;
@@ -4864,38 +4535,28 @@ test_return_t regression_bug_655423(memcached_st *memc)
  * Test that ensures that buffered set to not trigger problems during io_flush
  */
 #define regression_bug_490520_COUNT 200480
-test_return_t regression_bug_490520(memcached_st *memc)
+test_return_t regression_bug_490520(memcached_st *original_memc)
 {
+  memcached_st* memc= create_single_instance_memcached(original_memc, NULL);
+
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK,1);
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS,1);
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, 1000);
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT,1);
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 3600);
 
-  memc->number_of_hosts= 1;
-
-  char **keys= (char **)calloc(regression_bug_490520_COUNT, sizeof(char*));
-  size_t *key_length= (size_t *)calloc(regression_bug_490520_COUNT, sizeof(size_t));
-
   /* First add all of the items.. */
   char blob[3333] = {0};
   for (uint32_t x= 0; x < regression_bug_490520_COUNT; ++x)
   {
-    char k[251];
-    key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%u", x);
-    keys[x]= strdup(k);
-    test_true(keys[x]);
+    char key[251];
+    int key_length= snprintf(key, sizeof(key), "0200%u", x);
 
-    memcached_return rc= memcached_set(memc, keys[x], key_length[x], blob, sizeof(blob), 0, 0);
+    memcached_return rc= memcached_set(memc, key, key_length, blob, sizeof(blob), 0, 0);
     test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_last_error_message(memc));
   }
 
-  for (uint32_t x= 0; x < regression_bug_490520_COUNT; ++x)
-  {
-    free(keys[x]);
-  }
-  free(keys);
-  free(key_length);
+  memcached_free(memc);
 
   return TEST_SUCCESS;
 }
@@ -5028,3 +4689,33 @@ test_return_t regression_bug_(memcached_st *memc)
 
   return TEST_SUCCESS;
 }
+
+test_return_t kill_HUP_TEST(memcached_st *original_memc)
+{
+  memcached_st *memc= create_single_instance_memcached(original_memc, 0);
+  test_true(memc);
+
+  memcached_server_instance_st instance= memcached_server_instance_by_position(memc, 0);
+
+  pid_t pid;
+  test_true((pid= libmemcached_util_getpid(memcached_server_name(instance),
+                                           memcached_server_port(instance), NULL)) > -1);
+
+
+  test_compare(MEMCACHED_SUCCESS,
+               memcached_set(memc, 
+                             test_literal_param(__func__), // Keys
+                             test_literal_param(__func__), // Values
+                             0, 0));
+  test_true_got(kill(pid, SIGHUP) == 0, strerror(errno));
+
+  test_compare(MEMCACHED_CONNECTION_FAILURE,
+               memcached_set(memc, 
+                             test_literal_param(__func__), // Keys
+                             test_literal_param(__func__), // Values
+                             0, 0));
+
+  memcached_free(memc);
+
+  return TEST_SUCCESS;
+}