File: unlimited_storage_serialization_test.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (57 lines) | stat: -rw-r--r-- 1,881 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright 2018 Hans Dembinski
//
// 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_0.txt)

#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/histogram/serialization.hpp>
#include <boost/histogram/unlimited_storage.hpp>
#include <cassert>
#include <memory>
#include <sstream>
#include "serialization.hpp"
#include "throw_exception.hpp"

using unlimited_storage_type = boost::histogram::unlimited_storage<>;

using namespace boost::histogram;

template <typename T>
unlimited_storage_type prepare(std::size_t n, const T x) {
  std::unique_ptr<T[]> v(new T[n]);
  std::fill(v.get(), v.get() + n, static_cast<T>(0));
  v.get()[0] = x;
  return unlimited_storage_type(n, v.get());
}

template <typename T>
unlimited_storage_type prepare(std::size_t n) {
  return unlimited_storage_type(n, static_cast<T*>(nullptr));
}

template <typename T>
void run_test(const std::string& filename) {
  const auto a = prepare(1, T(1));
  print_xml(filename, a);
  unlimited_storage_type b;
  BOOST_TEST(!(a == b));
  load_xml(filename, b);
  BOOST_TEST(a == b);
}

int main(int argc, char** argv) {
  assert(argc == 2);

  run_test<uint8_t>(join(argv[1], "unlimited_storage_serialization_test_u8.xml"));
  run_test<uint16_t>(join(argv[1], "unlimited_storage_serialization_test_u16.xml"));
  run_test<uint32_t>(join(argv[1], "unlimited_storage_serialization_test_u32.xml"));
  run_test<uint64_t>(join(argv[1], "unlimited_storage_serialization_test_u64.xml"));
  run_test<unlimited_storage_type::large_int>(
      join(argv[1], "unlimited_storage_serialization_test_large_int.xml"));
  run_test<double>(join(argv[1], "unlimited_storage_serialization_test_double.xml"));

  return boost::report_errors();
}