Merge in fixes for SASL.
[awesomized/libmemcached] / tests / atomsmasher.cc
index ffde3877e7e8ccb0c3d4cd61f3d3444f7f6163d7..6949bcd6f2c184d0c37966ad8ec5459525f74f79 100644 (file)
 /*
   Sample test application.
 */
-#include "config.h"
+#include <config.h>
+
+#include <libtest/test.hpp>
 
 #include <libmemcached/memcached.h>
 #include <libmemcached/watchpoint.h>
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <cstdio>
+#include <cstdlib>
 #include <stdint.h>
-#include <string.h>
+#include <cstring>
 #include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <time.h>
+#include <ctime>
 #include <clients/generator.h>
 #include <clients/execute.h>
 
 #include <libtest/server.h>
-#include <libtest/test.h>
+
+#include <tests/debug.h>
+
+using namespace libtest;
 
 /* Number of items generated for tests */
 #define GLOBAL_COUNT 100000
@@ -43,17 +48,15 @@ static pairs_st *global_pairs;
 static char *global_keys[GLOBAL_COUNT];
 static size_t global_keys_length[GLOBAL_COUNT];
 
-static test_return_t cleanup_pairs(memcached_st *memc)
+static test_return_t cleanup_pairs(memcached_st *)
 {
-  (void)memc;
   pairs_free(global_pairs);
 
   return TEST_SUCCESS;
 }
 
-static test_return_t generate_pairs(memcached_st *memc)
+static test_return_t generate_pairs(memcached_st *)
 {
-  (void)memc;
   global_pairs= pairs_generate(GLOBAL_COUNT, 400);
   global_count= GLOBAL_COUNT;
 
@@ -68,14 +71,14 @@ static test_return_t generate_pairs(memcached_st *memc)
 
 static test_return_t drizzle(memcached_st *memc)
 {
-  memcached_return_t rc;
-  char *return_value;
-  size_t return_value_length;
-  uint32_t flags;
-
 infinite:
   for (size_t x= 0; x < TEST_COUNTER; x++)
   {
+    memcached_return_t rc;
+    char *return_value;
+    size_t return_value_length;
+    uint32_t flags;
+
     uint32_t test_bit;
     uint8_t which;
 
@@ -116,7 +119,9 @@ infinite:
   }
 
   if (getenv("MEMCACHED_ATOM_BURIN_IN"))
+  {
     goto infinite;
+  }
 
   return TEST_SUCCESS;
 }
@@ -134,30 +139,32 @@ static test_return_t pre_nonblock(memcached_st *memc)
 */
 static test_return_t add_test(memcached_st *memc)
 {
-  memcached_return_t rc;
   const char *key= "foo";
   const char *value= "when we sanitize";
-  unsigned long long setting_value;
-
-  setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);
 
+  memcached_return_t rc;
   rc= memcached_set(memc, key, strlen(key),
                     value, strlen(value),
                     (time_t)0, (uint32_t)0);
-  test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+  test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc));
   memcached_quit(memc);
   rc= memcached_add(memc, key, strlen(key),
                     value, strlen(value),
                     (time_t)0, (uint32_t)0);
 
+  if (rc == MEMCACHED_CONNECTION_FAILURE)
+  {
+    print_servers(memc);
+  }
+
   /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
-  if (setting_value)
+  if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK))
   {
-    test_true(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED);
+    test_true(rc == MEMCACHED_NOTSTORED or rc == MEMCACHED_STORED);
   }
   else
   {
-    test_true(rc == MEMCACHED_NOTSTORED);
+    test_compare_got(MEMCACHED_NOTSTORED, rc, memcached_strerror(NULL, rc));
   }
 
   return TEST_SUCCESS;
