2019-07-11 14:47:16 +00:00
|
|
|
/* Test for the long double variants of *scanf functions.
|
2020-01-01 00:14:33 +00:00
|
|
|
Copyright (C) 2019-2020 Free Software Foundation, Inc.
|
2019-07-11 14:47:16 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C 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.
|
|
|
|
|
|
|
|
The GNU C 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 the GNU C Library; if not, see
|
2019-11-27 21:14:14 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2019-07-11 14:47:16 +00:00
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
#include <support/check.h>
|
|
|
|
|
2019-07-11 14:47:43 +00:00
|
|
|
#define CLEAR_VARGS \
|
2019-07-11 14:47:16 +00:00
|
|
|
va_start (args, format); \
|
2019-07-11 14:47:43 +00:00
|
|
|
ldptr = va_arg (args, long double *); \
|
|
|
|
fptr = va_arg (args, float *); \
|
|
|
|
*ldptr = 0; \
|
|
|
|
*fptr = 0; \
|
2019-07-11 14:47:16 +00:00
|
|
|
va_end (args);
|
|
|
|
|
2019-07-11 14:47:43 +00:00
|
|
|
#define CHECK_VARGS \
|
2019-07-11 14:47:16 +00:00
|
|
|
va_start (args, format); \
|
2019-07-11 14:47:43 +00:00
|
|
|
ldptr = va_arg (args, long double *); \
|
|
|
|
fptr = va_arg (args, float *); \
|
2019-07-11 14:47:16 +00:00
|
|
|
va_end (args); \
|
2019-07-11 14:47:43 +00:00
|
|
|
if (*ldptr == -1 && *fptr == -2) \
|
2019-07-11 14:47:16 +00:00
|
|
|
printf ("OK"); \
|
|
|
|
else \
|
2019-07-11 14:47:43 +00:00
|
|
|
printf ("ERROR (%Lf %f)", *ldptr, *fptr); \
|
2019-07-11 14:47:16 +00:00
|
|
|
printf ("\n");
|
|
|
|
|
2019-07-11 14:47:43 +00:00
|
|
|
#define CLEAR_VALUE \
|
|
|
|
ld = 0; \
|
|
|
|
f = 0;
|
|
|
|
|
2019-07-11 14:47:16 +00:00
|
|
|
#define CHECK_VALUE \
|
2019-07-11 14:47:43 +00:00
|
|
|
if (ld == -1 && f == -2) \
|
2019-07-11 14:47:16 +00:00
|
|
|
printf ("OK"); \
|
|
|
|
else \
|
2019-07-11 14:47:43 +00:00
|
|
|
printf ("ERROR (%Lf %f)", ld, f); \
|
2019-07-11 14:47:16 +00:00
|
|
|
printf ("\n");
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_test_call (FILE *stream, CHAR *string, const CHAR *format, ...)
|
|
|
|
{
|
2019-07-11 14:47:43 +00:00
|
|
|
float f;
|
|
|
|
long double ld;
|
|
|
|
float *fptr;
|
|
|
|
long double *ldptr;
|
2019-07-11 14:47:16 +00:00
|
|
|
va_list args;
|
|
|
|
|
|
|
|
CLEAR_VALUE
|
|
|
|
printf ("fscanf: ");
|
2019-07-11 14:47:43 +00:00
|
|
|
FSCANF (stream, format, &ld, &f);
|
2019-07-11 14:47:16 +00:00
|
|
|
CHECK_VALUE
|
|
|
|
|
|
|
|
CLEAR_VALUE
|
|
|
|
printf ("scanf: ");
|
2019-07-11 14:47:43 +00:00
|
|
|
SCANF (format, &ld, &f);
|
2019-07-11 14:47:16 +00:00
|
|
|
CHECK_VALUE
|
|
|
|
|
|
|
|
CLEAR_VALUE
|
|
|
|
printf ("sscanf: ");
|
2019-07-11 14:47:43 +00:00
|
|
|
SSCANF (string, format, &ld, &f);
|
2019-07-11 14:47:16 +00:00
|
|
|
CHECK_VALUE
|
|
|
|
|
2019-07-11 14:47:43 +00:00
|
|
|
CLEAR_VARGS
|
2019-07-11 14:47:16 +00:00
|
|
|
printf ("vfscanf: ");
|
|
|
|
va_start (args, format);
|
|
|
|
VFSCANF (stream, format, args);
|
|
|
|
va_end (args);
|
2019-07-11 14:47:43 +00:00
|
|
|
CHECK_VARGS
|
2019-07-11 14:47:16 +00:00
|
|
|
|
2019-07-11 14:47:43 +00:00
|
|
|
CLEAR_VARGS
|
2019-07-11 14:47:16 +00:00
|
|
|
printf ("vscanf: ");
|
|
|
|
va_start (args, format);
|
|
|
|
VSCANF (format, args);
|
|
|
|
va_end (args);
|
2019-07-11 14:47:43 +00:00
|
|
|
CHECK_VARGS
|
2019-07-11 14:47:16 +00:00
|
|
|
|
2019-07-11 14:47:43 +00:00
|
|
|
CLEAR_VARGS
|
2019-07-11 14:47:16 +00:00
|
|
|
printf ("vsscanf: ");
|
|
|
|
va_start (args, format);
|
|
|
|
VSSCANF (string, format, args);
|
|
|
|
va_end (args);
|
2019-07-11 14:47:43 +00:00
|
|
|
CHECK_VARGS
|
2019-07-11 14:47:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_test (void)
|
|
|
|
{
|
|
|
|
CHAR string[256];
|
2019-07-11 14:47:43 +00:00
|
|
|
float f;
|
2019-07-11 14:47:16 +00:00
|
|
|
long double ld;
|
|
|
|
|
|
|
|
/* Scan in decimal notation. */
|
|
|
|
STRCPY (string,
|
2019-07-11 14:47:43 +00:00
|
|
|
L ("-1.0 -2.0\n")
|
|
|
|
L ("-1.0 -2.0\n") );
|
|
|
|
do_test_call (stdin, string, L("%Lf %f"), &ld, &f);
|
2019-07-11 14:47:16 +00:00
|
|
|
|
|
|
|
/* Scan in hexadecimal notation. */
|
|
|
|
STRCPY (string,
|
2019-07-11 14:47:43 +00:00
|
|
|
L ("-0x1.0p+0 -0x2.0p+0\n")
|
|
|
|
L ("-0x1.0p+0 -0x2.0p+0\n") );
|
|
|
|
/* For ISO C99, scan the single-precision value with "%as" to test
|
|
|
|
that __isoc99_*scanf ignores the 's'. For DEPRECATED_SCANF, do not
|
|
|
|
use "%as", because that would try to scan a string and allocate
|
|
|
|
space for it. */
|
|
|
|
#if __GLIBC_USE (DEPRECATED_SCANF)
|
|
|
|
# define FMT "%La %a"
|
|
|
|
#else
|
|
|
|
# define FMT "%La %as"
|
|
|
|
#endif
|
|
|
|
do_test_call (stdin, string, L(FMT), &ld, &f);
|
2019-07-11 14:47:16 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#include <support/test-driver.c>
|