41 return addressPattern;
47 return arguments.size();
52 return arguments.isEmpty();
57 return arguments.getReference (i);
62 return arguments.getReference (i);
67 return arguments.begin();
72 return arguments.begin();
77 return arguments.end();
82 return arguments.end();
103class OSCMessageTests final :
public UnitTest
107 :
UnitTest (
"OSCMessage class", UnitTestCategories::osc)
110 void runTest()
override
112 beginTest (
"Basic usage");
114 OSCMessage msg (
"/test/param0");
115 expectEquals (msg.size(), 0);
116 expect (msg.getAddressPattern().toString() ==
"/test/param0");
118 const int numTestArgs = 5;
120 const int testInt = 42;
121 const float testFloat = 3.14159f;
122 const String testString =
"Hello, World!";
123 const OSCColour testColour = { 10, 20, 150, 200 };
125 const uint8 testBlobData[5] = { 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
126 const MemoryBlock testBlob (testBlobData,
sizeof (testBlobData));
128 msg.addInt32 (testInt);
129 msg.addFloat32 (testFloat);
130 msg.addString (testString);
131 msg.addBlob (testBlob);
132 msg.addColour (testColour);
134 expectEquals (msg.size(), numTestArgs);
136 expectEquals (msg[0].getType(), OSCTypes::int32);
137 expectEquals (msg[1].getType(), OSCTypes::float32);
138 expectEquals (msg[2].getType(), OSCTypes::string);
139 expectEquals (msg[3].getType(), OSCTypes::blob);
140 expectEquals (msg[4].getType(), OSCTypes::colour);
142 expect (msg[0].isInt32());
143 expect (msg[1].isFloat32());
144 expect (msg[2].isString());
145 expect (msg[3].isBlob());
146 expect (msg[4].isColour());
148 expectEquals (msg[0].getInt32(), testInt);
149 expectEquals (msg[1].getFloat32(), testFloat);
150 expectEquals (msg[2].getString(), testString);
151 expect (msg[3].getBlob() == testBlob);
152 expect (msg[4].getColour().toInt32() == testColour.toInt32());
154 expect (msg.begin() + numTestArgs == msg.end());
156 auto arg = msg.begin();
157 expect (arg->isInt32());
158 expectEquals (arg->getInt32(), testInt);
160 expect (arg->isFloat32());
161 expectEquals (arg->getFloat32(), testFloat);
163 expect (arg->isString());
164 expectEquals (arg->getString(), testString);
166 expect (arg->isBlob());
167 expect (arg->getBlob() == testBlob);
169 expect (arg->isColour());
170 expect (arg->getColour().toInt32() == testColour.toInt32());
172 expect (arg == msg.end());
176 beginTest (
"Initialisation with argument list (C++11 only)");
179 float testFloat = 5.5;
180 String testString =
"Hello, World!";
183 OSCMessage msg (
"/test", testInt);
184 expect (msg.getAddressPattern().toString() == String (
"/test"));
185 expectEquals (msg.size(), 1);
186 expect (msg[0].isInt32());
187 expectEquals (msg[0].getInt32(), testInt);
190 OSCMessage msg (
"/test", testFloat);
191 expect (msg.getAddressPattern().toString() == String (
"/test"));
192 expectEquals (msg.size(), 1);
193 expect (msg[0].isFloat32());
194 expectEquals (msg[0].getFloat32(), testFloat);
197 OSCMessage msg (
"/test", testString);
198 expect (msg.getAddressPattern().toString() == String (
"/test"));
199 expectEquals (msg.size(), 1);
200 expect (msg[0].isString());
201 expectEquals (msg[0].getString(), testString);
204 OSCMessage msg (
"/test", testInt, testFloat, testString, testFloat, testInt);
205 expect (msg.getAddressPattern().toString() == String (
"/test"));
206 expectEquals (msg.size(), 5);
207 expect (msg[0].isInt32());
208 expect (msg[1].isFloat32());
209 expect (msg[2].isString());
210 expect (msg[3].isFloat32());
211 expect (msg[4].isInt32());
213 expectEquals (msg[0].getInt32(), testInt);
214 expectEquals (msg[1].getFloat32(), testFloat);
215 expectEquals (msg[2].getString(), testString);
216 expectEquals (msg[3].getFloat32(), testFloat);
217 expectEquals (msg[4].getInt32(), testInt);
223static OSCMessageTests OSCMessageUnitTests;
A class to hold a resizable block of raw data.
void addInt32(int32 value)
Creates a new OSCArgument of type int32 with the given value, and adds it to the OSCMessage object.
OSCArgument & operator[](int i) noexcept
Returns a reference to the OSCArgument at index i in the OSCMessage object.
void addString(const String &value)
Creates a new OSCArgument of type string with the given value, and adds it to the OSCMessage object.
void addFloat32(float value)
Creates a new OSCArgument of type float32 with the given value, and adds it to the OSCMessage object.
void setAddressPattern(const OSCAddressPattern &ap) noexcept
Sets the address pattern of the OSCMessage.
OSCMessage(const OSCAddressPattern &ap) noexcept
Constructs an OSCMessage object with the given address pattern and no arguments.
OSCAddressPattern getAddressPattern() const noexcept
Returns the address pattern of the OSCMessage.
OSCArgument * end() noexcept
Returns a pointer to the last OSCArgument in the OSCMessage object.
void clear()
Removes all arguments from the OSCMessage.
bool isEmpty() const noexcept
Returns true if the OSCMessage contains no OSCArgument objects; false otherwise.
void addBlob(MemoryBlock blob)
Creates a new OSCArgument of type blob with binary data content copied from the given MemoryBlock.
OSCArgument * begin() noexcept
Returns a pointer to the first OSCArgument in the OSCMessage object.
void addArgument(OSCArgument argument)
Adds the OSCArgument argument to the OSCMessage object.
int size() const noexcept
Returns the number of OSCArgument objects that belong to this OSCMessage.
void addColour(OSCColour colour)
Creates a new OSCArgument of type colour with the given value, and adds it to the OSCMessage object.
This is a base class for classes that perform a unit test.
signed int int32
A platform-independent 32-bit signed integer type.
Holds a 32-bit RGBA colour for passing to and from an OSCArgument.