Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
SclFileStreamerTest.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/SclFileStreamerTest.h"
25 #include "cheetah/exporters/SclFileStreamer.h"
26 #include "panda/test/TestDir.h"
27 #include <climits>
28 #include <unistd.h>
29 
30 
31 namespace ska {
32 namespace cheetah {
33 namespace exporters {
34 namespace test {
35 
36 
37 SclFileStreamerTest::SclFileStreamerTest()
38  : ::testing::Test()
39 {
40 }
41 
42 SclFileStreamerTest::~SclFileStreamerTest()
43 {
44 }
45 
46 void SclFileStreamerTest::SetUp()
47 {
48 }
49 
50 void SclFileStreamerTest::TearDown()
51 {
52 }
53 
54 TEST_F(SclFileStreamerTest, test_write_read)
55 {
56  data::Scl d1;
57  panda::test::TestDir tmp_dir;
58  ASSERT_NO_THROW(tmp_dir.create());
59  //set the candidate DM
60  typename data::Scl::CandidateType::Dm dm(12.0 * data::parsecs_per_cube_cm);
61  //set the candidate width
62  data::Scl::CandidateType::MsecTimeType width(0.001 * boost::units::si::seconds);
63  //set the candidate period
64  data::Scl::CandidateType::MsecTimeType period(2.0 * boost::units::si::seconds);
65  //set the candidate period derivative
66  data::Scl::CandidateType::SecPerSecType pdot(1e-4);
67  float sigma = 20.0;
68 
69  for (auto idx=0; idx<10; ++idx)
70  {
71  data::Scl::CandidateType candidate(period, pdot, dm, width, sigma, idx);
72  d1.push_back(candidate);
73  }
74 
75  SclFileStreamerConfig config;
76  config.dir(tmp_dir.dir_name());
77  SclFileStreamer writer(config);
78  writer << d1;
79  sync(); // ensure the OS actually writes to disc
80  auto it = boost::filesystem::directory_iterator(tmp_dir.path());
81 
82  //To check if directory created exists in the necessary path
83  ASSERT_FALSE(it == boost::filesystem::directory_iterator());
84  ASSERT_TRUE(boost::filesystem::exists(it->path()));
85 
86 }
87 
88 } // namespace test
89 } // namespace sps
90 } // namespace cheetah
91 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35