1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-01-15 03:35:46 +00:00

Replacing some raw pointers by smart pointers

This commit is contained in:
Carles Fernandez 2014-04-15 14:54:39 +02:00
parent 307ae28d50
commit 46fb0ea214
4 changed files with 25 additions and 28 deletions

View File

@ -1,12 +1,12 @@
/*!
* \file file_output_filter_test.cc
* \brief This class implements a Unit Test for the class FileOutputFilter.
* \author Carlos Avilés, 2010. carlos.avilesr(at)googlemail.com
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
*
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2014 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
@ -35,11 +35,13 @@
TEST(FileOutputFilter, Instantiate)
{
InMemoryConfiguration* config = new InMemoryConfiguration();
std::shared_ptr<InMemoryConfiguration> config = std::make_shared<InMemoryConfiguration>();
std::string path = std::string(TEST_PATH);
std::string file = path + "data/output.dat";
config->set_property("Test.filename", file);
config->set_property("Test.item_type", "float");
FileOutputFilter *output_filter = new FileOutputFilter(config, "Test", 1, 0);
delete output_filter;
std::unique_ptr<FileOutputFilter> output_filter(new FileOutputFilter(config.get(), "Test", 1, 0));
unsigned int res = 0;
if (output_filter) res = 1;
ASSERT_EQ(1, res);
}

View File

@ -39,7 +39,7 @@
TEST(FileSignalSource, Instantiate)
{
boost::shared_ptr<gr::msg_queue> queue = gr::msg_queue::make(0);
InMemoryConfiguration* config = new InMemoryConfiguration();
std::shared_ptr<InMemoryConfiguration> config = std::make_shared<InMemoryConfiguration>();
config->set_property("Test.samples", "0");
config->set_property("Test.sampling_frequency", "0");
@ -49,19 +49,16 @@ TEST(FileSignalSource, Instantiate)
config->set_property("Test.item_type", "gr_complex");
config->set_property("Test.repeat", "false");
FileSignalSource *signal_source = new FileSignalSource(config, "Test", 1, 1, queue);
std::unique_ptr<FileSignalSource> signal_source(new FileSignalSource(config.get(), "Test", 1, 1, queue));
//EXPECT_STREQ("../src/tests/signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat", signal_source->filename().c_str());
EXPECT_STREQ("gr_complex", signal_source->item_type().c_str());
EXPECT_TRUE(signal_source->repeat() == false);
delete signal_source;
}
TEST(FileSignalSource, InstantiateFileNotExists)
{
boost::shared_ptr<gr::msg_queue> queue = gr::msg_queue::make(0);
InMemoryConfiguration* config = new InMemoryConfiguration();
std::shared_ptr<InMemoryConfiguration> config = std::make_shared<InMemoryConfiguration>();
config->set_property("Test.samples", "0");
config->set_property("Test.sampling_frequency", "0");
@ -69,5 +66,5 @@ TEST(FileSignalSource, InstantiateFileNotExists)
config->set_property("Test.item_type", "gr_complex");
config->set_property("Test.repeat", "false");
EXPECT_THROW(new FileSignalSource(config, "Test", 1, 1, queue), std::exception);
EXPECT_THROW(auto uptr(new FileSignalSource(config.get(), "Test", 1, 1, queue)), std::exception);
}

View File

@ -51,22 +51,22 @@ protected:
{
queue = gr::msg_queue::make(0);
top_block = gr::make_top_block("Fir filter test");
config = new InMemoryConfiguration();
config = std::make_shared<InMemoryConfiguration>();
item_size = sizeof(gr_complex);
}
~Fir_Filter_Test()
{
delete config;
}
{}
void init();
boost::shared_ptr<gr::msg_queue> queue;
gr::top_block_sptr top_block;
InMemoryConfiguration* config;
std::shared_ptr<InMemoryConfiguration> config;
size_t item_size;
};
void Fir_Filter_Test::init()
{
config->set_property("InputFilter.number_of_taps", "4");
config->set_property("InputFilter.number_of_bands", "2");
@ -92,8 +92,10 @@ void Fir_Filter_Test::init()
TEST_F(Fir_Filter_Test, Instantiate)
{
init();
FirFilter *filter = new FirFilter(config, "InputFilter", 1, 1, queue);
delete filter;
std::unique_ptr<FirFilter> filter(new FirFilter(config.get(), "InputFilter", 1, 1, queue));
unsigned int res = 0;
if (filter) res = 1;
ASSERT_EQ(1, res);
}
@ -107,7 +109,7 @@ TEST_F(Fir_Filter_Test, ConnectAndRun)
init();
FirFilter *filter = new FirFilter(config, "InputFilter", 1, 1, queue);
std::shared_ptr<FirFilter> filter = std::make_shared<FirFilter>(config.get(), "InputFilter", 1, 1, queue);
ASSERT_NO_THROW( {
filter->connect(top_block);
@ -126,8 +128,6 @@ TEST_F(Fir_Filter_Test, ConnectAndRun)
top_block->run(); // Start threads and wait
gettimeofday(&tv, NULL);
end = tv.tv_sec *1000000 + tv.tv_usec;
}) << "Failure running he top_block."<< std::endl;
std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl;
delete filter;
}) << "Failure running the top_block." << std::endl;
//std::cout << "Filtered " << nsamples << " samples in " << (end-begin) << " microseconds" << std::endl;
}

View File

@ -42,8 +42,7 @@ TEST(Rtcm_Printer_Test, Instantiate)
std::string filename = "hello.rtcm";
bool flag_rtcm_tty_port = false;
std::string rtcm_dump_devname = "/dev/pts/4";
Rtcm_Printer *RTCM_printer = new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname);
delete RTCM_printer;
std::unique_ptr<Rtcm_Printer> RTCM_printer(new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname));
}
TEST(Rtcm_Printer_Test, Instantiate_and_Run)
@ -68,10 +67,9 @@ TEST(Rtcm_Printer_Test, Instantiate_and_Run)
bool flag_rtcm_tty_port = false;
std::string rtcm_dump_devname = "/dev/pts/4";
Rtcm_Printer *RTCM_printer = new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname);
std::unique_ptr<Rtcm_Printer> RTCM_printer(new Rtcm_Printer(filename, flag_rtcm_tty_port, rtcm_dump_devname));
std::string reference_msg = "D300133ED7D30202980EDEEF34B4BD62AC0941986F33360B98";
std::string testing_msg = RTCM_printer->print_M1005_test();
EXPECT_EQ(reference_msg, testing_msg);
delete RTCM_printer;
}