bounded_sequences_with_defaults_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (Bounded sequences with defaults)
2 
3 #include "boost/test/unit_test.hpp"
4 
6 #include "fhiclcpp/types/Name.h"
8 #include "fhiclcpp/types/Table.h"
9 #include "fhiclcpp/types/Tuple.h"
10 
11 #include <string>
12 
13 using namespace fhicl;
14 using namespace std;
15 using namespace string_literals;
16 
17 namespace {
18 
19  struct ArrayConfig {
20  Sequence<string, 2> composers{Name{"composers"}, {"Mahler", "Elgar"}};
21  };
22 
23  struct TupleConfig {
24  Tuple<string, unsigned> ages{Name{"ages"}, {"David"s, 9}};
25  };
26 
27  template <typename T>
28  Table<T>
29  validate(std::string const& cfg)
30  {
31  Table<T> validated_config{Name("validatedConfig")};
32  validated_config.validate(ParameterSet::make(cfg));
33  return validated_config;
34  }
35 }
36 
37 BOOST_AUTO_TEST_SUITE(bounded_sequence_with_defaults)
38 
40 {
41  string const good{};
42  auto const& validated = validate<ArrayConfig>(good);
43  BOOST_TEST(validated().composers(0) == "Mahler"s);
44  BOOST_TEST(validated().composers(1) == "Elgar"s);
45 }
46 
48 {
49  string const good{};
50  auto const& validated = validate<TupleConfig>(good);
51  BOOST_TEST(validated().ages.get<0>() == "David"s);
52  BOOST_TEST(validated().ages.get<1>() == 9u);
53 }
54 
56 {
57  string const bad{"composers: [Beethoven]"};
58  // Because the 'composers' parameter is a bounded sequence of atomic
59  // types, the preset_value function indirectly throws a
60  // fhicl::exception instead of a fhicl::detail::validationException.
61  // This should probably be fixed at some point.
62  BOOST_REQUIRE_THROW(validate<ArrayConfig>(bad), fhicl::exception);
63 }
64 
66 {
67  string const bad{"ages: [Jenny]"};
68  BOOST_REQUIRE_THROW(validate<TupleConfig>(bad), detail::validationException);
69 }
70 
71 BOOST_AUTO_TEST_SUITE_END()
std::string string
Definition: nybbler.cc:12
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
ChannelGroupService::Name Name
STL namespace.
def validate(nxgraph, desc)
Definition: graph.py:45
unsigned int bad()
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE(GoodArray)