Import Upstream version 0.8.2
[platform/upstream/mpc.git] / tests / mpc-tests.h
index d1ce586..dd9a275 100644 (file)
@@ -1,73 +1,37 @@
-/* mpc-tests.h -- Tests helper functions.
+/* Tests helper functions.
 
-Copyright (C) 2008, 2009, 2010, 2011, 2012 INRIA
+Copyright (C) 2008, 2009 Philippe Th\'eveny, Andreas Enge, Paul Zimmermann
 
-This file is part of GNU MPC.
+This file is part of the MPC Library.
 
-GNU MPC is free software; you can redistribute it and/or modify it under
-the terms of the GNU Lesser General Public License as published by the
-Free Software Foundation; either version 3 of the License, or (at your
+The MPC Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or (at your
 option) any later version.
 
-GNU MPC is distributed in the hope that it will be useful, but WITHOUT ANY
-WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
-more details.
+The MPC Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+License for more details.
 
 You should have received a copy of the GNU Lesser General Public License
-along with this program. If not, see http://www.gnu.org/licenses/ .
-*/
+along with the MPC Library; see the file COPYING.LIB.  If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
 
-#ifndef __MPC_TESTS_H
-#define __MPC_TESTS_H
+#ifndef MPC_TESTS_H
+#define MPC_TESTS_H
 
-#include "config.h"
 #include <stdio.h>
 #include <ctype.h>
