Updates, rpm now tests the install locations.
[m6w6/libmemcached] / tests / function.c
index b77786603ca22ddec8837dc8c74475157529ec19..9ccc40266207e02822e8f0be569aa2afb3602792 100644 (file)
@@ -235,8 +235,6 @@ static test_return_t  clone_test(memcached_st *memc)
       test_truth(memc_clone->flags.no_block == memc->flags.no_block);
       test_truth(memc_clone->flags.tcp_nodelay == memc->flags.tcp_nodelay);
       test_truth(memc_clone->flags.reuse_memory == memc->flags.reuse_memory);
-      test_truth(memc_clone->flags.use_md5 == memc->flags.use_md5);
-      test_truth(memc_clone->flags.use_crc == memc->flags.use_crc);
       test_truth(memc_clone->flags.use_cache_lookups == memc->flags.use_cache_lookups);
       test_truth(memc_clone->flags.support_cas == memc->flags.support_cas);
       test_truth(memc_clone->flags.buffer_requests == memc->flags.buffer_requests);
@@ -252,7 +250,7 @@ static test_return_t  clone_test(memcached_st *memc)
     }
     test_truth(memc_clone->get_key_failure == memc->get_key_failure);
     test_truth(memc_clone->hash == memc->hash);
-    test_truth(memc_clone->hash_continuum == memc->hash_continuum);
+    test_truth(memc_clone->distribution_hash == memc->distribution_hash);
     test_truth(memc_clone->io_bytes_watermark == memc->io_bytes_watermark);
     test_truth(memc_clone->io_msg_watermark == memc->io_msg_watermark);
     test_truth(memc_clone->io_key_prefetch == memc->io_key_prefetch);
@@ -716,6 +714,10 @@ static test_return_t  bad_key_test(memcached_st *memc)
   unsigned int set= 1;
   size_t max_keylen= 0xffff;
 
+  // Just skip if we are in binary mode.
+  if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL))
+    return TEST_SKIPPED;
+
   memc_clone= memcached_clone(NULL, memc);
   test_truth(memc_clone);
 
@@ -798,16 +800,16 @@ static test_return_t  bad_key_test(memcached_st *memc)
 }
 
 #define READ_THROUGH_VALUE "set for me"
-static memcached_return_t  read_through_trigger(memcached_st *memc __attribute__((unused)),
-                                                char *key __attribute__((unused)),
-                                                size_t key_length __attribute__((unused)),
-                                                memcached_result_st *result)
+static memcached_return_t read_through_trigger(memcached_st *memc __attribute__((unused)),
+                                               char *key __attribute__((unused)),
+                                               size_t key_length __attribute__((unused)),
+                                               memcached_result_st *result)
 {
 
   return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE));
 }
 
-static test_return_t  read_through(memcached_st *memc)
+static test_return_t read_through(memcached_st *memc)
 {
   memcached_return_t rc;
   const char *key= "foo";
@@ -820,8 +822,8 @@ static test_return_t  read_through(memcached_st *memc)
                         &string_length, &flags, &rc);
 
   test_truth(rc == MEMCACHED_NOTFOUND);
-  test_truth(string_length ==  0);
-  test_truth(!string);
+  test_false(string_length);
+  test_false(string);
 
   rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE,
                              *(void **)&cb);
@@ -832,7 +834,7 @@ static test_return_t  read_through(memcached_st *memc)
 
   test_truth(rc == MEMCACHED_SUCCESS);
   test_truth(string_length ==  strlen(READ_THROUGH_VALUE));
-  test_truth(!strcmp(READ_THROUGH_VALUE, string));
+  test_strcmp(READ_THROUGH_VALUE, string);
   free(string);
 
   string= memcached_get(memc, key, strlen(key),
@@ -847,8 +849,8 @@ static test_return_t  read_through(memcached_st *memc)
 }
 
 static memcached_return_t  delete_trigger(memcached_st *ptr __attribute__((unused)),
-                                        const char *key,
-                                        size_t key_length __attribute__((unused)))
+                                          const char *key,
+                                          size_t key_length __attribute__((unused)))
 {
   assert(key);
 
@@ -883,8 +885,8 @@ static test_return_t  get_test(memcached_st *memc)
                         &string_length, &flags, &rc);
 
   test_truth(rc == MEMCACHED_NOTFOUND);
-  test_truth(string_length ==  0);
-  test_truth(!string);
+  test_false(string_length);
+  test_false(string);
 
   return TEST_SUCCESS;
 }
