Classes | Macros | Functions
ContainerMeta_test.cc File Reference

Unit test for some of the utilities in ContainerMeta.h More...

#include <boost/test/unit_test.hpp>
#include "larcorealg/CoreUtils/ContainerMeta.h"
#include <list>
#include <memory>
#include <functional>
#include <type_traits>

Go to the source code of this file.

Classes

struct  O
 

Macros

#define BOOST_TEST_MODULE   ( ContainerMeta_test )
 

Functions

void make_collection_reference_test ()
 
void collection_from_reference_test ()
 
 BOOST_AUTO_TEST_CASE (CollectionReferenceTestCase)
 

Detailed Description

Unit test for some of the utilities in ContainerMeta.h

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
March 25, 2019
See also
larcorealg/CoreUtils/ContainerMeta.h

Definition in file ContainerMeta_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( ContainerMeta_test )

Definition at line 10 of file ContainerMeta_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( CollectionReferenceTestCase  )

Definition at line 253 of file ContainerMeta_test.cc.

253  {
256 } // BOOST_AUTO_TEST_CASE(CollectionReferenceTestCase)
void collection_from_reference_test()
void make_collection_reference_test()
void collection_from_reference_test ( )

Definition at line 182 of file ContainerMeta_test.cc.

182  {
183 
184  constexpr std::size_t Size = 10U;
185 
186  // BUG the double brace syntax is required to work around clang bug 21629
187  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
188  std::list<O> list {{ O{} }};
189  std::list<O> & ref = list;
190  std::list<O> const& cref = list;
191  auto refw = std::ref(list);
192  auto crefw = std::cref(list);
193 
194  O array [Size];
195  O* ptr = array;
196  O const* cptr = ptr;
197 
198  auto const uptr = std::unique_ptr<O>(new O[Size]);
199  auto array_uptr = std::unique_ptr<O[Size]>();
200  auto const array_uptrc = std::unique_ptr<O[Size]>();
201  auto garray_uptr = std::unique_ptr<O[]>(new O[Size]);
202 
203  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(list )>, decltype(ref )>);
204  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(ref )>, decltype(ref )>);
205  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(cref )>, decltype(cref)>);
206  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(refw )>, decltype(ref )>);
207  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(crefw )>, decltype(cref)>);
208 
209  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(array )>, O * >);
210  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(ptr )>, O * >);
211  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(cptr )>, O const* >);
212 
213  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(uptr )>, O * >);
214  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(array_uptr )>, O(*)[Size] >);
215  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(array_uptrc)>, O(*)[Size] >);
216  static_assert(std::is_same_v<util::collection_from_reference_t<decltype(garray_uptr)>, O * >);
217 
218  static_assert(std::is_same_v<decltype(util::collection_from_reference(list )), decltype(ref )>);
219  static_assert(std::is_same_v<decltype(util::collection_from_reference(ref )), decltype(ref )>);
220  static_assert(std::is_same_v<decltype(util::collection_from_reference(cref )), decltype(cref)>);
221  static_assert(std::is_same_v<decltype(util::collection_from_reference(refw )), decltype(ref )>);
222  static_assert(std::is_same_v<decltype(util::collection_from_reference(crefw )), decltype(cref)>);
223 
224  static_assert(std::is_same_v<decltype(util::collection_from_reference(array )), O * >);
225  static_assert(std::is_same_v<decltype(util::collection_from_reference(ptr )), O * >);
226  static_assert(std::is_same_v<decltype(util::collection_from_reference(cptr )), O const* >);
227 
228  static_assert(std::is_same_v<decltype(util::collection_from_reference(uptr )), O * >);
229  static_assert(std::is_same_v<decltype(util::collection_from_reference(array_uptr )), O(*)[Size] >);
230  static_assert(std::is_same_v<decltype(util::collection_from_reference(array_uptrc)), O(*)[Size] >);
231  static_assert(std::is_same_v<decltype(util::collection_from_reference(garray_uptr)), O * >);
232 
233  BOOST_TEST(&util::collection_from_reference(list ) == &list );
234  BOOST_TEST(&util::collection_from_reference(ref ) == &list );
235  BOOST_TEST(&util::collection_from_reference(cref ) == &list );
236  BOOST_TEST(&util::collection_from_reference(refw ) == &list );
237  BOOST_TEST(&util::collection_from_reference(crefw ) == &list );
238 
239  BOOST_TEST( util::collection_from_reference(array ) == array );
240  BOOST_TEST( util::collection_from_reference(ptr ) == ptr );
241  BOOST_TEST( util::collection_from_reference(cptr ) == cptr );
242 
243  BOOST_TEST( util::collection_from_reference(uptr ) == uptr.get() );
244  BOOST_TEST( util::collection_from_reference(array_uptr ) == array_uptr.get() );
245  BOOST_TEST( util::collection_from_reference(array_uptrc) == array_uptrc.get());
246  BOOST_TEST( util::collection_from_reference(garray_uptr) == garray_uptr.get());
247 
248 } // collection_from_reference_test()
typename collection_from_reference_type< Cont >::type collection_from_reference_t
Type contained in util::collection_from_reference_type trait.
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228
decltype(auto) collection_from_reference(CollRef &collRef)
Returns the object referenced by collRef as a C++ reference.
void make_collection_reference_test ( )

