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

Commit d77db57

Browse files
damonkohlerstonier
authored andcommitted
message_generation tests from rosjava_core.
1 parent 2a4c144 commit d77db57

File tree

108 files changed

+1514
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+1514
-7
lines changed

message_generation/build.gradle

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
*/
1616

1717
dependencies {
18-
compile "com.google.guava:guava:12.0"
19-
compile "commons-pool:commons-pool:1.6"
20-
compile "io.netty:netty:3.5.2.Final"
21-
compile "org.apache.commons:com.springsource.org.apache.commons.codec:1.3.0"
22-
compile "org.apache.commons:com.springsource.org.apache.commons.io:1.4.0"
23-
compile "org.apache.commons:com.springsource.org.apache.commons.lang:2.4.0"
24-
testCompile "junit:junit:4.8.2"
18+
compile 'io.netty:netty:3.5.2.Final'
19+
compile 'com.google.guava:guava:12.0'
20+
compile 'org.apache.commons:com.springsource.org.apache.commons.codec:1.3.0'
21+
compile 'org.apache.commons:com.springsource.org.apache.commons.io:1.4.0'
22+
compile 'commons-pool:commons-pool:1.6'
23+
compile 'org.apache.commons:com.springsource.org.apache.commons.lang:2.4.0'
24+
compile project(':gradle_plugins')
25+
testCompile 'junit:junit:4.8.2'
2526
}
2627

