2012-01-23 00:52:05 +00:00
|
|
|
/*!
|
|
|
|
* \file file_configuration_test.cc
|
2013-02-17 09:54:41 +00:00
|
|
|
* \brief This file implements tests for the file_configuration.
|
2012-01-23 00:52:05 +00:00
|
|
|
* \author Carles Fernandez-Prades, 2012. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2012-01-23 00:52:05 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2012-01-23 00:52:05 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is a software defined Global Navigation
|
|
|
|
* Satellite Systems receiver
|
|
|
|
*
|
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2012-01-23 00:52:05 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
2012-01-23 00:52:05 +00:00
|
|
|
|
2011-10-01 18:45:20 +00:00
|
|
|
#include "file_configuration.h"
|
2020-06-18 09:49:28 +00:00
|
|
|
#include "gnss_sdr_make_unique.h"
|
2018-12-09 21:00:09 +00:00
|
|
|
#include <string>
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2012-01-23 00:52:05 +00:00
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(FileConfigurationTest, OverridedProperties)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
2014-03-23 09:45:03 +00:00
|
|
|
std::string path = std::string(TEST_PATH);
|
|
|
|
std::string filename = path + "data/config_file_sample.txt";
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<FileConfiguration>(filename);
|
2020-06-18 09:49:28 +00:00
|
|
|
std::unique_ptr<ConfigurationInterface> configuration = std::make_unique<FileConfiguration>(filename);
|
2013-02-17 09:54:41 +00:00
|
|
|
std::string default_value = "default_value";
|
|
|
|
std::string value = configuration->property("NotThere", default_value);
|
|
|
|
EXPECT_STREQ("default_value", value.c_str());
|
|
|
|
configuration->set_property("NotThere", "Yes!");
|
|
|
|
value = configuration->property("NotThere", default_value);
|
|
|
|
EXPECT_STREQ("Yes!", value.c_str());
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 00:52:05 +00:00
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(FileConfigurationTest, LoadFromNonExistentFile)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
std::unique_ptr<ConfigurationInterface> configuration = std::make_unique<FileConfiguration>("./i_dont_exist.conf");
|
2013-02-17 09:54:41 +00:00
|
|
|
std::string default_value = "default_value";
|
|
|
|
std::string value = configuration->property("whatever.whatever", default_value);
|
|
|
|
EXPECT_STREQ("default_value", value.c_str());
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2012-01-23 00:52:05 +00:00
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(FileConfigurationTest, PropertyDoesNotExist)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
2014-03-23 09:45:03 +00:00
|
|
|
std::string path = std::string(TEST_PATH);
|
|
|
|
std::string filename = path + "data/config_file_sample.txt";
|
2020-06-18 09:49:28 +00:00
|
|
|
std::unique_ptr<ConfigurationInterface> configuration = std::make_unique<FileConfiguration>(filename);
|
2013-02-17 09:54:41 +00:00
|
|
|
std::string default_value = "default_value";
|
|
|
|
std::string value = configuration->property("whatever.whatever", default_value);
|
|
|
|
EXPECT_STREQ("default_value", value.c_str());
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|