@@ -1156,8 +1158,8 @@ static test_return_t  stats_servername_test(memcached_st *memc)
   memcached_return_t rc;
   memcached_stat_st memc_stat;
   rc= memcached_stat_servername(&memc_stat, NULL,
-                                 memc->hosts[0].hostname,
-                                 memc->hosts[0].port);
+                                memc->hosts[0].hostname,
+                                memc->hosts[0].port);
 
   return TEST_SUCCESS;
 }
@@ -1662,7 +1664,6 @@ static test_return_t  get_stats_keys(memcached_st *memc)
  test_truth(rc == MEMCACHED_SUCCESS);
  for (ptr= stat_list; *ptr; ptr++)
    test_truth(*ptr);
- fflush(stdout);
 
  free(stat_list);
 
@@ -1844,6 +1845,7 @@ static test_return_t  behavior_test(memcached_st *memc)
   value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS);
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, value + 1);
   test_truth((value + 1) == memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS));
+
   return TEST_SUCCESS;
 }
 
@@ -2734,7 +2736,7 @@ static test_return_t user_supplied_bug18(memcached_st *trash)
   {
     uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key));
     char *hostname = memc->hosts[server_idx].hostname;
-    test_truth(strcmp(hostname, ketama_test_cases[x].server) == 0);
+    test_strcmp(hostname, ketama_test_cases[x].server);
   }
 
   memcached_server_list_free(server_pool);
@@ -2813,8 +2815,11 @@ static test_return_t pre_binary(memcached_st *memc);
 
 static test_return_t user_supplied_bug21(memcached_st *memc)
 {
-  if (pre_binary(memc) != MEMCACHED_SUCCESS)
-    return TEST_SKIPPED;
+  test_return_t test_rc;
+  test_rc= pre_binary(memc);
+
+  if (test_rc != TEST_SUCCESS)
+    return test_rc;
 
   test_return_t rc;
 
@@ -2921,8 +2926,7 @@ static test_return_t output_ketama_weighted_keys(memcached_st *trash)
   test_truth(value == MEMCACHED_HASH_MD5);
 
 
-  test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE,
-                                MEMCACHED_KETAMA_COMPAT_SPY) == MEMCACHED_SUCCESS);
+  test_truth(memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY) == MEMCACHED_SUCCESS);
 
   memcached_server_st *server_pool;
   server_pool = memcached_servers_parse("10.0.1.1:11211,10.0.1.2:11211,10.0.1.3:11211,10.0.1.4:11211,10.0.1.5:11211,10.0.1.6:11211,10.0.1.7:11211,10.0.1.8:11211,192.168.1.1:11211,192.168.100.1:11211");
@@ -2946,7 +2950,7 @@ static test_return_t output_ketama_weighted_keys(memcached_st *trash)
 
     uint32_t server_idx = memcached_generate_hash(memc, key, strlen(key));
     char *hostname = memc->hosts[server_idx].hostname;
-    unsigned int port = memc->hosts[server_idx].port;
+    in_port_t port = memc->hosts[server_idx].port;
     fprintf(fp, "key %s is on host /%s:%u\n", key, hostname, port);
   }
   fclose(fp);
@@ -3367,7 +3371,7 @@ static test_return_t pre_nonblock_binary(memcached_st *memc)
   memcached_st *memc_clone;
 
   memc_clone= memcached_clone(NULL, memc);
-  assert(memc_clone);
+  test_truth(memc_clone);
   // The memcached_version needs to be done on a clone, because the server
   // will not toggle protocol on an connection.
   memcached_version(memc_clone);
@@ -3377,7 +3381,7 @@ static test_return_t pre_nonblock_binary(memcached_st *memc)
     memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
     rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
     test_truth(rc == MEMCACHED_SUCCESS);
-    assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1);
+    test_truth(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1);
   }
   else
   {
@@ -3517,10 +3521,14 @@ static test_return_t pre_binary(memcached_st *memc)
   return rc == MEMCACHED_SUCCESS ? TEST_SUCCESS : TEST_SKIPPED;
 }
 
