]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/histogram/test/unlimited_storage_serialization_test.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / histogram / test / unlimited_storage_serialization_test.cpp
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 <boost/archive/text_iarchive.hpp>
8 #include <boost/archive/text_oarchive.hpp>
9 #include <boost/assert.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/histogram/serialization.hpp>
12 #include <boost/histogram/unlimited_storage.hpp>
13 #include <memory>
14 #include <sstream>
15 #include "throw_exception.hpp"
16 #include "utility_serialization.hpp"
17
18 using unlimited_storage_type = boost::histogram::unlimited_storage<>;
19
20 using namespace boost::histogram;
21
22 template <typename T>
23 unlimited_storage_type prepare(std::size_t n, const T x) {
24 std::unique_ptr<T[]> v(new T[n]);
25 std::fill(v.get(), v.get() + n, static_cast<T>(0));
26 v.get()[0] = x;
27 return unlimited_storage_type(n, v.get());
28 }
29
30 template <typename T>
31 unlimited_storage_type prepare(std::size_t n) {
32 return unlimited_storage_type(n, static_cast<T*>(nullptr));
33 }
34
35 template <typename T>
36 void run_test(const std::string& filename) {
37 const auto a = prepare(1, T(1));
38 print_xml(filename, a);
39 unlimited_storage_type b;
40 BOOST_TEST(!(a == b));
41 load_xml(filename, b);
42 BOOST_TEST(a == b);
43 }
44
45 int main(int argc, char** argv) {
46 BOOST_ASSERT(argc == 2);
47
48 run_test<uint8_t>(join(argv[1], "unlimited_storage_serialization_test_u8.xml"));
49 run_test<uint16_t>(join(argv[1], "unlimited_storage_serialization_test_u16.xml"));
50 run_test<uint32_t>(join(argv[1], "unlimited_storage_serialization_test_u32.xml"));
51 run_test<uint64_t>(join(argv[1], "unlimited_storage_serialization_test_u64.xml"));
52 run_test<unlimited_storage_type::large_int>(
53 join(argv[1], "unlimited_storage_serialization_test_large_int.xml"));
54 run_test<double>(join(argv[1], "unlimited_storage_serialization_test_double.xml"));
55
56 return boost::report_errors();
57 }