-#include <stdlib.h>
-#include "mpc.h"
-
-/* pieces copied from mpc-impl.h */
-#define MPC_PREC_RE(x) (mpfr_get_prec(mpc_realref(x)))
-#define MPC_PREC_IM(x) (mpfr_get_prec(mpc_imagref(x)))
-#define MPC_MAX_PREC(x) MPC_MAX(MPC_PREC_RE(x), MPC_PREC_IM(x))
-#define MPC_MAX(h,i) ((h) > (i) ? (h) : (i))
-
-#define MPC_ASSERT(expr)                                        \
-  do {                                                          \
-    if (!(expr))                                                \
-      {                                                         \
-        fprintf (stderr, "%s:%d: MPC assertion failed: %s\n",   \
-                 __FILE__, __LINE__, #expr);                    \
-        abort();                                                \
-      }                                                         \
-  } while (0)
-
-#if defined (__cplusplus)
-extern "C" {
-#endif
-__MPC_DECLSPEC int  mpc_mul_naive (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
-__MPC_DECLSPEC int  mpc_mul_karatsuba (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
-__MPC_DECLSPEC int  mpc_fma_naive (mpc_ptr, mpc_srcptr, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
-#if defined (__cplusplus)
-}
-#endif
-/* end pieces copied from mpc-impl.h */
-
-#define MPC_OUT(x)                                              \
-do {                                                            \
-  printf (#x "[%lu,%lu]=", (unsigned long int) MPC_PREC_RE (x), \
-      (unsigned long int) MPC_PREC_IM (x));                     \
-  mpc_out_str (stdout, 2, 0, x, MPC_RNDNN);                     \
-  printf ("\n");                                                \
-} while (0)
-
-#define MPFR_OUT(x)                                             \
-do {                                                            \
-  printf (#x "[%lu]=", (unsigned long int) mpfr_get_prec (x));  \
-  mpfr_out_str (stdout, 2, 0, x, GMP_RNDN);                     \
-  printf ("\n");                                                \
-} while (0)
+
+#include "mpc-impl.h"
+
+/** OUTPUT HELPER MACROS */
+#define MPFR_OUT(X) \
+  printf (#X" [%ld]=", MPFR_PREC (X));\
+  mpfr_out_str (stdout, 2, 0, (X), GMP_RNDN);\
+  printf ("\n");
 
 
 #define MPC_INEX_STR(inex)                      \
@@ -81,16 +45,6 @@ do {                                                            \
     : (inex) == 9 ? "(+1, -1)"                  \
     : (inex) == 10 ? "(-1, -1)" : "unknown"
 
-#define TEST_FAILED(func,op,got,expected,rnd)                  \
-  do {                                                         \
-    printf ("%s(op) failed [rnd=%d]\n with", func, rnd);       \
-    MPC_OUT (op);                                              \
-    printf ("     ");                                          \
-    MPC_OUT (got);                                             \
-    MPC_OUT (expected);                                                \
-    exit (1);                                                  \
-  } while (0)
-
 #define QUOTE(X) NAME(X)
 #define NAME(X) #X
 
@@ -101,10 +55,13 @@ do {                                                            \
    gmp_randstate_t rands) in your tests
    - add test_end at the end the test function */
 extern gmp_randstate_t  rands;
+extern char             rands_initialized;
 
-extern void test_start (void);
-extern void test_end (void);
-extern void test_default_random (mpc_ptr, mp_exp_t, mp_exp_t, unsigned int, unsigned int);
+void test_start (void);
+void test_end (void);
+
+void test_default_random (mpc_ptr, mp_exp_t, mp_exp_t, unsigned int, unsigned int);
+unsigned long urandomm_ui (unsigned long);
 
 
 /** COMPARISON FUNCTIONS **/
@@ -124,16 +81,14 @@ typedef struct
    returns 0 in other cases.
    Unlike mpfr_cmp, same_mpfr_value(got, ref, x) return 1 when got and
    ref are both NaNs. */
-extern int same_mpfr_value (mpfr_ptr got, mpfr_ptr ref, int known_sign);
-extern int same_mpc_value (mpc_ptr got, mpc_ptr ref, known_signs_t known_signs);
+int same_mpfr_value (mpfr_ptr got, mpfr_ptr ref, int known_sign);
+int same_mpc_value (mpc_ptr got, mpc_ptr ref, known_signs_t known_signs);
 
 
 /** GENERIC TESTS **/
 
 typedef int (*CC_func_ptr) (mpc_t, mpc_srcptr, mpc_rnd_t);
-typedef int (*C_CC_func_ptr) (mpc_t, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
-typedef int (*CCCC_func_ptr) (mpc_t, mpc_srcptr, mpc_srcptr, mpc_srcptr,
-                             mpc_rnd_t);
+typedef int (*CCC_func_ptr) (mpc_t, mpc_srcptr, mpc_srcptr, mpc_rnd_t);
 typedef int (*CCU_func_ptr) (mpc_t, mpc_srcptr, unsigned long, mpc_rnd_t);
 typedef int (*CCS_func_ptr) (mpc_t, mpc_srcptr, long, mpc_rnd_t);
 typedef int (*CCI_func_ptr) (mpc_t, mpc_srcptr, int, mpc_rnd_t);
@@ -143,38 +98,35 @@ typedef int (*CUC_func_ptr) (mpc_t, unsigned long, mpc_srcptr, mpc_rnd_t);
 typedef int (*CUUC_func_ptr) (mpc_t, unsigned long, unsigned long, mpc_srcptr,
                               mpc_rnd_t);
 typedef int (*FC_func_ptr) (mpfr_t, mpc_srcptr, mpfr_rnd_t);
-typedef int (*CC_C_func_ptr) (mpc_t, mpc_t, mpc_srcptr, mpc_rnd_t, mpc_rnd_t);
-
-typedef union {
-   FC_func_ptr FC;     /* output: mpfr_t, input: mpc_t */
-   CC_func_ptr CC;     /* output: mpc_t, input: mpc_t */
-   C_CC_func_ptr C_CC; /* output: mpc_t, inputs: (mpc_t, mpc_t) */
-   CCCC_func_ptr CCCC; /* output: mpc_t, inputs: (mpc_t, mpc_t, mpc_t) */
-   CCU_func_ptr CCU;   /* output: mpc_t, inputs: (mpc_t, unsigned long) */
-   CCS_func_ptr CCS;   /* output: mpc_t, inputs: (mpc_t, long) */
-   CCI_func_ptr CCI;   /* output: mpc_t, inputs: (mpc_t, int) */
-   CCF_func_ptr CCF;   /* output: mpc_t, inputs: (mpc_t, mpfr_t) */
-   CFC_func_ptr CFC;   /* output: mpc_t, inputs: (mpfr_t, mpc_t) */
-   CUC_func_ptr CUC;   /* output: mpc_t, inputs: (unsigned long, mpc_t) */
-   CUUC_func_ptr CUUC; /* output: mpc_t, inputs: (ulong, ulong, mpc_t) */
-   CC_C_func_ptr CC_C;   /* outputs: (mpc_t, mpc_t), input: mpc_t */
+
+typedef union
+{
+  FC_func_ptr FC;     /* output: mpfr_t, input: mpc_t */
+  CC_func_ptr CC;     /* output: mpc_t, input: mpc_t */
+  CCC_func_ptr CCC;   /* output: mpc_t, inputs: (mpc_t, mpc_t) */
+  CCU_func_ptr CCU;   /* output: mpc_t, inputs: (mpc_t, unsigned long) */
+  CCS_func_ptr CCS;   /* output: mpc_t, inputs: (mpc_t, long) */
+  CCI_func_ptr CCI;   /* output: mpc_t, inputs: (mpc_t, int) */
+  CCF_func_ptr CCF;   /* output: mpc_t, inputs: (mpc_t, mpfr_t) */
+  CFC_func_ptr CFC;   /* output: mpc_t, inputs: (mpfr_t, mpc_t) */
+  CUC_func_ptr CUC;   /* output: mpc_t, inputs: (unsigned long, mpc_t) */
+  CUUC_func_ptr CUUC; /* output: mpc_t, inputs: (ulong, ulong, mpc_t) */
 } func_ptr;
 
 /* the rounding mode is implicit */
-typedef enum {
-   FC,   /* output: mpfr_t, input: mpc_t */
-   CC,   /* output: mpc_t, input: mpc_t */
-   C_CC, /* output: mpc_t, inputs: (mpc_t, mpc_t) */
-   CCCC, /* output: mpc_t, inputs: (mpc_t, mpc_t, mpc_t) */
-   CCU,  /* output: mpc_t, inputs: (mpc_t, unsigned long) */
-   CCS,  /* output: mpc_t, inputs: (mpc_t, long) */
-   CCI,  /* output: mpc_t, inputs: (mpc_t, int) */
-   CCF,  /* output: mpc_t, inputs: (mpc_t, mpfr_t) */
-   CFC,  /* output: mpc_t, inputs: (mpfr_t, mpc_t) */
-   CUC,  /* output: mpc_t, inputs: (unsigned long, mpc_t) */
-   CUUC, /* output: mpc_t, inputs: (ulong, ulong, mpc_t) */
-   CC_C  /* outputs: (mpc_t, mpc_t), input: mpc_t */
-} func_type;
+typedef enum
+  {
+    FC,   /* output: mpfr_t, input: mpc_t */
+    CC,   /* output: mpc_t, input: mpc_t */
+    CCC,  /* output: mpc_t, inputs: (mpc_t, mpc_t) */
+    CCU,  /* output: mpc_t, inputs: (mpc_t, unsigned long) */
+    CCS,  /* output: mpc_t, inputs: (mpc_t, long) */
+    CCI,  /* output: mpc_t, inputs: (mpc_t, int) */
+    CCF,  /* output: mpc_t, inputs: (mpc_t, mpfr_t) */
+    CFC,  /* output: mpc_t, inputs: (mpfr_t, mpc_t) */
+    CUC,  /* output: mpc_t, inputs: (unsigned long, mpc_t) */
+    CUUC  /* output: mpc_t, inputs: (ulong, ulong, mpc_t) */
+  } func_type;
 
 /* properties */
 #define FUNC_PROP_NONE     0
@@ -182,10 +134,10 @@ typedef enum {
 
 typedef struct
 {
-  func_ptr     pointer;
-  func_type    type;
-  const char * name;
-  int          properties;
+  func_ptr  pointer;
+  func_type type;
+  char *    name;
+  int       properties;
 } mpc_function;
 
 #define DECL_FUNC(_ftype, _fvar, _func)         \
@@ -211,25 +163,27 @@ void tgeneric (mpc_function, mpfr_prec_t, mpfr_prec_t, mpfr_prec_t, mp_exp_t);
 /** READ FILE WITH TEST DATA SET **/
 /* data_check (function, "data_file_name") checks function results against
    precomputed data in a file.*/
-extern void data_check (mpc_function, const char *);
+void data_check (mpc_function, const char *);
 
-extern FILE * open_data_file (const char *file_name);
-extern void close_data_file (FILE *fp);
+FILE * open_data_file (const char *file_name);
+void close_data_file (FILE *fp);
 
 /* helper file reading functions */
-extern void skip_whitespace_comments (FILE *fp);
-extern void read_ternary (FILE *fp, int* ternary);
-extern void read_mpfr_rounding_mode (FILE *fp, mpfr_rnd_t* rnd);
-extern void read_mpc_rounding_mode (FILE *fp, mpc_rnd_t* rnd);
-extern mpfr_prec_t read_mpfr_prec (FILE *fp);
-extern void read_int (FILE *fp, int *n, const char *name);
-extern size_t read_string (FILE *fp, char **buffer_ptr, size_t buffer_length, const char *name);
-extern void read_mpfr (FILE *fp, mpfr_ptr x, int *known_sign);
-extern void read_mpc (FILE *fp, mpc_ptr z, known_signs_t *ks);
+void skip_whitespace_comments (FILE *fp);
+void read_ternary (FILE *fp, int* ternary);
+void read_mpfr_rounding_mode (FILE *fp, mpfr_rnd_t* rnd);
+void read_mpc_rounding_mode (FILE *fp, mpc_rnd_t* rnd);
+mpfr_prec_t read_mpfr_prec (FILE *fp);
+void read_int (FILE *fp, int *n, const char *name);
+size_t read_string (FILE *fp, char **buffer_ptr, size_t buffer_length, const char *name);
+void read_mpfr (FILE *fp, mpfr_ptr x, int *known_sign);
+void read_mpc (FILE *fp, mpc_ptr z, known_signs_t *ks);
+void tests_memory_start (void);
+void tests_memory_end (void);
 
 #define TERNARY_NOT_CHECKED 255
    /* special value to indicate that the ternary value is not checked */
 #define TERNARY_ERROR 254
    /* special value to indicate that an error occurred in an mpc function */
 
-#endif /* __MPC_TESTS_H */
+#endif /* MPC_TESTS_H */