2010-03-15 15:11:48 -04:00
|
|
|
#include "tests/utils.h"
|
|
|
|
|
|
|
|
#include "audiographer/general/interleaver.h"
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
using namespace AudioGrapher;
|
|
|
|
|
|
|
|
class InterleaverTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE (InterleaverTest);
|
|
|
|
CPPUNIT_TEST (testUninitialized);
|
|
|
|
CPPUNIT_TEST (testInvalidInputIndex);
|
|
|
|
CPPUNIT_TEST (testInvalidInputSize);
|
|
|
|
CPPUNIT_TEST (testOutputSize);
|
|
|
|
CPPUNIT_TEST (testZeroInput);
|
|
|
|
CPPUNIT_TEST (testChannelSync);
|
|
|
|
CPPUNIT_TEST_SUITE_END ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
|
|
|
channels = 3;
|
2017-09-18 12:39:17 -04:00
|
|
|
samples = 128;
|
|
|
|
random_data = TestUtils::init_random_data (samples, 1.0);
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
interleaver.reset (new Interleaver<float>());
|
|
|
|
sink.reset (new VectorSink<float>());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
interleaver->init (channels, samples);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
delete [] random_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testUninitialized()
|
|
|
|
{
|
|
|
|
interleaver.reset (new Interleaver<float>());
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input(0)->process (c), Exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testInvalidInputIndex()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (3)->process (c), Exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testInvalidInputSize()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples + 1, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
interleaver->input (0)->process (c.beginning (samples));
|
|
|
|
interleaver->input (1)->process (c.beginning (samples));
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (samples - 1)), Exception);
|
2009-12-27 09:46:23 -05:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
interleaver->input (0)->process (c.beginning (samples - 1));
|
|
|
|
interleaver->input (1)->process (c.beginning (samples - 1));
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (samples)), Exception);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testOutputSize()
|
|
|
|
{
|
|
|
|
interleaver->add_output (sink);
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
interleaver->input (0)->process (c);
|
|
|
|
interleaver->input (1)->process (c);
|
|
|
|
interleaver->input (2)->process (c);
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t expected_samples = samples * channels;
|
|
|
|
samplecnt_t generated_samples = sink->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples);
|
2009-12-27 09:46:23 -05:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t less_samples = samples / 2;
|
|
|
|
interleaver->input (0)->process (c.beginning (less_samples));
|
|
|
|
interleaver->input (1)->process (c.beginning (less_samples));
|
|
|
|
interleaver->input (2)->process (c.beginning (less_samples));
|
2009-12-27 09:46:23 -05:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
expected_samples = less_samples * channels;
|
|
|
|
generated_samples = sink->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testZeroInput()
|
|
|
|
{
|
|
|
|
interleaver->add_output (sink);
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
// input zero samples to all inputs
|
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2010-03-15 15:11:48 -04:00
|
|
|
interleaver->input (0)->process (c.beginning (0));
|
|
|
|
interleaver->input (1)->process (c.beginning (0));
|
|
|
|
interleaver->input (2)->process (c.beginning (0));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// NOTE zero input is allowed to be a NOP
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
// ...now test regular input
|
|
|
|
interleaver->input (0)->process (c);
|
|
|
|
interleaver->input (1)->process (c);
|
|
|
|
interleaver->input (2)->process (c);
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t expected_samples = samples * channels;
|
|
|
|
samplecnt_t generated_samples = sink->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_samples, generated_samples);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testChannelSync()
|
|
|
|
{
|
|
|
|
interleaver->add_output (sink);
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
interleaver->input (0)->process (c);
|
2015-10-05 10:17:49 -04:00
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
boost::shared_ptr<Interleaver<float> > interleaver;
|
|
|
|
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink;
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t channels;
|
2009-12-27 09:46:23 -05:00
|
|
|
float * random_data;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t samples;
|
2009-12-27 09:46:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (InterleaverTest);
|
|
|
|
|