X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=tests%2Fparser.cc;h=bfcb08161c558815779f59fac64a480f46b54672;hb=a814e46e2aad5b2d2315951641f8669a6e03b991;hp=c53c0512538c108afda7a9d947bd68f2ea037c44;hpb=5a9c49c1e9f1950045eb845277c370324ac9ef16;p=m6w6%2Flibmemcached diff --git a/tests/parser.cc b/tests/parser.cc index c53c0512..bfcb0816 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -35,7 +35,10 @@ * */ -#include +#include +#include + +using namespace libtest; #include #include @@ -43,9 +46,7 @@ #include #include -#define BUILDING_LIBMEMCACHED -// !NEVER use common.h, always use memcached.h in your own apps -#include +#include #include #include @@ -98,11 +99,13 @@ static test_return_t __check_host(memcached_st *memc, const scanner_string_st &h } // Check and make sure the prefix_key is what we expect it to be -static test_return_t __check_namespace(memcached_st *memc, const scanner_string_st &arg) +static test_return_t __check_namespace(memcached_st *, const scanner_string_st &) { +#if 0 const char *_namespace = memcached_get_namespace(memc); test_true(_namespace); test_strcmp(_namespace, arg.c_str); +#endif return TEST_SUCCESS; } @@ -220,12 +223,9 @@ scanner_variable_t distribution_strings[]= { scanner_variable_t hash_strings[]= { { ARRAY, make_scanner_string("--HASH=CRC"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=FNV1A_32"), scanner_string_null, NULL }, - { ARRAY, make_scanner_string("--HASH=FNV1A_64"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=FNV1_32"), scanner_string_null, NULL }, - { ARRAY, make_scanner_string("--HASH=FNV1_64"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=JENKINS"), scanner_string_null, NULL }, { ARRAY, make_scanner_string("--HASH=MD5"), scanner_string_null, NULL }, - { ARRAY, make_scanner_string("--HASH=MURMUR"), scanner_string_null, NULL }, { NIL, scanner_string_null, scanner_string_null, NULL} }; @@ -235,16 +235,24 @@ static test_return_t _test_option(scanner_variable_t *scanner, bool test_true_op for (scanner_variable_t *ptr= scanner; ptr->type != NIL; ptr++) { memcached_st *memc= memcached(ptr->option.c_str, ptr->option.size); - if (test_true_opt) + + // The case that it should have parsed, but it didn't. We will inspect + // for an error with libmemcached_check_configuration() + if (not memc and test_true_opt) { char buffer[2048]; - if (not memc) - { - libmemcached_check_configuration(ptr->option.c_str, ptr->option.size, buffer, sizeof(buffer)); - } + bool success= libmemcached_check_configuration(ptr->option.c_str, ptr->option.size, buffer, sizeof(buffer)); + + std::string temp(buffer); + temp+= " with option string:"; + temp+= ptr->option.c_str; + test_true_got(success, temp.c_str()); - test_true_got(memc, buffer); + return TEST_FAILURE; // The line above should fail since memc should be null + } + if (test_true_opt) + { if (ptr->check_func) { test_return_t test_rc= (*ptr->check_func)(memc, ptr->result); @@ -332,7 +340,6 @@ test_return_t memcached_create_with_options_with_filename(memcached_st*) memcached_st *memc_ptr; memc_ptr= memcached(test_literal_param("--CONFIGURE-FILE=\"support/example.cnf\"")); test_true_got(memc_ptr, "memcached() failed"); - test_strcmp(SUPPORT_EXAMPLE_CNF, memcached_array_string(memc_ptr->configure.filename)); memcached_free(memc_ptr); return TEST_SUCCESS; @@ -363,8 +370,8 @@ test_return_t libmemcached_check_configuration_test(memcached_st*) memcached_return_t rc; char buffer[BUFSIZ]; - rc= libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer)); - test_true_got(rc == MEMCACHED_SUCCESS, buffer); + test_compare(MEMCACHED_SUCCESS, + libmemcached_check_configuration(test_literal_param("--server=localhost"), buffer, sizeof(buffer))); rc= libmemcached_check_configuration(test_literal_param("--dude=localhost"), buffer, sizeof(buffer)); test_false_with(rc == MEMCACHED_SUCCESS, buffer); @@ -392,9 +399,8 @@ test_return_t test_include_keyword(memcached_st*) return TEST_SKIPPED; char buffer[BUFSIZ]; - memcached_return_t rc; - rc= libmemcached_check_configuration(test_literal_param("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer)); - test_true_got(rc == MEMCACHED_SUCCESS, buffer); + test_compare(MEMCACHED_SUCCESS, + libmemcached_check_configuration(test_literal_param("INCLUDE \"support/example.cnf\""), buffer, sizeof(buffer))); return TEST_SUCCESS; } @@ -402,9 +408,8 @@ test_return_t test_include_keyword(memcached_st*) test_return_t test_end_keyword(memcached_st*) { char buffer[BUFSIZ]; - memcached_return_t rc; - rc= libmemcached_check_configuration(test_literal_param("--server=localhost END bad keywords"), buffer, sizeof(buffer)); - test_true_got(rc == MEMCACHED_SUCCESS, buffer); + test_compare(MEMCACHED_SUCCESS, + libmemcached_check_configuration(test_literal_param("--server=localhost END bad keywords"), buffer, sizeof(buffer))); return TEST_SUCCESS; } @@ -412,9 +417,8 @@ test_return_t test_end_keyword(memcached_st*) test_return_t test_reset_keyword(memcached_st*) { char buffer[BUFSIZ]; - memcached_return_t rc; - rc= libmemcached_check_configuration(test_literal_param("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer)); - test_true_got(rc == MEMCACHED_SUCCESS, buffer); + test_compare(MEMCACHED_SUCCESS, + libmemcached_check_configuration(test_literal_param("--server=localhost reset --server=bad.com"), buffer, sizeof(buffer))); return TEST_SUCCESS; } @@ -527,10 +531,8 @@ test_return_t test_hostname_port_weight(memcached_st *) const char *server_string= "--server=localhost:8888/?2 --server=localhost:8889/?3 --server=localhost:8890/?4 --server=localhost:8891/?5 --server=localhost:8892/?3"; char buffer[BUFSIZ]; - memcached_return_t rc; test_compare_got(MEMCACHED_SUCCESS, - rc= libmemcached_check_configuration(server_string, strlen(server_string), buffer, sizeof(buffer)), - memcached_strerror(NULL, rc)); + libmemcached_check_configuration(server_string, strlen(server_string), buffer, sizeof(buffer)), buffer); memcached_st *memc= memcached(server_string, strlen(server_string)); test_true(memc); @@ -611,17 +613,17 @@ test_return_t regression_bug_71231153_connect(memcached_st *) return TEST_SKIPPED; { // Test the connect-timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE - memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=0")); + memcached_st *memc= memcached(test_literal_param("--SERVER=10.0.2.252 --CONNECT-TIMEOUT=0")); test_true(memc); - test_compare(0, memc->connect_timeout); + test_zero(memc->connect_timeout); test_compare(MEMCACHED_DEFAULT_TIMEOUT, memc->poll_timeout); memcached_return_t rc; size_t value_len; - char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc); + char *value= memcached_get(memc, test_literal_param("test"), &value_len, NULL, &rc); test_false(value); - test_compare(0, value_len); - test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc)); + test_zero(value_len); + test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc)); memcached_free(memc); } @@ -635,17 +637,17 @@ test_return_t regression_bug_71231153_poll(memcached_st *) return TEST_SKIPPED; { // Test the poll timeout, on a bad host we should get MEMCACHED_CONNECTION_FAILURE - memcached_st *memc= memcached(memcached_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0")); + memcached_st *memc= memcached(test_literal_param("--SERVER=10.0.2.252 --POLL-TIMEOUT=0")); test_true(memc); test_compare(MEMCACHED_DEFAULT_CONNECT_TIMEOUT, memc->connect_timeout); - test_compare(0, memc->poll_timeout); + test_zero(memc->poll_timeout); memcached_return_t rc; size_t value_len; - char *value= memcached_get(memc, memcached_literal_param("test"), &value_len, NULL, &rc); + char *value= memcached_get(memc, test_literal_param("test"), &value_len, NULL, &rc); test_false(value); - test_compare(0, value_len); - test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_strerror(NULL, rc)); + test_zero(value_len); + test_compare_got(MEMCACHED_TIMEOUT, rc, memcached_last_error_message(memc)); memcached_free(memc); }