Macros | Functions
NameSelector_test.cxx File Reference
#include "larcorealg/TestUtils/NameSelector.h"
#include "canvas/Utilities/Exception.h"
#include <boost/test/unit_test.hpp>
#include <string>
#include <iostream>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( NameSelector_test )
 

Functions

void CheckNames (testing::NameSelector const &selector, std::vector< std::string > const &names)
 
 BOOST_AUTO_TEST_CASE (SimpleTest)
 
 BOOST_AUTO_TEST_CASE (MissingQuery)
 
 BOOST_AUTO_TEST_CASE (DefaultConstructorTest)
 
 BOOST_AUTO_TEST_CASE (DefaultThrowTest)
 
 BOOST_AUTO_TEST_CASE (DefaultRejectTest)
 
 BOOST_AUTO_TEST_CASE (DefaultAcceptTest)
 
 BOOST_AUTO_TEST_CASE (SetDefinitionTest)
 
 BOOST_AUTO_TEST_CASE (OverrideTest)
 
 BOOST_AUTO_TEST_CASE (GlobalSpecTest)
 
 BOOST_AUTO_TEST_CASE (ClearAllTest)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( NameSelector_test )

Definition at line 15 of file NameSelector_test.cxx.

Function Documentation

BOOST_AUTO_TEST_CASE ( SimpleTest  )

Definition at line 85 of file NameSelector_test.cxx.

85  {
86 
87  // default answer: yes
88  testing::NameSelector selector;
89 
90  //
91  // initialize with simple elements
92  //
93  std::cout << "SimpleTest" << std::endl;
94  selector.ParseNames("accept_one", "+accept_two");
95  selector.ParseName("-reject_three");
96 
97  //
98  // visually verify the configuration
99  //
100  selector.PrintConfiguration(std::cout);
101  std::cout << std::endl;
102 
103  //
104  // check all the symbols, plus one
105  //
106  CheckNames(selector, {
107  "accept_one", "accept_two", "reject_three", "accept_unknown"
108  });
109 
110  //
111  // verify that we did not miss anything
112  //
113  BOOST_TEST(selector.CheckQueryRegistry(std::cout));
114 
115 } // BOOST_AUTO_TEST_CASE(SimpleTest)
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
void ParseNames(NAMES...names)
Parses a list of names and adds them to the selector.
Definition: NameSelector.h:97
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
void ParseName(Name_t name)
Parses a name and adds it to the selector.
Manages a set of names.
Definition: NameSelector.h:36
bool CheckQueryRegistry() const
Checks that no known element with valid response was left unqueried.
Definition: NameSelector.h:160
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( MissingQuery  )

Definition at line 121 of file NameSelector_test.cxx.

121  {
122 
123  // default answer: yes
124  testing::NameSelector selector;
125 
126  //
127  // initialize with simple elements
128  //
129  std::cout << "MissingQuery" << std::endl;
130  selector.ParseName("accept_one");
131 
132  //
133  // verify that we did miss something
134  //
135  BOOST_TEST(!selector.CheckQueryRegistry(std::cout));
136 
137 } // BOOST_AUTO_TEST_CASE(MissingQuery)
void ParseName(Name_t name)
Parses a name and adds it to the selector.
Manages a set of names.
Definition: NameSelector.h:36
bool CheckQueryRegistry() const
Checks that no known element with valid response was left unqueried.
Definition: NameSelector.h:160
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( DefaultConstructorTest  )

Definition at line 143 of file NameSelector_test.cxx.

143  {
144 
145  // default answer: yes
146  testing::NameSelector selector;
147 
148  //
149  // initialize with simple elements
150  //
151  std::cout << "DefaultConstructorTest" << std::endl;
152 
153  //
154  // visually verify the configuration
155  //
156  selector.PrintConfiguration(std::cout);
157  std::cout << std::endl;
158 
159  //
160  // check all the symbols
161  //
162  CheckNames(selector, { "accept_one", "accept_two" });
163 
164 } // BOOST_AUTO_TEST_CASE(DefaultConstructorTest)
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
Manages a set of names.
Definition: NameSelector.h:36
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( DefaultThrowTest  )

Definition at line 170 of file NameSelector_test.cxx.

170  {
171 
172  // default answer: yes
174 
175  //
176  // initialize with simple elements
177  //
178  std::cout << "DefaultThrowTest" << std::endl;
179  selector.ParseNames("accept_one", "-reject_three");
180 
181  //
182  // check all the symbols
183  //
184  CheckNames(selector, { "accept_one", "reject_three", "throw_two" });
185 
186 } // BOOST_AUTO_TEST_CASE(DefaultThrowTest)
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
Manages a set of names.
Definition: NameSelector.h:36
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:46
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( DefaultRejectTest  )

