xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/tvalist.c (revision 8ecbf5f02b752fcb7debe1a8fab1dc82602bc760)
1 /* Test file for multiple mpfr.h inclusion and va_list related functions
2 
3 Copyright 2011-2018 Free Software Foundation, Inc.
4 Contributed by the AriC and Caramba projects, INRIA.
5 
6 This file is part of the GNU MPFR Library.
7 
8 The GNU MPFR Library is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 The GNU MPFR Library is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
16 License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with the GNU MPFR Library; see the file COPYING.LESSER.  If not, see
20 http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc.,
21 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */
22 
23 #if HAVE_STDARG
24 
25 #if _MPFR_EXP_FORMAT == 4
26 /* If mpfr_exp_t is defined as intmax_t, intmax_t must be defined before
27    the inclusion of mpfr.h (this test doesn't use mpfr-impl.h). */
28 # include <stdint.h>
29 #endif
30 
31 #define MPFR_DONT_USE_FILE  /* don't use FILE in mpfr-impl.h */
32 #ifdef MPFR_USE_MINI_GMP
33 #include "mpfr-test.h"
34 #endif
35 
36 /* One of the goals of this test is to detect potential issues with the
37  * following case in user code:
38  *
39  * #include <some_lib.h>
40  * #include <stdarg.h>
41  * #define MPFR_USE_VA_LIST
42  * #include <mpfr.h>
43  *
44  * where some_lib.h has "#include <mpfr.h>". So, the mpfr.h header file
45  * is included multiple times, a first time without <stdarg.h> before,
46  * and a second time with <stdarg.h> support. We need to make sure that
47  * the second inclusion is not a no-op due to some #include guard. This
48  * was fixed in r7320.
49  *
50  * With mini-gmp, mpfr-impl.h is included first, but this should not
51  * affect this test thanks to MPFR_DONT_USE_FILE.
52  */
53 #include <mpfr.h>
54 
55 #include <stdarg.h>
56 #define MPFR_USE_VA_LIST /* necessary due to GMP bug concerning inclusions */
57 #include <mpfr.h>
58 
59 #include <stdio.h>
60 #define MPFR_USE_FILE /* necessary due to GMP bug concerning inclusions */
61 #include <mpfr.h>
62 
63 #include "mpfr-test.h"
64 
65 static void
66 test (FILE *fout, const char *fmt, ...)
67 {
68   int (*fct) (FILE*, const char*, va_list);
69 
70   fct = mpfr_vfprintf;
71   if (0)
72     {
73       va_list ap;
74       va_start (ap, fmt);
75       fct (fout, fmt, ap);
76       va_end (ap);
77     }
78 }
79 
80 int
81 main (void)
82 {
83   tests_start_mpfr ();
84   test (stdout, "%d\n", 0);
85   tests_end_mpfr ();
86   return 0;
87 }
88 
89 #else  /* HAVE_STDARG */
90 
91 /* The test is disabled. */
92 
93 int
94 main (void)
95 {
96   return 77;
97 }
98 
99 #endif  /* HAVE_STDARG */
100