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)
{
{"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}
};
--- /dev/null
+/*
+ C++ to libmemcit
+*/
+#include "test.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <libmemcached/memcached.h>
+
+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<test_callback_fn>(exists_test) },
+ { "new", 0, reinterpret_cast<test_callback_fn>(new_test) },
+ { "copy", 0, reinterpret_cast<test_callback_fn>(copy_test) },
+ { "assign", 0, reinterpret_cast<test_callback_fn>(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;
+}