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