1 #include "tests/utils.h"
3 #include "audiographer/utils/identity_vertex.h"
5 using namespace AudioGrapher
;
7 class IdentityVertexTest
: public CppUnit::TestFixture
9 CPPUNIT_TEST_SUITE (IdentityVertexTest
);
10 CPPUNIT_TEST (testProcess
);
11 CPPUNIT_TEST (testRemoveOutput
);
12 CPPUNIT_TEST (testClearOutputs
);
13 CPPUNIT_TEST_SUITE_END ();
19 random_data
= TestUtils::init_random_data(frames
);
21 zero_data
= new float[frames
];
22 memset (zero_data
, 0, frames
* sizeof(float));
24 sink_a
.reset (new VectorSink
<float>());
25 sink_b
.reset (new VectorSink
<float>());
30 delete [] random_data
;
36 vertex
.reset (new IdentityVertex
<float>());
37 vertex
->add_output (sink_a
);
38 vertex
->add_output (sink_b
);
40 framecnt_t frames_output
= 0;
42 ProcessContext
<float> c (random_data
, frames
, 1);
45 frames_output
= sink_a
->get_data().size();
46 CPPUNIT_ASSERT_EQUAL (frames
, frames_output
);
48 frames_output
= sink_b
->get_data().size();
49 CPPUNIT_ASSERT_EQUAL (frames
, frames_output
);
51 CPPUNIT_ASSERT (TestUtils::array_equals (random_data
, sink_a
->get_array(), frames
));
52 CPPUNIT_ASSERT (TestUtils::array_equals (random_data
, sink_b
->get_array(), frames
));
55 void testRemoveOutput()
57 vertex
.reset (new IdentityVertex
<float>());
58 vertex
->add_output (sink_a
);
59 vertex
->add_output (sink_b
);
61 ProcessContext
<float> c (random_data
, frames
, 1);
64 vertex
->remove_output (sink_a
);
65 ProcessContext
<float> zc (zero_data
, frames
, 1);
68 CPPUNIT_ASSERT (TestUtils::array_equals (random_data
, sink_a
->get_array(), frames
));
69 CPPUNIT_ASSERT (TestUtils::array_equals (zero_data
, sink_b
->get_array(), frames
));
72 void testClearOutputs()
74 vertex
.reset (new IdentityVertex
<float>());
75 vertex
->add_output (sink_a
);
76 vertex
->add_output (sink_b
);
78 ProcessContext
<float> c (random_data
, frames
, 1);
81 vertex
->clear_outputs ();
82 ProcessContext
<float> zc (zero_data
, frames
, 1);
85 CPPUNIT_ASSERT (TestUtils::array_equals (random_data
, sink_a
->get_array(), frames
));
86 CPPUNIT_ASSERT (TestUtils::array_equals (random_data
, sink_b
->get_array(), frames
));
90 boost::shared_ptr
<IdentityVertex
<float> > vertex
;
91 boost::shared_ptr
<VectorSink
<float> > sink_a
;
92 boost::shared_ptr
<VectorSink
<float> > sink_b
;
99 CPPUNIT_TEST_SUITE_REGISTRATION (IdentityVertexTest
);