Blame gl/tests/macros.h

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