X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=libtest%2Ftest.h;h=d195dd5630462f28c5785e60af61a5e129600178;hb=58c279d58e2a44562f729e93e301dfedf42f530b;hp=9939886f6f294f4735a32a8d8ef493f9772df8cf;hpb=d8dedbd561c7cb57daf4192fe57ce5e205bcadd7;p=m6w6%2Flibmemcached diff --git a/libtest/test.h b/libtest/test.h index 9939886f..d195dd56 100644 --- a/libtest/test.h +++ b/libtest/test.h @@ -1,12 +1,34 @@ -/* - * uTest Copyright (C) 2011 Data Differential, http://datadifferential.com/ +/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab: + * + * libtest * - * Use and distribution licensed under the BSD license. See - * the COPYING file in the parent directory for full text. + * Copyright (C) 2011 Data Differential, http://datadifferential.com/ + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + #pragma once +#ifndef __INTEL_COMPILER +#pragma GCC diagnostic ignored "-Wold-style-cast" +#endif + +#include +#include + /** A structure describing the test case. */ @@ -16,11 +38,6 @@ struct test_st { test_callback_fn *test_fn; }; -#define TEST_STRINGIFY(x) #x -#define TEST_TOSTRING(x) TEST_STRINGIFY(x) -#define TEST_AT __FILE__ ":" TEST_TOSTRING(__LINE__) - - #define test_assert_errno(A) \ do \ { \ @@ -64,11 +81,11 @@ do \ } \ } while (0) -#define test_true_got(A,B) \ +#define test_true_got(__expected, __hint) \ do \ { \ - if (! (A)) { \ - fprintf(stderr, "\n%s:%d: Assertion \"%s\" failed, received \"%s\"\n", __FILE__, __LINE__, #A, (B));\ + if (not libtest::_compare_true_hint(__FILE__, __LINE__, __func__, ((__expected)), #__expected, ((__hint)))) \ + { \ create_core(); \ return TEST_FAILURE; \ } \ @@ -114,24 +131,31 @@ do \ } \ } while (0) +#define test_compare(__expected, __actual) \ +do \ +{ \ + if (not libtest::_compare(__FILE__, __LINE__, __func__, ((__expected)), ((__actual)))) \ + { \ + create_core(); \ + return TEST_FAILURE; \ + } \ +} while (0) -#define test_compare(A,B) \ +#define test_zero(__actual) \ do \ { \ - if ((A) != (B)) \ + if (not libtest::_compare_zero(__FILE__, __LINE__, __func__, ((__actual)))) \ { \ - fprintf(stderr, "\n%s:%d: Expected %s, got %lu\n", __FILE__, __LINE__, #A, (unsigned long)(B)); \ create_core(); \ return TEST_FAILURE; \ } \ } while (0) -#define test_compare_got(A,B,C) \ +#define test_compare_got(__expected, __actual, __hint) \ do \ { \ - if ((A) != (B)) \ + if (not libtest::_compare_hint(__FILE__, __LINE__, __func__, (__expected), (__actual), (__hint))) \ { \ - fprintf(stderr, "\n%s:%d: Expected %s, got %s\n", __FILE__, __LINE__, #A, (C)); \ create_core(); \ return TEST_FAILURE; \ } \