diff options
Diffstat (limited to 'libs/audiographer/tests')
-rw-r--r-- | libs/audiographer/tests/general/chunker_test.cc | 50 | ||||
-rw-r--r-- | libs/audiographer/tests/general/deinterleaver_test.cc | 28 | ||||
-rw-r--r-- | libs/audiographer/tests/general/interleaver_deinterleaver_test.cc | 34 | ||||
-rw-r--r-- | libs/audiographer/tests/general/interleaver_test.cc | 10 | ||||
-rw-r--r-- | libs/audiographer/tests/general/normalizer_test.cc | 10 | ||||
-rw-r--r-- | libs/audiographer/tests/general/peak_reader_test.cc | 6 | ||||
-rw-r--r-- | libs/audiographer/tests/general/sample_format_converter_test.cc | 48 | ||||
-rw-r--r-- | libs/audiographer/tests/general/silence_trimmer_test.cc | 48 | ||||
-rw-r--r-- | libs/audiographer/tests/general/sr_converter_test.cc | 28 | ||||
-rw-r--r-- | libs/audiographer/tests/general/threader_test.cc | 42 | ||||
-rw-r--r-- | libs/audiographer/tests/sndfile/tmp_file_test.cc | 4 | ||||
-rw-r--r-- | libs/audiographer/tests/type_utils_test.cc | 28 | ||||
-rw-r--r-- | libs/audiographer/tests/utils.h | 6 | ||||
-rw-r--r-- | libs/audiographer/tests/utils/identity_vertex_test.cc | 28 |
14 files changed, 185 insertions, 185 deletions
diff --git a/libs/audiographer/tests/general/chunker_test.cc b/libs/audiographer/tests/general/chunker_test.cc index d3adab3691..12b5da5dbc 100644 --- a/libs/audiographer/tests/general/chunker_test.cc +++ b/libs/audiographer/tests/general/chunker_test.cc @@ -35,52 +35,52 @@ class ChunkerTest : public CppUnit::TestFixture { chunker->add_output (sink); framecnt_t frames_output = 0; - + ProcessContext<float> const context (random_data, frames, 1); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (2 * frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames], frames)); - + sink->reset(); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (2 * frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames], frames)); } - + void testAsynchronousProcess() { assert (frames % 2 == 0); - + chunker->add_output (sink); framecnt_t frames_output = 0; - + ProcessContext<float> const half_context (random_data, frames / 2, 1); ProcessContext<float> const context (random_data, frames, 1); - + // 0.5 chunker->process (half_context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + // 1.5 chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + // 2.5 chunker->process (context); frames_output = sink->get_data().size(); @@ -88,14 +88,14 @@ class ChunkerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames / 2)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames / 2], frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * frames / 2], frames / 2)); - + sink->reset(); - + // 3.5 chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_output); - + // 4.0 chunker->process (half_context); frames_output = sink->get_data().size(); @@ -104,30 +104,30 @@ class ChunkerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[frames / 2], frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * frames / 2], frames / 2)); } - + void testChoppingProcess() { sink.reset (new AppendingVectorSink<float>()); - + assert (frames % 2 == 0); chunker.reset (new Chunker<float>(frames / 4)); - + chunker->add_output (sink); framecnt_t frames_output = 0; - + ProcessContext<float> const half_context (random_data, frames / 2, 1); ProcessContext<float> const context (random_data, frames, 1); - + // 0.5 chunker->process (half_context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) frames / 2, frames_output); - + // 1.5 chunker->process (context); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) frames / 2 * 3, frames_output); - + // 2.5 chunker->process (context); frames_output = sink->get_data().size(); @@ -140,15 +140,15 @@ class ChunkerTest : public CppUnit::TestFixture void testEndOfInputFlagHandling() { boost::shared_ptr<ProcessContextGrabber<float> > grabber(new ProcessContextGrabber<float>()); - + assert (frames % 2 == 0); chunker.reset (new Chunker<float>(frames)); chunker->add_output (grabber); - + ProcessContext<float> const half_context (random_data, frames / 2, 1); ProcessContext<float> const context (random_data, frames, 1); context.set_flag(ProcessContext<>::EndOfInput); - + // Process 0.5 then 1.0 chunker->process (half_context); chunker->process (context); diff --git a/libs/audiographer/tests/general/deinterleaver_test.cc b/libs/audiographer/tests/general/deinterleaver_test.cc index 3260045b11..f7e15459b3 100644 --- a/libs/audiographer/tests/general/deinterleaver_test.cc +++ b/libs/audiographer/tests/general/deinterleaver_test.cc @@ -48,15 +48,15 @@ class DeInterleaverTest : public CppUnit::TestFixture void testInvalidInputSize() { deinterleaver->init (channels, frames_per_channel); - + ProcessContext<float> c (random_data, 2 * total_frames, channels); - + // Too many, frames % channels == 0 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + channels)), Exception); - + // Too many, frames % channels != 0 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames + 1)), Exception); - + // Too few, frames % channels != 0 CPPUNIT_ASSERT_THROW (deinterleaver->process (c.beginning (total_frames - 1)), Exception); } @@ -64,13 +64,13 @@ class DeInterleaverTest : public CppUnit::TestFixture void assert_outputs (framecnt_t expected_frames) { framecnt_t generated_frames = 0; - + generated_frames = sink_a->get_data().size(); CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); - + generated_frames = sink_b->get_data().size(); CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); - + generated_frames = sink_c->get_data().size(); CPPUNIT_ASSERT_EQUAL (expected_frames, generated_frames); } @@ -78,34 +78,34 @@ class DeInterleaverTest : public CppUnit::TestFixture void testOutputSize() { deinterleaver->init (channels, frames_per_channel); - + deinterleaver->output (0)->add_output (sink_a); deinterleaver->output (1)->add_output (sink_b); deinterleaver->output (2)->add_output (sink_c); - + // Test maximum frame input ProcessContext<float> c (random_data, total_frames, channels); deinterleaver->process (c); assert_outputs (frames_per_channel); - + // Now with less frames framecnt_t const less_frames = frames_per_channel / 4; deinterleaver->process (c.beginning (less_frames * channels)); assert_outputs (less_frames); } - + void testZeroInput() { deinterleaver->init (channels, frames_per_channel); - + deinterleaver->output (0)->add_output (sink_a); deinterleaver->output (1)->add_output (sink_b); deinterleaver->output (2)->add_output (sink_c); - + // Input zero frames ProcessContext<float> c (random_data, total_frames, channels); deinterleaver->process (c.beginning (0)); - + // ...and now test regular input deinterleaver->process (c); assert_outputs (frames_per_channel); diff --git a/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc b/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc index da042b9494..4f46a83492 100644 --- a/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc +++ b/libs/audiographer/tests/general/interleaver_deinterleaver_test.cc @@ -18,14 +18,14 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture channels = 3; frames_per_channel = 128; total_frames = channels * frames_per_channel; - + random_data_a = TestUtils::init_random_data (total_frames, 1.0); random_data_b = TestUtils::init_random_data (frames_per_channel, 1.0); random_data_c = TestUtils::init_random_data (frames_per_channel, 1.0); deinterleaver.reset (new DeInterleaver<float>()); interleaver.reset (new Interleaver<float>()); - + sink_a.reset (new VectorSink<float>()); sink_b.reset (new VectorSink<float>()); sink_c.reset (new VectorSink<float>()); @@ -42,64 +42,64 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture { deinterleaver->init (channels, frames_per_channel); interleaver->init (channels, frames_per_channel); - + deinterleaver->output (0)->add_output (interleaver->input (0)); deinterleaver->output (1)->add_output (interleaver->input (1)); deinterleaver->output (2)->add_output (interleaver->input (2)); - + interleaver->add_output (sink_a); - + // Process and assert ProcessContext<float> c (random_data_a, total_frames, channels); deinterleaver->process (c); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), total_frames)); - + // And a second round... framecnt_t less_frames = (frames_per_channel / 10) * channels; deinterleaver->process (c.beginning (less_frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_frames)); } - + void testDeInterleavedInput() { deinterleaver->init (channels, frames_per_channel); interleaver->init (channels, frames_per_channel); - + interleaver->add_output (deinterleaver); - + deinterleaver->output (0)->add_output (sink_a); deinterleaver->output (1)->add_output (sink_b); deinterleaver->output (2)->add_output (sink_c); - + ProcessContext<float> c_a (random_data_a, frames_per_channel, 1); ProcessContext<float> c_b (random_data_b, frames_per_channel, 1); ProcessContext<float> c_c (random_data_c, frames_per_channel, 1); - + // Process and assert interleaver->input (0)->process (c_a); interleaver->input (1)->process (c_b); interleaver->input (2)->process (c_c); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), frames_per_channel)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), frames_per_channel)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), frames_per_channel)); - + // And a second round... framecnt_t less_frames = frames_per_channel / 5; interleaver->input (0)->process (c_a.beginning (less_frames)); interleaver->input (1)->process (c_b.beginning (less_frames)); interleaver->input (2)->process (c_c.beginning (less_frames)); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data_a, sink_a->get_array(), less_frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_b, sink_b->get_array(), less_frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data_c, sink_c->get_array(), less_frames)); - + } private: boost::shared_ptr<Interleaver<float> > interleaver; boost::shared_ptr<DeInterleaver<float> > deinterleaver; - + boost::shared_ptr<VectorSink<float> > sink_a; boost::shared_ptr<VectorSink<float> > sink_b; boost::shared_ptr<VectorSink<float> > sink_c; @@ -107,7 +107,7 @@ class InterleaverDeInterleaverTest : public CppUnit::TestFixture float * random_data_a; float * random_data_b; float * random_data_c; - + framecnt_t frames_per_channel; framecnt_t total_frames; unsigned int channels; diff --git a/libs/audiographer/tests/general/interleaver_test.cc b/libs/audiographer/tests/general/interleaver_test.cc index b82aac74bb..0b8f8b6952 100644 --- a/libs/audiographer/tests/general/interleaver_test.cc +++ b/libs/audiographer/tests/general/interleaver_test.cc @@ -24,7 +24,7 @@ class InterleaverTest : public CppUnit::TestFixture interleaver.reset (new Interleaver<float>()); sink.reset (new VectorSink<float>()); - + interleaver->init (channels, frames); } @@ -50,7 +50,7 @@ class InterleaverTest : public CppUnit::TestFixture { ProcessContext<float> c (random_data, frames + 1, 1); CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception); - + 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); @@ -92,9 +92,9 @@ class InterleaverTest : public CppUnit::TestFixture interleaver->input (0)->process (c.beginning (0)); interleaver->input (1)->process (c.beginning (0)); interleaver->input (2)->process (c.beginning (0)); - + // NOTE zero input is allowed to be a NOP - + // ...now test regular input interleaver->input (0)->process (c); interleaver->input (1)->process (c); @@ -110,7 +110,7 @@ class InterleaverTest : public CppUnit::TestFixture 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); + CPPUNIT_ASSERT_THROW (interleaver->input (0)->process (c), Exception); } diff --git a/libs/audiographer/tests/general/normalizer_test.cc b/libs/audiographer/tests/general/normalizer_test.cc index be23680202..fb8cd617c2 100644 --- a/libs/audiographer/tests/general/normalizer_test.cc +++ b/libs/audiographer/tests/general/normalizer_test.cc @@ -26,24 +26,24 @@ class NormalizerTest : public CppUnit::TestFixture { float target = 0.0; random_data = TestUtils::init_random_data(frames, 0.5); - + normalizer.reset (new Normalizer(target)); peak_reader.reset (new PeakReader()); sink.reset (new VectorSink<float>()); - + ProcessContext<float> const c (random_data, frames, 1); peak_reader->process (c); - + float peak = peak_reader->get_peak(); normalizer->alloc_buffer (frames); normalizer->set_peak (peak); normalizer->add_output (sink); normalizer->process (c); - + peak_reader->reset(); ConstProcessContext<float> normalized (sink->get_array(), frames, 1); peak_reader->process (normalized); - + peak = peak_reader->get_peak(); CPPUNIT_ASSERT (-FLT_EPSILON <= (peak - 1.0) && (peak - 1.0) <= 0.0); } diff --git a/libs/audiographer/tests/general/peak_reader_test.cc b/libs/audiographer/tests/general/peak_reader_test.cc index 6b60598a2e..a93d28a954 100644 --- a/libs/audiographer/tests/general/peak_reader_test.cc +++ b/libs/audiographer/tests/general/peak_reader_test.cc @@ -26,17 +26,17 @@ class PeakReaderTest : public CppUnit::TestFixture { reader.reset (new PeakReader()); ProcessContext<float> c (random_data, frames, 1); - + float peak = 1.5; random_data[10] = peak; reader->process (c); CPPUNIT_ASSERT_EQUAL(peak, reader->get_peak()); - + peak = 2.0; random_data[10] = peak; reader->process (c); CPPUNIT_ASSERT_EQUAL(peak, reader->get_peak()); - + peak = -2.1; random_data[10] = peak; reader->process (c); diff --git a/libs/audiographer/tests/general/sample_format_converter_test.cc b/libs/audiographer/tests/general/sample_format_converter_test.cc index 977e2b390a..734389a427 100644 --- a/libs/audiographer/tests/general/sample_format_converter_test.cc +++ b/libs/audiographer/tests/general/sample_format_converter_test.cc @@ -63,25 +63,25 @@ class SampleFormatConverterTest : public CppUnit::TestFixture { boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(1)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); - + converter->init (frames, D_Tri, 32); converter->add_output (sink); framecnt_t frames_output = 0; - + { ProcessContext<float> pc(random_data, frames / 2, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames / 2, frames_output); } - + { ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); } - + { ProcessContext<float> pc(random_data, frames + 1, 1); CPPUNIT_ASSERT_THROW(converter->process (pc), Exception); @@ -93,27 +93,27 @@ class SampleFormatConverterTest : public CppUnit::TestFixture boost::shared_ptr<SampleFormatConverter<float> > converter (new SampleFormatConverter<float>(1)); boost::shared_ptr<VectorSink<float> > sink (new VectorSink<float>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 32); converter->add_output (sink); - + converter->set_clip_floats (false); ProcessContext<float> const pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_equals(sink->get_array(), random_data, frames)); - + // Make sure a few samples are < -1.0 and > 1.0 random_data[10] = -1.5; random_data[20] = 1.5; - + converter->set_clip_floats (true); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); - + for (framecnt_t i = 0; i < frames; ++i) { // fp comparison needs a bit of tolerance, 1.01 << 1.5 CPPUNIT_ASSERT(sink->get_data()[i] < 1.01); @@ -126,77 +126,77 @@ class SampleFormatConverterTest : public CppUnit::TestFixture boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(1)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 32); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testInt24() { boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(1)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 24); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testInt16() { boost::shared_ptr<SampleFormatConverter<int16_t> > converter (new SampleFormatConverter<int16_t>(1)); boost::shared_ptr<VectorSink<int16_t> > sink (new VectorSink<int16_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 16); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testUint8() { boost::shared_ptr<SampleFormatConverter<uint8_t> > converter (new SampleFormatConverter<uint8_t>(1)); boost::shared_ptr<VectorSink<uint8_t> > sink (new VectorSink<uint8_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 8); converter->add_output (sink); - + ProcessContext<float> pc(random_data, frames, 1); converter->process (pc); frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); CPPUNIT_ASSERT (TestUtils::array_filled(sink->get_array(), frames)); } - + void testChannelCount() { boost::shared_ptr<SampleFormatConverter<int32_t> > converter (new SampleFormatConverter<int32_t>(3)); boost::shared_ptr<VectorSink<int32_t> > sink (new VectorSink<int32_t>()); framecnt_t frames_output = 0; - + converter->init(frames, D_Tri, 32); converter->add_output (sink); - + ProcessContext<float> pc(random_data, 4, 1); CPPUNIT_ASSERT_THROW (converter->process (pc), Exception); - + framecnt_t new_frame_count = frames - (frames % 3); converter->process (ProcessContext<float> (pc.data(), new_frame_count, 3)); frames_output = sink->get_data().size(); diff --git a/libs/audiographer/tests/general/silence_trimmer_test.cc b/libs/audiographer/tests/general/silence_trimmer_test.cc index dfcf3c7ca2..be53c89978 100644 --- a/libs/audiographer/tests/general/silence_trimmer_test.cc +++ b/libs/audiographer/tests/general/silence_trimmer_test.cc @@ -18,20 +18,20 @@ class SilenceTrimmerTest : public CppUnit::TestFixture void setUp() { frames = 128; - + random_data = TestUtils::init_random_data(frames); random_data[0] = 0.5; random_data[frames - 1] = 0.5; - + zero_data = new float[frames]; memset(zero_data, 0, frames * sizeof(float)); - + half_random_data = TestUtils::init_random_data(frames); memset(half_random_data, 0, (frames / 2) * sizeof(float)); - + trimmer.reset (new SilenceTrimmer<float> (frames / 2)); sink.reset (new AppendingVectorSink<float>()); - + trimmer->set_trim_beginning (true); trimmer->set_trim_end (true); } @@ -46,14 +46,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture void testFullBuffers() { trimmer->add_output (sink); - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); framecnt_t frames_processed = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL ((framecnt_t) 0, frames_processed); } - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); @@ -61,14 +61,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (frames, frames_processed); CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), random_data, frames)); } - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); framecnt_t frames_processed = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_processed); } - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); @@ -78,7 +78,7 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[frames], zero_data, frames)); CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[2 * frames], random_data, frames)); } - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); @@ -86,14 +86,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (3 * frames, frames_processed); } } - + void testPartialBuffers() { trimmer->add_output (sink); trimmer->reset (frames / 4); trimmer->set_trim_beginning (true); trimmer->set_trim_end (true); - + { ProcessContext<float> c (half_random_data, frames, 1); trimmer->process (c); @@ -101,14 +101,14 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (frames / 2, frames_processed); CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), &half_random_data[frames / 2], frames / 2)); } - + { ProcessContext<float> c (zero_data, frames, 1); trimmer->process (c); framecnt_t frames_processed = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames / 2, frames_processed); } - + { ProcessContext<float> c (half_random_data, frames, 1); trimmer->process (c); @@ -117,48 +117,48 @@ class SilenceTrimmerTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[frames + frames / 2], half_random_data, frames)); } } - + void testExceptions() { { CPPUNIT_ASSERT_THROW (trimmer->reset (0), Exception); } } - + void testAddSilenceBeginning() { trimmer->add_output (sink); - + framecnt_t silence = frames / 2; trimmer->add_silence_to_beginning (silence); - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); } - + CPPUNIT_ASSERT (TestUtils::array_equals (sink->get_array(), zero_data, silence)); CPPUNIT_ASSERT (TestUtils::array_equals (&sink->get_array()[silence], random_data, frames)); } - + void testAddSilenceEnd() { trimmer->add_output (sink); - + framecnt_t silence = frames / 3; trimmer->add_silence_to_end (silence); - + { ProcessContext<float> c (random_data, frames, 1); trimmer->process (c); } - + { ProcessContext<float> c (random_data, frames, 1); c.set_flag (ProcessContext<float>::EndOfInput); trimmer->process (c); } - + framecnt_t frames_processed = sink->get_data().size(); framecnt_t total_frames = 2 * frames + silence; CPPUNIT_ASSERT_EQUAL (total_frames, frames_processed); diff --git a/libs/audiographer/tests/general/sr_converter_test.cc b/libs/audiographer/tests/general/sr_converter_test.cc index 75834127f5..4f5afbb620 100644 --- a/libs/audiographer/tests/general/sr_converter_test.cc +++ b/libs/audiographer/tests/general/sr_converter_test.cc @@ -33,19 +33,19 @@ class SampleRateConverterTest : public CppUnit::TestFixture assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; framecnt_t frames_output = 0; - + converter->init (44100, 44100); converter->add_output (sink); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - + frames_output = sink->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink->get_array(), frames)); } @@ -54,11 +54,11 @@ class SampleRateConverterTest : public CppUnit::TestFixture assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; framecnt_t frames_output = 0; - + converter->init (44100, 88200); converter->allocate_buffers (half_frames); converter->add_output (sink); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); @@ -75,37 +75,37 @@ class SampleRateConverterTest : public CppUnit::TestFixture assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; framecnt_t frames_output = 0; - + converter->init (88200, 44100); converter->allocate_buffers (half_frames); converter->add_output (sink); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - + frames_output = sink->get_data().size(); framecnt_t tolerance = 3; CPPUNIT_ASSERT (half_frames - tolerance < frames_output && frames_output < half_frames + tolerance); } - + void testRespectsEndOfInput() { assert (frames % 2 == 0); framecnt_t const half_frames = frames / 2; - + converter->init (44100, 48000); converter->allocate_buffers (half_frames); converter->add_output (grabber); - + ProcessContext<float> c (random_data, half_frames, 1); converter->process (c); ProcessContext<float> c2 (&random_data[half_frames], half_frames / 2, 1); c2.set_flag (ProcessContext<float>::EndOfInput); converter->process (c2); - + for (std::list<ProcessContext<float> >::iterator it = grabber->contexts.begin(); it != grabber->contexts.end(); ++it) { std::list<ProcessContext<float> >::iterator next = it; ++next; if (next == grabber->contexts.end()) { @@ -115,7 +115,7 @@ class SampleRateConverterTest : public CppUnit::TestFixture } } } - + private: boost::shared_ptr<SampleRateConverter > converter; diff --git a/libs/audiographer/tests/general/threader_test.cc b/libs/audiographer/tests/general/threader_test.cc index 1e87c8d34d..cdb21a375b 100644 --- a/libs/audiographer/tests/general/threader_test.cc +++ b/libs/audiographer/tests/general/threader_test.cc @@ -18,20 +18,20 @@ class ThreaderTest : public CppUnit::TestFixture { frames = 128; random_data = TestUtils::init_random_data (frames, 1.0); - + zero_data = new float[frames]; memset (zero_data, 0, frames * sizeof(float)); - + thread_pool = new Glib::ThreadPool (3); threader.reset (new Threader<float> (*thread_pool)); - + sink_a.reset (new VectorSink<float>()); sink_b.reset (new VectorSink<float>()); sink_c.reset (new VectorSink<float>()); sink_d.reset (new VectorSink<float>()); sink_e.reset (new VectorSink<float>()); sink_f.reset (new VectorSink<float>()); - + throwing_sink.reset (new ThrowingSink<float>()); } @@ -39,7 +39,7 @@ class ThreaderTest : public CppUnit::TestFixture { delete [] random_data; delete [] zero_data; - + thread_pool->shutdown(); delete thread_pool; } @@ -52,10 +52,10 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_d); threader->add_output (sink_e); threader->add_output (sink_f); - + ProcessContext<float> c (random_data, frames, 1); threader->process (c); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), frames)); @@ -63,7 +63,7 @@ class ThreaderTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); } - + void testRemoveOutput() { threader->add_output (sink_a); @@ -72,18 +72,18 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_d); threader->add_output (sink_e); threader->add_output (sink_f); - + ProcessContext<float> c (random_data, frames, 1); threader->process (c); - + // Remove a, b and f threader->remove_output (sink_a); threader->remove_output (sink_b); threader->remove_output (sink_f); - + ProcessContext<float> zc (zero_data, frames, 1); threader->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_c->get_array(), frames)); @@ -91,7 +91,7 @@ class ThreaderTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals(zero_data, sink_e->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); } - + void testClearOutputs() { threader->add_output (sink_a); @@ -100,14 +100,14 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (sink_d); threader->add_output (sink_e); threader->add_output (sink_f); - + ProcessContext<float> c (random_data, frames, 1); threader->process (c); - + threader->clear_outputs(); ProcessContext<float> zc (zero_data, frames, 1); threader->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), frames)); @@ -115,7 +115,7 @@ class ThreaderTest : public CppUnit::TestFixture CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_e->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_f->get_array(), frames)); } - + void testExceptions() { threader->add_output (sink_a); @@ -124,10 +124,10 @@ class ThreaderTest : public CppUnit::TestFixture threader->add_output (throwing_sink); threader->add_output (sink_e); threader->add_output (throwing_sink); - + ProcessContext<float> c (random_data, frames, 1); CPPUNIT_ASSERT_THROW (threader->process (c), Exception); - + CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_b->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals(random_data, sink_c->get_array(), frames)); @@ -136,7 +136,7 @@ class ThreaderTest : public CppUnit::TestFixture private: Glib::ThreadPool * thread_pool; - + boost::shared_ptr<Threader<float> > threader; boost::shared_ptr<VectorSink<float> > sink_a; boost::shared_ptr<VectorSink<float> > sink_b; @@ -144,7 +144,7 @@ class ThreaderTest : public CppUnit::TestFixture boost::shared_ptr<VectorSink<float> > sink_d; boost::shared_ptr<VectorSink<float> > sink_e; boost::shared_ptr<VectorSink<float> > sink_f; - + boost::shared_ptr<ThrowingSink<float> > throwing_sink; float * random_data; diff --git a/libs/audiographer/tests/sndfile/tmp_file_test.cc b/libs/audiographer/tests/sndfile/tmp_file_test.cc index 9ce8af7a5c..32e39135ec 100644 --- a/libs/audiographer/tests/sndfile/tmp_file_test.cc +++ b/libs/audiographer/tests/sndfile/tmp_file_test.cc @@ -28,9 +28,9 @@ class TmpFileTest : public CppUnit::TestFixture AllocatingProcessContext<float> c (random_data, frames, channels); c.set_flag (ProcessContext<float>::EndOfInput); file->process (c); - + TypeUtils<float>::zero_fill (c.data (), c.frames()); - + file->seek (0, SEEK_SET); file->read (c); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, c.data(), c.frames())); diff --git a/libs/audiographer/tests/type_utils_test.cc b/libs/audiographer/tests/type_utils_test.cc index a2b2c96f11..1ae7b28451 100644 --- a/libs/audiographer/tests/type_utils_test.cc +++ b/libs/audiographer/tests/type_utils_test.cc @@ -17,12 +17,12 @@ class TypeUtilsTest : public CppUnit::TestFixture public: void setUp() { - + } void tearDown() { - + } void testZeroFillPod() @@ -35,7 +35,7 @@ class TypeUtilsTest : public CppUnit::TestFixture CPPUNIT_ASSERT_EQUAL (zero, buf[i]); } } - + void testZeroFillNonPod() { /* does not compile on OS X Lion @@ -48,26 +48,26 @@ class TypeUtilsTest : public CppUnit::TestFixture } */ } - + void testMoveBackward() { int seq[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - + TypeUtils<int>::move (&seq[4], &seq[2], 4); - + for (int i = 2; i < 2 + 4; ++i) { CPPUNIT_ASSERT_EQUAL (i + 2, seq[i]); } } - + void testMoveForward() { int seq[8] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - + TypeUtils<int>::move (&seq[2], &seq[4], 4); - + for (int i = 4; i < 4 + 4; ++i) { CPPUNIT_ASSERT_EQUAL (i - 2, seq[i]); } @@ -79,16 +79,16 @@ class TypeUtilsTest : public CppUnit::TestFixture int const seq2[4] = { 5, 6, 7, 8 }; int seq3[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - + TypeUtils<int>::copy (seq1, seq3, 4); for (int i = 0; i < 4; ++i) { CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]); } - + for (int i = 4; i < 8; ++i) { CPPUNIT_ASSERT_EQUAL (0, seq3[i]); } - + TypeUtils<int>::copy (seq2, &seq3[4], 4); for (int i = 0; i < 4; ++i) { CPPUNIT_ASSERT_EQUAL (seq1[i], seq3[i]); @@ -99,14 +99,14 @@ class TypeUtilsTest : public CppUnit::TestFixture } private: - + struct NonPodType { NonPodType() : data (42) {} bool operator== (NonPodType const & other) const { return data == other.data; } int data; }; - + }; diff --git a/libs/audiographer/tests/utils.h b/libs/audiographer/tests/utils.h index 2955f51102..b6b9e0136c 100644 --- a/libs/audiographer/tests/utils.h +++ b/libs/audiographer/tests/utils.h @@ -49,7 +49,7 @@ struct TestUtils unsigned int const granularity = 4096; float * data = new float[frames]; srand (std::time (NULL)); - + for (framecnt_t i = 0; i < frames; ++i) { do { int biased_int = (rand() % granularity) - (granularity / 2); @@ -127,10 +127,10 @@ class ProcessContextGrabber : public AudioGrapher::Sink<T> contexts.push_back (c); } using AudioGrapher::Sink<T>::process; - + typedef std::list<AudioGrapher::ProcessContext<T> > ContextList; ContextList contexts; - + }; #endif // AUDIOGRAPHER_TESTS_UTILS_H diff --git a/libs/audiographer/tests/utils/identity_vertex_test.cc b/libs/audiographer/tests/utils/identity_vertex_test.cc index 799dcca386..3c0fd71c70 100644 --- a/libs/audiographer/tests/utils/identity_vertex_test.cc +++ b/libs/audiographer/tests/utils/identity_vertex_test.cc @@ -17,7 +17,7 @@ class IdentityVertexTest : public CppUnit::TestFixture { frames = 128; random_data = TestUtils::init_random_data(frames); - + zero_data = new float[frames]; memset (zero_data, 0, frames * sizeof(float)); @@ -36,52 +36,52 @@ class IdentityVertexTest : public CppUnit::TestFixture vertex.reset (new IdentityVertex<float>()); vertex->add_output (sink_a); vertex->add_output (sink_b); - + framecnt_t frames_output = 0; - + ProcessContext<float> c (random_data, frames, 1); vertex->process (c); - + frames_output = sink_a->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); - + frames_output = sink_b->get_data().size(); CPPUNIT_ASSERT_EQUAL (frames, frames_output); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), frames)); } - + void testRemoveOutput() { vertex.reset (new IdentityVertex<float>()); vertex->add_output (sink_a); vertex->add_output (sink_b); - + ProcessContext<float> c (random_data, frames, 1); vertex->process (c); - + vertex->remove_output (sink_a); ProcessContext<float> zc (zero_data, frames, 1); vertex->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (zero_data, sink_b->get_array(), frames)); } - + void testClearOutputs() { vertex.reset (new IdentityVertex<float>()); vertex->add_output (sink_a); vertex->add_output (sink_b); - + ProcessContext<float> c (random_data, frames, 1); vertex->process (c); - + vertex->clear_outputs (); ProcessContext<float> zc (zero_data, frames, 1); vertex->process (zc); - + CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), frames)); CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), frames)); } |