nestedValidation_02_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (Nested Validation)
2 
3 #include "boost/test/unit_test.hpp"
4 
6 #include "fhiclcpp/types/Atom.h"
7 #include "fhiclcpp/types/Name.h"
9 #include "fhiclcpp/types/Table.h"
10 #include "fhiclcpp/types/Tuple.h"
11 
12 #include <string>
13 
14 using namespace fhicl;
15 using namespace std;
16 using namespace string_literals;
17 
18 namespace {
20  struct Config {
21  Val_t pars{Name("pars")};
22  };
23 
25  validateConfig(std::string const& cfg)
26  {
27  auto const ps = ParameterSet::make(cfg);
28  Table<Config> validatedConfig{Name("validatedConfig")};
29  validatedConfig.validate(ps);
30  return validatedConfig;
31  }
32 }
33 
34 BOOST_AUTO_TEST_SUITE(Nested_Validation)
35 
37 {
38  string const good{"pars: [[A, [B]], [X, [Y, Z]]]"s};
39  std::vector<std::string> const ref1{"B"s};
40  std::vector<std::string> const ref2{"Y"s, "Z"s};
41  auto validatedConfig = validateConfig(good);
42  auto const& pars = validatedConfig().pars();
43  BOOST_TEST_REQUIRE(pars.size() == 2ull);
44  BOOST_TEST_REQUIRE(std::get<0>(pars[0]) == "A"s);
45  BOOST_TEST_REQUIRE(std::get<1>(pars[0]) == ref1);
46  BOOST_TEST_REQUIRE(std::get<0>(pars[1]) == "X"s);
47  BOOST_TEST_REQUIRE(std::get<1>(pars[1]) == ref2);
48 }
49 
51 {
52  string const bad{"pars: [[A], [X, [Y, Z]]]"s};
53  BOOST_REQUIRE_THROW(validateConfig(bad), detail::validationException);
54 }
55 
57 {
58  string const bad{"pars: [[A]]"s};
59  BOOST_REQUIRE_THROW(validateConfig(bad), detail::validationException);
60 }
61 
63 {
64  string const bad{"pars: [[A, 7]]"s};
65  BOOST_REQUIRE_THROW(validateConfig(bad), fhicl::exception);
66 }
67 
68 BOOST_AUTO_TEST_SUITE_END()
std::string string
Definition: nybbler.cc:12
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
fhicl::Table< Config > validateConfig(std::string const &configStr)
ChannelGroupService::Name Name
STL namespace.
BOOST_AUTO_TEST_CASE(GoodTuple1)
BOOST_TEST_REQUIRE(static_cast< bool >(inFile))
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
static constexpr double ps
Definition: Units.h:99
unsigned int bad()
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33