summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarc Glisse <marc.glisse@inria.fr>2011-05-10 22:12:34 +0200
committerMarc Glisse <marc.glisse@inria.fr>2011-05-10 22:12:34 +0200
commitb672cadf0ce5c37ae3fa13324bd8b798c838b7ed (patch)
tree5f6ac6541e18e82500fd4c100f480b5ecb389367 /tests
parentf2f538129f025bf4b1d0e3e35fdf0ad66f243ed8 (diff)
downloadgmp-b672cadf0ce5c37ae3fa13324bd8b798c838b7ed.tar.gz
Test stream input/output on mp*_class and not just mp*_t.
Simple optimization: c=-(a+b) becomes c=a+b;c=-c.
Diffstat (limited to 'tests')
-rw-r--r--tests/cxx/Makefile.am7
-rw-r--r--tests/cxx/t-iostream.cc89
2 files changed, 93 insertions, 3 deletions
diff --git a/tests/cxx/Makefile.am b/tests/cxx/Makefile.am
index 16012c3ce..6e214ab6f 100644
--- a/tests/cxx/Makefile.am
+++ b/tests/cxx/Makefile.am
@@ -30,9 +30,9 @@ LDADD = -L$(top_builddir)/.libs \
$(top_builddir)/libgmp.la
if WANT_CXX
-check_PROGRAMS = t-assign t-binary t-cast t-constr t-headers t-istream \
- t-locale t-misc t-mix t-ops t-ops2 t-ops3 t-ostream t-prec t-rand \
- t-ternary t-unary
+check_PROGRAMS = t-assign t-binary t-cast t-constr t-headers t-iostream \
+ t-istream t-locale t-misc t-mix t-ops t-ops2 t-ops3 t-ostream t-prec \
+ t-rand t-ternary t-unary
TESTS = $(check_PROGRAMS)
endif
@@ -41,6 +41,7 @@ t_binary_SOURCES = t-binary.cc
t_cast_SOURCES = t-cast.cc
t_constr_SOURCES = t-constr.cc
t_headers_SOURCES = t-headers.cc
+t_iostream_SOURCES= t-iostream.cc
t_istream_SOURCES = t-istream.cc
t_locale_SOURCES = t-locale.cc clocale.c
t_misc_SOURCES = t-misc.cc
diff --git a/tests/cxx/t-iostream.cc b/tests/cxx/t-iostream.cc
new file mode 100644
index 000000000..9cdd1d54c
--- /dev/null
+++ b/tests/cxx/t-iostream.cc
@@ -0,0 +1,89 @@
+/* Test stream formatted input and output on mp*_class
+
+Copyright 2011 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP Library is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 3 of the License, or (at your
+option) any later version.
+
+The GNU MP Library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */
+
+#include <sstream>
+
+#include "gmp.h"
+#include "gmpxx.h"
+#include "gmp-impl.h"
+#include "tests.h"
+
+using namespace std;
+
+// The tests are extremely basic. These functions just forward to the
+// ones tested in t-istream.cc and t-ostream.cc; we rely on those for
+// advanced tests and only check the syntax here.
+
+void
+checki ()
+{
+ {
+ istringstream i("123");
+ mpz_class x;
+ i >> x;
+ ASSERT_ALWAYS (x == 123);
+ }
+ {
+ istringstream i("3/4");
+ mpq_class x;
+ i >> x;
+ ASSERT_ALWAYS (x == .75);
+ }
+ {
+ istringstream i("1.5");
+ mpf_class x;
+ i >> x;
+ ASSERT_ALWAYS (x == 1.5);
+ }
+}
+
+void
+checko ()
+{
+ {
+ ostringstream o;
+ mpz_class x=123;
+ o << x;
+ ASSERT_ALWAYS (o.str() == "123");
+ }
+ {
+ ostringstream o;
+ mpq_class x(3,4);
+ o << x;
+ ASSERT_ALWAYS (o.str() == "3/4");
+ }
+ {
+ ostringstream o;
+ mpf_class x=1.5;
+ o << x;
+ ASSERT_ALWAYS (o.str() == "1.5");
+ }
+}
+
+int
+main (int argc, char *argv[])
+{
+ tests_start ();
+
+ checki ();
+ checko ();
+
+ tests_end ();
+ return 0;
+}