xref: /netbsd-src/external/lgpl3/mpfr/dist/tests/tvalist.c (revision ba125506a622fe649968631a56eba5d42ff57863)
1 /* Test file for multiple mpfr.h inclusion and va_list related functions
2 
3 Copyright 2011-2023 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 https://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 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
26 
27 #if defined(HAVE_STDARG) && !defined(MPFR_USE_MINI_GMP)
28 
29 #if _MPFR_EXP_FORMAT == 4
30 /* If mpfr_exp_t is defined as intmax_t, intmax_t must be defined before
31    the inclusion of mpfr.h (this test doesn't use mpfr-impl.h). */
32 # include <stdint.h>
33 #endif
34 
35 /* One of the goals of this test is to detect potential issues with the
36  * following case in user code:
37  *
38  * #include <some_lib.h>
39  * #include <stdarg.h>
40  * #define MPFR_USE_VA_LIST
41  * #include <mpfr.h>
42  *
43  * where some_lib.h has "#include <mpfr.h>". So, the mpfr.h header file
44  * is included multiple times, a first time without <stdarg.h> before,
45  * and a second time with <stdarg.h> support. We need to make sure that
46  * the second inclusion is not a no-op due to some #include guard. This
47  * was fixed in r7320.
48  *
49  * Note: one needs to make sure that optimizations do not drop the call
50  * to mpfr_vfprintf.
51  */
52 #include <mpfr.h>
53 
54 #include <stdarg.h>
55 #define MPFR_USE_VA_LIST /* necessary due to GMP bug concerning inclusions */
56 #include <mpfr.h>
57 
58 #include <stdio.h>
59 #define MPFR_USE_FILE /* necessary due to GMP bug concerning inclusions */
60 #include <mpfr.h>
61 
62 #include "mpfr-test.h"
63 
64 static void
test(FILE * fout,const char * fmt,...)65 test (FILE *fout, const char *fmt, ...)
66 {
67   va_list ap;
68 
69   va_start (ap, fmt);
70   mpfr_vfprintf (fout, fmt, ap);
71   va_end (ap);
72 }
73 
74 int
main(void)75 main (void)
76 {
77   tests_start_mpfr ();
78   test (stdout, "");
79   tests_end_mpfr ();
80   return 0;
81 }
82 
83 #else  /* HAVE_STDARG */
84 
85 /* The test is disabled. */
86 
87 int
main(void)88 main (void)
89 {
90   return 77;
91 }
92 
93 #endif  /* HAVE_STDARG */
94