Classes | Macros | Functions
Dereference_test.cc File Reference

Test for Dereference.h utilities. More...

#include <type_traits>
#include <memory>
#include "boost/test/unit_test.hpp"
#include "lardata/Utilities/Dereference.h"

Go to the source code of this file.

Classes

struct  MyPtr< T >
 

Macros

#define BOOST_TEST_MODULE   ( StatCollector_test )
 

Functions

template<typename T >
void test ()
 
 BOOST_AUTO_TEST_CASE (TestInt)
 
 BOOST_AUTO_TEST_CASE (TestConstInt)
 

Detailed Description

Test for Dereference.h utilities.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
January 23rd, 2015

A static test is performed to verify that the compilation succeeds with the types int, int*, unique_ptr<int> and a custom smart pointer to int.

Definition in file Dereference_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( StatCollector_test )

Definition at line 25 of file Dereference_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( TestInt  )

Definition at line 202 of file Dereference_test.cc.

202  {
203  test<int>();
204 }
BOOST_AUTO_TEST_CASE ( TestConstInt  )

Definition at line 206 of file Dereference_test.cc.

206  {
207  test<const int>();
208 }
template<typename T >
void test ( )

Definition at line 176 of file Dereference_test.cc.

176  {
177 
178  T value = T(17);
179  T* cptr = &value;
180  MyPtr<T> my_ptr(&value);
181  auto uptr = std::make_unique<T>(value);
182 
183  T* ptr;
184  ptr = lar::util::make_pointer(uptr);
185  BOOST_TEST(*ptr == value);
186  ptr = lar::util::make_pointer(my_ptr);
187  BOOST_TEST(*ptr == value);
188  ptr = lar::util::make_pointer(cptr);
189  BOOST_TEST(*ptr == value);
190  ptr = lar::util::make_pointer(value);
191  BOOST_TEST(*ptr == value);
192 
193  BOOST_TEST(lar::util::dereference(uptr) == value);
194  BOOST_TEST(lar::util::dereference(my_ptr) == value);
195  BOOST_TEST(lar::util::dereference(cptr) == value);
196  BOOST_TEST(lar::util::dereference(value) == value);
197 
198 } // test<>()
details::make_pointer_class< T, details::has_dereference_class< T >::value >::pointer_type make_pointer(T &v)
Returns a pointer to the value of argument, or the argument itself.
Definition: Dereference.h:293
details::dereference_class< T, details::has_dereference_class< T >::value >::reference_type dereference(T &v)
Returns the value pointed by the argument, or the argument itself.
Definition: Dereference.h:254