storage_adaptor_serialization_test.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2018 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. #include <array>
  7. #include <boost/assert.hpp>
  8. #include <boost/core/lightweight_test.hpp>
  9. #include <boost/histogram/accumulators/thread_safe.hpp>
  10. #include <boost/histogram/serialization.hpp>
  11. #include <boost/histogram/storage_adaptor.hpp>
  12. #include <map>
  13. #include <vector>
  14. #include "throw_exception.hpp"
  15. #include "utility_serialization.hpp"
  16. using namespace boost::histogram;
  17. template <typename T>
  18. void test_serialization(const std::string& filename) {
  19. auto a = storage_adaptor<T>();
  20. a.reset(3);
  21. a[1] += 1;
  22. a[2] += 2;
  23. print_xml(filename, a);
  24. auto b = storage_adaptor<T>();
  25. BOOST_TEST_NOT(a == b);
  26. load_xml(filename, b);
  27. BOOST_TEST(a == b);
  28. }
  29. int main(int argc, char** argv) {
  30. BOOST_ASSERT(argc == 2);
  31. test_serialization<std::vector<int>>(
  32. join(argv[1], "storage_adaptor_serialization_test_vector_int.xml"));
  33. test_serialization<std::array<unsigned, 10>>(
  34. join(argv[1], "storage_adaptor_serialization_test_array_unsigned.xml"));
  35. test_serialization<std::map<std::size_t, double>>(
  36. join(argv[1], "storage_adaptor_serialization_test_map_double.xml"));
  37. test_serialization<std::vector<accumulators::thread_safe<int>>>(
  38. join(argv[1], "storage_adaptor_serialization_test_vector_thread_safe_int.xml"));
  39. return boost::report_errors();
  40. }