Skip to content

Commit 6a6e777

Browse files
author
Minggang Wang
authored
Merge pull request #254 from qiuzhong/tc-4pr251
Complete test cases for missing APIs in PR251
2 parents 1cfcf49 + e5f9ce4 commit 6a6e777

File tree

2 files changed

+97
-6
lines changed

2 files changed

+97
-6
lines changed

test/test-existance.js

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ const assertThrowsError = assertUtils.assertThrowsError;
2222

2323
describe('rclnodejs module existance testing', function() {
2424
describe('rclnodejs module members', function() {
25+
it('QoS member should exist', function() {
26+
assertMember('QoS', rclnodejs, rclnodejs.QoS, 'function');
27+
});
28+
29+
it('validator member should exist', function() {
30+
assertMember('validator', rclnodejs, rclnodejs.validator, 'object');
31+
});
32+
33+
it('createMessageObject method should exist', function() {
34+
assertMember('createMessageObject', rclnodejs, rclnodejs.createMessageObject, 'function');
35+
});
36+
2537
it('createNode method should exist', function() {
2638
assertMember('createNode', rclnodejs, rclnodejs.createNode, 'function');
2739
});
@@ -142,29 +154,65 @@ describe('rclnodejs class existance testing', function() {
142154

143155
it('destroyTimer method should exist', function() {
144156
assertMember('destroyTimer', node, node.destroyTimer, 'function');
145-
});
157+
});
158+
159+
it('name method should exist', function() {
160+
assertMember('name', node, node.name, 'function');
161+
});
162+
163+
it('namespace method should exist', function() {
164+
assertMember('namespace', node, node.namespace, 'function');
165+
});
146166
});
147167

148-
describe('Publisher class', function() {
149-
var node, RclString, publisher;
168+
describe('Publisher & Subscription class', function() {
169+
var node, RclString, publisher, subscription;
150170

151171
before(function() {
152172
node = rclnodejs.createNode('Publisher');
153173
RclString = 'std_msgs/msg/String';
154174
publisher = node.createPublisher(RclString, 'chatter');
175+
subscription = node.createSubscription(RclString, 'chatter', () => {});
155176
});
156177

157178
after(function() {
158179
node.destroy();
159180
});
160181

161-
it('topic property should exist', function() {
182+
it('topic property of a publisher should exist', function() {
162183
assertMember('topic', publisher, publisher.topic, 'string');
163184
});
164185

165-
it('publish method should exist', function() {
186+
it('publish method of a publisher should exist', function() {
166187
assertMember('publish', publisher, publisher.publish, 'function');
167188
});
189+
190+
it('topic member of a subscription should exist', function() {
191+
assertMember('topic', subscription, subscription.topic, 'string');
192+
});
193+
});
194+
195+
describe('Client & Service class', function() {
196+
var node, AddTwoInts, client, service;
197+
198+
before(function() {
199+
node = rclnodejs.createNode('Client');
200+
AddTwoInts = 'example_interfaces/srv/AddTwoInts';
201+
client = node.createClient(AddTwoInts, 'add_two_ints', (req, res) => {});
202+
service = node.createService(AddTwoInts, 'add_two_ints', (req) => {});
203+
});
204+
205+
after(function() {
206+
node.destroy();
207+
});
208+
209+
it('serviceName member of a client should exist', function() {
210+
assertMember('serviceName', client, client.serviceName, 'string');
211+
});
212+
213+
it('serviceName member of a service should exist', function() {
214+
assertMember('serviceName', service, service.serviceName, 'string');
215+
});
168216
});
169217

170218
describe('Timer class', function() {
@@ -200,7 +248,7 @@ describe('rclnodejs class existance testing', function() {
200248
it('reset method should exist', function() {
201249
assertMember('reset', timer, timer.reset, 'function');
202250
});
203-
251+
204252
it('timeSinceLastCall method should exist', function() {
205253
assertMember('timeSinceLastCall', timer, timer.timeSinceLastCall, 'function');
206254
});

test/test-node.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,46 @@ describe('rcl node methods testing', function() {
305305
});
306306
});
307307
});
308+
309+
describe('topic & serviceName getter/setter', function() {
310+
const RclString = 'std_msgs/msg/String';
311+
const AddTwoInts = 'example_interfaces/srv/AddTwoInts';
312+
313+
this.timeout(60 * 1000);
314+
315+
before(function() {
316+
return rclnodejs.init();
317+
});
318+
319+
after(function() {
320+
rclnodejs.shutdown();
321+
});
322+
323+
it('publisher: topic property getter', function() {
324+
var node = rclnodejs.createNode('publisher', '/topic_getter');
325+
var publisher = node.createPublisher(RclString, 'chatter');
326+
assert.deepStrictEqual(publisher.topic, 'chatter');
327+
node.destroy();
328+
});
329+
330+
it('subscription: topic property getter', function() {
331+
var node = rclnodejs.createNode('subscription', '/topic_getter');
332+
var subscription = node.createSubscription(RclString, 'chatter', (msg) => {});
333+
assert.deepStrictEqual(subscription.topic, 'chatter');
334+
node.destroy();
335+
});
336+
337+
it('client: serviceName property getter', function() {
338+
var node = rclnodejs.createNode('client', '/servicename_getter');
339+
var client = node.createClient(AddTwoInts, 'add_two_ints', (req, res) => {});
340+
assert.deepStrictEqual(client.serviceName, 'add_two_ints');
341+
node.destroy();
342+
});
343+
344+
it('service: topic property getter', function() {
345+
var node = rclnodejs.createNode('service', '/servicename_getter');
346+
var service = node.createService(AddTwoInts, 'add_two_ints', (req) => {});
347+
assert.deepStrictEqual(service.serviceName, 'add_two_ints');
348+
node.destroy();
349+
});
350+
});

0 commit comments

Comments
 (0)