1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 20:20:35 +00:00
gnss-sdr/tests/unit-tests/control-plane/file_configuration_test.cc

58 lines
2.2 KiB
C++
Raw Normal View History

/*!
* \file file_configuration_test.cc
* \brief This file implements tests for the file_configuration.
* \author Carles Fernandez-Prades, 2012. cfernandez(at)cttc.es
*
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
* This file is part of GNSS-SDR.
*
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
* SPDX-License-Identifier: GPL-3.0-or-later
*
2020-07-28 14:57:15 +00:00
* -----------------------------------------------------------------------------
*/
#include "file_configuration.h"
#include "gnss_sdr_make_unique.h"
#include <string>
#include <utility>
TEST(FileConfigurationTest, OverridedProperties)
{
std::string path = std::string(TEST_PATH);
std::string filename = path + "data/config_file_sample.txt";
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<FileConfiguration>(filename);
std::unique_ptr<ConfigurationInterface> configuration = std::make_unique<FileConfiguration>(filename);
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", std::move(default_value));
EXPECT_STREQ("Yes!", value.c_str());
}
TEST(FileConfigurationTest, LoadFromNonExistentFile)
{
std::unique_ptr<ConfigurationInterface> configuration = std::make_unique<FileConfiguration>("./i_dont_exist.conf");
std::string default_value = "default_value";
std::string value = configuration->property("whatever.whatever", std::move(default_value));
EXPECT_STREQ("default_value", value.c_str());
}
TEST(FileConfigurationTest, PropertyDoesNotExist)
{
std::string path = std::string(TEST_PATH);
std::string filename = path + "data/config_file_sample.txt";
std::unique_ptr<ConfigurationInterface> configuration = std::make_unique<FileConfiguration>(filename);
std::string default_value = "default_value";
std::string value = configuration->property("whatever.whatever", std::move(default_value));
EXPECT_STREQ("default_value", value.c_str());
}