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 2.1 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; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20
MA 02111-1307, USA. */
28
#include <unistd.h> /* for unlink */
36
#define FILENAME "t-inp_str.tmp"
51
{ "0/1", 10, "0", 3 },
54
{ "/123", 10, "0", 0 },
55
{ "blah", 10, "0", 0 },
56
{ "123/blah", 10, "0", 0 },
57
{ "5 /8", 10, "5", 1 },
58
{ "5/ 8", 10, "0", 0 },
60
{ "ff", 16, "255", 2 },
61
{ "-ff", 16, "-255", 3 },
62
{ "FF", 16, "255", 2 },
63
{ "-FF", 16, "-255", 3 },
69
{ "0x10", 0, "16", 4 },
70
{ "-0x0", 0, "0", 4 },
71
{ "-0x10", 0, "-16", 5 },
72
{ "-0x10/5", 0, "-16/5", 7 },
77
{ "-010", 0, "-8", 4 },
82
int i, post, j, got_nread;
88
for (i = 0; i < numberof (data); i++)
90
for (post = 0; post <= 2; post++)
92
mpq_set_str_or_abort (want, data[i].want, 0);
93
MPQ_CHECK_FORMAT (want);
95
fp = fopen (FILENAME, "w+");
96
ASSERT_ALWAYS (fp != NULL);
97
fputs (data[i].inp, fp);
98
for (j = 0; j < post; j++)
101
ASSERT_ALWAYS (! ferror(fp));
104
got_nread = mpq_inp_str (got, fp, data[i].base);
108
ftell_nread = ftell (fp);
109
if (got_nread != ftell_nread)
111
printf ("mpq_inp_str nread wrong\n");
112
printf (" inp \"%s\"\n", data[i].inp);
113
printf (" base %d\n", data[i].base);
114
printf (" got_nread %d\n", got_nread);
115
printf (" ftell_nread %ld\n", ftell_nread);
120
if (post == 0 && data[i].want_nread == strlen(data[i].inp))
125
printf ("mpq_inp_str didn't read to EOF\n");
126
printf (" inp \"%s\"\n", data[i].inp);
127
printf (" base %d\n", data[i].base);
128
printf (" c '%c' %#x\n", c, c);
133
if (got_nread != data[i].want_nread)
135
printf ("mpq_inp_str nread wrong\n");
136
printf (" inp \"%s\"\n", data[i].inp);
137
printf (" base %d\n", data[i].base);
138
printf (" got_nread %d\n", got_nread);
139
printf (" want_nread %d\n", data[i].want_nread);
143
MPQ_CHECK_FORMAT (got);
145
if (! mpq_equal (got, want))
147
printf ("mpq_inp_str wrong result\n");
148
printf (" inp \"%s\"\n", data[i].inp);
149
printf (" base %d\n", data[i].base);
150
mpq_trace (" got ", got);
151
mpq_trace (" want", want);
155
ASSERT_ALWAYS (fclose (fp) == 0);