2010-03-15 15:11:48 -04:00
|
|
|
#include "tests/utils.h"
|
|
|
|
|
|
|
|
#include "audiographer/utils/identity_vertex.h"
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
using namespace AudioGrapher;
|
|
|
|
|
|
|
|
class IdentityVertexTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE (IdentityVertexTest);
|
|
|
|
CPPUNIT_TEST (testProcess);
|
|
|
|
CPPUNIT_TEST (testRemoveOutput);
|
|
|
|
CPPUNIT_TEST (testClearOutputs);
|
|
|
|
CPPUNIT_TEST_SUITE_END ();
|
|
|
|
|
|
|
|
public:
|
|
|
|
void setUp()
|
|
|
|
{
|
2017-09-18 12:39:17 -04:00
|
|
|
samples = 128;
|
|
|
|
random_data = TestUtils::init_random_data(samples);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
zero_data = new float[samples];
|
|
|
|
memset (zero_data, 0, samples * sizeof(float));
|
2009-12-27 09:46:23 -05:00
|
|
|
|
|
|
|
sink_a.reset (new VectorSink<float>());
|
|
|
|
sink_b.reset (new VectorSink<float>());
|
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown()
|
|
|
|
{
|
|
|
|
delete [] random_data;
|
|
|
|
delete [] zero_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void testProcess()
|
|
|
|
{
|
|
|
|
vertex.reset (new IdentityVertex<float>());
|
|
|
|
vertex->add_output (sink_a);
|
|
|
|
vertex->add_output (sink_b);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t samples_output = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
vertex->process (c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samples_output = sink_a->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (samples, samples_output);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
samples_output = sink_b->get_data().size();
|
|
|
|
CPPUNIT_ASSERT_EQUAL (samples, samples_output);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), samples));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), samples));
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
void testRemoveOutput()
|
|
|
|
{
|
|
|
|
vertex.reset (new IdentityVertex<float>());
|
|
|
|
vertex->add_output (sink_a);
|
|
|
|
vertex->add_output (sink_b);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
vertex->process (c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
vertex->remove_output (sink_a);
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> zc (zero_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
vertex->process (zc);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), samples));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (zero_data, sink_b->get_array(), samples));
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
void testClearOutputs()
|
|
|
|
{
|
|
|
|
vertex.reset (new IdentityVertex<float>());
|
|
|
|
vertex->add_output (sink_a);
|
|
|
|
vertex->add_output (sink_b);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> c (random_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
vertex->process (c);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-27 09:46:23 -05:00
|
|
|
vertex->clear_outputs ();
|
2017-09-18 12:39:17 -04:00
|
|
|
ProcessContext<float> zc (zero_data, samples, 1);
|
2009-12-27 09:46:23 -05:00
|
|
|
vertex->process (zc);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_a->get_array(), samples));
|
|
|
|
CPPUNIT_ASSERT (TestUtils::array_equals (random_data, sink_b->get_array(), samples));
|
2009-12-27 09:46:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
boost::shared_ptr<IdentityVertex<float> > vertex;
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink_a;
|
|
|
|
boost::shared_ptr<VectorSink<float> > sink_b;
|
|
|
|
|
|
|
|
float * random_data;
|
|
|
|
float * zero_data;
|
2017-09-18 12:39:17 -04:00
|
|
|
samplecnt_t samples;
|
2009-12-27 09:46:23 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION (IdentityVertexTest);
|
|
|
|
|