Update all of the build/spec files.
[awesomized/libmemcached] / tests / mem_functions.cc
index cca23464e01ac16d9b63aa21e2c5cdef6ca3395d..3d2869ce23bfa0f9ca6fa83e7d365d5be1a7ebf0 100644 (file)
   Test cases
 */
 
-#include <libmemcached/memcached.h>
+#include <libmemcached-1.0/memcached.h>
 #include <libmemcached/is.h>
 #include <libmemcached/server_instance.h>
 
-#include <libhashkit/hashkit.h>
+#include <libhashkit-1.0/hashkit.h>
 
 #include <cassert>
 #include <cerrno>
@@ -78,6 +78,7 @@
 #include "tests/ketama.h"
 #include "tests/namespace.h"
 #include "tests/parser.h"
+#include "tests/callbacks.h"
 #include "tests/pool.h"
 #include "tests/print.h"
 #include "tests/replication.h"
@@ -86,7 +87,7 @@
 
 using namespace libtest;
 
-#include <libmemcached/memcached_util.h>
+#include <libmemcached/util.h>
 
 #include "hash_results.h"
 
@@ -981,28 +982,6 @@ static test_return_t read_through(memcached_st *memc)
   return TEST_SUCCESS;
 }
 
-static memcached_return_t delete_trigger(memcached_st *,
-                                         const char *key,
-                                         size_t key_length)
-{
-  assert(key);
-  assert(key_length);
-
-  return MEMCACHED_SUCCESS;
-}
-
-static test_return_t delete_through(memcached_st *memc)
-{
-  memcached_trigger_delete_key_fn callback;
-
-  callback= (memcached_trigger_delete_key_fn)delete_trigger;
-
-  test_compare(MEMCACHED_SUCCESS, 
-               memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, *(void**)&callback));
-
-  return TEST_SUCCESS;
-}
-
 static test_return_t get_test(memcached_st *memc)
 {
   memcached_return_t rc;
@@ -3733,7 +3712,7 @@ static test_return_t selection_of_namespace_tests(memcached_st *memc)
   /* Make sure be default none exists */
   value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
   test_null(value);
-  test_compare_got(MEMCACHED_FAILURE, rc, memcached_strerror(NULL, rc));
+  test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
 
   /* Test a clean set */
   test_compare(MEMCACHED_SUCCESS,
@@ -3749,8 +3728,8 @@ static test_return_t selection_of_namespace_tests(memcached_st *memc)
                memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, NULL));
 
   value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
-  test_false(value);
-  test_compare_got(MEMCACHED_FAILURE, rc, memcached_strerror(NULL, rc));
+  test_null(value);
+  test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
 
   /* Now setup for main test */
   test_compare(MEMCACHED_SUCCESS,
@@ -3770,9 +3749,8 @@ static test_return_t selection_of_namespace_tests(memcached_st *memc)
                  memcached_callback_set(memc, MEMCACHED_CALLBACK_NAMESPACE, NULL));
 
     value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
-    test_false(value);
-    test_true(rc == MEMCACHED_FAILURE);
-    test_true(value == NULL);
+    test_null(value);
+    test_compare(MEMCACHED_SUCCESS, rc);
 
     /* Test a long key for failure */
     /* TODO, extend test to determine based on setting, what result should be */
@@ -3802,10 +3780,10 @@ static test_return_t set_namespace(memcached_st *memc)
   const char *key= "mine";
   char *value;
 
-  /* Make sure be default none exists */
+  // Make sure we default to a null namespace
   value= (char*)memcached_callback_get(memc, MEMCACHED_CALLBACK_NAMESPACE, &rc);
   test_null(value);
-  test_compare_got(MEMCACHED_FAILURE, rc, memcached_strerror(NULL, rc));
+  test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc));
 
   /* Test a clean set */
   test_compare(MEMCACHED_SUCCESS,
@@ -4358,6 +4336,10 @@ static void* connection_release(void *arg)
 
 static test_return_t connection_pool3_test(memcached_st *memc)
 {
+#ifdef __APPLE__
+  return TEST_SKIPPED;
+#endif
+
   memcached_pool_st* pool= memcached_pool_create(memc, 1, 1);
   test_true(pool);
 
@@ -4385,17 +4367,24 @@ static test_return_t connection_pool3_test(memcached_st *memc)
 
   memcached_return_t rc;
   memcached_st *pop_memc;
+  // We do a hard loop, and try N times
   int counter= 5;
   do
   {
     struct timespec relative_time= { 0, 0 };
     pop_memc= memcached_pool_fetch(pool, &relative_time, &rc);
 
+    if (memcached_success(rc))
+    {
+      break;
+    }
+
     if (memcached_failed(rc))
     {
       test_null(pop_memc);
+      test_true(rc != MEMCACHED_TIMEOUT); // As long as relative_time is zero, MEMCACHED_TIMEOUT is invalid
     }
-  } while (rc == MEMCACHED_TIMEOUT and --counter);
+  } while (--counter);
 
   if (memcached_failed(rc)) // Cleanup thread since we will exit once we test.
   {
@@ -5954,7 +5943,7 @@ test_st tests[] ={
   {"bad_key", true, (test_callback_fn*)bad_key_test },
   {"memcached_server_cursor", true, (test_callback_fn*)memcached_server_cursor_test },
   {"read_through", true, (test_callback_fn*)read_through },
-  {"delete_through", true, (test_callback_fn*)delete_through },
+  {"delete_through", true, (test_callback_fn*)test_MEMCACHED_CALLBACK_DELETE_TRIGGER },
   {"noreply", true, (test_callback_fn*)noreply_test},
   {"analyzer", true, (test_callback_fn*)analyzer_test},
   {"memcached_pool_st", true, (test_callback_fn*)connection_pool_test },
@@ -5979,6 +5968,7 @@ test_st behavior_tests[] ={
   {"MEMCACHED_BEHAVIOR_TCP_KEEPALIVE", false, (test_callback_fn*)MEMCACHED_BEHAVIOR_TCP_KEEPALIVE_test},
   {"MEMCACHED_BEHAVIOR_TCP_KEEPIDLE", false, (test_callback_fn*)MEMCACHED_BEHAVIOR_TCP_KEEPIDLE_test},
   {"MEMCACHED_BEHAVIOR_POLL_TIMEOUT", false, (test_callback_fn*)MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test},
+  {"MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY", false, (test_callback_fn*)test_MEMCACHED_CALLBACK_DELETE_TRIGGER_and_MEMCACHED_BEHAVIOR_NOREPLY},
   {0, 0, 0}
 };