+
 static test_return_t pre_replication(memcached_st *memc)
 {
-  if (pre_binary(memc) != TEST_SUCCESS)
-    return TEST_FAILURE;
+  test_return_t test_rc;
+  test_rc= pre_binary(memc);
+
+  if (test_rc != TEST_SUCCESS)
+    return test_rc;
 
   /*
    * Make sure that we store the item on all servers
@@ -3535,40 +3543,88 @@ static test_return_t pre_replication(memcached_st *memc)
   return rc == MEMCACHED_SUCCESS ? TEST_SUCCESS : TEST_SKIPPED;
 }
 
+
 static test_return_t pre_replication_noblock(memcached_st *memc)
 {
-  test_return_t rc= MEMCACHED_FAILURE;
-  if (pre_replication(memc) == TEST_SUCCESS &&
-      pre_nonblock(memc) == TEST_SUCCESS)
-    rc= TEST_SUCCESS;
+  test_return_t rc;
+
+  rc= pre_replication(memc);
+  if (rc != TEST_SUCCESS)
+    return rc;
+
+  rc= pre_nonblock(memc);
 
   return rc;
 }
 
+
 static void my_free(memcached_st *ptr __attribute__((unused)), void *mem)
 {
+#ifdef HARD_MALLOC_TESTS
+  void *real_ptr= (mem == NULL) ? mem : (void*)((caddr_t)mem - 8);
+  free(real_ptr);
+#else
   free(mem);
+#endif
 }
 
+
 static void *my_malloc(memcached_st *ptr __attribute__((unused)), const size_t size)
 {
+#ifdef HARD_MALLOC_TESTS
+  void *ret= malloc(size + 8);
+  if (ret != NULL)
+  {
+    ret= (void*)((caddr_t)ret + 8);
+  }
+#else
   void *ret= malloc(size);
+#endif
+
   if (ret != NULL)
+  {
     memset(ret, 0xff, size);
+  }
 
   return ret;
 }
 
+
 static void *my_realloc(memcached_st *ptr __attribute__((unused)), void *mem, const size_t size)
 {
+#ifdef HARD_MALLOC_TESTS
+  void *real_ptr= (mem == NULL) ? NULL : (void*)((caddr_t)mem - 8);
+  void *nmem= realloc(real_ptr, size + 8);
+
+  void *ret= NULL;
+  if (nmem != NULL)
+  {
+    ret= (void*)((caddr_t)nmem + 8);
+  }
+
+  return ret;
+#else
   return realloc(mem, size);
+#endif
 }
 
+
 static void *my_calloc(memcached_st *ptr __attribute__((unused)), size_t nelem, const size_t size)
 {
+#ifdef HARD_MALLOC_TESTS
+  void *mem= my_malloc(ptr, nelem * size);
+  if (mem)
+  {
+    memset(mem, 0, nelem * size);
+  }
+
+  return mem;
+#else
   return calloc(nelem, size);
+#endif
 }
 
+
 static test_return_t set_prefix(memcached_st *memc)
 {
   memcached_return_t rc;
@@ -3638,6 +3694,7 @@ static test_return_t set_prefix(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
+
 #ifdef MEMCACHED_ENABLE_DEPRECATED
 static test_return_t deprecated_set_memory_alloc(memcached_st *memc)
 {
@@ -3686,6 +3743,7 @@ static test_return_t deprecated_set_memory_alloc(memcached_st *memc)
 }
 #endif
 
+
 static test_return_t set_memory_alloc(memcached_st *memc)
 {
   memcached_return_t rc;
@@ -3711,7 +3769,27 @@ static test_return_t set_memory_alloc(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-static test_return_t enable_consistent(memcached_st *memc)
+static test_return_t enable_consistent_crc(memcached_st *memc)
+{
+  test_return_t rc;
+  memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT;
+  memcached_hash_t hash;
+  memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, value);
+  if ((rc= pre_crc(memc)) != TEST_SUCCESS)
+    return rc;
+
+  value= (memcached_server_distribution_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION);
+  test_truth(value == MEMCACHED_DISTRIBUTION_CONSISTENT);
+
+  hash= (memcached_hash_t)memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_HASH);
+
+  if (hash != MEMCACHED_HASH_CRC)
+    return TEST_SKIPPED;
+
+  return TEST_SUCCESS;
+}
+
+static test_return_t enable_consistent_hsieh(memcached_st *memc)
 {
   test_return_t rc;
   memcached_server_distribution_t value= MEMCACHED_DISTRIBUTION_CONSISTENT;
@@ -4391,7 +4469,12 @@ static test_return_t init_udp(memcached_st *memc)
 
 static test_return_t binary_init_udp(memcached_st *memc)
 {
-  pre_binary(memc);
+  test_return_t test_rc;
+  test_rc= pre_binary(memc);
+
+  if (test_rc != TEST_SUCCESS)
+    return test_rc;
+
   return init_udp(memc);
 }
 
@@ -4865,46 +4948,45 @@ static test_return_t ketama_compatibility_libmemcached(memcached_st *trash)
   (void)trash;
 
   memc= memcached_create(NULL);
-  assert(memc);
+  test_truth(memc);
 
   rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
-  assert(value == 1);
+  test_truth(value == 1);
 
-  assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE,
-                                MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED) == MEMCACHED_SUCCESS);
+  test_truth(memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA) == MEMCACHED_SUCCESS);
+  test_truth(memcached_behavior_get_distribution(memc) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA);
 
-  assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE) ==
-         MEMCACHED_KETAMA_COMPAT_LIBMEMCACHED);
 
   server_pool = memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100");
   memcached_server_push(memc, server_pool);
 
   /* verify that the server list was parsed okay. */
-  assert(memc->number_of_hosts == 8);
-  assert(strcmp(server_pool[0].hostname, "10.0.1.1") == 0);
-  assert(server_pool[0].port == 11211);
-  assert(server_pool[0].weight == 600);
-  assert(strcmp(server_pool[2].hostname, "10.0.1.3") == 0);
-  assert(server_pool[2].port == 11211);
-  assert(server_pool[2].weight == 200);
-  assert(strcmp(server_pool[7].hostname, "10.0.1.8") == 0);
-  assert(server_pool[7].port == 11211);
-  assert(server_pool[7].weight == 100);
+  test_truth(memc->number_of_hosts == 8);
+  test_strcmp(server_pool[0].hostname, "10.0.1.1");
+  test_truth(server_pool[0].port == 11211);
+  test_truth(server_pool[0].weight == 600);
+  test_strcmp(server_pool[2].hostname, "10.0.1.3");
+  test_truth(server_pool[2].port == 11211);
+  test_truth(server_pool[2].weight == 200);
+  test_strcmp(server_pool[7].hostname, "10.0.1.8");
+  test_truth(server_pool[7].port == 11211);
+  test_truth(server_pool[7].weight == 100);
 
   /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
    * us test the boundary wraparound.
    */
-  assert(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index);
+  test_truth(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index);
 
   /* verify the standard ketama set. */
   for (x= 0; x < 99; x++)
   {
     uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key));
     char *hostname = memc->hosts[server_idx].hostname;
