From 2885b9da6342076013cb3632a1d43e59a6cfa397 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Fri, 22 Jan 2010 14:41:53 -0800 Subject: [PATCH] Adding test, showing off how to add a custom function to libmemcached. --- .bzrignore | 9 +++-- tests/mem_functions.c | 76 +++++++++++++++++++++++++++++++++++++++++++ tests/mem_plus.cc | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+), 3 deletions(-) create mode 100644 tests/mem_plus.cc diff --git a/.bzrignore b/.bzrignore index c78c4048..527ee066 100644 --- a/.bzrignore +++ b/.bzrignore @@ -64,6 +64,8 @@ libmemcached-0.30-1.src.rpm libmemcached-0.30-1.x86_64.rpm libmemcached-0.31-1.src.rpm libmemcached-0.31-1.x86_64.rpm +libmemcached-0.37-1.src.rpm +libmemcached-0.37-1.x86_64.rpm libmemcached-?.??/ libmemcached.pop libmemcached/configure.h @@ -161,6 +163,8 @@ memflush.pop memrm.pop memslap.pop memstat.pop +patch +patch2 stamp-h1 support/Makefile support/Makefile.in @@ -168,12 +172,11 @@ support/libmemcached-fc.spec support/libmemcached.pc support/libmemcached.spec tests/atomsmasher +tests/hashplus +tests/memplus tests/output.cmp tests/startservers tests/testapp tests/testhashkit tests/testplus tests/udptest -tests/hashplus -patch -patch2 diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 281f5938..cf48940b 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -5086,6 +5086,81 @@ static test_return_t jenkins_run (memcached_st *memc __attribute__((unused))) return TEST_SUCCESS; } +static uint32_t hash_md5_test_function(const char *string, size_t string_length, void *context) +{ + (void)context; + return libhashkit_md5(string, string_length); +} + +static uint32_t hash_crc_test_function(const char *string, size_t string_length, void *context) +{ + (void)context; + return libhashkit_crc32(string, string_length); +} + +static test_return_t memcached_get_hashkit_test (memcached_st *memc) +{ + uint32_t x; + const char **ptr; + hashkit_st *kit; + hashkit_return_t hash_rc; + + uint32_t md5_hosts[]= {4U, 1U, 0U, 1U, 4U, 2U, 0U, 3U, 0U, 0U, 3U, 1U, 0U, 0U, 1U, 3U, 0U, 0U, 0U, 3U, 1U, 0U, 4U, 4U, 3U}; + uint32_t crc_hosts[]= {2U, 4U, 1U, 0U, 2U, 4U, 4U, 4U, 1U, 2U, 3U, 4U, 3U, 4U, 1U, 3U, 3U, 2U, 0U, 0U, 0U, 1U, 2U, 4U, 0U}; + + kit= memcached_get_hashkit(memc); + + hash_rc= hashkit_set_custom_function(kit, hash_md5_test_function, NULL); + test_true(hash_rc == HASHKIT_SUCCESS); + + /* + Verify Setting the hash. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= hashkit_digest(kit, *ptr, strlen(*ptr)); + test_true(md5_values[x] == hash_val); + } + + + /* + Now check memcached_st. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr)); + test_true(md5_hosts[x] == hash_val); + } + + hash_rc= hashkit_set_custom_function(kit, hash_crc_test_function, NULL); + test_true(hash_rc == HASHKIT_SUCCESS); + + /* + Verify Setting the hash. + */ + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= hashkit_digest(kit, *ptr, strlen(*ptr)); + test_true(crc_values[x] == hash_val); + } + + for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++) + { + uint32_t hash_val; + + hash_val= memcached_generate_hash(memc, *ptr, strlen(*ptr)); + test_true(crc_hosts[x] == hash_val); + } + + return TEST_SUCCESS; +} + static test_return_t ketama_compatibility_libmemcached(memcached_st *trash) { @@ -6013,6 +6088,7 @@ test_st hash_tests[] ={ {"hsieh", 0, (test_callback_fn)hsieh_run }, {"murmur", 0, (test_callback_fn)murmur_run }, {"jenkis", 0, (test_callback_fn)jenkins_run }, + {"memcached_get_hashkit", 0, (test_callback_fn)memcached_get_hashkit_test }, {0, 0, (test_callback_fn)0} }; diff --git a/tests/mem_plus.cc b/tests/mem_plus.cc new file mode 100644 index 00000000..d62ae723 --- /dev/null +++ b/tests/mem_plus.cc @@ -0,0 +1,74 @@ +/* + C++ to libmemcit +*/ +#include "test.h" +#include +#include +#include + +#include + +static test_return_t exists_test(void *obj) +{ + Memcached memc; + (void)obj; + (void)memc; + + return TEST_SUCCESS; +} + +static test_return_t new_test(void *obj) +{ + Memcached *memc= new Memcached; + (void)obj; + + (void)memc; + + delete memc; + + return TEST_SUCCESS; +} + +static test_return_t copy_test(void *obj) +{ + Memcached *memc= new Memcached; + Memcached *copy(memc); + (void)obj; + + (void)copy; + + delete memc; + + return TEST_SUCCESS; +} + +static test_return_t assign_test(void *obj) +{ + Memcached memc; + Memcached copy; + (void)obj; + + copy= memc; + + (void)copy; + + return TEST_SUCCESS; +} + +test_st basic[] ={ + { "exists", 0, reinterpret_cast(exists_test) }, + { "new", 0, reinterpret_cast(new_test) }, + { "copy", 0, reinterpret_cast(copy_test) }, + { "assign", 0, reinterpret_cast(assign_test) }, + { 0, 0, 0} +}; + +collection_st collection[] ={ + {"basic", 0, 0, basic}, + {0, 0, 0, 0} +}; + +void get_world(world_st *world) +{ + world->collections= collection; +} -- 2.30.2