ensurePointer_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE(ensurePointer_t)
2 #include "boost/test/unit_test.hpp"
3 
5 
6 #include <vector>
7 
8 struct A {
9  virtual ~A() {}
10 };
11 struct B : A {};
12 
13 typedef std::vector<A> avec_t;
14 typedef std::vector<A*> apvec_t;
15 typedef std::vector<A const*> acpvec_t;
16 typedef std::vector<B> bvec_t;
17 typedef std::vector<B*> bpvec_t;
18 typedef std::vector<B const*> bcpvec_t;
19 typedef std::vector<int> ivec_t;
20 typedef std::vector<int*> ipvec_t;
21 typedef std::vector<int const*> icpvec_t;
22 
23 BOOST_AUTO_TEST_SUITE(ensurePointer_t)
24 
25 // Check basic type handling.
27 {
28  ivec_t i(1);
29  BOOST_CHECK_NO_THROW(art::ensurePointer<int*>(i.begin()));
30  ivec_t const ic(1);
31  BOOST_CHECK_NO_THROW(art::ensurePointer<int const*>(ic.begin()));
32  ipvec_t ip(1);
33  BOOST_CHECK_NO_THROW(art::ensurePointer<int*>(ip.begin()));
34  icpvec_t icp(1);
35  BOOST_CHECK_NO_THROW(art::ensurePointer<int const*>(icp.begin()));
36 }
37 
38 // No constness.
39 BOOST_AUTO_TEST_CASE(a_pointer_from_a)
40 {
41  avec_t a(1);
42  BOOST_CHECK_NO_THROW(art::ensurePointer<A*>(a.begin()));
43 }
44 
45 BOOST_AUTO_TEST_CASE(a_pointer_from_a_pointer)
46 {
47  apvec_t a(1);
48  BOOST_CHECK_NO_THROW(art::ensurePointer<A*>(a.begin()));
49 }
50 
51 BOOST_AUTO_TEST_CASE(a_pointer_from_b)
52 {
53  bvec_t b(1);
54  BOOST_CHECK_NO_THROW(art::ensurePointer<A*>(b.begin()));
55 }
56 
57 BOOST_AUTO_TEST_CASE(a_pointer_from_b_pointer)
58 {
59  bpvec_t b(1);
60  BOOST_CHECK_NO_THROW(art::ensurePointer<A*>(b.begin()));
61 }
62 
63 BOOST_AUTO_TEST_CASE(b_pointer_from_a_pointer)
64 {
65  apvec_t a;
66  std::unique_ptr<B> bp(new B);
67  std::unique_ptr<A> ap(new A);
68  a.push_back(bp.get());
69  a.push_back(ap.get());
70  BOOST_CHECK_NO_THROW(art::ensurePointer<B*>(a.begin()));
71  BOOST_CHECK_THROW(art::ensurePointer<B*>(a.begin() + 1), art::Exception);
72 }
73 
74 // const from const.
75 BOOST_AUTO_TEST_CASE(const_a_pointer_from_const_a)
76 {
77  avec_t const a(1);
78  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(a.begin()));
79 }
80 
81 BOOST_AUTO_TEST_CASE(const_a_pointer_from_const_a_pointer)
82 {
83  acpvec_t a(1);
84  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(a.begin()));
85 }
86 
87 BOOST_AUTO_TEST_CASE(const_a_pointer_from_const_b)
88 {
89  bvec_t const b(1);
90  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(b.begin()));
91 }
92 
93 BOOST_AUTO_TEST_CASE(const_a_pointer_from_const_b_pointer)
94 {
95  bcpvec_t b(1);
96  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(b.begin()));
97 }
98 
99 BOOST_AUTO_TEST_CASE(const_b_pointer_from_const_a_pointer)
100 {
101  acpvec_t a;
102  std::unique_ptr<B> bp(new B);
103  std::unique_ptr<A> ap(new A);
104  a.push_back(bp.get());
105  a.push_back(ap.get());
106  BOOST_CHECK_NO_THROW(art::ensurePointer<B const*>(a.begin()));
107  BOOST_CHECK_THROW(art::ensurePointer<B const*>(a.begin() + 1),
109 }
110 
111 // const from non-const.
112 BOOST_AUTO_TEST_CASE(const_a_pointer_from_a)
113 {
114  avec_t a(1);
115  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(a.begin()));
116 }
117 
118 BOOST_AUTO_TEST_CASE(const_a_pointer_from_a_pointer)
119 {
120  apvec_t a(1);
121  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(a.begin()));
122 }
123 
124 BOOST_AUTO_TEST_CASE(const_a_pointer_from_b)
125 {
126  bvec_t b(1);
127  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(b.begin()));
128 }
129 
130 BOOST_AUTO_TEST_CASE(const_a_pointer_from_b_pointer)
131 {
132  bpvec_t b(1);
133  BOOST_CHECK_NO_THROW(art::ensurePointer<A const*>(b.begin()));
134 }
135 
136 BOOST_AUTO_TEST_CASE(const_b_pointer_from_a_pointer)
137 {
138  apvec_t a;
139  std::unique_ptr<B> bp(new B);
140  std::unique_ptr<A> ap(new A);
141  a.push_back(bp.get());
142  a.push_back(ap.get());
143  BOOST_CHECK_NO_THROW(art::ensurePointer<B const*>(a.begin()));
144  BOOST_CHECK_THROW(art::ensurePointer<B const*>(a.begin() + 1),
146 }
147 
148 // Assume volatility works the same way.
149 
150 BOOST_AUTO_TEST_SUITE_END()
std::vector< A * > apvec_t
std::vector< B > bvec_t
std::vector< A > avec_t
std::vector< int const * > icpvec_t
std::vector< int > ivec_t
const double a
BOOST_AUTO_TEST_CASE(basic_types)
std::vector< int * > ipvec_t
std::vector< B * > bpvec_t
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
std::vector< B const * > bcpvec_t
virtual ~A()
static bool * b
Definition: config.cpp:1043
std::vector< A const * > acpvec_t