Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
CheetahConfigTest.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/pipeline/test/CheetahConfigTest.h"
25 #include "cheetah/pipeline/CheetahConfig.h"
26 
27 #include "panda/test/TestFile.h"
28 
29 namespace ska {
30 namespace cheetah {
31 namespace pipeline {
32 namespace test {
33 
34 
35 CheetahConfigTest::CheetahConfigTest()
36  : ::testing::Test()
37 {
38 }
39 
40 CheetahConfigTest::~CheetahConfigTest()
41 {
42 }
43 
44 void CheetahConfigTest::SetUp()
45 {
46 }
47 
48 void CheetahConfigTest::TearDown()
49 {
50 }
51 
52 TEST_F(CheetahConfigTest, test_pipeline_handlers_unset)
53 {
54  pipeline::CheetahConfig<uint8_t> config;
55  ASSERT_EQ("", config.pipeline_name()); // check there is an empty pipeline default
56 
57  // test --pipeline option is set
58  char cmd[] = "cheetah_test";
59  char pipeline_option[] = "--pipeline";
60  char option[]="test_a";
61  char* argv[3] = { cmd, pipeline_option, option };
62  ASSERT_EQ(0, config.parse(3, argv));
63  config.parse(3, argv);
64 
65 }
66 
67 TEST_F(CheetahConfigTest, test_pipeline_handlers_set)
68 {
69  pipeline::CheetahConfig<uint8_t> config;
70  std::vector<std::string> handlers( { "test_a", "test_b", "test_c" } );
71  config.set_pipeline_handlers(handlers);
72 
73  // test --pipeline option
74  char cmd[] = "cheetah_test";
75  char pipeline_option[] = "--pipeline";
76  char option[10];
77  char* argv[3] = { cmd, pipeline_option, option };
78  for( auto const& handler : handlers ) {
79  strcpy(option, handler.c_str());
80  ASSERT_EQ(0, config.parse(3, argv));
81  ASSERT_EQ(handler, config.pipeline_name()); // check pipeline is set as we expect
82  }
83 }
84 
85 TEST_F(CheetahConfigTest, test_parse_no_arguments)
86 {
87  char** argv = nullptr;
88  pipeline::CheetahConfig<uint8_t> config;
89  ASSERT_NO_THROW(config.parse(0, argv));
90 
91  ASSERT_NE("", config.version()); // check there is a non empty version string
92  ASSERT_FALSE(config.time_handler_invocation()); // check timers are off by default
93  ASSERT_EQ("", config.pipeline_name()); // check pipeline no set
94  ASSERT_NE("", config.stream_name()); // check there is a no stream default
95 }
96 
97 TEST_F(CheetahConfigTest, test_specify_non_existing_config_file)
98 {
99  char cmd[] = "cheetah_test";
100  char config_option[] = "--config";
101  char empty_config[10] ="./rubbish";
102  char* argv[3] = { cmd, config_option, empty_config };
103  pipeline::CheetahConfig<uint8_t> config;
104  ASSERT_THROW(config.parse(3, argv), panda::Error);
105 }
106 
107 TEST_F(CheetahConfigTest, test_specify_existing_config_file)
108 {
109  char cmd[] = "cheetah_test";
110  char config_option[] = "--config";
111  panda::test::TestFile config_file("%%%%-%%%%-%%%%-%%%%.xml");
112 
113  char config_filename[32];
114  strcpy(config_filename, config_file.filename().c_str());
115  char* argv[3] = { cmd, config_option, config_filename };
116  pipeline::CheetahConfig<uint8_t> config;
117  std::vector<std::string> handlers( { "test_a", "test_b", "test_c" } );
118  config.set_pipeline_handlers(handlers);
119  ASSERT_THROW(config.parse(3, argv), panda::Error); // invalid (empty) config file
120 
121  // add some content
122  config_file << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
123  config_file << "<cheetah>\n";
124  config_file << "<pipeline>" << "test_b" << "</pipeline>\n";
125  config_file << "</cheetah>\n";
126  config_file.flush();
127  ASSERT_EQ("", config.pipeline_name()); // check pipeline no set
128  config.parse(3, argv);
129  ASSERT_EQ("test_b", config.pipeline_name()); // check pipeline no set
130 
131  // assert command line options override config file settings
132  char pipeline_option[] = "--pipeline";
133  char option[]="test_a";
134  char* argv_2[5] = { cmd, pipeline_option, option, config_option, config_filename };
135  config.parse(3, argv_2);
136  ASSERT_EQ("test_a", config.pipeline_name());
137 }
138 
139 } // namespace test
140 } // namespace pipeline
141 } // namespace cheetah
142 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35