Skip to content

Commit 38748ff

Browse files
committed
Test rosidl translate extensions
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent f2c7e02 commit 38748ff

File tree

7 files changed

+262
-0
lines changed

7 files changed

+262
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# goal definition
2+
bool bool_value
3+
byte byte_value
4+
char char_value
5+
float32 float32_value
6+
float64 float64_value
7+
int8 int8_value
8+
uint8 uint8_value
9+
int16 int16_value
10+
uint16 uint16_value
11+
int32 int32_value
12+
uint32 uint32_value
13+
int64 int64_value
14+
uint64 uint64_value
15+
string string_value
16+
---
17+
# result definition
18+
bool ok
19+
---
20+
# feedback definition
21+
int32[] sequence
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// generated from rosidl_adapter/resource/action.idl.em
2+
// with input from test_msgs/action/Test.action
3+
// generated code does not contain a copyright notice
4+
5+
6+
module test_msgs {
7+
module action {
8+
@verbatim (language="comment", text=
9+
" goal definition")
10+
struct Test_Goal {
11+
boolean bool_value;
12+
13+
octet byte_value;
14+
15+
uint8 char_value;
16+
17+
float float32_value;
18+
19+
double float64_value;
20+
21+
int8 int8_value;
22+
23+
uint8 uint8_value;
24+
25+
int16 int16_value;
26+
27+
uint16 uint16_value;
28+
29+
int32 int32_value;
30+
31+
uint32 uint32_value;
32+
33+
int64 int64_value;
34+
35+
uint64 uint64_value;
36+
37+
string string_value;
38+
};
39+
struct Test_Result {
40+
@verbatim (language="comment", text=
41+
" result definition")
42+
boolean ok;
43+
};
44+
struct Test_Feedback {
45+
@verbatim (language="comment", text=
46+
" feedback definition")
47+
sequence<int32> sequence;
48+
};
49+
};
50+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// generated from rosidl_adapter/resource/msg.idl.em
2+
// with input from test_msgs/msg/Test.msg
3+
// generated code does not contain a copyright notice
4+
5+
6+
module test_msgs {
7+
module msg {
8+
struct Test {
9+
boolean bool_value;
10+
11+
octet byte_value;
12+
13+
uint8 char_value;
14+
15+
float float32_value;
16+
17+
double float64_value;
18+
19+
int8 int8_value;
20+
21+
uint8 uint8_value;
22+
23+
int16 int16_value;
24+
25+
uint16 uint16_value;
26+
27+
int32 int32_value;
28+
29+
uint32 uint32_value;
30+
31+
int64 int64_value;
32+
33+
uint64 uint64_value;
34+
};
35+
};
36+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
bool bool_value
2+
byte byte_value
3+
char char_value
4+
float32 float32_value
5+
float64 float64_value
6+
int8 int8_value
7+
uint8 uint8_value
8+
int16 int16_value
9+
uint16 uint16_value
10+
int32 int32_value
11+
uint32 uint32_value
12+
int64 int64_value
13+
uint64 uint64_value
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// generated from rosidl_adapter/resource/srv.idl.em
2+
// with input from test_msgs/srv/Test.srv
3+
// generated code does not contain a copyright notice
4+
5+
6+
module test_msgs {
7+
module srv {
8+
struct Test_Request {
9+
boolean bool_value;
10+
11+
octet byte_value;
12+
13+
uint8 char_value;
14+
15+
float float32_value;
16+
17+
double float64_value;
18+
19+
int8 int8_value;
20+
21+
uint8 uint8_value;
22+
23+
int16 int16_value;
24+
25+
uint16 uint16_value;
26+
27+
int32 int32_value;
28+
29+
uint32 uint32_value;
30+
31+
int64 int64_value;
32+
33+
uint64 uint64_value;
34+
35+
string string_value;
36+
};
37+
struct Test_Response {
38+
boolean ok;
39+
};
40+
};
41+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
bool bool_value
2+
byte byte_value
3+
char char_value
4+
float32 float32_value
5+
float64 float64_value
6+
int8 int8_value
7+
uint8 uint8_value
8+
int16 int16_value
9+
uint16 uint16_value
10+
int32 int32_value
11+
uint32 uint32_value
12+
int64 int64_value
13+
uint64 uint64_value
14+
string string_value
15+
---
16+
bool ok
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import filecmp
16+
import pathlib
17+
18+
from rosidl_cli.command.translate.api import translate
19+
20+
21+
DATA_PATH = pathlib.Path(__file__).parent / 'data'
22+
23+
24+
def test_translation_extensions(tmp_path, capsys):
25+
# NOTE(hidmic): pytest and empy do not play along,
26+
# the latter expects some proxy will stay in sys.stdout
27+
# and the former insists in overwriting it
28+
29+
with capsys.disabled(): # so do everything in one run
30+
# Test .msg to .idl translation
31+
idl_files = translate(
32+
package_name='test_msgs',
33+
interface_files=[
34+
f'{DATA_PATH}:msg/Test.msg'],
35+
output_path=tmp_path,
36+
output_format='idl',
37+
translators=['msg2idl']
38+
)
39+
40+
assert len(idl_files) == 1
41+
idl_file = idl_files[0]
42+
assert idl_file == f'{tmp_path}:msg/Test.idl'
43+
assert filecmp.cmp(
44+
tmp_path / 'msg' / 'Test.idl',
45+
DATA_PATH / 'msg' / 'Test.expected.idl',
46+
shallow=False
47+
)
48+
49+
# Test .srv to .idl translation
50+
idl_files = translate(
51+
package_name='test_msgs',
52+
interface_files=[
53+
f'{DATA_PATH}:srv/Test.srv'],
54+
output_path=tmp_path,
55+
output_format='idl',
56+
translators=['srv2idl']
57+
)
58+
59+
assert len(idl_files) == 1
60+
idl_file = idl_files[0]
61+
assert idl_file == f'{tmp_path}:srv/Test.idl'
62+
assert filecmp.cmp(
63+
tmp_path / 'srv' / 'Test.idl',
64+
DATA_PATH / 'srv' / 'Test.expected.idl',
65+
shallow=False
66+
)
67+
68+
# Test .action to .idl translation
69+
idl_files = translate(
70+
package_name='test_msgs',
71+
interface_files=[
72+
f'{DATA_PATH}:action/Test.action'],
73+
output_path=tmp_path,
74+
output_format='idl',
75+
translators=['action2idl']
76+
)
77+
78+
assert len(idl_files) == 1
79+
idl_file = idl_files[0]
80+
assert idl_file == f'{tmp_path}:action/Test.idl'
81+
assert filecmp.cmp(
82+
tmp_path / 'action' / 'Test.idl',
83+
DATA_PATH / 'action' / 'Test.expected.idl',
84+
shallow=False
85+
)

0 commit comments

Comments
 (0)