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
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2013 (see AUTHORS file for a list of contributors)
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
2013-02-17 09:54:41 +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
|
|
|
|
* at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "configuration_interface.h"
|
|
|
|
#include "in_memory_configuration.h"
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, IsPresent)
|
|
|
|
{
|
|
|
|
InMemoryConfiguration *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
EXPECT_FALSE(configuration->is_present("NotThere"));
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
configuration->set_property("NotThere", "Yes!");
|
|
|
|
EXPECT_TRUE(configuration->is_present("NotThere"));
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, StoreAndRetrieve)
|
|
|
|
{
|
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
((InMemoryConfiguration*)configuration)->set_property("Foo.property1", "value");
|
|
|
|
std::string default_value = "default_value";
|
|
|
|
std::string value = configuration->property("Foo.property1", default_value);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
EXPECT_STREQ("value", value.c_str());
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, NoStoringAndRetrieve)
|
|
|
|
{
|
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
|
|
|
std::string default_value = "default_value";
|
|
|
|
std::string value = configuration->property("Foo.property1", default_value);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
EXPECT_STREQ("default_value", value.c_str());
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveBool)
|
|
|
|
{
|
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
((InMemoryConfiguration*)configuration)->set_property("Foo.property1", "true");
|
|
|
|
bool value = configuration->property("Foo.property1", false);
|
|
|
|
bool expectedtrue = true;
|
|
|
|
EXPECT_EQ(expectedtrue, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveBoolFail)
|
|
|
|
{
|
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
((InMemoryConfiguration*)configuration)->set_property("Foo.property1", "tru");
|
|
|
|
bool value = configuration->property("Foo.property1", false);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
bool expectedfalse = false;
|
|
|
|
EXPECT_EQ(expectedfalse, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveBoolNoDefine)
|
|
|
|
{
|
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
bool value = configuration->property("Foo.property1", false);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
bool expectedfalse = false;
|
|
|
|
EXPECT_EQ(expectedfalse, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveSizeT)
|
|
|
|
{
|
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
((InMemoryConfiguration*)configuration)->set_property("Foo.property1", "8");
|
|
|
|
unsigned int value = configuration->property("Foo.property1", 4);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
unsigned int expected8 = 8;
|
|
|
|
EXPECT_EQ(expected8, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
TEST(InMemoryConfiguration, RetrieveSizeTFail)
|
|
|
|
{
|
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
((InMemoryConfiguration*)configuration)->set_property("Foo.property1", "true");
|
|
|
|
unsigned int value = configuration->property("Foo.property1", 4);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
unsigned int expected4 = 4;
|
|
|
|
EXPECT_EQ(expected4, value);
|
2011-10-01 18:45:20 +00:00
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(InMemoryConfiguration, RetrieveSizeTNoDefine) {
|
2013-02-17 09:54:41 +00:00
|
|
|
ConfigurationInterface *configuration = new InMemoryConfiguration();
|
2011-10-01 18:45:20 +00:00
|
|
|
|
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
|
|
|
|
2013-02-17 09:54:41 +00:00
|
|
|
delete configuration;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|