Fixed two typos in the update news
[supercollider.git] / testsuite / supernova / server_dsp_thread_queue_test.cpp
bloba43d0ffc5594553d9f45a0ecdf382cc8b278e4d6
1 #include <boost/test/unit_test.hpp>
3 #include "dsp_thread_queue/dsp_thread_queue.hpp"
5 namespace
8 struct dummy_runnable
10 dummy_runnable(void):
11 i(0)
14 void operator()(unsigned int dummy)
16 ++i;
19 int i;
22 dummy_runnable dummy;
25 typedef nova::dsp_queue_interpreter<dummy_runnable> dsp_queue_interpreter;
26 typedef nova::dsp_thread_queue_item<dummy_runnable> dsp_thread_queue_item;
27 typedef nova::dsp_thread_queue<dummy_runnable> dsp_thread_queue;
29 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_1 )
31 dsp_queue_interpreter interpreter(1);
33 bool runnable = interpreter.init_tick();
34 BOOST_REQUIRE(!runnable);
37 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_2 )
39 dsp_queue_interpreter interpreter(1);
41 bool runnable = interpreter.init_tick();
42 if (runnable)
43 interpreter.tick(0);
46 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_3 )
48 dsp_queue_interpreter interpreter(1);
50 std::unique_ptr<dsp_thread_queue> q (new dsp_thread_queue(1));
52 dsp_thread_queue_item * item = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 0);
54 q->add_initially_runnable(item);
56 interpreter.reset_queue(std::move(q));
58 bool runnable = interpreter.init_tick();
59 BOOST_REQUIRE(runnable);
61 interpreter.tick(0);
63 BOOST_REQUIRE_EQUAL(item->get_job().i, 1);
66 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_4 )
68 dsp_queue_interpreter interpreter(1);
70 std::unique_ptr<dsp_thread_queue> q (new dsp_thread_queue(2));
72 dsp_thread_queue_item * item1 = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 1);
74 dsp_thread_queue_item::successor_list sl(1);
75 sl[0] = item1;
77 dsp_thread_queue_item * item2 = q->allocate_queue_item(dummy, sl, 0);
78 q->add_initially_runnable(item2);
80 interpreter.reset_queue(std::move(q));
82 bool runnable = interpreter.init_tick();
83 BOOST_REQUIRE(runnable);
84 interpreter.tick(0);
86 BOOST_REQUIRE_EQUAL(item1->get_job().i, 1);
87 BOOST_REQUIRE_EQUAL(item2->get_job().i, 1);
90 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_5 )
92 dsp_queue_interpreter interpreter(1);
95 std::unique_ptr<dsp_thread_queue> q (new dsp_thread_queue(2));
97 dsp_thread_queue_item * item1 = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 1);
99 dsp_thread_queue_item::successor_list sl(1);
100 sl[0] = item1;
102 dsp_thread_queue_item * item2 = q->allocate_queue_item(dummy, sl, 0);
104 q->add_initially_runnable(item2);
106 interpreter.reset_queue(std::move(q));
108 for (int i = 0; i != 2; ++i) {
109 bool runnable = interpreter.init_tick();
110 BOOST_REQUIRE(runnable);
111 interpreter.tick(0);
113 BOOST_REQUIRE_EQUAL(item1->get_job().i, 2);
114 BOOST_REQUIRE_EQUAL(item2->get_job().i, 2);
118 std::unique_ptr<dsp_thread_queue> q (new dsp_thread_queue(2));
120 dsp_thread_queue_item * item1 = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 1);
122 dsp_thread_queue_item::successor_list sl(1);
123 sl[0] = item1;
125 dsp_thread_queue_item * item2 = q->allocate_queue_item(dummy, sl, 0);
127 q->add_initially_runnable(item2);
129 interpreter.reset_queue(std::move(q));
131 for (int i = 0; i != 2; ++i) {
132 bool runnable = interpreter.init_tick();
133 BOOST_REQUIRE(runnable);
134 interpreter.tick(0);
136 BOOST_REQUIRE_EQUAL(item1->get_job().i, 2);
137 BOOST_REQUIRE_EQUAL(item2->get_job().i, 2);