Skip to content

Commit 57c58f4

Browse files
mvollrathchris-smith
authored andcommitted
Add test for UTF-8 string content (#133)
1 parent aa8f75c commit 57c58f4

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

test/onTheFly.js

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,23 @@ describe('OnTheFly', function () {
2929
return master.shutdown();
3030
});
3131

32-
const geometry_msgs = rosnodejs.require('geometry_msgs').msg;
33-
const msg = new geometry_msgs.PoseWithCovariance({
34-
pose: {
35-
position: {x:0, y:0, z:0},
36-
orientation: {w:1, x:0, y:0, z:0}
37-
},
38-
covariance: [
39-
0,0,0,0,0,0.123,
40-
0,2,0,0,0,0,
41-
0,0,4,0,0,0,
42-
0,0,0,6,0,0,
43-
0,0,0,0,8,0,
44-
0.123,0,0,0,0,0.654321654321
45-
]
46-
});
47-
48-
it('serialize/deserialize', (done) => {
32+
it('serialize/deserialize PoseWithCovariance', (done) => {
33+
const geometry_msgs = rosnodejs.require('geometry_msgs').msg;
34+
const msg = new geometry_msgs.PoseWithCovariance({
35+
pose: {
36+
position: {x:0, y:0, z:0},
37+
orientation: {w:1, x:0, y:0, z:0}
38+
},
39+
covariance: [
40+
0,0,0,0,0,0.123,
41+
0,2,0,0,0,0,
42+
0,0,4,0,0,0,
43+
0,0,0,6,0,0,
44+
0,0,0,0,8,0,
45+
0.123,0,0,0,0,0.654321654321
46+
]
47+
});
48+
4949
const size = geometry_msgs.PoseWithCovariance.getMessageSize(msg);
5050
const buffer = new Buffer(size);
5151
geometry_msgs.PoseWithCovariance.serialize(msg, buffer, 0);
@@ -56,4 +56,21 @@ describe('OnTheFly', function () {
5656

5757
done();
5858
});
59+
60+
it('serialize/deserialize String', (done) => {
61+
const std_msgs = rosnodejs.require('std_msgs').msg;
62+
const data = 'sДvΣ τhΣ 子猫'; // Test with multi-byte UTF-8 characters.
63+
// If this test fails, you killed a kitten.
64+
const msg = new std_msgs.String({ data: data });
65+
66+
const size = std_msgs.String.getMessageSize(msg);
67+
68+
const buffer = new Buffer(size);
69+
std_msgs.String.serialize(msg, buffer, 0);
70+
71+
const read = std_msgs.String.deserialize(buffer);
72+
expect(read.data).to.deep.equal(data);
73+
74+
done();
75+
});
5976
});

0 commit comments

Comments
 (0)