aboutsummaryrefslogtreecommitdiffstats
path: root/host/tests/convert_test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'host/tests/convert_test.cpp')
-rw-r--r--host/tests/convert_test.cpp163
1 files changed, 159 insertions, 4 deletions
diff --git a/host/tests/convert_test.cpp b/host/tests/convert_test.cpp
index d71d756dd..8d359d2e2 100644
--- a/host/tests/convert_test.cpp
+++ b/host/tests/convert_test.cpp
@@ -417,16 +417,16 @@ BOOST_AUTO_TEST_CASE(test_convert_types_sc16_and_sc8){
}
/***********************************************************************
- * Test short conversion
+ * Test u8 conversion
**********************************************************************/
static void test_convert_types_u8(
size_t nsamps, convert::id_type &id
){
//fill the input samples
std::vector<boost::uint8_t> input(nsamps), output(nsamps);
- //BOOST_FOREACH(boost::uint8_t &in, input) in = boost::uint8_t(std::rand() & 0xFF);
- boost::uint32_t d = 48;
- BOOST_FOREACH(boost::uint8_t &in, input) in = d++;
+ BOOST_FOREACH(boost::uint8_t &in, input) in = boost::uint8_t(std::rand() & 0xFF);
+ //boost::uint32_t d = 48;
+ //BOOST_FOREACH(boost::uint8_t &in, input) in = d++;
//run the loopback and test
convert::id_type in_id = id;
@@ -455,3 +455,158 @@ BOOST_AUTO_TEST_CASE(test_convert_types_u8_and_u8){
test_convert_types_u8(nsamps, id);
}
}
+
+/***********************************************************************
+ * Test s8 conversion
+ **********************************************************************/
+static void test_convert_types_s8(
+ size_t nsamps, convert::id_type &id
+){
+ //fill the input samples
+ std::vector<boost::int8_t> input(nsamps), output(nsamps);
+ BOOST_FOREACH(boost::int8_t &in, input) in = boost::int8_t(std::rand() & 0xFF);
+
+ //run the loopback and test
+ convert::id_type in_id = id;
+ convert::id_type out_id = id;
+ std::swap(out_id.input_format, out_id.output_format);
+ std::swap(out_id.num_inputs, out_id.num_outputs);
+ loopback(nsamps, in_id, out_id, input, output);
+ BOOST_CHECK_EQUAL_COLLECTIONS(input.begin(), input.end(), output.begin(), output.end());
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_s8_and_s8){
+ convert::id_type id;
+ id.input_format = "s8";
+ id.num_inputs = 1;
+ id.num_outputs = 1;
+
+ //try various lengths to test edge cases
+ id.output_format = "s8_item32_le";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_s8(nsamps, id);
+ }
+
+ //try various lengths to test edge cases
+ id.output_format = "s8_item32_be";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_s8(nsamps, id);
+ }
+}
+
+/***********************************************************************
+ * Test s16 conversion
+ **********************************************************************/
+static void test_convert_types_s16(
+ size_t nsamps, convert::id_type &id
+){
+ //fill the input samples
+ std::vector<boost::int16_t> input(nsamps), output(nsamps);
+ BOOST_FOREACH(boost::int16_t &in, input) in = boost::int16_t(std::rand() & 0xFFFF);
+
+ //run the loopback and test
+ convert::id_type in_id = id;
+ convert::id_type out_id = id;
+ std::swap(out_id.input_format, out_id.output_format);
+ std::swap(out_id.num_inputs, out_id.num_outputs);
+ loopback(nsamps, in_id, out_id, input, output);
+ BOOST_CHECK_EQUAL_COLLECTIONS(input.begin(), input.end(), output.begin(), output.end());
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_s16_and_s16){
+ convert::id_type id;
+ id.input_format = "s16";
+ id.num_inputs = 1;
+ id.num_outputs = 1;
+
+ //try various lengths to test edge cases
+ id.output_format = "s16_item32_le";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_s16(nsamps, id);
+ }
+
+ //try various lengths to test edge cases
+ id.output_format = "s16_item32_be";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_s16(nsamps, id);
+ }
+}
+
+/***********************************************************************
+ * Test fc32 -> fc32 conversion
+ **********************************************************************/
+static void test_convert_types_fc32(
+ size_t nsamps, convert::id_type &id
+){
+ //fill the input samples
+ std::vector< std::complex<float> > 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
+ );
+
+ //run the loopback and test
+ convert::id_type in_id = id;
+ convert::id_type out_id = id;
+ std::swap(out_id.input_format, out_id.output_format);
+ std::swap(out_id.num_inputs, out_id.num_outputs);
+ loopback(nsamps, in_id, out_id, input, output);
+ BOOST_CHECK_EQUAL_COLLECTIONS(input.begin(), input.end(), output.begin(), output.end());
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_fc32_and_fc32){
+ convert::id_type id;
+ id.input_format = "fc32";
+ id.num_inputs = 1;
+ id.num_outputs = 1;
+
+ //try various lengths to test edge cases
+ id.output_format = "fc32_item32_le";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_fc32(nsamps, id);
+ }
+
+ //try various lengths to test edge cases
+ id.output_format = "fc32_item32_be";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_fc32(nsamps, id);
+ }
+}
+
+/***********************************************************************
+ * Test f32 -> f32 conversion
+ **********************************************************************/
+static void test_convert_types_f32(
+ size_t nsamps, convert::id_type &id
+){
+ //fill the input samples
+ std::vector<float> input(nsamps), output(nsamps);
+ BOOST_FOREACH(float &in, input) in = float((std::rand()/float(RAND_MAX/2)) - 1);
+
+ //run the loopback and test
+ convert::id_type in_id = id;
+ convert::id_type out_id = id;
+ std::swap(out_id.input_format, out_id.output_format);
+ std::swap(out_id.num_inputs, out_id.num_outputs);
+ loopback(nsamps, in_id, out_id, input, output);
+ BOOST_CHECK_EQUAL_COLLECTIONS(input.begin(), input.end(), output.begin(), output.end());
+}
+
+BOOST_AUTO_TEST_CASE(test_convert_types_f32_and_f32){
+ convert::id_type id;
+ id.input_format = "f32";
+ id.num_inputs = 1;
+ id.num_outputs = 1;
+
+ //try various lengths to test edge cases
+ id.output_format = "f32_item32_le";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_f32(nsamps, id);
+ }
+
+ //try various lengths to test edge cases
+ id.output_format = "f32_item32_be";
+ for (size_t nsamps = 1; nsamps < 16; nsamps++){
+ test_convert_types_f32(nsamps, id);
+ }
+}