Definition at line 192 of file NameSelector_test.cxx.

192  {
193 
194  // default answer: yes
196 
197  //
198  // initialize with simple elements
199  //
200  std::cout << "DefaultRejectTest" << std::endl;
201  selector.ParseNames("accept_one", "-reject_three");
202 
203  //
204  // check all the symbols, plus one
205  //
206  CheckNames(selector, { "accept_one", "reject_two", "reject_unknown" });
207 
208 } // BOOST_AUTO_TEST_CASE(DefaultRejectTest)
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
Manages a set of names.
Definition: NameSelector.h:36
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( DefaultAcceptTest  )

Definition at line 214 of file NameSelector_test.cxx.

214  {
215 
216  // default answer: yes
218 
219  //
220  // initialize with simple elements
221  //
222  std::cout << "DefaultAcceptTest" << std::endl;
223  selector.ParseNames("accept_one", "-reject_three");
224 
225  //
226  // check all the symbols, plus one
227  //
228  CheckNames(selector, { "accept_one", "accept_two", "accept_unknown" });
229 
230 } // BOOST_AUTO_TEST_CASE(DefaultAcceptTest)
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
Manages a set of names.
Definition: NameSelector.h:36
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( SetDefinitionTest  )

Definition at line 236 of file NameSelector_test.cxx.

236  {
237 
238  // default answer: yes
239  testing::NameSelector selector;
240 
241  // set 2 does not follow the naming convention because it will be subtracted
242  selector.AddToDefinition
243  ("set1", "accept_set1_one", "+accept_set1_two", "-reject_set1_three");
244  selector.AddToDefinition
245  ("set2", "-accept_set2_one", "-accept_set2_two", "+reject_set2_three");
246  selector.Define("set3", std::vector<std::string>
247  { "accept_set3_one", "+accept_set3_two", "-reject_set3_three" }
248  );
249 
250  //
251  // initialize with simple elements
252  //
253  std::cout << "SetDefinitionTest" << std::endl;
254  selector.ParseNames("accept_one", "set1", "-@set2", "+set3", "-reject_two");
255 
256  //
257  // visually verify the configuration
258  //
259  selector.PrintConfiguration(std::cout);
260  std::cout << std::endl;
261 
262  //
263  // check all the symbols, plus one
264  //
265  CheckNames(selector, {
266  "accept_set1_one", "accept_set1_two", "reject_set1_three",
267  "accept_set2_one", "accept_set2_two", "reject_set2_three",
268  "accept_one", "reject_two", "accept_unknown"
269  });
270 
271 } // BOOST_AUTO_TEST_CASE(SetDefinitionTest)
void Define(std::string set_name, LIST const &items)
Defines a set.
Definition: NameSelector.h:281
void AddToDefinition(std::string set_name, NAMES...names)
Parses a list of names and add them to the specified definition.
Definition: NameSelector.h:127
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
void ParseNames(NAMES...names)
Parses a list of names and adds them to the selector.
Definition: NameSelector.h:97
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
Manages a set of names.
Definition: NameSelector.h:36
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( OverrideTest  )

Definition at line 277 of file NameSelector_test.cxx.

277  {
278 
279  // default answer: yes
280  testing::NameSelector selector;
281 
282  // set does not follow the naming convention because it will be subtracted
283  selector.AddToDefinition("default",
284  "accept_one", "-accept_two", "+reject_three"
285  );
286 
287  //
288  // initialize with simple elements
289  //
290  std::cout << "OverrideTest" << std::endl;
291  selector.ParseNames("+reject_three", "-default", "accept_one", "accept_four");
292 
293  //
294  // visually verify the configuration
295  //
296  selector.PrintConfiguration(std::cout);
297  std::cout << std::endl;
298 
299  //
300  // check all the symbols
301  //
302  CheckNames(selector, {
303  "accept_one", "accept_two", "reject_three", "accept_four"
304  });
305 
306 } // BOOST_AUTO_TEST_CASE(OverrideTest)
void AddToDefinition(std::string set_name, NAMES...names)
Parses a list of names and add them to the specified definition.
Definition: NameSelector.h:127
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
void ParseNames(NAMES...names)
Parses a list of names and adds them to the selector.
Definition: NameSelector.h:97
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
Manages a set of names.
Definition: NameSelector.h:36
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( GlobalSpecTest  )

Definition at line 312 of file NameSelector_test.cxx.

