headers: sc_trunc - truncate via type casts
[supercollider.git] / testsuite / supernova / server_node_graph_test.cpp
blob8931b2e520599ba9a7d89aa00fbe33024c9fd047
1 #include <boost/test/unit_test.hpp>
3 #include "server/node_graph.hpp"
5 #include "test_synth.hpp"
7 #ifdef __GXX_EXPERIMENTAL_CXX0X__
8 #define auto_ptr unique_ptr
9 #endif
11 using namespace nova;
12 using namespace std;
14 BOOST_AUTO_TEST_CASE( simple_synth_test_1 )
16 rt_pool.init(1024 * 1024);
18 node_graph n;
20 node_position_constraint to_root = std::make_pair(n.root_group(), insert);
23 test_synth * s = new test_synth(1000, 0);
24 n.add_node(s, to_root);
25 BOOST_REQUIRE_EQUAL(n.synth_count(), 1u);
26 BOOST_REQUIRE_EQUAL(n.find_synth(1000), s);
27 n.remove_node(s);
28 BOOST_REQUIRE_EQUAL(n.synth_count(), 0u);
31 BOOST_REQUIRE_EQUAL(n.group_count(), 1u);
34 test_synth * s = new test_synth(1000, 0);
35 n.add_node(s/* , node_position_constraint() */);
36 BOOST_REQUIRE_EQUAL(n.synth_count(), 1u);
37 n.remove_node(s);
38 BOOST_REQUIRE_EQUAL(n.synth_count(), 0u);
41 BOOST_REQUIRE_EQUAL(n.group_count(), 1u);
44 BOOST_AUTO_TEST_CASE( simple_synth_test_2 )
46 node_graph n;
48 group * g = new group(1);
49 n.add_node(g);
50 BOOST_REQUIRE_EQUAL(n.find_group(1), g);
51 n.remove_node(g);
54 BOOST_AUTO_TEST_CASE( simple_synth_test_3 )
56 node_graph n;
58 group * g = new group(1);
60 n.add_node(g);
63 node_position_constraint to_group = std::make_pair(g, insert);
65 test_synth * s = new test_synth(1000, 0);
67 n.add_node(s, to_group);
68 n.remove_node(s);
70 n.remove_node(g);
73 BOOST_AUTO_TEST_CASE( simple_synth_test_4 )
75 node_graph n;
77 group * g = new group(1);
79 n.add_node(g);
81 test_synth * s = new test_synth(1000, 0);
83 node_position_constraint to_group = std::make_pair(g, insert);
85 n.add_node(s, to_group);
87 n.remove_node(g);
90 BOOST_AUTO_TEST_CASE( simple_synth_test_5 )
92 node_graph n;
94 test_synth * s = new test_synth(1000, 0);
95 test_synth * s2 = new test_synth(1001, 0);
97 n.add_node(s);
98 n.add_node(s2);
100 n.remove_node(s);
101 n.remove_node(s2);
105 BOOST_AUTO_TEST_CASE( simple_synth_test_6 )
107 node_graph n;
109 test_synth * s1 = new test_synth(1000, 0);
110 n.add_node(s1);
112 test_synth * s2 = new test_synth(1001, 0);
114 node_position_constraint to_group = std::make_pair(n.root_group(), insert);
116 n.add_node(s2, to_group);
119 test_synth * s3 = new test_synth(1002, 0);
121 node_position_constraint position = std::make_pair(s1, after);
123 n.add_node(s3, position);
126 test_synth * s4 = new test_synth(1003, 0);
128 node_position_constraint position = std::make_pair(s1, before);
130 n.add_node(s4, position);
133 //n.dump("test.dot");
135 n.remove_node(s1);
136 n.remove_node(s2);
137 n.remove_node(s3);
138 n.remove_node(s4);
141 BOOST_AUTO_TEST_CASE( free_all_test )
143 node_graph n;
145 group * g = new group(1);
147 n.add_node(g);
148 BOOST_REQUIRE_EQUAL(n.group_count(), 2u);
150 node_position_constraint to_group = std::make_pair(g, insert);
152 test_synth * s = new test_synth(1000, 0);
153 n.add_node(s, to_group);
155 test_synth * s2 = new test_synth(1001, 0);
156 n.add_node(s2, to_group);
158 group * g2 = new group(1002);
159 n.add_node(g2, to_group);
161 BOOST_REQUIRE_EQUAL(n.synth_count(), 2u);
162 BOOST_REQUIRE_EQUAL(n.group_count(), 3u);
164 BOOST_REQUIRE(n.find_node(s->id()));
165 BOOST_REQUIRE(n.find_node(s2->id()));
166 BOOST_REQUIRE(n.find_node(g2->id()));
168 BOOST_REQUIRE(n.group_free_all(g));
170 BOOST_REQUIRE(!n.find_node(s->id()));
171 BOOST_REQUIRE(!n.find_node(s2->id()));
172 BOOST_REQUIRE(!n.find_node(g2->id()));
174 BOOST_REQUIRE_EQUAL(n.synth_count(), 0u);
175 BOOST_REQUIRE_EQUAL(n.group_count(), 2u);
177 BOOST_REQUIRE(n.find_node(g->id()));
178 n.remove_node(g);
179 BOOST_REQUIRE(!n.find_node(g->id()));
180 BOOST_REQUIRE_EQUAL(n.group_count(), 1u);
183 BOOST_AUTO_TEST_CASE( free_deep_test )
185 node_graph n;
187 group * g = new group(1);
189 n.add_node(g);
190 BOOST_REQUIRE_EQUAL(n.group_count(), 2u);
192 node_position_constraint to_group = std::make_pair(g, insert);
194 test_synth * s = new test_synth(1000, 0);
195 n.add_node(s, to_group);
197 test_synth * s2 = new test_synth(1001, 0);
198 n.add_node(s2, to_group);
200 group * g2 = new group(1002);
201 n.add_node(g2, to_group);
203 BOOST_REQUIRE_EQUAL(n.synth_count(), 2u);
204 BOOST_REQUIRE_EQUAL(n.group_count(), 3u);
206 BOOST_REQUIRE(n.find_node(s->id()));
207 BOOST_REQUIRE(n.find_node(s2->id()));
208 BOOST_REQUIRE(n.find_node(g2->id()));
210 BOOST_REQUIRE(n.group_free_deep(g));
212 BOOST_REQUIRE(!n.find_node(s->id()));
213 BOOST_REQUIRE(!n.find_node(s2->id()));
214 BOOST_REQUIRE(n.find_node(g2->id()));
216 BOOST_REQUIRE_EQUAL(n.synth_count(), 0u);
217 BOOST_REQUIRE_EQUAL(n.group_count(), 3u);
219 BOOST_REQUIRE(n.find_node(g2->id()));
220 BOOST_REQUIRE(n.find_node(g->id()));
221 n.remove_node(g);
222 BOOST_REQUIRE(!n.find_node(g->id()));
223 BOOST_REQUIRE(!n.find_node(g2->id()));
224 BOOST_REQUIRE_EQUAL(n.group_count(), 1u);
228 BOOST_AUTO_TEST_CASE( queue_construction_test_1 )
230 node_graph n;
232 test_synth * s = new test_synth(1000, 0);
233 test_synth * s2 = new test_synth(1001, 0);
235 n.add_node(s);
236 n.add_node(s2);
238 auto_ptr<node_graph::dsp_thread_queue> q = n.generate_dsp_queue();
240 n.remove_node(s);
241 n.remove_node(s2);
244 BOOST_AUTO_TEST_CASE( queue_construction_test_2 )
246 node_graph n;
248 group * g = new group(1);
250 n.add_node(g);
251 auto_ptr<node_graph::dsp_thread_queue> q = n.generate_dsp_queue();
252 BOOST_REQUIRE_EQUAL(q->get_total_node_count(), 0u);
254 n.remove_node(g);
257 BOOST_AUTO_TEST_CASE( queue_construction_test_3 )
259 node_graph n;
261 test_synth * s = new test_synth(1000, 0);
262 n.add_node(s);
264 auto_ptr<node_graph::dsp_thread_queue> q1 = n.generate_dsp_queue();
265 BOOST_REQUIRE_EQUAL(q1->get_total_node_count(), 1u);
267 test_synth * s2 = new test_synth(3, 0);
268 n.add_node(s2);
270 auto_ptr<node_graph::dsp_thread_queue> q2 = n.generate_dsp_queue();
271 BOOST_REQUIRE_EQUAL(q2->get_total_node_count(), 1u);
273 n.remove_node(s);
274 n.remove_node(s2);
280 BOOST_AUTO_TEST_CASE( pgroup_test_1 )
282 node_graph n;
284 parallel_group * g = new parallel_group(1);
285 n.add_node(g);
286 BOOST_REQUIRE_EQUAL(n.find_group(1), g);
288 auto_ptr<node_graph::dsp_thread_queue> q = n.generate_dsp_queue();
289 BOOST_REQUIRE_EQUAL(q->get_total_node_count(), 0u);
290 n.remove_node(g);
294 BOOST_AUTO_TEST_CASE( pgroup_test_2 )
296 node_graph n;
298 parallel_group * g = new parallel_group(1);
300 n.add_node(g);
303 node_position_constraint to_group = std::make_pair(g, insert);
305 test_synth * s = new test_synth(2, 0);
306 n.add_node(s, to_group);
307 n.remove_node(s);
309 n.remove_node(g);
312 BOOST_AUTO_TEST_CASE( pgroup_test_3 )
314 node_graph n;
316 parallel_group * g = new parallel_group(1);
318 n.add_node(g);
320 test_synth * s = new test_synth(2, 0);
322 node_position_constraint to_group = std::make_pair(g, insert);
324 n.add_node(s, to_group);
326 n.remove_node(g);
329 BOOST_AUTO_TEST_CASE( pgroup_test_4 )
331 node_graph n;
333 parallel_group * g = new parallel_group(1);
335 n.add_node(g);
338 node_position_constraint to_group = std::make_pair(g, insert);
340 test_synth * s = new test_synth(2, 0);
341 n.add_node(s, to_group);
343 auto_ptr<node_graph::dsp_thread_queue> q = n.generate_dsp_queue();
344 BOOST_REQUIRE_EQUAL(q->get_total_node_count(), 1u);
346 n.remove_node(s);
348 n.remove_node(g);
352 BOOST_AUTO_TEST_CASE( pgroup_test_5 )
354 node_graph n;
356 parallel_group * g = new parallel_group(1);
358 n.add_node(g);
361 node_position_constraint to_group = std::make_pair(g, insert);
363 test_synth * s1 = new test_synth(2, 0);
364 test_synth * s2 = new test_synth(3, 0);
365 n.add_node(s1, to_group);
366 n.add_node(s2, to_group);
368 auto_ptr<node_graph::dsp_thread_queue> q = n.generate_dsp_queue();
370 BOOST_REQUIRE_EQUAL(q->get_total_node_count(), 2u);
372 n.remove_node(s1);
373 n.remove_node(s2);
375 n.remove_node(g);
378 BOOST_AUTO_TEST_CASE( pgroup_test_6 )
380 node_graph n;
382 parallel_group * g = new parallel_group(1);
384 n.add_node(g);
387 node_position_constraint to_group = std::make_pair(g, insert);
389 test_synth * s1 = new test_synth(2, 0);
390 test_synth * s2 = new test_synth(3, 0);
391 test_synth * s3 = new test_synth(4, 0);
392 n.add_node(s1, to_group);
393 n.add_node(s2, to_group);
394 n.add_node(s3, to_group);
396 auto_ptr<node_graph::dsp_thread_queue> q = n.generate_dsp_queue();
397 BOOST_REQUIRE_EQUAL(q->get_total_node_count(), 3u);
399 n.remove_node(g);
402 BOOST_AUTO_TEST_CASE( pgroup_test_7 )
404 node_graph n;
406 parallel_group * g = new parallel_group(1);
408 n.add_node(g);
411 node_position_constraint to_group = std::make_pair(g, insert);
413 group * g1 = new group(2);
414 group * g2 = new group(3);
415 group * g3 = new group(4);
416 n.add_node(g1, to_group);
417 n.add_node(g2, to_group);
418 n.add_node(g3, to_group);
420 node_position_constraint to_g1 = std::make_pair(g1, insert);
421 node_position_constraint to_g2 = std::make_pair(g2, insert);
422 test_synth * s1 = new test_synth(1000, 0);
423 test_synth * s2 = new test_synth(1001, 0);
424 n.add_node(s1, to_g1);
425 n.add_node(s2, to_g2);
427 auto_ptr<node_graph::dsp_thread_queue> q = n.generate_dsp_queue();
428 BOOST_REQUIRE_EQUAL(q->get_total_node_count(), 2u);
430 n.remove_node(g);
433 BOOST_AUTO_TEST_CASE( noid_test )
435 rt_pool.init(1024 * 1024);
437 node_graph n;
439 node_position_constraint to_root = std::make_pair(n.root_group(), insert);
442 test_synth * s = new test_synth(1000, 0);
443 n.add_node(s, to_root);
444 BOOST_REQUIRE(s->id() == 1000 );
445 n.synth_reassign_id(1000);
446 BOOST_REQUIRE(s->id() != 1000 );
447 n.remove_node(s);
451 test_synth * s = new test_synth(1000, 0);
452 n.add_node(s/* , node_position_constraint() */);
453 BOOST_REQUIRE(s->id() == 1000 );
454 n.synth_reassign_id(1000);
455 BOOST_REQUIRE(s->id() != 1000 );
456 n.remove_node(s);