diff mbox series

Add scanf/vfscanf/vscanf tests of long double without <stdio.h>

Message ID 20240524174630.3169757-1-hjl.tools@gmail.com
State New
Headers show
Series Add scanf/vfscanf/vscanf tests of long double without <stdio.h> | expand

Commit Message

H.J. Lu May 24, 2024, 5:46 p.m. UTC
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     | 41 +++++++++++++++++++++++++++++++++-
 stdio-common/test-fscanf.input |  3 +++
 2 files changed, 43 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/stdio-common/test-fscanf.c b/stdio-common/test-fscanf.c
index f2c4250b51..446d4a307d 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,35 @@ 
    License along with the GNU C Library; if not, see
    <https://www.gnu.org/licenses/>.  */
 
+#include <stdarg.h>
 #include <string.h>
 
 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)
@@ -30,6 +54,21 @@  main (void)
   char name[50];
   n = fscanf (stdin, "%d%Lf%s", &i, &x, name);
 
+  if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
+    return 1;
+
+  n = scanf ("%d%Lf%s", &i, &x, name);
+
+  if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
+    return 1;
+
+  n = wrap_vfscanf (stdin, "%d%Lf%s", &i, &x, name);
+
+  if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
+    return 1;
+
+  n = wrap_vscanf ("%d%Lf%s", &i, &x, name);
+
   if (n != 3 || i != 25 || x != 24.5 || strcmp (name, "thompson"))
     return 1;
 
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