+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+
+ rc= memcached_delete(memc, key, strlen(key), (time_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+
+ return 0;
+}
+
+test_return flush_test(memcached_st *memc)
+{
+ memcached_return rc;
+
+ rc= memcached_flush(memc, 0);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ return 0;
+}
+
+memcached_return server_function(memcached_st *ptr, memcached_server_st *server, void *context)
+{
+ /* Do Nothing */
+
+ return MEMCACHED_SUCCESS;
+}
+
+test_return memcached_server_cursor_test(memcached_st *memc)
+{
+ char *context= "foo bad";
+ memcached_server_function callbacks[1];
+
+ callbacks[0]= server_function;
+ memcached_server_cursor(memc, callbacks, context, 1);
+
+ return 0;
+}
+
+test_return bad_key_test(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo bad";
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+ memcached_st *clone;
+ unsigned int set= 1;
+
+ clone= memcached_clone(NULL, memc);
+ assert(clone);
+
+ (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
+
+ string= memcached_get(clone, key, strlen(key),
+ &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_BAD_KEY_PROVIDED);
+ assert(string_length == 0);
+ assert(!string);
+
+ set= 0;
+ (void)memcached_behavior_set(clone, MEMCACHED_BEHAVIOR_VERIFY_KEY, set);
+ string= memcached_get(clone, key, strlen(key),
+ &string_length, &flags, &rc);
+ assert(rc == MEMCACHED_NOTFOUND);
+ assert(string_length == 0);
+ assert(!string);
+
+ memcached_free(clone);
+
+ return 0;
+}
+
+#define READ_THROUGH_VALUE "set for me"
+memcached_return read_through_trigger(memcached_st *memc,
+ char *key, size_t key_length,
+ memcached_result_st *result)
+{
+
+ return memcached_result_set_value(result, READ_THROUGH_VALUE, strlen(READ_THROUGH_VALUE));
+}
+
+test_return read_through(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+
+ assert(rc == MEMCACHED_NOTFOUND);
+ assert(string_length == 0);
+ assert(!string);
+
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_GET_FAILURE, read_through_trigger);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(string_length == strlen(READ_THROUGH_VALUE));
+ assert(!strcmp(READ_THROUGH_VALUE, string));
+ free(string);
+
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(string_length == strlen(READ_THROUGH_VALUE));
+ assert(!strcmp(READ_THROUGH_VALUE, string));
+ free(string);
+
+ return 0;
+}
+
+memcached_return delete_trigger(memcached_st *ptr, char *key, size_t key_length)
+{
+ assert(key);
+
+ return MEMCACHED_SUCCESS;
+}
+
+test_return delete_through(memcached_st *memc)
+{
+ memcached_trigger_delete_key callback;
+ memcached_return rc;
+
+ callback= delete_trigger;
+
+ rc= memcached_callback_set(memc, MEMCACHED_CALLBACK_DELETE_TRIGGER, callback);
+ assert(rc == MEMCACHED_SUCCESS);
+
+ return 0;
+}
+
+test_return get_test(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+
+ rc= memcached_delete(memc, key, strlen(key), (time_t)0);
+ assert(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND);
+
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+
+ assert(rc == MEMCACHED_NOTFOUND);
+ assert(string_length == 0);
+ assert(!string);
+
+ return 0;
+}
+
+test_return get_test2(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *value= "when we sanitize";
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+
+ rc= memcached_set(memc, key, strlen(key),
+ value, strlen(value),
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+
+ assert(string);
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(string_length == strlen(value));
+ assert(!memcmp(string, value, string_length));
+
+ free(string);
+
+ return 0;
+}
+
+test_return set_test2(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *value= "train in the brain";
+ size_t value_length= strlen(value);
+ unsigned int x;
+
+ for (x= 0; x < 10; x++)
+ {
+ rc= memcached_set(memc, key, strlen(key),
+ value, value_length,
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+ }
+
+ return 0;
+}
+
+test_return set_test3(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *value;
+ size_t value_length= 8191;
+ unsigned int x;
+
+ value = (char*)malloc(value_length);
+ assert(value);
+
+ for (x= 0; x < value_length; x++)
+ value[x] = (char) (x % 127);
+
+ for (x= 0; x < 1; x++)
+ {
+ rc= memcached_set(memc, key, strlen(key),
+ value, value_length,
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+ }
+
+ free(value);
+
+ return 0;
+}
+
+test_return get_test3(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *value;
+ size_t value_length= 8191;
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+ int x;
+
+ value = (char*)malloc(value_length);
+ assert(value);
+
+ for (x= 0; x < value_length; x++)
+ value[x] = (char) (x % 127);
+
+ rc= memcached_set(memc, key, strlen(key),
+ value, value_length,
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(string);
+ assert(string_length == value_length);
+ assert(!memcmp(string, value, string_length));
+
+ free(string);
+ free(value);
+
+ return 0;
+}
+
+test_return get_test4(memcached_st *memc)
+{
+ memcached_return rc;
+ char *key= "foo";
+ char *value;
+ size_t value_length= 8191;
+ char *string;
+ size_t string_length;
+ uint32_t flags;
+ int x;
+
+ value = (char*)malloc(value_length);
+ assert(value);
+
+ for (x= 0; x < value_length; x++)
+ value[x] = (char) (x % 127);
+
+ rc= memcached_set(memc, key, strlen(key),
+ value, value_length,
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
+
+ for (x= 0; x < 10; x++)
+ {
+ string= memcached_get(memc, key, strlen(key),
+ &string_length, &flags, &rc);
+
+ assert(rc == MEMCACHED_SUCCESS);
+ assert(string);
+ assert(string_length == value_length);
+ assert(!memcmp(string, value, string_length));
+ free(string);
+ }
+
+ free(value);
+
+ return 0;
+}
+
+/* Do not copy the style of this code, I just access hosts to testthis function */
+test_return stats_servername_test(memcached_st *memc)
+{
+ memcached_return rc;
+ memcached_stat_st stat;
+ rc= memcached_stat_servername(&stat, NULL,
+ memc->hosts[0].hostname,
+ memc->hosts[0].port);
+
+ return 0;
+}
+
+test_return increment_test(memcached_st *memc)
+{
+ uint64_t new_number;
+ memcached_return rc;
+ char *key= "number";
+ char *value= "0";
+
+ rc= memcached_set(memc, key, strlen(key),
+ value, strlen(value),
+ (time_t)0, (uint32_t)0);
+ assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);