All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Namespaces | Macros | Functions | Variables
ProviderList_test.cc File Reference

Unit test for ProviderList.h. More...

#include "larcorealg/TestUtils/ProviderList.h"
#include <boost/test/unit_test.hpp>
#include <set>
#include <memory>

Go to the source code of this file.

Classes

struct  NormalDatumClass
 
struct  UncopiableDatumClass
 
struct  UnmovableDatumClass
 
struct  PinnedDatumClassBase
 
struct  PinnedDatumClass
 

Namespaces

 testing
 LArSoft test utilities.
 

Macros

#define BOOST_TEST_MODULE   ProviderList_test
 

Functions

template<>
std::unique_ptr
< UnmovableDatumClass
testing::setupProvider< UnmovableDatumClass > ()
 
template<typename T , typename LIST >
void TestElement (LIST &l, std::string label="", bool present=true)
 
template<typename LIST >
void TestBase (LIST &l)
 
void ConstTest (testing::ProviderList const &l)
 
void NonConstTest (testing::ProviderList &l)
 
 BOOST_AUTO_TEST_CASE (ProviderListTest)
 

Variables

std::set< void * > TrackedMemory
 

Detailed Description

Unit test for ProviderList.h.

Date
April 22nd, 2016
Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
See Also
ProviderList.h

This test does not take any argument.

Definition in file ProviderList_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ProviderList_test

Definition at line 17 of file ProviderList_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( ProviderListTest  )

Definition at line 186 of file ProviderList_test.cc.

187 {
188  BOOST_TEST_MESSAGE("Construction and instantiation of ProviderList");
189  auto l = std::make_unique<testing::ProviderList>();
190 
191  BOOST_TEST(l->setup<NormalDatumClass>(12));
192  BOOST_TEST(l->setup_instance<UncopiableDatumClass>("One", "uncopiable"));
193  BOOST_TEST(l->setup<UnmovableDatumClass>());
194  BOOST_TEST
195  (l->custom_setup<PinnedDatumClass>(&PinnedDatumClass::New, 1.0, 0.0));
196  BOOST_TEST((l->set_alias<PinnedDatumClass, PinnedDatumClassBase>()));
197 
198  // second creation shoudl fail
199  BOOST_TEST(!l->setup_instance<UncopiableDatumClass>("One", "uncopiableII"));
200 
201  BOOST_TEST_MESSAGE("Constant list test");
202  ConstTest(*l);
203  BOOST_TEST_MESSAGE("Mutable list test");
204  NonConstTest(*l);
205 
206  BOOST_TEST_MESSAGE("ProviderListTest completed");
207 
208  // make sure that we did not leak anything
209  l.reset();
210  BOOST_TEST(TrackedMemory.empty());
211 
212  // check that we noticed a single call for a custom setup
213  BOOST_TEST(PinnedDatumClass::nNewCalls == 1U);
214 
215 } // BOOST_AUTO_TEST_CASE(ProviderListTest)
static std::unique_ptr< PinnedDatumClass > New(float x, float y)
void ConstTest(testing::ProviderList const &l)
static unsigned int nNewCalls
std::set< void * > TrackedMemory
void NonConstTest(testing::ProviderList &l)
void ConstTest ( testing::ProviderList const &  l)

Definition at line 154 of file ProviderList_test.cc.

154 { TestBase(l); }
void TestBase(LIST &l)
void NonConstTest ( testing::ProviderList l)

Definition at line 155 of file ProviderList_test.cc.

155  {
156  TestBase(l);
157 
158  // check that no "Acquired" is available yet
159  TestElement<UncopiableDatumClass>(l, "Acquired", false);
160 
161  // acquire a new one
162  BOOST_TEST(
163  l.acquire(std::make_unique<UncopiableDatumClass>
164  ("another uncopiable"), "Acquired")
165  );
166  TestElement<UncopiableDatumClass>(l, "Acquired", true);
167 
168  // erase it
169  BOOST_TEST(l.erase<UncopiableDatumClass>("Acquired"));
170  TestElement<UncopiableDatumClass>(l, "Acquired", false);
171 
172  // erase it again
173  BOOST_TEST(!l.erase<UncopiableDatumClass>("Acquired"));
174  TestElement<UncopiableDatumClass>(l, "Acquired", false);
175 
176  // erase something that was never there
177  BOOST_TEST(!l.erase<UncopiableDatumClass>("Never"));
178  TestElement<UncopiableDatumClass>(l, "Never", false);
179 
180 } // NonConstTest()
void TestBase(LIST &l)
template<typename LIST >
void TestBase ( LIST &  l)

Definition at line 137 of file ProviderList_test.cc.

137  {
138 
139  TestElement<NormalDatumClass>(l);
140  TestElement<UncopiableDatumClass>(l, "", false); // empty label not present
141  TestElement<UncopiableDatumClass>(l, "One"); // label "One" present
142  TestElement<UncopiableDatumClass>(l, "Two", false); // label "Two" not there
143  TestElement<UnmovableDatumClass>(l);
144  TestElement<PinnedDatumClass>(l);
145  TestElement<PinnedDatumClassBase>(l);
146  TestElement<int>(l, "", false); // no int present
147 
148  // test that the polymorphism is preserved by aliases
149  BOOST_TEST(!l.template get<PinnedDatumClassBase>().abstract());
150 
151 } // TestBase()
template<typename T , typename LIST >
void TestElement ( LIST &  l,
std::string  label = "",
bool  present = true 
)

Definition at line 118 of file ProviderList_test.cc.

118  {
119 
120  BOOST_TEST_MESSAGE("Testing class '" << typeid(T).name() << "' label \""
121  << label << "\" (" << (present? "present": "not present") << ")" );
122  BOOST_TEST(l.template known<T>(label) == present);
123  BOOST_TEST(l.template valid<T>(label) == present);
124  try {
125  auto const& item = l.template get<T>(label);
126  BOOST_TEST(present); // if not present, we should not be here!
127  BOOST_TEST(&item);
128  }
130  BOOST_TEST(!present); // if present, we should not be here!
131  }
132 
133 } // TestElement()
Exception thrown on a request about an unregistered type.
Definition: ProviderList.h:184
do i e
then echo fcl name

Variable Documentation

std::set<void*> TrackedMemory

Definition at line 27 of file ProviderList_test.cc.