Skip to content
This repository was archived by the owner on Jan 14, 2023. It is now read-only.

Commit b9a9858

Browse files
authored
Merge pull request #67 from ernestmc/test_fixed_size_arrays
Test fixed size arrays
2 parents 62f865d + fe6c536 commit b9a9858

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

message_generation/src/test/java/org/ros/internal/message/RawMessageSerializationTest.java

+124
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static org.junit.Assert.assertTrue;
2020

2121
import com.google.common.collect.Lists;
22+
import java.util.Arrays;
2223

2324
import org.jboss.netty.buffer.ChannelBuffer;
2425
import org.junit.Before;
@@ -266,4 +267,127 @@ public void testFloat64Array() {
266267
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3, 4, 5 });
267268
checkSerializeAndDeserialize(rawMessage);
268269
}
270+
271+
@Test
272+
public void testChannelBufferFixedSizeWithInitialization() {
273+
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
274+
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
275+
buffer.writeBytes(new byte[] { 1, 2, 3, 4, 5 });
276+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
277+
rawMessage.setChannelBuffer("data", buffer);
278+
checkSerializeAndDeserialize(rawMessage);
279+
}
280+
281+
@Test
282+
public void testChannelBufferFixedSizeWithIncompleteInitialization() {
283+
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
284+
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
285+
buffer.writeBytes(new byte[] { 1, 2, 3 });
286+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
287+
rawMessage.setChannelBuffer("data", buffer);
288+
checkSerializeAndDeserialize(rawMessage);
289+
}
290+
291+
@Test
292+
public void testChannelBufferFixedSizeNoInitialization() {
293+
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
294+
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
295+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
296+
rawMessage.setChannelBuffer("data", buffer);
297+
checkSerializeAndDeserialize(rawMessage);
298+
}
299+
300+
@Test
301+
public void testInt32FixedSizeArrayWithInitialization() {
302+
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
303+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
304+
rawMessage.setInt32Array("data", new int[] { 1, 2, 3, 4, 5 });
305+
checkSerializeAndDeserialize(rawMessage);
306+
}
307+
308+
@Test
309+
public void testInt32FixedSizeArrayWithIncompleteInitialization() {
310+
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
311+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
312+
rawMessage.setInt32Array("data", new int[] { 1, 2, 3 });
313+
checkSerializeAndDeserialize(rawMessage);
314+
}
315+
316+
@Test
317+
public void testInt32FixedSizeArrayNoInitialization() {
318+
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
319+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
320+
checkSerializeAndDeserialize(rawMessage);
321+
}
322+
323+
@Test
324+
public void testFloat64FixedSizeArrayWithInitialization() {
325+
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
326+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
327+
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3, 4, 5 });
328+
checkSerializeAndDeserialize(rawMessage);
329+
}
330+
331+
@Test
332+
public void testFloat64FixedSizeArrayWithIncompleteInitialization() {
333+
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
334+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
335+
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3 });
336+
checkSerializeAndDeserialize(rawMessage);
337+
}
338+
339+
@Test
340+
public void testFloat64FixedSizeArrayNoInitialization() {
341+
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
342+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
343+
checkSerializeAndDeserialize(rawMessage);
344+
}
345+
346+
@Test
347+
public void testStringFixedSizeArrayWithInitialization() {
348+
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
349+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
350+
String[] stringArray = new String[] { "String 1", "String 2", "String 3", "String 4", "String 5" };
351+
rawMessage.setStringList("data", Arrays.asList(stringArray));
352+
checkSerializeAndDeserialize(rawMessage);
353+
}
354+
355+
@Test
356+
public void testStringFixedSizeArrayWithIncompleteInitialization() {
357+
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
358+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
359+
String[] stringArray = new String[] { "String 1", "String 2", "String 3" };
360+
rawMessage.setStringList("data", Arrays.asList(stringArray));
361+
checkSerializeAndDeserialize(rawMessage);
362+
}
363+
364+
@Test
365+
public void testStringFixedSizeArrayWithNoInitialization() {
366+
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
367+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
368+
checkSerializeAndDeserialize(rawMessage);
369+
}
370+
371+
@Test
372+
public void testByteFixedSizeArrayWithInitialization() {
373+
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
374+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
375+
rawMessage.setInt8Array("data", new byte[] { 1, 2, 3, 4, 5 });
376+
checkSerializeAndDeserialize(rawMessage);
377+
}
378+
379+
@Test
380+
public void testByteFixedSizeArrayWithIncompleteInitialization() {
381+
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
382+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
383+
rawMessage.setInt8Array("data", new byte[] { 1, 2, 3 });
384+
checkSerializeAndDeserialize(rawMessage);
385+
}
386+
387+
@Test
388+
public void testByteFixedSizeArrayWithNoInitialization() {
389+
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
390+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
391+
checkSerializeAndDeserialize(rawMessage);
392+
}
269393
}

0 commit comments

Comments
 (0)