annotate oscpack/tests/OscSendTests.cpp @ 101:52e44ee1c791 tip master

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