Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SigProcHeaderTest.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/sigproc/test/SigProcHeaderTest.h"
25 #include "cheetah/sigproc/SigProcHeader.h"
26 #include "cheetah/utils/chrono.h"
27 #include "cheetah/data/Units.h"
28 
29 #include <sstream>
30 
31 namespace ska {
32 namespace cheetah {
33 namespace sigproc {
34 namespace test {
35 
36 
37 SigProcHeaderTest::SigProcHeaderTest()
38  : ::testing::Test()
39 {
40 }
41 
42 SigProcHeaderTest::~SigProcHeaderTest()
43 {
44 }
45 
46 void SigProcHeaderTest::SetUp()
47 {
48 }
49 
50 void SigProcHeaderTest::TearDown()
51 {
52 }
53 
54 // save a header to a stream and then restore it into a fresh SigProcHeader object which is returned
55 SigProcHeader save_restore(SigProcHeader const& h)
56 {
57  std::stringstream ss;
58  h.write(ss);
59  SigProcHeader r;
60  r.read(ss);
61  return r;
62 }
63 
64 TEST_F(SigProcHeaderTest, number_of_channels)
65 {
66  SigProcHeader h;
67  ASSERT_EQ(0, h.number_of_channels());
68  h.number_of_channels(332);
69  ASSERT_EQ(332, h.number_of_channels());
70  SigProcHeader h2 = save_restore(h);
71  ASSERT_EQ(h2.number_of_channels(), h.number_of_channels());
72 
73  h.reset();
74  ASSERT_EQ(0, h.number_of_channels());
75 }
76 
77 TEST_F(SigProcHeaderTest, number_of_bits)
78 {
79  SigProcHeader h;
80  ASSERT_EQ(0, h.number_of_bits());
81  h.number_of_bits(32);
82  ASSERT_EQ(32, h.number_of_bits());
83  SigProcHeader h2 = save_restore(h);
84  ASSERT_EQ(h2.number_of_bits(), h.number_of_bits());
85  h.reset();
86  ASSERT_EQ(0, h.number_of_bits());
87 }
88 
89 TEST_F(SigProcHeaderTest, test_start_time)
90 {
91  utils::TimePoint<utils::ModifiedJulianClock> epoch(utils::julian_day(0));
92  utils::TimePoint<utils::ModifiedJulianClock> t(utils::julian_day(12));
93  SigProcHeader h;
94  ASSERT_EQ(epoch, h.start_time());
95  h.start_time(t);
96  SigProcHeader h2 = save_restore(h);
97  ASSERT_EQ(h2.start_time(), h.start_time());
98  ASSERT_EQ(t, h.start_time());
99  h.reset();
100  ASSERT_EQ(epoch, h.start_time());
101 }
102 
103 TEST_F(SigProcHeaderTest, test_sample_interval)
104 {
105  SigProcHeader::TimeType zero = SigProcHeader::TimeType::from_value(0.0);
106  SigProcHeader::TimeType t = SigProcHeader::TimeType::from_value(20.0);
107  SigProcHeader h;
108  ASSERT_EQ(zero, h.sample_interval());
109  h.sample_interval(t);
110  SigProcHeader h2 = save_restore(h);
111  ASSERT_EQ(h2.sample_interval(), h.sample_interval());
112  ASSERT_EQ(t, h.sample_interval());
113  h.reset();
114  ASSERT_EQ(zero, h.sample_interval());
115 }
116 
117 TEST_F(SigProcHeaderTest, test_source_name)
118 {
119  std::string s("abc");
120  std::string empty;
121 
122  SigProcHeader h;
123  ASSERT_FALSE(h.source_name().is_set());
124  h.source_name(s);
125  ASSERT_EQ(s, *h.source_name());
126  SigProcHeader h2 = save_restore(h);
127  ASSERT_EQ(h2.source_name(), h.source_name());
128  h.reset();
129  ASSERT_FALSE(h.source_name().is_set());
130 }
131 
132 TEST_F(SigProcHeaderTest, test_size)
133 {
134  SigProcHeader h;
135  std::stringstream ss;
136  h.write(ss);
137 
138  SigProcHeader r;
139  r.read(ss);
140 
141  ASSERT_EQ(r.size(), ss.str().size());
142  ASSERT_EQ(r.size(), h.size());
143 }
144 
145 TEST_F(SigProcHeaderTest, test_frequency_array)
146 {
147  typedef typename SigProcHeader::FrequencyType FrequencyType;
148  std::vector<FrequencyType> channel_frequencies { FrequencyType(1.5 * data::hz), FrequencyType( 2.0 * data::hz) };
149 
150  SigProcHeader h;
151  h.frequency_channels(channel_frequencies);
152  ASSERT_EQ(h.frequency_channels(), channel_frequencies);
153 
154  std::stringstream ss;
155  h.write(ss);
156 
157  SigProcHeader r;
158  r.read(ss);
159 
160  ASSERT_EQ(h.frequency_channels(), r.frequency_channels());
161  ASSERT_EQ(channel_frequencies.size(), (unsigned)h.number_of_channels());
162  ASSERT_EQ(channel_frequencies.size(), (unsigned)r.number_of_channels());
163 
164  h.reset();
165  ASSERT_EQ(0U, h.frequency_channels().size());
166 }
167 
168 } // namespace test
169 } // namespace sigproc
170 } // namespace cheetah
171 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35