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;
|
|
|
|
frames = 128;
|
|
|
|
random_data = TestUtils::init_random_data (frames, 1.0);
|
|
|
|
|
|
|
|
interleaver.reset (new Interleaver<float>());
|
|
|
|
sink.reset (new VectorSink<float>());
|
|
|
|
|
|
|
|
interleaver->init (channels, frames);
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
delete [] random_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testUninitialized()
|
|
|
|
{
|
|
|
|
interleaver.reset (new Interleaver<float>());
|
|
|
|
ProcessContext<float> c (random_data, frames, 1);
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input(0)->process (c), Exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testInvalidInputIndex()
|
|
|
|
{
|
|
|
|
ProcessContext<float> c (random_data, frames, 1);
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (3)->process (c), Exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testInvalidInputSize()
|
|
|
|
{
|
|
|
|
ProcessContext<float> c (random_data, frames + 1, 1);
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception);
|
|
|
|
|
2010-03-15 15:11:48 -04:00
|
|
|
interleaver->input (0)->process (c.beginning (frames));
|
|
|
|
interleaver->input (1)->process (c.beginning (frames));
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (frames - 1)), Exception);
|
2009-12-27 09:46:23 -05:00
|
|
|
|
2010-03-15 15:11:48 -04:00
|
|
|
interleaver->input (0)->process (c.beginning (frames - 1));
|
|
|
|
interleaver->input (1)->process (c.beginning (frames - 1));
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c.beginning (frames)), Exception);
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void testOutputSize()
|
|
|
|
{
|
|
|
|
interleaver->add_output (sink);
|
|
|
|
|
|
|
|
ProcessContext<float> c (random_data, frames, 1);
|
|
|
|
interleaver->input (0)->process (c);
|
|
|
|
interleaver->input (1)->process (c);
|
|
|
|
interleaver->input (2)->process (c);
|
|
|
|
|
|
|
|
nframes_t expected_frames = frames * channels;
|
|
|
|
nframes_t generated_frames = sink->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
|
|
|
|
|
|
|
|
nframes_t less_frames = frames / 2;
|
2010-03-15 15:11:48 -04:00
|
|
|
interleaver->input (0)->process (c.beginning (less_frames));
|
|
|
|
interleaver->input (1)->process (c.beginning (less_frames));
|
|
|
|
interleaver->input (2)->process (c.beginning (less_frames));
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
expected_frames = less_frames * channels;
|
|
|
|
generated_frames = sink->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testZeroInput()
|
|
|
|
{
|
|
|
|
interleaver->add_output (sink);
|
|
|
|
|
|
|
|
// input zero frames to all inputs
|
2010-03-15 15:11:48 -04:00
|
|
|
ProcessContext<float> c (random_data, frames, 1);
|
|
|
|
interleaver->input (0)->process (c.beginning (0));
|
|
|
|
interleaver->input (1)->process (c.beginning (0));
|
|
|
|
interleaver->input (2)->process (c.beginning (0));
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
// NOTE zero input is allowed to be a NOP
|
|
|
|
|
|
|
|
// ...now test regular input
|
|
|
|
interleaver->input (0)->process (c);
|
|
|
|
interleaver->input (1)->process (c);
|
|
|
|
interleaver->input (2)->process (c);
|
|
|
|
|
|
|
|
nframes_t expected_frames = frames * channels;
|
|
|
|
nframes_t generated_frames = sink->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
|
|
|
|
}
|
|
|
|
|
|
|
|
void testChannelSync()
|
|
|
|
{
|
|
|
|
interleaver->add_output (sink);
|
|
|
|
ProcessContext<float> c (random_data, frames, 1);
|
|
|
|
interleaver->input (0)->process (c);
|
|
|
|
CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
boost::shared_ptr<Interleaver<float> > interleaver;
|
|
|
|
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink;
|
|
|
|
|
|
|
|
nframes_t channels;
|
|
|
|
float * random_data;
|
|
|
|
nframes_t frames;
|
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (InterleaverTest);
|
|
|
|
|