2012-06-22 14:17:28 +00:00
|
|
|
/*!
|
|
|
|
* \file file_signal_source_test.cc
|
|
|
|
* \brief This class implements a Unit Test for the class FileSignalSource.
|
|
|
|
* \author Carlos Avilés, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2012-06-22 14:17:28 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2012-06-22 14:17:28 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
2019-07-16 15:41:12 +00:00
|
|
|
#include "concurrent_queue.h"
|
2019-07-26 10:38:20 +00:00
|
|
|
#include "file_signal_source.h"
|
2020-06-18 09:49:28 +00:00
|
|
|
#include "gnss_sdr_make_unique.h"
|
2019-07-17 13:56:30 +00:00
|
|
|
#include "in_memory_configuration.h"
|
2013-07-04 13:47:40 +00:00
|
|
|
#include <gnuradio/top_block.h>
|
2014-12-19 22:19:50 +00:00
|
|
|
#include <gtest/gtest.h>
|
2018-12-09 21:00:09 +00:00
|
|
|
#include <stdexcept>
|
2023-12-03 09:10:40 +00:00
|
|
|
#include <utility>
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2012-10-28 08:43:48 +00:00
|
|
|
TEST(FileSignalSource, Instantiate)
|
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
auto queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
|
|
|
|
auto config = std::make_shared<InMemoryConfiguration>();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
config->set_property("Test.samples", "0");
|
|
|
|
config->set_property("Test.sampling_frequency", "0");
|
2014-03-23 09:45:03 +00:00
|
|
|
std::string path = std::string(TEST_PATH);
|
|
|
|
std::string filename = path + "signal_samples/GPS_L1_CA_ID_1_Fs_4Msps_2ms.dat";
|
2023-12-03 09:10:40 +00:00
|
|
|
config->set_property("Test.filename", std::move(filename));
|
2013-07-04 13:47:40 +00:00
|
|
|
config->set_property("Test.item_type", "gr_complex");
|
|
|
|
config->set_property("Test.repeat", "false");
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
auto signal_source = std::make_unique<FileSignalSource>(config.get(), "Test", 0, 1, queue.get());
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
EXPECT_STREQ("gr_complex", signal_source->item_type().c_str());
|
|
|
|
EXPECT_TRUE(signal_source->repeat() == false);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2012-10-28 08:43:48 +00:00
|
|
|
TEST(FileSignalSource, InstantiateFileNotExists)
|
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
auto queue = std::make_shared<Concurrent_Queue<pmt::pmt_t>>();
|
|
|
|
auto config = std::make_shared<InMemoryConfiguration>();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-07-04 13:47:40 +00:00
|
|
|
config->set_property("Test.samples", "0");
|
|
|
|
config->set_property("Test.sampling_frequency", "0");
|
|
|
|
config->set_property("Test.filename", "./signal_samples/i_dont_exist.dat");
|
|
|
|
config->set_property("Test.item_type", "gr_complex");
|
|
|
|
config->set_property("Test.repeat", "false");
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2021-02-15 22:33:16 +00:00
|
|
|
// the file existence test was moved from the ctor to the connect() call. The argument to
|
|
|
|
// connect doesn't matter, since the exception should be thrown sooner than any connections
|
|
|
|
auto top = gr::make_top_block("GNSSUnitTest");
|
|
|
|
auto uptr = std::make_shared<FileSignalSource>(config.get(), "Test", 0, 1, queue.get());
|
2023-12-03 09:10:40 +00:00
|
|
|
EXPECT_THROW({ uptr->connect(std::move(top)); }, std::exception);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|