void test3() { int bufferSize = 1000; char *buffer = AllocateAligned4( bufferSize ); // single message tests // empty message { std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/no_arguments" ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n";\ } TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool ); #ifndef _OBJC_OBJC_H_ TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil ); #endif TEST_PACK_UNPACK0( "/nil", OscNil, true, IsNil ); TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum ); TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 ); TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat ); TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar ); TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor ); TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage ); TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 ); TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag ); TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble ); // blob { char blobData[] = "abcd"; std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/a_blob" ) << Blob( blobData, 4 ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; const void *value; osc_bundle_element_size_t size; m.ArgumentsBegin()->AsBlob( value, size ); assertEqual( size, (osc_bundle_element_size_t)4 ); assertEqual( (memcmp( value, blobData, 4 ) == 0), true ); } // array { int32 arrayData[] = {1,2,3,4}; const std::size_t sourceArrayItemCount = 4; std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/an_array" ) << BeginArray; for( std::size_t j=0; j < sourceArrayItemCount; ++j ) ps << arrayData[j]; ps << EndArray << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; ReceivedMessageArgumentIterator i = m.ArgumentsBegin(); assertEqual( i->IsArrayBegin(), true ); assertEqual( i->ComputeArrayItemCount(), sourceArrayItemCount ); std::size_t arrayItemCount = i->ComputeArrayItemCount(); ++i; // move past array begin marker for( std::size_t j=0; j < arrayItemCount; ++j ){ assertEqual( true, i->IsInt32() ); int32 k = i->AsInt32(); assertEqual( k, arrayData[j] ); ++i; } assertEqual( i->IsArrayEnd(), true ); } TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString ); TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol ); // nested bundles, and multiple messages in bundles... { std::memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginBundle() << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage << EndBundle; assertEqual( ps.IsReady(), true ); ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << b << "\n"; } }
void test3() { int bufferSize = 1000; char *buffer = AllocateAligned4( bufferSize ); // single message tests // empty message { memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/no_arguments" ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n";\ } TEST_PACK_UNPACK( "/a_bool", true, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", false, bool, AsBool ); TEST_PACK_UNPACK( "/a_bool", (bool)1, bool, AsBool ); TEST_PACK_UNPACK0( "/nil", Nil, true, IsNil ); TEST_PACK_UNPACK0( "/inf", Infinitum, true, IsInfinitum ); TEST_PACK_UNPACK( "/an_int", (int32)1234, int32, AsInt32 ); TEST_PACK_UNPACK( "/a_float", 3.1415926f, float, AsFloat ); TEST_PACK_UNPACK( "/a_char", 'c', char, AsChar ); TEST_PACK_UNPACK( "/an_rgba_color", RgbaColor(0x22334455), uint32, AsRgbaColor ); TEST_PACK_UNPACK( "/a_midi_message", MidiMessage(0x7F), uint32, AsMidiMessage ); TEST_PACK_UNPACK( "/an_int64", (int64)(0xFFFFFFFF), int64, AsInt64 ); TEST_PACK_UNPACK( "/a_time_tag", TimeTag(0xFFFFFFFF), uint64, AsTimeTag ); TEST_PACK_UNPACK( "/a_double", (double)3.1415926, double, AsDouble ); // blob { char blobData[] = "abcd"; memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginMessage( "/a_blob" ) << Blob( blobData, 4 ) << EndMessage; assertEqual( ps.IsReady(), true ); ReceivedMessage m( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << m << "\n"; const void *value; unsigned long size; m.ArgumentsBegin()->AsBlob( value, size ); assertEqual( size, (unsigned long)4 ); assertEqual( (memcmp( value, blobData, 4 ) == 0), true ); } TEST_PACK_UNPACK( "/a_string", "hello world", const char*, AsString ); TEST_PACK_UNPACK( "/a_symbol", Symbol("foobar"), const char*, AsSymbol ); // nested bundles, and multiple messages in bundles... { memset( buffer, 0x74, bufferSize ); OutboundPacketStream ps( buffer, bufferSize ); ps << BeginBundle() << BeginMessage( "/message_one" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_two" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_three" ) << 1 << 2 << 3 << 4 << EndMessage << BeginMessage( "/message_four" ) << 1 << 2 << 3 << 4 << EndMessage << EndBundle; assertEqual( ps.IsReady(), true ); ReceivedBundle b( ReceivedPacket(ps.Data(), ps.Size()) ); std::cout << b << "\n"; } }