+ (void)memc;
+
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
+
+ hash_val= memcached_generate_hash_value(*ptr, strlen(*ptr), MEMCACHED_HASH_JENKINS);
+ test_true(jenkins_values[x] == hash_val);
+ }
+
+ 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;
+ const hashkit_st *kit;
+ hashkit_st new_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);
+
+ hashkit_clone(&new_kit, kit);
+ hash_rc= hashkit_set_custom_function(&new_kit, hash_md5_test_function, NULL);
+ test_true(hash_rc == HASHKIT_SUCCESS);
+
+ memcached_set_hashkit(memc, &new_kit);
+
+ /*
+ 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(&new_kit, hash_crc_test_function, NULL);
+ test_true(hash_rc == HASHKIT_SUCCESS);
+
+ memcached_set_hashkit(memc, &new_kit);
+
+ /*
+ 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;
+}
+
+/*
+ Test case adapted from John Gorman <johngorman2@gmail.com>
+
+ We are testing the error condition when we connect to a server via memcached_get()
+ but find that the server is not available.
+*/
+static test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *memc)
+{
+ (void)memc;
+ memcached_st *tl_memc_h;
+ memcached_server_st *servers;
+
+ const char *key= "MemcachedLives";
+ size_t len;
+ uint32_t flags;
+ memcached_return rc;
+ char *value;
+
+ // Create a handle.
+ tl_memc_h= memcached_create(NULL);
+ servers= memcached_servers_parse("localhost:9898,localhost:9899"); // This server should not exist
+ memcached_server_push(tl_memc_h, servers);
+ memcached_server_list_free(servers);
+
+ // See if memcached is reachable.
+ value= memcached_get(tl_memc_h, key, strlen(key), &len, &flags, &rc);
+
+ test_false(value);
+ test_true(len == 0);
+ test_false(rc == MEMCACHED_SUCCESS);
+
+ memcached_free(tl_memc_h);
+
+ return TEST_SUCCESS;
+}
+
+/*
+ We connect to a server which exists, but search for a key that does not exist.
+*/
+static test_return_t memcached_get_MEMCACHED_NOTFOUND(memcached_st *memc)
+{
+ const char *key= "MemcachedKeyNotEXIST";
+ size_t len;
+ uint32_t flags;
+ memcached_return rc;
+ char *value;
+
+ // See if memcached is reachable.
+ value= memcached_get(memc, key, strlen(key), &len, &flags, &rc);
+
+ test_false(value);
+ test_true(len == 0);
+ test_true(rc == MEMCACHED_NOTFOUND);
+
+ return TEST_SUCCESS;
+}
+
+/*
+ Test case adapted from John Gorman <johngorman2@gmail.com>
+
+ We are testing the error condition when we connect to a server via memcached_get_by_key()
+ but find that the server is not available.
+*/
+static test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *memc)
+{
+ (void)memc;
+ memcached_st *tl_memc_h;
+ memcached_server_st *servers;