|
| 1 | +// Copyright (c) 2017 Intel Corporation. All rights reserved. |
| 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 | +'use strict'; |
| 16 | + |
| 17 | +const assert = require('assert'); |
| 18 | +const rclnodejs = require('../index.js'); |
| 19 | +const utils = require('./utils.js'); |
| 20 | + |
| 21 | +describe('rclnodejs expand topic API testing', function() { |
| 22 | + this.timeout(60 * 1000); |
| 23 | + |
| 24 | + before(function() { |
| 25 | + return rclnodejs.init(); |
| 26 | + }); |
| 27 | + |
| 28 | + after(function() { |
| 29 | + rclnodejs.shutdown(); |
| 30 | + }); |
| 31 | + |
| 32 | + it('test_expand_topic_name', function() { |
| 33 | + var tests = { |
| 34 | + '/ns/chatter': ['chatter', 'node_name', '/ns'], |
| 35 | + '/chatter': ['chatter', 'node_name', '/'], |
| 36 | + '/ns/node_name/chatter': ['~/chatter', 'node_name', '/ns'], |
| 37 | + '/node_name/chatter': ['~/chatter', 'node_name', '/'] |
| 38 | + }; |
| 39 | + |
| 40 | + for (let test in tests) { |
| 41 | + var [topic, name, namespace] = tests[test]; |
| 42 | + assert.deepStrictEqual(test, rclnodejs.expandTopicName(topic, name, namespace)); |
| 43 | + } |
| 44 | + }); |
| 45 | + |
| 46 | + it('expand_topic_name_invalid_node_name', function() { |
| 47 | + utils.assertThrowsError(() => { |
| 48 | + rclnodejs.expandTopicName('topic', 'invalid_node_name?', '/ns'); |
| 49 | + }, Error, 'node name is invalid', 'invalid node name'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('expand_topic_name_invalid_namespace_empty', function() { |
| 53 | + utils.assertThrowsError(() => { |
| 54 | + rclnodejs.expandTopicName('topic', 'node_name', ''); |
| 55 | + }, Error, 'node namespace is invalid', 'invalid namespace'); |
| 56 | + }); |
| 57 | + |
| 58 | + it('expand_topic_name_invalid_namespace_relative', function() { |
| 59 | + utils.assertThrowsError(() => { |
| 60 | + rclnodejs.expandTopicName('topic', 'node_name', 'ns'); |
| 61 | + }, Error, 'node namespace is invalid', 'invalid namespace'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('expand_topic_name_invalid_topic', function() { |
| 65 | + utils.assertThrowsError(() => { |
| 66 | + rclnodejs.expandTopicName('invalid/topic?', 'node_name', '/ns'); |
| 67 | + }, Error, 'topic name is invalid', 'invalid topic name'); |
| 68 | + }); |
| 69 | +}); |
0 commit comments