[Gmp-commit] /var/hg/gmp: mini-gmp: Test mpz_out_str.
mercurial at gmplib.org
mercurial at gmplib.org
Mon Jan 21 21:55:49 CET 2013
details: /var/hg/gmp/rev/7763dbcce0a1
changeset: 15336:7763dbcce0a1
user: Niels M?ller <nisse at lysator.liu.se>
date: Mon Jan 21 21:55:42 2013 +0100
description:
mini-gmp: Test mpz_out_str.
diffstat:
ChangeLog | 5 +++++
mini-gmp/tests/t-str.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 0 deletions(-)
diffs (80 lines):
diff -r c8538b70fce6 -r 7763dbcce0a1 ChangeLog
--- a/ChangeLog Sun Jan 20 15:58:27 2013 +0100
+++ b/ChangeLog Mon Jan 21 21:55:42 2013 +0100
@@ -1,3 +1,8 @@
+2013-01-21 Niels Möller <nisse at lysator.liu.se>
+
+ * mini-gmp/tests/t-str.c (testmain): Test mpz_out_str, using
+ the tmpfile function for i/o.
+
2013-01-20 Torbjorn Granlund <tege at gmplib.org>
* Makefile.am (check-mini-gmp): Set also DYLD_LIBRARY_PATH for the
diff -r c8538b70fce6 -r 7763dbcce0a1 mini-gmp/tests/t-str.c
--- a/mini-gmp/tests/t-str.c Sun Jan 20 15:58:27 2013 +0100
+++ b/mini-gmp/tests/t-str.c Mon Jan 21 21:55:42 2013 +0100
@@ -141,6 +141,8 @@
mpz_t a, b;
+ FILE *tmp;
+
void (*freefunc) (void *, size_t);
mp_get_memory_functions (NULL, NULL, &freefunc);
@@ -149,6 +151,11 @@
mpz_init (a);
mpz_init (b);
+ tmp = tmpfile ();
+ if (!tmp)
+ fprintf (stderr,
+ "Failed to create temporary file. Skipping mpz_out_str tests.\n");
+
for (i = 0; i < COUNT; i++)
{
int base;
@@ -185,6 +192,43 @@
abort ();
}
+ /* Just a few tests with file i/o. */
+ if (tmp && i < 20)
+ {
+ size_t tn;
+ rewind (tmp);
+ tn = mpz_out_str (tmp, i&1 ? base: -base, a);
+ if (tn != rn)
+ {
+ fprintf (stderr, "mpz_out_str, bad return value:\n");
+ dump ("a", a);
+ fprintf (stderr, "r = %s\n", rp);
+ fprintf (stderr, " base %d, correct size %u, got %u\n",
+ base, (unsigned) rn, (unsigned)tn);
+ abort ();
+ }
+ rewind (tmp);
+ memset (bp, 0, rn);
+ tn = fread (bp, 1, rn, tmp);
+ if (tn != rn)
+ {
+ fprintf (stderr,
+ "fread failed, expected %u bytes, got only %u.\n",
+ rn, tn);
+ abort ();
+ }
+
+ if (memcmp (bp, rp, rn) != 0)
+ {
+ fprintf (stderr, "mpz_out_str failed:\n");
+ dump ("a", a);
+ fprintf (stderr, "b = %s\n", bp);
+ fprintf (stderr, " base = %d\n", base);
+ fprintf (stderr, "r = %s\n", rp);
+ abort ();
+ }
+ }
+
mpz_set_str (b, rp, base);
if (mpz_cmp (a, b))
More information about the gmp-commit
mailing list