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
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-07-26 10:38:20 +00:00
|
|
|
* Copyright (C) 2010-2019 (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.
|
|
|
|
*
|
|
|
|
* GNSS-SDR is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2015-01-08 18:49:59 +00:00
|
|
|
* (at your option) any later version.
|
2012-01-23 00:52:05 +00:00
|
|
|
*
|
|
|
|
* GNSS-SDR is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
2012-01-23 00:52:05 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2012-01-23 00:52:05 +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"
|
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";
|
2014-04-03 21:59:14 +00:00
|
|
|
//std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<FileConfiguration>(filename);
|
|
|
|
std::unique_ptr<ConfigurationInterface> configuration(new 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
|
|
|
{
|
2014-04-03 21:59:14 +00:00
|
|
|
std::unique_ptr<ConfigurationInterface> configuration(new 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";
|
2014-04-03 21:59:14 +00:00
|
|
|
std::unique_ptr<ConfigurationInterface> configuration(new 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
|
|
|
}
|