utility_test.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 <boost/core/lightweight_test.hpp>
  7. #include "throw_exception.hpp"
  8. #include <sstream>
  9. #include <tuple>
  10. #include <vector>
  11. #include "utility_allocator.hpp"
  12. #include "std_ostream.hpp"
  13. using namespace boost::histogram;
  14. int main() {
  15. // vector streaming
  16. {
  17. std::ostringstream os;
  18. std::vector<int> v = {1, 3, 2};
  19. os << v;
  20. BOOST_TEST_EQ(os.str(), std::string("[ 1 3 2 ]"));
  21. }
  22. // tuple streaming
  23. {
  24. std::ostringstream os;
  25. auto v = std::make_tuple(1, 2.5, "hi");
  26. os << v;
  27. BOOST_TEST_EQ(os.str(), std::string("[ 1 2.5 hi ]"));
  28. }
  29. // tracing_allocator
  30. {
  31. tracing_allocator_db db;
  32. tracing_allocator<char> a(db);
  33. auto p1 = a.allocate(2);
  34. a.deallocate(p1, 2);
  35. tracing_allocator<int> b(a);
  36. auto p2 = b.allocate(3);
  37. b.deallocate(p2, 3);
  38. BOOST_TEST_EQ(db.size(), 2);
  39. BOOST_TEST_EQ(db.at<char>().first, 0);
  40. BOOST_TEST_EQ(db.at<char>().second, 2);
  41. BOOST_TEST_EQ(db.at<int>().first, 0);
  42. BOOST_TEST_EQ(db.at<int>().second, 3);
  43. BOOST_TEST_EQ(db.first, 0);
  44. BOOST_TEST_EQ(db.second, 2 + 3 * sizeof(int));
  45. }
  46. return boost::report_errors();
  47. }