Macros | Functions
maybeCastObj_t.cc File Reference
#include "boost/test/unit_test.hpp"
#include <string>
#include "canvas/Persistency/Common/detail/maybeCastObj.h"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (Tests of maybeCastObj interface)
 

Functions

 BOOST_AUTO_TEST_CASE (identical_types)
 
 BOOST_AUTO_TEST_CASE (mismatched_types)
 
 BOOST_AUTO_TEST_CASE (user_types)
 
 BOOST_AUTO_TEST_CASE (user_type_variables)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (Tests of maybeCastObj interface)

Definition at line 1 of file maybeCastObj_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( identical_types  )

Definition at line 74 of file maybeCastObj_t.cc.

75 {
76  // Primitive types
77  BOOST_TEST_REQUIRE((runUpcastAllowed<int, int>()));
78  BOOST_TEST_REQUIRE((runUpcastAllowed<double, double>()));
79 
80  // Std class type
81  BOOST_TEST_REQUIRE((runUpcastAllowed<std::string, std::string>()));
82 
83  // User class types
84  BOOST_TEST_REQUIRE((runUpcastAllowed<MCBase, MCBase>()));
85  BOOST_TEST_REQUIRE((runUpcastAllowed<MCConcrete, MCConcrete>()));
86 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE ( mismatched_types  )

Definition at line 88 of file maybeCastObj_t.cc.

89 {
90  // Different non-class types are never castable
91  BOOST_TEST_REQUIRE(!(runUpcastAllowed<int, double>()));
92 
93  // Can never cast primitive->class or class->primitive
94  BOOST_TEST_REQUIRE((!runUpcastAllowed<double, std::string>()));
95  BOOST_TEST_REQUIRE((!runUpcastAllowed<std::string, char>()));
96 
97  // Should not be able to cast from one user hierarchy to another
98  BOOST_TEST_REQUIRE((!runUpcastAllowed<MCConcrete, MCOtherBase>()));
99 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE ( user_types  )

Definition at line 101 of file maybeCastObj_t.cc.

102 {
103  // NB: In all of the below, tests of valid upcasts fail on
104  // Root implementation. *Possibly* due to lack of dictionary?
105  // Cast from base <-> concrete (non-virtual)
106  BOOST_TEST_REQUIRE((!runUpcastAllowed<MCBase, MCConcrete>()));
107  BOOST_TEST_REQUIRE((runUpcastAllowed<MCConcrete, MCBase>()));
108 
109  // Cast from raw base <-> concrete (virtual)
110  BOOST_TEST_REQUIRE((!runUpcastAllowed<MCBaseVirtual, MCConcreteVirtual_A>()));
111  BOOST_TEST_REQUIRE((runUpcastAllowed<MCConcreteVirtual_A, MCBaseVirtual>()));
112 
113  // Across hierarchy
115  (!runUpcastAllowed<MCConcreteVirtual_B, MCConcreteVirtual_A>()));
116 
117  // Between levels
119  (runUpcastAllowed<MCConcreteVirtual_C, MCConcreteVirtual_B>()));
120  BOOST_TEST_REQUIRE((runUpcastAllowed<MCConcreteVirtual_C, MCConcrete>()));
121 
122  // Multiple
123  BOOST_TEST_REQUIRE((runUpcastAllowed<MCConcreteMultiple, MCBase>()));
124  BOOST_TEST_REQUIRE((runUpcastAllowed<MCConcreteMultiple, MCOtherBase>()));
125 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
BOOST_AUTO_TEST_CASE ( user_type_variables  )

Definition at line 127 of file maybeCastObj_t.cc.

128 {
129  // Non Virtual
130  MCConcrete actualConcrete{};
131  MCBase& refToBase = actualConcrete;
133  (!art::detail::upcastAllowed(typeid(refToBase), typeid(MCConcrete))));
134 
135  // Virtual
136  MCConcreteVirtual_A actualConcreteVirtual{};
137  MCBaseVirtual& refToBaseVirtual = actualConcreteVirtual;
138  BOOST_TEST_REQUIRE((art::detail::upcastAllowed(typeid(refToBaseVirtual),
139  typeid(MCConcreteVirtual_A))));
141  typeid(refToBaseVirtual), typeid(MCConcreteVirtual_B))));
142 }
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
bool upcastAllowed(std::type_info const &tiFrom, std::type_info const &tiTo)