74 return OSCColour::fromInt32 ((
uint32) intValue);
77 return { 0, 0, 0, 0 };
95 MemoryBlock
block (numBytes);
97 Random
rng = getRandom();
99 for (
size_t i = 0; i < numBytes; ++i)
100 block[i] = (
char)
rng.nextInt (256);
105 void runTest()
override
114 int value = 123456789;
116 OSCArgument
arg (value);
118 expect (
arg.getType() == OSCTypes::int32);
119 expect (
arg.isInt32());
120 expect (!
arg.isFloat32());
121 expect (!
arg.isString());
122 expect (!
arg.isBlob());
123 expect (!
arg.isColour());
125 expect (
arg.getInt32() == value);
128 beginTest (
"Float32");
130 float value = 12345.6789f;
132 OSCArgument
arg (value);
134 expect (
arg.getType() == OSCTypes::float32);
135 expect (!
arg.isInt32());
136 expect (
arg.isFloat32());
137 expect (!
arg.isString());
138 expect (!
arg.isBlob());
139 expect (!
arg.isColour());
141 expectEquals (
arg.getFloat32(), value);
144 beginTest (
"String");
146 String value =
"Hello, World!";
147 OSCArgument
arg (value);
149 expect (
arg.getType() == OSCTypes::string);
150 expect (!
arg.isInt32());
151 expect (!
arg.isFloat32());
152 expect (
arg.isString());
153 expect (!
arg.isBlob());
154 expect (!
arg.isColour());
156 expect (
arg.getString() == value);
159 beginTest (
"String (from C string)");
161 OSCArgument
arg (
"Hello, World!");
163 expect (
arg.getType() == OSCTypes::string);
164 expect (!
arg.isInt32());
165 expect (!
arg.isFloat32());
166 expect (
arg.isString());
167 expect (!
arg.isBlob());
168 expect (!
arg.isColour());
170 expect (
arg.getString() ==
"Hello, World!");
176 OSCArgument
arg (blob);
178 expect (
arg.getType() == OSCTypes::blob);
179 expect (!
arg.isInt32());
180 expect (!
arg.isFloat32());
181 expect (!
arg.isString());
182 expect (
arg.isBlob());
183 expect (!
arg.isColour());
185 expect (
arg.getBlob() == blob);
188 beginTest (
"Colour");
190 Random
rng = getRandom();
192 for (
int i = 100; --i >= 0;)
201 expect (
arg.getType() == OSCTypes::colour);
202 expect (!
arg.isInt32());
203 expect (!
arg.isFloat32());
204 expect (!
arg.isString());
205 expect (!
arg.isBlob());
206 expect (
arg.isColour());
208 expect (
arg.getColour().toInt32() ==
col.toInt32());
212 beginTest (
"Copy, move and assignment");
216 OSCArgument
arg (value);
219 expect (
copy.getType() == OSCTypes::int32);
220 expect (
copy.getInt32() == value);
222 OSCArgument
assignment (
"this will be overwritten!");
224 expect (
assignment.getType() == OSCTypes::int32);
228 const size_t numBytes = 412;
230 OSCArgument
arg (blob);
233 expect (
copy.getType() == OSCTypes::blob);
234 expect (
copy.getBlob() == blob);
236 OSCArgument
assignment (
"this will be overwritten!");
238 expect (
assignment.getType() == OSCTypes::blob);
A class to hold a resizable block of raw data.
OSCColour getColour() const noexcept
Returns the value of the OSCArgument as an OSCColour.
String getString() const noexcept
Returns the value of the OSCArgument as a string.
bool isFloat32() const noexcept
Returns whether the type of the OSCArgument is float.
bool isBlob() const noexcept
Returns whether the type of the OSCArgument is blob.
bool isColour() const noexcept
Returns whether the type of the OSCArgument is colour.
int32 getInt32() const noexcept
Returns the value of the OSCArgument as an int32.
OSCArgument(int32 value)
Constructs an OSCArgument with type int32 and a given value.
float getFloat32() const noexcept
Returns the value of the OSCArgument as a float32.
const MemoryBlock & getBlob() const noexcept
Returns the binary data contained in the blob and owned by the OSCArgument, as a reference to a JUCE ...
bool isInt32() const noexcept
Returns whether the type of the OSCArgument is int32.
bool isString() const noexcept
Returns whether the type of the OSCArgument is string.
The definitions of supported OSC types and their associated OSC type tags, as defined in the OpenSoun...
This is a base class for classes that perform a unit test.
@ copy
The command ID that should be used to send a "Copy to clipboard" command.
signed int int32
A platform-independent 32-bit signed integer type.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
unsigned int uint32
A platform-independent 32-bit unsigned integer type.
unsigned char uint8
A platform-independent 8-bit unsigned integer type.
Holds a 32-bit RGBA colour for passing to and from an OSCArgument.