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 { "125", 10, "125", 3 },
54 { "125e1", 10, "1250", 5 },
55 { "125e-1", 10, "12.5", 6 },
57 { "ff", 16, "255", 2 },
58 { "-ff", 16, "-255", 3 },
59 { "FF", 16, "255", 2 },
60 { "-FF", 16, "-255", 3 },
62 { "100", 16, "256", 3 },
63 { "100@1", 16, "4096", 5 },
64 { "100@10", 16, "4722366482869645213696", 6 },
65 { "100@10", -16, "281474976710656", 6 },
66 { "100@-1", 16, "16", 6 },
67 { "10000000000000000@-10", 16, "1", 21 },
68 { "10000000000@-10", -16, "1", 15 },
72 { "z@1", 36, "1260", 3 },
73 { "Z@1", 36, "1260", 3 },
80 int i, pre, post, j, got_nread, want_nread;
86 for (i = 0; i < numberof (data); i++)
88 for (pre = 0; pre <= 3; pre++)
90 for (post = 0; post <= 2; post++)
92 mpf_set_str_or_abort (want, data[i].want, 10);
93 MPF_CHECK_FORMAT (want);
95 /* create the file new each time to ensure its length is what
97 fp = fopen (FILENAME, "w+");
98 ASSERT_ALWAYS (fp != NULL);
99 for (j = 0; j < pre; j++)
101 fputs (data[i].inp, fp);
102 for (j = 0; j < post; j++)
105 ASSERT_ALWAYS (! ferror(fp));
108 got_nread = mpf_inp_str (got, fp, data[i].base);
112 ftell_nread = ftell (fp);
113 if (got_nread != ftell_nread)
115 printf ("mpf_inp_str nread wrong\n");
116 printf (" inp \"%s\"\n", data[i].inp);
117 printf (" base %d\n", data[i].base);
118 printf (" pre %d\n", pre);
119 printf (" post %d\n", post);
120 printf (" got_nread %d\n", got_nread);
121 printf (" ftell_nread %ld\n", ftell_nread);
126 /* if data[i].inp is a whole string to read and there's no post
127 whitespace then expect to have EOF */
128 if (post == 0 && data[i].want_nread == strlen(data[i].inp))
133 printf ("mpf_inp_str didn't read to EOF\n");
134 printf (" inp \"%s\"\n", data[i].inp);
135 printf (" base %d\n", data[i].base);
136 printf (" pre %d\n", pre);
137 printf (" post %d\n", post);
138 printf (" c '%c' %#x\n", c, c);
143 /* only expect "pre" included in the count when non-zero */
144 want_nread = data[i].want_nread;
148 if (got_nread != want_nread)
150 printf ("mpf_inp_str nread wrong\n");
151 printf (" inp \"%s\"\n", data[i].inp);
152 printf (" base %d\n", data[i].base);
153 printf (" pre %d\n", pre);
154 printf (" post %d\n", post);
155 printf (" got_nread %d\n", got_nread);
156 printf (" want_nread %d\n", want_nread);
160 MPF_CHECK_FORMAT (got);
162 if (mpf_cmp (got, want) != 0)
164 printf ("mpf_inp_str wrong result\n");
165 printf (" inp \"%s\"\n", data[i].inp);
166 printf (" base %d\n", data[i].base);
167 mpf_trace (" got ", got);
168 mpf_trace (" want", want);
172 ASSERT_ALWAYS (fclose (fp) == 0);