Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
DataExportConfigTest.cpp
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 #include "cheetah/exporters/test/DataExportConfigTest.h"
25 #include "cheetah/exporters/DataExportConfig.h"
26 #include <boost/property_tree/xml_parser.hpp>
27 
28 namespace ska {
29 namespace cheetah {
30 namespace exporters {
31 namespace test {
32 
33 
34 DataExportConfigTest::DataExportConfigTest()
35  : ::testing::Test()
36 {
37 }
38 
39 DataExportConfigTest::~DataExportConfigTest()
40 {
41 }
42 
43 void DataExportConfigTest::SetUp()
44 {
45 }
46 
47 void DataExportConfigTest::TearDown()
48 {
49 }
50 
52  public:
53  Sink_1_Config() : cheetah::utils::Config("sink_1") {}
54  protected:
55  void add_options(OptionsDescriptionEasyInit& ) override {}
56 };
57 
58 struct Sink_1 {
59  typedef Sink_1_Config ConfigType;
60 };
61 
63  public:
64  Sink_2_Config() : cheetah::utils::Config("sink_2") {}
65  protected:
66  void add_options(OptionsDescriptionEasyInit& ) override {};
67 };
68 
69 struct Sink_2 {
70  typedef Sink_2_Config ConfigType;
71 };
72 
73 TEST_F(DataExportConfigTest, test_parse_tree_no_registered)
74 {
75  boost::property_tree::ptree pt_root;
76  boost::property_tree::ptree pt_exporter_1;
77  boost::property_tree::ptree pt_exporter_2_a;
78  boost::property_tree::ptree pt_exporter_2_b;
79 
80  pt_root.put_child("exporter_1", pt_exporter_1);
81  pt_root.add_child("exporter_2", pt_exporter_2_a);
82  pt_root.add_child("exporter_2", pt_exporter_2_b);
83 
85  boost::program_options::variables_map vm;
86  c.parse_property_tree(pt_root, vm);
87  boost::program_options::notify(vm);
88 
89  ASSERT_EQ(0U, c.exporters().size()); // no data exporters registered
90 
91 }
92 
93 TEST_F(DataExportConfigTest, test_parse_tree)
94 {
95  boost::property_tree::ptree pt_root;
96  boost::property_tree::ptree pt_channels;
97  //boost::property_tree::ptree pt_sinks;
98  boost::property_tree::ptree pt_sink_configs;
99 
100  boost::property_tree::ptree pt_channel_1;
101  boost::property_tree::ptree pt_channel_2;
102  boost::property_tree::ptree sink_1;
103  sink_1.put<std::string>("id","sink_1_id");
104  boost::property_tree::ptree sink_2;
105  sink_2.put<std::string>("id","sink_2_id");
106  boost::property_tree::ptree sink_3;
107  sink_3.put<std::string>("id","sink_3_id");
108  boost::property_tree::ptree sink_4; // empty
109 
110  pt_channel_1.put<std::string>("active", "true");
111  pt_channel_1.add_child("sink", sink_1);
112  pt_channel_1.add_child("sink", sink_2);
113  pt_channel_2.add_child("sink", sink_3);
114  pt_channel_2.add_child("sink", sink_4);
115  pt_channels.add_child("channel_1", pt_channel_1);
116  pt_channels.add_child("channel_2", pt_channel_2);
117  pt_root.put_child("channels", pt_channels);
118 
119  // add sink configurations
120  boost::property_tree::ptree sink_1_config;
121  boost::property_tree::ptree sink_1_with_id_config;
122  sink_1_with_id_config.put<std::string>("id","sink_1_id");
123  boost::property_tree::ptree sink_2_config;
124  boost::property_tree::ptree sink_2_with_id_config;
125  sink_2_with_id_config.put<std::string>("id","sink_2_id");
126  //pt_sinks.add_child("sink_2", sink_2_config);
127  //pt_sinks.add_child("sink_2", sink_2_config);
128  //pt_root.put_child("sinks", pt_sinks);
129  pt_sink_configs.add_child("sink_1", sink_1_config);
130  pt_sink_configs.add_child("sink_1", sink_1_with_id_config);
131  pt_sink_configs.add_child("sink_2", sink_2_config);
132  pt_sink_configs.add_child("sink_2", sink_2_with_id_config);
133  pt_root.put_child("sink_configs", pt_sink_configs);
134 
135  boost::property_tree::xml_parser::write_xml(std::cout, pt_root);
136 
138  c.add_sink("sink_1", []() { return new Sink_1_Config(); });
139  c.add_sink("sink_2", []() { return new Sink_2_Config(); });
140 
141  boost::program_options::variables_map vm;
142  c.parse_property_tree(pt_root, vm);
143  boost::program_options::notify(vm);
144 
145  // register some exporters
146  ASSERT_EQ(2U, c.exporters().size());
147  Sink_1_Config const& c1 = dynamic_cast<Sink_1_Config const&>(c.exporters()[0].sink_config());
148  ASSERT_EQ("sink_1",c1.name());
149  Sink_2_Config const& c2 = dynamic_cast<Sink_2_Config const&>(c.exporters()[1].sink_config());
150  ASSERT_EQ("sink_2",c2.name());
151 }
152 
153 } // namespace test
154 } // namespace exporters
155 } // namespace cheetah
156 } // namespace ska
Configuration Object for DataExport module.
std::vector< DataExportStreamConfig > const & exporters() const
return a list of configured export streamer configurations
Base class for module configuration.
Definition: Config.h:42
Some limits and constants for FLDO.
Definition: Brdz.h:35