class library: Spawner - don't access PriorityQueue-array
[supercollider.git] / testsuite / supernova / osc_dispatcher_test.cpp
blobc64c9772fe928b603f0e780a06130f1ef49fd75e
1 #include <boost/test/unit_test.hpp>
3 #include "utilities/osc_dispatcher.hpp"
4 #include <memory>
6 using namespace nova;
7 using namespace std;
9 namespace
11 struct osc_test_responder:
12 public osc_responder
14 osc_test_responder(void):
15 i(0)
18 void run(osc::ReceivedMessageArgumentIterator begin,
19 osc::ReceivedMessageArgumentIterator const & end)
21 ++i;
24 int i;
28 BOOST_AUTO_TEST_CASE( osc_dispatcher_test_1 )
30 osc_dispatcher dispatcher;
32 std::auto_ptr<osc_test_responder> resp (new osc_test_responder());
33 dispatcher.add_responder("foo", resp.get());
34 dispatcher.remove_responder("foo", resp.get());
37 BOOST_AUTO_TEST_CASE( osc_pattern_test )
39 BOOST_REQUIRE_EQUAL(osc_dispatcher::is_pattern("/abc?de"), true);
40 BOOST_REQUIRE_EQUAL(osc_dispatcher::is_pattern("/abc*de"), true);
41 BOOST_REQUIRE_EQUAL(osc_dispatcher::is_pattern("/ab*?de"), true);
42 BOOST_REQUIRE_EQUAL(osc_dispatcher::is_pattern("/abcde"), false);
44 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/abcde", "/abcde"), true);
45 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/abcde", "/abcdef"), false);
46 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/abcdef", "/abcde"), false);
48 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab?de", "/abcde"), true);
49 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab?de", "/abcdf"), false);
50 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab?de", "/abcdef"), false);
52 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab*de", "/abcde"), true);
53 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab*de", "/ab"), false);
54 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab*de", "/abxyz"), false);
55 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab*de", "/abxdez"), false);
56 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab*de*", "/abxdez"), true);
57 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/ab*de*", "/abxedz"), false);
58 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/*de*", "/abcdefghi"), true);
59 BOOST_REQUIRE_EQUAL(osc_dispatcher::match_pattern("/*de*", "/abcedfghi"), false);
63 BOOST_AUTO_TEST_CASE( osc_dispatcher_test_2 )
65 osc_dispatcher dispatcher;
67 std::auto_ptr<osc_test_responder> resp (new osc_test_responder());
68 dispatcher.add_responder("/foo", resp.get());
69 dispatcher.add_responder("/fpp", resp.get());
71 dispatcher.handle_packet("/foo\0\0\0", 8);
72 dispatcher.handle_packet("/fo*\0\0\0", 8);
74 BOOST_REQUIRE_EQUAL(resp->i, 2);
75 dispatcher.remove_responder("/foo", resp.get());
76 dispatcher.remove_responder("/fpp", resp.get());