axis_variant_serialization_test.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // This test is inspired by the corresponding boost/beast test of detail_variant.
  7. #include <boost/assert.hpp>
  8. #include <boost/core/lightweight_test.hpp>
  9. #include <boost/histogram/axis/integer.hpp>
  10. #include <boost/histogram/axis/ostream.hpp>
  11. #include <boost/histogram/axis/regular.hpp>
  12. #include <boost/histogram/axis/variant.hpp>
  13. #include <boost/histogram/serialization.hpp>
  14. #include "throw_exception.hpp"
  15. #include "utility_axis.hpp"
  16. #include "utility_serialization.hpp"
  17. using namespace boost::histogram::axis;
  18. int main(int argc, char** argv) {
  19. BOOST_ASSERT(argc == 2);
  20. const auto filename = join(argv[1], "axis_variant_serialization_test.xml");
  21. using R = regular<>;
  22. using I = integer<>;
  23. variant<I, R> a(I(0, 3));
  24. variant<I, R> b(R(1, 0, 1));
  25. print_xml(filename, b);
  26. BOOST_TEST_NE(a, b);
  27. load_xml(filename, a);
  28. BOOST_TEST_EQ(a, b);
  29. variant<I> c; // load incompatible version
  30. BOOST_TEST_THROWS(load_xml(filename, c), std::runtime_error);
  31. return boost::report_errors();
  32. }