Skip to content

Commit 3dcad9d

Browse files
committed
[test]Add test cases for MultiArray message type
1 parent 30a0c25 commit 3dcad9d

File tree

4 files changed

+81
-19
lines changed

4 files changed

+81
-19
lines changed

test/py/publisher_msg.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ def main():
9797
publisher = node.create_publisher(Float64, 'Float64_py_js_channel')
9898
msg = Float64()
9999
msg.data = 3.14
100+
elif rclType == 'Array':
101+
node = rclpy.create_node('py_array_publisher')
102+
publisher = node.create_publisher(ByteMultiArray, 'Array_py_js_channel');
103+
104+
lengthDim = MultiArrayDimension()
105+
lengthDim.label = 'length'
106+
lengthDim.size = 1;
107+
lengthDim.stride = 3;
108+
109+
layout = MultiArrayLayout()
110+
layout.dim = [lengthDim]
111+
layout.data_offset = 0;
112+
113+
msg = ByteMultiArray()
114+
msg.layout = layout
115+
msg.data = [b'\x41', b'\x42', b'\x43']
100116
elif rclType == 'ColorRGBA':
101117
node = rclpy.create_node('py_colorrgba_publisher')
102118
publisher = node.create_publisher(ColorRGBA, 'ColorRGBA_py_js_channel')

test/py/subscription_msg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def callback(msg):
3636
sys.stdout.write(str(msg.data))
3737
sys.stdout.flush()
3838

39+
def callback_array(msg):
40+
sys.stdout.write(''.join([r.decode('utf-8') for r in msg.data]))
41+
sys.stdout.flush()
42+
3943
def callback_colorrgba(msg):
4044
sys.stdout.write('(' + str(msg.r) + ','
4145
+ str(msg.g) + ','
@@ -109,6 +113,9 @@ def main():
109113
elif rclType == 'Float64':
110114
node = rclpy.create_node('py_float64_subscription')
111115
subscription = node.create_subscription(Float64, 'Float64_js_py_channel', callback)
116+
elif rclType == 'Array':
117+
node = rclpy.create_node('py_array_subscription')
118+
subscription = node.create_subscription(ByteMultiArray, 'Array_js_py_channel', callback_array)
112119
elif rclType == 'ColorRGBA':
113120
node = rclpy.create_node('py_colorrgba_subscription')
114121
subscription = node.create_subscription(ColorRGBA, 'ColorRGBA_js_py_channel', callback_colorrgba)

test/test-compound-msg-type-check.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,6 @@ describe('Compound types', function() {
3838
assert.deepStrictEqual(typeof msg.g, 'number');
3939
assert.deepStrictEqual(typeof msg.b, 'number');
4040
assert.deepStrictEqual(typeof msg.a, 'number');
41-
42-
// assertThrowsError(() => {
43-
// msg.r = -1;
44-
// msg.r = 256;
45-
// }, TypeError, 'out of bounds', 'Invalid RGBA value');
46-
// assertThrowsError(() => {
47-
// msg.g = -1;
48-
// msg.g = 256;
49-
// }, TypeError, 'out of bounds', 'Invalid RGBA value');
50-
// assertThrowsError(() => {
51-
// msg.b = -1;
52-
// msg.b = 256;
53-
// }, TypeError, 'out of bounds', 'Invalid RGBA value');
54-
// assertThrowsError(() => {
55-
// msg.a = -0.1;
56-
// msg.a = 1.1;
57-
// }, TypeError, 'out of bounds', 'Invalid RGBA value');
5841
});
5942

6043
it('Array', function() {

test/test-msg-type-py-node.js

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,23 @@ describe('Rclnodejs - Python message type testing', function() {
294294
rclnodejs.spin(node);
295295
});
296296

297-
// it('Array', function(done) {
298-
// });
297+
it('Array', function(done) {
298+
var node = rclnodejs.createNode('array_js_subscription');
299+
const ByteMultiArray = rclnodejs.require('std_msgs').msg.ByteMultiArray;
300+
var destroy = false;
301+
var publisher = utils.launchPythonProcess([`${__dirname}/py/publisher_msg.py`, 'Array']);
302+
var subscription = node.createSubscription(ByteMultiArray, 'Array_py_js_channel', (msg) => {
303+
assert.deepStrictEqual(msg.data, [65, 66, 67]);
304+
305+
if (!destroy) {
306+
node.destroy();
307+
publisher.kill('SIGINT');
308+
destroy = true;
309+
}
310+
done();
311+
});
312+
rclnodejs.spin(node);
313+
});
299314

300315
it('Header', function(done) {
301316
var node = rclnodejs.createNode('header_js_publisher');
@@ -733,6 +748,47 @@ describe('Rclnodejs - Python message type testing', function() {
733748
describe('Rclnodejs publisher - Python subscription: compound msg types', function() {
734749
this.timeout(60 * 1000);
735750

751+
it('Array', function(done) {
752+
var node = rclnodejs.createNode('multiarray_js_publisher');
753+
const Byte = rclnodejs.require('std_msgs').msg.Byte;
754+
const MultiArrayDimension = rclnodejs.require('std_msgs').msg.MultiArrayDimension;
755+
const MultiArrayLayout = rclnodejs.require('std_msgs').msg.MultiArrayLayout;
756+
const ByteMultiArray = rclnodejs.require('std_msgs').msg.ByteMultiArray;
757+
758+
let lengthDim = new MultiArrayDimension();
759+
lengthDim.label = 'length';
760+
lengthDim.size = 1;
761+
lengthDim.stride = 3;
762+
763+
let layout = new MultiArrayLayout();
764+
layout.dim.fill([lengthDim]);
765+
// eslint-disable-next-line
766+
layout.data_offset = 0;
767+
768+
let byteArray = new ByteMultiArray();
769+
byteArray.layout = layout;
770+
byteArray.data = [65, 66, 67];
771+
772+
var destroy = false;
773+
var subscription = utils.launchPythonProcess([`${__dirname}/py/subscription_msg.py`, 'Array']);
774+
var publisher = node.createPublisher(ByteMultiArray, 'Array_js_py_channel');
775+
const expected = 'ABC';
776+
subscription.stdout.on('data', (data) => {
777+
if (!destroy) {
778+
clearInterval(timer);
779+
assert.deepStrictEqual(data.toString(), expected);
780+
done();
781+
node.destroy();
782+
subscription.kill('SIGINT');
783+
destroy = true;
784+
}
785+
});
786+
var timer = setInterval(() => {
787+
publisher.publish(byteArray);
788+
}, 100);
789+
rclnodejs.spin(node);
790+
});
791+
736792
it('ColorRGBA', function(done) {
737793
var node = rclnodejs.createNode('colorrgba_js_publisher');
738794
const ColorRGBA = rclnodejs.require('std_msgs').msg.ColorRGBA;

0 commit comments

Comments
 (0)