File: ProcessingTest.cxx

package info (click to toggle)
clam 1.4.0-5.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 17,780 kB
  • sloc: cpp: 92,499; python: 9,721; ansic: 1,602; xml: 444; sh: 239; makefile: 153; perl: 54; asm: 15
file content (360 lines) | stat: -rw-r--r-- 11,574 bytes parent folder | download | duplicates (2)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#include <cppunit/extensions/HelperMacros.h>
#include "Processing.hxx" // CLAM

#include "InPort.hxx" // CLAM
#include "InControl.hxx" // CLAM
#include <CLAM/InControl.hxx> // CLAM
#include "OutPort.hxx" // CLAM
#include "OutControl.hxx" // CLAM
#include <CLAM/OutControl.hxx> // CLAM
#include "DummyProcessingData.hxx"

namespace CLAMTest
{

class ProcessingTest;
CPPUNIT_TEST_SUITE_REGISTRATION( ProcessingTest );

class ProcessingTest : public CppUnit::TestFixture, public CLAM::Processing
{
	CPPUNIT_TEST_SUITE( ProcessingTest );

	CPPUNIT_TEST( testGetInControl_GetTheRightControl );
	CPPUNIT_TEST( testGetOutControl_GetTheRightControl );
	CPPUNIT_TEST( testGetInControl_WithOutOfRangeIndexThrowException );
	CPPUNIT_TEST( testGetOutControl_WithOutOfRangeIndexThrowException );
	CPPUNIT_TEST( testLinkAndSendControl_ChangesInControlState );
	// new controls/ports interface.
	// todo: adapt the old tests:
	CPPUNIT_TEST( testInControls_GetByNumber_GetTheRightControl );
	CPPUNIT_TEST( testOutControls_GetByNumber_GetTheRightControl );
	CPPUNIT_TEST( testOutPorts_GetByNumber_GetTheRightPort );
	CPPUNIT_TEST( testInPorts_GetByNumber_GetTheRightPort );
	CPPUNIT_TEST( testInControls_GetByName_GetTheRightControl );
	CPPUNIT_TEST( testOutControls_GetByName_GetTheRightControl );
	CPPUNIT_TEST( testOutPorts_GetByName_GetTheRightPort );
	CPPUNIT_TEST( testInPorts_GetByName_GetTheRightPort );
	CPPUNIT_TEST( testInControls_Size );
	CPPUNIT_TEST( testOutControls_Size );
	CPPUNIT_TEST( testInPorts_Size );
	CPPUNIT_TEST( testOutPorts_Size );
	CPPUNIT_TEST( testOutPorts_Delete);
	CPPUNIT_TEST( testInPorts_Delete);
	CPPUNIT_TEST( testOutControls_Delete);
	CPPUNIT_TEST( testInControls_Delete);
	CPPUNIT_TEST( testUnRegistredOutPorts);
	CPPUNIT_TEST( testUnRegistredInPorts);
	CPPUNIT_TEST( testUnRegistredOutControls);
	CPPUNIT_TEST( testUnRegistredInControls);
		
	CPPUNIT_TEST( testConnectPorts_usingNames );
	CPPUNIT_TEST( testConnectPorts_usingNumbers );
	CPPUNIT_TEST( testConnectControls_usingNames );
	CPPUNIT_TEST( testConnectControls_usingNumbers );
	CPPUNIT_TEST( testHasInControl_usingRegisteredControlName );
	CPPUNIT_TEST( testHasInControl_usingNotRegisteredControlName );
	CPPUNIT_TEST( testHasOutControl_usingRegisteredControlName );
	CPPUNIT_TEST( testHasOutControl_usingNotRegisteredControlName );

	CPPUNIT_TEST( testIsSyncSource_default );
	
	CPPUNIT_TEST_SUITE_END();

public:
	template<class TControlData>
	class InControl;
	template<class TControlData>
	class OutControl;