-    assert(strcmp(hostname, ketama_test_cases[x].server) == 0);
+
+    test_strcmp(hostname, ketama_test_cases[x].server);
   }
 
   memcached_server_list_free(server_pool);
@@ -4924,46 +5006,43 @@ static test_return_t ketama_compatibility_spymemcached(memcached_st *trash)
   (void)trash;
 
   memc= memcached_create(NULL);
-  assert(memc);
+  test_truth(memc);
 
   rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED, 1);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_WEIGHTED);
-  assert(value == 1);
-
-  assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE,
-                                MEMCACHED_KETAMA_COMPAT_SPY) == MEMCACHED_SUCCESS);
+  test_truth(value == 1);
 
-  assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_KETAMA_COMPAT_MODE) ==
-         MEMCACHED_KETAMA_COMPAT_SPY);
+  test_truth(memcached_behavior_set_distribution(memc, MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY) == MEMCACHED_SUCCESS);
+  test_truth(memcached_behavior_get_distribution(memc) == MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA_SPY);
 
   server_pool = memcached_servers_parse("10.0.1.1:11211 600,10.0.1.2:11211 300,10.0.1.3:11211 200,10.0.1.4:11211 350,10.0.1.5:11211 1000,10.0.1.6:11211 800,10.0.1.7:11211 950,10.0.1.8:11211 100");
   memcached_server_push(memc, server_pool);
 
   /* verify that the server list was parsed okay. */
-  assert(memc->number_of_hosts == 8);
-  assert(strcmp(server_pool[0].hostname, "10.0.1.1") == 0);
-  assert(server_pool[0].port == 11211);
-  assert(server_pool[0].weight == 600);
-  assert(strcmp(server_pool[2].hostname, "10.0.1.3") == 0);
-  assert(server_pool[2].port == 11211);
-  assert(server_pool[2].weight == 200);
-  assert(strcmp(server_pool[7].hostname, "10.0.1.8") == 0);
-  assert(server_pool[7].port == 11211);
-  assert(server_pool[7].weight == 100);
+  test_truth(memc->number_of_hosts == 8);
+  test_strcmp(server_pool[0].hostname, "10.0.1.1");
+  test_truth(server_pool[0].port == 11211);
+  test_truth(server_pool[0].weight == 600);
+  test_strcmp(server_pool[2].hostname, "10.0.1.3");
+  test_truth(server_pool[2].port == 11211);
+  test_truth(server_pool[2].weight == 200);
+  test_strcmp(server_pool[7].hostname, "10.0.1.8");
+  test_truth(server_pool[7].port == 11211);
+  test_truth(server_pool[7].weight == 100);
 
   /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets
    * us test the boundary wraparound.
    */
