inline unary ops: fix sc_floor for non-sse4.1
[supercollider.git] / testsuite / supernova / server_dsp_thread_queue_test.cpp
blobf1fa5995ff032dde2a7d7af0e62b5be608253286
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 #ifdef __GXX_EXPERIMENTAL_CXX0X__
30 #define auto_ptr unique_ptr
31 #define MOVE(X) std::move(X)
32 #else
33 #define MOVE(X) X
34 #endif
36 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_1 )
38 dsp_queue_interpreter interpreter(1);
40 bool runnable = interpreter.init_tick();
41 BOOST_REQUIRE(!runnable);
44 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_2 )
46 dsp_queue_interpreter interpreter(1);
48 bool runnable = interpreter.init_tick();
49 if (runnable)
50 interpreter.tick(0);
53 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_3 )
55 dsp_queue_interpreter interpreter(1);
57 std::auto_ptr<dsp_thread_queue> q (new dsp_thread_queue(1));
59 dsp_thread_queue_item * item = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 0);
61 q->add_initially_runnable(item);
63 interpreter.reset_queue(MOVE(q));
65 bool runnable = interpreter.init_tick();
66 BOOST_REQUIRE(runnable);
68 interpreter.tick(0);
70 BOOST_REQUIRE_EQUAL(item->get_job().i, 1);
73 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_4 )
75 dsp_queue_interpreter interpreter(1);
77 std::auto_ptr<dsp_thread_queue> q (new dsp_thread_queue(2));
79 dsp_thread_queue_item * item1 = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 1);
81 dsp_thread_queue_item::successor_list sl(1);
82 sl[0] = item1;
84 dsp_thread_queue_item * item2 = q->allocate_queue_item(dummy, sl, 0);
85 q->add_initially_runnable(item2);
87 interpreter.reset_queue(MOVE(q));
89 bool runnable = interpreter.init_tick();
90 BOOST_REQUIRE(runnable);
91 interpreter.tick(0);
93 BOOST_REQUIRE_EQUAL(item1->get_job().i, 1);
94 BOOST_REQUIRE_EQUAL(item2->get_job().i, 1);
97 BOOST_AUTO_TEST_CASE( dsp_thread_queue_test_5 )
99 dsp_queue_interpreter interpreter(1);
102 std::auto_ptr<dsp_thread_queue> q (new dsp_thread_queue(2));
104 dsp_thread_queue_item * item1 = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 1);
106 dsp_thread_queue_item::successor_list sl(1);
107 sl[0] = item1;
109 dsp_thread_queue_item * item2 = q->allocate_queue_item(dummy, sl, 0);
111 q->add_initially_runnable(item2);
113 interpreter.reset_queue(MOVE(q));
115 for (int i = 0; i != 2; ++i) {
116 bool runnable = interpreter.init_tick();
117 BOOST_REQUIRE(runnable);
118 interpreter.tick(0);
120 BOOST_REQUIRE_EQUAL(item1->get_job().i, 2);
121 BOOST_REQUIRE_EQUAL(item2->get_job().i, 2);
125 std::auto_ptr<dsp_thread_queue> q (new dsp_thread_queue(2));
127 dsp_thread_queue_item * item1 = q->allocate_queue_item(dummy, dsp_thread_queue_item::successor_list(), 1);
129 dsp_thread_queue_item::successor_list sl(1);
130 sl[0] = item1;
132 dsp_thread_queue_item * item2 = q->allocate_queue_item(dummy, sl, 0);
134 q->add_initially_runnable(item2);
136 interpreter.reset_queue(MOVE(q));
138 for (int i = 0; i != 2; ++i) {
139 bool runnable = interpreter.init_tick();
140 BOOST_REQUIRE(runnable);
141 interpreter.tick(0);
143 BOOST_REQUIRE_EQUAL(item1->get_job().i, 2);
144 BOOST_REQUIRE_EQUAL(item2->get_job().i, 2);