pointersEqual_t.cc
Go to the documentation of this file.
1 // Test of pointersEqual
2 #define BOOST_TEST_MODULE (pointersEqual_t)
3 #include "boost/test/unit_test.hpp"
4 
6 BOOST_AUTO_TEST_SUITE(pointersEqual_t)
7 
8 class A {};
9 class B {};
10 class C : public A, public B {};
11 struct D : public C {};
12 class E : public A {};
13 
15 {
16  int i = 3;
17  int j = 3;
18  int* ip1 = &i;
19  int* ip2 = &i;
20  double p = i;
21  BOOST_TEST(art::pointersEqual(ip1, ip2));
22  BOOST_TEST(art::pointersEqual(&i, ip1));
23  BOOST_TEST(art::pointersEqual(&i, ip2));
24  BOOST_CHECK_THROW(art::pointersEqual(&i, &p), art::Exception);
25  BOOST_TEST(!art::pointersEqual(&i, &j));
26 }
27 
29 {
30  D d1;
31  D* pd1d1(&d1);
32  D* pd1d2(&d1);
33  A* pd1a1(&d1);
34  B* pd1b1(&d1);
35  D d2;
36  A a1;
37  B b1;
38  E e1;
39  BOOST_TEST(art::pointersEqual(pd1d1, pd1d2));
40  BOOST_TEST(art::pointersEqual(pd1d1, pd1a1));
41  BOOST_TEST(art::pointersEqual(pd1d1, pd1b1));
42  BOOST_CHECK_THROW(art::pointersEqual(pd1a1, pd1b1), art::Exception);
43  BOOST_CHECK_THROW(art::pointersEqual(&a1, &b1), art::Exception);
44  BOOST_TEST(!art::pointersEqual(pd1a1, &a1));
45  BOOST_TEST(!art::pointersEqual(pd1a1, &e1));
46  BOOST_TEST(!art::pointersEqual(&d1, &d2));
47 }
48 
50 {
51  D d1;
52  A const* da1(&d1);
53  BOOST_TEST(art::pointersEqual(&d1, da1));
54 }
55 
56 BOOST_AUTO_TEST_SUITE_END()
std::enable_if_t< std::is_same< T1, T2 >::value||std::is_base_of< T1, T2 >::value||std::is_base_of< T2, T1 >::value, bool > pointersEqual(T1 *t1, T2 *t2)
Definition: pointersEqual.h:15
p
Definition: test.py:223
BOOST_AUTO_TEST_CASE(basic_types)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
#define a1