ca7bae06b0243e5fca62e86fdf9c2dcf1b1779ad
[platform/upstream/diffutils.git] / gnulib-tests / macros.h
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Common macros used by gnulib tests.
4    Copyright (C) 2006-2011 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19
20 /* This file contains macros that are used by many gnulib tests.
21    Put here only frequently used macros, say, used by 10 tests or more.  */
22
23 #include <stdio.h>
24 #include <stdlib.h>
25
26 /* Define ASSERT_STREAM before including this file if ASSERT must
27    target a stream other than stderr.  */
28 #ifndef ASSERT_STREAM
29 # define ASSERT_STREAM stderr
30 #endif
31
32 /* ASSERT (condition);
33    verifies that the specified condition is fulfilled.  If not, a message
34    is printed to ASSERT_STREAM if defined (defaulting to stderr if
35    undefined) and the program is terminated with an error code.
36
37    This macro has the following properties:
38      - The programmer specifies the expected condition, not the failure
39        condition.  This simplifies thinking.
40      - The condition is tested always, regardless of compilation flags.
41        (Unlike the macro from <assert.h>.)
42      - On Unix platforms, the tester can debug the test program with a
43        debugger (provided core dumps are enabled: "ulimit -c unlimited").
44      - For the sake of platforms where no debugger is available (such as
45        some mingw systems), an error message is printed on the error
46        stream that includes the source location of the ASSERT invocation.
47  */
48 #define ASSERT(expr) \
49   do                                                                         \
50     {                                                                        \
51       if (!(expr))                                                           \
52         {                                                                    \
53           fprintf (ASSERT_STREAM, "%s:%d: assertion failed\n",               \
54                    __FILE__, __LINE__);                                      \
55           fflush (ASSERT_STREAM);                                            \
56           abort ();                                                          \
57         }                                                                    \
58     }                                                                        \
59   while (0)
60
61 /* SIZEOF (array)
62    returns the number of elements of an array.  It works for arrays that are
63    declared outside functions and for local variables of array type.  It does
64    *not* work for function parameters of array type, because they are actually
65    parameters of pointer type.  */
66 #define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
67
68 /* STREQ (str1, str2)
69    Return true if two strings compare equal.  */
70 #define STREQ(a, b) (strcmp (a, b) == 0)