312  {
313 
314  // default answer: yes
315  testing::NameSelector selector;
316 
317  // set 2 does not follow the naming convention because it will be subtracted
318  selector.AddToDefinition("default",
319  "accept_one", "-accept_two", "+reject_three"
320  );
321 
322  //
323  // initialize with simple elements
324  //
325  std::cout << "GlobalSpecTest" << std::endl;
326  selector.ParseNames("accept_one", "-*", "-reject_three", "accept_four");
327 
328  //
329  // visually verify the configuration
330  //
331  selector.PrintConfiguration(std::cout);
332  std::cout << std::endl;
333 
334  //
335  // check all the symbols, plus one
336  //
337  CheckNames(selector, {
338  "accept_one", "reject_unknown", "reject_three", "accept_four"
339  });
340 
341 } // BOOST_AUTO_TEST_CASE(GlobalSpecTest)
void AddToDefinition(std::string set_name, NAMES...names)
Parses a list of names and add them to the specified definition.
Definition: NameSelector.h:127
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
void ParseNames(NAMES...names)
Parses a list of names and adds them to the selector.
Definition: NameSelector.h:97
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
Manages a set of names.
Definition: NameSelector.h:36
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE ( ClearAllTest  )

Definition at line 347 of file NameSelector_test.cxx.

347  {
348 
349  // default answer: yes
351 
352  //
353  // initialize
354  //
355  std::cout << "ClearAllTest" << std::endl;
356  selector.ParseNames("throw_lost", "!", "-reject_three", "accept_four");
357 
358  //
359  // visually verify the configuration
360  //
361  selector.PrintConfiguration(std::cout);
362  std::cout << std::endl;
363 
364  //
365  // check all the symbols, plus one
366  //
367  CheckNames(selector, {
368  "throw_lost", "throw_unknown", "reject_three", "accept_four"
369  });
370 
371 } // BOOST_AUTO_TEST_CASE(ClearAllTest)
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
Manages a set of names.
Definition: NameSelector.h:36
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:46
QTextStream & endl(QTextStream &s)
void CheckNames ( testing::NameSelector const &  selector,
std::vector< std::string > const &  names 
)

In the following tests, the names are conventionally called "acceptXXX" if the final result of the query is expected to be acceptance, "rejectXXX" if the final result of the query is expected to be rejection, or "throwXXX" if the final result of the query is expected to be the throw of an exception.

If an error does happen, run the test with '–log_level=all' to get enough information to track the error location:

  • for an unexpected exception (even without '–log_level=all'):

    .../NameSelector_test.cxx(53): error in "DefaultThrowTest": check selector.Query(name) == testing::NameSelector::rsAccepted failed [2 != 1] unknown location(0): fatal error in "DefaultThrowTest": std::exception: -— Configuration BEGIN NameSelector: name 'accept_unknown' not configured. -— Configuration END

    Boost error points to the test name ("DefaultThrowTest") and to the check that failed (line 53), while the message of the exception fills in with the name being checked

  • for a wrong result, running with '–log_level=all':

    Testing 'accept_unknown' ../NameSelector_test.cxx(53): error in "DefaultRejectTest": check selector.Query(name) == testing::NameSelector::rsAccepted failed [0 != 1]

    Boost points to the test and the failed check as before, while BOOST_TEST_MESSAGE informs about which name was being tested.

Definition at line 52 of file NameSelector_test.cxx.

53 {
54 
55  for (std::string const& name: names) {
56  BOOST_TEST_MESSAGE("Testing '" << name << "'");
57  if (name.find("throw") == 0U) {
58  BOOST_TEST(selector.Query(name) == testing::NameSelector::rsThrow);
59  BOOST_CHECK_THROW(selector(name), art::Exception);
60  BOOST_CHECK_THROW(selector.Accepted(name), art::Exception);
61  BOOST_CHECK_THROW(selector.Rejected(name), art::Exception);
62  }
63  else if (name.find("reject") == 0U) {
64  BOOST_TEST
65  (selector.Query(name) == testing::NameSelector::rsRejected);
66  BOOST_TEST(!selector(name));
67  BOOST_TEST(!selector.Accepted(name));
68  BOOST_TEST(selector.Rejected(name));
69  }
70  else { // accept
71  BOOST_TEST
72  (selector.Query(name) == testing::NameSelector::rsAccepted);
73  BOOST_TEST(selector(name));
74  BOOST_TEST(selector.Accepted(name));
75  BOOST_TEST(!selector.Rejected(name));
76  }
77  } // for
78 
79 } // CheckNames()
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
int find(char c, int index=0, bool cs=TRUE) const
Definition: qcstring.cpp:41
throw art::Exception (art::errors::Configuration)
Definition: NameSelector.h:46
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66