-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathtest_rticonnextdds_connector.js
More file actions
145 lines (130 loc) · 6 KB
/
test_rticonnextdds_connector.js
File metadata and controls
145 lines (130 loc) · 6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/******************************************************************************
* (c) 2005-2019 Copyright, Real-Time Innovations. All rights reserved. *
* No duplications, whole or partial, manual or electronic, may be made *
* without express written permission. Any such copies, or revisions thereof, *
* must display this notice unaltered. *
* This code contains trade secrets of Real-Time Innovations, Inc. *
******************************************************************************/
const path = require('path')
const expect = require('chai').expect
const rti = require(path.join(__dirname, '/../../rticonnextdds-connector'))
const sinon = require('sinon')
// We have to do this due to the expect() syntax of chai and the fact
// that we install mocha globally
/* eslint-disable no-unused-expressions */
/* eslint-disable no-undef */
describe('Connector Tests', function () {
it('Connector should throw an error for invalid xml path', function () {
const participantProfile = 'MyParticipantLibrary::Zero'
const invalidXmlPath = 'invalid/path/to/xml'
expect(function () {
new rti.Connector(participantProfile, invalidXmlPath) // eslint-disable-line no-new
}).to.throw(Error)
})
it('Connector should throw an error for invalid participant profile', function () {
const invalidParticipantProfile = 'InvalidParticipantProfile'
const xmlPath = path.join(__dirname, '/../xml/TestConnector.xml')
expect(function () {
new rti.Connector(invalidParticipantProfile, xmlPath) // eslint-disable-line no-new
}).to.throw(Error)
})
it('Connector should throw an error for invalid xml profile', function () {
const participantProfile = 'MyParticipantLibrary::Zero'
const invalidXml = path.join(__dirname, '/../xml/InvalidXml.xml')
expect(function () {
new rti.Connector(participantProfile, invalidXml) // eslint-disable-line no-new
}).to.throw(Error)
})
it('Connector should get instantiated for valid' +
'xml and participant profile', function () {
const participantProfile = 'MyParticipantLibrary::Zero'
const xmlProfile = path.join(__dirname, '/../xml/TestConnector.xml')
const connector = new rti.Connector(participantProfile, xmlProfile)
expect(connector).to.exist
expect(connector).to.be.instanceOf(rti.Connector)
connector.close()
})
it('Multiple Connector objects can be instantiated', () => {
const participantProfile = 'MyParticipantLibrary::Zero'
const xmlProfile = path.join(__dirname, '/../xml/TestConnector.xml')
const connectors = []
for (var i = 0; i < 3; i++) {
connectors.push(new rti.Connector(participantProfile, xmlProfile))
}
connectors.forEach((connector) => {
expect(connector).to.exist
expect(connector).to.be.instanceOf(rti.Connector)
connector.close()
})
})
// Test for CON-163
it('Multiple Connector obejcts can be instantiated without participant QoS', () => {
const participantProfile = 'MyParticipantLibrary::MyParticipant'
const xmlProfile = path.join(__dirname, '/../xml/TestConnector3.xml')
const connectors = []
for (var i = 0; i < 2; i++) {
connectors.push(new rti.Connector(participantProfile, xmlProfile))
}
connectors.forEach((connector) => {
expect(connector).to.exist
expect(connector).to.be.instanceOf(rti.Connector)
connector.close()
})
})
it('Load two XML files using the url group syntax', function () {
const xmlProfile1 = path.join(__dirname, '/../xml/TestConnector.xml')
const xmlProfile2 = path.join(__dirname, '/../xml/TestConnector2.xml')
const fullXmlPath = xmlProfile1 + ';' + xmlProfile2
const connector = new rti.Connector('MyParticipantLibrary2::MyParticipant2', fullXmlPath)
expect(connector).to.exist
expect(connector).to.be.instanceOf(rti.Connector)
const output = connector.getOutput('MyPublisher2::MySquareWriter2')
expect(output).to.exist
connector.close()
})
it('Should be possible to create a Connector with participant qos', function () {
const xmlProfile = path.join(__dirname, '/../xml/TestConnector.xml')
const connector = new rti.Connector(
'MyParticipantLibrary::ConnectorWithParticipantQos',
xmlProfile)
expect(connector).to.exist
expect(connector).to.be.instanceOf(rti.Connector)
})
// Test for CON-200
it('Connector should not segfault if deleted twice', async function () {
const xmlProfile1 = path.join(__dirname, '/../xml/TestConnector.xml')
const xmlProfile2 = path.join(__dirname, '/../xml/TestConnector2.xml')
const fullXmlPath = xmlProfile1 + ';' + xmlProfile2
const connector = new rti.Connector('MyParticipantLibrary2::MyParticipant2', fullXmlPath)
expect(connector).to.exist
expect(connector).to.be.instanceOf(rti.Connector)
await connector.close()
await connector.close()
})
describe('Connector callback test', function () {
let connector
// Initialization before all tests are executed
before(() => {
const participantProfile = 'MyParticipantLibrary::Zero'
const xmlProfile = path.join(__dirname, '/../xml/TestConnector.xml')
connector = new rti.Connector(participantProfile, xmlProfile)
})
// Cleanup after all tests have executed
after(async () => {
await connector.delete()
})
it('on_data_available callback gets called when data is available', function (done) {
// spies are used for testing callbacks
const spy = sinon.spy()
setTimeout(() => {
expect(spy.calledOnce).to.be.true
done() // Pattern for async testing: next test won't execute until done gets called.
}, 1000) // Expectation Test will execute after 1000 milisec
connector.once('on_data_available', spy)
output = connector.getOutput('MyPublisher::MySquareWriter')
testMsg = '{"x":1,"y":1,"z":true,"color":"BLUE","shapesize":5}'
output.instance.setFromJson(JSON.parse(testMsg))
output.write()
})
})
})