diff options
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | cxx/ismpf.cc | 2 | ||||
-rw-r--r-- | cxx/ismpq.cc | 2 | ||||
-rw-r--r-- | cxx/ismpznw.cc | 2 | ||||
-rw-r--r-- | tests/cxx/t-istream.cc | 92 | ||||
-rw-r--r-- | tests/cxx/t-misc.cc | 24 | ||||
-rw-r--r-- | tests/cxx/t-ostream.cc | 4 |
7 files changed, 104 insertions, 33 deletions
@@ -1,3 +1,14 @@ +2011-03-09 Marc Glisse <marc.glisse@inria.fr> + + * tests/cxx/t-ostream.cc: Use bool instead of int. + * tests/cxx/t-istream.cc: Likewise. + * tests/cxx/t-misc.cc: Likewise. + + * cxx/ismpznw.cc: Don't clear eofbit. + * cxx/ismpq.cc: Likewise. + * cxx/ismpf.cc: Likewise. + * tests/cxx/t-istream.cc: Test accordingly. + 2011-03-09 Marco Bodrato <bodrato@mail.dm.unipi.it> * mpn/x86/atom/sse2/bdiv_dbm1c.asm: New file. diff --git a/cxx/ismpf.cc b/cxx/ismpf.cc index bfe4dc8b9..520d4c3e2 100644 --- a/cxx/ismpf.cc +++ b/cxx/ismpf.cc @@ -120,7 +120,7 @@ operator>> (istream &i, mpf_ptr f) if (i.good()) // last character read was non-numeric i.putback(c); else if (i.eof() && ok) // stopped just before eof - i.clear(); + i.clear(ios::eofbit); if (ok) ASSERT_NOCARRY (mpf_set_str(f, s.c_str(), base)); // extract the number diff --git a/cxx/ismpq.cc b/cxx/ismpq.cc index 23eec7657..5cf8c4f94 100644 --- a/cxx/ismpq.cc +++ b/cxx/ismpq.cc @@ -49,7 +49,7 @@ operator>> (istream &i, mpq_ptr q) if (i.good()) i.putback(c); else if (i.eof()) - i.clear(); + i.clear(ios::eofbit); } return i; diff --git a/cxx/ismpznw.cc b/cxx/ismpznw.cc index 387d092ac..4111575d0 100644 --- a/cxx/ismpznw.cc +++ b/cxx/ismpznw.cc @@ -49,7 +49,7 @@ __gmpz_operator_in_nowhite (istream &i, mpz_ptr z, char c) if (i.good()) // last character read was non-numeric i.putback(c); else if (i.eof() && (ok || zero)) // stopped just before eof - i.clear(); + i.clear(ios::eofbit); if (ok) ASSERT_NOCARRY (mpz_set_str (z, s.c_str(), base)); // extract the number diff --git a/tests/cxx/t-istream.cc b/tests/cxx/t-istream.cc index 59600be16..34b1509c0 100644 --- a/tests/cxx/t-istream.cc +++ b/tests/cxx/t-istream.cc @@ -37,7 +37,7 @@ using namespace std; // since there's no mantissa digits, but g++ reads the whole thing and only // then decides it's bad. -int option_check_standard = 0; +bool option_check_standard = false; // On some versions of g++ 2.96 it's been observed that putback() may leave @@ -45,7 +45,7 @@ int option_check_standard = 0; // result of a bug, since for instance it's ok in g++ 2.95 and g++ 3.3. We // detect the problem at runtime and disable affected checks. -int putback_tellg_works = 1; +bool putback_tellg_works = true; void check_putback_tellg (void) @@ -63,7 +63,7 @@ check_putback_tellg (void) { cout << "Warning, istringstream has a bug: putback() doesn't update tellg().\n";; cout << "Tests on tellg() will be skipped.\n"; - putback_tellg_works = 0; + putback_tellg_works = false; } } @@ -132,7 +132,8 @@ check_mpz (void) }; mpz_t got, want; - int got_ok, want_ok; + bool got_ok, want_ok; + bool got_eof, want_eof; long got_si, want_si; streampos init_tellg, got_pos, want_pos; @@ -141,8 +142,10 @@ check_mpz (void) for (size_t i = 0; i < numberof (data); i++) { + size_t input_length = strlen (data[i].input); want_pos = (data[i].want_pos == -1 - ? strlen (data[i].input) : data[i].want_pos); + ? input_length : data[i].want_pos); + want_eof = (want_pos == input_length); want_ok = (data[i].want != NULL); @@ -159,7 +162,8 @@ check_mpz (void) want_si = mpz_get_si (want); input >> got_si; - got_ok = (input ? 1 : 0); + got_ok = !input.fail(); + got_eof = input.eof(); input.clear(); got_pos = input.tellg() - init_tellg; @@ -175,6 +179,12 @@ check_mpz (void) cout << " got_si: " << got_si << "\n"; cout << " want_si: " << want_si << "\n"; } + if (want_ok && got_eof != want_eof) + { + WRONG ("stdc++ operator>> wrong EOF state, check_mpz"); + cout << " got_eof: " << got_eof << "\n"; + cout << " want_eof: " << want_eof << "\n"; + } if (putback_tellg_works && got_pos != want_pos) { WRONG ("stdc++ operator>> wrong position, check_mpz"); @@ -190,7 +200,8 @@ check_mpz (void) mpz_set_ui (got, 0xDEAD); input >> got; - got_ok = (input ? 1 : 0); + got_ok = !input.fail(); + got_eof = input.eof(); input.clear(); got_pos = input.tellg() - init_tellg; @@ -208,6 +219,13 @@ check_mpz (void) mpz_trace (" want", want); abort (); } + if (want_ok && got_eof != want_eof) + { + WRONG ("mpz operator>> wrong EOF state"); + cout << " want_eof: " << want_eof << "\n"; + cout << " got_eof: " << got_eof << "\n"; + abort (); + } if (putback_tellg_works && got_pos != want_pos) { WRONG ("mpz operator>> wrong position"); @@ -271,10 +289,17 @@ check_mpq (void) { " 123", 0, NULL, (ios::fmtflags) 0 }, // not without skipws { " 123", -1, "123", ios::skipws }, + + { "123 /456", 3, "123", (ios::fmtflags) 0 }, + { "123/ 456", 4, NULL, (ios::fmtflags) 0 }, + { "123/" , -1, NULL, (ios::fmtflags) 0 }, + { "123 /456", 3, "123", ios::skipws }, + { "123/ 456", 4, NULL, ios::skipws }, }; mpq_t got, want; - int got_ok, want_ok; + bool got_ok, want_ok; + bool got_eof, want_eof; long got_si, want_si; streampos init_tellg, got_pos, want_pos; @@ -283,8 +308,10 @@ check_mpq (void) for (size_t i = 0; i < numberof (data); i++) { + size_t input_length = strlen (data[i].input); want_pos = (data[i].want_pos == -1 - ? strlen (data[i].input) : data[i].want_pos); + ? input_length : data[i].want_pos); + want_eof = (want_pos == input_length); want_ok = (data[i].want != NULL); @@ -303,7 +330,8 @@ check_mpq (void) want_si = mpz_get_si (mpq_numref(want)); input >> got_si; - got_ok = (input ? 1 : 0); + got_ok = !input.fail(); + got_eof = input.eof(); input.clear(); got_pos = input.tellg() - init_tellg; @@ -319,6 +347,12 @@ check_mpq (void) cout << " got_si: " << got_si << "\n"; cout << " want_si: " << want_si << "\n"; } + if (want_ok && got_eof != want_eof) + { + WRONG ("stdc++ operator>> wrong EOF state, check_mpq"); + cout << " got_eof: " << got_eof << "\n"; + cout << " want_eof: " << want_eof << "\n"; + } if (putback_tellg_works && got_pos != want_pos) { WRONG ("stdc++ operator>> wrong position, check_mpq"); @@ -334,7 +368,8 @@ check_mpq (void) mpq_set_si (got, 0xDEAD, 0xBEEF); input >> got; - got_ok = (input ? 1 : 0); + got_ok = !input.fail(); + got_eof = input.eof(); input.clear(); got_pos = input.tellg() - init_tellg; @@ -355,6 +390,13 @@ check_mpq (void) mpq_trace (" want", want); abort (); } + if (want_ok && got_eof != want_eof) + { + WRONG ("mpq operator>> wrong EOF state"); + cout << " want_eof: " << want_eof << "\n"; + cout << " got_eof: " << got_eof << "\n"; + abort (); + } if (putback_tellg_works && got_pos != want_pos) { WRONG ("mpq operator>> wrong position"); @@ -428,7 +470,8 @@ check_mpf (void) }; mpf_t got, want; - int got_ok, want_ok; + bool got_ok, want_ok; + bool got_eof, want_eof; double got_d, want_d; streampos init_tellg, got_pos, want_pos; @@ -437,8 +480,10 @@ check_mpf (void) for (size_t i = 0; i < numberof (data); i++) { + size_t input_length = strlen (data[i].input); want_pos = (data[i].want_pos == -1 - ? strlen (data[i].input) : data[i].want_pos); + ? input_length : data[i].want_pos); + want_eof = (want_pos == input_length); want_ok = (data[i].want != NULL); @@ -455,7 +500,8 @@ check_mpf (void) init_tellg = input.tellg(); input >> got_d; - got_ok = (input ? 1 : 0); + got_ok = !input.fail(); + got_eof = input.eof(); input.clear(); got_pos = input.tellg() - init_tellg; @@ -471,6 +517,12 @@ check_mpf (void) cout << " got: " << got_d << "\n"; cout << " want: " << want_d << "\n"; } + if (want_ok && got_eof != want_eof) + { + WRONG ("stdc++ operator>> wrong EOF state, check_mpf"); + cout << " got_eof: " << got_eof << "\n"; + cout << " want_eof: " << want_eof << "\n"; + } if (putback_tellg_works && got_pos != want_pos) { WRONG ("stdc++ operator>> wrong position, check_mpf"); @@ -486,7 +538,8 @@ check_mpf (void) mpf_set_ui (got, 0xDEAD); input >> got; - got_ok = (input ? 1 : 0); + got_ok = !input.fail(); + got_eof = input.eof(); input.clear(); got_pos = input.tellg() - init_tellg; @@ -504,6 +557,13 @@ check_mpf (void) mpf_trace (" want", want); abort (); } + if (want_ok && got_eof != want_eof) + { + WRONG ("mpf operator>> wrong EOF state"); + cout << " want_eof: " << want_eof << "\n"; + cout << " got_eof: " << got_eof << "\n"; + abort (); + } if (putback_tellg_works && got_pos != want_pos) { WRONG ("mpf operator>> wrong position"); @@ -524,7 +584,7 @@ int main (int argc, char *argv[]) { if (argc > 1 && strcmp (argv[1], "-s") == 0) - option_check_standard = 1; + option_check_standard = true; tests_start (); diff --git a/tests/cxx/t-misc.cc b/tests/cxx/t-misc.cc index 19c54992b..d6f37bcf0 100644 --- a/tests/cxx/t-misc.cc +++ b/tests/cxx/t-misc.cc @@ -41,7 +41,7 @@ check_mpz (void) { // mpz_class::fits_sint_p { - int fits; + bool fits; mpz_class z; z = INT_MIN; fits = z.fits_sint_p(); ASSERT_ALWAYS (fits); z--; fits = z.fits_sint_p(); ASSERT_ALWAYS (! fits); @@ -51,7 +51,7 @@ check_mpz (void) // mpz_class::fits_uint_p { - int fits; + bool fits; mpz_class z; z = 0; fits = z.fits_uint_p(); ASSERT_ALWAYS (fits); z--; fits = z.fits_uint_p(); ASSERT_ALWAYS (! fits); @@ -61,7 +61,7 @@ check_mpz (void) // mpz_class::fits_slong_p { - int fits; + bool fits; mpz_class z; z = LONG_MIN; fits = z.fits_slong_p(); ASSERT_ALWAYS (fits); z--; fits = z.fits_slong_p(); ASSERT_ALWAYS (! fits); @@ -71,7 +71,7 @@ check_mpz (void) // mpz_class::fits_ulong_p { - int fits; + bool fits; mpz_class z; z = 0; fits = z.fits_ulong_p(); ASSERT_ALWAYS (fits); z--; fits = z.fits_ulong_p(); ASSERT_ALWAYS (! fits); @@ -81,7 +81,7 @@ check_mpz (void) // mpz_class::fits_sshort_p { - int fits; + bool fits; mpz_class z; z = SHRT_MIN; fits = z.fits_sshort_p(); ASSERT_ALWAYS (fits); z--; fits = z.fits_sshort_p(); ASSERT_ALWAYS (! fits); @@ -91,7 +91,7 @@ check_mpz (void) // mpz_class::fits_ushort_p { - int fits; + bool fits; mpz_class z; z = 0; fits = z.fits_ushort_p(); ASSERT_ALWAYS (fits); z--; fits = z.fits_ushort_p(); ASSERT_ALWAYS (! fits); @@ -241,7 +241,7 @@ check_mpf (void) { // mpf_class::fits_sint_p { - int fits; + bool fits; mpf_class f (0, 2*8*sizeof(int)); f = INT_MIN; fits = f.fits_sint_p(); ASSERT_ALWAYS (fits); f--; fits = f.fits_sint_p(); ASSERT_ALWAYS (! fits); @@ -251,7 +251,7 @@ check_mpf (void) // mpf_class::fits_uint_p { - int fits; + bool fits; mpf_class f (0, 2*8*sizeof(int)); f = 0; fits = f.fits_uint_p(); ASSERT_ALWAYS (fits); f--; fits = f.fits_uint_p(); ASSERT_ALWAYS (! fits); @@ -261,7 +261,7 @@ check_mpf (void) // mpf_class::fits_slong_p { - int fits; + bool fits; mpf_class f (0, 2*8*sizeof(long)); f = LONG_MIN; fits = f.fits_slong_p(); ASSERT_ALWAYS (fits); f--; fits = f.fits_slong_p(); ASSERT_ALWAYS (! fits); @@ -271,7 +271,7 @@ check_mpf (void) // mpf_class::fits_ulong_p { - int fits; + bool fits; mpf_class f (0, 2*8*sizeof(long)); f = 0; fits = f.fits_ulong_p(); ASSERT_ALWAYS (fits); f--; fits = f.fits_ulong_p(); ASSERT_ALWAYS (! fits); @@ -281,7 +281,7 @@ check_mpf (void) // mpf_class::fits_sshort_p { - int fits; + bool fits; mpf_class f (0, 2*8*sizeof(short)); f = SHRT_MIN; fits = f.fits_sshort_p(); ASSERT_ALWAYS (fits); f--; fits = f.fits_sshort_p(); ASSERT_ALWAYS (! fits); @@ -291,7 +291,7 @@ check_mpf (void) // mpf_class::fits_ushort_p { - int fits; + bool fits; mpf_class f (0, 2*8*sizeof(short)); f = 0; fits = f.fits_ushort_p(); ASSERT_ALWAYS (fits); f--; fits = f.fits_ushort_p(); ASSERT_ALWAYS (! fits); diff --git a/tests/cxx/t-ostream.cc b/tests/cxx/t-ostream.cc index 0eeb7be62..d18cb012f 100644 --- a/tests/cxx/t-ostream.cc +++ b/tests/cxx/t-ostream.cc @@ -27,7 +27,7 @@ along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ using namespace std; -int option_check_standard = 0; +bool option_check_standard = false; #define CALL(expr) \ @@ -437,7 +437,7 @@ int main (int argc, char *argv[]) { if (argc > 1 && strcmp (argv[1], "-s") == 0) - option_check_standard = 1; + option_check_standard = true; tests_start (); |