	// void implementation the pure virtual methods of processing
	ProcessingTest() : 
		mInControl("in", this), 
		mInControlCallback("in tmpl",this,&ProcessingTest::ControlHandler),
		mOutControl1("out1", this),
		mOutControl2("out2", this),
		
		mTypedInControl("TypedIn", this),
		mTypedOutControl("TypedOut", this),
		mTypedOutControl2("TypedOut2", this),
		
		mInPort(std::string("in"),this),
		mOutPort1("out1",this),
		mOutPort2("out2",this)
	{};

private:
	// using testing pattern Self Shunt (make the fixture be a Processing under test)
	bool ConcreteConfigure(const CLAM::ProcessingConfig&) { return false; }
	const CLAM::ProcessingConfig &GetConfig() const {
		return *static_cast<CLAM::ProcessingConfig*>(0);
	}
	bool Do(void){ return false; }
	const char * GetClassName() const { return "ProcessingTest"; };	
	void ControlHandler( CLAM::TControlData ) { };
	
	CLAM::FloatInControl mInControl;
	CLAM::FloatInControl mInControlCallback;
	CLAM::FloatOutControl mOutControl1;
	CLAM::FloatOutControl mOutControl2;
	
	CLAM::InControl<int> mTypedInControl;
	CLAM::OutControl<int> mTypedOutControl;
	CLAM::OutControl<float> mTypedOutControl2;
	
	CLAM::InPort<DummyProcessingData> mInPort;
	CLAM::OutPort<DummyProcessingData> mOutPort1;
	CLAM::OutPort<DummyProcessingData> mOutPort2;

	void testGetInControl_GetTheRightControl()
	{
		CPPUNIT_ASSERT_EQUAL( std::string("in"), GetInControl(0).GetName() );
	}
	void testGetOutControl_GetTheRightControl()
	{
		CPPUNIT_ASSERT_EQUAL( std::string("out1"), GetOutControl(0).GetName() );
	}
	void testGetInControl_WithOutOfRangeIndexThrowException() 
	{
		try
		{
			GetInControl(2); // we have two published in controls: indexs 0,1
			CPPUNIT_FAIL("std::out_of_range was expected but none was thrown");
		}
		catch( ... ) {}
	}
	void testGetOutControl_WithOutOfRangeIndexThrowException() 
	{
		try
		{
			GetOutControl(2); // we have two published out controls: indexs 0,1
			CPPUNIT_FAIL("std::out_of_range was expected but none was thrown");
		}
		catch( ... ) {}
	}
	void testLinkAndSendControl_ChangesInControlState()
	{
		const int outId=0, inId=0;
		GetOutControl(outId).AddLink(GetInControl(inId));
		SendFloatToOutControl(*this,outId,1.f);
		CPPUNIT_ASSERT_EQUAL( 1.f, GetFloatFromInControl(*this,inId) );
	}
	//---------------------------------------
	// new controls/ports interface tests

	void testInControls_GetByNumber_GetTheRightControl()
	{
		CLAM::InControlBase* returned = &GetInControl(0);
		CLAM::InControlBase* expected = &mInControl;
		CPPUNIT_ASSERT_EQUAL( expected, returned );
	}
	void testOutControls_GetByNumber_GetTheRightControl()
	{
		CLAM::OutControlBase* returned = &GetOutControl(1); // get the second control
		CLAM::OutControlBase* expected = &mOutControl2;
		CPPUNIT_ASSERT_EQUAL( expected, returned );
	}
	void testOutPorts_GetByNumber_GetTheRightPort()
	{
		CLAM::OutPortBase* returnedPort = &GetOutPort(1); // get the second port
		CLAM::OutPortBase* expectedPort = &mOutPort2;
		CPPUNIT_ASSERT_EQUAL( expectedPort,  returnedPort );
	}
	void testInPorts_GetByNumber_GetTheRightPort()
	{
		CLAM::InPortBase* returnedPort = &GetInPort(0); // get the first port
		CLAM::InPortBase* expectedPort = &mInPort;
		CPPUNIT_ASSERT_EQUAL( expectedPort,  returnedPort );
	}
	void testInControls_GetByName_GetTheRightControl()
	{
		CLAM::InControlBase* returned = &GetInControl("in");
		CLAM::InControlBase* expected = &mInControl;
		CPPUNIT_ASSERT_EQUAL( expected, returned );
	}

