From: Brian Aker Date: Tue, 1 Jan 2013 01:49:31 +0000 (-0500) Subject: Second pass on update of yatl. X-Git-Tag: 1.0.16~20^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=543d6be67139ee7cb47c0c8e7d383743f4e68857;p=awesomized%2Flibmemcached Second pass on update of yatl. --- diff --git a/libtest/fatal.cc b/libtest/fatal.cc index 626ec6f8..99b15535 100644 --- a/libtest/fatal.cc +++ b/libtest/fatal.cc @@ -41,17 +41,47 @@ namespace libtest { #pragma GCC diagnostic ignored "-Wformat-nonliteral" + fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) : - __test_result(file_arg, line_arg, func_arg) + __test_result(file_arg, line_arg, func_arg), + _error_message(NULL), + _error_message_size(0) +{ + va_list args; + va_start(args, func_arg); + const char *format= va_arg(args, const char *); + _error_message_size= vasprintf(&_error_message, format, args); + assert(_error_message_size != -1); + if (_error_message_size > 0) + { + _error_message_size++; + } + va_end(args); +} + +fatal::fatal( const fatal& other ) : + __test_result(other), + _error_message_size(other._error_message_size) +{ + _error_message= (char*) malloc(_error_message_size); + if (_error_message) + { + memcpy(_error_message, other._error_message, _error_message_size); + } + else { - va_list args; - va_start(args, func_arg); - const char *format= va_arg(args, const char *); - int last_error_length= vsnprintf(0, 0, format, args); - _error_message.resize(last_error_length +1); - last_error_length= vsnprintf(&_error_message[0], _error_message.size(), format, args); - va_end(args); + _error_message_size= -1; } +} + +fatal::~fatal() throw() +{ + if ((_error_message_size > 0) and _error_message) + { + free(_error_message); + _error_message= NULL; + } +} static bool _disabled= false; static uint32_t _counter= 0; diff --git a/libtest/include.am b/libtest/include.am index 1b6f8e29..b303e2e8 100644 --- a/libtest/include.am +++ b/libtest/include.am @@ -155,9 +155,7 @@ libtest_unittest_CXXFLAGS= libtest_unittest_LDADD= # We are either building in tree, or with -if HAVE_MEMCACHED_BINARY libtest_libtest_la_SOURCES+= libtest/memcached.cc -endif if HAVE_LIBDRIZZLE diff --git a/libtest/m4/ax_prog_memcached.m4 b/libtest/m4/ax_prog_memcached.m4 deleted file mode 100644 index d161dbe3..00000000 --- a/libtest/m4/ax_prog_memcached.m4 +++ /dev/null @@ -1,59 +0,0 @@ -# =========================================================================== -# http://www.gnu.org/software/autoconf-archive/ax_prog_memcached.html -# =========================================================================== -# -# SYNOPSIS -# -# AX_PROG_MEMCACHED -# -# DESCRIPTION -# -# Check for the program 'memcached' let script continue if exists & works -# pops up error message if not. -# -# Besides checking existence, this macro also set these environment -# variables upon completion: -# -# MEMCACHED = which memcached -# -# LICENSE -# -# Copyright (c) 2012 Brian Aker -# Copyright (c) 2008 Gleen Salmon -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; either version 2 of the License, or (at your -# option) any later version. -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program. If not, see . -# -# As a special exception, the respective Autoconf Macro's copyright owner -# gives unlimited permission to copy, distribute and modify the configure -# scripts that are the output of Autoconf when processing the Macro. You -# need not follow the terms of the GNU General Public License when using -# or distributing such scripts, even though portions of the text of the -# Macro appear in them. The GNU General Public License (GPL) does govern -# all other use of the material that constitutes the Autoconf Macro. -# -# This special exception to the GPL applies to versions of the Autoconf -# Macro released by the Autoconf Archive. When you make and distribute a -# modified version of the Autoconf Macro, you may extend this special -# exception to the GPL to apply to your modified version as well. - -#serial 6 - -AU_ALIAS([AC_PROG_MEMCACHED], [AX_PROG_MEMCACHED]) -AC_DEFUN([AX_PROG_MEMCACHED],[ -AC_REQUIRE([AC_EXEEXT])dnl -AC_PATH_PROG(MEMCACHED, memcached$EXEEXT, nocommand) -if test "$MEMCACHED" = nocommand; then - AC_MSG_WARN([memcached not found in $PATH]) -fi;dnl -]) diff --git a/libtest/m4/memcached.m4 b/libtest/m4/memcached.m4 index 43b87433..0fece500 100644 --- a/libtest/m4/memcached.m4 +++ b/libtest/m4/memcached.m4 @@ -1,14 +1,11 @@ #serial 2 AC_DEFUN([YATL_MEMCACHED], - [AC_REQUIRE([AX_ENABLE_LIBMEMCACHED]) - - AX_WITH_PROG(MEMCACHED_BINARY, [memcached]) + [AX_WITH_PROG(MEMCACHED_BINARY, [memcached]) AS_IF([test -f "$ac_cv_path_MEMCACHED_BINARY"], [AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) AC_DEFINE_UNQUOTED([MEMCACHED_BINARY], "$ac_cv_path_MEMCACHED_BINARY", [Name of the memcached binary used in make test])], [AC_DEFINE([HAVE_MEMCACHED_BINARY], [1], [If Memcached binary is available]) AC_DEFINE([MEMCACHED_BINARY], ["memcached/memcached"], [Name of the memcached binary used in make test]) ]) - AM_CONDITIONAL([HAVE_MEMCACHED_BINARY],[test -f "$ac_cv_path_MEMCACHED_BINARY"]) ]) diff --git a/libtest/memcached.cc b/libtest/memcached.cc index 717ccb69..ff246b5a 100644 --- a/libtest/memcached.cc +++ b/libtest/memcached.cc @@ -222,23 +222,22 @@ bool Memcached::build(size_t argc, const char *argv[]) libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port) { - return new Memcached(hostname, try_port, false); -} + if (HAVE_MEMCACHED_BINARY) + { + return new Memcached(hostname, try_port, false); + } -libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port) -{ - return new Memcached(socket_file, try_port, true); + return NULL; } -libtest::Server *build_memcached_sasl(const std::string& hostname, const in_port_t try_port, const std::string& username, const std::string &password) +libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port) { - if (username.empty()) + if (HAVE_MEMCACHED_BINARY) { - return new Memcached(hostname, try_port, false, "memcached", "memcached"); + return new Memcached(socket_file, try_port, true); } - return new Memcached(hostname, try_port, false, username, password); + return NULL; } } // namespace libtest - diff --git a/libtest/memcached.h b/libtest/memcached.h index 405f275f..195ce7ab 100644 --- a/libtest/memcached.h +++ b/libtest/memcached.h @@ -40,13 +40,7 @@ namespace libtest { libtest::Server *build_memcached(const std::string& hostname, const in_port_t try_port); -libtest::Server *build_memcached_light(const std::string& socket_file, const in_port_t try_port); - libtest::Server *build_memcached_socket(const std::string& socket_file, const in_port_t try_port); -libtest::Server *build_memcached_sasl(const std::string& hostname, const in_port_t try_port, const std::string& username, const std::string& password); - -libtest::Server *build_memcached_sasl_socket(const std::string& socket_file, const in_port_t try_port, const std::string& username, const std::string& password); - } diff --git a/libtest/result/fatal.hpp b/libtest/result/fatal.hpp index 39778ab8..deebb358 100644 --- a/libtest/result/fatal.hpp +++ b/libtest/result/fatal.hpp @@ -43,9 +43,9 @@ class fatal : public __test_result public: fatal(const char *file, int line, const char *func, ...); - ~fatal() throw() - { - } + fatal(const fatal&); + + ~fatal() throw(); const char* what() const throw() { @@ -60,7 +60,8 @@ public: static void increment_disabled_counter(); private: - vchar_t _error_message; + char* _error_message; + int _error_message_size; }; } // namespace libtest diff --git a/libtest/server_container.cc b/libtest/server_container.cc index 802514d2..e9b2f4e0 100644 --- a/libtest/server_container.cc +++ b/libtest/server_container.cc @@ -333,7 +333,7 @@ bool server_startup_st::start_socket_server(const std::string& server_type, cons } else if (server_type.compare("memcached") == 0) { - if (MEMCACHED_BINARY) + if (HAVE_MEMCACHED_BINARY) { server= build_memcached_socket("localhost", try_port); } diff --git a/libtest/unittest.cc b/libtest/unittest.cc index 75b41f70..e35911bf 100644 --- a/libtest/unittest.cc +++ b/libtest/unittest.cc @@ -143,10 +143,7 @@ static test_return_t test_throw_skip_TEST(void *) static test_return_t test_throw_fail_TEST(void *) { try { -#if 0 FAIL("test message!"); -#endif - throw libtest::__failure(LIBYATL_DEFAULT_PARAM, "test message!"); } catch (const libtest::__failure& e) { @@ -168,10 +165,9 @@ static test_return_t ASSERT_FALSE__TEST(void *) try { ASSERT_FALSE_(true, __func__); } - catch (libtest::__failure e) + catch (const libtest::__failure& e) { - std::string compare_message(__func__); - ASSERT_EQ(compare_message.compare(e.what()), -32); + ASSERT_STREQ(e.what(), "Assertion '!true' [ ASSERT_FALSE__TEST ]"); return TEST_SUCCESS; } catch (...) @@ -187,10 +183,9 @@ static test_return_t ASSERT_FALSE_TEST(void *) try { FAIL(__func__); } - catch (libtest::__failure e) + catch (const libtest::__failure& e) { - std::string compare_message(__func__); - ASSERT_EQ(0, compare_message.compare(e.what())); + ASSERT_STREQ(e.what(), __func__); return TEST_SUCCESS; } catch (...)