Classes | Namespaces | Macros | Functions
value_ptr_test.cc File Reference
#include "boost/test/unit_test.hpp"
#include <ostream>
#include <string>
#include "cetlib/value_ptr.h"

Go to the source code of this file.

Classes

struct  Base
 
struct  Derived
 

Namespaces

 cet
 

Macros

#define BOOST_TEST_MODULE   (value_ptr test)
 

Functions

std::ostream & cet::boost_test_print_type (std::ostream &os, value_ptr< int > const p)
 
 BOOST_AUTO_TEST_CASE (nullptr_test)
 
 BOOST_AUTO_TEST_CASE (basic_test)
 
 BOOST_AUTO_TEST_CASE (compile_failure_test)
 
 BOOST_AUTO_TEST_CASE (polymorphism_test)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (value_ptr test)

Definition at line 7 of file value_ptr_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( nullptr_test  )

Definition at line 45 of file value_ptr_test.cc.

46 {
48  BOOST_TEST(!p);
49  BOOST_TEST(p == nullptr);
50  BOOST_TEST(nullptr == p);
51 }
p
Definition: test.py:223
BOOST_AUTO_TEST_CASE ( basic_test  )

Definition at line 53 of file value_ptr_test.cc.

54 {
55  value_ptr<int> p(new int(16));
56  BOOST_TEST(static_cast<bool>(p));
57  BOOST_TEST(*p == 16);
58 
59  int* p_addr = p.get();
60  value_ptr<int> q(p);
61  BOOST_TEST(*p == *q);
62  BOOST_TEST(p != q);
63  BOOST_TEST(p_addr != q.get());
64 
65  p.reset(new int(0));
66  BOOST_TEST(*p == 0);
67  BOOST_TEST(p_addr != p.get());
68 }
p
Definition: test.py:223
BOOST_AUTO_TEST_CASE ( compile_failure_test  )

Definition at line 70 of file value_ptr_test.cc.

71 {
72 #if 0
73  value_ptr<double> p( new int(16) ); // unrelated types
74  value_ptr<Base> b( new Derived ); // polymorphic, but no clone()
75  value_ptr<Derived> d( new Base ); // no conversion in this direction
76 #endif
77 }
p
Definition: test.py:223
static bool * b
Definition: config.cpp:1043
BOOST_AUTO_TEST_CASE ( polymorphism_test  )

Definition at line 79 of file value_ptr_test.cc.

80 {
82  BOOST_TEST(bool(b));
83  BOOST_TEST(b->who() == std::string("Base"));
84 
85  value_ptr<Base, default_copy<Base> // request slicing
86  >
87  d(new Derived);
88  BOOST_TEST(bool(d));
89  BOOST_TEST(d->who() == std::string("Derived"));
90 }
std::string string
Definition: nybbler.cc:12
static bool * b
Definition: config.cpp:1043