From b1f0b5ce09ce9e64f4a5f30591877fae1abc973d Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 9 Apr 2012 08:22:46 -0700 Subject: [PATCH] Additional test key.w x --- tests/include.am | 14 +++--- tests/libmemcached-1.0/all_tests.h | 1 + tests/libmemcached-1.0/encoding_key.cc | 61 ++++++++++++++++++++++++++ tests/libmemcached-1.0/encoding_key.h | 1 + 4 files changed, 70 insertions(+), 7 deletions(-) diff --git a/tests/include.am b/tests/include.am index f4c6dcfd..c0d7771c 100644 --- a/tests/include.am +++ b/tests/include.am @@ -66,28 +66,28 @@ test: check check-local: $(TEST_DOCS) @echo "Tests completed" -test-mem: tests/var tests/libmemcached-1.0/testapp +test-mem: tests/libmemcached-1.0/testapp @tests/libmemcached-1.0/testapp test-sasl: tests/sasl @tests/sasl -test-atom: tests/var tests/atomsmasher +test-atom: tests/atomsmasher @tests/atomsmasher -test-plus: tests/var tests/testplus +test-plus: tests/testplus @tests/testplus -test-hash: tests/var tests/testhashkit +test-hash: tests/testhashkit @tests/testhashkit -test-hashplus: tests/var tests/hash_plus +test-hashplus: tests/hash_plus @tests/hash_plus -test-cycle: tests/var tests/cycle +test-cycle: tests/cycle @tests/cycle -test-memcapable: tests/var tests/memcapable +test-memcapable: tests/memcapable @tests/memcapable pahole-mem: tests/testapp diff --git a/tests/libmemcached-1.0/all_tests.h b/tests/libmemcached-1.0/all_tests.h index 9f01ae29..4dab69ff 100644 --- a/tests/libmemcached-1.0/all_tests.h +++ b/tests/libmemcached-1.0/all_tests.h @@ -414,6 +414,7 @@ test_st memcached_set_encoding_key_TESTS[] ={ {"memcached_set_encoding_key() +increment_with_initial()", true, (test_callback_fn*)memcached_set_encoding_key_increment_with_initial_TEST }, {"memcached_set_encoding_key() +decrement_with_initial()", true, (test_callback_fn*)memcached_set_encoding_key_decrement_with_initial_TEST }, {"memcached_set_encoding_key() +set() +get() +cloen()", true, (test_callback_fn*)memcached_set_encoding_key_set_get_clone_TEST }, + {"memcached_set_encoding_key() +set() +get() increase value size", true, (test_callback_fn*)memcached_set_encoding_key_set_grow_key_TEST }, {0, 0, (test_callback_fn*)0} }; diff --git a/tests/libmemcached-1.0/encoding_key.cc b/tests/libmemcached-1.0/encoding_key.cc index 114de1f1..b9edbc67 100644 --- a/tests/libmemcached-1.0/encoding_key.cc +++ b/tests/libmemcached-1.0/encoding_key.cc @@ -317,3 +317,64 @@ test_return_t memcached_set_encoding_key_set_get_clone_TEST(memcached_st* memc) return TEST_SUCCESS; } + +test_return_t memcached_set_encoding_key_set_grow_key_TEST(memcached_st* memc) +{ + memcached_st *memc_no_crypt= memcached_clone(NULL, memc); + test_true(memc_no_crypt); + test_compare(MEMCACHED_SUCCESS, memcached_set_encoding_key(memc, test_literal_param(__func__))); + + size_t payload_size[] = { 100, 1000, 10000, 1000000, 1000000, 0 }; + libtest::vchar_t payload; + for (size_t *ptr= payload_size; *ptr; ptr++) + { + payload.reserve(*ptr); + for (size_t x= payload.size(); x < *ptr; x++) + { + payload.push_back(rand()); + } + + { + memcached_return_t rc= memcached_set(memc, + test_literal_param(__func__), // Key + &payload[0], payload.size(), // Value + time_t(0), + uint32_t(0)); + + // If we run out of space on the server, we just end the test early. + if (rc == MEMCACHED_SERVER_MEMORY_ALLOCATION_FAILURE) + { + break; + } + test_compare_hint(MEMCACHED_SUCCESS, rc, memcached_last_error_message(memc)); + } + + { + memcached_return_t rc; + size_t value_length; + char *value; + test_true((value= memcached_get(memc, + test_literal_param(__func__), // Key + &value_length, NULL, &rc))); + test_compare(MEMCACHED_SUCCESS, rc); + test_compare(payload.size(), value_length); + test_memcmp(&payload[0], value, value_length); + + size_t raw_value_length; + char *raw_value; + test_true((raw_value= memcached_get(memc_no_crypt, + test_literal_param(__func__), // Key + &raw_value_length, NULL, &rc))); + test_compare(MEMCACHED_SUCCESS, rc); + test_ne_compare(payload.size(), raw_value_length); + test_ne_compare(0, memcmp(&payload[0], raw_value, raw_value_length)); + + free(value); + free(raw_value); + } + } + + memcached_free(memc_no_crypt); + + return TEST_SUCCESS; +} diff --git a/tests/libmemcached-1.0/encoding_key.h b/tests/libmemcached-1.0/encoding_key.h index 3abbf0e6..4be0cb14 100644 --- a/tests/libmemcached-1.0/encoding_key.h +++ b/tests/libmemcached-1.0/encoding_key.h @@ -48,3 +48,4 @@ test_return_t memcached_set_encoding_key_decrement_with_initial_TEST(memcached_s test_return_t memcached_set_encoding_key_prepend_TEST(memcached_st*); test_return_t memcached_set_encoding_key_append_TEST(memcached_st*); test_return_t memcached_set_encoding_key_set_get_clone_TEST(memcached_st*); +test_return_t memcached_set_encoding_key_set_grow_key_TEST(memcached_st*); -- 2.30.2