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