Application::error_t Application::join()
{
pid_t waited_pid= waitpid(_pid, &_status, 0);
-
if (waited_pid == _pid and WIFEXITED(_status) == false)
{
/*
buffer.resize(1024);
int length= snprintf(&buffer[0], buffer.size(), "--log-file=%s", log_file.c_str());
fatal_assert(length > 0 and size_t(length) < buffer.size());
- built_argv.push_back(&buffer[0]);
+ built_argv.push_back(strdup(&buffer[0]));
}
else if (_use_gdb)
{
template <class T>
void operator() ( T* ptr) const
{
- free(ptr);
+ if (ptr)
+ {
+ free(ptr);
+ }
}
};
#include <spawn.h>
// http://www.gnu.org/software/automake/manual/automake.html#Using-the-TAP-test-protocol
-#define EXIT_SKIP 77
-#define EXIT_FATAL 77
+#ifndef EXIT_SKIP
+# define EXIT_SKIP 77
+#endif
+
+#ifndef EXIT_FATAL
+# define EXIT_FATAL 99
+#endif
#ifndef EX_NOEXEC
# define EX_NOEXEC 126
std::string print();
- void use_valgrind(bool arg= true)
+ void use_valgrind(bool arg)
{
_use_valgrind= arg;
}
bool slurp();
void murder();
- void use_gdb(bool arg= true)
+ void use_gdb(bool arg)
{
_use_gdb= arg;
}
- void use_ptrcheck(bool arg= true)
+ void use_ptrcheck(bool arg)
{
_use_ptrcheck= arg;
}
return false;
}
-bool valgrind_is_caller(void)
-{
- if (bool(getenv("TESTS_ENVIRONMENT")) and strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
- {
- return true;
- }
-
- return false;
-}
-
bool gdb_is_caller(void)
{
if (bool(getenv("TESTS_ENVIRONMENT")) and strstr(getenv("TESTS_ENVIRONMENT"), "gdb"))
#include <typeinfo>
#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED
-# include <libmemcached-1.0/memcached.h>
-# include <libmemcachedutil-1.0/ostream.hpp>
-# include <libtest/memcached.hpp>
+#include <libmemcached-1.0/memcached.h>
+#include <libmemcachedutil-1.0/ostream.hpp>
+#include <libtest/memcached.hpp>
#endif
#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
-# include <libgearman-1.0/ostream.hpp>
+#include <libgearman-1.0/ostream.hpp>
#endif
namespace libtest {
LIBTEST_API
bool gdb_is_caller(void);
-LIBTEST_API
-bool valgrind_is_caller(void);
-
LIBTEST_API
bool _in_valgrind(const char *file, int line, const char *func);
namespace libtest {
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, const char *format, ...) :
- std::runtime_error(func_arg),
- _line(line_arg),
- _file(file_arg),
- _func(func_arg)
+fatal::fatal(const char *file_arg, int line_arg, const char *func_arg, ...) :
+ __test_result(file_arg, line_arg, func_arg)
{
va_list args;
- va_start(args, format);
- char last_error[BUFSIZ];
- int last_error_length= vsnprintf(last_error, sizeof(last_error), format, 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);
-
- strncpy(_mesg, last_error, sizeof(_mesg));
-
- snprintf(_error_message, sizeof(_error_message), "%.*s", last_error_length, last_error);
}
static bool _disabled= false;
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
disconnected::disconnected(const char *file_arg, int line_arg, const char *func_arg,
- const std::string& instance, const in_port_t port,
- const char *format, ...) :
+ const std::string& instance, const in_port_t port, ...) :
std::runtime_error(func_arg),
_port(port),
_line(line_arg),
_func(func_arg)
{
va_list args;
- va_start(args, format);
+ va_start(args, port);
+ const char *format= va_arg(args, const char *);
char last_error[BUFSIZ];
(void)vsnprintf(last_error, sizeof(last_error), format, args);
va_end(args);
#include <stdexcept>
-#ifndef __PRETTY_FUNCTION__
-#define __PRETTY_FUNCTION__ __func__
-#endif
-
-#define YATL_STRINGIFY(x) #x
-#define YATL_TOSTRING(x) YATL_STRINGIFY(x)
-#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__)
-#define YATL_AT_PARAM __func__, AT
-#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique"
-#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func"
-
-#define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__
-
namespace libtest {
-class fatal : std::runtime_error
-{
-public:
- fatal(const char *file, int line, const char *func, const char *format, ...);
-
- const char* what() const throw()
- {
- return _error_message;
- }
-
- const char* mesg() const throw()
- {
- return _error_message;
- }
-
- // The following are just for unittesting the exception class
- static bool is_disabled();
- static void disable();
- static void enable();
- static uint32_t disabled_counter();
- static void increment_disabled_counter();
-
- int line()
- {
- return _line;
- }
-
- const char* file()
- {
- return _file;
- }
-
- const char* func()
- {
- return _func;
- }
-
-private:
- char _error_message[BUFSIZ];
- char _mesg[BUFSIZ];
- int _line;
- const char* _file;
- const char* _func;
-};
-
class disconnected : std::runtime_error
{
public:
- disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, const char *format, ...);
+ disconnected(const char *file, int line, const char *func, const std::string&, const in_port_t port, ...);
const char* what() const throw()
{
- return _error_message;
+ return &_error_message[0];
}
// The following are just for unittesting the exception class
const char* _func;
};
-
} // namespace libtest
-
-#define fatal_message(__mesg) throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", __mesg)
-#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, "%s", #__assert); }
catch (libtest::fatal& e)
{
_failed++;
- stream::cerr(e.file(), e.line(), e.func()) << e.mesg();
+ stream::cerr(e.file(), e.line(), e.func()) << e.what();
}
catch (libtest::disconnected& e)
{
#
# included from Top Level Makefile.am
# All paths should be given relative to the root
-#
+#
LIBTOOL_COMMAND= ${abs_top_builddir}/libtool --mode=execute
VALGRIND_EXEC_COMMAND= $(LIBTOOL_COMMAND) valgrind --error-exitcode=1 --leak-check=yes --track-fds=yes --malloc-fill=A5 --free-fill=DE
noinst_HEADERS+= libtest/formatter.hpp
noinst_HEADERS+= libtest/timer.hpp
noinst_HEADERS+= libtest/alarm.h
-noinst_HEADERS+= libtest/binaries.h
-noinst_HEADERS+= libtest/cpu.hpp
-noinst_HEADERS+= libtest/blobslap_worker.h
-noinst_HEADERS+= libtest/callbacks.h
-noinst_HEADERS+= libtest/dns.hpp
-noinst_HEADERS+= libtest/cmdline.h
-noinst_HEADERS+= libtest/collection.h
-noinst_HEADERS+= libtest/common.h
-noinst_HEADERS+= libtest/comparison.hpp
-noinst_HEADERS+= libtest/core.h
-noinst_HEADERS+= libtest/dream.h
-noinst_HEADERS+= libtest/error.h
-noinst_HEADERS+= libtest/failed.h
-noinst_HEADERS+= libtest/fatal.hpp
-noinst_HEADERS+= libtest/framework.h
-noinst_HEADERS+= libtest/gearmand.h
-noinst_HEADERS+= libtest/drizzled.h
-noinst_HEADERS+= libtest/get.h
-noinst_HEADERS+= libtest/has.hpp
-noinst_HEADERS+= libtest/http.hpp
-noinst_HEADERS+= libtest/is_pid.hpp
-noinst_HEADERS+= libtest/is_local.hpp
-noinst_HEADERS+= libtest/killpid.h
-noinst_HEADERS+= libtest/libtool.hpp
-noinst_HEADERS+= libtest/memcached.h
+noinst_HEADERS+= libtest/binaries.h
+noinst_HEADERS+= libtest/cpu.hpp
+noinst_HEADERS+= libtest/blobslap_worker.h
+noinst_HEADERS+= libtest/callbacks.h
+noinst_HEADERS+= libtest/dns.hpp
+noinst_HEADERS+= libtest/cmdline.h
+noinst_HEADERS+= libtest/collection.h
+noinst_HEADERS+= libtest/common.h
+noinst_HEADERS+= libtest/comparison.hpp
+noinst_HEADERS+= libtest/core.h
+noinst_HEADERS+= libtest/dream.h
+noinst_HEADERS+= libtest/error.h
+noinst_HEADERS+= libtest/failed.h
+noinst_HEADERS+= libtest/fatal.hpp
+noinst_HEADERS+= libtest/framework.h
+noinst_HEADERS+= libtest/gearmand.h
+noinst_HEADERS+= libtest/drizzled.h
+noinst_HEADERS+= libtest/get.h
+noinst_HEADERS+= libtest/has.hpp
+noinst_HEADERS+= libtest/http.hpp
+noinst_HEADERS+= libtest/is_pid.hpp
+noinst_HEADERS+= libtest/is_local.hpp
+noinst_HEADERS+= libtest/killpid.h
+noinst_HEADERS+= libtest/libtool.hpp
+noinst_HEADERS+= libtest/memcached.h
noinst_HEADERS+= libtest/memcached.hpp
noinst_HEADERS+= libtest/poll_error.hpp
-noinst_HEADERS+= libtest/port.h
-noinst_HEADERS+= libtest/result.hpp
-noinst_HEADERS+= libtest/runner.h
-noinst_HEADERS+= libtest/server.h
-noinst_HEADERS+= libtest/server_container.h
-noinst_HEADERS+= libtest/signal.h
-noinst_HEADERS+= libtest/socket.hpp
-noinst_HEADERS+= libtest/stream.h
-noinst_HEADERS+= libtest/strerror.h
-noinst_HEADERS+= libtest/string.hpp
-noinst_HEADERS+= libtest/test.h
-noinst_HEADERS+= libtest/test.hpp
+noinst_HEADERS+= libtest/port.h
+noinst_HEADERS+= libtest/result.hpp
+noinst_HEADERS+= libtest/result/base.hpp
+noinst_HEADERS+= libtest/result/fail.hpp
+noinst_HEADERS+= libtest/result/fatal.hpp
+noinst_HEADERS+= libtest/result/skip.hpp
+noinst_HEADERS+= libtest/result/success.hpp
+noinst_HEADERS+= libtest/runner.h
+noinst_HEADERS+= libtest/server.h
+noinst_HEADERS+= libtest/server_container.h
+noinst_HEADERS+= libtest/signal.h
+noinst_HEADERS+= libtest/socket.hpp
+noinst_HEADERS+= libtest/stream.h
+noinst_HEADERS+= libtest/strerror.h
+noinst_HEADERS+= libtest/string.hpp
+noinst_HEADERS+= libtest/test.h
+noinst_HEADERS+= libtest/test.hpp
noinst_HEADERS+= libtest/thread.hpp
-noinst_HEADERS+= libtest/tmpfile.hpp
-noinst_HEADERS+= libtest/vchar.hpp
-noinst_HEADERS+= libtest/version.h
-noinst_HEADERS+= libtest/visibility.h
+noinst_HEADERS+= libtest/tmpfile.hpp
+noinst_HEADERS+= libtest/lite.h
+noinst_HEADERS+= libtest/vchar.hpp
+noinst_HEADERS+= libtest/version.h
+noinst_HEADERS+= libtest/visibility.h
noinst_HEADERS+= libtest/wait.h
+noinst_HEADERS+= libtest/yatl.h
noinst_LTLIBRARIES+= libtest/libtest.la
libtest_libtest_la_LIBADD=
libtest_libtest_la_SOURCES=
-libtest_libtest_la_SOURCES+= libtest/alarm.cc
-libtest_libtest_la_SOURCES+= libtest/binaries.cc
-libtest_libtest_la_SOURCES+= libtest/cmdline.cc
-libtest_libtest_la_SOURCES+= libtest/collection.cc
-libtest_libtest_la_SOURCES+= libtest/comparison.cc
-libtest_libtest_la_SOURCES+= libtest/core.cc
-libtest_libtest_la_SOURCES+= libtest/cpu.cc
-libtest_libtest_la_SOURCES+= libtest/dns.cc
-libtest_libtest_la_SOURCES+= libtest/dream.cc
-libtest_libtest_la_SOURCES+= libtest/drizzled.cc
-libtest_libtest_la_SOURCES+= libtest/fatal.cc
-libtest_libtest_la_SOURCES+= libtest/formatter.cc
-libtest_libtest_la_SOURCES+= libtest/client.cc
-libtest_libtest_la_SOURCES+= libtest/framework.cc
-libtest_libtest_la_SOURCES+= libtest/has.cc
-libtest_libtest_la_SOURCES+= libtest/http.cc
-libtest_libtest_la_SOURCES+= libtest/is_local.cc
-libtest_libtest_la_SOURCES+= libtest/killpid.cc
-libtest_libtest_la_SOURCES+= libtest/libtool.cc
-libtest_libtest_la_SOURCES+= libtest/main.cc
-libtest_libtest_la_SOURCES+= libtest/port.cc
-libtest_libtest_la_SOURCES+= libtest/result.cc
-libtest_libtest_la_SOURCES+= libtest/runner.cc
-libtest_libtest_la_SOURCES+= libtest/server.cc
-libtest_libtest_la_SOURCES+= libtest/server_container.cc
-libtest_libtest_la_SOURCES+= libtest/signal.cc
-libtest_libtest_la_SOURCES+= libtest/socket.cc
-libtest_libtest_la_SOURCES+= libtest/strerror.cc
-libtest_libtest_la_SOURCES+= libtest/timer.cc
-libtest_libtest_la_SOURCES+= libtest/tmpfile.cc
+libtest_libtest_la_SOURCES+= libtest/alarm.cc
+libtest_libtest_la_SOURCES+= libtest/binaries.cc
+libtest_libtest_la_SOURCES+= libtest/cmdline.cc
+libtest_libtest_la_SOURCES+= libtest/collection.cc
+libtest_libtest_la_SOURCES+= libtest/comparison.cc
+libtest_libtest_la_SOURCES+= libtest/core.cc
+libtest_libtest_la_SOURCES+= libtest/cpu.cc
+libtest_libtest_la_SOURCES+= libtest/dns.cc
+libtest_libtest_la_SOURCES+= libtest/dream.cc
+libtest_libtest_la_SOURCES+= libtest/drizzled.cc
+libtest_libtest_la_SOURCES+= libtest/fatal.cc
+libtest_libtest_la_SOURCES+= libtest/formatter.cc
+libtest_libtest_la_SOURCES+= libtest/client.cc
+libtest_libtest_la_SOURCES+= libtest/framework.cc
+libtest_libtest_la_SOURCES+= libtest/has.cc
+libtest_libtest_la_SOURCES+= libtest/http.cc
+libtest_libtest_la_SOURCES+= libtest/is_local.cc
+libtest_libtest_la_SOURCES+= libtest/killpid.cc
+libtest_libtest_la_SOURCES+= libtest/libtool.cc
+libtest_libtest_la_SOURCES+= libtest/main.cc
+libtest_libtest_la_SOURCES+= libtest/port.cc
+libtest_libtest_la_SOURCES+= libtest/result.cc
+libtest_libtest_la_SOURCES+= libtest/runner.cc
+libtest_libtest_la_SOURCES+= libtest/server.cc
+libtest_libtest_la_SOURCES+= libtest/server_container.cc
+libtest_libtest_la_SOURCES+= libtest/signal.cc
+libtest_libtest_la_SOURCES+= libtest/socket.cc
+libtest_libtest_la_SOURCES+= libtest/strerror.cc
+libtest_libtest_la_SOURCES+= libtest/timer.cc
+libtest_libtest_la_SOURCES+= libtest/tmpfile.cc
libtest_libtest_la_SOURCES+= libtest/vchar.cc
libtest_libtest_la_CXXFLAGS+= -DBUILDING_LIBTEST
libtest_libtest_la_LIBADD+= @RT_LIB@
EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest_tmp_dir
-EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest/abort
-EXTRA_libtest_libtest_la_DEPENDENCIES+= libtest/wait
+EXTRA_libtest_libtest_la_DEPENDENCIES+=libtest/abort
+EXTRA_libtest_libtest_la_DEPENDENCIES+=libtest/wait
# Declare unittest so that we can append to it
libtest_unittest_CXXFLAGS=
libtest_unittest_LDADD=
# We are either building in tree, or with
-if BUILDING_LIBMEMCACHED
-libtest_libtest_la_SOURCES+= libtest/memcached.cc
-libtest_libtest_la_CXXFLAGS+= -DHAVE_LIBMEMCACHED
-
-libtest_unittest_CXXFLAGS+= -DHAVE_LIBMEMCACHED
-else
-if HAVE_LIBMEMCACHED
+if HAVE_MEMCACHED_BINARY
libtest_libtest_la_SOURCES+= libtest/memcached.cc
-else
-libtest_libtest_la_CXXFLAGS+= -DHAVE_LIBMEMCACHED=0
-libtest_unittest_CXXFLAGS+= -DHAVE_LIBMEMCACHED=0
-endif
endif
if HAVE_LIBDRIZZLE
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) 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.
+ *
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+# include <cstddef>
+# include <cstdlib>
+# include <cstring>
+#include <cstdarg>
+#else
+# include <stddef.h>
+# include <stdlib.h>
+# include <stdbool.h>
+# include <string.h>
+# include <stdarg.h>
+#endif
+
+#include <alloca.h>
+
+#ifndef __PRETTY_FUNCTION__
+# define __PRETTY_FUNCTION__ __func__
+#endif
+
+#ifndef EXIT_SKIP
+# define EXIT_SKIP 77
+#endif
+
+#ifndef YATL_FULL
+# define YATL_FULL 0
+#endif
+
+#ifndef FAIL
+# define FAIL(__message_format, ...)
+#endif
+
+static inline bool valgrind_is_caller(void)
+{
+ if (getenv("TESTS_ENVIRONMENT") && strstr(getenv("TESTS_ENVIRONMENT"), "valgrind"))
+ {
+ return true;
+ }
+
+ return false;
+}
+
+static inline size_t yatl_strlen(const char *s)
+{
+ if (s)
+ {
+ return strlen(s);
+ }
+
+ return (size_t)(0);
+}
+
+static inline int yatl_strcmp(const char *s1, const char *s2, size_t *s1_length, size_t *s2_length)
+{
+ *s1_length= yatl_strlen(s1);
+ *s2_length= yatl_strlen(s2);
+
+ if (*s1_length == 0 && *s1_length == *s2_length)
+ {
+ return 0;
+ }
+
+ if (*s1_length == 0 && *s2_length)
+ {
+ return 1;
+ }
+
+ if (*s1_length && *s2_length == 0)
+ {
+ return 1;
+ }
+
+ return strcmp(s1, s2);
+}
+
+#define SKIP_IF(__expression) \
+do \
+{ \
+ if ((__expression)) { \
+ fprintf(stderr, "\n%s:%d: %s SKIP '!%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression); \
+ exit(EXIT_SKIP); \
+ } \
+} while (0)
+
+#define ASSERT_TRUE(__expression) \
+do \
+{ \
+ if (! (__expression)) { \
+ if (YATL_FULL) { \
+ FAIL("Assertion '%s'", #__expression); \
+ } \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression);\
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_FALSE(__expression) \
+do \
+{ \
+ if ((__expression)) { \
+ if (YATL_FULL) { \
+ FAIL("Assertion '!%s'", #__expression); \
+ } \
+ fprintf(stderr, "\n%s:%d: %s Assertion '!%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression);\
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_NULL_(__expression, ...) \
+do \
+{ \
+ if ((__expression) != NULL) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' != NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\
+ free(buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_NOT_NULL(__expression) \
+do \
+{ \
+ if ((__expression) == NULL) { \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression,);\
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_NOT_NULL_(__expression, ...) \
+do \
+{ \
+ if ((__expression) == NULL) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == NULL [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer);\
+ free(buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define SKIP_IF_(__expression, ...) \
+do \
+{ \
+ if ((__expression)) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stdout, "\n%s:%d: %s SKIP '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
+ free(buffer); \
+ exit(EXIT_SKIP); \
+ } \
+} while (0)
+
+#define ASSERT_TRUE_(__expression, ...) \
+do \
+{ \
+ if (! (__expression)) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
+ free(buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_EQ(__expected, __actual) \
+do \
+{ \
+ if ((__expected) != (__actual)) { \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_EQ_(__expected, __actual, ...) \
+do \
+{ \
+ if ((__expected) != (__actual)) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' != '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \
+ free(buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_STREQ(__expected_str, __actual_str) \
+do \
+{ \
+ size_t __expected_length; \
+ size_t __actual_length; \
+ int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \
+ if (ret) { \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
+ (int)(__expected_length), (__expected_str), \
+ (int)__actual_length, (__actual_str)) ; \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_STREQ_(__expected_str, __actual_str, ...) \
+do \
+{ \
+ size_t __expected_length; \
+ size_t __actual_length; \
+ int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \
+ if (ret) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ ask= snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' != '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
+ (int)(__expected_length), (__expected_str), \
+ (int)(__actual_length), (__actual_str), \
+ (int)(ask), buffer); \
+ free(buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_STRNE(__expected_str, __actual_str) \
+do \
+{ \
+ size_t __expected_length; \
+ size_t __actual_length; \
+ int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \
+ if (ret == 0) { \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
+ (int)(__expected_length), (__expected_str), \
+ (int)__actual_length, (__actual_str)) ; \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_STRNE_(__expected_str, __actual_str, ...) \
+do \
+{ \
+ size_t __expected_length; \
+ size_t __actual_length; \
+ int ret= yatl_strcmp(__expected_str, __actual_str, &__expected_length, &__actual_length); \
+ if (ret == 0) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ ask= snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%.*s' == '%.*s' [ %.*s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, \
+ (int)(__expected_length), (__expected_str), \
+ (int)(__actual_length), (__actual_str), \
+ (int)(ask), buffer); \
+ free(buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_NEQ(__expected, __actual, ...) \
+do \
+{ \
+ if ((__expected) == (__actual)) { \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s'\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_NEQ_(__expected, __actual, ...) \
+do \
+{ \
+ if ((__expected) == (__actual)) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)malloc(sizeof(char) * ask); \
+ snprintf(buffer, ask, __VA_ARGS__); \
+ fprintf(stderr, "\n%s:%d: %s Assertion '%s' == '%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expected, #__actual, buffer); \
+ free(buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
+
+#define ASSERT_FALSE_(__expression, ...) \
+do \
+{ \
+ if ((__expression)) { \
+ size_t ask= snprintf(0, 0, __VA_ARGS__); \
+ ask++; \
+ char *buffer= (char*)alloca(sizeof(char) * ask); \
+ snprintf(buffer, ask, __VA_ARGS__); \
+ if (YATL_FULL) { \
+ throw libtest::__failure(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Assertion '!%s' [ %s ]", #__expression, buffer); \
+ } \
+ fprintf(stderr, "\n%s:%d: %s Assertion '!%s' [ %s ]\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, #__expression, buffer); \
+ exit(EXIT_FAILURE); \
+ } \
+} while (0)
-#serial 1
+#serial 2
- AC_DEFUN([YATL_MEMCACHED], [
- AC_REQUIRE([AX_ENABLE_LIBMEMCACHED])
+AC_DEFUN([YATL_MEMCACHED],
+ [AC_REQUIRE([AX_ENABLE_LIBMEMCACHED])
- 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])
- ])
- ])
+ 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"])
+ ])
return EXIT_SKIP;
case TEST_FAILURE:
- std::cerr << "frame->create()" << std::endl;
+ std::cerr << "Could not call frame->create()" << std::endl;
return EXIT_FAILURE;
}
}
{
}
-__failure::__failure(const char *file_arg, int line_arg, const char *func_arg, const std::string& mesg):
- __test_result(file_arg, line_arg, func_arg)
+__failure::__failure(const char *file_arg, int line_arg, const char *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);
+}
+
+__failure::__failure( const __failure& other ) :
+ __test_result(other),
+ _error_message_size(other._error_message_size)
{
- snprintf(_error_message, sizeof(_error_message), "%.*s", int(mesg.size()), mesg.c_str());
+ _error_message= (char*) malloc(_error_message_size);
+ if (_error_message)
+ {
+ memcpy(_error_message, other._error_message, _error_message_size);
+ }
+ else
+ {
+ _error_message_size= -1;
+ }
}
+__failure::~__failure() throw()
+{
+ if ((_error_message_size > 0) and _error_message)
+ {
+ free(_error_message);
+ _error_message= NULL;
+ }
+}
+
+
} // namespace libtest
#pragma once
#include <libtest/fatal.hpp>
+#include <libtest/result/base.hpp>
+#include <libtest/result/fail.hpp>
+#include <libtest/result/fatal.hpp>
+#include <libtest/result/skip.hpp>
+#include <libtest/result/success.hpp>
-namespace libtest {
-
-class __test_result : public std::exception
-{
-public:
- __test_result(const char *file, int line, const char *func);
-
- int line()
- {
- return _line;
- }
-
- const char* file()
- {
- return _file;
- }
-
- const char* func()
- {
- return _func;
- }
-
-private:
- int _line;
- const char* _file;
- const char* _func;
-};
-
-class __success : public __test_result
-{
-public:
- __success(const char *file, int line, const char *func);
-
- const char* what() const throw()
- {
- return "SUCCESS";
- }
-
-private:
-};
-
-class __skipped : public __test_result
-{
-public:
- __skipped(const char *file, int line, const char *func);
-
- const char* what() const throw()
- {
- return "SKIPPED";
- }
-
-private:
-};
-
-class __failure : public __test_result
-{
-public:
- __failure(const char *file, int line, const char *func, const std::string&);
-
- const char* what() const throw()
- {
- return _error_message;
- }
-
-private:
- char _error_message[BUFSIZ];
-};
+#define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM)
+#define SKIP throw libtest::__skipped(LIBYATL_DEFAULT_PARAM)
+#define FAIL(...) \
+do \
+{ \
+ throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
+} while (0)
-} // namespace libtest
+#define fatal_message(...) \
+do \
+{ \
+ throw libtest::fatal(LIBYATL_DEFAULT_PARAM, __VA_ARGS__); \
+} while (0)
-#define _SUCCESS throw libtest::__success(LIBYATL_DEFAULT_PARAM)
-#define SKIP throw libtest::__skipped(LIBYATL_DEFAULT_PARAM)
-#define FAIL(__mesg) throw libtest::__failure(LIBYATL_DEFAULT_PARAM, __mesg)
+#define fatal_assert(__assert) if((__assert)) {} else { throw libtest::fatal(LIBYATL_DEFAULT_PARAM, #__assert); }
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) 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.
+ *
+ */
+
+#pragma once
+
+namespace libtest {
+
+class __test_result : public std::exception
+{
+public:
+ __test_result(const char *file, int line, const char *func);
+
+ __test_result( const __test_result& other ) :
+ _line(other._line),
+ _file(other._file),
+ _func(other._func)
+ {
+ }
+
+ int line()
+ {
+ return _line;
+ }
+
+ const char* file()
+ {
+ return _file;
+ }
+
+ const char* func()
+ {
+ return _func;
+ }
+
+private:
+ int _line;
+ const char* _file;
+ const char* _func;
+};
+
+} // namespace libtest
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) 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.
+ *
+ */
+
+#pragma once
+
+namespace libtest {
+
+class __failure : public __test_result
+{
+public:
+ __failure(const char *file, int line, const char *func, ...);
+
+ __failure(const __failure& other);
+
+ ~__failure() throw();
+
+ const char* what() const throw()
+ {
+ return _error_message;
+ }
+
+private:
+ char* _error_message;
+ int _error_message_size;
+};
+
+} // namespace libtest
+
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) 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.
+ *
+ */
+
+#pragma once
+
+namespace libtest {
+
+class fatal : public __test_result
+{
+public:
+ fatal(const char *file, int line, const char *func, ...);
+
+ ~fatal() throw()
+ {
+ }
+
+ const char* what() const throw()
+ {
+ return &_error_message[0];
+ }
+
+ // The following are just for unittesting the exception class
+ static bool is_disabled();
+ static void disable();
+ static void enable();
+ static uint32_t disabled_counter();
+ static void increment_disabled_counter();
+
+private:
+ vchar_t _error_message;
+};
+
+} // namespace libtest
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) 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.
+ *
+ */
+
+#pragma once
+
+namespace libtest {
+
+class __skipped : public __test_result
+{
+public:
+ __skipped(const char *file, int line, const char *func);
+
+ const char* what() const throw()
+ {
+ return "SKIPPED";
+ }
+
+private:
+};
+
+} // namespace libtest
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) 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.
+ *
+ */
+
+#pragma once
+
+namespace libtest {
+
+class __success : public __test_result
+{
+public:
+ __success(const char *file, int line, const char *func);
+
+ const char* what() const throw()
+ {
+ return "SUCCESS";
+ }
+
+private:
+};
+
+} // namespace libtest
#endif
}
- // This needs more work.
-#if 0
- if (gdb_is_caller())
+ if (getenv("YATL_GDB_SERVER"))
{
- _app.use_gdb();
+ _app.use_gdb(true);
}
-#endif
if (port() == LIBTEST_FAIL_PORT)
{
if (getenv("YATL_PTRCHECK_SERVER"))
{
- _app.use_ptrcheck();
+ _app.use_ptrcheck(true);
}
else if (getenv("YATL_VALGRIND_SERVER"))
{
- _app.use_valgrind();
+ _app.use_valgrind(true);
}
out_of_ban_killed(false);
uint32_t waited;
uint32_t retry;
- for (waited= 0, retry= 7; ; retry++, waited+= this_wait)
+ for (waited= 0, retry= 1; ; retry++, waited+= this_wait)
{
if (_app.check() == false)
{
break;
}
- Error << "ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error();
-
this_wait= retry * retry / 3 + 1;
libtest::dream(this_wait, 0);
}
if (pinged == false)
{
+ Error << "ping(" << _app.pid() << ") wait: " << this_wait << " " << hostname() << ":" << port() << " run:" << _running << " " << error();
+
// If we happen to have a pid file, lets try to kill it
if ((pid_file().empty() == false) and (access(pid_file().c_str(), R_OK) == 0))
{
{
if (GEARMAND_BINARY)
{
- if (HAVE_LIBGEARMAN)
- {
- server= build_gearmand("localhost", try_port);
- }
+ server= build_gearmand("localhost", try_port);
}
}
else if (server_type.compare("hostile-gearmand") == 0)
{
if (GEARMAND_BINARY)
{
- if (HAVE_LIBGEARMAN)
- {
- server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand");
- }
+ server= build_gearmand("localhost", try_port, "gearmand/hostile_gearmand");
}
}
else if (server_type.compare("drizzled") == 0)
{
if (HAVE_MEMCACHED_BINARY)
{
- if (HAVE_LIBMEMCACHED)
- {
- server= build_memcached("localhost", try_port);
- }
+ server= build_memcached("localhost", try_port);
}
}
{
if (MEMCACHED_BINARY)
{
- if (HAVE_LIBMEMCACHED)
- {
server= build_memcached_socket("localhost", try_port);
- }
- else
- {
- Error << "Libmemcached was not found";
- }
}
else
{
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
+#include <libtest/lite.h>
+
/**
A structure describing the test case.
*/
} \
} while (0)
-#define test_assert(A, B) \
-do \
-{ \
- if ((A)) { \
- fprintf(stderr, "\n%s:%d: Assertion failed %s, with message %s, in %s", __FILE__, __LINE__, (B), #A, __func__ );\
- fprintf(stderr, "\n"); \
- libtest::create_core(); \
- assert((A)); \
- } \
-} while (0)
-
#define test_truth(A) \
do \
{ \
Structures for generic tests.
*/
+#pragma once
+
+#ifndef __PRETTY_FUNCTION__
+#define __PRETTY_FUNCTION__ __func__
+#endif
+
+#define YATL_STRINGIFY(x) #x
+#define YATL_TOSTRING(x) YATL_STRINGIFY(x)
+#define YATL_AT __FILE__ ":" YATL_TOSTRING(__LINE__)
+#define YATL_AT_PARAM __func__, AT
+#define YATL_UNIQUE __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique"
+#define YATL_UNIQUE_FUNC_NAME __FILE__ ":" YATL_TOSTRING(__LINE__) "_unique_func"
+
+#define LIBYATL_DEFAULT_PARAM __FILE__, __LINE__, __PRETTY_FUNCTION__
+
#include <cstdio>
#include <cstdlib>
#include <arpa/inet.h>
#include "libtest/yatlcon.h"
-#include <libtest/test.hpp>
+#include <libtest/yatl.h>
#if defined(HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H) && HAVE_LIBMEMCACHED_1_0_TYPES_RETURN_H
# include <libmemcached-1.0/types/return.h>
static test_return_t test_throw_fail_TEST(void *)
{
- std::string error_messsage("test message!");
try {
- FAIL(error_messsage);
+#if 0
+ FAIL("test message!");
+#endif
+ throw libtest::__failure(LIBYATL_DEFAULT_PARAM, "test message!");
}
- catch (libtest::__failure e)
+ catch (const libtest::__failure& e)
{
std::string compare_message("test message!");
test_zero(compare_message.compare(e.what()));
return TEST_FAILURE;
}
+#pragma GCC diagnostic ignored "-Wstack-protector"
+
+static test_return_t ASSERT_FALSE__TEST(void *)
+{
+ try {
+ ASSERT_FALSE_(true, __func__);
+ }
+ catch (libtest::__failure e)
+ {
+ std::string compare_message(__func__);
+ ASSERT_EQ(compare_message.compare(e.what()), -32);
+ return TEST_SUCCESS;
+ }
+ catch (...)
+ {
+ return TEST_FAILURE;
+ }
+
+ return TEST_FAILURE;
+}
+
+static test_return_t ASSERT_FALSE_TEST(void *)
+{
+ try {
+ FAIL(__func__);
+ }
+ catch (libtest::__failure e)
+ {
+ std::string compare_message(__func__);
+ ASSERT_EQ(0, compare_message.compare(e.what()));
+ return TEST_SUCCESS;
+ }
+ catch (...)
+ {
+ return TEST_FAILURE;
+ }
+
+ return TEST_FAILURE;
+}
static test_return_t test_failure_test(void *)
{
test_skip(0, access("/usr/bin/true", X_OK ));
Application true_app("/usr/bin/true");
- true_app.use_gdb();
+ true_app.use_gdb(true);
test_compare(Application::SUCCESS, true_app.run());
test_compare(Application::SUCCESS, true_app.join());
test_skip(0, access("/usr/bin/true", X_OK ));
Application true_app("/usr/bin/true");
- true_app.use_gdb();
+ true_app.use_gdb(true);
const char *args[]= { "--fubar", 0 };
test_compare(Application::SUCCESS, true_app.run(args));
test_skip(0, access("libtest/wait", X_OK ));
libtest::Application wait_app("libtest/wait", true);
- wait_app.use_gdb();
+ wait_app.use_gdb(true);
const char *args[]= { "/etc/services", 0 };
test_compare(Application::SUCCESS, wait_app.run(args));
test_skip(0, access("libtest/wait", X_OK ));
libtest::Application wait_app("libtest/wait", true);
- wait_app.use_gdb();
+ wait_app.use_gdb(true);
const char *args[]= { "/etc/services", 0 };
test_compare(Application::SUCCESS, wait_app.run(args));
#endif
libtest::Application abort_app("libtest/abort", true);
- abort_app.use_gdb();
+ abort_app.use_gdb(true);
test_compare(Application::SUCCESS, abort_app.run());
test_compare(Application::SUCCESS, abort_app.join());
#if defined(HAVE_GEARMAND_BINARY) && HAVE_GEARMAND_BINARY
if (GEARMAND_BINARY)
{
- test_zero(access(GEARMAND_BINARY, X_OK ));
+ if (strcmp(GEARMAND_BINARY, "./gearmand/gearmand"))
+ {
+ test_zero(access(GEARMAND_BINARY, X_OK ));
+ }
}
else
{
return TEST_SUCCESS;
}
-static test_return_t check_for_libmemcached(void* object)
+static test_return_t check_for_memcached(void* object)
{
- test_skip(true, HAVE_LIBMEMCACHED);
test_skip(true, has_memcached());
server_startup_st *servers= (server_startup_st*)object;
{"SUCCESS", false, test_throw_success_TEST },
{"SKIP", false, test_throw_skip_TEST },
{"FAIL", false, test_throw_fail_TEST },
+ {"ASSERT_FALSE_", false, ASSERT_FALSE__TEST },
+ {"ASSERT_FALSE", false, ASSERT_FALSE_TEST },
{0, 0, 0}
};
{"directories", 0, 0, directories_tests},
{"comparison", 0, 0, comparison_tests},
{"gearmand", check_for_gearman, clear_servers, gearmand_tests},
- {"memcached", check_for_libmemcached, clear_servers, memcached_TESTS },
+ {"memcached", check_for_memcached, clear_servers, memcached_TESTS },
{"drizzled", check_for_drizzle, clear_servers, drizzled_tests},
{"cmdline", 0, 0, cmdline_tests},
{"application", 0, 0, application_tests},
*
* Data Differential YATL (i.e. libtest) library
*
- * Copyright (C) 2011 Data Differential, http://datadifferential.com/
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
--- /dev/null
+/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ *
+ * Data Differential YATL (i.e. libtest) 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.
+ *
+ */
+
+#pragma once
+
+#ifndef YATL_FULL
+# define YATL_FULL 1
+#endif
+
+#include <libtest/test.hpp>