Blame gnulib-tests/macros.h

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