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