From: Brian Aker Date: Fri, 18 Mar 2011 17:29:45 +0000 (-0700) Subject: Merge in new scanner/parser suite with updated test cases. X-Git-Tag: 0.51~15^2~75^2~22 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=aaf07fb6d380f4e4f0b5404d6b006afcfe62aa7f;p=awesomized%2Flibmemcached Merge in new scanner/parser suite with updated test cases. --- diff --git a/clients/memparse.cc b/clients/memparse.cc index 50eedfc6..c2be258e 100644 --- a/clients/memparse.cc +++ b/clients/memparse.cc @@ -55,6 +55,7 @@ int main(int argc, char *argv[]) memc= memcached_create(NULL); memcached_return_t rc= memcached_parse_options(memc, argv[1], strlen(argv[1])); + memcached_free(memc); if (rc != MEMCACHED_SUCCESS) { diff --git a/libmemcached/constants.h b/libmemcached/constants.h index 00abb7bf..2ec8a9e8 100644 --- a/libmemcached/constants.h +++ b/libmemcached/constants.h @@ -9,6 +9,7 @@ * */ +#pragma once #ifndef __LIBMEMCACHED_CONSTANTS_H__ #define __LIBMEMCACHED_CONSTANTS_H__ diff --git a/libmemcached/hosts.c b/libmemcached/hosts.c index 7034d3ec..3efc675f 100644 --- a/libmemcached/hosts.c +++ b/libmemcached/hosts.c @@ -17,6 +17,7 @@ static memcached_return_t server_add(memcached_st *ptr, const char *hostname, in_port_t port, uint32_t weight, memcached_connection_t type); + static memcached_return_t update_continuum(memcached_st *ptr); static int compare_servers(const void *p1, const void *p2) diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index ae7e6d5f..4bba48a2 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -72,18 +72,20 @@ inline int libmemcached_error(YYLTYPE *locp, type_st *parser, yyscan_t *scanner, %start statement %verbose -%token EQ %token SERVER %token SERVERS %token TCPNODELAY %token UNKNOWN %token VERIFY_KEY -%token COMMA +%nonassoc ',' +%nonassoc '=' %token NUMBER %token FLOAT %token IDENTIFIER %token SERVER_WITH_PORT +%token IPADDRESS +%token IPADDRESS_WITH_PORT %type server @@ -98,11 +100,11 @@ statement: expression: - SERVER EQ server + SERVER '=' server { (void) memcached_server_add(parser->memc, $3.c_str, $3.port); } - | SERVERS EQ server_list + | SERVERS '=' server_list { } | TCPNODELAY { @@ -119,7 +121,7 @@ server_list: { (void) memcached_server_add(parser->memc, $1.c_str, $1.port); } - | server_list COMMA server + | server_list ',' server { (void) memcached_server_add(parser->memc, $3.c_str, $3.port); } @@ -129,13 +131,25 @@ server: SERVER_WITH_PORT NUMBER { $$.c_str= $1.c_str; - $$.length= $1.length; + $$.length= $1.length -1; $$.port= $2; } | IDENTIFIER { $$.c_str= $1.c_str; $$.length= $1.length; - $$.port= 80; + $$.port= MEMCACHED_DEFAULT_PORT; + } + | IPADDRESS_WITH_PORT NUMBER + { + $$.c_str= $1.c_str; + $$.length= $1.length -1; + $$.port= $2; + } + | IPADDRESS + { + $$.c_str= $1.c_str; + $$.length= $1.length; + $$.port= MEMCACHED_DEFAULT_PORT; } ; diff --git a/libmemcached/options/scanner.l b/libmemcached/options/scanner.l index e11fcf49..77f16ebe 100644 --- a/libmemcached/options/scanner.l +++ b/libmemcached/options/scanner.l @@ -52,12 +52,13 @@ static void get_lex_chars(char* buffer, int& result, int max_size, struct type_s %% -[=] { return EQ; } -[,] { return COMMA; } -[0-9]+ { yylval->number = atoi(yytext); return (NUMBER); } +=|, { return yytext[0];} -([0-9]*.[0-9]+) { yylval->double_number = atof(yytext); return (FLOAT); } + +[[:digit:]]+ { yylval->number = atoi(yytext); return (NUMBER); } + +([[:digit:]]*.[:digit:]+) { yylval->double_number = atof(yytext); return (FLOAT); } [ \t\r\n] ; /* skip whitespace */ @@ -68,22 +69,32 @@ static void get_lex_chars(char* buffer, int& result, int max_size, struct type_s "--VERIFY_KEY" { return VERIFY_KEY; } "--VERIFY-KEY" { return VERIFY_KEY; } -[A-Za-z][A-Za-z0-9_]*[:] { - yylval->string.c_str = yytext; - yylval->string.length = yyleng; - return SERVER_WITH_PORT; - } - -[A-Za-z][A-Za-z0-9_]* { - yylval->string.c_str = yytext; - yylval->string.length = yyleng; - return IDENTIFIER; - } -[-] ; - -. { - std::cerr << "Near " << yytext << std::endl; - return UNKNOWN; - } +[[:alnum:]][[:alnum:].]*[[:alpha:]]: { + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return SERVER_WITH_PORT; + } + +[[:alnum:]][[:alnum:].]*[[:alpha:]] { + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return IDENTIFIER; + } +[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}: { + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return IPADDRESS_WITH_PORT; + } + +[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3}"."[[:digit:]]{1,3} { + yylval->string.c_str = yytext; + yylval->string.length = yyleng; + return IPADDRESS; + } + +. { + std::cerr << "Near " << yytext << std::endl; + return UNKNOWN; + } %% diff --git a/libmemcached/string.h b/libmemcached/string.h index ca2c1220..4b44e6ed 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -9,6 +9,7 @@ * */ +#pragma once #ifndef __LIBMEMCACHED_STRING_H__ #define __LIBMEMCACHED_STRING_H__ diff --git a/libtest/include.am b/libtest/include.am index d6d9b18a..e6012ddc 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -10,7 +10,8 @@ noinst_HEADERS+= \ libtest/server.h \ - libtest/test.h + libtest/test.h \ + libtest/visibility.h noinst_LTLIBRARIES+= libtest/libserver.la libtest_libserver_la_SOURCES= libtest/server.c diff --git a/libtest/test.h b/libtest/test.h index cc0fd78a..88cc0115 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -1,19 +1,49 @@ -/* uTest - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2010 Brian Aker + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. */ +#pragma once + +#include + /* Structures for generic tests. */ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include @@ -39,9 +69,6 @@ typedef test_return_t (*test_callback_fn)(void *); typedef test_return_t (*test_callback_runner_fn)(test_callback_fn, void *); typedef test_return_t (*test_callback_error_fn)(test_return_t, void *); -/* Help function for use with gettimeofday() */ -long int timedif(struct timeval a, struct timeval b); - /** A structure describing the test case. */ @@ -139,14 +166,25 @@ typedef struct { uint32_t total; } world_stats_st; +#ifdef __cplusplus +extern "C" { +#endif + +/* Help function for use with gettimeofday() */ +LIBTEST_API +long int timedif(struct timeval a, struct timeval b); + /* How we make all of this work :) */ +LIBTEST_API void get_world(world_st *world); +LIBTEST_INTERNAL_API void create_core(void); /** @note Friendly print function for errors. */ +LIBTEST_API const char *test_strerror(test_return_t code); #define test_fail(A) \ @@ -200,6 +238,23 @@ do \ } \ } while (0) + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define AT __FILE__ ":" TOSTRING(__LINE__) + +#ifdef __cplusplus +#define STRING_WITH_LEN(X) (X), (static_cast((sizeof(X) - 1))) +#else +#define STRING_WITH_LEN(X) (X), ((size_t)((sizeof(X) - 1))) +#endif + +#ifdef __cplusplus +#define STRING_PARAM_WITH_LEN(X) X, static_cast(sizeof(X) - 1) +#else +#define STRING_PARAM_WITH_LEN(X) X, (size_t)((sizeof(X) - 1)) +#endif + #ifdef __cplusplus } #endif diff --git a/libtest/visibility.h b/libtest/visibility.h new file mode 100644 index 00000000..73d01f18 --- /dev/null +++ b/libtest/visibility.h @@ -0,0 +1,69 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#if defined(BUILDING_LIBTEST) +# if defined(HAVE_VISIBILITY) +# define LIBTEST_API __attribute__ ((visibility("default"))) +# define LIBTEST_INTERNAL_API __attribute__ ((visibility("hidden"))) +# define LIBTEST_API_DEPRECATED __attribute__ ((deprecated,visibility("default"))) +# define LIBTEST_LOCAL __attribute__ ((visibility("hidden"))) +# elif defined (__SUNPRO_C) && (__SUNPRO_C >= 0x550) +# define LIBTEST_API __global +# define LIBTEST_INTERNAL_API __hidden +# define LIBTEST_API_DEPRECATED __global +# define LIBTEST_LOCAL __hidden +# elif defined(_MSC_VER) +# define LIBTEST_API extern __declspec(dllexport) +# define LIBTEST_INTERNAL_API extern __declspec(dllexport) +# define LIBTEST_DEPRECATED_API extern __declspec(dllexport) +# define LIBTEST_LOCAL +# endif /* defined(HAVE_VISIBILITY) */ +#else /* defined(BUILDING_LIBTEST) */ +# if defined(_MSC_VER) +# define LIBTEST_API extern __declspec(dllimport) +# define LIBTEST_INTERNAL_API extern __declspec(dllimport) +# define LIBTEST_API_DEPRECATED extern __declspec(dllimport) +# define LIBTEST_LOCAL +# else +# define LIBTEST_API +# define LIBTEST_INTERNAL_API +# define LIBTEST_API_DEPRECATED +# define LIBTEST_LOCAL +# endif /* defined(_MSC_VER) */ +#endif /* defined(BUILDING_LIBTEST) */ diff --git a/tests/include.am b/tests/include.am index f940caf8..a88a804b 100644 --- a/tests/include.am +++ b/tests/include.am @@ -31,7 +31,9 @@ noinst_HEADERS+= \ tests/hash_results.h \ tests/ketama_test_cases.h \ tests/ketama_test_cases_spy.h \ - tests/libmemcached_world.h + tests/libmemcached_world.h \ + tests/parser.h \ + tests/print.h noinst_PROGRAMS+= \ tests/atomsmasher \ @@ -44,7 +46,11 @@ noinst_PROGRAMS+= \ tests/testudp tests_testapp_CFLAGS= $(AM_CFLAGS) $(NO_CONVERSION) $(NO_STRICT_ALIASING) -tests_testapp_SOURCES= tests/mem_functions.c +tests_testapp_SOURCES= \ + tests/mem_functions.c \ + tests/parser.cc \ + tests/print.cc + tests_testapp_DEPENDENCIES= \ $(BUILT_SOURCES) \ clients/libgenexec.la \ diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 74ab33a0..5b6dd2fe 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -34,6 +34,8 @@ #define SMALL_STRING_LEN 1024 #include +#include "tests/parser.h" +#include "tests/print.h" #ifdef HAVE_LIBMEMCACHEDUTIL @@ -189,21 +191,6 @@ static test_return_t server_sort2_test(memcached_st *ptr) return TEST_SUCCESS; } -static memcached_return_t server_print_callback(const memcached_st *ptr, - const memcached_server_st *server, - void *context) -{ - (void)server; // Just in case we aren't printing. - (void)ptr; - (void)context; - -#if 0 - fprintf(stderr, "%s(%d)", memcached_server_name(server), memcached_server_port(server)); -#endif - - return MEMCACHED_SUCCESS; -} - static test_return_t memcached_server_remove_test(memcached_st *ptr) { memcached_return_t rc; @@ -6561,6 +6548,13 @@ test_st error_conditions[] ={ {0, 0, (test_callback_fn)0} }; + +test_st parser_tests[] ={ + {"server", 0, (test_callback_fn)server_test }, + {"servers", 0, (test_callback_fn)servers_test }, + {0, 0, (test_callback_fn)0} +}; + collection_st collection[] ={ #if 0 {"hash_sanity", 0, 0, hash_sanity}, @@ -6623,6 +6617,7 @@ collection_st collection[] ={ {"behaviors", 0, 0, behavior_tests}, {"regression_binary_vs_block", (test_callback_fn)key_setup, (test_callback_fn)key_teardown, regression_binary_vs_block}, {"error_conditions", 0, 0, error_conditions}, + {"parser", 0, 0, parser_tests}, {0, 0, 0, 0} }; diff --git a/tests/parser.cc b/tests/parser.cc new file mode 100644 index 00000000..e7a4414f --- /dev/null +++ b/tests/parser.cc @@ -0,0 +1,109 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include + +#include "tests/parser.h" +#include "tests/print.h" + +struct scanner_string_st { + const char *c_ptr; + size_t size; +}; + +test_return_t server_test(memcached_st *junk) +{ + (void)junk; + memcached_return_t rc; + memcached_st *memc; + memc= memcached_create(NULL); + + scanner_string_st test_strings[]= { + { STRING_WITH_LEN("--server=localhost") }, + { STRING_WITH_LEN("--server=10.0.2.1") }, + { STRING_WITH_LEN("--server=example.com") }, + { STRING_WITH_LEN("--server=localhost:30") }, + { STRING_WITH_LEN("--server=10.0.2.1:20") }, + { STRING_WITH_LEN("--server=example.com:1024") }, + { NULL, 0} + }; + + for (scanner_string_st *ptr= test_strings; ptr->size; ptr++) + { + rc= memcached_parse_options(memc, ptr->c_ptr, ptr->size); + test_true(rc == MEMCACHED_SUCCESS); + memcached_servers_reset(memc); + } + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t servers_test(memcached_st *junk) +{ + (void)junk; + memcached_st *memc; + memc= memcached_create(NULL); + + scanner_string_st test_strings[]= { + { STRING_WITH_LEN("--servers=localhost:11221,localhost:11222,localhost:11223,localhost:11224,localhost:11225") }, + { STRING_WITH_LEN("--servers=a.example.com:80,localhost:80,b.example.com") }, + { STRING_WITH_LEN("--servers=localhost,localhost:80") }, + { NULL, 0} + }; + + for (scanner_string_st *ptr= test_strings; ptr->size; ptr++) + { + memcached_return_t rc; + rc= memcached_parse_options(memc, ptr->c_ptr, ptr->size); + + test_true(rc == MEMCACHED_SUCCESS); + + memcached_server_fn callbacks[1]; + callbacks[0]= server_print_callback; + memcached_server_cursor(memc, callbacks, memc, 1); + + memcached_servers_reset(memc); + } + + memcached_free(memc); + + return TEST_SUCCESS; +} diff --git a/tests/parser.h b/tests/parser.h new file mode 100644 index 00000000..82d04031 --- /dev/null +++ b/tests/parser.h @@ -0,0 +1,54 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +test_return_t server_test(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t servers_test(memcached_st *memc); + +#ifdef __cplusplus +} +#endif diff --git a/tests/print.cc b/tests/print.cc new file mode 100644 index 00000000..570ab0f0 --- /dev/null +++ b/tests/print.cc @@ -0,0 +1,59 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include + +#include +#include + +#include "tests/print.h" + +memcached_return_t server_print_callback(const memcached_st *ptr, + const memcached_server_st *server, + void *context) +{ + (void)ptr; + + if (context) + { + std::cerr << memcached_server_name(server) << ":" << memcached_server_port(server) << std::endl; + } + + return MEMCACHED_SUCCESS; +} diff --git a/tests/print.h b/tests/print.h new file mode 100644 index 00000000..efd148f6 --- /dev/null +++ b/tests/print.h @@ -0,0 +1,51 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * + * * The names of its contributors may not be used to endorse or + * promote products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +memcached_return_t server_print_callback(const memcached_st *ptr, + const memcached_server_st *server, + void *context); + +#ifdef __cplusplus +} +#endif