	void testOutControls_GetByName_GetTheRightControl()
	{
		CLAM::OutControlBase* returned = &GetOutControl("out2"); // get the second control
		CLAM::OutControlBase* expected = &mOutControl2;
		CPPUNIT_ASSERT_EQUAL( expected, returned );
	}
	void testOutPorts_GetByName_GetTheRightPort()
	{
		CLAM::OutPortBase* returnedPort = &GetOutPort("out2"); // get the second port
		CLAM::OutPortBase* expectedPort = &mOutPort2;
		CPPUNIT_ASSERT_EQUAL( expectedPort,  returnedPort );
	}
	void testInPorts_GetByName_GetTheRightPort()
	{
		CLAM::InPortBase* returnedPort = &GetInPort("in"); // get the first port
		CLAM::InPortBase* expectedPort = &mInPort;
		CPPUNIT_ASSERT_EQUAL( expectedPort,  returnedPort );
	}

	void testInControls_Size()
	{
		CPPUNIT_ASSERT_EQUAL( 3, GetInControls().Size() );
	}
	void testOutControls_Size()
	{
		CPPUNIT_ASSERT_EQUAL( 4, GetOutControls().Size() );
	}
	void testInPorts_Size()
	{
		CPPUNIT_ASSERT_EQUAL( 1, GetInPorts().Size() );
	}
	void testOutPorts_Size()
	{
		CPPUNIT_ASSERT_EQUAL( 2, GetOutPorts().Size() );
	}
	void testOutPorts_Delete()
	{
		int initialNumPorts = GetOutPorts().Size();
		CLAM::OutPort<int>* port = new CLAM::OutPort<int>( "out", this);
		CPPUNIT_ASSERT_EQUAL( initialNumPorts+1, GetOutPorts().Size() );
		delete port;
		CPPUNIT_ASSERT_EQUAL( initialNumPorts, GetOutPorts().Size() );

	}
	void testInPorts_Delete()
	{
		int initialNumPorts = GetInPorts().Size();
		CLAM::InPort<int>* port = new CLAM::InPort<int>( "in", this);
		CPPUNIT_ASSERT_EQUAL( initialNumPorts+1, GetInPorts().Size() );
		delete port;
		CPPUNIT_ASSERT_EQUAL( initialNumPorts, GetInPorts().Size() );

	}
	void testOutControls_Delete()
	{
		int initialNumControls = GetOutControls().Size();
		CLAM::OutControlBase* control = new CLAM::FloatOutControl( "outControl", this);
		CPPUNIT_ASSERT_EQUAL( initialNumControls+1, GetOutControls().Size() );
		delete control;
		CPPUNIT_ASSERT_EQUAL( initialNumControls, GetOutControls().Size() );

	}
	void testInControls_Delete()
	{
		int initialNumControls = GetInControls().Size();
		CLAM::FloatInControl* control = new CLAM::FloatInControl( "inControl", this);
		CPPUNIT_ASSERT_EQUAL( initialNumControls+1, GetInControls().Size() );
		delete control;
		CPPUNIT_ASSERT_EQUAL( initialNumControls, GetInControls().Size() );

	}
	void testUnRegistredOutPorts()
	{	int initialNumPorts = GetOutPorts().Size();
		new CLAM::OutPort<int>( "out");
		CPPUNIT_ASSERT_EQUAL( initialNumPorts, GetOutPorts().Size() );
	}	
	void testUnRegistredInPorts()
	{	int initialNumPorts = GetInPorts().Size();
		new CLAM::InPort<int>( "in");
		CPPUNIT_ASSERT_EQUAL( initialNumPorts, GetInPorts().Size() );
	}
	void testUnRegistredOutControls()
	{	int initialNumControls = GetOutControls().Size();
		new CLAM::FloatOutControl( "outControl");
		CPPUNIT_ASSERT_EQUAL( initialNumControls, GetOutControls().Size() );
	}	
	void testUnRegistredInControls()
	{	int initialNumControls = GetInControls().Size();
		new CLAM::FloatInControl( "inControl");
		CPPUNIT_ASSERT_EQUAL( initialNumControls, GetInControls().Size() );
	}

