2 oscpack -- Open Sound Control packet manipulation library
3 http://www.audiomulch.com/~rossb/oscpack
5 Copyright (c) 2004-2005 Ross Bencina <rossb@audiomulch.com>
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files
9 (the "Software"), to deal in the Software without restriction,
10 including without limitation the rights to use, copy, modify, merge,
11 publish, distribute, sublicense, and/or sell copies of the Software,
12 and to permit persons to whom the Software is furnished to do so,
13 subject to the following conditions:
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
18 Any person wishing to distribute modifications to the Software is
19 requested to send the modifications to the original developer so that
20 they can be incorporated into the canonical version.
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
27 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 #include "OscSendTests.h"
36 #include "osc/OscOutboundPacketStream.h"
38 #include "ip/UdpSocket.h"
39 #include "ip/IpEndpointName.h"
41 #define IP_MTU_SIZE 1536
45 void RunSendTests( const IpEndpointName
& host
)
47 char buffer
[IP_MTU_SIZE
];
48 osc::OutboundPacketStream
p( buffer
, IP_MTU_SIZE
);
49 UdpTransmitSocket
socket( host
);
52 p
<< osc::BeginMessage( "/test1" )
53 << true << 23 << (float)3.1415 << "hello" << osc::EndMessage
;
54 socket
.Send( p
.Data(), p
.Size() );
56 // test1 message with too few arguments
58 p
<< osc::BeginMessage( "/test1" )
59 << true << osc::EndMessage
;
60 socket
.Send( p
.Data(), p
.Size() );
62 // test1 message with too many arguments
64 p
<< osc::BeginMessage( "/test1" )
65 << true << 23 << (float)3.1415 << "hello" << 42 << osc::EndMessage
;
66 socket
.Send( p
.Data(), p
.Size() );
68 // test1 message with wrong argument type
70 p
<< osc::BeginMessage( "/test1" )
71 << true << 1.0 << (float)3.1415 << "hello" << osc::EndMessage
;
72 socket
.Send( p
.Data(), p
.Size() );
75 p
<< osc::BeginMessage( "/test2" )
76 << true << 23 << (float)3.1415 << "hello" << osc::EndMessage
;
77 socket
.Send( p
.Data(), p
.Size() );
79 // send four /test3 messages, each with a different type of argument
81 p
<< osc::BeginMessage( "/test3" )
82 << true << osc::EndMessage
;
83 socket
.Send( p
.Data(), p
.Size() );
86 p
<< osc::BeginMessage( "/test3" )
87 << 23 << osc::EndMessage
;
88 socket
.Send( p
.Data(), p
.Size() );
91 p
<< osc::BeginMessage( "/test3" )
92 << (float)3.1415 << osc::EndMessage
;
93 socket
.Send( p
.Data(), p
.Size() );
96 p
<< osc::BeginMessage( "/test3" )
97 << "hello" << osc::EndMessage
;
98 socket
.Send( p
.Data(), p
.Size() );
103 p
<< osc::BeginBundle();
105 p
<< osc::BeginMessage( "/no_arguments" )
108 p
<< osc::BeginMessage( "/a_bool" )
109 << true << osc::EndMessage
;
111 p
<< osc::BeginMessage( "/a_bool" )
112 << false << osc::EndMessage
;
114 p
<< osc::BeginMessage( "/a_bool" )
115 << (bool)1234 << osc::EndMessage
;
117 p
<< osc::BeginMessage( "/nil" )
118 << osc::Nil
<< osc::EndMessage
;
120 p
<< osc::BeginMessage( "/inf" )
121 << osc::Infinitum
<< osc::EndMessage
;
123 p
<< osc::BeginMessage( "/an_int" ) << 1234 << osc::EndMessage
;
125 p
<< osc::BeginMessage( "/a_float" )
126 << 3.1415926f
<< osc::EndMessage
;
128 p
<< osc::BeginMessage( "/a_char" )
129 << 'c' << osc::EndMessage
;
131 p
<< osc::BeginMessage( "/an_rgba_color" )
132 << osc::RgbaColor(0x22334455) << osc::EndMessage
;
134 p
<< osc::BeginMessage( "/a_midi_message" )
135 << MidiMessage(0x7F) << osc::EndMessage
;
137 p
<< osc::BeginMessage( "/an_int64" )
138 << (int64
)(0xFFFFFFF) << osc::EndMessage
;
140 p
<< osc::BeginMessage( "/a_time_tag" )
141 << osc::TimeTag(0xFFFFFFFUL
) << osc::EndMessage
;
143 p
<< osc::BeginMessage( "/a_double" )
144 << (double)3.1415926 << osc::EndMessage
;
146 p
<< osc::BeginMessage( "/a_string" )
147 << "hello world" << osc::EndMessage
;
149 p
<< osc::BeginMessage( "/a_symbol" )
150 << osc::Symbol("foobar") << osc::EndMessage
;
154 char blobData
[] = "abcd";
156 p
<< osc::BeginMessage( "/a_blob" )
157 << osc::Blob( blobData
, 4 )
162 socket
.Send( p
.Data(), p
.Size() );
166 // nested bundles, and multiple messages in bundles...
168 p
<< osc::BeginBundle( 1234 )
169 << osc::BeginMessage( "/an_int" ) << 1 << osc::EndMessage
170 << osc::BeginMessage( "/an_int" ) << 2 << osc::EndMessage
171 << osc::BeginMessage( "/an_int" ) << 3 << osc::EndMessage
172 << osc::BeginMessage( "/an_int" ) << 4 << osc::EndMessage
173 << osc::BeginBundle( 12345 )
174 << osc::BeginMessage( "/an_int" ) << 5 << osc::EndMessage
175 << osc::BeginMessage( "/an_int" ) << 6 << osc::EndMessage
179 socket
.Send( p
.Data(), p
.Size() );
184 #ifndef NO_OSC_TEST_MAIN
186 int main(int argc
, char* argv
[])
188 if( argc
>= 2 && strcmp( argv
[1], "-h" ) == 0 ){
189 std::cout
<< "usage: OscSendTests [hostname [port]]\n";
193 const char *hostName
= "localhost";
200 port
= atoi( argv
[2] );
203 IpEndpointName
host( hostName
, port
);
205 char hostIpAddress
[ IpEndpointName::ADDRESS_STRING_LENGTH
];
206 host
.AddressAsString( hostIpAddress
);
208 std::cout
<< "sending test messages to " << hostName
209 << " (" << hostIpAddress
<< ") on port " << port
<< "...\n";
211 osc::RunSendTests( host
);
214 #endif /* NO_OSC_TEST_MAIN */