-  assert(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index);
+  test_truth(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index);
 
   /* verify the standard ketama set. */
   for (x= 0; x < 99; x++)
   {
     uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases_spy[x].key, strlen(ketama_test_cases_spy[x].key));
     char *hostname = memc->hosts[server_idx].hostname;
-    assert(strcmp(hostname, ketama_test_cases_spy[x].server) == 0);
+    test_strcmp(hostname, ketama_test_cases_spy[x].server);
   }
 
   memcached_server_list_free(server_pool);
@@ -4974,21 +5053,24 @@ static test_return_t ketama_compatibility_spymemcached(memcached_st *trash)
 
 static test_return_t regression_bug_434484(memcached_st *memc)
 {
-  if (pre_binary(memc) != MEMCACHED_SUCCESS)
-    return TEST_SKIPPED;
+  test_return_t test_rc;
+  test_rc= pre_binary(memc);
+
+  if (test_rc != TEST_SUCCESS)
+    return test_rc;
 
   memcached_return_t ret;
   const char *key= "regression_bug_434484";
   size_t keylen= strlen(key);
 
   ret= memcached_append(memc, key, keylen, key, keylen, 0, 0);
-  assert(ret == MEMCACHED_NOTSTORED);
+  test_truth(ret == MEMCACHED_NOTSTORED);
 
   size_t size= 2048 * 1024;
   void *data= calloc(1, size);
-  assert(data != NULL);
+  test_truth(data != NULL);
   ret= memcached_set(memc, key, keylen, data, size, 0, 0);
-  assert(ret == MEMCACHED_E2BIG);
+  test_truth(ret == MEMCACHED_E2BIG);
   free(data);
 
   return TEST_SUCCESS;
@@ -4996,8 +5078,11 @@ static test_return_t regression_bug_434484(memcached_st *memc)
 
 static test_return_t regression_bug_434843(memcached_st *memc)
 {
-  if (pre_binary(memc) != MEMCACHED_SUCCESS)
-    return TEST_SKIPPED;
+  test_return_t test_rc;
+  test_rc= pre_binary(memc);
+
+  if (test_rc != TEST_SUCCESS)
+    return test_rc;
 
   memcached_return_t rc;
   unsigned int counter= 0;
@@ -5020,7 +5105,7 @@ static test_return_t regression_bug_434843(memcached_st *memc)
      char k[251];
      key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%u", x);
      keys[x]= strdup(k);
-     assert(keys[x] != NULL);
+     test_truth(keys[x] != NULL);
   }
 
   /*
@@ -5030,24 +5115,24 @@ static test_return_t regression_bug_434843(memcached_st *memc)
   for (int y= 0; y < 2; ++y)
   {
     rc= memcached_mget(memc, (const char**)keys, key_length, max_keys);
-    assert(rc == MEMCACHED_SUCCESS);
+    test_truth(rc == MEMCACHED_SUCCESS);
     rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
     if (y == 0)
     {
       /* The first iteration should give me a 100% cache miss. verify that*/
-      assert(counter == 0);
+      test_truth(counter == 0);
       char blob[1024]= { 0 };
       for (int x= 0; x < (int)max_keys; ++x)
       {
         rc= memcached_add(memc, keys[x], key_length[x],
                           blob, sizeof(blob), 0, 0);
-        assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+        test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
       }
     }
     else
     {
       /* Verify that we received all of the key/value pairs */
-       assert(counter == (unsigned int)max_keys);
+       test_truth(counter == (unsigned int)max_keys);
     }
   }
 
@@ -5065,7 +5150,7 @@ static test_return_t regression_bug_434843_buffered(memcached_st *memc)
 {
   memcached_return_t rc;
   rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   return regression_bug_434843(memc);
 }
