NOOP, remove trailing tabs/whitespace.
[ardour.git] / libs / audiographer / tests / general / deinterleaver_test.cc
1 #include "tests/utils.h"
2
3 #include "audiographer/general/deinterleaver.h"
4
5 using namespace AudioGrapher;
6
7 class DeInterleaverTest : public CppUnit::TestFixture
8 {
9   CPPUNIT_TEST_SUITE (DeInterleaverTest);
10   CPPUNIT_TEST (testUninitialized);
11   CPPUNIT_TEST (testInvalidOutputIndex);
12   CPPUNIT_TEST (testInvalidInputSize);
13   CPPUNIT_TEST (testOutputSize);
14   CPPUNIT_TEST (testZeroInput);
15   CPPUNIT_TEST_SUITE_END ();
16
17   public:
18         void setUp()
19         {
20                 channels = 3;
21                 frames_per_channel = 128;
22                 total_frames = channels * frames_per_channel;
23                 random_data = TestUtils::init_random_data (total_frames, 1.0);
24
25                 deinterleaver.reset (new DeInterleaver<float>());
26                 sink_a.reset (new VectorSink<float>());
27                 sink_b.reset (new VectorSink<float>());
28                 sink_c.reset (new VectorSink<float>());
29         }
30
31         void tearDown()
32         {
33                 delete [] random_data;
34         }
35
36         void testUninitialized()
37         {
38                 deinterleaver.reset (new DeInterleaver<float>());
39                 CPPUNIT_ASSERT_THROW (deinterleaver->output(0)->add_output (sink_a), Exception);
40         }
41
42         void testInvalidOutputIndex()
43         {
44                 deinterleaver->init (3, frames_per_channel);
45                 CPPUNIT_ASSERT_THROW (deinterleaver->output(3)->add_output (sink_a), Exception);
46         }
47
48         void testInvalidInputSize()
49         {
50                 deinterleaver->init (channels, frames_per_channel);
51
52                 ProcessContext<float> c (random_data, 2 * total_frames, channels);
53
54                 // Too many, frames % channels == 0
55                 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + channels)), Exception);
56
57                 // Too many, frames % channels != 0
58                 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + 1)), Exception);
59
60                 // Too few, frames % channels != 0
61                 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames - 1)), Exception);
62         }
63
64         void assert_outputs (framecnt_t expected_frames)
65         {
66                 framecnt_t generated_frames = 0;
67
68                 generated_frames = sink_a->get_data().size();
69                 CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
70
71                 generated_frames = sink_b->get_data().size();
72                 CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
73
74                 generated_frames = sink_c->get_data().size();
75                 CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames);
76         }
77
78         void testOutputSize()
79         {
80                 deinterleaver->init (channels, frames_per_channel);
81
82                 deinterleaver->output (0)->add_output (sink_a);
83                 deinterleaver->output (1)->add_output (sink_b);
84                 deinterleaver->output (2)->add_output (sink_c);
85
86                 // Test maximum frame input
87                 ProcessContext<float> c (random_data, total_frames, channels);
88                 deinterleaver->process (c);
89                 assert_outputs (frames_per_channel);
90
91                 // Now with less frames
92                 framecnt_t const less_frames = frames_per_channel / 4;
93                 deinterleaver->process (c.beginning (less_frames * channels));
94                 assert_outputs (less_frames);
95         }
96
97         void testZeroInput()
98         {
99                 deinterleaver->init (channels, frames_per_channel);
100
101                 deinterleaver->output (0)->add_output (sink_a);
102                 deinterleaver->output (1)->add_output (sink_b);
103                 deinterleaver->output (2)->add_output (sink_c);
104
105                 // Input zero frames
106                 ProcessContext<float> c (random_data, total_frames, channels);
107                 deinterleaver->process (c.beginning (0));
108
109                 // ...and now test regular input
110                 deinterleaver->process (c);
111                 assert_outputs (frames_per_channel);
112         }
113
114
115   private:
116         boost::shared_ptr<DeInterleaver<float> > deinterleaver;
117
118         boost::shared_ptr<VectorSink<float> > sink_a;
119         boost::shared_ptr<VectorSink<float> > sink_b;
120         boost::shared_ptr<VectorSink<float> > sink_c;
121
122         float * random_data;
123         framecnt_t frames_per_channel;
124         framecnt_t total_frames;
125         unsigned int channels;
126 };
127
128 CPPUNIT_TEST_SUITE_REGISTRATION (DeInterleaverTest);
129