void runTestInitialisation() { beginTest ("Int32"); { int value = 123456789; OSCArgument arg (value); expect (arg.getType() == OSCTypes::int32); expect (arg.isInt32()); expect (! arg.isFloat32()); expect (! arg.isString()); expect (! arg.isBlob()); expect (arg.getInt32() == value); } beginTest ("Float32"); { float value = 12345.6789f; OSCArgument arg (value); expect (arg.getType() == OSCTypes::float32); expect (! arg.isInt32()); expect (arg.isFloat32()); expect (! arg.isString()); expect (! arg.isBlob()); expect (arg.getFloat32() == value); } beginTest ("String"); { String value = "Hello, World!"; OSCArgument arg (value); expect (arg.getType() == OSCTypes::string); expect (! arg.isInt32()); expect (! arg.isFloat32()); expect (arg.isString()); expect (! arg.isBlob()); expect (arg.getString() == value); } beginTest ("String (from C string)"); { OSCArgument arg ("Hello, World!"); expect (arg.getType() == OSCTypes::string); expect (! arg.isInt32()); expect (! arg.isFloat32()); expect (arg.isString()); expect (! arg.isBlob()); expect (arg.getString() == String ("Hello, World!")); } beginTest ("Blob"); { const size_t numBytes = 412; MemoryBlock blob = getMemoryBlockWithRandomData (numBytes); OSCArgument arg (blob); expect (arg.getType() == OSCTypes::blob); expect (! arg.isInt32()); expect (! arg.isFloat32()); expect (! arg.isString()); expect (arg.isBlob()); expect (arg.getBlob() == blob); } beginTest ("Copy, move and assignment"); { { int value = -42; OSCArgument arg (value); OSCArgument copy = arg; expect (copy.getType() == OSCTypes::int32); expect (copy.getInt32() == value); OSCArgument assignment ("this will be overwritten!"); assignment = copy; expect (assignment.getType() == OSCTypes::int32); expect (assignment.getInt32() == value); } { const size_t numBytes = 412; MemoryBlock blob = getMemoryBlockWithRandomData (numBytes); OSCArgument arg (blob); OSCArgument copy = arg; expect (copy.getType() == OSCTypes::blob); expect (copy.getBlob() == blob); OSCArgument assignment ("this will be overwritten!"); assignment = copy; expect (assignment.getType() == OSCTypes::blob); expect (assignment.getBlob() == blob); } } }
void runTest() { beginTest ("Basic usage"); { OSCMessage msg ("/test/param0"); expectEquals (msg.size(), 0); expect (msg.getAddressPattern().toString() == "/test/param0"); const int numTestArgs = 4; const int testInt = 42; const float testFloat = 3.14159f; const String testString = "Hello, World!"; const uint8 testBlobData[5] = { 0xBB, 0xCC, 0xDD, 0xEE, 0xFF }; const MemoryBlock testBlob (testBlobData, sizeof (testBlobData)); msg.addInt32 (testInt); msg.addFloat32 (testFloat); msg.addString (testString); msg.addBlob (testBlob); expectEquals (msg.size(), numTestArgs); expectEquals (msg[0].getType(), OSCTypes::int32); expectEquals (msg[1].getType(), OSCTypes::float32); expectEquals (msg[2].getType(), OSCTypes::string); expectEquals (msg[3].getType(), OSCTypes::blob); expect (msg[0].isInt32()); expect (msg[1].isFloat32()); expect (msg[2].isString()); expect (msg[3].isBlob()); expectEquals (msg[0].getInt32(), testInt); expectEquals (msg[1].getFloat32(), testFloat); expectEquals (msg[2].getString(), testString); expect (msg[3].getBlob() == testBlob); expect (msg.begin() + numTestArgs == msg.end()); OSCArgument* arg = msg.begin(); expect (arg->isInt32()); expectEquals (arg->getInt32(), testInt); ++arg; expect (arg->isFloat32()); expectEquals (arg->getFloat32(), testFloat); ++arg; expect (arg->isString()); expectEquals (arg->getString(), testString); ++arg; expect (arg->isBlob()); expect(arg->getBlob() == testBlob); ++arg; expect (arg == msg.end()); } beginTest ("Initialisation with argument list (C++11 only)"); { int testInt = 42; float testFloat = 5.5; String testString = "Hello, World!"; { OSCMessage msg ("/test", testInt); expect (msg.getAddressPattern().toString() == String ("/test")); expectEquals (msg.size(), 1); expect (msg[0].isInt32()); expectEquals (msg[0].getInt32(), testInt); } { OSCMessage msg ("/test", testFloat); expect (msg.getAddressPattern().toString() == String ("/test")); expectEquals (msg.size(), 1); expect (msg[0].isFloat32()); expectEquals (msg[0].getFloat32(), testFloat); } { OSCMessage msg ("/test", testString); expect (msg.getAddressPattern().toString() == String ("/test")); expectEquals (msg.size(), 1); expect (msg[0].isString()); expectEquals (msg[0].getString(), testString); } { OSCMessage msg ("/test", testInt, testFloat, testString, testFloat, testInt); expect (msg.getAddressPattern().toString() == String ("/test")); expectEquals (msg.size(), 5); expect (msg[0].isInt32()); expect (msg[1].isFloat32()); expect (msg[2].isString()); expect (msg[3].isFloat32()); expect (msg[4].isInt32()); expectEquals (msg[0].getInt32(), testInt); expectEquals (msg[1].getFloat32(), testFloat); expectEquals (msg[2].getString(), testString); expectEquals (msg[3].getFloat32(), testFloat); expectEquals (msg[4].getInt32(), testInt); } } }