|
16 | 16 |
|
17 | 17 | const assert = require('assert'); |
18 | 18 | const rclnodejs = require('../index.js'); |
| 19 | +const rclnodejsNative = require('../lib/native_loader.js'); |
19 | 20 | const DistroUtils = require('../lib/distro.js'); |
20 | 21 | const sinon = require('sinon'); |
21 | 22 |
|
@@ -222,6 +223,39 @@ describe('rclnodejs Timer class testing', function () { |
222 | 223 | rclnodejs.spin(node); |
223 | 224 | }); |
224 | 225 |
|
| 226 | + it('timer callback preserves zero arguments when TimerInfo is unavailable', function (done) { |
| 227 | + const originalFunc = rclnodejsNative.callTimerWithInfo; |
| 228 | + |
| 229 | + try { |
| 230 | + Object.defineProperty(rclnodejsNative, 'callTimerWithInfo', { |
| 231 | + value: undefined, |
| 232 | + configurable: true, |
| 233 | + writable: true, |
| 234 | + }); |
| 235 | + } catch (e) { |
| 236 | + this.skip(); |
| 237 | + return; |
| 238 | + } |
| 239 | + |
| 240 | + const timer = node.createTimer(TIMER_INTERVAL, function () { |
| 241 | + try { |
| 242 | + assert.strictEqual(arguments.length, 0); |
| 243 | + timer.cancel(); |
| 244 | + done(); |
| 245 | + } finally { |
| 246 | + try { |
| 247 | + Object.defineProperty(rclnodejsNative, 'callTimerWithInfo', { |
| 248 | + value: originalFunc, |
| 249 | + configurable: true, |
| 250 | + writable: true, |
| 251 | + }); |
| 252 | + } catch (e) {} |
| 253 | + } |
| 254 | + }); |
| 255 | + |
| 256 | + rclnodejs.spin(node); |
| 257 | + }); |
| 258 | + |
225 | 259 | it('timer.setOnResetCallback', function (done) { |
226 | 260 | if (DistroUtils.getDistroId() <= DistroUtils.getDistroId('humble')) { |
227 | 261 | this.skip(); |
@@ -382,4 +416,15 @@ describe('rclnodejs Timer class coverage testing', function () { |
382 | 416 | node.createTimer(TIMER_INTERVAL, () => {}, { autostart: 'false' }); |
383 | 417 | }, /options\.autostart/); |
384 | 418 | }); |
| 419 | + |
| 420 | + it('native createTimer validates autostart argument type', function () { |
| 421 | + assert.throws(() => { |
| 422 | + rclnodejsNative.createTimer( |
| 423 | + node.getClock().handle, |
| 424 | + node.context.handle, |
| 425 | + TIMER_INTERVAL, |
| 426 | + 'false' |
| 427 | + ); |
| 428 | + }, /Timer autostart must be a boolean/); |
| 429 | + }); |
385 | 430 | }); |
0 commit comments