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