X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Ffunction.c;h=ba3c32193943569d89ff9b928f08565b0af56788;hb=e4d80b668c93b1abfa4f299904551f56d44a9351;hp=cfa5f5970c422e72f7e4e88998cab83c855eed98;hpb=a07bb255b72aa59d0f4c4c63bb71695b2e9df537;p=awesomized%2Flibmemcached diff --git a/tests/function.c b/tests/function.c index cfa5f597..ba3c3219 100644 --- a/tests/function.c +++ b/tests/function.c @@ -872,7 +872,6 @@ static test_return set_test2(memcached_st *memc) static test_return set_test3(memcached_st *memc) { memcached_return rc; - char *key= "foo"; char *value; size_t value_length= 8191; unsigned int x; @@ -883,8 +882,13 @@ static test_return set_test3(memcached_st *memc) for (x= 0; x < value_length; x++) value[x] = (char) (x % 127); - for (x= 0; x < 1; x++) + /* The dump test relies on there being at least 32 items in memcached */ + for (x= 0; x < 32; x++) { + char key[16]; + + sprintf(key, "foo%u", x); + rc= memcached_set(memc, key, strlen(key), value, value_length, (time_t)0, (uint32_t)0); @@ -2557,7 +2561,7 @@ static test_return string_alloc_with_size_toobig(memcached_st *memc) { memcached_string_st *string; - string= memcached_string_create(memc, NULL, INT64_MAX); + string= memcached_string_create(memc, NULL, SIZE_MAX); assert(string == NULL); return 0; @@ -2604,7 +2608,7 @@ static test_return string_alloc_append_toobig(memcached_st *memc) rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); assert(rc == MEMCACHED_SUCCESS); } - rc= memcached_string_append(string, buffer, INT64_MAX); + rc= memcached_string_append(string, buffer, SIZE_MAX); assert(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); memcached_string_free(string); @@ -3035,7 +3039,7 @@ static void my_free(memcached_st *ptr __attribute__((unused)), void *mem) static void *my_malloc(memcached_st *ptr __attribute__((unused)), const size_t size) { - return malloc(size); + return calloc(1, size); } static void *my_realloc(memcached_st *ptr __attribute__((unused)), void *mem, const size_t size) @@ -3342,12 +3346,12 @@ static test_return noreply_test(memcached_st *memc) uint32_t flags; memcached_result_st results_obj; memcached_result_st *results; - ret=memcached_mget(memc, keys, lengths, 1); + ret= memcached_mget(memc, keys, lengths, 1); assert(ret == MEMCACHED_SUCCESS); - results=memcached_result_create(memc, &results_obj); + results= memcached_result_create(memc, &results_obj); assert(results); - results=memcached_fetch_result(memc, &results_obj, &ret); + results= memcached_fetch_result(memc, &results_obj, &ret); assert(results); assert(ret == MEMCACHED_SUCCESS); uint64_t cas= memcached_result_cas(results); @@ -3390,6 +3394,45 @@ static test_return analyzer_test(memcached_st *memc) return TEST_SUCCESS; } +/* Count the objects */ +static memcached_return callback_dump_counter(memcached_st *ptr __attribute__((unused)), + const char *key __attribute__((unused)), + size_t key_length __attribute__((unused)), + void *context) +{ + uint32_t *counter= (uint32_t *)context; + + *counter= *counter + 1; + + return MEMCACHED_SUCCESS; +} + +static test_return dump_test(memcached_st *memc) +{ + memcached_return rc; + uint32_t counter= 0; + memcached_dump_func callbacks[1]; + test_return main_rc; + + callbacks[0]= &callback_dump_counter; + + /* No support for Binary protocol yet */ + if (memc->flags & MEM_BINARY_PROTOCOL) + return TEST_SUCCESS; + + main_rc= set_test3(memc); + + assert (main_rc == TEST_SUCCESS); + + rc= memcached_dump(memc, callbacks, (void *)&counter, 1); + assert(rc == MEMCACHED_SUCCESS); + + /* We may have more then 32 if our previous flush has not completed */ + assert(counter >= 32); + + return TEST_SUCCESS; +} + #ifdef HAVE_LIBMEMCACHEDUTIL static void* connection_release(void *arg) { struct { @@ -3832,6 +3875,7 @@ test_st tests[] ={ {"set", 0, set_test }, {"set2", 0, set_test2 }, {"set3", 0, set_test3 }, + {"dump", 1, dump_test}, {"add", 1, add_test }, {"replace", 1, replace_test }, {"delete", 1, delete_test },