annotate trunk/external/oscpack/tests/OscSendTests.cpp @ 706:f8e90b5d85fd tip

Delete CARFAC code from this repository. It has been moved to https://github.com/google/carfac Please email me with your github username to get access. I've also created a new mailing list to discuss CARFAC development: https://groups.google.com/forum/#!forum/carfac-dev
author ronw@google.com
date Thu, 18 Jul 2013 20:56:51 +0000
parents 4b37b53105a3
children
rev   line source
tomwalters@570 1 /*
tomwalters@570 2 oscpack -- Open Sound Control packet manipulation library
tomwalters@570 3 http://www.audiomulch.com/~rossb/oscpack
tomwalters@570 4
tomwalters@570 5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com>
tomwalters@570 6
tomwalters@570 7 Permission is hereby granted, free of charge, to any person obtaining
tomwalters@570 8 a copy of this software and associated documentation files
tomwalters@570 9 (the "Software"), to deal in the Software without restriction,
tomwalters@570 10 including without limitation the rights to use, copy, modify, merge,
tomwalters@570 11 publish, distribute, sublicense, and/or sell copies of the Software,
tomwalters@570 12 and to permit persons to whom the Software is furnished to do so,
tomwalters@570 13 subject to the following conditions:
tomwalters@570 14
tomwalters@570 15 The above copyright notice and this permission notice shall be
tomwalters@570 16 included in all copies or substantial portions of the Software.
tomwalters@570 17
tomwalters@570 18 Any person wishing to distribute modifications to the Software is
tomwalters@570 19 requested to send the modifications to the original developer so that
tomwalters@570 20 they can be incorporated into the canonical version.
tomwalters@570 21
tomwalters@570 22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
tomwalters@570 23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
tomwalters@570 24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
tomwalters@570 25 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
tomwalters@570 26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
tomwalters@570 27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
tomwalters@570 28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
tomwalters@570 29 */
tomwalters@570 30 #include "OscSendTests.h"
tomwalters@570 31
tomwalters@570 32 #include <iostream>
tomwalters@570 33 #include <string.h>
tomwalters@570 34
tomwalters@570 35 #include "osc/OscOutboundPacketStream.h"
tomwalters@570 36
tomwalters@570 37 #include "ip/UdpSocket.h"
tomwalters@570 38 #include "ip/IpEndpointName.h"
tomwalters@570 39
tomwalters@570 40 #define IP_MTU_SIZE 1536
tomwalters@570 41
tomwalters@570 42 namespace osc{
tomwalters@570 43
tomwalters@570 44 void RunSendTests( const IpEndpointName& host )
tomwalters@570 45 {
tomwalters@570 46 char buffer[IP_MTU_SIZE];
tomwalters@570 47 osc::OutboundPacketStream p( buffer, IP_MTU_SIZE );
tomwalters@570 48 UdpTransmitSocket socket( host );
tomwalters@570 49
tomwalters@570 50 p.Clear();
tomwalters@570 51 p << osc::BeginMessage( "/test1" )
tomwalters@570 52 << true << 23 << (float)3.1415 << "hello" << osc::EndMessage;
tomwalters@570 53 socket.Send( p.Data(), p.Size() );
tomwalters@570 54
tomwalters@570 55 // test1 message with too few arguments
tomwalters@570 56 p.Clear();
tomwalters@570 57 p << osc::BeginMessage( "/test1" )
tomwalters@570 58 << true << osc::EndMessage;
tomwalters@570 59 socket.Send( p.Data(), p.Size() );
tomwalters@570 60
tomwalters@570 61 // test1 message with too many arguments
tomwalters@570 62 p.Clear();
tomwalters@570 63 p << osc::BeginMessage( "/test1" )
tomwalters@570 64 << true << 23 << (float)3.1415 << "hello" << 42 << osc::EndMessage;
tomwalters@570 65 socket.Send( p.Data(), p.Size() );
tomwalters@570 66
tomwalters@570 67 // test1 message with wrong argument type
tomwalters@570 68 p.Clear();
tomwalters@570 69 p << osc::BeginMessage( "/test1" )
tomwalters@570 70 << true << 1.0 << (float)3.1415 << "hello" << osc::EndMessage;
tomwalters@570 71 socket.Send( p.Data(), p.Size() );
tomwalters@570 72
tomwalters@570 73 p.Clear();
tomwalters@570 74 p << osc::BeginMessage( "/test2" )
tomwalters@570 75 << true << 23 << (float)3.1415 << "hello" << osc::EndMessage;
tomwalters@570 76 socket.Send( p.Data(), p.Size() );
tomwalters@570 77
tomwalters@570 78 // send four /test3 messages, each with a different type of argument
tomwalters@570 79 p.Clear();
tomwalters@570 80 p << osc::BeginMessage( "/test3" )
tomwalters@570 81 << true << osc::EndMessage;
tomwalters@570 82 socket.Send( p.Data(), p.Size() );
tomwalters@570 83
tomwalters@570 84 p.Clear();
tomwalters@570 85 p << osc::BeginMessage( "/test3" )
tomwalters@570 86 << 23 << osc::EndMessage;
tomwalters@570 87 socket.Send( p.Data(), p.Size() );
tomwalters@570 88
tomwalters@570 89 p.Clear();
tomwalters@570 90 p << osc::BeginMessage( "/test3" )
tomwalters@570 91 << (float)3.1415 << osc::EndMessage;
tomwalters@570 92 socket.Send( p.Data(), p.Size() );
tomwalters@570 93
tomwalters@570 94 p.Clear();
tomwalters@570 95 p << osc::BeginMessage( "/test3" )
tomwalters@570 96 << "hello" << osc::EndMessage;
tomwalters@570 97 socket.Send( p.Data(), p.Size() );
tomwalters@570 98
tomwalters@570 99
tomwalters@570 100 // send a bundle
tomwalters@570 101 p.Clear();
tomwalters@570 102 p << osc::BeginBundle();
tomwalters@570 103
tomwalters@570 104 p << osc::BeginMessage( "/no_arguments" )
tomwalters@570 105 << osc::EndMessage;
tomwalters@570 106
tomwalters@570 107 p << osc::BeginMessage( "/a_bool" )
tomwalters@570 108 << true << osc::EndMessage;
tomwalters@570 109
tomwalters@570 110 p << osc::BeginMessage( "/a_bool" )
tomwalters@570 111 << false << osc::EndMessage;
tomwalters@570 112
tomwalters@570 113 p << osc::BeginMessage( "/a_bool" )
tomwalters@570 114 << (bool)1234 << osc::EndMessage;
tomwalters@570 115
tomwalters@570 116 p << osc::BeginMessage( "/nil" )
tomwalters@570 117 << osc::Nil << osc::EndMessage;
tomwalters@570 118
tomwalters@570 119 p << osc::BeginMessage( "/inf" )
tomwalters@570 120 << osc::Infinitum << osc::EndMessage;
tomwalters@570 121
tomwalters@570 122 p << osc::BeginMessage( "/an_int" ) << 1234 << osc::EndMessage;
tomwalters@570 123
tomwalters@570 124 p << osc::BeginMessage( "/a_float" )
tomwalters@570 125 << 3.1415926f << osc::EndMessage;
tomwalters@570 126
tomwalters@570 127 p << osc::BeginMessage( "/a_char" )
tomwalters@570 128 << 'c' << osc::EndMessage;
tomwalters@570 129
tomwalters@570 130 p << osc::BeginMessage( "/an_rgba_color" )
tomwalters@570 131 << osc::RgbaColor(0x22334455) << osc::EndMessage;
tomwalters@570 132
tomwalters@570 133 p << osc::BeginMessage( "/a_midi_message" )
tomwalters@570 134 << MidiMessage(0x7F) << osc::EndMessage;
tomwalters@570 135
tomwalters@570 136 p << osc::BeginMessage( "/an_int64" )
tomwalters@570 137 << (int64)(0xFFFFFFF) << osc::EndMessage;
tomwalters@570 138
tomwalters@570 139 p << osc::BeginMessage( "/a_time_tag" )
tomwalters@570 140 << osc::TimeTag(0xFFFFFFFUL) << osc::EndMessage;
tomwalters@570 141
tomwalters@570 142 p << osc::BeginMessage( "/a_double" )
tomwalters@570 143 << (double)3.1415926 << osc::EndMessage;
tomwalters@570 144
tomwalters@570 145 p << osc::BeginMessage( "/a_string" )
tomwalters@570 146 << "hello world" << osc::EndMessage;
tomwalters@570 147
tomwalters@570 148 p << osc::BeginMessage( "/a_symbol" )
tomwalters@570 149 << osc::Symbol("foobar") << osc::EndMessage;
tomwalters@570 150
tomwalters@570 151 // blob
tomwalters@570 152 {
tomwalters@570 153 char blobData[] = "abcd";
tomwalters@570 154
tomwalters@570 155 p << osc::BeginMessage( "/a_blob" )
tomwalters@570 156 << osc::Blob( blobData, 4 )
tomwalters@570 157 << osc::EndMessage;
tomwalters@570 158 }
tomwalters@570 159
tomwalters@570 160 p << osc::EndBundle;
tomwalters@570 161 socket.Send( p.Data(), p.Size() );
tomwalters@570 162
tomwalters@570 163
tomwalters@570 164
tomwalters@570 165 // nested bundles, and multiple messages in bundles...
tomwalters@570 166 p.Clear();
tomwalters@570 167 p << osc::BeginBundle( 1234 )
tomwalters@570 168 << osc::BeginMessage( "/an_int" ) << 1 << osc::EndMessage
tomwalters@570 169 << osc::BeginMessage( "/an_int" ) << 2 << osc::EndMessage
tomwalters@570 170 << osc::BeginMessage( "/an_int" ) << 3 << osc::EndMessage
tomwalters@570 171 << osc::BeginMessage( "/an_int" ) << 4 << osc::EndMessage
tomwalters@570 172 << osc::BeginBundle( 12345 )
tomwalters@570 173 << osc::BeginMessage( "/an_int" ) << 5 << osc::EndMessage
tomwalters@570 174 << osc::BeginMessage( "/an_int" ) << 6 << osc::EndMessage
tomwalters@570 175 << osc::EndBundle
tomwalters@570 176 << osc::EndBundle;
tomwalters@570 177
tomwalters@570 178 socket.Send( p.Data(), p.Size() );
tomwalters@570 179 }
tomwalters@570 180
tomwalters@570 181 } // namespace osc
tomwalters@570 182
tomwalters@570 183 #ifndef NO_OSC_TEST_MAIN
tomwalters@570 184
tomwalters@570 185 int main(int argc, char* argv[])
tomwalters@570 186 {
tomwalters@570 187 if( argc >= 2 && strcmp( argv[1], "-h" ) == 0 ){
tomwalters@570 188 std::cout << "usage: OscSendTests [hostname [port]]\n";
tomwalters@570 189 return 0;
tomwalters@570 190 }
tomwalters@570 191
tomwalters@570 192 char *hostName = "localhost";
tomwalters@570 193 int port = 7000;
tomwalters@570 194
tomwalters@570 195 if( argc >= 2 )
tomwalters@570 196 hostName = argv[1];
tomwalters@570 197
tomwalters@570 198 if( argc >= 3 )
tomwalters@570 199 port = atoi( argv[2] );
tomwalters@570 200
tomwalters@570 201
tomwalters@570 202 IpEndpointName host( hostName, port );
tomwalters@570 203
tomwalters@570 204 char hostIpAddress[ IpEndpointName::ADDRESS_STRING_LENGTH ];
tomwalters@570 205 host.AddressAsString( hostIpAddress );
tomwalters@570 206
tomwalters@570 207 std::cout << "sending test messages to " << hostName
tomwalters@570 208 << " (" << hostIpAddress << ") on port " << port << "...\n";
tomwalters@570 209
tomwalters@570 210 osc::RunSendTests( host );
tomwalters@570 211 }
tomwalters@570 212
tomwalters@570 213 #endif /* NO_OSC_TEST_MAIN */