From: Brian Aker Date: Tue, 28 Jun 2011 22:15:36 +0000 (-0700) Subject: Merge in additional test for increment with namespace key. X-Git-Tag: 0.51~1^2~9^2~15 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=36dd2e646b1290791dfcd2e8d94ab02591f32904;p=m6w6%2Flibmemcached Merge in additional test for increment with namespace key. --- diff --git a/ChangeLog b/ChangeLog index 200846cf..2c62d617 100644 --- 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. diff --git a/docs/memcached_callback.rst b/docs/memcached_callback.rst index d5be9af6..060e43ab 100644 --- a/docs/memcached_callback.rst +++ b/docs/memcached_callback.rst @@ -14,7 +14,7 @@ SYNOPSIS #include -.. 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); diff --git a/libmemcached/callback.cc b/libmemcached/callback.cc index 3625992e..4eab7e49 100644 --- a/libmemcached/callback.cc +++ b/libmemcached/callback.cc @@ -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(data); break; } case MEMCACHED_CALLBACK_CLEANUP_FUNCTION: diff --git a/libmemcached/callback.h b/libmemcached/callback.h index 816e966b..a9465d2e 100644 --- a/libmemcached/callback.h +++ b/libmemcached/callback.h @@ -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, diff --git a/libmemcached/get.cc b/libmemcached/get.cc index ae0711f0..bcc2dd8c 100644 --- a/libmemcached/get.cc +++ b/libmemcached/get.cc @@ -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); diff --git a/tests/include.am b/tests/include.am index 7ce21a12..fb72ea8d 100644 --- a/tests/include.am +++ b/tests/include.am @@ -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 \ diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index 3c2064f1..159848ea 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -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} }; diff --git a/tests/namespace.cc b/tests/namespace.cc index 15975c64..21c14e40 100644 --- a/tests/namespace.cc +++ b/tests/namespace.cc @@ -36,13 +36,12 @@ */ #include +#include +#include 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; }