@@ -169,18 +176,19 @@ static test_return_t add_test(memcached_st *memc)
  */
 static test_return_t many_adds(memcached_st *memc)
 {
+  test_true(memc);
   for (size_t x= 0; x < TEST_COUNTER; x++)
   {
-    add_test(memc);
+    test_compare_got(TEST_SUCCESS, add_test(memc), x);
   }
   return TEST_SUCCESS;
 }
 
 test_st smash_tests[] ={
-  {"generate_pairs", 1, (test_callback_fn*)generate_pairs },
-  {"drizzle", 1, (test_callback_fn*)drizzle },
-  {"cleanup", 1, (test_callback_fn*)cleanup_pairs },
-  {"many_adds", 1, (test_callback_fn*)many_adds },
+  {"generate_pairs", true, (test_callback_fn*)generate_pairs },
+  {"drizzle", true, (test_callback_fn*)drizzle },
+  {"cleanup", true, (test_callback_fn*)cleanup_pairs },
+  {"many_adds", true, (test_callback_fn*)many_adds },
   {0, 0, 0}
 };
 
@@ -194,9 +202,8 @@ struct benchmark_state_st
   memcached_st *clone;
 } benchmark_state;
 
-static test_return_t memcached_create_benchmark(memcached_st *memc)
+static test_return_t memcached_create_benchmark(memcached_st *)
 {
-  (void)memc;
   benchmark_state.create_init= true;
 
   for (size_t x= 0; x < BENCHMARK_TEST_LOOP; x++)
@@ -225,9 +232,8 @@ static test_return_t memcached_clone_benchmark(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-static test_return_t pre_allocate(memcached_st *memc)
+static test_return_t pre_allocate(memcached_st *)
 {
-  (void)memc;
   memset(&benchmark_state, 0, sizeof(benchmark_state));
 
   benchmark_state.create= (memcached_st *)calloc(BENCHMARK_TEST_LOOP, sizeof(memcached_st));
@@ -238,16 +244,19 @@ static test_return_t pre_allocate(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-static test_return_t post_allocate(memcached_st *memc)
+static test_return_t post_allocate(memcached_st *)
 {
-  (void)memc;
   for (size_t x= 0; x < BENCHMARK_TEST_LOOP; x++)
   {
     if (benchmark_state.create_init)
+    {
       memcached_free(&benchmark_state.create[x]);
+    }
 
     if (benchmark_state.clone_init)
+    {
       memcached_free(&benchmark_state.clone[x]);
+    }
   }
 
   free(benchmark_state.create);
@@ -272,25 +281,26 @@ collection_st collection[] ={
 };
 
 
+#define TEST_PORT_BASE MEMCACHED_DEFAULT_PORT +10
 #define SERVERS_TO_CREATE 5
 
 #include "libmemcached_world.h"
 
-void get_world(world_st *world)
+void get_world(Framework *world)
 {
   world->collections= collection;
 
-  world->create= (test_callback_create_fn*)world_create;
-  world->destroy= (test_callback_fn*)world_destroy;
+  world->_create= (test_callback_create_fn*)world_create;
+  world->_destroy= (test_callback_destroy_fn*)world_destroy;
 
-  world->run_startup= (test_callback_fn*)world_test_startup;
-  world->flush= (test_callback_fn*)world_flush;
-  world->pre_run= (test_callback_fn*)world_pre_run;
-  world->post_run= (test_callback_fn*)world_post_run;
-  world->on_error= (test_callback_error_fn*)world_on_error;
+  world->item._startup= (test_callback_fn*)world_test_startup;
+  world->item._flush= (test_callback_fn*)world_flush;
+  world->item.set_pre((test_callback_fn*)world_pre_run);
+  world->item.set_post((test_callback_fn*)world_post_run);
+  world->_on_error= (test_callback_error_fn*)world_on_error;
 
   world->collection_startup= (test_callback_fn*)world_container_startup;
   world->collection_shutdown= (test_callback_fn*)world_container_shutdown;
 
-  world->runner= &defualt_libmemcached_runner;
+  world->set_runner(&defualt_libmemcached_runner);
 }