From 43b19815fec253dc7e5538329f9fe1363f007b8a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 3 Feb 2011 16:45:34 -0800 Subject: uhd: added io type and conversion for complex64 (its not really useful) --- host/tests/convert_test.cpp | 46 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'host/tests') diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp index 5f2aaf3d1..d3c235e9b 100644 --- a/host/tests/convert_test.cpp +++ b/host/tests/convert_test.cpp @@ -29,6 +29,7 @@ using namespace uhd; //typedefs for complex types typedef std::complex sc16_t; typedef std::complex fc32_t; +typedef std::complex fc64_t; #define MY_CHECK_CLOSE(a, b, f) if ((std::abs(a) > (f) and std::abs(b) > (f))) \ BOOST_CHECK_CLOSE_FRACTION(a, b, f) @@ -109,23 +110,26 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_sc16){ /*********************************************************************** * Test float conversion **********************************************************************/ -static void test_convert_types_fc32( +template +static void test_convert_types_for_floats( size_t nsamps, const io_type_t &io_type, const otw_type_t &otw_type ){ + typedef typename data_type::value_type value_type; + //fill the input samples - std::vector input(nsamps), output(nsamps); - BOOST_FOREACH(fc32_t &in, input) in = fc32_t( - (std::rand()/float(RAND_MAX/2)) - 1, - (std::rand()/float(RAND_MAX/2)) - 1 + std::vector input(nsamps), output(nsamps); + BOOST_FOREACH(data_type &in, input) in = data_type( + (std::rand()/value_type(RAND_MAX/2)) - 1, + (std::rand()/value_type(RAND_MAX/2)) - 1 ); //run the loopback and test loopback(nsamps, io_type, otw_type, input, output); for (size_t i = 0; i < nsamps; i++){ - MY_CHECK_CLOSE(input[i].real(), output[i].real(), float(0.01)); - MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), float(0.01)); + MY_CHECK_CLOSE(input[i].real(), output[i].real(), value_type(0.01)); + MY_CHECK_CLOSE(input[i].imag(), output[i].imag(), value_type(0.01)); } } @@ -137,7 +141,7 @@ BOOST_AUTO_TEST_CASE(test_convert_types_be_fc32){ //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_fc32(nsamps, io_type, otw_type); + test_convert_types_for_floats(nsamps, io_type, otw_type); } } @@ -149,7 +153,31 @@ BOOST_AUTO_TEST_CASE(test_convert_types_le_fc32){ //try various lengths to test edge cases for (size_t nsamps = 1; nsamps < 16; nsamps++){ - test_convert_types_fc32(nsamps, io_type, otw_type); + test_convert_types_for_floats(nsamps, io_type, otw_type); + } +} + +BOOST_AUTO_TEST_CASE(test_convert_types_be_fc64){ + io_type_t io_type(io_type_t::COMPLEX_FLOAT64); + otw_type_t otw_type; + otw_type.byteorder = otw_type_t::BO_BIG_ENDIAN; + otw_type.width = 16; + + //try various lengths to test edge cases + for (size_t nsamps = 1; nsamps < 16; nsamps++){ + test_convert_types_for_floats(nsamps, io_type, otw_type); + } +} + +BOOST_AUTO_TEST_CASE(test_convert_types_le_fc64){ + io_type_t io_type(io_type_t::COMPLEX_FLOAT64); + otw_type_t otw_type; + otw_type.byteorder = otw_type_t::BO_LITTLE_ENDIAN; + otw_type.width = 16; + + //try various lengths to test edge cases + for (size_t nsamps = 1; nsamps < 16; nsamps++){ + test_convert_types_for_floats(nsamps, io_type, otw_type); } } -- cgit v1.2.3