From 46fb0ea2149b05b52d4d27250403610d7a01ecb9 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 15 Apr 2014 14:54:39 +0200 Subject: [PATCH] Replacing some raw pointers by smart pointers --- .../gnss_block/file_output_filter_test.cc | 12 ++++++---- .../gnss_block/file_signal_source_test.cc | 11 ++++----- src/tests/gnss_block/fir_filter_test.cc | 24 +++++++++---------- src/tests/gnss_block/rtcm_printer_test.cc | 6 ++--- 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/src/tests/gnss_block/file_output_filter_test.cc b/src/tests/gnss_block/file_output_filter_test.cc index cdf9688bb..3b28d7bda 100644 --- a/src/tests/gnss_block/file_output_filter_test.cc +++ b/src/tests/gnss_block/file_output_filter_test.cc @@ -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 config = std::make_shared(); 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 output_filter(new FileOutputFilter(config.get(), "Test", 1, 0)); + unsigned int res = 0; + if (output_filter) res = 1; + ASSERT_EQ(1, res); } diff --git a/src/tests/gnss_block/file_signal_source_test.cc b/src/tests/gnss_block/file_signal_source_test.cc index 0b15b505a..d5a96b967 100644 --- a/src/tests/gnss_block/file_signal_source_test.cc +++ b/src/tests/gnss_block/file_signal_source_test.cc @@ -39,7 +39,7 @@ TEST(FileSignalSource, Instantiate) { boost::shared_ptr queue = gr::msg_queue::make(0); - InMemoryConfiguration* config = new InMemoryConfiguration(); + std::shared_ptr config = std::make_shared(); 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 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 queue = gr::msg_queue::make(0); - InMemoryConfiguration* config = new InMemoryConfiguration(); + std::shared_ptr config = std::make_shared(); 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); } diff --git a/src/tests/gnss_block/fir_filter_test.cc b/src/tests/gnss_block/fir_filter_test.cc index df536c821..80306af08 100644 --- a/src/tests/gnss_block/fir_filter_test.cc +++ b/src/tests/gnss_block/fir_filter_test.cc @@ -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(); item_size = sizeof(gr_complex); } ~Fir_Filter_Test() - { - delete config; - } + {} + void init(); boost::shared_ptr queue; gr::top_block_sptr top_block; - InMemoryConfiguration* config; + std::shared_ptr 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 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 filter = std::make_shared(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; } diff --git a/src/tests/gnss_block/rtcm_printer_test.cc b/src/tests/gnss_block/rtcm_printer_test.cc index c6c5d49ac..7c42b8199 100644 --- a/src/tests/gnss_block/rtcm_printer_test.cc +++ b/src/tests/gnss_block/rtcm_printer_test.cc @@ -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(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(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; }