	class DummyIOProcessing : public CLAM::Processing
	{
	public:
		CLAM::InPort<int> in;
		CLAM::OutPort<int> out;
		CLAM::FloatInControl inControl;
		CLAM::FloatOutControl outControl;
//		CLAM::InControl<int> typedInControl;
//		CLAM::OutControl<int> typedOutControl;
		
		DummyIOProcessing()
			: in("In", this)
			, out("Out", this)
			, inControl("In", this)
			, outControl("Out", this)
//			, typedInControl("TypedIn", this)
//			, typedOutControl("TypedOut", this)
		{
		}
		bool Do() { return false; }
		const char* GetClassName() const { return ""; }
		bool ConcreteConfigure(const CLAM::ProcessingConfig & ) { return false; }
		const CLAM::ProcessingConfig & GetConfig() const { throw 0;}

		
	};
	void testConnectPorts_usingNames()
	{
		DummyIOProcessing sender, receiver;
		CLAM::ConnectPorts(sender, "Out", receiver, "In");
		sender.out.GetData()=2;
		sender.out.Produce();
		CPPUNIT_ASSERT_EQUAL(2, receiver.in.GetData() );
	}
	void testConnectPorts_usingNumbers()
	{
		DummyIOProcessing sender, receiver;
		CLAM::ConnectPorts(sender, 0, receiver, 0);
		sender.out.GetData()=2;
		sender.out.Produce();
		CPPUNIT_ASSERT_EQUAL(2, receiver.in.GetData() );
	}
	void testConnectControls_usingNames()
	{
		DummyIOProcessing sender, receiver;
		CLAM::ConnectControls(sender, "Out", receiver, "In");
		receiver.inControl.DoControl(666); // A previous value
		CLAM::TControlData event(1.7);
		sender.outControl.SendControl(event);
		CPPUNIT_ASSERT_EQUAL(event, receiver.inControl.GetLastValue() );
	}
	void testConnectControls_usingNumbers()
	{

		DummyIOProcessing sender, receiver;
		CLAM::ConnectControls(sender, 0, receiver, 0);
		receiver.inControl.DoControl(666); // A previous value
		CLAM::TControlData event(1.7);
		sender.outControl.SendControl(event);
		CPPUNIT_ASSERT_EQUAL(event, receiver.inControl.GetLastValue() );
	}

	void testHasInControl_usingRegisteredControlName()
	{
		DummyIOProcessing test;
		CPPUNIT_ASSERT_EQUAL(true, test.HasInControl("In"));
	}
	void testHasInControl_usingNotRegisteredControlName()
	{
		DummyIOProcessing test;
		CPPUNIT_ASSERT_EQUAL(false, test.HasInControl("FalseIn"));
	}
	void testHasOutControl_usingRegisteredControlName()
	{
		DummyIOProcessing test;
		CPPUNIT_ASSERT_EQUAL(true, test.HasOutControl("Out"));
	}
	void testHasOutControl_usingNotRegisteredControlName()
	{
		DummyIOProcessing test;
		CPPUNIT_ASSERT_EQUAL(false, test.HasOutControl("FalseOut"));
	}

	void testIsSyncSource_default()
	{
		DummyIOProcessing proc;
		CPPUNIT_ASSERT_EQUAL( false, proc.IsSyncSource() );
	}


};

} // namespace CLAMTest