2013-02-17 09:54:41 +00:00
|
|
|
/*!
|
|
|
|
* \file in_memory_configuration_test.cc
|
|
|
|
* \brief This file implements tests for the in_memory_configuration.
|
|
|
|
* \author Carles Fernandez-Prades, 2013. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2013-02-17 09:54:41 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2013-02-17 09:54:41 +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
|
2013-02-17 09:54:41 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "configuration_interface.h"
|
2020-06-18 09:49:28 +00:00
|
|
|
#include "gnss_sdr_make_unique.h"
|
2011-10-01 18:45:20 +00:00
|
|
|
#include "in_memory_configuration.h"
|
2023-12-03 09:10:40 +00:00
|
|
|
#include <utility>
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, IsPresent)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<InMemoryConfiguration> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2013-02-17 09:54:41 +00:00
|
|
|
EXPECT_FALSE(configuration->is_present("NotThere"));
|
|
|
|
configuration->set_property("NotThere", "Yes!");
|
|
|
|
EXPECT_TRUE(configuration->is_present("NotThere"));
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, StoreAndRetrieve)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2014-04-03 21:59:14 +00:00
|
|
|
configuration->set_property("Foo.property1", "value");
|
2013-02-17 09:54:41 +00:00
|
|
|
std::string default_value = "default_value";
|
2023-12-03 09:10:40 +00:00
|
|
|
std::string value = configuration->property("Foo.property1", std::move(default_value));
|
2013-02-17 09:54:41 +00:00
|
|
|
EXPECT_STREQ("value", value.c_str());
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, NoStoringAndRetrieve)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2013-02-17 09:54:41 +00:00
|
|
|
std::string default_value = "default_value";
|
2023-12-03 09:10:40 +00:00
|
|
|
std::string value = configuration->property("Foo.property1", std::move(default_value));
|
2013-02-17 09:54:41 +00:00
|
|
|
EXPECT_STREQ("default_value", value.c_str());
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveBool)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2014-04-03 21:59:14 +00:00
|
|
|
configuration->set_property("Foo.property1", "true");
|
2013-02-17 09:54:41 +00:00
|
|
|
bool value = configuration->property("Foo.property1", false);
|
|
|
|
bool expectedtrue = true;
|
|
|
|
EXPECT_EQ(expectedtrue, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveBoolFail)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2014-04-03 21:59:14 +00:00
|
|
|
configuration->set_property("Foo.property1", "tru");
|
2013-02-17 09:54:41 +00:00
|
|
|
bool value = configuration->property("Foo.property1", false);
|
|
|
|
bool expectedfalse = false;
|
|
|
|
EXPECT_EQ(expectedfalse, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveBoolNoDefine)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2013-02-17 09:54:41 +00:00
|
|
|
bool value = configuration->property("Foo.property1", false);
|
|
|
|
bool expectedfalse = false;
|
|
|
|
EXPECT_EQ(expectedfalse, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveSizeT)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2014-04-03 21:59:14 +00:00
|
|
|
configuration->set_property("Foo.property1", "8");
|
2013-02-17 09:54:41 +00:00
|
|
|
unsigned int value = configuration->property("Foo.property1", 4);
|
|
|
|
unsigned int expected8 = 8;
|
|
|
|
EXPECT_EQ(expected8, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveSizeTFail)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2014-04-03 21:59:14 +00:00
|
|
|
configuration->set_property("Foo.property1", "true");
|
2013-02-17 09:54:41 +00:00
|
|
|
unsigned int value = configuration->property("Foo.property1", 4);
|
|
|
|
unsigned int expected4 = 4;
|
|
|
|
EXPECT_EQ(expected4, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
|
2014-04-03 21:59:14 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveSizeTNoDefine)
|
|
|
|
{
|
2019-08-18 23:29:04 +00:00
|
|
|
// std::shared_ptr<ConfigurationInterface> configuration = std::make_shared<InMemoryConfiguration>();
|
2020-06-18 09:49:28 +00:00
|
|
|
auto configuration = std::make_unique<InMemoryConfiguration>();
|
2013-02-17 09:54:41 +00:00
|
|
|
unsigned int value = configuration->property("Foo.property1", 4);
|
|
|
|
unsigned int expected4 = 4;
|
|
|
|
EXPECT_EQ(expected4, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|