#include "TestUtils/NameSelector.h"
#include "canvas/Utilities/Exception.h"
#include <cetlib/quiet_unit_test.hpp>
#include <boost/test/test_tools.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 86 of file NameSelector_test.cxx.
95 selector.
ParseNames(
"accept_one",
"+accept_two");
108 "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 122 of file NameSelector_test.cxx.
130 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 144 of file NameSelector_test.cxx.
152 std::cout <<
"DefaultConstructorTest" <<
std::endl;
163 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 171 of file NameSelector_test.cxx.
179 std::cout <<
"DefaultThrowTest" <<
std::endl;
180 selector.ParseNames(
"accept_one",
"-reject_three");
185 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 193 of file NameSelector_test.cxx.
201 std::cout <<
"DefaultRejectTest" <<
std::endl;
202 selector.ParseNames(
"accept_one",
"-reject_three");
207 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 215 of file NameSelector_test.cxx.
223 std::cout <<
"DefaultAcceptTest" <<
std::endl;
224 selector.ParseNames(
"accept_one",
"-reject_three");
229 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 237 of file NameSelector_test.cxx.
244 (
"set1",
"accept_set1_one",
"+accept_set1_two",
"-reject_set1_three");
246 (
"set2",
"-accept_set2_one",
"-accept_set2_two",
"+reject_set2_three");
247 selector.
Define(
"set3", std::vector<std::string>
248 {
"accept_set3_one",
"+accept_set3_two",
"-reject_set3_three" }
254 std::cout <<
"SetDefinitionTest" <<
std::endl;
255 selector.
ParseNames(
"accept_one",
"set1",
"-@set2",
"+set3",
"-reject_two");
267 "accept_set1_one",
"accept_set1_two",
"reject_set1_three",
268 "accept_set2_one",
"accept_set2_two",
"reject_set2_three",
269 "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 278 of file NameSelector_test.cxx.
285 "accept_one",
"-accept_two",
"+reject_three" 291 std::cout <<
"OverrideTest" <<
std::endl;
292 selector.
ParseNames(
"+reject_three",
"-default",
"accept_one",
"accept_four");
304 "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 313 of file NameSelector_test.cxx.
320 "accept_one",
"-accept_two",
"+reject_three" 326 std::cout <<
"GlobalSpecTest" <<
std::endl;
327 selector.
ParseNames(
"accept_one",
"-*",
"-reject_three",
"accept_four");
339 "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 348 of file NameSelector_test.cxx.
356 std::cout <<
"ClearAllTest" <<
std::endl;
357 selector.ParseNames(
"throw_lost",
"!",
"-reject_three",
"accept_four");
362 selector.PrintConfiguration(std::cout);
369 "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 53 of file NameSelector_test.cxx.
57 BOOST_TEST_MESSAGE(
"Testing '" <<
name <<
"'");
64 else if (
name.
find(
"reject") == 0U) {
67 BOOST_CHECK(!selector(
name));
68 BOOST_CHECK(!selector.Accepted(
name));
69 BOOST_CHECK(selector.Rejected(
name));
74 BOOST_CHECK(selector(
name));
75 BOOST_CHECK(selector.Accepted(
name));
76 BOOST_CHECK(!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