From: Brian Aker Date: Sat, 26 Mar 2011 23:56:28 +0000 (-0700) Subject: Merge in additional tests/remove any usages of STL from main library. X-Git-Tag: 0.51~15^2~72 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=833ab6461e5066f3b88663dc8b64efaa65da54bd;p=m6w6%2Flibmemcached Merge in additional tests/remove any usages of STL from main library. --- diff --git a/libmemcached/common.h b/libmemcached/common.h index c4cd0e53..1a813a02 100644 --- a/libmemcached/common.h +++ b/libmemcached/common.h @@ -47,6 +47,7 @@ #include "libmemcached/memcached.h" #include "libmemcached/watchpoint.h" #include "libmemcached/is.h" +#include "libmemcached/prefix_key.h" typedef struct memcached_server_st * memcached_server_write_instance_st; diff --git a/libmemcached/include.am b/libmemcached/include.am index c290989e..de354b4c 100644 --- a/libmemcached/include.am +++ b/libmemcached/include.am @@ -89,6 +89,7 @@ libmemcached_libmemcachedcallbacks_la_SOURCES = libmemcached/callback.c # These symbols will not be exposed in the shipped .so noinst_LTLIBRARIES+= libmemcached/libmemcachedinternal.la libmemcached_libmemcachedinternal_la_SOURCES= \ + libmemcached/error.c \ libmemcached/string.c lib_LTLIBRARIES+= libmemcached/libmemcached.la @@ -103,7 +104,6 @@ libmemcached_libmemcached_la_SOURCES+= \ libmemcached/delete.c \ libmemcached/do.c \ libmemcached/dump.c \ - libmemcached/error.c \ libmemcached/fetch.c \ libmemcached/flush.c \ libmemcached/flush_buffers.c \ diff --git a/libmemcached/io.h b/libmemcached/io.h index 3662954d..b4f7806f 100644 --- a/libmemcached/io.h +++ b/libmemcached/io.h @@ -16,10 +16,6 @@ #include "libmemcached/memcached.h" -#ifdef __cplusplus -extern "C" { -#endif - #define MAX_UDP_DATAGRAM_LENGTH 1400 #define UDP_DATAGRAM_HEADER_LENGTH 8 #define UDP_REQUEST_ID_MSG_SIG_DIGITS 10 @@ -46,6 +42,10 @@ struct libmemcached_io_vector_st const void *buffer; }; +#ifdef __cplusplus +extern "C" { +#endif + LIBMEMCACHED_LOCAL memcached_return_t memcached_io_wait_for_write(memcached_server_write_instance_st ptr); diff --git a/libmemcached/options/build.cc b/libmemcached/options/build.cc new file mode 100644 index 00000000..9381b516 --- /dev/null +++ b/libmemcached/options/build.cc @@ -0,0 +1,69 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * 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 + +namespace parser { + +void abort_func(Context *context, const char *error) +{ + if (context->rc == MEMCACHED_SUCCESS) + context->rc= MEMCACHED_PARSE_ERROR; + + memcached_string_st *error_string= memcached_string_create(context->memc, NULL, 1024); + memcached_string_append(error_string, memcached_string_with_size("Error occured while parsing: ")); + memcached_string_append(error_string, memcached_string_make_from_cstr(context->begin)); + memcached_string_append(error_string, memcached_string_with_size(" (")); + + if (context->rc == MEMCACHED_PARSE_ERROR and error) + { + memcached_string_append(error_string, memcached_string_make_from_cstr(error)); + } + else + { + memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, context->rc))); + } + memcached_string_append(error_string, memcached_string_with_size(")")); + + memcached_set_error_string(context->memc, context->rc, memcached_string_value(error_string), memcached_string_length(error_string)); + + memcached_string_free(error_string); +} + +} // namespace parser diff --git a/libmemcached/options/build.h b/libmemcached/options/build.h new file mode 100644 index 00000000..d267354f --- /dev/null +++ b/libmemcached/options/build.h @@ -0,0 +1,46 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * LibMemcached + * + * 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 + +class Conext; + +namespace parser { + +void abort_func(Context *context, const char *error); + +} diff --git a/libmemcached/options/include.am b/libmemcached/options/include.am index d110a943..562a3278 100644 --- a/libmemcached/options/include.am +++ b/libmemcached/options/include.am @@ -14,6 +14,7 @@ EXTRA_DIST+= \ libmemcached/options/parser.yy noinst_HEADERS+= \ + libmemcached/options/build.h \ libmemcached/options/context.h \ libmemcached/options/parser.h \ libmemcached/options/scanner.h \ @@ -22,6 +23,7 @@ noinst_HEADERS+= \ libmemcached/options/symbol.h libmemcached_libmemcached_la_SOURCES+= \ + libmemcached/options/build.cc \ libmemcached/options/parser.cc \ libmemcached/options/scanner.cc diff --git a/libmemcached/options/parser.yy b/libmemcached/options/parser.yy index adf3dc01..fb7ccd86 100644 --- a/libmemcached/options/parser.yy +++ b/libmemcached/options/parser.yy @@ -40,43 +40,23 @@ #include #include +#include #include #include +#include +#include #pragma GCC diagnostic ignored "-Wold-style-cast" #include int libmemcached_lex(YYSTYPE* lvalp, void* scanner); -#define parser_abort(A, B) do { parser_abort_func((A), (B)); YYABORT; } while (0) - -inline void parser_abort_func(Context *context, const char *error) -{ - (void)error; - if (context->rc == MEMCACHED_SUCCESS) - context->rc= MEMCACHED_PARSE_ERROR; - - std::string error_message; - error_message+= "Error occured while parsing: "; - error_message+= context->begin; - error_message+= " ("; - if (context->rc == MEMCACHED_PARSE_ERROR and error) - { - error_message+= error; - } - else - { - error_message+= memcached_strerror(NULL, context->rc); - } - error_message+= ")"; - - memcached_set_error_string(context->memc, context->rc, error_message.c_str(), error_message.size()); -} +#define parser_abort(A, B) do { parser::abort_func((A), (B)); YYABORT; } while (0) inline void libmemcached_error(Context *context, yyscan_t *scanner, const char *error) { if (not context->end()) - parser_abort_func(context, error); + parser::abort_func(context, error); } int libmemcached_parse(Context*, yyscan_t *); @@ -242,7 +222,7 @@ expression: behaviors: PREFIX_KEY '=' string { - if ((context->rc= memcached_callback_set(context->memc, MEMCACHED_CALLBACK_PREFIX_KEY, std::string($3.c_str, $3.length).c_str())) != MEMCACHED_SUCCESS) + if ((context->rc= memcached_set_prefix_key(context->memc, $3.c_str, $3.length)) != MEMCACHED_SUCCESS) { parser_abort(context, NULL);; } diff --git a/libmemcached/string.c b/libmemcached/string.c index 10a29581..34597067 100644 --- a/libmemcached/string.c +++ b/libmemcached/string.c @@ -212,12 +212,3 @@ void memcached_string_set_length(memcached_string_st *self, size_t length) { self->end= self->string + length; } - -memcached_string_t memcached_string_make(const char *str, size_t length) -{ - memcached_string_t tmp; - tmp.c_str= str; - tmp.size= length; - - return tmp; -} diff --git a/libmemcached/string.h b/libmemcached/string.h index 5dd7d8dd..77c55489 100644 --- a/libmemcached/string.h +++ b/libmemcached/string.h @@ -80,18 +80,22 @@ char *memcached_string_value_mutable(const memcached_string_st *self); LIBMEMCACHED_LOCAL void memcached_string_set_length(memcached_string_st *self, size_t length); -LIBMEMCACHED_LOCAL -memcached_string_t memcached_string_make(const char *str, size_t length); - #ifdef __cplusplus } #endif +#ifdef BUILDING_LIBMEMCACHED #ifdef __cplusplus #define memcached_string_with_size(X) (X), (static_cast((sizeof(X) - 1))) +#define memcached_string_make(X) (static_cast((sizeof(X) - 1))), (X) #else #define memcached_string_with_size(X) (X), ((size_t)((sizeof(X) - 1))) +#define memcached_string_make(X) (((size_t)((sizeof(X) - 1))), (X) +#endif + +#define memcached_string_make_from_cstr(X) (X), ((X) ? strlen(X) : 0) + #endif #endif /* __LIBMEMCACHED_STRING_H__ */ diff --git a/tests/error_conditions.cc b/tests/error_conditions.cc index b46b3ca2..d06f4225 100644 --- a/tests/error_conditions.cc +++ b/tests/error_conditions.cc @@ -37,6 +37,8 @@ #include +#define BUILDING_LIBMEMCACHED + #include #include #include diff --git a/tests/include.am b/tests/include.am index 232cce93..bd5ef260 100644 --- a/tests/include.am +++ b/tests/include.am @@ -36,7 +36,9 @@ noinst_HEADERS+= \ tests/libmemcached_world.h \ tests/parser.h \ tests/print.h \ - tests/replication.h + tests/replication.h \ + tests/string.h + noinst_PROGRAMS+= \ tests/atomsmasher \ @@ -55,7 +57,8 @@ tests_testapp_SOURCES= \ tests/mem_functions.c \ tests/parser.cc \ tests/print.cc \ - tests/replication.cc + tests/replication.cc \ + tests/string.cc tests_testapp_DEPENDENCIES= \ $(BUILT_SOURCES) \ @@ -243,7 +246,7 @@ UDP_COMMAND= tests/testudp $(COLLECTION) $(SUITE) HASH_COMMAND= tests/testhashkit $(COLLECTION) $(SUITE) -test-mem: tests/testapp +test-mem: tests/testapp support/example.cnf $(MEM_COMMAND) test-udp: tests/testudp diff --git a/tests/mem_functions.c b/tests/mem_functions.c index c3f5c30e..93722602 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -35,6 +35,7 @@ #include #include "tests/parser.h" +#include "tests/string.h" #include "tests/replication.h" #include "tests/basic.h" #include "tests/error_conditions.h" @@ -3229,118 +3230,6 @@ static test_return_t result_alloc(memcached_st *memc) return TEST_SUCCESS; } -static test_return_t string_static_null(memcached_st *memc) -{ - memcached_string_st string; - memcached_string_st *string_ptr; - - string_ptr= memcached_string_create(memc, &string, 0); - test_true(string.options.is_initialized == true); - test_true(string_ptr); - - /* The following two better be the same! */ - test_true(memcached_is_allocated(string_ptr) == false); - test_true(memcached_is_allocated(&string) == false); - test_true(&string == string_ptr); - - test_true(string.options.is_initialized == true); - test_true(memcached_is_initialized(&string) == true); - memcached_string_free(&string); - test_true(memcached_is_initialized(&string) == false); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_null(memcached_st *memc) -{ - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, 0); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_with_size(memcached_st *memc) -{ - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, 1024); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_with_size_toobig(memcached_st *memc) -{ - memcached_string_st *string; - - string= memcached_string_create(memc, NULL, SIZE_MAX); - test_true(string == NULL); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_append(memcached_st *memc) -{ - unsigned int x; - char buffer[SMALL_STRING_LEN]; - memcached_string_st *string; - - /* Ring the bell! */ - memset(buffer, 6, SMALL_STRING_LEN); - - string= memcached_string_create(memc, NULL, 100); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - - for (x= 0; x < 1024; x++) - { - memcached_return_t rc; - rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); - test_true(rc == MEMCACHED_SUCCESS); - } - test_true(memcached_is_allocated(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - -static test_return_t string_alloc_append_toobig(memcached_st *memc) -{ - memcached_return_t rc; - unsigned int x; - char buffer[SMALL_STRING_LEN]; - memcached_string_st *string; - - /* Ring the bell! */ - memset(buffer, 6, SMALL_STRING_LEN); - - string= memcached_string_create(memc, NULL, 100); - test_true(string); - test_true(memcached_is_allocated(string) == true); - test_true(memcached_is_initialized(string) == true); - - for (x= 0; x < 1024; x++) - { - rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); - test_true(rc == MEMCACHED_SUCCESS); - } - rc= memcached_string_append(string, buffer, SIZE_MAX); - test_true(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); - test_true(memcached_is_allocated(string) == true); - memcached_string_free(string); - - return TEST_SUCCESS; -} - static test_return_t cleanup_pairs(memcached_st *memc) { (void)memc; @@ -6138,6 +6027,7 @@ test_st string_tests[] ={ {"string alloc with malloc failure", 0, (test_callback_fn)string_alloc_with_size_toobig }, {"string append", 0, (test_callback_fn)string_alloc_append }, {"string append failure (too big)", 0, (test_callback_fn)string_alloc_append_toobig }, + {"string_alloc_append_multiple", 0, (test_callback_fn)string_alloc_append_multiple }, {0, 0, (test_callback_fn)0} }; diff --git a/tests/parser.cc b/tests/parser.cc index 717859b4..d559b84d 100644 --- a/tests/parser.cc +++ b/tests/parser.cc @@ -41,6 +41,7 @@ #include #include +#define BUILDING_LIBMEMCACHED #include #include "tests/parser.h" @@ -345,15 +346,21 @@ test_return_t parser_key_prefix_test(memcached_st *junk) return _test_option(distribution_strings); } +#define SUPPORT_EXAMPLE_CNF "support/example.cnf" + test_return_t memcached_parse_configure_file_test(memcached_st *junk) { (void)junk; + + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; + memcached_st memc; memcached_st *memc_ptr= memcached_create(&memc); test_true(memc_ptr); - memcached_return_t rc= memcached_parse_configure_file(memc_ptr, memcached_string_with_size("support/example.cnf")); + memcached_return_t rc= memcached_parse_configure_file(memc_ptr, memcached_string_with_size(SUPPORT_EXAMPLE_CNF)); test_true_got(rc == MEMCACHED_SUCCESS, memcached_last_error_message(memc_ptr) ? memcached_last_error_message(memc_ptr) : memcached_strerror(NULL, rc)); memcached_free(memc_ptr); @@ -363,6 +370,8 @@ test_return_t memcached_parse_configure_file_test(memcached_st *junk) test_return_t memcached_create_with_options_with_filename(memcached_st *junk) { (void)junk; + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; memcached_st *memc_ptr; memc_ptr= memcached_create_with_options(STRING_WITH_LEN("--CONFIGURE-FILE=\"support/example.cnf\"")); @@ -375,6 +384,10 @@ test_return_t memcached_create_with_options_with_filename(memcached_st *junk) test_return_t libmemcached_check_configuration_with_filename_test(memcached_st *junk) { (void)junk; + + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; + memcached_return_t rc; char buffer[BUFSIZ]; @@ -424,6 +437,9 @@ test_return_t memcached_create_with_options_test(memcached_st *junk) test_return_t test_include_keyword(memcached_st *junk) { + if (access(SUPPORT_EXAMPLE_CNF, R_OK)) + return TEST_SKIPPED; + (void)junk; char buffer[BUFSIZ]; memcached_return_t rc; diff --git a/tests/string.cc b/tests/string.cc new file mode 100644 index 00000000..827d0f2c --- /dev/null +++ b/tests/string.cc @@ -0,0 +1,168 @@ +/* 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 "libmemcached/common.h" +#include "libmemcached/error.h" +#include "tests/string.h" + +test_return_t string_static_null(memcached_st *memc) +{ + memcached_string_st string; + memcached_string_st *string_ptr; + + string_ptr= memcached_string_create(memc, &string, 0); + test_true(string.options.is_initialized == true); + test_true(string_ptr); + + /* The following two better be the same! */ + test_true(memcached_is_allocated(string_ptr) == false); + test_true(memcached_is_allocated(&string) == false); + test_true(&string == string_ptr); + + test_true(string.options.is_initialized == true); + test_true(memcached_is_initialized(&string) == true); + memcached_string_free(&string); + test_true(memcached_is_initialized(&string) == false); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_null(memcached_st *memc) +{ + memcached_string_st *string; + + string= memcached_string_create(memc, NULL, 0); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_with_size(memcached_st *memc) +{ + memcached_string_st *string; + + string= memcached_string_create(memc, NULL, 1024); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_with_size_toobig(memcached_st *memc) +{ + memcached_string_st *string; + + string= memcached_string_create(memc, NULL, SIZE_MAX); + test_true(string == NULL); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_append(memcached_st *memc) +{ + unsigned int x; + char buffer[SMALL_STRING_LEN]; + memcached_string_st *string; + + /* Ring the bell! */ + memset(buffer, 6, SMALL_STRING_LEN); + + string= memcached_string_create(memc, NULL, 100); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + + for (x= 0; x < 1024; x++) + { + memcached_return_t rc; + rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); + test_true(rc == MEMCACHED_SUCCESS); + } + test_true(memcached_is_allocated(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_append_toobig(memcached_st *memc) +{ + memcached_return_t rc; + char buffer[SMALL_STRING_LEN]; + memcached_string_st *string; + + /* Ring the bell! */ + memset(buffer, 6, sizeof(buffer)); + + string= memcached_string_create(memc, NULL, 100); + test_true(string); + test_true(memcached_is_allocated(string) == true); + test_true(memcached_is_initialized(string) == true); + + for (unsigned int x= 0; x < 1024; x++) + { + rc= memcached_string_append(string, buffer, SMALL_STRING_LEN); + test_true(rc == MEMCACHED_SUCCESS); + } + rc= memcached_string_append(string, buffer, SIZE_MAX); + test_true(rc == MEMCACHED_MEMORY_ALLOCATION_FAILURE); + test_true(memcached_is_allocated(string) == true); + memcached_string_free(string); + + return TEST_SUCCESS; +} + +test_return_t string_alloc_append_multiple(memcached_st *memc) +{ + memcached_string_st *error_string= memcached_string_create(memc, NULL, 1024); + memcached_string_append(error_string, memcached_string_with_size("Error occured while parsing: ")); + memcached_string_append(error_string, memcached_string_make_from_cstr("jog the strlen() method")); + memcached_string_append(error_string, memcached_string_with_size(" (")); + + memcached_string_append(error_string, memcached_string_make_from_cstr(memcached_strerror(NULL, MEMCACHED_SUCCESS))); + memcached_string_append(error_string, memcached_string_with_size(")")); + + memcached_set_error_string(memc, MEMCACHED_FAILURE, memcached_string_value(error_string), memcached_string_length(error_string)); + + memcached_string_free(error_string); + + return TEST_SUCCESS; +} diff --git a/tests/string.h b/tests/string.h new file mode 100644 index 00000000..eebd0c11 --- /dev/null +++ b/tests/string.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 + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +LIBTEST_INTERNAL_API +test_return_t string_static_null(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_null(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_with_size(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_with_size_toobig(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_append(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_append_toobig(memcached_st *memc); + +LIBTEST_INTERNAL_API +test_return_t string_alloc_append_multiple(memcached_st *memc); + +#ifdef __cplusplus +} +#endif