@@ -5074,29 +5159,30 @@ static test_return_t regression_bug_421108(memcached_st *memc)
 {
   memcached_return_t rc;
   memcached_stat_st *memc_stat= memcached_stat(memc, NULL, &rc);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   char *bytes= memcached_stat_get_value(memc, memc_stat, "bytes", &rc);
-  assert(rc == MEMCACHED_SUCCESS);
-  assert(bytes != NULL);
+  test_truth(rc == MEMCACHED_SUCCESS);
+  test_truth(bytes != NULL);
   char *bytes_read= memcached_stat_get_value(memc, memc_stat,
                                              "bytes_read", &rc);
-  assert(rc == MEMCACHED_SUCCESS);
-  assert(bytes_read != NULL);
+  test_truth(rc == MEMCACHED_SUCCESS);
+  test_truth(bytes_read != NULL);
 
   char *bytes_written= memcached_stat_get_value(memc, memc_stat,
                                                 "bytes_written", &rc);
-  assert(rc == MEMCACHED_SUCCESS);
-  assert(bytes_written != NULL);
+  test_truth(rc == MEMCACHED_SUCCESS);
+  test_truth(bytes_written != NULL);
 
-  assert(strcmp(bytes, bytes_read) != 0);
-  assert(strcmp(bytes, bytes_written) != 0);
+  test_truth(strcmp(bytes, bytes_read) != 0);
+  test_truth(strcmp(bytes, bytes_written) != 0);
 
   /* Release allocated resources */
   free(bytes);
   free(bytes_read);
   free(bytes_written);
   memcached_stat_free(NULL, memc_stat);
+
   return TEST_SUCCESS;
 }
 
@@ -5115,7 +5201,7 @@ static test_return_t regression_bug_442914(memcached_st *memc)
 {
   memcached_return_t rc;
   rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
   memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1);
 
   uint32_t number_of_hosts= memc->number_of_hosts;
@@ -5128,17 +5214,17 @@ static test_return_t regression_bug_442914(memcached_st *memc)
   {
      len= (size_t)snprintf(k, sizeof(k), "%0250u", x);
      rc= memcached_delete(memc, k, len, 0);
-     assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+     test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
   }
 
   len= (size_t)snprintf(k, sizeof(k), "%037u", 251);
   rc= memcached_delete(memc, k, len, 0);
-  assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+  test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
 
   rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
   rc= memcached_delete(memc, k, len, 0);
-  assert(rc == MEMCACHED_NOTFOUND);
+  test_truth(rc == MEMCACHED_NOTFOUND);
 
   memc->number_of_hosts= number_of_hosts;
 
@@ -5153,7 +5239,7 @@ static test_return_t regression_bug_447342(memcached_st *memc)
   memcached_return_t rc;
 
   rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 2);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   const size_t max_keys= 100;
   char **keys= calloc(max_keys, sizeof(char*));
@@ -5164,9 +5250,9 @@ static test_return_t regression_bug_447342(memcached_st *memc)
     char k[251];
     key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%u", x);
     keys[x]= strdup(k);
-    assert(keys[x] != NULL);
+    test_truth(keys[x] != NULL);
     rc= memcached_set(memc, k, key_length[x], k, key_length[x], 0, 0);
-    assert(rc == MEMCACHED_SUCCESS);
+    test_truth(rc == MEMCACHED_SUCCESS);
   }
 
   /*
@@ -5188,13 +5274,13 @@ static test_return_t regression_bug_447342(memcached_st *memc)
    * into the servers
    */
   rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   unsigned int counter= 0;
   memcached_execute_fn callbacks[1]= { [0]= &callback_counter };
   rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
   /* Verify that we received all of the key/value pairs */
-  assert(counter == (unsigned int)max_keys);
+  test_truth(counter == (unsigned int)max_keys);
 
   memcached_quit(memc);
   /*
@@ -5203,17 +5289,18 @@ static test_return_t regression_bug_447342(memcached_st *memc)
    * This is to verify correct behavior in the library. Fake that two servers
    * are dead..
    */
-  unsigned int port0= memc->hosts[0].port;
-  unsigned int port2= memc->hosts[2].port;
+  in_port_t port0= memc->hosts[0].port;
+  in_port_t port2= memc->hosts[2].port;
+
   memc->hosts[0].port= 0;
   memc->hosts[2].port= 0;
 
   rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   counter= 0;
   rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
-  assert(counter == (unsigned int)max_keys);
+  test_truth(counter == (unsigned int)max_keys);
 
   /* restore the memc handle */
   memc->hosts[0].port= port0;
@@ -5223,11 +5310,13 @@ static test_return_t regression_bug_447342(memcached_st *memc)
 
   /* Remove half of the objects */
   for (int x= 0; x < (int)max_keys; ++x)
+  {
     if (x & 1)
     {
       rc= memcached_delete(memc, keys[x], key_length[x], 0);
-      assert(rc == MEMCACHED_SUCCESS);
+      test_truth(rc == MEMCACHED_SUCCESS);
     }
+  }
 
   memcached_quit(memc);
   memc->hosts[0].port= 0;
