[PATCH v2] Add scanf/vfscanf/vscanf tests of long double without <stdio.h>
H.J. Lu
hjl.tools@gmail.com
Fri May 24 17:52:19 GMT 2024
Update test-fscanf.c to add scanf/vfscanf/vscanf tests of long double
without including <stdio.h>.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
stdio-common/test-fscanf.c | 55 ++++++++++++++++++++++++++++++++--
stdio-common/test-fscanf.input | 3 ++
2 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/stdio-common/test-fscanf.c b/stdio-common/test-fscanf.c
index f2c4250b51..26477300a5 100644
--- a/stdio-common/test-fscanf.c
+++ b/stdio-common/test-fscanf.c
@@ -1,4 +1,4 @@
-/* Test fscanf of long double without <stdio.h>.
+/* Test fscanf/scanf/vfscanf/vscanf of long double without <stdio.h>.
Copyright (C) 2024 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@@ -16,11 +16,39 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <stdarg.h>
#include <string.h>
+#ifndef EXPECTED_LONG_DOUBLE_VALUE
+# define EXPECTED_LONG_DOUBLE_VALUE 24.5
+#endif
+
struct FILE;
extern struct FILE *stdin;
extern int fscanf (struct FILE *, const char *, ...);
+extern int scanf (const char *, ...);
+extern int vfscanf (struct FILE *, const char *, va_list);
+extern int vscanf (const char *, va_list);
+
+static int
+wrap_vfscanf (struct FILE *fp, const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ int ret = vfscanf (fp, format, ap);
+ va_end (ap);
+ return ret;
+}
+
+static int
+wrap_vscanf (const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ int ret = vscanf (format, ap);
+ va_end (ap);
+ return ret;
+}
int
main (void)
@@ -29,8 +57,31 @@ main (void)
long double x;
char name[50];
n = fscanf (stdin, "%d%Lf%s", &i, &x, name);
+ if (n != 3
+ || i != 25
+ || x != EXPECTED_LONG_DOUBLE_VALUE
+ || strcmp (name, "thompson"))
+ return 1;
+
+ n = scanf ("%d%Lf%s", &i, &x, name);
+ if (n != 3
+ || i != 25
+ || x != EXPECTED_LONG_DOUBLE_VALUE
+ || strcmp (name, "thompson"))
+ return 1;
+
+ n = wrap_vfscanf (stdin, "%d%Lf%s", &i, &x, name);
+ if (n != 3
+ || i != 25
+ || x != EXPECTED_LONG_DOUBLE_VALUE
+ || strcmp (name, "thompson"))
+ return 1;
- if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
+ n = wrap_vscanf ("%d%Lf%s", &i, &x, name);
+ if (n != 3
+ || i != 25
+ || x != EXPECTED_LONG_DOUBLE_VALUE
+ || strcmp (name, "thompson"))
return 1;
return 0;
diff --git a/stdio-common/test-fscanf.input b/stdio-common/test-fscanf.input
index 69322cc51a..20859d314a 100644
--- a/stdio-common/test-fscanf.input
+++ b/stdio-common/test-fscanf.input
@@ -1 +1,4 @@
25 24.5 thompson
+25 24.5 thompson
+25 24.5 thompson
+25 24.5 thompson
--
2.45.1
More information about the Libc-alpha
mailing list