#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.
#define BOOST_TEST_MODULE ( NameSelector_test ) |
BOOST_AUTO_TEST_CASE |
( |
SimpleTest |
| ) |
|
Definition at line 85 of file NameSelector_test.cxx.
94 selector.
ParseNames(
"accept_one",
"+accept_two");
107 "accept_one",
"accept_two",
"reject_three",
"accept_unknown" 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.
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.
bool CheckQueryRegistry() const
Checks that no known element with valid response was left unqueried.
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
MissingQuery |
| ) |
|
Definition at line 121 of file NameSelector_test.cxx.
129 std::cout <<
"MissingQuery" <<
std::endl;
void ParseName(Name_t name)
Parses a name and adds it to the selector.
bool CheckQueryRegistry() const
Checks that no known element with valid response was left unqueried.
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
DefaultConstructorTest |
| ) |
|
Definition at line 143 of file NameSelector_test.cxx.
151 std::cout <<
"DefaultConstructorTest" <<
std::endl;
162 CheckNames(selector, {
"accept_one",
"accept_two" });
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
DefaultThrowTest |
| ) |
|
Definition at line 170 of file NameSelector_test.cxx.
178 std::cout <<
"DefaultThrowTest" <<
std::endl;
179 selector.ParseNames(
"accept_one",
"-reject_three");
184 CheckNames(selector, {
"accept_one",
"reject_three",
"throw_two" });
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
throw art::Exception (art::errors::Configuration)
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
DefaultRejectTest |
| ) |
|
Definition at line 192 of file NameSelector_test.cxx.
200 std::cout <<
"DefaultRejectTest" <<
std::endl;
201 selector.ParseNames(
"accept_one",
"-reject_three");
206 CheckNames(selector, {
"accept_one",
"reject_two",
"reject_unknown" });
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
DefaultAcceptTest |
| ) |
|
Definition at line 214 of file NameSelector_test.cxx.
222 std::cout <<
"DefaultAcceptTest" <<
std::endl;
223 selector.ParseNames(
"accept_one",
"-reject_three");
228 CheckNames(selector, {
"accept_one",
"accept_two",
"accept_unknown" });
void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
SetDefinitionTest |
| ) |
|
Definition at line 236 of file NameSelector_test.cxx.
243 (
"set1",
"accept_set1_one",
"+accept_set1_two",
"-reject_set1_three");
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" }
253 std::cout <<
"SetDefinitionTest" <<
std::endl;
254 selector.
ParseNames(
"accept_one",
"set1",
"-@set2",
"+set3",
"-reject_two");
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" void Define(std::string set_name, LIST const &items)
Defines a set.
void AddToDefinition(std::string set_name, NAMES...names)
Parses a list of names and add them to the specified definition.
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.
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
OverrideTest |
| ) |
|
Definition at line 277 of file NameSelector_test.cxx.
284 "accept_one",
"-accept_two",
"+reject_three" 290 std::cout <<
"OverrideTest" <<
std::endl;
291 selector.
ParseNames(
"+reject_three",
"-default",
"accept_one",
"accept_four");
303 "accept_one",
"accept_two",
"reject_three",
"accept_four" void AddToDefinition(std::string set_name, NAMES...names)
Parses a list of names and add them to the specified definition.
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.
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
GlobalSpecTest |
| ) |
|
Definition at line 312 of file NameSelector_test.cxx.
319 "accept_one",
"-accept_two",
"+reject_three" 325 std::cout <<
"GlobalSpecTest" <<
std::endl;
326 selector.
ParseNames(
"accept_one",
"-*",
"-reject_three",
"accept_four");
338 "accept_one",
"reject_unknown",
"reject_three",
"accept_four" void AddToDefinition(std::string set_name, NAMES...names)
Parses a list of names and add them to the specified definition.
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.
void PrintConfiguration(std::ostream &) const
Prints the configuration into a stream.
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE |
( |
ClearAllTest |
| ) |
|
Definition at line 347 of file NameSelector_test.cxx.
355 std::cout <<
"ClearAllTest" <<
std::endl;
356 selector.ParseNames(
"throw_lost",
"!",
"-reject_three",
"accept_four");
361 selector.PrintConfiguration(std::cout);
368 "throw_lost",
"throw_unknown",
"reject_three",
"accept_four" void CheckNames(testing::NameSelector const &selector, std::vector< std::string > const &names)
throw art::Exception (art::errors::Configuration)
QTextStream & endl(QTextStream &s)
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.
56 BOOST_TEST_MESSAGE(
"Testing '" <<
name <<
"'");
63 else if (
name.
find(
"reject") == 0U) {
66 BOOST_TEST(!selector(
name));
67 BOOST_TEST(!selector.Accepted(
name));
68 BOOST_TEST(selector.Rejected(
name));
73 BOOST_TEST(selector(
name));
74 BOOST_TEST(selector.Accepted(
name));
75 BOOST_TEST(!selector.Rejected(
name));
int find(char c, int index=0, bool cs=TRUE) const
throw art::Exception (art::errors::Configuration)
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception