Merge pull request #506 from andrewcsmith/patch-2
[supercollider.git] / testsuite / supernova / osc_server_test.cpp
bloba6cf412c4025b60620f409e7e5c7686be961e685
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 {
9 struct osc_test_responder:
10 public osc_responder
12 osc_test_responder(void):
13 i(0), sem(0)
16 void run(osc::ReceivedMessageArgumentIterator begin,
17 osc::ReceivedMessageArgumentIterator const & end)
19 ++i;
20 sem.post();
23 int i;
24 semaphore sem;
28 BOOST_AUTO_TEST_CASE( network_thread_test )
30 network_thread thread;
33 BOOST_AUTO_TEST_CASE( osc_server_test_1 )
35 osc_server server(12321);
38 BOOST_AUTO_TEST_CASE( osc_server_test_2 )
40 osc_server server(12321);
41 std::unique_ptr<osc_test_responder> resp (new osc_test_responder());
42 server.add_responder("/foo", resp.get());
43 server.remove_responder("/foo", resp.get());
46 BOOST_AUTO_TEST_CASE( osc_server_test_3 )
48 std::unique_ptr<osc_test_responder> resp (new osc_test_responder());
50 osc_server server(12321);
52 server.add_responder("/foo", resp.get());
55 using namespace boost::asio::ip;
57 boost::asio::io_service io_service;
59 udp::resolver resolver(io_service);
60 udp::resolver::query query(udp::v4(), "localhost", "12321");
61 udp::endpoint receiver_endpoint = *resolver.resolve(query);
63 udp::socket socket(io_service);
64 socket.open(udp::v4());
65 socket.send_to(boost::asio::buffer("/foo\0\0\0", 8), receiver_endpoint);
68 resp->sem.wait();
70 server.remove_responder("/foo", resp.get());
73 BOOST_REQUIRE_EQUAL(resp->i, 1);