3 Copyright 2001, 2002 Free Software Foundation, Inc.
5 This file is part of the GNU MP Library.
7 The GNU MP Library is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 The GNU MP Library is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
26 #include <unistd.h> /* for unlink */
34 #define FILENAME "t-inp_str.tmp"
50 { "abc", 10, "0", 0 },
51 { "ghi", 16, "0", 0 },
53 { "ff", 16, "255", 2 },
54 { "-ff", 16, "-255", 3 },
55 { "FF", 16, "255", 2 },
56 { "-FF", 16, "-255", 3 },
62 { "0x10", 0, "16", 4 },
63 { "-0x0", 0, "0", 4 },
64 { "-0x10", 0, "-16", 5 },
69 { "-010", 0, "-8", 4 },
77 int i, pre, post, j, got_nread, want_nread;
83 for (i = 0; i < numberof (data); i++)
85 for (pre = 0; pre <= 3; pre++)
87 for (post = 0; post <= 2; post++)
89 mpz_set_str_or_abort (want, data[i].want, 0);
90 MPZ_CHECK_FORMAT (want);
92 /* create the file new each time to ensure its length is what
94 fp = fopen (FILENAME, "w+");
95 ASSERT_ALWAYS (fp != NULL);
96 for (j = 0; j < pre; j++)
98 fputs (data[i].inp, fp);
99 for (j = 0; j < post; j++)
102 ASSERT_ALWAYS (! ferror(fp));
105 got_nread = mpz_inp_str (got, fp, data[i].base);
109 ftell_nread = ftell (fp);
110 if (got_nread != ftell_nread)
112 printf ("mpz_inp_str nread wrong\n");
113 printf (" inp \"%s\"\n", data[i].inp);
114 printf (" base %d\n", data[i].base);
115 printf (" pre %d\n", pre);
116 printf (" post %d\n", post);
117 printf (" got_nread %d\n", got_nread);
118 printf (" ftell_nread %ld\n", ftell_nread);
123 /* if data[i].inp is a whole string to read and there's no post
124 whitespace then expect to have EOF */
125 if (post == 0 && data[i].want_nread == strlen(data[i].inp))
130 printf ("mpz_inp_str didn't read to EOF\n");
131 printf (" inp \"%s\"\n", data[i].inp);
132 printf (" base %d\n", data[i].base);
133 printf (" pre %d\n", pre);
134 printf (" post %d\n", post);
135 printf (" c '%c' %#x\n", c, c);
140 /* only expect "pre" included in the count when non-zero */
141 want_nread = data[i].want_nread;
145 if (got_nread != want_nread)
147 printf ("mpz_inp_str nread wrong\n");
148 printf (" inp \"%s\"\n", data[i].inp);
149 printf (" base %d\n", data[i].base);
150 printf (" pre %d\n", pre);
151 printf (" post %d\n", post);
152 printf (" got_nread %d\n", got_nread);
153 printf (" want_nread %d\n", want_nread);
157 MPZ_CHECK_FORMAT (got);
159 if (mpz_cmp (got, want) != 0)
161 printf ("mpz_inp_str wrong result\n");
162 printf (" inp \"%s\"\n", data[i].inp);
163 printf (" base %d\n", data[i].base);
164 mpz_trace (" got ", got);
165 mpz_trace (" want", want);
169 ASSERT_ALWAYS (fclose (fp) == 0);