X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=tests%2Ffunction.c;h=29de4f734b40972f263826e3f5ef805be60d85c4;hb=bf4da83be9c867a2ecb10615297aa5dd5cb1d6ab;hp=fadd41cd91de481c92db54ecd047d543d8e2cb89;hpb=3936140765093cf4e3b28e0a4b837a67b79c1cbf;p=m6w6%2Flibmemcached diff --git a/tests/function.c b/tests/function.c index fadd41cd..29de4f73 100644 --- a/tests/function.c +++ b/tests/function.c @@ -80,7 +80,7 @@ static test_return_t server_list_null_test(memcached_st *ptr __attribute__((unu } #define TEST_PORT_COUNT 7 -uint32_t test_ports[TEST_PORT_COUNT]; +in_port_t test_ports[TEST_PORT_COUNT]; static memcached_return_t server_display_function(memcached_st *ptr __attribute__((unused)), memcached_server_st *server, void *context) { @@ -106,10 +106,10 @@ static test_return_t server_sort_test(memcached_st *ptr __attribute__((unused)) for (x= 0; x < TEST_PORT_COUNT; x++) { - test_ports[x]= (uint32_t)random() % 64000; + test_ports[x]= (in_port_t)random() % 64000; rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0); - test_truth(local_memc->number_of_hosts == x + 1); - test_truth(local_memc->hosts[0].count == x+1); + test_truth(memcached_server_count(local_memc) == x + 1); + test_truth(memcached_servers_count(local_memc->hosts) == x+1); test_truth(rc == MEMCACHED_SUCCESS); } @@ -177,10 +177,10 @@ static test_return_t server_unsort_test(memcached_st *ptr __attribute__((unused for (x= 0; x < TEST_PORT_COUNT; x++) { - test_ports[x]= (uint32_t)(random() % 64000); + test_ports[x]= (in_port_t)(random() % 64000); rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0); - test_truth(local_memc->number_of_hosts == x+1); - test_truth(local_memc->hosts[0].count == x+1); + test_truth(memcached_server_count(local_memc) == x+1); + test_truth(memcached_servers_count(local_memc->hosts) == x+1); test_truth(rc == MEMCACHED_SUCCESS); } @@ -849,8 +849,8 @@ static test_return_t read_through(memcached_st *memc) } static memcached_return_t delete_trigger(memcached_st *ptr __attribute__((unused)), - const char *key, - size_t key_length __attribute__((unused))) + const char *key, + size_t key_length __attribute__((unused))) { assert(key); @@ -2030,11 +2030,7 @@ static test_return_t user_supplied_bug4(memcached_st *memc) size_t return_value_length; /* Here we free everything before running a bunch of mget tests */ - { - memcached_server_list_free(memc->hosts); - memc->hosts= NULL; - memc->number_of_hosts= 0; - } + memcached_servers_reset(memc); /* We need to empty the server before continueing test */ @@ -2715,7 +2711,7 @@ static test_return_t user_supplied_bug18(memcached_st *trash) memcached_server_push(memc, server_pool); /* verify that the server list was parsed okay. */ - test_truth(memc->number_of_hosts == 8); + test_truth(memcached_server_count(memc) == 8); test_truth(strcmp(server_pool[0].hostname, "10.0.1.1") == 0); test_truth(server_pool[0].port == 11211); test_truth(server_pool[0].weight == 600); @@ -2866,7 +2862,7 @@ static test_return_t auto_eject_hosts(memcached_st *trash) memcached_server_push(memc, server_pool); /* verify that the server list was parsed okay. */ - test_truth(memc->number_of_hosts == 8); + test_truth(memcached_server_count(memc) == 8); test_truth(strcmp(server_pool[0].hostname, "10.0.1.1") == 0); test_truth(server_pool[0].port == 11211); test_truth(server_pool[0].weight == 600); @@ -3371,7 +3367,7 @@ static test_return_t pre_nonblock_binary(memcached_st *memc) memcached_st *memc_clone; memc_clone= memcached_clone(NULL, memc); - assert(memc_clone); + test_truth(memc_clone); // The memcached_version needs to be done on a clone, because the server // will not toggle protocol on an connection. memcached_version(memc_clone); @@ -3381,7 +3377,7 @@ static test_return_t pre_nonblock_binary(memcached_st *memc) memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0); rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1); test_truth(rc == MEMCACHED_SUCCESS); - assert(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1); + test_truth(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1); } else { @@ -3536,9 +3532,9 @@ static test_return_t pre_replication(memcached_st *memc) */ memcached_return_t rc; rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, - memc->number_of_hosts - 1); + memcached_server_count(memc) - 1); test_truth(rc == MEMCACHED_SUCCESS); - test_truth(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS) == memc->number_of_hosts - 1); + test_truth(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS) == memcached_server_count(memc) - 1); return rc == MEMCACHED_SUCCESS ? TEST_SUCCESS : TEST_SKIPPED; } @@ -3843,9 +3839,7 @@ static test_return_t pre_unix_socket(memcached_st *memc) memcached_return_t rc; struct stat buf; - memcached_server_list_free(memc->hosts); - memc->hosts= NULL; - memc->number_of_hosts= 0; + memcached_servers_reset(memc); if (stat("/tmp/memcached.socket", &buf)) return TEST_SKIPPED; @@ -3935,7 +3929,7 @@ static test_return_t noreply_test(memcached_st *memc) ** way it is supposed to do!!!! */ int no_msg=0; - for (uint32_t x=0; x < memc->number_of_hosts; ++x) + for (uint32_t x=0; x < memcached_server_count(memc); ++x) no_msg+=(int)(memc->hosts[x].cursor_active); test_truth(no_msg == 0); @@ -4212,7 +4206,7 @@ static test_return_t replication_get_test(memcached_st *memc) * within the library, and this is not a supported interface. * This is to verify correct behavior in the library */ - for (uint32_t host= 0; host < memc->number_of_hosts; ++host) + for (uint32_t host= 0; host < memcached_server_count(memc); ++host) { memcached_st *memc_clone= memcached_clone(NULL, memc); memc_clone->hosts[host].port= 0; @@ -4410,11 +4404,11 @@ static void increment_request_id(uint16_t *id) static uint16_t *get_udp_request_ids(memcached_st *memc) { - uint16_t *ids= malloc(sizeof(uint16_t) * memc->number_of_hosts); + uint16_t *ids= malloc(sizeof(uint16_t) * memcached_server_count(memc)); assert(ids != NULL); unsigned int x; - for (x= 0; x < memc->number_of_hosts; x++) + for (x= 0; x < memcached_server_count(memc); x++) ids[x]= get_udp_datagram_request_id((struct udp_datagram_header_st *) memc->hosts[x].write_buffer); return ids; @@ -4426,7 +4420,7 @@ static test_return_t post_udp_op_check(memcached_st *memc, uint16_t *expected_re memcached_server_st *cur_server = memc->hosts; uint16_t *cur_req_ids = get_udp_request_ids(memc); - for (x= 0; x < memc->number_of_hosts; x++) + for (x= 0; x < memcached_server_count(memc); x++) { test_truth(cur_server[x].cursor_active == 0); test_truth(cur_req_ids[x] == expected_req_ids[x]); @@ -4449,7 +4443,7 @@ static test_return_t init_udp(memcached_st *memc) || memc->hosts[0].micro_version < 6) return TEST_SKIPPED; - uint32_t num_hosts= memc->number_of_hosts; + uint32_t num_hosts= memcached_server_count(memc); unsigned int x= 0; memcached_server_st servers[num_hosts]; memcpy(servers, memc->hosts, sizeof(memcached_server_st) * num_hosts); @@ -4512,7 +4506,7 @@ static test_return_t set_udp_behavior_test(memcached_st *memc) test_truth(memc->flags.use_udp); test_truth(memc->flags.no_reply); - test_truth(memc->number_of_hosts == 0); + test_truth(memcached_server_count(memc) == 0); memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP,0); test_truth(! (memc->flags.use_udp)); @@ -4619,7 +4613,7 @@ static test_return_t udp_verbosity_test(memcached_st *memc) memcached_return_t rc; uint16_t *expected_ids= get_udp_request_ids(memc); unsigned int x; - for (x= 0; x < memc->number_of_hosts;x++) + for (x= 0; x < memcached_server_count(memc); x++) increment_request_id(&expected_ids[x]); rc= memcached_verbosity(memc,3); @@ -4639,7 +4633,7 @@ static test_return_t udp_flush_test(memcached_st *memc) memcached_return_t rc; uint16_t *expected_ids= get_udp_request_ids(memc); unsigned int x; - for (x= 0; x < memc->number_of_hosts;x++) + for (x= 0; x < memcached_server_count(memc);x++) increment_request_id(&expected_ids[x]); rc= memcached_flush(memc,0); @@ -4964,28 +4958,29 @@ static test_return_t ketama_compatibility_libmemcached(memcached_st *trash) memcached_server_push(memc, server_pool); /* verify that the server list was parsed okay. */ - assert(memc->number_of_hosts == 8); - assert(strcmp(server_pool[0].hostname, "10.0.1.1") == 0); - assert(server_pool[0].port == 11211); - assert(server_pool[0].weight == 600); - assert(strcmp(server_pool[2].hostname, "10.0.1.3") == 0); - assert(server_pool[2].port == 11211); - assert(server_pool[2].weight == 200); - assert(strcmp(server_pool[7].hostname, "10.0.1.8") == 0); - assert(server_pool[7].port == 11211); - assert(server_pool[7].weight == 100); + test_truth(memcached_server_count(memc) == 8); + test_strcmp(server_pool[0].hostname, "10.0.1.1"); + test_truth(server_pool[0].port == 11211); + test_truth(server_pool[0].weight == 600); + test_strcmp(server_pool[2].hostname, "10.0.1.3"); + test_truth(server_pool[2].port == 11211); + test_truth(server_pool[2].weight == 200); + test_strcmp(server_pool[7].hostname, "10.0.1.8"); + test_truth(server_pool[7].port == 11211); + test_truth(server_pool[7].weight == 100); /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets * us test the boundary wraparound. */ - assert(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); + test_truth(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); /* verify the standard ketama set. */ for (x= 0; x < 99; x++) { uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key)); char *hostname = memc->hosts[server_idx].hostname; - assert(strcmp(hostname, ketama_test_cases[x].server) == 0); + + test_strcmp(hostname, ketama_test_cases[x].server); } memcached_server_list_free(server_pool); @@ -5020,28 +5015,28 @@ static test_return_t ketama_compatibility_spymemcached(memcached_st *trash) memcached_server_push(memc, server_pool); /* verify that the server list was parsed okay. */ - assert(memc->number_of_hosts == 8); - assert(strcmp(server_pool[0].hostname, "10.0.1.1") == 0); - assert(server_pool[0].port == 11211); - assert(server_pool[0].weight == 600); - assert(strcmp(server_pool[2].hostname, "10.0.1.3") == 0); - assert(server_pool[2].port == 11211); - assert(server_pool[2].weight == 200); - assert(strcmp(server_pool[7].hostname, "10.0.1.8") == 0); - assert(server_pool[7].port == 11211); - assert(server_pool[7].weight == 100); + test_truth(memcached_server_count(memc) == 8); + test_strcmp(server_pool[0].hostname, "10.0.1.1"); + test_truth(server_pool[0].port == 11211); + test_truth(server_pool[0].weight == 600); + test_strcmp(server_pool[2].hostname, "10.0.1.3"); + test_truth(server_pool[2].port == 11211); + test_truth(server_pool[2].weight == 200); + test_strcmp(server_pool[7].hostname, "10.0.1.8"); + test_truth(server_pool[7].port == 11211); + test_truth(server_pool[7].weight == 100); /* VDEAAAAA hashes to fffcd1b5, after the last continuum point, and lets * us test the boundary wraparound. */ - assert(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); + test_truth(memcached_generate_hash(memc, (char *)"VDEAAAAA", 8) == memc->continuum[0].index); /* verify the standard ketama set. */ for (x= 0; x < 99; x++) { uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases_spy[x].key, strlen(ketama_test_cases_spy[x].key)); char *hostname = memc->hosts[server_idx].hostname; - assert(strcmp(hostname, ketama_test_cases_spy[x].server) == 0); + test_strcmp(hostname, ketama_test_cases_spy[x].server); } memcached_server_list_free(server_pool); @@ -5063,13 +5058,13 @@ static test_return_t regression_bug_434484(memcached_st *memc) size_t keylen= strlen(key); ret= memcached_append(memc, key, keylen, key, keylen, 0, 0); - assert(ret == MEMCACHED_NOTSTORED); + test_truth(ret == MEMCACHED_NOTSTORED); size_t size= 2048 * 1024; void *data= calloc(1, size); - assert(data != NULL); + test_truth(data != NULL); ret= memcached_set(memc, key, keylen, data, size, 0, 0); - assert(ret == MEMCACHED_E2BIG); + test_truth(ret == MEMCACHED_E2BIG); free(data); return TEST_SUCCESS; @@ -5093,7 +5088,7 @@ static test_return_t regression_bug_434843(memcached_st *memc) * 1024 (that should satisfy most users don't you think?). Future versions * will include a mget_execute function call if you need a higher number. */ - uint32_t number_of_hosts= memc->number_of_hosts; + uint32_t number_of_hosts= memcached_server_count(memc); memc->number_of_hosts= 1; const size_t max_keys= 1024; char **keys= calloc(max_keys, sizeof(char*)); @@ -5104,7 +5099,7 @@ static test_return_t regression_bug_434843(memcached_st *memc) char k[251]; key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%u", x); keys[x]= strdup(k); - assert(keys[x] != NULL); + test_truth(keys[x] != NULL); } /* @@ -5114,24 +5109,24 @@ static test_return_t regression_bug_434843(memcached_st *memc) for (int y= 0; y < 2; ++y) { rc= memcached_mget(memc, (const char**)keys, key_length, max_keys); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1); if (y == 0) { /* The first iteration should give me a 100% cache miss. verify that*/ - assert(counter == 0); + test_truth(counter == 0); char blob[1024]= { 0 }; for (int x= 0; x < (int)max_keys; ++x) { rc= memcached_add(memc, keys[x], key_length[x], blob, sizeof(blob), 0, 0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } } else { /* Verify that we received all of the key/value pairs */ - assert(counter == (unsigned int)max_keys); + test_truth(counter == (unsigned int)max_keys); } } @@ -5142,6 +5137,7 @@ static test_return_t regression_bug_434843(memcached_st *memc) free(key_length); memc->number_of_hosts= number_of_hosts; + return TEST_SUCCESS; } @@ -5149,7 +5145,7 @@ static test_return_t regression_bug_434843_buffered(memcached_st *memc) { memcached_return_t rc; rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); return regression_bug_434843(memc); } @@ -5158,29 +5154,30 @@ static test_return_t regression_bug_421108(memcached_st *memc) { memcached_return_t rc; memcached_stat_st *memc_stat= memcached_stat(memc, NULL, &rc); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); char *bytes= memcached_stat_get_value(memc, memc_stat, "bytes", &rc); - assert(rc == MEMCACHED_SUCCESS); - assert(bytes != NULL); + test_truth(rc == MEMCACHED_SUCCESS); + test_truth(bytes != NULL); char *bytes_read= memcached_stat_get_value(memc, memc_stat, "bytes_read", &rc); - assert(rc == MEMCACHED_SUCCESS); - assert(bytes_read != NULL); + test_truth(rc == MEMCACHED_SUCCESS); + test_truth(bytes_read != NULL); char *bytes_written= memcached_stat_get_value(memc, memc_stat, "bytes_written", &rc); - assert(rc == MEMCACHED_SUCCESS); - assert(bytes_written != NULL); + test_truth(rc == MEMCACHED_SUCCESS); + test_truth(bytes_written != NULL); - assert(strcmp(bytes, bytes_read) != 0); - assert(strcmp(bytes, bytes_written) != 0); + test_truth(strcmp(bytes, bytes_read) != 0); + test_truth(strcmp(bytes, bytes_written) != 0); /* Release allocated resources */ free(bytes); free(bytes_read); free(bytes_written); memcached_stat_free(NULL, memc_stat); + return TEST_SUCCESS; } @@ -5199,10 +5196,10 @@ static test_return_t regression_bug_442914(memcached_st *memc) { memcached_return_t rc; rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_TCP_NODELAY, 1); - uint32_t number_of_hosts= memc->number_of_hosts; + uint32_t number_of_hosts= memcached_server_count(memc); memc->number_of_hosts= 1; char k[250]; @@ -5212,17 +5209,17 @@ static test_return_t regression_bug_442914(memcached_st *memc) { len= (size_t)snprintf(k, sizeof(k), "%0250u", x); rc= memcached_delete(memc, k, len, 0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); } len= (size_t)snprintf(k, sizeof(k), "%037u", 251); rc= memcached_delete(memc, k, len, 0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); rc= memcached_delete(memc, k, len, 0); - assert(rc == MEMCACHED_NOTFOUND); + test_truth(rc == MEMCACHED_NOTFOUND); memc->number_of_hosts= number_of_hosts; @@ -5231,13 +5228,13 @@ static test_return_t regression_bug_442914(memcached_st *memc) static test_return_t regression_bug_447342(memcached_st *memc) { - if (memc->number_of_hosts < 3 || pre_replication(memc) != MEMCACHED_SUCCESS) + if (memcached_server_count(memc) < 3 || pre_replication(memc) != MEMCACHED_SUCCESS) return TEST_SKIPPED; memcached_return_t rc; rc= memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 2); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); const size_t max_keys= 100; char **keys= calloc(max_keys, sizeof(char*)); @@ -5248,9 +5245,9 @@ static test_return_t regression_bug_447342(memcached_st *memc) char k[251]; key_length[x]= (size_t)snprintf(k, sizeof(k), "0200%u", x); keys[x]= strdup(k); - assert(keys[x] != NULL); + test_truth(keys[x] != NULL); rc= memcached_set(memc, k, key_length[x], k, key_length[x], 0, 0); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); } /* @@ -5272,13 +5269,13 @@ static test_return_t regression_bug_447342(memcached_st *memc) * into the servers */ rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); unsigned int counter= 0; memcached_execute_fn callbacks[1]= { [0]= &callback_counter }; rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1); /* Verify that we received all of the key/value pairs */ - assert(counter == (unsigned int)max_keys); + test_truth(counter == (unsigned int)max_keys); memcached_quit(memc); /* @@ -5294,11 +5291,11 @@ static test_return_t regression_bug_447342(memcached_st *memc) memc->hosts[2].port= 0; rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); counter= 0; rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1); - assert(counter == (unsigned int)max_keys); + test_truth(counter == (unsigned int)max_keys); /* restore the memc handle */ memc->hosts[0].port= port0; @@ -5312,7 +5309,7 @@ static test_return_t regression_bug_447342(memcached_st *memc) if (x & 1) { rc= memcached_delete(memc, keys[x], key_length[x], 0); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); } } @@ -5322,11 +5319,11 @@ static test_return_t regression_bug_447342(memcached_st *memc) /* now retry the command, this time we should have cache misses */ rc= memcached_mget(memc, (const char* const *)keys, key_length, max_keys); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); counter= 0; rc= memcached_fetch_execute(memc, callbacks, (void *)&counter, 1); - assert(counter == (unsigned int)(max_keys >> 1)); + test_truth(counter == (unsigned int)(max_keys >> 1)); /* Release allocated resources */ for (size_t x= 0; x < max_keys; ++x) @@ -5344,8 +5341,8 @@ static test_return_t regression_bug_447342(memcached_st *memc) static test_return_t regression_bug_463297(memcached_st *memc) { memcached_st *memc_clone= memcached_clone(NULL, memc); - assert(memc_clone != NULL); - assert(memcached_version(memc_clone) == MEMCACHED_SUCCESS); + test_truth(memc_clone != NULL); + test_truth(memcached_version(memc_clone) == MEMCACHED_SUCCESS); if (memc_clone->hosts[0].major_version > 1 || (memc_clone->hosts[0].major_version == 1 && @@ -5353,44 +5350,45 @@ static test_return_t regression_bug_463297(memcached_st *memc) { /* Binary protocol doesn't support deferred delete */ memcached_st *bin_clone= memcached_clone(NULL, memc); - assert(bin_clone != NULL); - assert(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS); - assert(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS); + test_truth(bin_clone != NULL); + test_truth(memcached_behavior_set(bin_clone, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1) == MEMCACHED_SUCCESS); + test_truth(memcached_delete(bin_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS); memcached_free(bin_clone); memcached_quit(memc_clone); /* If we know the server version, deferred delete should fail * with invalid arguments */ - assert(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS); + test_truth(memcached_delete(memc_clone, "foo", 3, 1) == MEMCACHED_INVALID_ARGUMENTS); /* If we don't know the server version, we should get a protocol error */ memcached_return_t rc= memcached_delete(memc, "foo", 3, 1); + /* but there is a bug in some of the memcached servers (1.4) that treats * the counter as noreply so it doesn't send the proper error message */ - assert(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR); + test_truth(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR); /* And buffered mode should be disabled and we should get protocol error */ - assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS); + test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 1) == MEMCACHED_SUCCESS); rc= memcached_delete(memc, "foo", 3, 1); - assert(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR); + test_truth(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR); /* Same goes for noreply... */ - assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS); + test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 1) == MEMCACHED_SUCCESS); rc= memcached_delete(memc, "foo", 3, 1); - assert(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR); + test_truth(rc == MEMCACHED_PROTOCOL_ERROR || rc == MEMCACHED_NOTFOUND || rc == MEMCACHED_CLIENT_ERROR); /* but a normal request should go through (and be buffered) */ - assert((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED); - assert(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS); + test_truth((rc= memcached_delete(memc, "foo", 3, 0)) == MEMCACHED_BUFFERED); + test_truth(memcached_flush_buffers(memc) == MEMCACHED_SUCCESS); - assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS); + test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BUFFER_REQUESTS, 0) == MEMCACHED_SUCCESS); /* unbuffered noreply should be success */ - assert(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS); + test_truth(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_SUCCESS); /* unbuffered with reply should be not found... */ - assert(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS); - assert(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND); + test_truth(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY, 0) == MEMCACHED_SUCCESS); + test_truth(memcached_delete(memc, "foo", 3, 0) == MEMCACHED_NOTFOUND); } memcached_free(memc_clone); @@ -5414,10 +5412,10 @@ static test_return_t test_get_last_disconnect(memcached_st *memc) rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); disconnected_server = memcached_server_get_last_disconnect(memc); - assert(disconnected_server == NULL); + test_truth(disconnected_server == NULL); /* With a non existing server */ memcached_st *mine; @@ -5426,22 +5424,22 @@ static test_return_t test_get_last_disconnect(memcached_st *memc) const char *server_list= "localhost:9"; servers= memcached_servers_parse(server_list); - assert(servers); + test_truth(servers); mine= memcached_create(NULL); rc= memcached_server_push(mine, servers); - assert(rc == MEMCACHED_SUCCESS); + test_truth(rc == MEMCACHED_SUCCESS); memcached_server_list_free(servers); - assert(mine); + test_truth(mine); rc= memcached_set(mine, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); - assert(rc != MEMCACHED_SUCCESS); + test_truth(rc != MEMCACHED_SUCCESS); disconnected_server = memcached_server_get_last_disconnect(mine); - assert(disconnected_server != NULL); - assert(disconnected_server->port == 9); - assert(strncmp(disconnected_server->hostname,"localhost",9) == 0); + test_truth(disconnected_server != NULL); + test_truth(disconnected_server->port == 9); + test_truth(strncmp(disconnected_server->hostname,"localhost",9) == 0); memcached_quit(mine); memcached_free(mine); @@ -5466,14 +5464,14 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) * in a non-portable way and you shouldn't be doing this. I'm only * doing this in order to verify that the library works the way it should */ - uint32_t number_of_hosts= memc->number_of_hosts; + uint32_t number_of_hosts= memcached_server_count(memc); memc->number_of_hosts= 1; /* Ensure that we are connected to the server by setting a value */ rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0); - assert(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); + test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED); /* The test is to see that the memcached_quit doesn't increase the @@ -5488,7 +5486,7 @@ static test_return_t wrong_failure_counter_test(memcached_st *memc) * Please note that this isn't bullet proof, because an error could * occur... */ - assert(memc->hosts[0].server_failure_counter == 0); + test_truth(memc->hosts[0].server_failure_counter == 0); /* restore the instance */ memc->number_of_hosts= number_of_hosts;