]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/multiprecision/test/test_float_serial.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / multiprecision / test / test_float_serial.hpp
index 219943207ce270eb45d61875b2613c84345a70e1..98298e043f3d6976ff603eab21c7b4e0c48977e8 100644 (file)
@@ -1,7 +1,7 @@
 ///////////////////////////////////////////////////////////////
 //  Copyright 2013 John Maddock. Distributed under the Boost
 //  Software License, Version 1.0. (See accompanying file
-//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_
+//  LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt
 
 #include <boost/random/mersenne_twister.hpp>
 #include <boost/random/uniform_int.hpp>
 #include <boost/archive/text_oarchive.hpp>
 #include <boost/archive/binary_iarchive.hpp>
 #include <boost/archive/binary_oarchive.hpp>
+#include <boost/archive/xml_iarchive.hpp>
+#include <boost/archive/xml_oarchive.hpp>
 #include <boost/exception/all.hpp>
 
-
 #ifndef BOOST_MP_TEST_FLOAT_SERIAL_HPP
 #define BOOST_MP_TEST_FLOAT_SERIAL_HPP
 
@@ -25,10 +26,10 @@ template <class T>
 T generate_random(unsigned /*bits_wanted*/)
 {
    typedef typename T::backend_type::exponent_type e_type;
-   static boost::random::mt19937 gen;
-   T val = gen();
-   T prev_val = -1;
-   while(val != prev_val)
+   static boost::random::mt19937                   gen;
+   T                                               val      = gen();
+   T                                               prev_val = -1;
+   while (val != prev_val)
    {
       val *= (gen.max)();
       prev_val = val;
@@ -46,25 +47,38 @@ void test()
 {
    boost::timer tim;
 
-   while(true)
+   while (true)
    {
-      T val = generate_random<T>(boost::math::tools::digits<T>());
-      int test_id = 0;
+      T           val     = generate_random<T>(boost::math::tools::digits<T>());
+      int         test_id = 0;
       std::string stream_contents;
 #ifndef BOOST_NO_EXCEPTIONS
-      try{
+      try
+      {
 #endif
          test_id = 0;
          {
-            std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+            std::stringstream             ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
             boost::archive::text_oarchive oa(ss);
             oa << static_cast<const T&>(val);
             stream_contents = ss.str();
             boost::archive::text_iarchive ia(ss);
-            T val2;
+            T                             val2;
             ia >> val2;
             BOOST_CHECK_EQUAL(val, val2);
          }
+         {
+            std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+            {
+               boost::archive::xml_oarchive oa(ss);
+               oa << boost::serialization::make_nvp("value", static_cast<const T&>(val));
+               stream_contents = ss.str();
+            }
+            boost::archive::xml_iarchive ia(ss);
+            T                            val2;
+            ia >> boost::serialization::make_nvp("value", val2);
+            BOOST_CHECK_EQUAL(val, val2);
+         }
          {
             std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
             ++test_id;
@@ -72,7 +86,7 @@ void test()
             ba << static_cast<const T&>(val);
             stream_contents = ss.str();
             boost::archive::binary_iarchive ib(ss);
-            T val2;
+            T                               val2;
             ib >> val2;
             BOOST_CHECK_EQUAL(val, val2);
          }
@@ -84,10 +98,23 @@ void test()
             oa2 << static_cast<const T&>(val);
             stream_contents = ss.str();
             boost::archive::text_iarchive ia2(ss);
-            T val2;
+            T                             val2;
             ia2 >> val2;
             BOOST_CHECK_EQUAL(val, val2);
          }
+         {
+            std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
+            ++test_id;
+            {
+               boost::archive::xml_oarchive oa2(ss);
+               oa2 << boost::serialization::make_nvp("value", static_cast<const T&>(val));
+               stream_contents = ss.str();
+            }
+            boost::archive::xml_iarchive ia2(ss);
+            T                            val2;
+            ia2 >> boost::serialization::make_nvp("value", val2);
+            BOOST_CHECK_EQUAL(val, val2);
+         }
          {
             std::stringstream ss(std::ios_base::in | std::ios_base::out | std::ios_base::binary);
             ++test_id;
@@ -95,27 +122,29 @@ void test()
             ba2 << static_cast<const T&>(val);
             stream_contents = ss.str();
             boost::archive::binary_iarchive ib2(ss);
-            T val2;
+            T                               val2;
             ib2 >> val2;
             BOOST_CHECK_EQUAL(val, val2);
          }
 #ifndef BOOST_NO_EXCEPTIONS
       }
-      catch(const boost::exception& e)
+      catch (const boost::exception& e)
       {
          std::cout << "Caught boost::exception with:\n";
          std::cout << diagnostic_information(e);
          std::cout << "Failed test ID = " << test_id << std::endl;
-         std::cout << "Stream contents were: \n" << stream_contents << std::endl;
+         std::cout << "Stream contents were: \n"
+                   << stream_contents << std::endl;
          ++boost::detail::test_errors();
          break;
       }
-      catch(const std::exception& e)
+      catch (const std::exception& e)
       {
          std::cout << "Caught std::exception with:\n";
          std::cout << e.what() << std::endl;
          std::cout << "Failed test ID = " << test_id << std::endl;
-         std::cout << "Stream contents were: \n" << stream_contents << std::endl;
+         std::cout << "Stream contents were: \n"
+                   << stream_contents << std::endl;
          ++boost::detail::test_errors();
          break;
       }
@@ -126,9 +155,9 @@ void test()
       // so don't get too close to that:
       //
 #ifndef CI_SUPPRESS_KNOWN_ISSUES
-      if(tim.elapsed() > 150)
+      if (tim.elapsed() > 150)
 #else
-      if(tim.elapsed() > 25)
+      if (tim.elapsed() > 25)
 #endif
       {
          std::cout << "Timeout reached, aborting tests now....\n";