Blame gnulib/tests/macros.h

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