Blame gnulib-tests/macros.h

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