Skip to content
Snippets Groups Projects
Commit 3b086190 authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

cleaned bazel, removed depricated tests

parent e971dff6
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 1162 deletions
/*
* Copyright (C) 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ros.internal.message;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.ros.internal.message.topic.TopicDefinitionResourceProvider;
import org.ros.message.MessageDeclaration;
import org.ros.message.MessageFactory;
/**
* @author damonkohler@google.com (Damon Kohler)
*/
public class MessageInterfaceBuilderTest {
private TopicDefinitionResourceProvider topicDefinitionResourceProvider;
private MessageFactory messageFactory;
@Before
public void before() {
topicDefinitionResourceProvider = new TopicDefinitionResourceProvider();
messageFactory = new DefaultMessageFactory(topicDefinitionResourceProvider);
}
@Test
public void testDuplicateFieldNames() {
MessageInterfaceBuilder builder = new MessageInterfaceBuilder();
builder.setPackageName("foo");
builder.setInterfaceName("bar");
builder.setMessageDeclaration(MessageDeclaration.of("foo/bar", "int32 foo\nint32 Foo"));
builder.setAddConstantsAndMethods(true);
String result = builder.build(messageFactory);
assertEquals("package foo;\n\n"
+ "public interface bar extends org.ros.internal.message.Message {\n"
+ " static final java.lang.String _TYPE = \"foo/bar\";\n"
+ " static final java.lang.String _DEFINITION = \"int32 foo\\nint32 Foo\";\n"
+ " int getFoo();\n" + " void setFoo(int value);\n" + "}\n", result);
}
}
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ros.internal.message;
import static org.junit.Assert.assertEquals;
import com.google.common.collect.Lists;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.buffer.ChannelBuffers;
import org.junit.Before;
import org.junit.Test;
import org.ros.internal.message.topic.TopicDefinitionResourceProvider;
import org.ros.message.MessageFactory;
import java.nio.ByteOrder;
/**
* @author damonkohler@google.com (Damon Kohler)
*/
public class MessageTest {
private TopicDefinitionResourceProvider topicDefinitionResourceProvider;
private MessageFactory messageFactory;
@Before
public void before() {
topicDefinitionResourceProvider = new TopicDefinitionResourceProvider();
messageFactory = new DefaultMessageFactory(topicDefinitionResourceProvider);
}
@Test
public void testCreateEmptyMessage() {
topicDefinitionResourceProvider.add("foo/foo", "");
messageFactory.newFromType("foo/foo");
}
@Test
public void testCreateEmptyMessageWithBlankLines() {
topicDefinitionResourceProvider.add("foo/foo", "\n\n\n\n\n");
messageFactory.newFromType("foo/foo");
}
@Test
public void testString() {
String data = "Hello, ROS!";
RawMessage rawMessage = messageFactory.newFromType("std_msgs/String");
rawMessage.setString("data", data);
assertEquals(data, rawMessage.getString("data"));
}
@Test
public void testStringWithComments() {
topicDefinitionResourceProvider.add("foo/foo", "# foo\nstring data\n # string other data");
String data = "Hello, ROS!";
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setString("data", data);
assertEquals(data, rawMessage.getString("data"));
}
@Test
public void testInt8() {
byte data = 42;
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Int8");
rawMessage.setInt8("data", data);
assertEquals(data, rawMessage.getInt8("data"));
}
@Test
public void testNestedMessage() {
topicDefinitionResourceProvider.add("foo/foo", "bar data");
topicDefinitionResourceProvider.add("foo/bar", "int8 data");
RawMessage fooMessage = messageFactory.newFromType("foo/foo");
RawMessage barMessage = messageFactory.newFromType("foo/bar");
fooMessage.setMessage("data", barMessage);
byte data = 42;
barMessage.setInt8("data", data);
assertEquals(data, fooMessage.getMessage("data").toRawMessage().getInt8("data"));
}
@Test
public void testNestedMessageList() {
topicDefinitionResourceProvider.add("foo/foo", "bar[] data");
topicDefinitionResourceProvider.add("foo/bar", "int8 data");
RawMessage fooMessage = messageFactory.newFromType("foo/foo");
RawMessage barMessage = messageFactory.newFromType("foo/bar");
fooMessage.setMessageList("data", Lists.<Message>newArrayList(barMessage));
byte data = 42;
barMessage.toRawMessage().setInt8("data", data);
assertEquals(data, fooMessage.getMessageList("data").get(0).toRawMessage().getInt8("data"));
}
@Test
public void testConstantInt8() {
topicDefinitionResourceProvider.add("foo/foo", "int8 data=42");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
assertEquals(42, rawMessage.getInt8("data"));
}
@Test
public void testConstantString() {
topicDefinitionResourceProvider.add("foo/foo", "string data=Hello, ROS! # comment ");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
assertEquals("Hello, ROS! # comment", rawMessage.getString("data"));
}
@Test
public void testInt8List() {
topicDefinitionResourceProvider.add("foo/foo", "int8[] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
byte[] rawData = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
ChannelBuffer data = ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, rawData);
rawMessage.setInt8Array("data", rawData);
assertEquals(data, rawMessage.getInt8Array("data"));
}
}
\ No newline at end of file
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ros.internal.message;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.Lists;
import java.util.Arrays;
import org.jboss.netty.buffer.ChannelBuffer;
import org.junit.Before;
import org.junit.Test;
import org.ros.internal.message.topic.TopicDefinitionResourceProvider;
import org.ros.message.Duration;
import org.ros.message.MessageFactory;
import org.ros.message.Time;
/**
* @author damonkohler@google.com (Damon Kohler)
* @author mick.gaillard@gmail.com (Mickael Gaillard)
*/
public class RawMessageSerializationTest {
private TopicDefinitionResourceProvider topicDefinitionResourceProvider;
private MessageFactory messageFactory;
@Before
public void before() {
topicDefinitionResourceProvider = new TopicDefinitionResourceProvider();
messageFactory = new DefaultMessageFactory(topicDefinitionResourceProvider);
}
private void checkSerializeAndDeserialize(Message message) {
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
DefaultMessageSerializer serializer = new DefaultMessageSerializer();
serializer.serialize(message, buffer);
DefaultMessageDeserializer<RawMessage> deserializer =
new DefaultMessageDeserializer<RawMessage>(message.toRawMessage().getIdentifier(),
messageFactory);
RawMessage deserializedMessage = deserializer.deserialize(buffer);
assertTrue(message.equals(deserializedMessage));
}
@Test
public void testBool() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Bool");
rawMessage.setBool("data", true);
checkSerializeAndDeserialize(rawMessage);
rawMessage.setBool("data", false);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt8() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Int8");
rawMessage.setInt8("data", (byte) 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testUint8() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/UInt8");
rawMessage.setUInt8("data", (byte) 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt16() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Int16");
rawMessage.setInt16("data", (short) 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testUInt16() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/UInt16");
rawMessage.setUInt16("data", (short) 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt32() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Int32");
rawMessage.setInt32("data", 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testUInt32() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/UInt32");
rawMessage.setUInt32("data", 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt64() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Int64");
rawMessage.setInt64("data", 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testUInt64() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/UInt64");
rawMessage.setUInt64("data", 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testFloat32() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Float32");
rawMessage.setFloat32("data", 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testFloat64() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Float64");
rawMessage.setFloat64("data", 42);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testString() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/String");
rawMessage.setString("data", "Hello, ROS!");
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testStringUTF8() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/String");
rawMessage.setString("data", "éêè €àáßëœ 文字化け");
checkSerializeAndDeserialize(rawMessage);
// i18n test case
// base on http://www.inter-locale.com/whitepaper/learn/learn-to-test.html
// Combining Marks and Accents test
rawMessage.setString("data", "àéîōũ");
checkSerializeAndDeserialize(rawMessage);
// DOS 860 test
rawMessage.setString("data", "você nós mãe avô irmã criança");
checkSerializeAndDeserialize(rawMessage);
// Windows-1252 test
rawMessage.setString("data", "€ŒœŠš™©‰ƒ");
checkSerializeAndDeserialize(rawMessage);
// Turkish test
rawMessage.setString("data", "ışık bir İyi Günler");
checkSerializeAndDeserialize(rawMessage);
// Dakuten and handakuten marks test
rawMessage.setString("data", "がざばだぱか゛さ゛た゛は");
checkSerializeAndDeserialize(rawMessage);
// Combining Grapheme Joiner character
rawMessage.setString("data", "אִ͏ַ");
checkSerializeAndDeserialize(rawMessage);
// Bidi with Latin test
rawMessage.setString("data", "abcאבגדabc ");
checkSerializeAndDeserialize(rawMessage);
rawMessage.setString("data", "אבגדabcאבגד");
checkSerializeAndDeserialize(rawMessage);
rawMessage.setString("data", "אבגד012אבגד");
checkSerializeAndDeserialize(rawMessage);
rawMessage.setString("data", "אבגד 012 012");
checkSerializeAndDeserialize(rawMessage);
// Complex Scripts test
rawMessage.setString("data", "สวัสดี");
checkSerializeAndDeserialize(rawMessage);
rawMessage.setString("data", "டாஹ்கோ");
checkSerializeAndDeserialize(rawMessage);
rawMessage.setString("data", "بِسْمِ اللّهِ الرَّحْمـَنِ الرَّحِيمِ");
checkSerializeAndDeserialize(rawMessage);
// Numeric Shaping test
rawMessage.setString("data", "عدد مارس ١٩٩٨");
checkSerializeAndDeserialize(rawMessage);
// Common Scripts and Encodings test
rawMessage.setString("data", "Слава Жанна Ювеналий Ярополк");
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testTime() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Time");
rawMessage.setTime("data", new Time());
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testDuration() {
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Duration");
rawMessage.setDuration("data", new Duration());
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testNestedMessage() {
topicDefinitionResourceProvider.add("foo/foo", "std_msgs/String data");
RawMessage fooMessage = messageFactory.newFromType("foo/foo");
RawMessage stringMessage = messageFactory.newFromType("std_msgs/String");
stringMessage.setString("data", "Hello, ROS!");
fooMessage.setMessage("data", stringMessage);
checkSerializeAndDeserialize(fooMessage);
}
@Test
public void testNestedMessageArray() {
topicDefinitionResourceProvider.add("foo/foo", "std_msgs/String[] data");
RawMessage fooMessage = messageFactory.newFromType("foo/foo");
RawMessage stringMessageA = messageFactory.newFromType("std_msgs/String");
stringMessageA.setString("data", "Hello, ROS!");
RawMessage stringMessageB = messageFactory.newFromType("std_msgs/String");
stringMessageB.setString("data", "Goodbye, ROS!");
fooMessage.setMessageList("data", Lists.<Message>newArrayList(stringMessageA, stringMessageB));
checkSerializeAndDeserialize(fooMessage);
}
@Test
public void testChannelBuffer() {
topicDefinitionResourceProvider.add("foo/foo", "uint8[] data");
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
buffer.writeBytes(new byte[] { 1, 2, 3, 4, 5 });
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setChannelBuffer("data", buffer);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt32Array() {
topicDefinitionResourceProvider.add("foo/foo", "int32[] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt32Array("data", new int[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testFloat64Array() {
topicDefinitionResourceProvider.add("foo/foo", "float64[] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testChannelBufferFixedSizeWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
buffer.writeBytes(new byte[] { 1, 2, 3, 4, 5 });
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setChannelBuffer("data", buffer);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testChannelBufferFixedSizeWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
buffer.writeBytes(new byte[] { 1, 2, 3 });
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setChannelBuffer("data", buffer);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testChannelBufferFixedSizeNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "uint8[5] data");
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setChannelBuffer("data", buffer);
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt32FixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt32Array("data", new int[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt32FixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt32Array("data", new int[] { 1, 2, 3 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testInt32FixedSizeArrayNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "int32[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testFloat64FixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testFloat64FixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setFloat64Array("data", new double[] { 1, 2, 3 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testFloat64FixedSizeArrayNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "float64[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testStringFixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
String[] stringArray = new String[] { "String 1", "String 2", "String 3", "String 4", "String 5" };
rawMessage.setStringList("data", Arrays.asList(stringArray));
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testStringFixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
String[] stringArray = new String[] { "String 1", "String 2", "String 3" };
rawMessage.setStringList("data", Arrays.asList(stringArray));
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testStringFixedSizeArrayWithNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "string[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testByteFixedSizeArrayWithInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt8Array("data", new byte[] { 1, 2, 3, 4, 5 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testByteFixedSizeArrayWithIncompleteInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
rawMessage.setInt8Array("data", new byte[] { 1, 2, 3 });
checkSerializeAndDeserialize(rawMessage);
}
@Test
public void testByteFixedSizeArrayWithNoInitialization() {
topicDefinitionResourceProvider.add("foo/foo", "byte[5] data");
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
checkSerializeAndDeserialize(rawMessage);
}
}
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ros.internal.message;
import org.junit.Before;
import org.junit.Test;
import org.ros.internal.message.service.ServiceDefinitionResourceProvider;
import org.ros.internal.message.service.ServiceRequestMessageFactory;
import org.ros.internal.message.service.ServiceResponseMessageFactory;
/**
* @author damonkohler@google.com (Damon Kohler)
*/
public class ServiceTest {
private ServiceDefinitionResourceProvider serviceDefinitionResourceProvider;
private ServiceRequestMessageFactory serviceRequestMessageFactory;
private ServiceResponseMessageFactory serviceResponseMessageFactory;
@Before
public void setUp() {
serviceDefinitionResourceProvider = new ServiceDefinitionResourceProvider();
serviceDefinitionResourceProvider.add("foo/Echo", "string data\n---\nstring data");
serviceRequestMessageFactory =
new ServiceRequestMessageFactory(serviceDefinitionResourceProvider);
serviceResponseMessageFactory =
new ServiceResponseMessageFactory(serviceDefinitionResourceProvider);
}
@Test
public void testCreateEchoService() {
RawMessage request = serviceRequestMessageFactory.newFromType("foo/Echo");
RawMessage response = serviceResponseMessageFactory.newFromType("foo/Echo");
request.setString("data", "Hello, ROS!");
response.setString("data", "Hello, ROS!");
}
}
/*
* Copyright (C) 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ros.internal.message.field;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import org.ros.internal.message.MessageBuffers;
import org.jboss.netty.buffer.ChannelBuffer;
import org.junit.Test;
/**
* The following unit tests were created by inspecting the serialization of
* array fields using the ROS Python client library.
*
* @author damonkohler@google.com (Damon Kohler)
*/
public class ArrayFieldTest {
@Test
public void testBooleanArrayFieldVariableSize() {
BooleanArrayField field = BooleanArrayField.newVariable("foo", -1);
boolean[] value = new boolean[] { true, false, true, false };
field.setValue(value);
assertEquals(PrimitiveFieldType.BOOL, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 4, 0, 0, 0, 1, 0, 1, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testBooleanArrayFieldFixedSize() {
BooleanArrayField field = BooleanArrayField.newVariable("foo", 4);
field.setValue(new boolean[] { true, false, true, false });
assertEquals(PrimitiveFieldType.BOOL, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 1, 0, 1, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@SuppressWarnings("deprecation")
@Test
public void testByteArrayFieldVariableSize() {
testByteArrayFieldVariableSize(PrimitiveFieldType.INT8);
testByteArrayFieldVariableSize(PrimitiveFieldType.BYTE);
testByteArrayFieldVariableSize(PrimitiveFieldType.UINT8);
testByteArrayFieldVariableSize(PrimitiveFieldType.CHAR);
}
private void testByteArrayFieldVariableSize(FieldType type) {
ByteArrayField field = ByteArrayField.newVariable(type, "foo", -1);
field.setValue(new byte[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 4, 0, 0, 0, 1, 2, 3, 4 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@SuppressWarnings("deprecation")
@Test
public void testByteArrayFieldFixedSize() {
testByteArrayFieldFixedSize(PrimitiveFieldType.INT8);
testByteArrayFieldFixedSize(PrimitiveFieldType.BYTE);
testByteArrayFieldFixedSize(PrimitiveFieldType.UINT8);
testByteArrayFieldFixedSize(PrimitiveFieldType.CHAR);
}
private void testByteArrayFieldFixedSize(FieldType type) {
ByteArrayField field = ByteArrayField.newVariable(type, "foo", 4);
field.setValue(new byte[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 1, 2, 3, 4 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testDoubleArrayFieldVariableSize() {
DoubleArrayField field = DoubleArrayField.newVariable("foo", -1);
field.setValue(new double[] { 1, 2, 3, 4 });
assertEquals(PrimitiveFieldType.FLOAT64, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected =
new byte[] { 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0,
0, 8, 64, 0, 0, 0, 0, 0, 0, 16, 64 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testDoubleArrayFieldFixedSize() {
DoubleArrayField field = DoubleArrayField.newVariable("foo", 4);
field.setValue(new double[] { 1, 2, 3, 4 });
assertEquals(PrimitiveFieldType.FLOAT64, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected =
new byte[] { 0, 0, 0, 0, 0, 0, -16, 63, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 8, 64,
0, 0, 0, 0, 0, 0, 16, 64 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testFloatArrayFieldVariableSize() {
FloatArrayField field = FloatArrayField.newVariable("foo", -1);
field.setValue(new float[] { 1, 2, 3, 4 });
assertEquals(PrimitiveFieldType.FLOAT32, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected =
new byte[] { 4, 0, 0, 0, 0, 0, -128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, -128, 64 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testFloatArrayFieldFixedSize() {
FloatArrayField field = FloatArrayField.newVariable("foo", 4);
field.setValue(new float[] { 1, 2, 3, 4 });
assertEquals(PrimitiveFieldType.FLOAT32, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 0, 0, -128, 63, 0, 0, 0, 64, 0, 0, 64, 64, 0, 0, -128, 64 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testIntegerArrayFieldVariableSize() {
testIntegerArrayFieldVariableSize(PrimitiveFieldType.INT32);
testIntegerArrayFieldVariableSize(PrimitiveFieldType.UINT32);
}
private void testIntegerArrayFieldVariableSize(FieldType type) {
IntegerArrayField field = IntegerArrayField.newVariable(type, "foo", -1);
field.setValue(new int[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 4, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testIntegerArrayFieldFixedSize() {
testIntegerArrayFieldFixedSize(PrimitiveFieldType.INT32);
testIntegerArrayFieldFixedSize(PrimitiveFieldType.UINT32);
}
private void testIntegerArrayFieldFixedSize(FieldType type) {
IntegerArrayField field = IntegerArrayField.newVariable(type, "foo", 4);
field.setValue(new int[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testLongArrayFieldVariableSize() {
testLongArrayFieldVariableSize(PrimitiveFieldType.INT64);
testLongArrayFieldVariableSize(PrimitiveFieldType.UINT64);
}
private void testLongArrayFieldVariableSize(FieldType type) {
LongArrayField field = LongArrayField.newVariable(type, "foo", -1);
field.setValue(new long[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected =
new byte[] { 4, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0,
0, 0, 4, 0, 0, 0, 0, 0, 0, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testLongArrayFieldFixedSize() {
testLongArrayFieldFixedSize(PrimitiveFieldType.INT64);
testLongArrayFieldFixedSize(PrimitiveFieldType.UINT64);
}
private void testLongArrayFieldFixedSize(FieldType type) {
LongArrayField field = LongArrayField.newVariable(type, "foo", 4);
field.setValue(new long[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected =
new byte[] { 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0,
0, 0, 0, 0, 0, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testShortArrayFieldVariableSize() {
testShortArrayFieldVariableSize(PrimitiveFieldType.INT16);
testShortArrayFieldVariableSize(PrimitiveFieldType.UINT16);
}
private void testShortArrayFieldVariableSize(FieldType type) {
ShortArrayField field = ShortArrayField.newVariable(type, "foo", -1);
field.setValue(new short[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 4, 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
@Test
public void testShortArrayFieldFixedSize() {
testShortArrayFieldFixedSize(PrimitiveFieldType.INT16);
testShortArrayFieldFixedSize(PrimitiveFieldType.UINT16);
}
private void testShortArrayFieldFixedSize(FieldType type) {
ShortArrayField field = ShortArrayField.newVariable(type, "foo", 4);
field.setValue(new short[] { 1, 2, 3, 4 });
assertEquals(type, field.getType());
ChannelBuffer buffer = MessageBuffers.dynamicBuffer();
field.serialize(buffer);
byte[] expected = new byte[] { 1, 0, 2, 0, 3, 0, 4, 0 };
byte[] actual = new byte[buffer.readableBytes()];
buffer.readBytes(actual);
assertArrayEquals(expected, actual);
}
}
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ros.message;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
/**
* @author kwc@willowgarage.com (Ken Conley)
*/
public class DurationTest {
@Before
public void setUp() {
}
@Test
public void testConstructor() {
// Test no args constructor.
Duration t = new Duration();
assertEquals(0, t.nsecs);
assertEquals(0, t.secs);
// Test secs/nsecs constructor with no normalization.
t = new Duration(1, 2);
assertEquals(1, t.secs);
assertEquals(2, t.nsecs);
// Test secs/nsecs constructor with normalization.
t = new Duration(2, -1);
assertEquals(1, t.secs);
assertEquals(1000000000 - 1, t.nsecs);
t = new Duration(2, 1000000000 + 2);
assertEquals(3, t.secs);
assertEquals(2, t.nsecs);
}
@Test
public void testNormalize() {
Duration d = new Duration(0, 0);
d.secs = 1;
d.nsecs = 1000000000;
d.normalize();
assertEquals(2, d.secs);
assertEquals(0, d.nsecs);
d.secs = 1;
d.nsecs = -1;
d.normalize();
assertEquals(0, d.secs);
assertEquals(1000000000-1, d.nsecs);
}
@Test
public void testIsZero() {
assertTrue(new Duration(0, 0).isZero());
assertFalse(new Duration(1, 0).isZero());
assertFalse(new Duration(0, 1).isZero());
}
@Test
public void testComparable() {
assertEquals(0, new Duration(0, 0).compareTo(new Duration(0, 0)));
assertEquals(0, new Duration(1, 0).compareTo(new Duration(1, 0)));
assertTrue(new Duration(0, 0).compareTo(new Duration(0, -1)) > 0);
assertTrue(new Duration(0, -1).compareTo(new Duration(0, 0)) < 0);
assertTrue(new Duration(0, 0).compareTo(new Duration(-1, 0)) > 0);
assertTrue(new Duration(-1, 0).compareTo(new Duration(0, 0)) < 0);
assertTrue(new Duration(1, 0).compareTo(new Duration(0, 0)) > 0);
assertTrue(new Duration(0, 0).compareTo(new Duration(1, 0)) < 0);
assertTrue(new Duration(0, 1).compareTo(new Duration(0, 0)) > 0);
assertTrue(new Duration(0, 0).compareTo(new Duration(0, 1)) < 0);
}
}
\ No newline at end of file
/*
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.ros.message;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
/**
* @author kwc@willowgarage.com (Ken Conley)
*/
public class TimeTest {
@Before
public void setUp() {
}
@Test
public void testConstructor() {
// Test no args constructor.
Time t = new Time();
assertEquals(0, t.nsecs);
assertEquals(0, t.secs);
// Test secs/nsecs constructor with no normalization.
t = new Time(1, 2);
assertEquals(1, t.secs);
assertEquals(2, t.nsecs);
// Test secs/nsecs constructor with normalization.
t = new Time(2, -1);
assertEquals(1, t.secs);
assertEquals(1000000000 - 1, t.nsecs);
t = new Time(2, 1000000000 + 2);
assertEquals(3, t.secs);
assertEquals(2, t.nsecs);
}
@Test
public void testFromMillis() {
assertEquals(new Time(0, 0), Time.fromMillis(0));
assertEquals(new Time(0, 1000000), Time.fromMillis(1));
assertEquals(new Time(1, 0), Time.fromMillis(1000));
assertEquals(new Time(10, 0), Time.fromMillis(10000));
assertEquals(new Time(1, 1000000), Time.fromMillis(1001));
assertEquals(new Time(1, 11000000), Time.fromMillis(1011));
}
@Test
public void testNormalize() {
Time t = new Time(0, 0);
t.secs = 1;
t.nsecs = 1000000000;
t.normalize();
assertEquals(2, t.secs);
assertEquals(0, t.nsecs);
t.secs = 1;
t.nsecs = -1;
t.normalize();
assertEquals(0, t.secs);
assertEquals(1000000000 - 1, t.nsecs);
}
@Test
public void testIsZero() {
assertTrue(new Time(0, 0).isZero());
assertFalse(new Time(1, 0).isZero());
assertFalse(new Time(0, 1).isZero());
}
@Test
public void testComparable() {
assertEquals(0, new Time(0, 0).compareTo(new Time(0, 0)));
assertEquals(0, new Time(1, 1).compareTo(new Time(1, 1)));
assertTrue(new Time(0, 1).compareTo(new Time(0, 0)) > 0);
assertEquals(-1, new Time(0, 0).compareTo(new Time(0, 1)));
assertTrue(new Time(0, 0).compareTo(new Time(0, 1)) < 0);
assertTrue(new Time(1, 0).compareTo(new Time(0, 0)) > 0);
assertTrue(new Time(0, 0).compareTo(new Time(1, 0)) < 0);
}
}
\ No newline at end of file
# This contains the position of a point in free space
float64 x
float64 y
float64 z
# This contains the position of a point in free space(with 32 bits of precision).
# It is recommeded to use Point wherever possible instead of Point32.
#
# This recommendation is to promote interoperability.
#
# This message is designed to take up less space when sending
# lots of points at once, as in the case of a PointCloud.
float32 x
float32 y
float32 z
\ No newline at end of file
# This represents a Point with reference coordinate frame and timestamp
Header header
Point point
#A specification of a polygon where the first and last points are assumed to be connected
Point32[] points
# This represents a Polygon with reference coordinate frame and timestamp
Header header
Polygon polygon
# A representation of pose in free space, composed of postion and orientation.
Point position
Quaternion orientation
# This expresses a position and orientation on a 2D manifold.
float64 x
float64 y
float64 theta
\ No newline at end of file
# An array of poses with a header for global reference.
Header header
Pose[] poses
# A Pose with reference coordinate frame and timestamp
Header header
Pose pose
# This represents a pose in free space with uncertainty.
Pose pose
# Row-major representation of the 6x6 covariance matrix
# The orientation parameters use a fixed-axis representation.
# In order, the parameters are:
# (x, y, z, rotation about X axis, rotation about Y axis, rotation about Z axis)
float64[36] covariance
# This expresses an estimated pose with a reference coordinate frame and timestamp
Header header
PoseWithCovariance pose
# This represents an orientation in free space in quaternion form.
float64 x
float64 y
float64 z
float64 w
# This represents an orientation with reference coordinate frame and timestamp.
Header header
Quaternion quaternion
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment