class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / testsuite / supernova / osc_server_test.cpp
blob638ffab255ffe814f23e4c90e15ea153d3995da6
1 #include <boost/test/unit_test.hpp>
3 #include "utilities/osc_server.hpp"
4 #include "nova-tt/semaphore.hpp"
6 using namespace nova;
8 namespace
10 struct osc_test_responder:
11 public osc_responder
13 osc_test_responder(void):
14 i(0), sem(0)
17 void run(osc::ReceivedMessageArgumentIterator begin,
18 osc::ReceivedMessageArgumentIterator const & end)
20 ++i;
21 sem.post();
24 int i;
25 semaphore sem;
29 BOOST_AUTO_TEST_CASE( network_thread_test )
31 network_thread thread;
34 BOOST_AUTO_TEST_CASE( osc_server_test_1 )
36 osc_server server(12321);
39 BOOST_AUTO_TEST_CASE( osc_server_test_2 )
41 osc_server server(12321);
42 std::auto_ptr<osc_test_responder> resp (new osc_test_responder());
43 server.add_responder("/foo", resp.get());
44 server.remove_responder("/foo", resp.get());
47 BOOST_AUTO_TEST_CASE( osc_server_test_3 )
49 std::auto_ptr<osc_test_responder> resp (new osc_test_responder());
51 osc_server server(12321);
53 server.add_responder("/foo", resp.get());
56 using namespace boost::asio::ip;
58 boost::asio::io_service io_service;
60 udp::resolver resolver(io_service);
61 udp::resolver::query query(udp::v4(), "localhost", "12321");
62 udp::endpoint receiver_endpoint = *resolver.resolve(query);
64 udp::socket socket(io_service);
65 socket.open(udp::v4());
66 socket.send_to(boost::asio::buffer("/foo\0\0\0", 8), receiver_endpoint);
69 resp->sem.wait();
71 server.remove_responder("/foo", resp.get());
74 BOOST_REQUIRE_EQUAL(resp->i, 1);