summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2007-08-08 12:45:54 +0000
committerEric Blake <ebb9@byu.net>2007-08-08 12:45:54 +0000
commitc7110f3b833159c91e8cbe6a14349174aeef4ab6 (patch)
treeb1f30e57f6dab6db962d6ac823191b940964c6d6 /tests
parentfe32d83182dd651bbdaee9a8b6a54c6e3ad9ad2e (diff)
downloadgnulib-c7110f3b833159c91e8cbe6a14349174aeef4ab6.tar.gz
Move xstrtol messages into gnulib domain, when --pobase is used.
* lib/xstrtol.h (_STRTOL_ERROR): Move messages out of macro... * lib/xstrtol-error.c (xstrtol_error): ...into new file. * modules/xstrtol (Files): Distribute new file. * m4/xstrtol.m4 (gl_XSTRTOL): Build new file. * lib/xstrtol.c (TESTING_XSTRTO): Move tests... * tests/test-xstrtol.c: ...into new file. * tests/test-xstrtoul.c: Also test xstrtoul. * tests/test-xstrtoimax.c: Also test xstrtoimax. * tests/test-xstrtoumax.c: Also test xstrtoumax. * tests/test-xstrtol.sh: Drive the tests. * tests/test-xstrtoimax.sh: Likewise. * tests/test-xstrtoumax.sh: Likewise. * modules/xstrtol-tests: New module. * modules/xstrtoimax-tests: Likewise. * modules/xstrtoumax-tests: Likewise.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-xstrtoimax.c4
-rwxr-xr-xtests/test-xstrtoimax.sh43
-rw-r--r--tests/test-xstrtol.c59
-rwxr-xr-xtests/test-xstrtol.sh64
-rw-r--r--tests/test-xstrtoul.c4
-rw-r--r--tests/test-xstrtoumax.c4
-rwxr-xr-xtests/test-xstrtoumax.sh43
7 files changed, 221 insertions, 0 deletions
diff --git a/tests/test-xstrtoimax.c b/tests/test-xstrtoimax.c
new file mode 100644
index 0000000000..cc2f6ae895
--- /dev/null
+++ b/tests/test-xstrtoimax.c
@@ -0,0 +1,4 @@
+#define __xstrtol xstrtoimax
+#define __strtol_t intmax_t
+#define __spec PRIdMAX
+#include "test-xstrtol.c"
diff --git a/tests/test-xstrtoimax.sh b/tests/test-xstrtoimax.sh
new file mode 100755
index 0000000000..d053751c50
--- /dev/null
+++ b/tests/test-xstrtoimax.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-xstrtoimax.tmp t-xstrtoimax.xo"
+: > t-xstrtoimax.tmp
+too_big=99999999999999999999999999999999999999999999999999999999999999999999
+result=0
+
+# test xstrtoimax
+./test-xstrtoimax${EXEEXT} 1 >> t-xstrtoimax.tmp 2>&1 || result=1
+./test-xstrtoimax${EXEEXT} -1 >> t-xstrtoimax.tmp 2>&1 || result=1
+./test-xstrtoimax${EXEEXT} 1k >> t-xstrtoimax.tmp 2>&1 || result=1
+./test-xstrtoimax${EXEEXT} ${too_big}h >> t-xstrtoimax.tmp 2>&1 && result=1
+./test-xstrtoimax${EXEEXT} $too_big >> t-xstrtoimax.tmp 2>&1 && result=1
+./test-xstrtoimax${EXEEXT} x >> t-xstrtoimax.tmp 2>&1 && result=1
+./test-xstrtoimax${EXEEXT} 9x >> t-xstrtoimax.tmp 2>&1 && result=1
+./test-xstrtoimax${EXEEXT} 010 >> t-xstrtoimax.tmp 2>&1 || result=1
+./test-xstrtoimax${EXEEXT} MiB >> t-xstrtoimax.tmp 2>&1 || result=1
+
+# normalize output
+sed -e 's/^[^:]*: //' < t-xstrtoimax.tmp > t-xstrtoimax.xo
+mv t-xstrtoimax.xo t-xstrtoimax.tmp
+
+# compare expected output
+cat > t-xstrtoimax.xo <<EOF
+1->1 ()
+-1->-1 ()
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+010->8 ()
+MiB->1048576 ()
+EOF
+
+diff t-xstrtoimax.xo t-xstrtoimax.tmp || result=1
+
+rm -fr $tmpfiles
+
+exit $result
diff --git a/tests/test-xstrtol.c b/tests/test-xstrtol.c
new file mode 100644
index 0000000000..5f09452a54
--- /dev/null
+++ b/tests/test-xstrtol.c
@@ -0,0 +1,59 @@
+/* Test of xstrtol module.
+ Copyright (C) 1995, 1996, 1998, 1999, 2000, 2001, 2003, 2004, 2005,
+ 2006, 2007 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+
+#include <config.h>
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "xstrtol.h"
+#include "error.h"
+
+#ifndef __xstrtol
+# define __xstrtol xstrtol
+# define __strtol_t long int
+# define __spec "ld"
+#endif
+
+char *program_name;
+
+int
+main (int argc, char **argv)
+{
+ strtol_error s_err;
+ int i;
+
+ program_name = argv[0];
+ for (i = 1; i < argc; i++)
+ {
+ char *p;
+ __strtol_t val;
+
+ s_err = __xstrtol (argv[i], &p, 0, &val, "bckMw0");
+ if (s_err == LONGINT_OK)
+ {
+ printf ("%s->%" __spec " (%s)\n", argv[i], val, p);
+ }
+ else
+ {
+ STRTOL_FATAL_ERROR ("arg", argv[i], s_err);
+ }
+ }
+ exit (0);
+}
diff --git a/tests/test-xstrtol.sh b/tests/test-xstrtol.sh
new file mode 100755
index 0000000000..7bf883379b
--- /dev/null
+++ b/tests/test-xstrtol.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-xstrtol.tmp t-xstrtol.xo"
+: > t-xstrtol.tmp
+too_big=99999999999999999999999999999999999999999999999999999999999999999999
+result=0
+
+# test xstrtol
+./test-xstrtol${EXEEXT} 1 >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtol${EXEEXT} -1 >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtol${EXEEXT} 1k >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtol${EXEEXT} ${too_big}h >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtol${EXEEXT} $too_big >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtol${EXEEXT} x >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtol${EXEEXT} 9x >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtol${EXEEXT} 010 >> t-xstrtol.tmp 2>&1 || result=1
+# suffix without integer is valid
+./test-xstrtol${EXEEXT} MiB >> t-xstrtol.tmp 2>&1 || result=1
+
+# test xstrtoul
+./test-xstrtoul${EXEEXT} 1 >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtoul${EXEEXT} -1 >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} 1k >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtoul${EXEEXT} ${too_big}h >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} $too_big >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} x >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} 9x >> t-xstrtol.tmp 2>&1 && result=1
+./test-xstrtoul${EXEEXT} 010 >> t-xstrtol.tmp 2>&1 || result=1
+./test-xstrtoul${EXEEXT} MiB >> t-xstrtol.tmp 2>&1 || result=1
+
+# normalize output
+sed -e 's/^[^:]*: //' < t-xstrtol.tmp > t-xstrtol.xo
+mv t-xstrtol.xo t-xstrtol.tmp
+
+# compare expected output
+cat > t-xstrtol.xo <<EOF
+1->1 ()
+-1->-1 ()
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+010->8 ()
+MiB->1048576 ()
+1->1 ()
+invalid arg argument \`-1'
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+010->8 ()
+MiB->1048576 ()
+EOF
+
+diff t-xstrtol.xo t-xstrtol.tmp || result=1
+
+rm -fr $tmpfiles
+
+exit $result
diff --git a/tests/test-xstrtoul.c b/tests/test-xstrtoul.c
new file mode 100644
index 0000000000..9dda9ee67e
--- /dev/null
+++ b/tests/test-xstrtoul.c
@@ -0,0 +1,4 @@
+#define __xstrtol xstrtoul
+#define __strtol_t unsigned long int
+#define __spec "lu"
+#include "test-xstrtol.c"
diff --git a/tests/test-xstrtoumax.c b/tests/test-xstrtoumax.c
new file mode 100644
index 0000000000..2e68c2e5d8
--- /dev/null
+++ b/tests/test-xstrtoumax.c
@@ -0,0 +1,4 @@
+#define __xstrtol xstrtoumax
+#define __strtol_t uintmax_t
+#define __spec PRIuMAX
+#include "test-xstrtol.c"
diff --git a/tests/test-xstrtoumax.sh b/tests/test-xstrtoumax.sh
new file mode 100755
index 0000000000..ab065ba580
--- /dev/null
+++ b/tests/test-xstrtoumax.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="t-xstrtoumax.tmp t-xstrtoumax.xo"
+: > t-xstrtoumax.tmp
+too_big=99999999999999999999999999999999999999999999999999999999999999999999
+result=0
+
+# test xstrtoumax
+./test-xstrtoumax${EXEEXT} 1 >> t-xstrtoumax.tmp 2>&1 || result=1
+./test-xstrtoumax${EXEEXT} -1 >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} 1k >> t-xstrtoumax.tmp 2>&1 || result=1
+./test-xstrtoumax${EXEEXT} ${too_big}h >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} $too_big >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} x >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} 9x >> t-xstrtoumax.tmp 2>&1 && result=1
+./test-xstrtoumax${EXEEXT} 010 >> t-xstrtoumax.tmp 2>&1 || result=1
+./test-xstrtoumax${EXEEXT} MiB >> t-xstrtoumax.tmp 2>&1 || result=1
+
+# normalize output
+sed -e 's/^[^:]*: //' < t-xstrtoumax.tmp > t-xstrtoumax.xo
+mv t-xstrtoumax.xo t-xstrtoumax.tmp
+
+# compare expected output
+cat > t-xstrtoumax.xo <<EOF
+1->1 ()
+invalid arg argument \`-1'
+1k->1024 ()
+invalid suffix in arg argument \`${too_big}h'
+arg argument \`$too_big' too large
+invalid arg argument \`x'
+invalid suffix in arg argument \`9x'
+010->8 ()
+MiB->1048576 ()
+EOF
+
+diff t-xstrtoumax.xo t-xstrtoumax.tmp || result=1
+
+rm -fr $tmpfiles
+
+exit $result