nestedValidation_01_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/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  using Val_t = Tuple<string, Sequence<string>>;
19  struct Config {
20  Val_t pars{Name("pars")};
21  };
22 
24  validateConfig(std::string const& cfg)
25  {
26  auto const ps = ParameterSet::make(cfg);
27  Table<Config> validatedConfig{Name("validatedConfig")};
28  validatedConfig.validate(ps);
29  return validatedConfig;
30  }
31 }
32 
33 BOOST_AUTO_TEST_SUITE(Nested_Validation)
34 
36 {
37  string const good{"pars: [X, [Y, Z]]"s};
38  std::vector<std::string> const ref{"Y"s, "Z"s};
39  auto validatedConfig = validateConfig(good);
40  auto const& pars = validatedConfig().pars();
41  BOOST_TEST_REQUIRE(std::get<0>(pars) == "X"s);
42  BOOST_TEST_REQUIRE(std::get<1>(pars) == ref);
43 }
44 
46 {
47  string const bad{"pars: [ X ]"s};
48  BOOST_REQUIRE_THROW(validateConfig(bad), detail::validationException);
49 }
50 
52 {
53  string const bad{"pars: [ X, 1 ]"s};
54  BOOST_CHECK_THROW(validateConfig(bad), fhicl::exception);
55 }
56 
57 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_TEST_REQUIRE(static_cast< bool >(inFile))
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
static constexpr double ps
Definition: Units.h:99
BOOST_AUTO_TEST_CASE(GoodTuple)
unsigned int bad()
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33