Macros | Functions
maybe_ref_test.cc File Reference
#include "boost/test/unit_test.hpp"
#include "cetlib/maybe_ref.h"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (maybe_ref test)
 

Functions

 BOOST_AUTO_TEST_CASE (default_behavior)
 
 BOOST_AUTO_TEST_CASE (copy_behavior)
 
 BOOST_AUTO_TEST_CASE (const_behavior)
 
 BOOST_AUTO_TEST_CASE (reseat_behavior)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (maybe_ref test)

Definition at line 1 of file maybe_ref_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( default_behavior  )

Definition at line 8 of file maybe_ref_test.cc.

9 {
10  {
11  typedef int T;
12  T x = 16;
14  BOOST_TEST(m.isValid());
15  BOOST_TEST(m.ref() == 16);
16  T& r = m.ref();
17  BOOST_TEST(r == x);
18  BOOST_TEST(&r == &x);
19  T const& r2 = m.ref();
20  BOOST_TEST(m.ref() == 16);
21  BOOST_TEST(r2 == x);
22  BOOST_TEST(&r2 == &x);
23  }
24  {
25  typedef double T;
27  BOOST_TEST(!m.isValid());
28  BOOST_CHECK_THROW(m.ref(), std::logic_error);
29  }
30 }
bool isValid() const
Definition: maybe_ref.h:60
list x
Definition: train.py:276
BOOST_AUTO_TEST_CASE ( copy_behavior  )

Definition at line 32 of file maybe_ref_test.cc.

33 {
34  {
35  typedef unsigned T;
36  T x = 16u;
38  BOOST_TEST(m.isValid());
39  BOOST_TEST(m.ref() == 16u);
41  BOOST_TEST(m2.isValid());
42  BOOST_TEST(m2.ref() == 16u);
43  }
44  {
45  typedef long T;
46  T x = 16;
48  BOOST_TEST(m.isValid());
49  BOOST_TEST(m.ref() == 16);
51  BOOST_TEST(!m2.isValid());
52  m2 = m;
53  BOOST_TEST(m2.isValid());
54  BOOST_TEST(m2.ref() == 16);
55  }
56 }
static constexpr double m2
Definition: Units.h:72
list x
Definition: train.py:276
BOOST_AUTO_TEST_CASE ( const_behavior  )

Definition at line 58 of file maybe_ref_test.cc.

59 {
60  {
61  typedef int const T;
62  T x = 16;
64  BOOST_TEST(m.isValid());
65  T& r = m.ref();
66  BOOST_TEST(r == x);
67  BOOST_TEST(&r == &x);
68  }
69 }
list x
Definition: train.py:276
BOOST_AUTO_TEST_CASE ( reseat_behavior  )

Definition at line 71 of file maybe_ref_test.cc.

72 {
73  {
74  typedef int const T;
75  T x = 16;
76  T y = 48;
78  BOOST_TEST(m.isValid());
79  BOOST_TEST(m.ref() == 16);
80  BOOST_TEST(&m.ref() == &x);
81  m.reseat();
82  BOOST_TEST(!m.isValid());
83  m.reseat(y);
84  BOOST_TEST(m.isValid());
85  BOOST_TEST(m.ref() == 48);
86  BOOST_TEST(&m.ref() == &y);
87  }
88 }
list x
Definition: train.py:276