From 609d07c5a051c301ce6595747c2f64d3819554f5 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Thu, 7 Jul 2011 15:10:26 -0700 Subject: [PATCH] Adding additional tests for namespace. --- libmemcached/namespace.cc | 8 ++++++++ libmemcached/namespace.h | 3 +++ libmemcached/options/parser.cc | 16 ++++++---------- libmemcached/options/parser.yy | 4 ---- libtest/test.cc | 3 +-- tests/mem_functions.cc | 1 + tests/parser.cc | 28 ++++++++++++++-------------- tests/parser.h | 3 +++ 8 files changed, 36 insertions(+), 30 deletions(-) diff --git a/libmemcached/namespace.cc b/libmemcached/namespace.cc index 372af2a9..5cefae56 100644 --- a/libmemcached/namespace.cc +++ b/libmemcached/namespace.cc @@ -83,3 +83,11 @@ memcached_return_t memcached_set_namespace(memcached_st *self, const char *key, return MEMCACHED_SUCCESS; } + +const char * memcached_get_namespace(memcached_st *self) +{ + if (not self->_namespace) + return NULL; + + return memcached_array_string(self->_namespace); +} diff --git a/libmemcached/namespace.h b/libmemcached/namespace.h index 60cddd65..015c024d 100644 --- a/libmemcached/namespace.h +++ b/libmemcached/namespace.h @@ -44,6 +44,9 @@ extern "C" { LIBMEMCACHED_LOCAL memcached_return_t memcached_set_namespace(memcached_st *self, const char *str, size_t length); +LIBMEMCACHED_API + const char * memcached_get_namespace(memcached_st *self); + #ifdef __cplusplus } #endif diff --git a/libmemcached/options/parser.cc b/libmemcached/options/parser.cc index 096a3111..839444ba 100644 --- a/libmemcached/options/parser.cc +++ b/libmemcached/options/parser.cc @@ -529,7 +529,7 @@ static const yytype_uint16 yyrline[] = 305, 309, 313, 317, 321, 325, 329, 333, 340, 344, 348, 352, 356, 360, 364, 368, 372, 376, 380, 384, 391, 392, 397, 398, 403, 407, 411, 415, 419, 423, - 427, 431, 435, 442, 446, 457, 461, 465 + 427, 431, 435, 442, 446, 453, 457, 461 }; #endif @@ -2078,17 +2078,13 @@ yyreduce: #line 447 "libmemcached/options/parser.yy" { (yyval.string)= (yyvsp[(1) - (1)].string); - #if 0 - (yyval.string).c_str= (yyvsp[(1) - (1)].string).c_str +1; // +1 to move use passed the initial quote - (yyval.string).size= (yyvsp[(1) - (1)].string).size -2; // -2 removes the begin and end quote - #endif ;} break; case 65: /* Line 1464 of yacc.c */ -#line 458 "libmemcached/options/parser.yy" +#line 454 "libmemcached/options/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_CONSISTENT; ;} @@ -2097,7 +2093,7 @@ yyreduce: case 66: /* Line 1464 of yacc.c */ -#line 462 "libmemcached/options/parser.yy" +#line 458 "libmemcached/options/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_MODULA; ;} @@ -2106,7 +2102,7 @@ yyreduce: case 67: /* Line 1464 of yacc.c */ -#line 466 "libmemcached/options/parser.yy" +#line 462 "libmemcached/options/parser.yy" { (yyval.distribution)= MEMCACHED_DISTRIBUTION_RANDOM; ;} @@ -2115,7 +2111,7 @@ yyreduce: /* Line 1464 of yacc.c */ -#line 2119 "libmemcached/options/parser.cc" +#line 2115 "libmemcached/options/parser.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); @@ -2327,7 +2323,7 @@ yyreturn: /* Line 1684 of yacc.c */ -#line 471 "libmemcached/options/parser.yy" +#line 467 "libmemcached/options/parser.yy" void Context::start() diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index 81415226..f9d1f1e2 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -446,10 +446,6 @@ string: | QUOTED_STRING { $$= $1; - #if 0 - $$.c_str= $1.c_str +1; // +1 to move use passed the initial quote - $$.size= $1.size -2; // -2 removes the begin and end quote - #endif } ; diff --git a/libtest/test.cc b/libtest/test.cc index 8beef356..a8b91094 100644 --- a/libtest/test.cc +++ b/libtest/test.cc @@ -390,8 +390,6 @@ int main(int argc, char *argv[]) Error << "Failed while running on_error()"; break; } - - Logn(); } if (next->post and world->runner->post) @@ -406,6 +404,7 @@ int main(int argc, char *argv[]) cleanup: world->shutdown(creators_ptr); + Logn(); } if (not is_shutdown()) diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index f70dbba4..5476f8bd 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -6466,6 +6466,7 @@ test_st parser_tests[] ={ {"server with weights", 0, (test_callback_fn*)server_with_weight_test }, {"parsing servername, port, and weight", 0, (test_callback_fn*)test_hostname_port_weight }, {"--socket=", 0, (test_callback_fn*)test_parse_socket }, + {"--namespace=", 0, (test_callback_fn*)test_namespace_keyword }, {0, 0, (test_callback_fn*)0} }; diff --git a/tests/parser.cc b/tests/parser.cc index f1020ff4..c53c0512 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -98,16 +98,11 @@ 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_prefix_key(memcached_st *memc, const scanner_string_st &hostname) +static test_return_t __check_namespace(memcached_st *memc, const scanner_string_st &arg) { - memcached_server_instance_st instance= - memcached_server_instance_by_position(memc, 0); - - test_true(instance); - - const char *first_hostname = memcached_server_name(instance); - test_true(first_hostname); - test_strcmp(first_hostname, hostname.c_str); + const char *_namespace = memcached_get_namespace(memc); + test_true(_namespace); + test_strcmp(_namespace, arg.c_str); return TEST_SUCCESS; } @@ -206,10 +201,10 @@ scanner_variable_t test_boolean_options[]= { { NIL, scanner_string_null, scanner_string_null, NULL} }; -scanner_variable_t prefix_key_strings[]= { - { ARRAY, make_scanner_string("--NAMESPACE=foo"), make_scanner_string("foo"), __check_prefix_key }, - { ARRAY, make_scanner_string("--NAMESPACE=\"foo\""), make_scanner_string("foo"), __check_prefix_key }, - { ARRAY, make_scanner_string("--NAMESPACE=\"This_is_a_very_long_key\""), make_scanner_string("This_is_a_very_long_key"), __check_prefix_key }, +scanner_variable_t namespace_strings[]= { + { ARRAY, make_scanner_string("--NAMESPACE=foo"), make_scanner_string("foo"), __check_namespace }, + { ARRAY, make_scanner_string("--NAMESPACE=\"foo\""), make_scanner_string("foo"), __check_namespace }, + { ARRAY, make_scanner_string("--NAMESPACE=\"This_is_a_very_long_key\""), make_scanner_string("This_is_a_very_long_key"), __check_namespace }, { NIL, scanner_string_null, scanner_string_null, NULL} }; @@ -322,6 +317,11 @@ test_return_t parser_key_prefix_test(memcached_st*) return _test_option(distribution_strings); } +test_return_t test_namespace_keyword(memcached_st*) +{ + return _test_option(namespace_strings); +} + #define SUPPORT_EXAMPLE_CNF "support/example.cnf" test_return_t memcached_create_with_options_with_filename(memcached_st*) @@ -443,7 +443,7 @@ test_return_t random_statement_build_test(memcached_st*) for (scanner_variable_t *ptr= test_boolean_options; ptr->type != NIL; ptr++) option_list.push_back(&ptr->option); - for (scanner_variable_t *ptr= prefix_key_strings; ptr->type != NIL; ptr++) + for (scanner_variable_t *ptr= namespace_strings; ptr->type != NIL; ptr++) option_list.push_back(&ptr->option); for (scanner_variable_t *ptr= distribution_strings; ptr->type != NIL; ptr++) diff --git a/tests/parser.h b/tests/parser.h index 11b5368f..05272ee6 100644 --- a/tests/parser.h +++ b/tests/parser.h @@ -107,6 +107,9 @@ test_return_t regression_bug_71231153_poll(memcached_st *); LIBTEST_INTERNAL_API test_return_t test_parse_socket(memcached_st *); +LIBTEST_INTERNAL_API +test_return_t test_namespace_keyword(memcached_st*); + #ifdef __cplusplus } #endif -- 2.30.2