2728
apply plugin: "application"
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright (C) 2011 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package org.ros.internal.message;
18+
19+
import static org.junit.Assert.assertEquals;
20+
21+
import org.ros.internal.message.definition.MessageDefinitionProviderChain;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.ros.internal.message.service.ServiceDefinitionResourceProvider;
26+
import org.ros.internal.message.service.ServiceDescription;
27+
import org.ros.internal.message.service.ServiceDescriptionFactory;
28+
import org.ros.internal.message.topic.TopicDefinitionResourceProvider;
29+
import org.ros.internal.message.topic.TopicDescription;
30+
import org.ros.internal.message.topic.TopicDescriptionFactory;
31+
32+
/**
33+
* @author [email protected] (Damon Kohler)
34+
*/
35+
public class Md5GeneratorTest {
36+
37+
private TopicDescriptionFactory topicDescriptionFactory;
38+
private ServiceDescriptionFactory serviceDescriptionFactory;
39+
40+
@Before
41+
public void setUp() {
42+
MessageDefinitionProviderChain messageDefinitionProviderChain =
43+
new MessageDefinitionProviderChain();
44+
messageDefinitionProviderChain
45+
.addMessageDefinitionProvider(new TopicDefinitionResourceProvider());
46+
messageDefinitionProviderChain
47+
.addMessageDefinitionProvider(new ServiceDefinitionResourceProvider());
48+
topicDescriptionFactory = new TopicDescriptionFactory(messageDefinitionProviderChain);
49+
serviceDescriptionFactory = new ServiceDescriptionFactory(messageDefinitionProviderChain);
50+
}
51+
52+
@Test
53+
public void testPrimitives() {
54+
TopicDescription topicDescription =
55+
topicDescriptionFactory.newFromType("test_msgs/TestPrimitives");
56+
assertEquals("3e70f428a22c0d26ca67f87802c8e00f", topicDescription.getMd5Checksum());
57+
}
58+
59+
@Test
60+
public void testString() {
61+
TopicDescription topicDescription = topicDescriptionFactory.newFromType("test_msgs/TestString");
62+
assertEquals("334ff4377be93faa44ebc66d23d40fd3", topicDescription.getMd5Checksum());
63+
}
64+
65+
@Test
66+
public void testHeader() {
67+
TopicDescription topicDescription = topicDescriptionFactory.newFromType("test_msgs/TestHeader");
68+
assertEquals("4b5a00f536da2f756ba6aebcf795a967", topicDescription.getMd5Checksum());
69+
}
70+
71+
@Test
72+
public void testArrays() {
73+
TopicDescription topicDescription = topicDescriptionFactory.newFromType("test_msgs/TestArrays");
74+
assertEquals("4cc9b5e2cebe791aa3e994f5bc159eb6", topicDescription.getMd5Checksum());
75+
}
76+
77+
@Test
78+
public void testComposite() {
79+
TopicDescription topicDescription = topicDescriptionFactory.newFromType("test_msgs/Composite");
80+
assertEquals("d8fb6eb869ad3956b50e8737d96dc9fa", topicDescription.getMd5Checksum());
81+
}
82+
83+
@Test
84+
public void testOdometry() {
85+
TopicDescription topicDescription = topicDescriptionFactory.newFromType("nav_msgs/Odometry");
86+
assertEquals("cd5e73d190d741a2f92e81eda573aca7", topicDescription.getMd5Checksum());
87+
}
88+
89+
@Test
90+
public void testEmpty() {
91+
ServiceDescription serviceDescription = serviceDescriptionFactory.newFromType("std_srvs/Empty");
92+
assertEquals("d41d8cd98f00b204e9800998ecf8427e", serviceDescription.getMd5Checksum());
93+
}
94+
95+
@Test
96+
public void testAddTwoInts() {
97+
ServiceDescription serviceDescription =
98+
serviceDescriptionFactory.newFromType("test_msgs/AddTwoInts");
99+
assertEquals("6a2e34150c00229791cc89ff309fff21", serviceDescription.getMd5Checksum());
100+
}
101+
102+
@Test
103+
public void testTransitiveSrv() {
104+
ServiceDescription serviceDescription =
105+
serviceDescriptionFactory.newFromType("test_msgs/TransitiveSrv");
106+
assertEquals("8b7918ee2b81eaf825f4c70de011f6fa", serviceDescription.getMd5Checksum());
107+
}
108+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (C) 2012 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package org.ros.internal.message;
18+
19+
import static org.junit.Assert.assertEquals;
20+
21+
import org.junit.Before;
22+
import org.junit.Test;
23+
import org.ros.internal.message.topic.TopicDefinitionResourceProvider;
24+
import org.ros.message.MessageDeclaration;
25+
import org.ros.message.MessageFactory;
26+
27+
/**
28+
* @author [email protected] (Damon Kohler)
29+
*/
30+
public class MessageInterfaceBuilderTest {
31+
32+
private TopicDefinitionResourceProvider topicDefinitionResourceProvider;
33+
private MessageFactory messageFactory;
34+
35+
@Before
36+
public void before() {
37+
topicDefinitionResourceProvider = new TopicDefinitionResourceProvider();
38+
messageFactory = new DefaultMessageFactory(topicDefinitionResourceProvider);
39+
}
40+
41+
@Test
42+
public void testDuplicateFieldNames() {
43+
MessageInterfaceBuilder builder = new MessageInterfaceBuilder();
44+
builder.setPackageName("foo");
45+
builder.setInterfaceName("bar");
46+
builder.setMessageDeclaration(MessageDeclaration.of("foo/bar", "int32 foo\nint32 Foo"));
47+
builder.setAddConstantsAndMethods(true);
48+
String result = builder.build(messageFactory);
49+
assertEquals("package foo;\n\n"
50+
+ "public interface bar extends org.ros.internal.message.Message {\n"
51+
+ " static final java.lang.String _TYPE = \"foo/bar\";\n"
52+
+ " static final java.lang.String _DEFINITION = \"int32 foo\\nint32 Foo\";\n"
53+
+ " int getFoo();\n" + " void setFoo(int value);\n" + "}\n", result);
54+
}
55+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* Copyright (C) 2011 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package org.ros.internal.message;
18+
19+
import static org.junit.Assert.assertEquals;
20+
21+
import com.google.common.collect.Lists;
22+
23+
import org.junit.Before;
24+
import org.junit.Test;
25+
import org.ros.internal.message.topic.TopicDefinitionResourceProvider;
26+
import org.ros.message.MessageFactory;
27+
28+
/**
29+
* @author [email protected] (Damon Kohler)
30+
*/
31+
public class MessageTest {
32+
33+
private TopicDefinitionResourceProvider topicDefinitionResourceProvider;
34+
private MessageFactory messageFactory;
35+
36+
@Before
37+
public void before() {
38+
topicDefinitionResourceProvider = new TopicDefinitionResourceProvider();
39+
messageFactory = new DefaultMessageFactory(topicDefinitionResourceProvider);
40+
}
41+
42+
@Test
43+
public void testCreateEmptyMessage() {
44+
topicDefinitionResourceProvider.add("foo/foo", "");
45+
messageFactory.newFromType("foo/foo");
46+
}
47+
48+
@Test
49+
public void testCreateEmptyMessageWithBlankLines() {
50+
topicDefinitionResourceProvider.add("foo/foo", "\n\n\n\n\n");
51+
messageFactory.newFromType("foo/foo");
52+
}
53+
54+
@Test
55+
public void testString() {
56+
String data = "Hello, ROS!";
57+
RawMessage rawMessage = messageFactory.newFromType("std_msgs/String");
58+
rawMessage.setString("data", data);
59+
assertEquals(data, rawMessage.getString("data"));
60+
}
61+
62+
@Test
63+
public void testStringWithComments() {
64+
topicDefinitionResourceProvider.add("foo/foo", "# foo\nstring data\n # string other data");
65+
String data = "Hello, ROS!";
66+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
67+
rawMessage.setString("data", data);
68+
assertEquals(data, rawMessage.getString("data"));
69+
}
70+
71+
@Test
72+
public void testInt8() {
73+
byte data = 42;
74+
RawMessage rawMessage = messageFactory.newFromType("std_msgs/Int8");
75+
rawMessage.setInt8("data", data);
76+
assertEquals(data, rawMessage.getInt8("data"));
77+
}
78+
79+
@Test
80+
public void testNestedMessage() {
81+
topicDefinitionResourceProvider.add("foo/foo", "bar data");
82+
topicDefinitionResourceProvider.add("foo/bar", "int8 data");
83+
RawMessage fooMessage = messageFactory.newFromType("foo/foo");
84+
RawMessage barMessage = messageFactory.newFromType("foo/bar");
85+
fooMessage.setMessage("data", barMessage);
86+
byte data = 42;
87+
barMessage.setInt8("data", data);
88+
assertEquals(data, fooMessage.getMessage("data").toRawMessage().getInt8("data"));
89+
}
90+
91+
@Test
92+
public void testNestedMessageList() {
93+
topicDefinitionResourceProvider.add("foo/foo", "bar[] data");
94+
topicDefinitionResourceProvider.add("foo/bar", "int8 data");
95+
RawMessage fooMessage = messageFactory.newFromType("foo/foo");
96+
RawMessage barMessage = messageFactory.newFromType("foo/bar");
97+
fooMessage.setMessageList("data", Lists.<Message>newArrayList(barMessage));
98+
byte data = 42;
99+
barMessage.toRawMessage().setInt8("data", data);
100+
assertEquals(data, fooMessage.getMessageList("data").get(0).toRawMessage().getInt8("data"));
101+
}
102+
103+
@Test
104+
public void testConstantInt8() {
105+
topicDefinitionResourceProvider.add("foo/foo", "int8 data=42");
106+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
107+
assertEquals(42, rawMessage.getInt8("data"));
108+
}
109+
110+
@Test
111+
public void testConstantString() {
112+
topicDefinitionResourceProvider.add("foo/foo", "string data=Hello, ROS! # comment ");
113+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
114+
assertEquals("Hello, ROS! # comment", rawMessage.getString("data"));
115+
}
116+
117+
public void testInt8List() {
118+
topicDefinitionResourceProvider.add("foo/foo", "int8[] data");
119+
RawMessage rawMessage = messageFactory.newFromType("foo/foo");
120+
byte[] data = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
121+
rawMessage.setInt8Array("data", data);
122+
assertEquals(data, rawMessage.getInt8Array("data"));
123+
}
124+
}

0 commit comments

Comments
 (0)