X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Flibmemcached-1.0%2Fmem_functions.cc;h=a4d424f0b66f44bf1dd0c0bcac9b70b850cfb7c3;hb=603d93c1346162f4f9d2e3065e5120e948139dda;hp=29009ce3e2d9a73bfcf1da91f95fba474a2f1e8b;hpb=f9e87d61f6870b6ffbd83d9eaa81ee579d8c4964;p=awesomized%2Flibmemcached diff --git a/tests/libmemcached-1.0/mem_functions.cc b/tests/libmemcached-1.0/mem_functions.cc index 29009ce3..a4d424f0 100644 --- a/tests/libmemcached-1.0/mem_functions.cc +++ b/tests/libmemcached-1.0/mem_functions.cc @@ -95,7 +95,7 @@ using namespace libtest; #define GLOBAL_COUNT 10000 #define GLOBAL2_COUNT 100 #define SERVERS_TO_CREATE 5 -static uint32_t global_count; +static uint32_t global_count= GLOBAL2_COUNT; static pairs_st *global_pairs; static const char *global_keys[GLOBAL_COUNT]; @@ -112,6 +112,16 @@ static test_return_t pre_binary(memcached_st *memc) return TEST_SUCCESS; } +static bool return_value_based_on_buffering(memcached_st *memc) +{ + if (memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)) + { + return MEMCACHED_BUFFERED; + } + + return MEMCACHED_SUCCESS; +} + static memcached_st * create_single_instance_memcached(const memcached_st *original_memc, const char *options) { /* @@ -512,7 +522,7 @@ static test_return_t set_test(memcached_st *memc) test_literal_param("foo"), test_literal_param("when we sanitize"), time_t(0), (uint32_t)0); - test_true_got(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_true_got(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); return TEST_SUCCESS; } @@ -643,7 +653,6 @@ static test_return_t cas2_test(memcached_st *memc) static test_return_t cas_test(memcached_st *memc) { - memcached_return_t rc; const char *key= "fun"; size_t key_length= strlen(key); const char *value= "we the people"; @@ -655,17 +664,15 @@ static test_return_t cas_test(memcached_st *memc) memcached_result_st results_obj; memcached_result_st *results; - unsigned int set= 1; - rc= memcached_flush(memc, 0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, memcached_flush(memc, 0)); - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set); + test_skip(true, memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true)); - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, key, strlen(key), + value, strlen(value), + (time_t)0, (uint32_t)0)); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, keys, keylengths, 1)); @@ -673,6 +680,7 @@ static test_return_t cas_test(memcached_st *memc) results= memcached_result_create(memc, &results_obj); test_true(results); + memcached_return_t rc; results= memcached_fetch_result(memc, &results_obj, &rc); test_true(results); test_compare(MEMCACHED_SUCCESS, rc); @@ -705,32 +713,31 @@ static test_return_t cas_test(memcached_st *memc) static test_return_t prepend_test(memcached_st *memc) { - memcached_return_t rc; const char *key= "fig"; const char *value= "people"; - char *out_value= NULL; - size_t value_length; - uint32_t flags; - rc= memcached_flush(memc, 0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_flush(memc, 0)); - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_set(memc, key, strlen(key), + value, strlen(value), + time_t(0), uint32_t(0))); - rc= memcached_prepend(memc, key, strlen(key), - "the ", strlen("the "), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_prepend(memc, key, strlen(key), + "the ", strlen("the "), + time_t(0), uint32_t(0))); - rc= memcached_prepend(memc, key, strlen(key), - "we ", strlen("we "), - (time_t)0, (uint32_t)0); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_prepend(memc, key, strlen(key), + "we ", strlen("we "), + time_t(0), uint32_t(0))); - out_value= memcached_get(memc, key, strlen(key), + size_t value_length; + uint32_t flags; + memcached_return_t rc; + char *out_value= memcached_get(memc, key, strlen(key), &value_length, &flags, &rc); test_memcmp(out_value, "we the people", strlen("we the people")); test_compare(strlen("we the people"), value_length); @@ -756,7 +763,7 @@ static test_return_t add_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); memcached_quit(memc); rc= memcached_add(memc, key, strlen(key), value, strlen(value), @@ -765,11 +772,11 @@ static test_return_t add_test(memcached_st *memc) /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */ if (setting_value) { - test_true(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED); + test_true(rc == MEMCACHED_NOTSTORED or rc == MEMCACHED_STORED); } else { - test_true(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_DATA_EXISTS); + test_true(rc == MEMCACHED_NOTSTORED or rc == MEMCACHED_DATA_EXISTS); } return TEST_SUCCESS; @@ -820,17 +827,18 @@ static test_return_t replace_test(memcached_st *memc) static test_return_t delete_test(memcached_st *memc) { - memcached_return_t rc; - const char *key= "foo"; - const char *value= "when we sanitize"; - - rc= memcached_set(memc, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_compare(return_value_based_on_buffering(memc), + memcached_set(memc, + test_literal_param(__func__), + test_literal_param("when we sanitize"), + time_t(0), uint32_t(0))); - rc= memcached_delete(memc, key, strlen(key), (time_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + memcached_return_t rc= memcached_delete(memc, + test_literal_param(__func__), + time_t(0)); + test_compare_hint(MEMCACHED_SUCCESS, + rc, + memcached_last_error_message(memc)); return TEST_SUCCESS; } @@ -1042,7 +1050,7 @@ static test_return_t get_test(memcached_st *memc) uint64_t query_id= memcached_query_id(memc); rc= memcached_delete(memc, key, strlen(key), (time_t)0); - test_true(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND); + test_true_got(rc == MEMCACHED_BUFFERED || rc == MEMCACHED_NOTFOUND, memcached_last_error_message(memc)); test_compare(query_id +1, memcached_query_id(memc)); string= memcached_get(memc, key, strlen(key), @@ -2483,37 +2491,36 @@ static test_return_t user_supplied_bug8(memcached_st *) /* Test flag store/retrieve */ static test_return_t user_supplied_bug7(memcached_st *memc) { - const char *keys= "036790384900"; - size_t key_length= strlen(keys); - char return_key[MEMCACHED_MAX_KEY]; - size_t return_key_length; - char *value; - size_t value_length; - uint32_t flags; char *insert_data= new (std::nothrow) char[VALUE_SIZE_BUG5]; + test_true(insert_data); - for (unsigned int x= 0; x < VALUE_SIZE_BUG5; x++) + for (size_t x= 0; x < VALUE_SIZE_BUG5; x++) { insert_data[x]= (signed char)rand(); } memcached_flush(memc, 0); - flags= 245; - test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length, - insert_data, VALUE_SIZE_BUG5, - (time_t)0, flags)); + const char *keys= "036790384900"; + size_t key_length= strlen(keys); + test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, keys, key_length, + insert_data, VALUE_SIZE_BUG5, + time_t(0), 245U), + memcached_last_error_message(memc)); memcached_return_t rc; - flags= 0; - value= memcached_get(memc, keys, key_length, - &value_length, &flags, &rc); + size_t value_length; + uint32_t flags= 0; + char *value= memcached_get(memc, keys, key_length, + &value_length, &flags, &rc); test_compare(245U, flags); test_true(value); free(value); test_compare(MEMCACHED_SUCCESS, memcached_mget(memc, &keys, &key_length, 1)); + char return_key[MEMCACHED_MAX_KEY]; + size_t return_key_length; flags= 0; value= memcached_fetch(memc, return_key, &return_key_length, &value_length, &flags, &rc); @@ -2795,19 +2802,20 @@ static test_return_t user_supplied_bug15(memcached_st *memc) /* Check the return sizes on FLAGS to make sure it stores 32bit unsigned values correctly */ static test_return_t user_supplied_bug16(memcached_st *memc) { - memcached_return_t rc= memcached_set(memc, test_literal_param("mykey"), - NULL, 0, - (time_t)0, UINT32_MAX); + test_compare_hint(MEMCACHED_SUCCESS, memcached_set(memc, test_literal_param("mykey"), + NULL, 0, + (time_t)0, UINT32_MAX), + memcached_last_error_message(memc)); - test_compare(MEMCACHED_SUCCESS, rc); size_t length; uint32_t flags; + memcached_return_t rc; char *value= memcached_get(memc, test_literal_param("mykey"), &length, &flags, &rc); test_compare(MEMCACHED_SUCCESS, rc); - test_true(value == NULL); + test_null(value); test_zero(length); test_compare(flags, UINT32_MAX); @@ -3115,7 +3123,7 @@ static test_return_t generate_data(memcached_st *memc) { unsigned int check_execute= execute_set(memc, global_pairs, global_count); - test_compare(check_execute, global_count); + test_compare(global_count, check_execute); return TEST_SUCCESS; } @@ -3934,11 +3942,11 @@ static test_return_t MEMCACHED_BEHAVIOR_POLL_TIMEOUT_test(memcached_st *memc) static test_return_t noreply_test(memcached_st *memc) { test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, true)); test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, true)); test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, true)); test_compare(1LLU, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NOREPLY)); test_compare(1LLU, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS)); test_compare(1LLU, memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS)); @@ -5088,14 +5096,14 @@ static test_return_t memcached_stat_execute_test(memcached_st *memc) memcached_return_t rc= memcached_stat_execute(memc, NULL, stat_printer, NULL); test_compare(MEMCACHED_SUCCESS, rc); - rc= memcached_stat_execute(memc, "slabs", stat_printer, NULL); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, "slabs", stat_printer, NULL)); - rc= memcached_stat_execute(memc, "items", stat_printer, NULL); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, "items", stat_printer, NULL)); - rc= memcached_stat_execute(memc, "sizes", stat_printer, NULL); - test_compare(MEMCACHED_SUCCESS, rc); + test_compare(MEMCACHED_SUCCESS, + memcached_stat_execute(memc, "sizes", stat_printer, NULL)); return TEST_SUCCESS; } @@ -5125,7 +5133,7 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); - test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_true(rc == MEMCACHED_SUCCESS or rc == MEMCACHED_BUFFERED); instance= memcached_server_instance_by_position(memc, 0); @@ -5155,53 +5163,45 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) */ static test_return_t wrong_failure_counter_two_test(memcached_st *memc) { - memcached_return rc; - - memcached_st *memc_clone; - memc_clone= memcached_clone(NULL, memc); - test_true(memc_clone); - /* Set value to force connection to the server */ const char *key= "marmotte"; const char *value= "milka"; - char *string = NULL; - size_t string_length; - uint32_t flags; - rc= memcached_set(memc_clone, key, strlen(key), - value, strlen(value), - (time_t)0, (uint32_t)0); - test_true_got(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED, memcached_strerror(NULL, rc)); + test_compare_hint(MEMCACHED_SUCCESS, + memcached_set(memc, key, strlen(key), + value, strlen(value), + (time_t)0, (uint32_t)0), + memcached_last_error_message(memc)); /* put failure limit to 1 */ test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, true)); /* Put a retry timeout to effectively activate failure_limit effect */ test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, true)); /* change behavior that triggers memcached_quit()*/ test_compare(MEMCACHED_SUCCESS, - memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1)); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, true)); /* Check if we still are connected */ - string= memcached_get(memc_clone, key, strlen(key), - &string_length, &flags, &rc); + uint32_t flags; + size_t string_length; + memcached_return rc; + char *string= memcached_get(memc, key, strlen(key), + &string_length, &flags, &rc); test_compare_got(MEMCACHED_SUCCESS, rc, memcached_strerror(NULL, rc)); test_true(string); free(string); - memcached_free(memc_clone); return TEST_SUCCESS; } - - /* * Test that ensures mget_execute does not end into recursive calls that finally fails */