1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-25 22:43:14 +00:00

Avoid null pointer dereference warning from cppcheck

This commit is contained in:
Carles Fernandez 2020-07-12 12:46:13 +02:00
parent c178d9a8a6
commit d5972398c3
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D

View File

@ -27,6 +27,7 @@
#include "concurrent_queue.h"
#include "gnss_block_factory.h"
#include "gnss_block_interface.h"
#include "gnss_sdr_make_unique.h"
#include "in_memory_configuration.h"
#include "observables_interface.h"
#include "pvt_interface.h"
@ -59,7 +60,7 @@ TEST(GNSSBlockFactoryTest, InstantiateWrongSignalSource)
configuration->set_property("SignalSource.implementation", "Pepito");
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
// Example of a factory as a unique_ptr
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
// Example of a block as a unique_ptr
std::unique_ptr<GNSSBlockInterface> signal_source = factory->GetSignalSource(configuration.get(), queue.get());
EXPECT_EQ(nullptr, signal_source);
@ -70,7 +71,7 @@ TEST(GNSSBlockFactoryTest, InstantiateSignalConditioner)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("SignalConditioner.implementation", "Signal_Conditioner");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> signal_conditioner = factory->GetSignalConditioner(configuration.get());
EXPECT_STREQ("SignalConditioner", signal_conditioner->role().c_str());
EXPECT_STREQ("Signal_Conditioner", signal_conditioner->implementation().c_str());
@ -103,7 +104,7 @@ TEST(GNSSBlockFactoryTest, InstantiateFIRFilter)
configuration->set_property("InputFilter.filter_type", "bandpass");
configuration->set_property("InputFilter.grid_density", "16");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> input_filter = factory->GetBlock(configuration.get(), "InputFilter", "Fir_Filter", 1, 1);
EXPECT_STREQ("InputFilter", input_filter->role().c_str());
@ -138,7 +139,7 @@ TEST(GNSSBlockFactoryTest, InstantiateFreqXlatingFIRFilter)
configuration->set_property("InputFilter.sampling_frequency", "4000000");
configuration->set_property("InputFilter.IF", "34000");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> input_filter = factory->GetBlock(configuration.get(), "InputFilter", "Freq_Xlating_Fir_Filter", 1, 1);
EXPECT_STREQ("InputFilter", input_filter->role().c_str());
@ -151,7 +152,7 @@ TEST(GNSSBlockFactoryTest, InstantiatePulseBlankingFilter)
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
configuration->set_property("InputFilter.implementation", "Pulse_Blanking_Filter");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> input_filter = factory->GetBlock(configuration.get(), "InputFilter", "Pulse_Blanking_Filter", 1, 1);
EXPECT_STREQ("InputFilter", input_filter->role().c_str());
@ -164,7 +165,7 @@ TEST(GNSSBlockFactoryTest, InstantiateNotchFilter)
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
configuration->set_property("InputFilter.implementation", "Notch_Filter");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> input_filter = factory->GetBlock(configuration.get(), "InputFilter", "Notch_Filter", 1, 1);
EXPECT_STREQ("InputFilter", input_filter->role().c_str());
@ -177,7 +178,7 @@ TEST(GNSSBlockFactoryTest, InstantiateNotchFilterLite)
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
configuration->set_property("InputFilter.implementation", "Notch_Filter_Lite");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> input_filter = factory->GetBlock(configuration.get(), "InputFilter", "Notch_Filter_Lite", 1, 1);
EXPECT_STREQ("InputFilter", input_filter->role().c_str());
@ -188,7 +189,7 @@ TEST(GNSSBlockFactoryTest, InstantiateDirectResampler)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Resampler.implementation", "Direct_Resampler");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> resampler = factory->GetBlock(configuration.get(), "Resampler", "Direct_Resampler", 1, 1);
EXPECT_STREQ("Resampler", resampler->role().c_str());
EXPECT_STREQ("Direct_Resampler", resampler->implementation().c_str());
@ -198,7 +199,7 @@ TEST(GNSSBlockFactoryTest, InstantiateGpsL1CaPcpsAcquisition)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Acquisition.implementation", "GPS_L1_CA_PCPS_Acquisition");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> acq_ = factory->GetBlock(configuration.get(), "Acquisition", "GPS_L1_CA_PCPS_Acquisition", 1, 0);
std::shared_ptr<AcquisitionInterface> acquisition = std::dynamic_pointer_cast<AcquisitionInterface>(acq_);
EXPECT_STREQ("Acquisition", acquisition->role().c_str());
@ -233,7 +234,7 @@ TEST(GNSSBlockFactoryTest, InstantiateGalileoE1PcpsAmbiguousAcquisition)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Acquisition.implementation", "Galileo_E1_PCPS_Ambiguous_Acquisition");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> acq_ = factory->GetBlock(configuration.get(), "Acquisition", "Galileo_E1_PCPS_Ambiguous_Acquisition", 1, 0);
std::shared_ptr<AcquisitionInterface> acquisition = std::dynamic_pointer_cast<AcquisitionInterface>(acq_);
EXPECT_STREQ("Acquisition", acquisition->role().c_str());
@ -245,7 +246,7 @@ TEST(GNSSBlockFactoryTest, InstantiateGpsL1CaDllPllTracking)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Tracking.implementation", "GPS_L1_CA_DLL_PLL_Tracking");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> trk_ = factory->GetBlock(configuration.get(), "Tracking", "GPS_L1_CA_DLL_PLL_Tracking", 1, 1);
std::shared_ptr<TrackingInterface> tracking = std::dynamic_pointer_cast<TrackingInterface>(trk_);
EXPECT_STREQ("Tracking", tracking->role().c_str());
@ -257,7 +258,7 @@ TEST(GNSSBlockFactoryTest, InstantiateGpsL1CaTcpConnectorTracking)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Tracking.implementation", "GPS_L1_CA_TCP_CONNECTOR_Tracking");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> trk_ = factory->GetBlock(configuration.get(), "Tracking", "GPS_L1_CA_TCP_CONNECTOR_Tracking", 1, 1);
std::shared_ptr<TrackingInterface> tracking = std::dynamic_pointer_cast<TrackingInterface>(trk_);
EXPECT_STREQ("Tracking", tracking->role().c_str());
@ -269,7 +270,7 @@ TEST(GNSSBlockFactoryTest, InstantiateGalileoE1DllPllVemlTracking)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Tracking.implementation", "Galileo_E1_DLL_PLL_VEML_Tracking");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> trk_ = factory->GetBlock(configuration.get(), "Tracking", "Galileo_E1_DLL_PLL_VEML_Tracking", 1, 1);
std::shared_ptr<TrackingInterface> tracking = std::dynamic_pointer_cast<TrackingInterface>(trk_);
EXPECT_STREQ("Tracking", tracking->role().c_str());
@ -281,7 +282,7 @@ TEST(GNSSBlockFactoryTest, InstantiateGpsL1CaTelemetryDecoder)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("TelemetryDecoder.implementation", "GPS_L1_CA_Telemetry_Decoder");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> telemetry_decoder = factory->GetBlock(configuration.get(), "TelemetryDecoder", "GPS_L1_CA_Telemetry_Decoder", 1, 1);
EXPECT_STREQ("TelemetryDecoder", telemetry_decoder->role().c_str());
EXPECT_STREQ("GPS_L1_CA_Telemetry_Decoder", telemetry_decoder->implementation().c_str());
@ -300,7 +301,7 @@ TEST(GNSSBlockFactoryTest, InstantiateChannels)
configuration->set_property("Acquisition_1C.implementation", "GPS_L1_CA_PCPS_Acquisition");
configuration->set_property("Channel1.item_type", "gr_complex");
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<std::vector<std::unique_ptr<GNSSBlockInterface>>> channels = factory->GetChannels(configuration.get(), queue.get());
EXPECT_EQ(static_cast<unsigned int>(2), channels->size());
channels->erase(channels->begin(), channels->end());
@ -311,7 +312,7 @@ TEST(GNSSBlockFactoryTest, InstantiateObservables)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Observables.implementation", "Pass_Through");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
auto observables = factory->GetObservables(configuration.get());
EXPECT_STREQ("Observables", observables->role().c_str());
EXPECT_STREQ("Pass_Through", observables->implementation().c_str());
@ -322,7 +323,7 @@ TEST(GNSSBlockFactoryTest, InstantiateGpsL1CaObservables)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("Observables.implementation", "Hybrid_Observables");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::unique_ptr<GNSSBlockInterface> observables = factory->GetObservables(configuration.get());
EXPECT_STREQ("Observables", observables->role().c_str());
EXPECT_STREQ("Hybrid_Observables", observables->implementation().c_str());
@ -333,7 +334,7 @@ TEST(GNSSBlockFactoryTest, InstantiateRTKLIBPvt)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("PVT.implementation", "RTKLIB_PVT");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> pvt_ = factory->GetPVT(configuration.get());
std::shared_ptr<PvtInterface> pvt = std::dynamic_pointer_cast<PvtInterface>(pvt_);
EXPECT_STREQ("PVT", pvt->role().c_str());
@ -345,7 +346,7 @@ TEST(GNSSBlockFactoryTest, InstantiateWrongPvt)
{
std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
configuration->set_property("PVT.implementation", "Pepito");
std::unique_ptr<GNSSBlockFactory> factory;
std::unique_ptr<GNSSBlockFactory> factory = std::make_unique<GNSSBlockFactory>();
std::shared_ptr<GNSSBlockInterface> pvt_ = factory->GetPVT(configuration.get());
std::shared_ptr<PvtInterface> pvt = std::dynamic_pointer_cast<PvtInterface>(pvt_);
EXPECT_EQ(nullptr, pvt);