Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions rticonnextdds-connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ var _ConnectorOptions = StructType({
enable_on_data_event: ref.types.int,
one_based_sequence_indexing: ref.types.int
})

class _ConnectorBinding {
constructor () {
let libDir = ''
Expand Down Expand Up @@ -137,7 +136,8 @@ class _ConnectorBinding {
RTI_Connector_free_string: ['void', ['char *']],
RTIDDSConnector_getJSONInstance:['char *', ['pointer', 'string']],
// This API is only used in the unit tests
RTI_Connector_create_test_scenario: ['int', ['pointer', 'int', 'pointer']]
RTI_Connector_create_test_scenario: ['int', ['pointer', 'int', 'pointer']],
RTI_Connector_get_build_versions: ['int', [ref.refType('char *'), ref.refType('char *')]]
})
}
}
Expand Down Expand Up @@ -2055,6 +2055,38 @@ class Connector extends EventEmitter {
*/
static setMaxObjectsPerThread (value) {
}

/**
* Returns the version of Connector.
*
* This static method provides the build IDs of the native libraries being used
* by Connector, as well as the version of the Connector API.
*
* .. note::
* This is a static method. It can be called before creating a
* :class:`Connector` instance.
*
* @returns {string} A string containing information about the version of Connector.
*/
static get_version() {
// Obtain version of Connector from package.json
const versionString = require('./package.json').version
// Parse numbers out of string
const versionNumbers = versionString.split('.')
// Now get the build IDs of the native libraries
const nativeConnectorVersion = ref.alloc('char *')
const nativeCoreCVersion = ref.alloc('char *')
_checkRetcode(connectorBinding.api.RTI_Connector_get_build_versions(
nativeCoreCVersion,
nativeConnectorVersion))

// Now create the string containing all of the above information
let versionStr = "RTI Connector for JavaScript, version "
+ versionNumbers[0] + "." + versionNumbers[1] + "." + versionNumbers[2] + "\n"
versionStr += ref.readCString(nativeCoreCVersion.deref()) + "\n"
versionStr += ref.readCString(nativeConnectorVersion.deref())
return versionStr
}
}

// Export the API
Expand Down
23 changes: 23 additions & 0 deletions test/nodejs/test_rticonnextdds_connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@ describe('Connector Tests', function () {
expect(connector).to.be.instanceOf(rti.Connector)
})

it('is possible to obtain the current version of Connector', function () {
const version = rti.Connector.get_version()
expect(version).to.be.a.string

// The returned version string should contain four pieces of information:
// - the API version of Connector
// - the build ID of core.1.0
// - the build ID of dds_c.1.0
// - the build ID of lua_binding.1.0
// Expect "RTI Connector for JavaScript, version X.X.X"
let regex = /RTI Connector for JavaScript, version ([0-9][.]){2}[0-9]/
expect(regex.test(version)).deep.equals(true)
// Expect "NDDSCORE_BUILD_<VERSION>_<DATE>T<TIMESTAMP>Z"
regex = /.*NDDSCORE_BUILD_([0-9][.]){2}[0-9]_[0-9]{8}T[0-9]{6}Z/
expect(regex.test(version)).deep.equals(true)
// Expect "NDDSC_BUILD_<VERSION>_<DATE>T<TIMESTAMP>Z"
regex = /.*NDDSC_BUILD_([0-9][.]){2}[0-9]_[0-9]{8}T[0-9]{6}Z/
expect(regex.test(version)).deep.equals(true)
// Expect "RTICONNECTOR_BUILD_<VERSION>_<DATE>T<TIMESTAMP>Z"
regex = /.*RTICONNECTOR_BUILD_([0-9][.]){2}[0-9]_[0-9]{8}T[0-9]{6}Z/
expect(regex.test(version)).deep.equals(true)
})

// Test for CON-200
it('Connector should not segfault if deleted twice', async function () {
const xmlProfile1 = path.join(__dirname, '/../xml/TestConnector.xml')
Expand Down