X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Ftest.h;h=656be1698967f36f92c0d50b6aefbb5b99e4cee0;hb=088eed04d829b8cf6591201564118c356d3cf935;hp=cc0fd78aaaf21c8e5614c0776fdf4631ea355d76;hpb=49fc1e5ea4ea006f4a2ac71428833760f6fac030;p=m6w6%2Flibmemcached diff --git a/libtest/test.h b/libtest/test.h index cc0fd78a..656be169 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -1,19 +1,49 @@ -/* uTest - * Copyright (C) 2006-2009 Brian Aker - * All rights reserved. +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * Gearmand client and server library. + * + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * Copyright (C) 2006-2010 Brian Aker + * 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. * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. */ +#pragma once + +#include + /* Structures for generic tests. */ -#ifdef __cplusplus -extern "C" { -#endif - #include #include #include @@ -39,9 +69,6 @@ typedef test_return_t (*test_callback_fn)(void *); typedef test_return_t (*test_callback_runner_fn)(test_callback_fn, void *); typedef test_return_t (*test_callback_error_fn)(test_return_t, void *); -/* Help function for use with gettimeofday() */ -long int timedif(struct timeval a, struct timeval b); - /** A structure describing the test case. */ @@ -139,14 +166,25 @@ typedef struct { uint32_t total; } world_stats_st; +#ifdef __cplusplus +extern "C" { +#endif + +/* Help function for use with gettimeofday() */ +LIBTEST_API +long int timedif(struct timeval a, struct timeval b); + /* How we make all of this work :) */ +LIBTEST_API void get_world(world_st *world); +LIBTEST_INTERNAL_API void create_core(void); /** @note Friendly print function for errors. */ +LIBTEST_API const char *test_strerror(test_return_t code); #define test_fail(A) \ @@ -179,6 +217,17 @@ do \ } \ } while (0) +#define test_compare(A,B) \ +do \ +{ \ + if ((A) != (B)) \ + { \ + fprintf(stderr, "\n%s:%d: Expected %lu == %lu\n", __FILE__, __LINE__, (unsigned long)(A), (unsigned long)(B)); \ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + #define test_false(A) \ do \ { \ @@ -189,17 +238,54 @@ do \ } \ } while (0) +#define test_false_with(A,B) \ +do \ +{ \ + if ((A)) { \ + fprintf(stderr, "\nAssertion failed at %s:%d: %s with %s\n", __FILE__, __LINE__, #A, (B));\ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + #define test_strcmp(A,B) \ do \ { \ if (strcmp((A), (B))) \ { \ - fprintf(stderr, "\n%s:%d: %s -> %s\n", __FILE__, __LINE__, (A), (B)); \ + fprintf(stderr, "\n%s:%d: `%s` -> `%s`\n", __FILE__, __LINE__, (A), (B)); \ create_core(); \ return TEST_FAILURE; \ } \ } while (0) +#define test_memcmp(A,B,C) \ +do \ +{ \ + if (memcmp((A), (B), (C))) \ + { \ + fprintf(stderr, "\n%s:%d: %.*s -> %.*s\n", __FILE__, __LINE__, (int)(C), (char *)(A), (int)(C), (char *)(B)); \ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) + +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) +#define AT __FILE__ ":" TOSTRING(__LINE__) + +#ifdef __cplusplus +#define STRING_WITH_LEN(X) (X), (static_cast((sizeof(X) - 1))) +#else +#define STRING_WITH_LEN(X) (X), ((size_t)((sizeof(X) - 1))) +#endif + +#ifdef __cplusplus +#define STRING_PARAM_WITH_LEN(X) X, static_cast(sizeof(X) - 1) +#else +#define STRING_PARAM_WITH_LEN(X) X, (size_t)((sizeof(X) - 1)) +#endif + #ifdef __cplusplus } #endif