Macros | Functions
intermediate_table_t.cc File Reference
#include "boost/test/unit_test.hpp"
#include "fhiclcpp/ParameterSet.h"
#include "fhiclcpp/intermediate_table.h"
#include <string>
#include <vector>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (intermediate_table_t)
 

Functions

 BOOST_AUTO_TEST_CASE (main)
 
 BOOST_AUTO_TEST_CASE (prolog_erase_nested)
 
 BOOST_AUTO_TEST_CASE (prolog_erase_dotted)
 
 BOOST_AUTO_TEST_CASE (prolog_nested_partial_dup_nested)
 
 BOOST_AUTO_TEST_CASE (prolog_nested_partial_dup_dotted)
 
 BOOST_AUTO_TEST_CASE (prolog_dotted_partial_dup_nested)
 
 BOOST_AUTO_TEST_CASE (prolog_dotted_partial_dup_dotted)
 
 BOOST_AUTO_TEST_CASE (prolog_nested_dup_nested)
 
 BOOST_AUTO_TEST_CASE (prolog_nested_dup_dotted)
 
 BOOST_AUTO_TEST_CASE (prolog_dotted_dup_nested)
 
 BOOST_AUTO_TEST_CASE (prolog_dotted_dup_dotted)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (intermediate_table_t)

Definition at line 1 of file intermediate_table_t.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( main  )

Definition at line 14 of file intermediate_table_t.cc.

15 {
16  intermediate_table table;
19  table.put("string1", "string");
20  table.put("string2", std::string("string"));
21  table.put("complex", std::complex<double>(-3, -0.5));
22  table.put("sequence", std::vector<int>{5, 10, 15, 20, 25});
23  table.put("double", 28.5);
24  table.put("sequence[6]", 35);
25  table.put("table.val1", 92);
26  table.put("table.t1.val", "oops");
27  BOOST_CHECK_NO_THROW(table.erase("table.t1.waldo"));
28  BOOST_CHECK_NO_THROW(table.erase("table.t1.val"));
29  BOOST_TEST(!table.exists("table.t1.val"));
30  BOOST_CHECK_THROW(table.erase("table.val1.valX"), fhicl::exception);
31  BOOST_TEST(table.get<std::string>("string1") == "string");
32  BOOST_TEST(table.get<std::string>("string2") == "string");
33  BOOST_TEST(table.get<std::complex<double>>("complex") ==
34  std::complex<double>(-3, -0.5));
35  BOOST_TEST(table.get<sequence_t const&>("sequence").size() == 7u);
36  BOOST_TEST(table.get<int>("sequence[3]") == 20);
37  BOOST_CHECK_THROW(table.get<int>("sequence[5]"), fhicl::exception); // Nil
38  BOOST_TEST(table.get<table_t const&>("table").size() == 2u);
39  BOOST_TEST(table.get<table_t const&>("table.t1").size() == 0u);
40 }
size_type size() const
Definition: stdmap_shims.h:282
std::string string
Definition: nybbler.cc:12
fhicl::extended_value::table_t table_t
bool put(std::string const &name, std::string const &value, bool in_prolog=false)
bool exists(std::string const &key) const
fhicl::extended_value::sequence_t sequence_t
void erase(std::string const &key, bool in_prolog=false)
T get(std::string const &name)
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
BOOST_AUTO_TEST_CASE ( prolog_erase_nested  )

Definition at line 42 of file intermediate_table_t.cc.

43 {
44  char const* cfg = R"(BEGIN_PROLOG
45 w: { x: { y: { z: { a: 2 b: 3 } } } }
46 END_PROLOG
47 q: { @table::w.x.y })";
48  auto const pset = ParameterSet::make(cfg);
49  BOOST_TEST(pset.has_key("q.z"));
50  BOOST_TEST(!pset.has_key("w"));
51 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_erase_dotted  )

Definition at line 53 of file intermediate_table_t.cc.

