1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
#include "tests/utils.h"
#include "audiographer/utils/identity_vertex.h"
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()
{
frames = 128;
random_data = TestUtils::init_random_data(frames);
zero_data = new float[frames];
memset (zero_data, 0, frames * sizeof(float));
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);
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));
}
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;
framecnt_t frames;
};
CPPUNIT_TEST_SUITE_REGISTRATION (IdentityVertexTest);
|