table_insertionOperator_t.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test operator<< for Table
4 //
5 // ======================================================================
6 
7 #define BOOST_TEST_MODULE (table_insertionOperator_t)
8 
9 #include "boost/test/unit_test.hpp"
10 
11 #include "fhiclcpp/types/Atom.h"
13 #include "fhiclcpp/types/Table.h"
15 
16 #include <iostream>
17 #include <string>
18 
19 using namespace fhicl;
20 using namespace std;
21 
22 namespace {
23 
24  struct Config {
25  Atom<bool> flag{Name("flag"), true};
26  Atom<string> name{Name("name"), "Billy"};
27  };
28 
29  struct Logger {
30  std::string log;
31 
32  template <typename T>
33  Logger&
34  operator<<(T const& t)
35  {
36  std::ostringstream oss;
37  oss << t;
38  log.append(oss.str());
39  return *this;
40  }
41  };
42 
44  reference()
45  {
46  return "\n " + detail::optional_parameter_message() +
47  "\n\n"
48  " config: {\n"
49  "\n"
50  " flag: true # default\n"
51  "\n"
52  " name: \"Billy\" # default\n"
53  " }\n";
54  }
55 
57  optional_reference()
58  {
59  return "\n " + detail::optional_parameter_message() +
60  "\n\n"
61  " # config: {\n"
62  " #\n"
63  " # flag: true # default\n"
64  " #\n"
65  " # name: \"Billy\" # default\n"
66  " # }\n";
67  }
68 }
69 
70 BOOST_AUTO_TEST_SUITE(table_insertionOperator_test)
71 
73 {
74  Table<Config> config{Name("config")};
75  ostringstream oss;
76  oss << config;
77  auto const& test = oss.str();
78  auto const& ref = reference();
79  BOOST_TEST(test == ref);
80 }
81 
83 {
84  Table<Config> config{Name("config")};
85  Logger logger;
86  logger << config;
87  BOOST_TEST(logger.log == reference());
88 
89  Logger const logger2 = (Logger() << config);
90  BOOST_TEST(logger2.log == reference());
91 }
92 
93 BOOST_AUTO_TEST_CASE(loggerOptional)
94 {
96  Logger logger;
97  logger << config;
98  BOOST_TEST(logger.log == optional_reference());
99 
100  Logger const logger2 = (Logger() << config);
101  BOOST_TEST(logger2.log == optional_reference());
102 }
103 
104 BOOST_AUTO_TEST_SUITE_END()
static QCString name
Definition: declinfo.cpp:673
std::string string
Definition: nybbler.cc:12
ChannelGroupService::Name Name
STL namespace.
std::string optional_parameter_message(bool const with_comment=true)
typename config_impl< T >::type Config
Definition: ModuleMacros.h:52
static Config * config
Definition: config.cpp:1054
std::ostream & operator<<(std::ostream &, ParameterSetID const &)
BOOST_AUTO_TEST_CASE(simple)