54 {
55  char const* cfg = R"(BEGIN_PROLOG
56 w.x.y: { z: { a: 2 b: 3 } }
57 END_PROLOG
58 q: { @table::w.x.y })";
59  auto const pset = ParameterSet::make(cfg);
60  BOOST_TEST(pset.has_key("q.z"));
61  BOOST_TEST(!pset.has_key("w"));
62 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_nested_partial_dup_nested  )

Definition at line 64 of file intermediate_table_t.cc.

65 {
66  char const* cfg = R"(BEGIN_PROLOG
67 w: { x: { y: 7 } }
68 END_PROLOG
69 w: { b: { c: 6 } })";
70  auto const pset = ParameterSet::make(cfg);
71  BOOST_TEST(pset.has_key("w.b"));
72  BOOST_TEST(!pset.has_key("w.x"));
73 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_nested_partial_dup_dotted  )

Definition at line 75 of file intermediate_table_t.cc.

76 {
77  char const* cfg = R"(BEGIN_PROLOG
78 w: { x: { y: 7 } }
79 END_PROLOG
80 w.b.c: 6)";
81  auto const pset = ParameterSet::make(cfg);
82  BOOST_TEST(pset.has_key("w.b"));
83  BOOST_TEST(!pset.has_key("w.x"));
84 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_dotted_partial_dup_nested  )

Definition at line 86 of file intermediate_table_t.cc.

87 {
88  char const* cfg = R"(BEGIN_PROLOG
89 w.x.y: 7
90 END_PROLOG
91 w: { b: { c: 6 } })";
92  auto const pset = ParameterSet::make(cfg);
93  BOOST_TEST(pset.has_key("w.b"));
94  BOOST_TEST(!pset.has_key("w.x"));
95 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_dotted_partial_dup_dotted  )

Definition at line 97 of file intermediate_table_t.cc.

98 {
99  char const* cfg = R"(BEGIN_PROLOG
100 w.x.y: 7
101 END_PROLOG
102 w.b.c: 6)";
103  auto const pset = ParameterSet::make(cfg);
104  BOOST_TEST(pset.has_key("w.b"));
105  BOOST_TEST(!pset.has_key("w.x"));
106 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_nested_dup_nested  )

Definition at line 108 of file intermediate_table_t.cc.

109 {
110  char const* cfg = R"(BEGIN_PROLOG
111 w: { x: { y: 7 } }
112 END_PROLOG
113 w: { x: { c: 6 } })";
114  auto const pset = ParameterSet::make(cfg);
115  BOOST_TEST(pset.has_key("w.x.c"));
116  BOOST_TEST(!pset.has_key("w.x.y"));
117 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_nested_dup_dotted  )

Definition at line 119 of file intermediate_table_t.cc.

120 {
121  char const* cfg = R"(BEGIN_PROLOG
122 w: { x: { y: 7 } }
123 END_PROLOG
124 w.x.c: 6)";
125  auto const pset = ParameterSet::make(cfg);
126  BOOST_TEST(pset.has_key("w.x.c"));
127  BOOST_TEST(!pset.has_key("w.x.y"));
128 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_dotted_dup_nested  )

Definition at line 130 of file intermediate_table_t.cc.

131 {
132  char const* cfg = R"(BEGIN_PROLOG
133 w.x.y: 7
134 END_PROLOG
135 w: { x: { c: 6 } })";
136  auto const pset = ParameterSet::make(cfg);
137  BOOST_TEST(pset.has_key("w.x.c"));
138  BOOST_TEST(!pset.has_key("w.x.y"));
139 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)
BOOST_AUTO_TEST_CASE ( prolog_dotted_dup_dotted  )

Definition at line 141 of file intermediate_table_t.cc.

142 {
143  char const* cfg = R"(BEGIN_PROLOG
144 w.x.y: 7
145 END_PROLOG
146 w.x.c: 6)";
147  auto const pset = ParameterSet::make(cfg);
148  BOOST_TEST(pset.has_key("w.x.c"));
149  BOOST_TEST(!pset.has_key("w.x.y"));
150 }
unique_ptr< InputSource > make(ParameterSet const &conf, InputSourceDescription &desc)