Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / histogram / test / axis_variant_serialization_test.cpp
1 // Copyright (c) 2019 Hans Dembinski
2 //
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt
5 // or copy at http://www.boost.org/LICENSE_1_0.txt)
6
7 // This test is inspired by the corresponding boost/beast test of detail_variant.
8
9 #include <boost/assert.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/histogram/axis/integer.hpp>
12 #include <boost/histogram/axis/ostream.hpp>
13 #include <boost/histogram/axis/regular.hpp>
14 #include <boost/histogram/axis/variant.hpp>
15 #include <boost/histogram/serialization.hpp>
16 #include "throw_exception.hpp"
17 #include "utility_axis.hpp"
18 #include "utility_serialization.hpp"
19
20 using namespace boost::histogram::axis;
21
22 int main(int argc, char** argv) {
23   BOOST_ASSERT(argc == 2);
24
25   const auto filename = join(argv[1], "axis_variant_serialization_test.xml");
26
27   using R = regular<>;
28   using I = integer<>;
29
30   variant<I, R> a(I(0, 3));
31   variant<I, R> b(R(1, 0, 1));
32   print_xml(filename, b);
33   BOOST_TEST_NE(a, b);
34   load_xml(filename, a);
35   BOOST_TEST_EQ(a, b);
36
37   variant<I> c; // load incompatible version
38   BOOST_TEST_THROWS(load_xml(filename, c), std::runtime_error);
39
40   return boost::report_errors();
41 }