From: Brian Aker Date: Fri, 4 May 2012 02:27:50 +0000 (-0700) Subject: Update to add ENV variable LIBMEMCACHED X-Git-Tag: 1.0.8~9^2^2^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=26f4a2a69a448fbda346b7bec93b6bd1d825e12b;p=awesomized%2Flibmemcached Update to add ENV variable LIBMEMCACHED --- diff --git a/.bzrignore b/.bzrignore index 10a43471..2ce25562 100644 --- a/.bzrignore +++ b/.bzrignore @@ -148,3 +148,4 @@ memcached/.git memcached/.gitignore memcached/memcached memcached/memcached.spec +tests/parser diff --git a/libmemcached/memcached.cc b/libmemcached/memcached.cc index 2eb91281..2bcf6fa8 100644 --- a/libmemcached/memcached.cc +++ b/libmemcached/memcached.cc @@ -208,30 +208,49 @@ memcached_st *memcached_create(memcached_st *ptr) memcached_st *memcached(const char *string, size_t length) { - memcached_st *self= memcached_create(NULL); - if (self == NULL) + if (length == 0 and string) + { + return NULL; + } + + if (length and string == NULL) { return NULL; } if (length == 0) { - return self; + if (bool(getenv("LIBMEMCACHED"))) + { + string= getenv("LIBMEMCACHED"); + length= string ? strlen(string) : 0; + } + } + + memcached_st *memc= memcached_create(NULL); + if (memc == NULL) + { + return NULL; + } + + if (length == 0 or string == NULL) + { + return memc; } - memcached_return_t rc= memcached_parse_configuration(self, string, length); - if (memcached_success(rc) and memcached_parse_filename(self)) + memcached_return_t rc= memcached_parse_configuration(memc, string, length); + if (memcached_success(rc) and memcached_parse_filename(memc)) { - rc= memcached_parse_configure_file(*self, memcached_parse_filename(self), memcached_parse_filename_length(self)); + rc= memcached_parse_configure_file(*memc, memcached_parse_filename(memc), memcached_parse_filename_length(memc)); } if (memcached_failed(rc)) { - memcached_free(self); + memcached_free(memc); return NULL; } - return self; + return memc; } memcached_return_t memcached_reset(memcached_st *ptr) diff --git a/libtest/core.cc b/libtest/core.cc index 1663bf47..fba81c03 100644 --- a/libtest/core.cc +++ b/libtest/core.cc @@ -45,7 +45,7 @@ void create_core(void) #ifdef TARGET_OS_OSX return; #endif - if (getenv("LIBMEMCACHED_NO_COREDUMP") == NULL) + if (getenv("YATL_COREDUMP")) { pid_t pid= fork(); diff --git a/libtest/framework.cc b/libtest/framework.cc index 55881b18..eb0f4120 100644 --- a/libtest/framework.cc +++ b/libtest/framework.cc @@ -87,6 +87,7 @@ Framework::~Framework() { delete *iter; } + _collection.clear(); } bool Framework::match(const char* arg) diff --git a/tests/include.am b/tests/include.am index 93801422..8063be75 100644 --- a/tests/include.am +++ b/tests/include.am @@ -41,6 +41,8 @@ noinst_PROGRAMS+= tests/cycle include tests/libmemcached-1.0/include.am +include tests/parser.am + tests_failure_SOURCES= tests_failure_SOURCES+= tests/failure.cc tests_failure_SOURCES+= clients/execute.cc diff --git a/tests/libmemcached-1.0/all_tests.cc b/tests/libmemcached-1.0/all_tests.cc index c9536da1..e5a6d2bf 100644 --- a/tests/libmemcached-1.0/all_tests.cc +++ b/tests/libmemcached-1.0/all_tests.cc @@ -45,10 +45,10 @@ #include "tests/exist.h" #include "tests/ketama.h" #include "tests/namespace.h" -#include "tests/parser.h" #include "tests/libmemcached-1.0/dump.h" #include "tests/libmemcached-1.0/generate.h" #include "tests/libmemcached-1.0/haldenbrand.h" +#include "tests/libmemcached-1.0/parser.h" #include "tests/libmemcached-1.0/stat.h" #include "tests/touch.h" #include "tests/callbacks.h" diff --git a/tests/libmemcached-1.0/all_tests_socket.cc b/tests/libmemcached-1.0/all_tests_socket.cc index 983f38aa..cdc7b211 100644 --- a/tests/libmemcached-1.0/all_tests_socket.cc +++ b/tests/libmemcached-1.0/all_tests_socket.cc @@ -45,7 +45,7 @@ #include "tests/exist.h" #include "tests/ketama.h" #include "tests/namespace.h" -#include "tests/parser.h" +#include "tests/libmemcached-1.0/parser.h" #include "tests/libmemcached-1.0/dump.h" #include "tests/libmemcached-1.0/generate.h" #include "tests/libmemcached-1.0/haldenbrand.h" diff --git a/tests/libmemcached-1.0/include.am b/tests/libmemcached-1.0/include.am index 5201653a..02dc26a7 100644 --- a/tests/libmemcached-1.0/include.am +++ b/tests/libmemcached-1.0/include.am @@ -20,16 +20,16 @@ noinst_HEADERS+= tests/ketama_test_cases_spy.h noinst_HEADERS+= tests/libmemcached-1.0/all_tests.h noinst_HEADERS+= tests/libmemcached-1.0/callback_counter.h noinst_HEADERS+= tests/libmemcached-1.0/dump.h +noinst_HEADERS+= tests/libmemcached-1.0/encoding_key.h noinst_HEADERS+= tests/libmemcached-1.0/fetch_all_results.h noinst_HEADERS+= tests/libmemcached-1.0/generate.h -noinst_HEADERS+= tests/libmemcached-1.0/encoding_key.h noinst_HEADERS+= tests/libmemcached-1.0/haldenbrand.h noinst_HEADERS+= tests/libmemcached-1.0/mem_functions.h noinst_HEADERS+= tests/libmemcached-1.0/memcached_get.h +noinst_HEADERS+= tests/libmemcached-1.0/parser.h noinst_HEADERS+= tests/libmemcached-1.0/setup_and_teardowns.h noinst_HEADERS+= tests/libmemcached-1.0/stat.h noinst_HEADERS+= tests/namespace.h -noinst_HEADERS+= tests/parser.h noinst_HEADERS+= tests/pool.h noinst_HEADERS+= tests/print.h noinst_HEADERS+= tests/replication.h diff --git a/tests/libmemcached-1.0/parser.cc b/tests/libmemcached-1.0/parser.cc index b8b4f47a..3afc12ba 100644 --- a/tests/libmemcached-1.0/parser.cc +++ b/tests/libmemcached-1.0/parser.cc @@ -47,7 +47,7 @@ using namespace libtest; #include #include -#include +#include #include enum scanner_type_t @@ -639,7 +639,6 @@ static memcached_return_t dump_server_information(const memcached_st *, return MEMCACHED_SUCCESS; } - 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"; diff --git a/tests/libmemcached-1.0/parser.h b/tests/libmemcached-1.0/parser.h new file mode 100644 index 00000000..a58bba21 --- /dev/null +++ b/tests/libmemcached-1.0/parser.h @@ -0,0 +1,118 @@ +/* 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 + +#ifdef __cplusplus +extern "C" { +#endif + +test_return_t memcached_NULL_string_TEST(memcached_st*); +test_return_t memcached_zero_string_length_TEST(memcached_st*); + +LIBTEST_LOCAL +test_return_t server_test(memcached_st *memc); + +LIBTEST_LOCAL +test_return_t servers_bad_test(memcached_st *memc); + +LIBTEST_LOCAL +test_return_t behavior_parser_test(memcached_st*); + +LIBTEST_LOCAL +test_return_t parser_number_options_test(memcached_st*); + +LIBTEST_LOCAL +test_return_t parser_distribution_test(memcached_st*); + +LIBTEST_LOCAL +test_return_t parser_hash_test(memcached_st*); + +LIBTEST_LOCAL +test_return_t parser_boolean_options_test(memcached_st*); + +LIBTEST_LOCAL +test_return_t parser_key_prefix_test(memcached_st*); + +LIBTEST_LOCAL + test_return_t libmemcached_check_configuration_test(memcached_st*); + +LIBTEST_LOCAL + test_return_t memcached_create_with_options_test(memcached_st*); + +LIBTEST_LOCAL + test_return_t memcached_create_with_options_with_filename(memcached_st*); + +LIBTEST_LOCAL + test_return_t libmemcached_check_configuration_with_filename_test(memcached_st*); + +LIBTEST_LOCAL + test_return_t random_statement_build_test(memcached_st*); + +LIBTEST_LOCAL +test_return_t test_include_keyword(memcached_st*); + +LIBTEST_LOCAL +test_return_t test_end_keyword(memcached_st*); + +LIBTEST_LOCAL +test_return_t test_reset_keyword(memcached_st*); + +LIBTEST_LOCAL +test_return_t test_error_keyword(memcached_st*); + +LIBTEST_LOCAL +test_return_t server_with_weight_test(memcached_st *); + +LIBTEST_LOCAL +test_return_t test_hostname_port_weight(memcached_st *); + +LIBTEST_LOCAL +test_return_t regression_bug_71231153_connect(memcached_st *); + +LIBTEST_LOCAL +test_return_t regression_bug_71231153_poll(memcached_st *); + +LIBTEST_LOCAL +test_return_t test_parse_socket(memcached_st *); + +LIBTEST_LOCAL +test_return_t test_namespace_keyword(memcached_st*); + +#ifdef __cplusplus +} +#endif diff --git a/tests/parser.am b/tests/parser.am new file mode 100644 index 00000000..25ab3db4 --- /dev/null +++ b/tests/parser.am @@ -0,0 +1,30 @@ +# vim:ft=automake +# Copyright (C) 2012 Data Differential +# All rights reserved. +# +# Use and distribution licensed under the BSD license. See +# the COPYING file in the parent directory for full text. +# +# included from Top Level Makefile.am +# All paths should be given relative to the root + +noinst_HEADERS+= tests/libmemcached-1.0/parser.h + +tests_parser_SOURCES= +tests_parser_CXXFLAGS= +tests_parser_DEPENDENCIES= +tests_parser_LDADD= + +tests_parser_SOURCES+= tests/parser.cc + +tests_parser_CXXFLAGS+= $(AM_CXXFLAGS) $(NO_EFF_CXX) +tests_parser_DEPENDENCIES+= $(TESTS_LDADDS) +tests_parser_LDADD+= $(tests_parser_DEPENDENCIES) +check_PROGRAMS+= tests/parser +noinst_PROGRAMS+= tests/parser + +test-parser: tests/parser + @tests/parser + +valgrind-parser: tests/parser + $(VALGRIND_COMMAND) tests/parser diff --git a/tests/parser.cc b/tests/parser.cc new file mode 100644 index 00000000..740a9c19 --- /dev/null +++ b/tests/parser.cc @@ -0,0 +1,131 @@ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Libmemcached library + * + * Copyright (C) 2012 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. + * + */ + +#include + +/* + C++ interface test +*/ +#include +#include + +using namespace libtest; + +static test_return_t memcached_NULL_string_TEST(void*) +{ + test_null(memcached(NULL, 75)); + return TEST_SUCCESS; +} + +static test_return_t memcached_zero_string_length_TEST(void*) +{ + test_null(memcached("value", 0)); + return TEST_SUCCESS; +} + +static test_return_t putenv_localhost_quoted_TEST(void*) +{ + char set_env[1024]; + + snprintf(set_env, sizeof(set_env), "LIBMEMCACHED=\"--server=localhost\""); + test_zero(putenv(set_env)); + test_null(memcached(NULL, 0)); + + return TEST_SUCCESS; +} + +static test_return_t putenv_NULL_TEST(void*) +{ + char set_env[1024]; + + snprintf(set_env, sizeof(set_env), "LIBMEMCACHED"); + test_zero(putenv(set_env)); + memcached_st *memc= memcached(NULL, 0); + test_true(memc); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +static test_return_t putenv_NULL_TEST2(void*) +{ + char set_env[1024]; + + snprintf(set_env, sizeof(set_env), "LIBMEMCACHED="); + test_zero(putenv(set_env)); + memcached_st *memc= memcached(NULL, 0); + test_true(memc); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +static test_return_t putenv_localhost_TEST(void*) +{ + char set_env[1024]; + + snprintf(set_env, sizeof(set_env), "LIBMEMCACHED=--server=localhost"); + test_zero(putenv(set_env)); + memcached_st *memc= memcached(NULL, 0); + test_true(memc); + + memcached_free(memc); + + return TEST_SUCCESS; +} + +test_st memcached_TESTS[] ={ + {"memcached(NULL, 75)", false, (test_callback_fn*)memcached_NULL_string_TEST }, + {"memcached(\"value\", 0)", false, (test_callback_fn*)memcached_zero_string_length_TEST }, + {"putenv(LIBMEMCACHED=--server=localhost)", false, (test_callback_fn*)putenv_localhost_TEST }, + {"putenv(LIBMEMCACHED)", false, (test_callback_fn*)putenv_NULL_TEST }, + {"putenv(LIBMEMCACHED=)", false, (test_callback_fn*)putenv_NULL_TEST2 }, + {"putenv(LIBMEMCACHED=--server=\"localhost\")", false, (test_callback_fn*)putenv_localhost_quoted_TEST }, + {0, 0, 0} +}; + +collection_st collection[] ={ + {"memcached()", 0, 0, memcached_TESTS}, + {0, 0, 0, 0} +}; + +void get_world(Framework *world) +{ + world->collections= collection; +} + diff --git a/tests/parser.h b/tests/parser.h deleted file mode 100644 index 73356dad..00000000 --- a/tests/parser.h +++ /dev/null @@ -1,115 +0,0 @@ -/* 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 - -#ifdef __cplusplus -extern "C" { -#endif - -LIBTEST_LOCAL -test_return_t server_test(memcached_st *memc); - -LIBTEST_LOCAL -test_return_t servers_bad_test(memcached_st *memc); - -LIBTEST_LOCAL -test_return_t behavior_parser_test(memcached_st*); - -LIBTEST_LOCAL -test_return_t parser_number_options_test(memcached_st*); - -LIBTEST_LOCAL -test_return_t parser_distribution_test(memcached_st*); - -LIBTEST_LOCAL -test_return_t parser_hash_test(memcached_st*); - -LIBTEST_LOCAL -test_return_t parser_boolean_options_test(memcached_st*); - -LIBTEST_LOCAL -test_return_t parser_key_prefix_test(memcached_st*); - -LIBTEST_LOCAL - test_return_t libmemcached_check_configuration_test(memcached_st*); - -LIBTEST_LOCAL - test_return_t memcached_create_with_options_test(memcached_st*); - -LIBTEST_LOCAL - test_return_t memcached_create_with_options_with_filename(memcached_st*); - -LIBTEST_LOCAL - test_return_t libmemcached_check_configuration_with_filename_test(memcached_st*); - -LIBTEST_LOCAL - test_return_t random_statement_build_test(memcached_st*); - -LIBTEST_LOCAL -test_return_t test_include_keyword(memcached_st*); - -LIBTEST_LOCAL -test_return_t test_end_keyword(memcached_st*); - -LIBTEST_LOCAL -test_return_t test_reset_keyword(memcached_st*); - -LIBTEST_LOCAL -test_return_t test_error_keyword(memcached_st*); - -LIBTEST_LOCAL -test_return_t server_with_weight_test(memcached_st *); - -LIBTEST_LOCAL -test_return_t test_hostname_port_weight(memcached_st *); - -LIBTEST_LOCAL -test_return_t regression_bug_71231153_connect(memcached_st *); - -LIBTEST_LOCAL -test_return_t regression_bug_71231153_poll(memcached_st *); - -LIBTEST_LOCAL -test_return_t test_parse_socket(memcached_st *); - -LIBTEST_LOCAL -test_return_t test_namespace_keyword(memcached_st*); - -#ifdef __cplusplus -} -#endif