From: Brian Aker Date: Tue, 16 Aug 2011 01:57:05 +0000 (-0700) Subject: Add test cases for add server for NULL cases. X-Git-Tag: 0.52~22 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=0ae14bed70947882f5ee9423dfcb20eeda7acdd9;p=m6w6%2Flibmemcached Add test cases for add server for NULL cases. --- diff --git a/libmemcached/allocators.cc b/libmemcached/allocators.cc index ec491ddb..cc41f2c3 100644 --- a/libmemcached/allocators.cc +++ b/libmemcached/allocators.cc @@ -40,7 +40,9 @@ void _libmemcached_free(const memcached_st*, void *mem, void*) { if (mem) + { free(mem); + } } void *_libmemcached_malloc(const memcached_st *, size_t size, void *) @@ -59,7 +61,9 @@ void *_libmemcached_calloc(const memcached_st *self, size_t nelem, size_t size, { void *ret = _libmemcached_malloc(self, nelem * size, context); if (not ret) + { memset(ret, 0, nelem * size); + } return ret; } @@ -80,6 +84,11 @@ memcached_return_t memcached_set_memory_allocators(memcached_st *self, memcached_calloc_fn mem_calloc, void *context) { + if (self == NULL) + { + return MEMCACHED_INVALID_ARGUMENTS; + } + /* All should be set, or none should be set */ if (mem_malloc == NULL && mem_free == NULL && mem_realloc == NULL && mem_calloc == NULL) { @@ -87,7 +96,7 @@ memcached_return_t memcached_set_memory_allocators(memcached_st *self, } else if (mem_malloc == NULL || mem_free == NULL || mem_realloc == NULL || mem_calloc == NULL) { - return MEMCACHED_FAILURE; + return memcached_set_error(*self, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("NULL parameter provided for one or more allocators")); } else { @@ -112,6 +121,11 @@ void memcached_get_memory_allocators(const memcached_st *self, memcached_realloc_fn *mem_realloc, memcached_calloc_fn *mem_calloc) { + if (self == NULL) + { + return; + } + *mem_malloc= self->allocators.malloc; *mem_free= self->allocators.free; *mem_realloc= self->allocators.realloc; diff --git a/libmemcached/common.h b/libmemcached/common.h index 62a2b1c6..5af6916c 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -116,6 +116,7 @@ memcached_return_t memcached_server_execute(memcached_st *ptr, #ifdef __cplusplus #include #include +#include #endif #include @@ -164,14 +165,6 @@ memcached_return_t memcached_key_test(const memcached_st& memc, LIBMEMCACHED_LOCAL memcached_return_t memcached_purge(memcached_server_write_instance_st ptr); -LIBMEMCACHED_LOCAL - memcached_server_st *__server_create_with(const memcached_st *memc, - memcached_server_write_instance_st host, - const char *hostname, - in_port_t port, - uint32_t weight, - memcached_connection_t type); - static inline memcached_return_t memcached_validate_key_length(size_t key_length, bool binary) { diff --git a/libmemcached/connect.cc b/libmemcached/connect.cc index 3c12339c..fa35d84e 100644 --- a/libmemcached/connect.cc +++ b/libmemcached/connect.cc @@ -153,6 +153,7 @@ static memcached_return_t set_hostinfo(memcached_server_st *server) hints.ai_protocol= IPPROTO_TCP; } + server->address_info= NULL; int errcode; switch(errcode= getaddrinfo(server->hostname, str_port, &hints, &server->address_info)) { diff --git a/libmemcached/hosts.cc b/libmemcached/hosts.cc index 1bcaaa7a..4a9a1033 100644 --- a/libmemcached/hosts.cc +++ b/libmemcached/hosts.cc @@ -41,11 +41,6 @@ #include /* Protoypes (static) */ -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) @@ -342,6 +337,51 @@ static memcached_return_t update_continuum(memcached_st *ptr) return MEMCACHED_SUCCESS; } +static memcached_return_t server_add(memcached_st *ptr, + const memcached_string_t& hostname, + in_port_t port, + uint32_t weight, + memcached_connection_t type) +{ + assert_msg(ptr, "Programmer mistake, somehow server_add() was passed a NULL memcached_st"); + if ( (ptr->flags.use_udp and type != MEMCACHED_CONNECTION_UDP) + or ( (type == MEMCACHED_CONNECTION_UDP) and (not ptr->flags.use_udp) ) ) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_HOST_PROTOCOL, MEMCACHED_AT); + } + + memcached_server_st *new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), + sizeof(memcached_server_st) * (ptr->number_of_hosts + 1))); + + if (not new_host_list) + { + return MEMCACHED_MEMORY_ALLOCATION_FAILURE; + } + + memcached_server_list_set(ptr, new_host_list); + + /* TODO: Check return type */ + memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); + + if (not __server_create_with(ptr, instance, hostname, port, weight, type)) + { + return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + } + + if (weight > 1) + { + ptr->ketama.weighted= true; + } + + ptr->number_of_hosts++; + + // @note we place the count in the bottom of the server list + instance= memcached_server_instance_fetch(ptr, 0); + memcached_servers_set_count(instance, memcached_server_count(ptr)); + + return run_distribution(ptr); +} + memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_server_list_st list) { @@ -377,8 +417,10 @@ memcached_return_t memcached_server_push(memcached_st *ptr, const memcached_serv instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); WATCHPOINT_ASSERT(instance); - if (not __server_create_with(ptr, instance, list[x].hostname, - list[x].port, list[x].weight, list[x].type)) + memcached_string_t hostname= { memcached_string_make_from_cstr(list[x].hostname) }; + if (__server_create_with(ptr, instance, + hostname, + list[x].port, list[x].weight, list[x].type) == NULL) { return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); } @@ -411,10 +453,18 @@ memcached_return_t memcached_server_add_unix_socket_with_weight(memcached_st *pt const char *filename, uint32_t weight) { - if (! filename) + if (ptr == NULL) + { return MEMCACHED_FAILURE; + } + + memcached_string_t _filename= { memcached_string_make_from_cstr(filename) }; + if (memcached_is_valid_servername(_filename) == false) + { + memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid filename for socket provided")); + } - return server_add(ptr, filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET); + return server_add(ptr, _filename, 0, weight, MEMCACHED_CONNECTION_UNIX_SOCKET); } memcached_return_t memcached_server_add_udp(memcached_st *ptr, @@ -429,13 +479,28 @@ memcached_return_t memcached_server_add_udp_with_weight(memcached_st *ptr, in_port_t port, uint32_t weight) { + if (ptr == NULL) + { + return MEMCACHED_INVALID_ARGUMENTS; + } + if (not port) + { port= MEMCACHED_DEFAULT_PORT; + } if (not hostname) + { hostname= "localhost"; + } - return server_add(ptr, hostname, port, weight, MEMCACHED_CONNECTION_UDP); + memcached_string_t _hostname= { memcached_string_make_from_cstr(hostname) }; + if (memcached_is_valid_servername(_hostname) == false) + { + memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid hostname provided")); + } + + return server_add(ptr, _hostname, port, weight, MEMCACHED_CONNECTION_UDP); } memcached_return_t memcached_server_add(memcached_st *ptr, @@ -450,55 +515,31 @@ memcached_return_t memcached_server_add_with_weight(memcached_st *ptr, in_port_t port, uint32_t weight) { - if (not port) - port= MEMCACHED_DEFAULT_PORT; - - if (not hostname) - hostname= "localhost"; - - return server_add(ptr, hostname, port, weight, hostname[0] == '/' ? MEMCACHED_CONNECTION_UNIX_SOCKET : MEMCACHED_CONNECTION_TCP); -} - -static memcached_return_t server_add(memcached_st *ptr, const char *hostname, - in_port_t port, - uint32_t weight, - memcached_connection_t type) -{ - - if ( (ptr->flags.use_udp and type != MEMCACHED_CONNECTION_UDP) - or ( (type == MEMCACHED_CONNECTION_UDP) and (not ptr->flags.use_udp) ) ) + if (ptr == NULL) { - return MEMCACHED_INVALID_HOST_PROTOCOL; + return MEMCACHED_INVALID_ARGUMENTS; } - memcached_server_st *new_host_list= static_cast(libmemcached_realloc(ptr, memcached_server_list(ptr), - sizeof(memcached_server_st) * (ptr->number_of_hosts + 1))); - - if (not new_host_list) - return MEMCACHED_MEMORY_ALLOCATION_FAILURE; - - memcached_server_list_set(ptr, new_host_list); - - /* TODO: Check return type */ - memcached_server_write_instance_st instance= memcached_server_instance_fetch(ptr, memcached_server_count(ptr)); - - if (not __server_create_with(ptr, instance, hostname, port, weight, type)) + if (port == 0) { - return memcached_set_error(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); + port= MEMCACHED_DEFAULT_PORT; } - if (weight > 1) + size_t hostname_length= hostname ? strlen(hostname) : 0; + if (hostname_length == 0) { - ptr->ketama.weighted= true; + hostname= "localhost"; + hostname_length= sizeof("localhost") -1; } - ptr->number_of_hosts++; + memcached_string_t _hostname= { hostname, hostname_length }; - // @note we place the count in the bottom of the server list - instance= memcached_server_instance_fetch(ptr, 0); - memcached_servers_set_count(instance, memcached_server_count(ptr)); + if (memcached_is_valid_servername(_hostname) == false) + { + return memcached_set_error(*ptr, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid hostname provided")); + } - return run_distribution(ptr); + return server_add(ptr, _hostname, port, weight, _hostname.c_str[0] == '/' ? MEMCACHED_CONNECTION_UNIX_SOCKET : MEMCACHED_CONNECTION_TCP); } memcached_return_t memcached_server_add_parsed(memcached_st *ptr, @@ -512,7 +553,9 @@ memcached_return_t memcached_server_add_parsed(memcached_st *ptr, memcpy(buffer, hostname, hostname_length); buffer[hostname_length]= 0; - return server_add(ptr, buffer, + memcached_string_t _hostname= { buffer, hostname_length }; + + return server_add(ptr, _hostname, port, weight, MEMCACHED_CONNECTION_TCP); diff --git a/libmemcached/include.am b/libmemcached/include.am index 425cec0b..aa15f8e3 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -31,6 +31,7 @@ noinst_HEADERS+= \ libmemcached/protocol/binary_handler.h \ libmemcached/protocol/common.h \ libmemcached/response.h \ + libmemcached/server.hpp \ libmemcached/server_instance.h \ libmemcached/string.hpp \ libmemcached/virtual_bucket.h diff --git a/libmemcached/server.cc b/libmemcached/server.cc index 5576caaa..073972dd 100644 --- a/libmemcached/server.cc +++ b/libmemcached/server.cc @@ -41,7 +41,8 @@ #include static inline void _server_init(memcached_server_st *self, memcached_st *root, - const char *hostname, in_port_t port, + const memcached_string_t& hostname, + in_port_t port, uint32_t weight, memcached_connection_t type) { self->options.is_shutting_down= false; @@ -80,14 +81,8 @@ static inline void _server_init(memcached_server_st *self, memcached_st *root, self->root= root; self->limit_maxbytes= 0; - if (hostname) - { - strncpy(self->hostname, hostname, NI_MAXHOST - 1); - } - else - { - self->hostname[0]= 0; - } + memcpy(self->hostname, hostname.c_str, hostname.size); + self->hostname[hostname.size]= 0; } static memcached_server_st *_server_create(memcached_server_st *self, const memcached_st *memc) @@ -97,7 +92,9 @@ static memcached_server_st *_server_create(memcached_server_st *self, const memc self= (memcached_server_st *)libmemcached_malloc(memc, sizeof(memcached_server_st)); if (not self) + { return NULL; /* MEMCACHED_MEMORY_ALLOCATION_FAILURE */ + } self->options.is_allocated= true; } @@ -111,11 +108,19 @@ static memcached_server_st *_server_create(memcached_server_st *self, const memc return self; } -memcached_server_st *__server_create_with(const memcached_st *memc, +memcached_server_st *__server_create_with(memcached_st *memc, memcached_server_write_instance_st self, - const char *hostname, in_port_t port, - uint32_t weight, memcached_connection_t type) + const memcached_string_t& hostname, + const in_port_t port, + uint32_t weight, + const memcached_connection_t type) { + if (memcached_is_valid_servername(hostname) == false) + { + memcached_set_error(*memc, MEMCACHED_INVALID_ARGUMENTS, MEMCACHED_AT, memcached_literal_param("Invalid hostname provided")); + return NULL; + } + self= _server_create(self, memc); if (not self) @@ -143,6 +148,7 @@ void __server_free(memcached_server_st *self) { freeaddrinfo(self->address_info); self->address_info= NULL; + self->address_info_next= NULL; } memcached_error_free(*self); @@ -175,14 +181,18 @@ void memcached_server_free(memcached_server_st *self) If we do not have a valid object to clone from, we toss an error. */ memcached_server_st *memcached_server_clone(memcached_server_st *destination, - const memcached_server_st *source) + memcached_server_st *source) { /* We just do a normal create if source is missing */ if (not source) + { return NULL; + } + memcached_string_t hostname= { memcached_string_make_from_cstr(source->hostname) }; destination= __server_create_with(source->root, destination, - source->hostname, source->port, source->weight, + hostname, + source->port, source->weight, source->type); if (not destination) { diff --git a/libmemcached/server.h b/libmemcached/server.h index fec1d48c..dc112153 100644 --- a/libmemcached/server.h +++ b/libmemcached/server.h @@ -108,7 +108,7 @@ void memcached_server_free(memcached_server_st *ptr); LIBMEMCACHED_LOCAL memcached_server_st *memcached_server_clone(memcached_server_st *destination, - const memcached_server_st *source); + memcached_server_st *source); LIBMEMCACHED_API memcached_server_instance_st memcached_server_get_last_disconnect(const memcached_st *ptr); diff --git a/libmemcached/server.hpp b/libmemcached/server.hpp new file mode 100644 index 00000000..05b51f4f --- /dev/null +++ b/libmemcached/server.hpp @@ -0,0 +1,53 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * 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 + +static inline bool memcached_is_valid_servername(const memcached_string_t& arg) +{ + return arg.size > 0 or arg.size < NI_MAXHOST; +} + +LIBMEMCACHED_LOCAL + memcached_server_st *__server_create_with(memcached_st *memc, + memcached_server_write_instance_st host, + const memcached_string_t& hostname, + const in_port_t port, + uint32_t weight, + const memcached_connection_t type); diff --git a/libmemcached/server_list.cc b/libmemcached/server_list.cc index a599e0b6..a4a617c0 100644 --- a/libmemcached/server_list.cc +++ b/libmemcached/server_list.cc @@ -66,6 +66,7 @@ memcached_server_list_append_with_weight(memcached_server_list_st ptr, port= MEMCACHED_DEFAULT_PORT; } + /* Increment count for hosts */ count= 1; if (ptr != NULL) @@ -80,8 +81,9 @@ memcached_server_list_append_with_weight(memcached_server_list_st ptr, return NULL; } + memcached_string_t _hostname= { memcached_string_make_from_cstr(hostname) }; /* @todo Check return type */ - if (not __server_create_with(NULL, &new_host_list[count-1], hostname, port, weight, port ? MEMCACHED_CONNECTION_TCP : MEMCACHED_CONNECTION_UNIX_SOCKET)) + if (not __server_create_with(NULL, &new_host_list[count-1], _hostname, port, weight, port ? MEMCACHED_CONNECTION_TCP : MEMCACHED_CONNECTION_UNIX_SOCKET)) { *error= memcached_set_errno(*ptr, MEMCACHED_MEMORY_ALLOCATION_FAILURE, MEMCACHED_AT); return NULL; diff --git a/tests/include.am b/tests/include.am index b5f4fb0d..a05bd2b8 100644 --- a/tests/include.am +++ b/tests/include.am @@ -36,6 +36,7 @@ noinst_HEADERS+= \ tests/pool.h \ tests/print.h \ tests/replication.h \ + tests/server_add.h \ tests/string.h \ tests/virtual_buckets.h @@ -77,6 +78,7 @@ tests_testapp_SOURCES= \ tests/pool.cc \ tests/print.cc \ tests/replication.cc \ + tests/server_add.cc \ tests/virtual_buckets.cc tests_testapp_SOURCES+= clients/generator.cc clients/execute.cc tests_testapp_DEPENDENCIES= \ diff --git a/tests/mem_functions.cc b/tests/mem_functions.cc index 6845074b..ab850f50 100644 --- a/tests/mem_functions.cc +++ b/tests/mem_functions.cc @@ -68,16 +68,18 @@ #define SMALL_STRING_LEN 1024 #include + +#include "tests/basic.h" +#include "tests/debug.h" #include "tests/deprecated.h" -#include "tests/parser.h" +#include "tests/error_conditions.h" #include "tests/ketama.h" -#include "tests/pool.h" #include "tests/namespace.h" -#include "tests/replication.h" -#include "tests/debug.h" -#include "tests/basic.h" -#include "tests/error_conditions.h" +#include "tests/parser.h" +#include "tests/pool.h" #include "tests/print.h" +#include "tests/replication.h" +#include "tests/server_add.h" #include "tests/virtual_buckets.h" using namespace libtest; @@ -3875,7 +3877,7 @@ static test_return_t deprecated_set_memory_alloc(memcached_st *memc) static test_return_t set_memory_alloc(memcached_st *memc) { - test_compare(MEMCACHED_FAILURE, + test_compare(MEMCACHED_INVALID_ARGUMENTS, memcached_set_memory_allocators(memc, NULL, my_free, my_realloc, my_calloc, NULL)); @@ -6131,6 +6133,12 @@ test_st virtual_bucket_tests[] ={ {0, 0, (test_callback_fn*)0} }; +test_st memcached_server_add_tests[] ={ + {"memcached_server_add(\"\")", false, (test_callback_fn*)memcached_server_add_empty_test }, + {"memcached_server_add(NULL)", false, (test_callback_fn*)memcached_server_add_null_test }, + {0, 0, (test_callback_fn*)0} +}; + test_st namespace_tests[] ={ {"basic tests", true, (test_callback_fn*)selection_of_namespace_tests }, {"increment", true, (test_callback_fn*)memcached_increment_namespace }, @@ -6145,6 +6153,7 @@ collection_st collection[] ={ {"basic", 0, 0, basic_tests}, {"hsieh_availability", 0, 0, hsieh_availability}, {"murmur_availability", 0, 0, murmur_availability}, + {"memcached_server_add", 0, 0, memcached_server_add_tests}, {"block", 0, 0, tests}, {"binary", (test_callback_fn*)pre_binary, 0, tests}, {"nonblock", (test_callback_fn*)pre_nonblock, 0, tests}, diff --git a/tests/server_add.cc b/tests/server_add.cc new file mode 100644 index 00000000..b343bf9c --- /dev/null +++ b/tests/server_add.cc @@ -0,0 +1,67 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * 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 + +using namespace libtest; + +#include + +#include + +test_return_t memcached_server_add_null_test(memcached_st*) +{ + memcached_st *memc= memcached_create(NULL); + + test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, NULL, 0)); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_return_t memcached_server_add_empty_test(memcached_st*) +{ + memcached_st *memc= memcached_create(NULL); + + test_compare(MEMCACHED_SUCCESS, memcached_server_add(memc, "", 0)); + + memcached_free(memc); + + return TEST_SUCCESS; +} diff --git a/tests/server_add.h b/tests/server_add.h new file mode 100644 index 00000000..53ced524 --- /dev/null +++ b/tests/server_add.h @@ -0,0 +1,41 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached Client and Server + * + * 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 + +test_return_t memcached_server_add_null_test(memcached_st*); +test_return_t memcached_server_add_empty_test(memcached_st*);