2 #include "audiographer/interleaver.h"
4 using namespace AudioGrapher;
6 class InterleaverTest : public CppUnit::TestFixture
8 CPPUNIT_TEST_SUITE (InterleaverTest);
9 CPPUNIT_TEST (testUninitialized);
10 CPPUNIT_TEST (testInvalidInputIndex);
11 CPPUNIT_TEST (testInvalidInputSize);
12 CPPUNIT_TEST (testOutputSize);
13 CPPUNIT_TEST (testZeroInput);
14 CPPUNIT_TEST (testChannelSync);
15 CPPUNIT_TEST_SUITE_END ();
22 random_data = TestUtils::init_random_data (frames, 1.0);
24 interleaver.reset (new Interleaver<float>());
25 sink.reset (new VectorSink<float>());
27 interleaver->init (channels, frames);
32 delete [] random_data;
35 void testUninitialized()
37 interleaver.reset (new Interleaver<float>());
38 ProcessContext<float> c (random_data, frames, 1);
39 CPPUNIT_ASSERT_THROW (interleaver->input(0)->process (c), Exception);
42 void testInvalidInputIndex()
44 ProcessContext<float> c (random_data, frames, 1);
45 CPPUNIT_ASSERT_THROW (interleaver->input (3)->process (c), Exception);
48 void testInvalidInputSize()
50 ProcessContext<float> c (random_data, frames + 1, 1);
51 CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception);
54 interleaver->input (0)->process (c);
55 interleaver->input (1)->process (c);
56 c.frames() = frames -1;
57 CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c), Exception);
59 interleaver->input (0)->process (c);
60 interleaver->input (1)->process (c);
62 CPPUNIT_ASSERT_THROW (interleaver->input (2)->process (c), Exception);
67 interleaver->add_output (sink);
69 ProcessContext<float> c (random_data, frames, 1);
70 interleaver->input (0)->process (c);
71 interleaver->input (1)->process (c);
72 interleaver->input (2)->process (c);
74 nframes_t expected_frames = frames * channels;
75 nframes_t generated_frames = sink->get_data().size();
76 CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
78 nframes_t less_frames = frames / 2;
79 c.frames() = less_frames;
80 interleaver->input (0)->process (c);
81 interleaver->input (1)->process (c);
82 interleaver->input (2)->process (c);
84 expected_frames = less_frames * channels;
85 generated_frames = sink->get_data().size();
86 CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
91 interleaver->add_output (sink);
93 // input zero frames to all inputs
94 ProcessContext<float> c (random_data, 0, 1);
95 interleaver->input (0)->process (c);
96 interleaver->input (1)->process (c);
97 interleaver->input (2)->process (c);
99 // NOTE zero input is allowed to be a NOP
101 // ...now test regular input
103 interleaver->input (0)->process (c);
104 interleaver->input (1)->process (c);
105 interleaver->input (2)->process (c);
107 nframes_t expected_frames = frames * channels;
108 nframes_t generated_frames = sink->get_data().size();
109 CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
112 void testChannelSync()
114 interleaver->add_output (sink);
115 ProcessContext<float> c (random_data, frames, 1);
116 interleaver->input (0)->process (c);
117 CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception);
122 boost::shared_ptr<Interleaver<float> > interleaver;
124 boost::shared_ptr<VectorSink<float> > sink;
131 CPPUNIT_TEST_SUITE_REGISTRATION (InterleaverTest);