rob@76: /* rob@76: oscpack -- Open Sound Control (OSC) packet manipulation library rob@76: http://www.rossbencina.com/code/oscpack rob@76: rob@76: Copyright (c) 2004-2013 Ross Bencina rob@76: rob@76: Permission is hereby granted, free of charge, to any person obtaining rob@76: a copy of this software and associated documentation files rob@76: (the "Software"), to deal in the Software without restriction, rob@76: including without limitation the rights to use, copy, modify, merge, rob@76: publish, distribute, sublicense, and/or sell copies of the Software, rob@76: and to permit persons to whom the Software is furnished to do so, rob@76: subject to the following conditions: rob@76: rob@76: The above copyright notice and this permission notice shall be rob@76: included in all copies or substantial portions of the Software. rob@76: rob@76: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, rob@76: EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF rob@76: MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. rob@76: IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR rob@76: ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF rob@76: CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION rob@76: WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rob@76: */ rob@76: rob@76: /* rob@76: The text above constitutes the entire oscpack license; however, rob@76: the oscpack developer(s) also make the following non-binding requests: rob@76: rob@76: Any person wishing to distribute modifications to the Software is rob@76: requested to send the modifications to the original developer so that rob@76: they can be incorporated into the canonical version. It is also rob@76: requested that these non-binding requests be included whenever the rob@76: above license is reproduced. rob@76: */ rob@76: #include "OscSendTests.h" rob@76: rob@76: #include rob@76: #include rob@76: #include rob@76: rob@76: #if defined(__BORLANDC__) // workaround for BCB4 release build intrinsics bug rob@76: namespace std { rob@76: using ::__strcmp__; // avoid error: E2316 '__strcmp__' is not a member of 'std'. rob@76: } rob@76: #endif rob@76: rob@76: #include "osc/OscOutboundPacketStream.h" rob@76: rob@76: #include "ip/UdpSocket.h" rob@76: #include "ip/IpEndpointName.h" rob@76: rob@76: #define IP_MTU_SIZE 1536 rob@76: rob@76: namespace osc{ rob@76: rob@76: void RunSendTests( const IpEndpointName& host ) rob@76: { rob@76: char buffer[IP_MTU_SIZE]; rob@76: osc::OutboundPacketStream p( buffer, IP_MTU_SIZE ); rob@76: UdpTransmitSocket socket( host ); rob@76: rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test1" ) rob@76: << true << 23 << (float)3.1415 << "hello" << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: std::cout << "NOTE: sending /test1 message with too few arguments\n"\ rob@76: "(expect an exception if receiving with OscReceiveTest)\n\n"; rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test1" ) rob@76: << true << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: std::cout << "NOTE: sending /test1 message with too many arguments\n"\ rob@76: "(expect an exception if receiving with OscReceiveTest)\n\n"; rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test1" ) rob@76: << true << 23 << (float)3.1415 << "hello" << 42 << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: std::cout << "NOTE: sending /test1 message with wrong argument type\n"\ rob@76: "(expect an exception if receiving with OscReceiveTest)\n\n"; rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test1" ) rob@76: << true << 1.0 << (float)3.1415 << "hello" << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test2" ) rob@76: << true << 23 << (float)3.1415 << "hello" << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: // send four /test3 messages, each with a different type of argument rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test3" ) rob@76: << true << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test3" ) rob@76: << 23 << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test3" ) rob@76: << (float)3.1415 << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: p.Clear(); rob@76: p << osc::BeginMessage( "/test3" ) rob@76: << "hello" << osc::EndMessage; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: rob@76: // send a bundle rob@76: p.Clear(); rob@76: p << osc::BeginBundle(); rob@76: rob@76: p << osc::BeginMessage( "/no_arguments" ) rob@76: << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_bool" ) rob@76: << true << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_bool" ) rob@76: << false << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_bool" ) rob@76: << (bool)1234 << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/nil" ) rob@76: << osc::Nil << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/inf" ) rob@76: << osc::Infinitum << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/an_int" ) << 1234 << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_float" ) rob@76: << 3.1415926f << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_char" ) rob@76: << 'c' << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/an_rgba_color" ) rob@76: << osc::RgbaColor(0x22334455) << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_midi_message" ) rob@76: << MidiMessage(0x7F) << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/an_int64" ) rob@76: << (int64)(0xFFFFFFF) << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_time_tag" ) rob@76: << osc::TimeTag(0xFFFFFFFUL) << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_double" ) rob@76: << (double)3.1415926 << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_string" ) rob@76: << "hello world" << osc::EndMessage; rob@76: rob@76: p << osc::BeginMessage( "/a_symbol" ) rob@76: << osc::Symbol("foobar") << osc::EndMessage; rob@76: rob@76: // blob rob@76: { rob@76: char blobData[] = "abcd"; rob@76: rob@76: p << osc::BeginMessage( "/a_blob" ) rob@76: << osc::Blob( blobData, 4 ) rob@76: << osc::EndMessage; rob@76: } rob@76: rob@76: p << osc::EndBundle; rob@76: socket.Send( p.Data(), p.Size() ); rob@76: rob@76: rob@76: rob@76: // nested bundles, and multiple messages in bundles... rob@76: p.Clear(); rob@76: p << osc::BeginBundle( 1234 ) rob@76: << osc::BeginMessage( "/an_int" ) << 1 << osc::EndMessage rob@76: << osc::BeginMessage( "/an_int" ) << 2 << osc::EndMessage rob@76: << osc::BeginMessage( "/an_int" ) << 3 << osc::EndMessage rob@76: << osc::BeginMessage( "/an_int" ) << 4 << osc::EndMessage rob@76: << osc::BeginBundle( 12345 ) rob@76: << osc::BeginMessage( "/an_int" ) << 5 << osc::EndMessage rob@76: << osc::BeginMessage( "/an_int" ) << 6 << osc::EndMessage rob@76: << osc::EndBundle rob@76: << osc::EndBundle; rob@76: rob@76: socket.Send( p.Data(), p.Size() ); rob@76: } rob@76: rob@76: } // namespace osc rob@76: rob@76: #ifndef NO_OSC_TEST_MAIN rob@76: rob@76: int main(int argc, char* argv[]) rob@76: { rob@76: if( argc >= 2 && std::strcmp( argv[1], "-h" ) == 0 ){ rob@76: std::cout << "usage: OscSendTests [hostname [port]]\n"; rob@76: return 0; rob@76: } rob@76: rob@76: const char *hostName = "localhost"; rob@76: int port = 7000; rob@76: rob@76: if( argc >= 2 ) rob@76: hostName = argv[1]; rob@76: rob@76: if( argc >= 3 ) rob@76: port = std::atoi( argv[2] ); rob@76: rob@76: rob@76: IpEndpointName host( hostName, port ); rob@76: rob@76: char hostIpAddress[ IpEndpointName::ADDRESS_STRING_LENGTH ]; rob@76: host.AddressAsString( hostIpAddress ); rob@76: rob@76: std::cout << "sending test messages to " << hostName rob@76: << " (" << hostIpAddress << ") on port " << port << "...\n\n"; rob@76: rob@76: osc::RunSendTests( host ); rob@76: } rob@76: rob@76: #endif /* NO_OSC_TEST_MAIN */