Classes | Namespaces | Macros | Functions | Variables
ProviderList_test.cc File Reference
#include "TestUtils/ProviderList.h"
#include <cetlib/quiet_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< UnmovableDatumClasstesting::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
 

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_CHECK(l->setup<NormalDatumClass>(12));
192  BOOST_CHECK(l->setup_instance<UncopiableDatumClass>("One", "uncopiable"));
193  BOOST_CHECK(l->setup<UnmovableDatumClass>());
194  BOOST_CHECK
195  (l->custom_setup<PinnedDatumClass>(&PinnedDatumClass::New, 1.0, 0.0));
196  BOOST_CHECK((l->set_alias<PinnedDatumClass, PinnedDatumClassBase>()));
197 
198  // second creation shoudl fail
199  BOOST_CHECK(!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_CHECK(TrackedMemory.empty());
211 
212  // check that we noticed a single call for a custom setup
213  BOOST_CHECK_EQUAL(PinnedDatumClass::nNewCalls, 1U);
214 
215 } // BOOST_AUTO_TEST_CASE(ProviderListTest)
static std::unique_ptr< PinnedDatumClass > New(float x, float y)
static QStrList * l
Definition: config.cpp:1044
std::set< void * > TrackedMemory
static unsigned int nNewCalls
void NonConstTest(testing::ProviderList &l)
void ConstTest(testing::ProviderList const &l)
void ConstTest ( testing::ProviderList const &  l)

Definition at line 154 of file ProviderList_test.cc.

154 { TestBase(l); }
void TestBase(LIST &l)
static QStrList * l
Definition: config.cpp:1044
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_CHECK(
163  l.acquire(std::make_unique<UncopiableDatumClass>
164  ("another uncopiable"), "Acquired")
165  );
166  TestElement<UncopiableDatumClass>(l, "Acquired", true);
167 
168  // erase it
169  BOOST_CHECK(l.erase<UncopiableDatumClass>("Acquired"));
170  TestElement<UncopiableDatumClass>(l, "Acquired", false);
171 
172  // erase it again
173  BOOST_CHECK(!l.erase<UncopiableDatumClass>("Acquired"));
174  TestElement<UncopiableDatumClass>(l, "Acquired", false);
175 
176  // erase something that was never there
177  BOOST_CHECK(!l.erase<UncopiableDatumClass>("Never"));
178  TestElement<UncopiableDatumClass>(l, "Never", false);
179 
180 } // NonConstTest()
void TestBase(LIST &l)
static QStrList * l
Definition: config.cpp:1044
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_CHECK(!l.template get<PinnedDatumClassBase>().abstract());
150 
151 } // TestBase()
static QStrList * l
Definition: config.cpp:1044
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_CHECK_EQUAL(l.template known<T>(label), present);
123  BOOST_CHECK_EQUAL(l.template valid<T>(label), present);
124  try {
125  auto const& item = l.template get<T>(label);
126  BOOST_CHECK(present); // if not present, we should not be here!
127  BOOST_CHECK(&item);
128  }
130  BOOST_CHECK(!present); // if present, we should not be here!
131  }
132 
133 } // TestElement()
static QCString name
Definition: declinfo.cpp:673
Exception thrown on a request about an unregistered type.
Definition: ProviderList.h:184
static QStrList * l
Definition: config.cpp:1044
const double e
constexpr ProductStatus present() noexcept
Definition: ProductStatus.h:10

Variable Documentation

std::set<void*> TrackedMemory

Definition at line 27 of file ProviderList_test.cc.