Definition at line 131 of file ContainerMeta_test.cc.

131  {
132 
133  /*
134  * `std::unique_ptr<T[N]>` is a strange beast which really deals with pointers
135  * to whole C arrays (`T(*)[N]`).
136  * It should be understood that this is not the same as `T*`
137  */
138  constexpr std::size_t Size = 10U;
139 
140  // BUG the double brace syntax is required to work around clang bug 21629
141  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
142  std::list<O> list {{ O{} }};
143  O array [Size];
144  O* ptr = array;
145  O const* cptr = ptr;
146  O const* const cptrc = ptr;
147  O const* const& cptrcr = cptrc;
148  auto refw = std::ref(list);
149  auto crefw = std::cref(list);
150  auto const uptr = std::unique_ptr<O>(new O[Size]);
151  auto array_uptr = std::unique_ptr<O[Size]>();
152  auto garray_uptr = std::unique_ptr<O[]>(new O[Size]);
153 
154  static_assert(std::is_same_v<decltype(util::make_collection_reference(list )), decltype(std::ref(list))>);
155  static_assert(std::is_same_v<decltype(util::make_collection_reference(array )), decltype(ptr )>);
156  static_assert(std::is_same_v<decltype(util::make_collection_reference(ptr )), decltype(ptr )>);
157  static_assert(std::is_same_v<decltype(util::make_collection_reference(cptr )), decltype(cptr )>);
158  static_assert(std::is_same_v<decltype(util::make_collection_reference(cptrc )), decltype(cptr )>);
159  static_assert(std::is_same_v<decltype(util::make_collection_reference(cptrcr )), decltype(cptr )>);
160  static_assert(std::is_same_v<decltype(util::make_collection_reference(refw )), decltype(refw )>);
161  static_assert(std::is_same_v<decltype(util::make_collection_reference(crefw )), decltype(crefw )>);
162  static_assert(std::is_same_v<decltype(util::make_collection_reference(uptr )), decltype(ptr )>);
163  static_assert(std::is_same_v<decltype(util::make_collection_reference(array_uptr )), decltype(&array )>);
164  static_assert(std::is_same_v<decltype(util::make_collection_reference(garray_uptr)), decltype(ptr )>);
165 
166  BOOST_TEST(&(util::make_collection_reference(list ).get().front()) == &list.front() );
167  BOOST_TEST(&(util::make_collection_reference(array )[0] ) == &array[0] );
168  BOOST_TEST(&(util::make_collection_reference(ptr )[0] ) == ptr );
169  BOOST_TEST(&(util::make_collection_reference(cptr )[0] ) == cptr );
170  BOOST_TEST(&(util::make_collection_reference(cptrc )[0] ) == cptr );
171  BOOST_TEST(&(util::make_collection_reference(cptrcr )[0] ) == cptr );
172  BOOST_TEST(&(util::make_collection_reference(refw ).get().front()) == &list.front() );
173  BOOST_TEST(&(util::make_collection_reference(crefw ).get().front()) == &list.front() );
174  BOOST_TEST(&(util::make_collection_reference(uptr )[0] ) == uptr.get() );
175  BOOST_TEST(&(util::make_collection_reference(array_uptr )[0] ) == array_uptr.get() );
176  BOOST_TEST(&(util::make_collection_reference(garray_uptr)[0] ) == garray_uptr.get() );
177 
178 } // make_collection_reference_test()
auto make_collection_reference(Coll &&coll)
Returns an object referencing to the data contained in coll.
auto array(Array const &a)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:228