diff options
author | Kevin Ryde <user42@zip.com.au> | 2001-12-07 00:26:35 +0100 |
---|---|---|
committer | Kevin Ryde <user42@zip.com.au> | 2001-12-07 00:26:35 +0100 |
commit | a5d91b6097128ac297e8f40d95e0522c853b5b09 (patch) | |
tree | 2c59361e25da479c7d346c5b3709fae6d05826aa | |
parent | d454029f86a4759bb811f2a5a8354a580a0e724d (diff) | |
download | gmp-a5d91b6097128ac297e8f40d95e0522c853b5b09.tar.gz |
* printf/doprnti.c: Don't showbase on a zero mpq denominator.
* tests/misc/t-printf.c, tests/cxx/t-ostream.c: Add test cases.
-rw-r--r-- | tests/cxx/t-ostream.cc | 16 | ||||
-rw-r--r-- | tests/misc/t-printf.c | 18 |
2 files changed, 32 insertions, 2 deletions
diff --git a/tests/cxx/t-ostream.cc b/tests/cxx/t-ostream.cc index 75320c659..78d4a2fb1 100644 --- a/tests/cxx/t-ostream.cc +++ b/tests/cxx/t-ostream.cc @@ -195,6 +195,19 @@ check_mpq (void) { "5/8", "5/8", ios::dec }, { "5/8", "0X5/0X8", ios::hex | ios::showbase | ios::uppercase }, + + /* zero denominator with showbase */ + { "0/0", " 0/0", ios::oct | ios::showbase, 10 }, + { "0/0", " 0/0", ios::dec | ios::showbase, 10 }, + { "0/0", " 0x0/0x0", ios::hex | ios::showbase, 10 }, + { "123/0", " 0173/0", ios::oct | ios::showbase, 10 }, + { "123/0", " 123/0", ios::dec | ios::showbase, 10 }, + { "123/0", " 0x7b/0x0", ios::hex | ios::showbase, 10 }, + { "123/0", " 0X7B/0X0", ios::hex | ios::showbase | ios::uppercase, 10 }, + { "0/123", " 0/0173", ios::oct | ios::showbase, 10 }, + { "0/123", " 0/123", ios::dec | ios::showbase, 10 }, + { "0/123", " 0x0/0x7b", ios::hex | ios::showbase, 10 }, + { "0/123", " 0X0/0X7B", ios::hex | ios::showbase | ios::uppercase, 10 }, }; size_t i; @@ -207,6 +220,8 @@ check_mpq (void) for (i = 0; i < numberof (data); i++) { mpq_set_str_or_abort (q, data[i].q, 0); + MPZ_CHECK_FORMAT (mpq_numref (q)); + MPZ_CHECK_FORMAT (mpq_denref (q)); if (option_check_standard && mpz_fits_slong_p (mpq_numref(q)) @@ -226,7 +241,6 @@ check_mpq (void) { ostrstream got; - MPQ_CHECK_FORMAT (q); CALL (operator<< (got, q) << '\0'); if (strcmp (got.str(), data[i].want) != 0) { diff --git a/tests/misc/t-printf.c b/tests/misc/t-printf.c index 65a66a000..d8ee60905 100644 --- a/tests/misc/t-printf.c +++ b/tests/misc/t-printf.c @@ -408,6 +408,10 @@ check_z (void) { "%+#08Zx", "123", "+0x0007b" }, { "%+#08Zx", "-123", "-0x0007b" }, + { "%.0Zd", "0", "" }, + { "%.1Zd", "0", "0" }, + { "%.2Zd", "0", "00" }, + { "%.3Zd", "0", "000" }, }; int i; @@ -484,6 +488,19 @@ check_q (void) { "%#Qo", "5/7", "05/07" }, { "%#Qo", "-5/7", "-05/07" }, + /* zero denominator and showbase */ + { "%#10Qo", "0/0", " 0/0" }, + { "%#10Qd", "0/0", " 0/0" }, + { "%#10Qx", "0/0", " 0/0" }, + { "%#10Qo", "123/0", " 0173/0" }, + { "%#10Qd", "123/0", " 123/0" }, + { "%#10Qx", "123/0", " 0x7b/0" }, + { "%#10QX", "123/0", " 0X7B/0" }, + { "%#10Qo", "-123/0", " -0173/0" }, + { "%#10Qd", "-123/0", " -123/0" }, + { "%#10Qx", "-123/0", " -0x7b/0" }, + { "%#10QX", "-123/0", " -0X7B/0" }, + { "%10Qd", "0", " 0" }, { "%-10Qd", "0", "0 " }, { "%10Qd", "123", " 123" }, @@ -511,7 +528,6 @@ check_q (void) { "%+#08Qx", "0", "+0000000" }, { "%+#08Qx", "123", "+0x0007b" }, { "%+#08Qx", "-123", "-0x0007b" }, - }; int i; |