wrapper_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (Tests of Wrapper interface)
2 #include "boost/test/unit_test.hpp"
3 
7 
8 using namespace art;
9 
10 namespace {
11  InputTag const invalid{};
12 
13  template <typename T>
14  std::unique_ptr<EDProduct>
15  make_product(T&& t)
16  {
17  auto product = std::make_unique<T>(std::forward<T>(t));
18  return std::make_unique<Wrapper<T>>(std::move(product));
19  }
20 }
21 
22 BOOST_AUTO_TEST_SUITE(wrapper_t)
23 
24 BOOST_AUTO_TEST_CASE(sampled_product)
25 {
27  auto edp = w.createEmptySampledProduct(invalid);
28  BOOST_TEST_REQUIRE(edp.get());
29  BOOST_TEST(edp->isPresent());
30 
31  auto const& sampled = static_cast<Wrapper<Sampled<int>> const&>(*edp);
32  BOOST_TEST(sampled->empty());
33 }
34 
35 BOOST_AUTO_TEST_CASE(no_sampled_product_recursion)
36 {
38  BOOST_CHECK_EXCEPTION(
39  w.createEmptySampledProduct(invalid), Exception, [](auto const& e) {
40  return e.categoryCode() == errors::LogicError and
41  e.explain_self().find("recursion is not allowed") !=
42  std::string::npos;
43  });
44 }
45 
47 {
48  auto int_product = make_product(3);
49  BOOST_TEST(int_product->productSize() == "-");
50 
51  auto map_product = make_product<std::map<int, double>>({{1, 1.5}, {2, 3.}});
52  BOOST_TEST(map_product->productSize() == "2");
53 
54  struct CustomTypeWithSize {
55  size_t
56  size() const noexcept
57  {
58  return 3;
59  }
60  };
61  auto custom_product = make_product<CustomTypeWithSize>({});
62  BOOST_TEST(custom_product->productSize() == "3");
63 }
64 
65 BOOST_AUTO_TEST_SUITE_END()
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
const double e
BOOST_AUTO_TEST_CASE(sampled_product)
Definition: wrapper_t.cc:24
def move(depos, offset)
Definition: depos.py:107
std::unique_ptr< EDProduct > createEmptySampledProduct(InputTag const &tag) const
Definition: EDProduct.h:94
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66