2012-01-23 00:52:05 +00:00
|
|
|
/*!
|
|
|
|
* \file string_converter_test.cc
|
2014-04-24 20:39:13 +00:00
|
|
|
* \brief This file implements unit tests for the StringConverter class.
|
2012-01-23 00:52:05 +00:00
|
|
|
* \author Carlos Aviles, 2010. carlos.avilesr(at)googlemail.com
|
|
|
|
* 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-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2012-01-23 00:52:05 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
2011-10-01 18:45:20 +00:00
|
|
|
*
|
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
|
2012-01-23 00:52:05 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2011-10-01 18:45:20 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-18 09:49:28 +00:00
|
|
|
#include "gnss_sdr_make_unique.h"
|
2011-10-01 18:45:20 +00:00
|
|
|
#include "string_converter.h"
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(StringConverterTest, StringToBool)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
auto converter = std::make_unique<StringConverter>();
|
2012-01-23 00:52:05 +00:00
|
|
|
bool conversion_result = converter->convert("false", true);
|
2012-01-25 03:25:39 +00:00
|
|
|
bool expected_false = false;
|
|
|
|
EXPECT_EQ(expected_false, conversion_result);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(StringConverterTest, StringToSizeT)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
2014-04-24 20:39:13 +00:00
|
|
|
// Example using a raw pointer
|
2012-01-25 03:16:08 +00:00
|
|
|
StringConverter* converter;
|
|
|
|
converter = new StringConverter();
|
2012-01-23 00:52:05 +00:00
|
|
|
size_t conversion_result = converter->convert("8", 1);
|
2012-01-25 03:25:39 +00:00
|
|
|
unsigned int expected8 = 8;
|
|
|
|
EXPECT_EQ(expected8, conversion_result);
|
2012-01-23 00:52:05 +00:00
|
|
|
delete converter;
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(StringConverterTest, StringToBoolFail)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
auto converter = std::make_unique<StringConverter>();
|
2012-01-23 00:52:05 +00:00
|
|
|
bool conversion_result = converter->convert("lse", true);
|
2012-01-25 03:25:39 +00:00
|
|
|
bool expected_true = true;
|
|
|
|
EXPECT_EQ(expected_true, conversion_result);
|
2011-10-01 18:45:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-25 20:53:11 +00:00
|
|
|
TEST(StringConverterTest, StringToSizeTFail)
|
2012-01-23 00:52:05 +00:00
|
|
|
{
|
2020-06-18 09:49:28 +00:00
|
|
|
auto converter = std::make_unique<StringConverter>();
|
2012-01-23 00:52:05 +00:00
|
|
|
size_t conversion_result = converter->convert("false", 1);
|
2012-01-25 03:16:08 +00:00
|
|
|
unsigned int expected1 = 1;
|
|
|
|
EXPECT_EQ(expected1, conversion_result);
|
2012-01-23 00:52:05 +00:00
|
|
|
}
|