2014-03-28 15:07:53 +00:00
|
|
|
//
|
|
|
|
|
// Copyright 2014 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2014-03-28 15:07:53 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2014-03-28 15:07:53 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <uhd/utils/cast.hpp>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
#include <iostream>
|
2014-03-28 15:07:53 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
BOOST_AUTO_TEST_CASE(test_mac_addr)
|
|
|
|
|
{
|
|
|
|
|
std::string in = "0x0100";
|
2016-10-31 21:30:52 +00:00
|
|
|
uint16_t correct_result = 256;
|
2019-01-14 18:35:25 +00:00
|
|
|
uint16_t x = uhd::cast::hexstr_cast<uint16_t>(in);
|
|
|
|
|
// uint16_t x = uhd::cast::hexstr_cast(in);
|
|
|
|
|
std::cout << "Testing hex -> uint16_t conversion. " << in << " == " << std::hex << x
|
|
|
|
|
<< "?" << std::endl;
|
2014-03-28 15:07:53 +00:00
|
|
|
BOOST_CHECK_EQUAL(x, correct_result);
|
|
|
|
|
}
|
2019-08-26 17:51:52 +00:00
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(test_from_str)
|
|
|
|
|
{
|
|
|
|
|
using namespace uhd::cast;
|
|
|
|
|
BOOST_CHECK_EQUAL(5.0, from_str<double>("5.0"));
|
|
|
|
|
BOOST_CHECK_EQUAL(23, from_str<int>("23"));
|
|
|
|
|
BOOST_CHECK_EQUAL("foo", from_str<std::string>("foo"));
|
|
|
|
|
}
|