Merge in additional test for increment with namespace key.
authorBrian Aker <brian@tangent.org>
Tue, 28 Jun 2011 22:15:36 +0000 (15:15 -0700)
committerBrian Aker <brian@tangent.org>
Tue, 28 Jun 2011 22:15:36 +0000 (15:15 -0700)
ChangeLog
docs/memcached_callback.rst
libmemcached/callback.cc
libmemcached/callback.h
libmemcached/get.cc
tests/include.am
tests/mem_functions.cc
tests/namespace.cc

index 200846cf6ad260dc44e4aa79009869a45fac5448..2c62d617e3b37d20110fb2c75f8acd0787993772 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+0.51
+
+  * memcached_callback_set() now takes its data argument as const
+
+
 0.50 Mon Jun 20 10:36:57 PDT 2011
  * Updates to C++ interface 
  * Custom free allocators need to now check for value before calling free.
index d5be9af6a053dd2dae5019b416e57db83506e89c..060e43ab69664c8a2cd2236c85106e57bda7c19f 100644 (file)
@@ -14,7 +14,7 @@ SYNOPSIS
 
 #include <libmemcached/memcached.h>
  
-.. c:function:: memcached_return_t memcached_callback_set (memcached_st *ptr, memcached_callback_t flag, void *data);
+.. c:function:: memcached_return_t memcached_callback_set (memcached_st *ptr, memcached_callback_t flag, const void *data);
  
 .. c:function:: void * memcached_callback_get (memcached_st *ptr, memcached_callback_t flag, memcached_return_t *error);
 
index 3625992ef8734dfafa5687261c6479cc54928051..4eab7e49b3be520ead688087543be360f5e45562 100644 (file)
@@ -20,7 +20,7 @@
 
 memcached_return_t memcached_callback_set(memcached_st *ptr,
                                           const memcached_callback_t flag,
-                                          void *data)
+                                          const void *data)
 {
   switch (flag)
   {
@@ -30,7 +30,7 @@ memcached_return_t memcached_callback_set(memcached_st *ptr,
     }
   case MEMCACHED_CALLBACK_USER_DATA:
     {
-      ptr->user_data= data;
+      ptr->user_data= const_cast<void *>(data);
       break;
     }
   case MEMCACHED_CALLBACK_CLEANUP_FUNCTION:
index 816e966b935553d3bbad81e3fad364d1f19d16cf..a9465d2e3e2061e9438860904cf5769d4ba8b1bc 100644 (file)
@@ -50,7 +50,7 @@ extern "C" {
 LIBMEMCACHED_API
 memcached_return_t memcached_callback_set(memcached_st *ptr,
                                           const memcached_callback_t flag,
-                                          void *data);
+                                          const void *data);
 LIBMEMCACHED_API
 void *memcached_callback_get(memcached_st *ptr,
                              const memcached_callback_t flag,
index ae0711f0439c9ed3c66615e1053b060ad65a042e..bcc2dd8cd409adf61e4917bc1a3be6a36cb051e1 100644 (file)
@@ -67,6 +67,10 @@ char *memcached_get_by_key(memcached_st *ptr,
                            uint32_t *flags,
                            memcached_return_t *error)
 {
+  memcached_return_t unused;
+  if (error == NULL)
+    error= &unused;
+
   unlikely (ptr->flags.use_udp)
   {
     if (value_length) 
@@ -81,8 +85,8 @@ char *memcached_get_by_key(memcached_st *ptr,
 
   /* Request the key */
   *error= memcached_mget_by_key_real(ptr, group_key, group_key_length,
-                                     (const char * const *)&key,
-                                     &key_length, 1, false);
+                                     (const char * const *)&key, &key_length, 
+                                     1, false);
   assert(ptr->query_id == query_id +1);
 
 
index 7ce21a1279f394e3bc4dec93e2ced4431a68a981..fb72ea8d78edbf78faff1945d9541e091116cfc3 100644 (file)
@@ -34,6 +34,7 @@ noinst_HEADERS+= \
                 tests/ketama_test_cases.h \
                 tests/ketama_test_cases_spy.h \
                 tests/libmemcached_world.h \
+                tests/namespace.h \
                 tests/parser.h \
                 tests/deprecated.h \
                 tests/pool.h \
@@ -58,6 +59,7 @@ tests_testapp_SOURCES= \
                       tests/deprecated.cc \
                       tests/error_conditions.cc \
                       tests/mem_functions.cc \
+                      tests/namespace.cc \
                       tests/parser.cc \
                       tests/pool.cc \
                       tests/print.cc \
index 3c2064f1131cb97d3cf549578e05b886070c3b49..159848ea9e2dac0ef8c9ceadb94e29efb4302934 100644 (file)
@@ -66,6 +66,7 @@
 #include "tests/deprecated.h"
 #include "tests/parser.h"
 #include "tests/pool.h"
+#include "tests/namespace.h"
 #include "tests/string.h"
 #include "tests/replication.h"
 #include "tests/basic.h"
@@ -6485,9 +6486,7 @@ test_st virtual_bucket_tests[] ={
 
 test_st namespace_tests[] ={
   {"basic tests", 0, (test_callback_fn*)selection_of_namespace_tests },
-#if 0
   {"increment", 0, (test_callback_fn*)memcached_increment_namespace },
-#endif
   {0, 0, (test_callback_fn*)0}
 };
 
index 15975c6485eb589c425995e2b9c8ade18731265a..21c14e404ccc7c8e3d842f8920be18ea2faaaa4b 100644 (file)
  */
 
 #include <libtest/common.h>
+#include <libmemcached/memcached.h>
+#include <tests/namespace.h>
 
 test_return_t memcached_increment_namespace(memcached_st *memc)
 {
   uint64_t new_number;
-  memcached_return_t rc;
-  const char *key= "number";
-  const char *value= "0";
 
   test_compare(MEMCACHED_SUCCESS, 
                memcached_set(memc, 
@@ -64,13 +63,40 @@ test_return_t memcached_increment_namespace(memcached_st *memc)
 
   memcached_st *clone= memcached_clone(NULL, memc);
 
+  test_compare(MEMCACHED_SUCCESS, 
+               memcached_callback_set(clone, MEMCACHED_CALLBACK_NAMESPACE, "all_your_bases"));
+
   test_compare(MEMCACHED_NOTFOUND, 
-               memcached_increment(memc,
+               memcached_increment(clone,
                                    test_literal_param("number"),
                                    1, &new_number));
-  test_compare(1, new_number);
 
+  test_compare(MEMCACHED_SUCCESS, 
+               memcached_add(clone, 
+                             test_literal_param("number"),
+                             test_literal_param("10"),
+                             (time_t)0, (uint32_t)0));
+
+  char *value= memcached_get(clone, 
+                             test_literal_param("number"),
+                             0, 0, 0);
+  test_true(value);
+  test_compare(2, strlen(value));
+  test_strcmp("10", value);
+
+  test_compare(MEMCACHED_SUCCESS, 
+               memcached_increment(clone,
+                                   test_literal_param("number"),
+                                   1, &new_number));
+  test_compare(11, new_number);
+
+  test_compare(MEMCACHED_SUCCESS, 
+               memcached_increment(memc,
+                                   test_literal_param("number"),
+                                   1, &new_number));
+  test_compare(3, new_number);
 
+  memcached_free(clone);
 
   return TEST_SUCCESS;
 }