@@ -5235,11 +5324,11 @@ static test_return_t regression_bug_447342(memcached_st *memc)
 
   /* now retry the command, this time we should have cache misses */
   rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
 
   counter= 0;
   rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1);
-  assert(counter == (unsigned int)(max_keys >> 1));
+  test_truth(counter == (unsigned int)(max_keys >> 1));
 
   /* Release allocated resources */
   for (size_t x= 0; x < max_keys; ++x)
@@ -5250,14 +5339,15 @@ static test_return_t regression_bug_447342(memcached_st *memc)
   /* restore the memc handle */
   memc->hosts[0].port= port0;
   memc->hosts[2].port= port2;
+
   return TEST_SUCCESS;
 }
 
 static test_return_t regression_bug_463297(memcached_st *memc)
 {
   memcached_st *memc_clone= memcached_clone(NULL, memc);
-  assert(memc_clone != NULL);
-  assert(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
+  test_truth(memc_clone != NULL);
+  test_truth(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
 
   if (memc_clone->hosts[0].major_version > 1 ||
       (memc_clone->hosts[0].major_version == 1 &&
@@ -5265,44 +5355,45 @@ static test_return_t regression_bug_463297(memcached_st *memc)
   {
      /* Binary protocol doesn't support deferred delete */
      memcached_st *bin_clone= memcached_clone(NULL, memc);
-     assert(bin_clone != NULL);
-     assert(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS);
-     assert(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
+     test_truth(bin_clone != NULL);
+     test_truth(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS);
+     test_truth(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
      memcached_free(bin_clone);
 
      memcached_quit(memc_clone);
 
      /* If we know the server version, deferred delete should fail
       * with invalid arguments */
-     assert(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
+     test_truth(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS);
 
      /* If we don't know the server version, we should get a protocol error */
      memcached_return_t rc= memcached_delete(memc, "foo", 3, 1);
+
      /* but there is a bug in some of the memcached servers (1.4) that treats
       * the counter as noreply so it doesn't send the proper error message
       */
-     assert(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
+     test_truth(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
 
      /* And buffered mode should be disabled and we should get protocol error */
-     assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS);
+     test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS);
      rc= memcached_delete(memc, "foo", 3, 1);
-     assert(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
+     test_truth(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
 
      /* Same goes for noreply... */
-     assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS);
+     test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS);
      rc= memcached_delete(memc, "foo", 3, 1);
-     assert(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
+     test_truth(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR);
 
      /* but a normal request should go through (and be buffered) */
-     assert((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED);
-     assert(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
+     test_truth((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED);
+     test_truth(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS);
 
-     assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS);
+     test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS);
      /* unbuffered noreply should be success */
-     assert(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS);
+     test_truth(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS);
      /* unbuffered with reply should be not found... */
-     assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS);
-     assert(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND);
+     test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS);
+     test_truth(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND);
   }
 
   memcached_free(memc_clone);
@@ -5326,10 +5417,10 @@ static test_return_t  test_get_last_disconnect(memcached_st *memc)
   rc= memcached_set(memc, key, strlen(key),
                     value, strlen(value),
                     (time_t)0, (uint32_t)0);
-  assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+  test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
 
   disconnected_server = memcached_server_get_last_disconnect(memc);
-  assert(disconnected_server == NULL);
+  test_truth(disconnected_server == NULL);
 
   /* With a non existing server */
   memcached_st *mine;
@@ -5338,22 +5429,22 @@ static test_return_t  test_get_last_disconnect(memcached_st *memc)
   const char *server_list= "localhost:9";
 
   servers= memcached_servers_parse(server_list);
-  assert(servers);
+  test_truth(servers);
   mine= memcached_create(NULL);
   rc= memcached_server_push(mine, servers);
-  assert(rc == MEMCACHED_SUCCESS);
+  test_truth(rc == MEMCACHED_SUCCESS);
   memcached_server_list_free(servers);
-  assert(mine);
+  test_truth(mine);
 
   rc= memcached_set(mine, key, strlen(key),
                     value, strlen(value),
                     (time_t)0, (uint32_t)0);
-  assert(rc != MEMCACHED_SUCCESS);
+  test_truth(rc != MEMCACHED_SUCCESS);
 
   disconnected_server = memcached_server_get_last_disconnect(mine);
-  assert(disconnected_server != NULL);
-  assert(disconnected_server->port == 9);
-  assert(strncmp(disconnected_server->hostname,"localhost",9) == 0);
+  test_truth(disconnected_server != NULL);
+  test_truth(disconnected_server->port == 9);
+  test_truth(strncmp(disconnected_server->hostname,"localhost",9) == 0);
 
   memcached_quit(mine);
   memcached_free(mine);
@@ -5385,7 +5476,7 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc)
   rc= memcached_set(memc, key, strlen(key),
                     value, strlen(value),
                     (time_t)0, (uint32_t)0);
-  assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+  test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
 
 
   /* The test is to see that the memcached_quit doesn't increase the
@@ -5400,7 +5491,7 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc)
    * Please note that this isn't bullet proof, because an error could
    * occur...
    */
-  assert(memc->hosts[0].server_failure_counter == 0);
+  test_truth(memc->hosts[0].server_failure_counter == 0);
 
   /* restore the instance */
   memc->number_of_hosts= number_of_hosts;
@@ -5445,7 +5536,6 @@ test_st tests[] ={
   {"clone_test", 0, (test_callback_fn)clone_test },
   {"connection_test", 0, (test_callback_fn)connection_test},
   {"callback_test", 0, (test_callback_fn)callback_test},
-  {"behavior_test", 0, (test_callback_fn)behavior_test},
   {"userdata_test", 0, (test_callback_fn)userdata_test},
   {"error", 0, (test_callback_fn)error_test },
   {"set", 0, (test_callback_fn)set_test },
@@ -5480,8 +5570,6 @@ test_st tests[] ={
   {"add_host_test", 0, (test_callback_fn)add_host_test },
   {"add_host_test_1", 0, (test_callback_fn)add_host_test1 },
   {"get_stats_keys", 0, (test_callback_fn)get_stats_keys },
-  {"behavior_test", 0, (test_callback_fn)get_stats_keys },
-  {"callback_test", 0, (test_callback_fn)get_stats_keys },
   {"version_string_test", 0, (test_callback_fn)version_string_test},
   {"bad_key", 1, (test_callback_fn)bad_key_test },
   {"memcached_server_cursor", 1, (test_callback_fn)memcached_server_cursor_test },
@@ -5496,6 +5584,11 @@ test_st tests[] ={
   {0, 0, 0}
 };
 
+test_st behavior_tests[] ={
+  {"behavior_test", 0, (test_callback_fn)behavior_test},
+  {0, 0, 0}
+};
+
 test_st async_tests[] ={
   {"add", 1, (test_callback_fn)add_wrapper },
   {0, 0, 0}
@@ -5686,7 +5779,8 @@ collection_st collection[] ={
   {"unix_socket_nodelay", (test_callback_fn)pre_nodelay, 0, tests},
   {"poll_timeout", (test_callback_fn)poll_timeout, 0, tests},
   {"gets", (test_callback_fn)enable_cas, 0, tests},
-  {"consistent", (test_callback_fn)enable_consistent, 0, tests},
+  {"consistent_crc", (test_callback_fn)enable_consistent_crc, 0, tests},
+  {"consistent_hsieh", (test_callback_fn)enable_consistent_hsieh, 0, tests},
 #ifdef MEMCACHED_ENABLE_DEPRECATED
   {"deprecated_memory_allocators", (test_callback_fn)deprecated_set_memory_alloc, 0, tests},
 #endif
@@ -5701,7 +5795,7 @@ collection_st collection[] ={
   {"generate", 0, 0, generate_tests},
   {"generate_hsieh", (test_callback_fn)pre_hsieh, 0, generate_tests},
   {"generate_ketama", (test_callback_fn)pre_behavior_ketama, 0, generate_tests},
-  {"generate_hsieh_consistent", (test_callback_fn)enable_consistent, 0, generate_tests},
+  {"generate_hsieh_consistent", (test_callback_fn)enable_consistent_hsieh, 0, generate_tests},
   {"generate_md5", (test_callback_fn)pre_md5, 0, generate_tests},
   {"generate_murmur", (test_callback_fn)pre_murmur, 0, generate_tests},
   {"generate_jenkins", (test_callback_fn)pre_jenkins, 0, generate_tests},
@@ -5714,6 +5808,7 @@ collection_st collection[] ={
   {"replication", (test_callback_fn)pre_replication, 0, replication_tests},
   {"replication_noblock", (test_callback_fn)pre_replication_noblock, 0, replication_tests},
   {"regression", 0, 0, regression_tests},
+  {"behaviors", 0, 0, behavior_tests},
   {0, 0, 0, 0}
 };