make_tool_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (make_tool_t)
2 #include "boost/test/unit_test.hpp"
3 
11 #include "fhiclcpp/ParameterSet.h"
12 
13 #include <string>
14 
15 namespace {
16  auto
17  pset_from_oss(std::ostringstream const& ss)
18  {
19  return fhicl::ParameterSet::make(ss.str());
20  }
21 } // namespace
22 
23 using namespace std::string_literals;
24 
25 BOOST_AUTO_TEST_SUITE(make_tool_t)
26 
28 {
30  ps.put("tool_type", "ClassTool"s);
31  auto t1 = art::make_tool<arttest::ClassTool>(ps);
32  BOOST_TEST(t1->addOne(17) == 18);
33 }
34 
35 BOOST_AUTO_TEST_CASE(tool_function)
36 {
38  ps.put("tool_type", "FunctionTool"s);
39  int i{17};
40  auto addOne1 = art::make_tool<decltype(arttest::addOne)>(ps, "addOne");
41  auto addOne2 = art::make_tool<int(int)>(ps, "addOne");
42  BOOST_TEST(addOne1(i) == 18);
43  BOOST_TEST(addOne2(i) == 18);
44 }
45 
46 BOOST_AUTO_TEST_CASE(nested_function_tools)
47 {
48  std::ostringstream ss;
49  ss << "tool_type: NestedFunctionTool\n"
50  << "addOneTool: {"
51  << " tool_type: FunctionTool"
52  << "}";
53  auto const& ps = pset_from_oss(ss);
54  auto callThroughToAddOne =
55  art::make_tool<decltype(arttest::callThroughToAddOne)>(
56  ps, "callThroughToAddOne");
57  auto const& nestedPS = ps.get<fhicl::ParameterSet>("addOneTool");
58  BOOST_TEST(callThroughToAddOne(nestedPS, 17) == 18);
59 }
60 
61 BOOST_AUTO_TEST_CASE(nested_class_tools)
62 {
63  std::ostringstream ss;
64  ss << "tool_type: NestedClassTool\n"
65  << "addOneTool: {"
66  << " tool_type: ClassTool"
67  << "}";
68  auto const& ps = pset_from_oss(ss);
69  auto t = art::make_tool<arttest::NestedClassTool>(ps);
70  BOOST_TEST(t->callThroughToAddOne(17) == 18);
71 }
72 
73 BOOST_AUTO_TEST_CASE(nested_function_in_class_tools)
74 {
75  std::ostringstream ss;
76  ss << "tool_type: NestedFunctionInClassTool\n"
77  << "addOneTool: {"
78  << " tool_type: FunctionTool"
79  << "}";
80  auto const& ps = pset_from_oss(ss);
81  auto t = art::make_tool<arttest::NestedFunctionInClassTool>(ps);
82  BOOST_TEST(t->callThroughToAddOne(17) == 18);
83 }
84 
85 BOOST_AUTO_TEST_CASE(polymorphic_tools)
86 {
87  int i{17};
88  {
90  ps.put("tool_type", "AddNumber");
91  ps.put("incrementBy", 7);
92  art::make_tool<arttest::OperationBase>(ps)->adjustNumber(i);
93  BOOST_TEST(i == 24);
94  }
95  {
97  ps.put("tool_type", "SubtractNumber");
98  art::make_tool<arttest::OperationBase>(ps)->adjustNumber(i);
99  BOOST_TEST(i == 23);
100  }
101  {
103  ps.put("tool_type", "MultiplyNumber");
104  art::make_tool<arttest::OperationBase>(ps)->adjustNumber(i);
105  BOOST_TEST(i == 46);
106  }
107 }
108 
109 BOOST_AUTO_TEST_SUITE_END()
static ParameterSet make(intermediate_table const &tbl)
Definition: ParameterSet.cc:68
BOOST_AUTO_TEST_CASE(tool_class)
Definition: make_tool_t.cc:27
static constexpr double ps
Definition: Units.h:99
int callThroughToAddOne(fhicl::ParameterSet const &pset, int const i)
static QCString * s
Definition: config.cpp:1042
void put(std::string const &key)