From: Brian Aker Date: Tue, 14 Feb 2012 01:00:16 +0000 (-0800) Subject: Update tests for cleanup. X-Git-Tag: 1.0.5~49 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=487f4d6fb9d8a0bcc9be11ded428cbd870c131e8;p=m6w6%2Flibmemcached Update tests for cleanup. --- diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 7f8342da..07cec98f 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -3953,7 +3953,6 @@ test_return_t memcached_get_hashkit_test (memcached_st *) */ test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *) { - const char *key= "MemcachedLives"; size_t len; uint32_t flags; memcached_return rc; @@ -3962,7 +3961,9 @@ test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *) memcached_st *tl_memc_h= memcached(test_literal_param("--server=localhost:9898 --server=localhost:9899")); // This server should not exist // See if memcached is reachable. - char *value= memcached_get(tl_memc_h, key, strlen(key), &len, &flags, &rc); + char *value= memcached_get(tl_memc_h, + test_literal_param(__func__), + &len, &flags, &rc); test_false(value); test_zero(len); @@ -3978,13 +3979,14 @@ test_return_t memcached_get_MEMCACHED_ERRNO(memcached_st *) */ test_return_t memcached_get_MEMCACHED_NOTFOUND(memcached_st *memc) { - const char *key= "MemcachedKeyNotEXIST"; size_t len; uint32_t flags; memcached_return rc; // See if memcached is reachable. - char *value= memcached_get(memc, key, strlen(key), &len, &flags, &rc); + char *value= memcached_get(memc, + test_literal_param(__func__), + &len, &flags, &rc); test_false(value); test_zero(len); @@ -3999,26 +4001,23 @@ test_return_t memcached_get_MEMCACHED_NOTFOUND(memcached_st *memc) 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. */ -test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *memc) +test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *) { - (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_st *tl_memc_h= memcached_create(NULL); + memcached_server_st *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_by_key(tl_memc_h, key, strlen(key), key, strlen(key), &len, &flags, &rc); + char *value= memcached_get_by_key(tl_memc_h, + test_literal_param(__func__), // Key + test_literal_param(__func__), // Value + &len, &flags, &rc); test_false(value); test_zero(len); @@ -4034,14 +4033,15 @@ test_return_t memcached_get_by_key_MEMCACHED_ERRNO(memcached_st *memc) */ test_return_t memcached_get_by_key_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_by_key(memc, key, strlen(key), key, strlen(key), &len, &flags, &rc); + char *value= memcached_get_by_key(memc, + test_literal_param(__func__), // Key + test_literal_param(__func__), // Value + &len, &flags, &rc); test_false(value); test_zero(len); @@ -4054,18 +4054,18 @@ test_return_t regression_bug_434484(memcached_st *memc) { test_skip(TEST_SUCCESS, pre_binary(memc)); - const char *key= "regression_bug_434484"; - size_t keylen= strlen(key); - - memcached_return_t ret= memcached_append(memc, key, keylen, key, keylen, 0, 0); - test_compare(MEMCACHED_NOTSTORED, ret); + test_compare(MEMCACHED_NOTSTORED, + memcached_append(memc, + test_literal_param(__func__), // Key + test_literal_param(__func__), // Value + 0, 0)); - size_t size= 2048 * 1024; - char *data= (char*)calloc(1, size); - test_true(data); + libtest::vchar_t data; + data.resize(2048 * 1024); test_compare(MEMCACHED_E2BIG, - memcached_set(memc, key, keylen, data, size, 0, 0)); - free(data); + memcached_set(memc, + test_literal_param(__func__), // Key + &data[0], data.size(), 0, 0)); return TEST_SUCCESS; } @@ -4086,27 +4086,16 @@ test_return_t regression_bug_434843(memcached_st *original_memc) */ memcached_st *memc= create_single_instance_memcached(original_memc, "--BINARY-PROTOCOL"); - const size_t max_keys= 1024; - char **keys= (char**)calloc(max_keys, sizeof(char*)); - size_t *key_length= (size_t *)calloc(max_keys, sizeof(size_t)); - - for (size_t x= 0; x < max_keys; ++x) - { - char k[251]; - - key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%lu", (unsigned long)x); - keys[x]= strdup(k); - test_true(keys[x]); - } + keys_st keys(1024); /* * Run two times.. the first time we should have 100% cache miss, * and the second time we should have 100% cache hits */ - for (size_t y= 0; y < 2; y++) + for (ptrdiff_t y= 0; y < 2; y++) { test_compare(MEMCACHED_SUCCESS, - memcached_mget(memc, (const char**)keys, key_length, max_keys)); + memcached_mget(memc, keys.keys_ptr(), keys.lengths_ptr(), keys.size())); // One the first run we should get a NOT_FOUND, but on the second some data // should be returned. @@ -4120,9 +4109,10 @@ test_return_t regression_bug_434843(memcached_st *original_memc) test_false(counter); - for (size_t x= 0; x < max_keys; ++x) + for (size_t x= 0; x < keys.size(); ++x) { - rc= memcached_add(memc, keys[x], key_length[x], + rc= memcached_add(memc, + keys.key_at(x), keys.length_at(x), blob, sizeof(blob), 0, 0); test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } @@ -4130,18 +4120,10 @@ test_return_t regression_bug_434843(memcached_st *original_memc) else { /* Verify that we received all of the key/value pairs */ - test_compare(counter, max_keys); + test_compare(counter, keys.size()); } } - /* Release allocated resources */ - for (size_t x= 0; x < max_keys; ++x) - { - free(keys[x]); - } - free(keys); - free(key_length); - memcached_free(memc); return TEST_SUCCESS; @@ -4149,9 +4131,7 @@ test_return_t regression_bug_434843(memcached_st *original_memc) test_return_t regression_bug_434843_buffered(memcached_st *memc) { - memcached_return_t rc; - rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true)); return regression_bug_434843(memc); } @@ -4210,23 +4190,24 @@ test_return_t regression_bug_442914(memcached_st *memc) uint32_t number_of_hosts= memcached_server_count(memc); memc->number_of_hosts= 1; - char k[250]; - size_t len; - for (uint32_t x= 0; x < 250; ++x) { - len= (size_t)snprintf(k, sizeof(k), "%0250u", x); - memcached_return_t rc= memcached_delete(memc, k, len, 0); + char key[250]; + size_t len= (size_t)snprintf(key, sizeof(key), "%0250u", x); + memcached_return_t rc= memcached_delete(memc, key, len, 0); test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_last_error_message(memc)); } - len= snprintf(k, sizeof(k), "%037u", 251U); - - memcached_return_t rc= memcached_delete(memc, k, len, 0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + // Delete, and then delete again to look for not found + { + char key[250]; + size_t len= snprintf(key, sizeof(key), "%037u", 251U); + memcached_return_t rc= memcached_delete(memc, key, len, 0); + test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); - test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0)); - test_compare(MEMCACHED_NOTFOUND, memcached_delete(memc, k, len, 0)); + test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0)); + test_compare(MEMCACHED_NOTFOUND, memcached_delete(memc, key, len, 0)); + } memc->number_of_hosts= number_of_hosts;