|
Packit |
709fb3 |
/* Common macros used by gnulib tests.
|
|
Packit |
709fb3 |
Copyright (C) 2006-2017 Free Software Foundation, Inc.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
This program is free software: you can redistribute it and/or modify
|
|
Packit |
709fb3 |
it under the terms of the GNU General Public License as published by
|
|
Packit |
709fb3 |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit |
709fb3 |
(at your option) any later version.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
This program is distributed in the hope that it will be useful,
|
|
Packit |
709fb3 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
709fb3 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
709fb3 |
GNU General Public License for more details.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
You should have received a copy of the GNU General Public License
|
|
Packit |
709fb3 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* This file contains macros that are used by many gnulib tests.
|
|
Packit |
709fb3 |
Put here only frequently used macros, say, used by 10 tests or more. */
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
#include <stdio.h>
|
|
Packit |
709fb3 |
#include <stdlib.h>
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
#ifndef FALLTHROUGH
|
|
Packit |
709fb3 |
# if __GNUC__ < 7
|
|
Packit |
709fb3 |
# define FALLTHROUGH ((void) 0)
|
|
Packit |
709fb3 |
# else
|
|
Packit |
709fb3 |
# define FALLTHROUGH __attribute__ ((__fallthrough__))
|
|
Packit |
709fb3 |
# endif
|
|
Packit |
709fb3 |
#endif
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* Define ASSERT_STREAM before including this file if ASSERT must
|
|
Packit |
709fb3 |
target a stream other than stderr. */
|
|
Packit |
709fb3 |
#ifndef ASSERT_STREAM
|
|
Packit |
709fb3 |
# define ASSERT_STREAM stderr
|
|
Packit |
709fb3 |
#endif
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* ASSERT (condition);
|
|
Packit |
709fb3 |
verifies that the specified condition is fulfilled. If not, a message
|
|
Packit |
709fb3 |
is printed to ASSERT_STREAM if defined (defaulting to stderr if
|
|
Packit |
709fb3 |
undefined) and the program is terminated with an error code.
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
This macro has the following properties:
|
|
Packit |
709fb3 |
- The programmer specifies the expected condition, not the failure
|
|
Packit |
709fb3 |
condition. This simplifies thinking.
|
|
Packit |
709fb3 |
- The condition is tested always, regardless of compilation flags.
|
|
Packit |
709fb3 |
(Unlike the macro from <assert.h>.)
|
|
Packit |
709fb3 |
- On Unix platforms, the tester can debug the test program with a
|
|
Packit |
709fb3 |
debugger (provided core dumps are enabled: "ulimit -c unlimited").
|
|
Packit |
709fb3 |
- For the sake of platforms where no debugger is available (such as
|
|
Packit |
709fb3 |
some mingw systems), an error message is printed on the error
|
|
Packit |
709fb3 |
stream that includes the source location of the ASSERT invocation.
|
|
Packit |
709fb3 |
*/
|
|
Packit |
709fb3 |
#define ASSERT(expr) \
|
|
Packit |
709fb3 |
do \
|
|
Packit |
709fb3 |
{ \
|
|
Packit |
709fb3 |
if (!(expr)) \
|
|
Packit |
709fb3 |
{ \
|
|
Packit |
709fb3 |
fprintf (ASSERT_STREAM, "%s:%d: assertion '%s' failed\n", \
|
|
Packit |
709fb3 |
__FILE__, __LINE__, #expr); \
|
|
Packit |
709fb3 |
fflush (ASSERT_STREAM); \
|
|
Packit |
709fb3 |
abort (); \
|
|
Packit |
709fb3 |
} \
|
|
Packit |
709fb3 |
} \
|
|
Packit |
709fb3 |
while (0)
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* SIZEOF (array)
|
|
Packit |
709fb3 |
returns the number of elements of an array. It works for arrays that are
|
|
Packit |
709fb3 |
declared outside functions and for local variables of array type. It does
|
|
Packit |
709fb3 |
*not* work for function parameters of array type, because they are actually
|
|
Packit |
709fb3 |
parameters of pointer type. */
|
|
Packit |
709fb3 |
#define SIZEOF(array) (sizeof (array) / sizeof (array[0]))
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* STREQ (str1, str2)
|
|
Packit |
709fb3 |
Return true if two strings compare equal. */
|
|
Packit |
709fb3 |
#define STREQ(a, b) (strcmp (a, b) == 0)
|
|
Packit |
709fb3 |
|
|
Packit |
709fb3 |
/* Some numbers in the interval [0,1). */
|
|
Packit |
709fb3 |
extern const float randomf[1000];
|
|
Packit |
709fb3 |
extern const double randomd[1000];
|
|
Packit |
709fb3 |
extern const long double randoml[1000];
|