|
| 1 | +var withService = require('./with-service'); |
| 2 | +var tap = require('tap'); |
| 3 | +var DBus = require('../'); |
| 4 | + |
| 5 | +tap.plan(4); |
| 6 | +withService('service-dynamic.js', function(err, done) { |
| 7 | + if (err) throw err; |
| 8 | + |
| 9 | + var dbus = new DBus(); |
| 10 | + var bus = dbus.getBus('session'); |
| 11 | + var process = done.process; |
| 12 | + |
| 13 | + addObject(process, '1', function() { |
| 14 | + checkInterface(bus, '1', function(err, result) { |
| 15 | + tap.equal(result, true); |
| 16 | + checkInterface(bus, '2', function(err, result) { |
| 17 | + tap.equal(result, false); |
| 18 | + addObject(process, '2', function() { |
| 19 | + checkInterface(bus, '2', function(err, result) { |
| 20 | + tap.equal(result, true); |
| 21 | + removeObject(process, '2', function() { |
| 22 | + checkInterface(bus, '2', function(err, result) { |
| 23 | + tap.equal(result, false); |
| 24 | + done(); |
| 25 | + }); |
| 26 | + }); |
| 27 | + }); |
| 28 | + }); |
| 29 | + }); |
| 30 | + }); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +function addObject(process, value, callback) { |
| 35 | + process.once('message', function() { |
| 36 | + callback(); |
| 37 | + }); |
| 38 | + process.send({ type: 'add', value: value }); |
| 39 | +} |
| 40 | + |
| 41 | +function removeObject(process, value, callback) { |
| 42 | + process.once('message', function() { |
| 43 | + callback(); |
| 44 | + }); |
| 45 | + process.send({ type: 'remove', value: value }); |
| 46 | +} |
| 47 | + |
| 48 | +function checkInterface(bus, value, callback) { |
| 49 | + value = value.toString(); |
| 50 | + bus.getInterface('test.dbus.DynamicTestService', '/test/dbus/DynamicTestService/subs/' + value, 'test.dbus.DynamicTestService.DynamicInterface1', function(err, iface) { |
| 51 | + if (!err) { |
| 52 | + // We might have the interface cached. Let's actually |
| 53 | + // try to get a property. |
| 54 | + iface.getProperty('Value', function(err, result) { |
| 55 | + if (!err) { |
| 56 | + return callback(null, true); |
| 57 | + } |
| 58 | + if (/UnknownMethod/.test(err.message)) { |
| 59 | + // This object doesn't exist. We're good. |
| 60 | + return callback(null, false); |
| 61 | + } |
| 62 | + return callback(err); |
| 63 | + }); |
| 64 | + return; |
| 65 | + } |
| 66 | + if (/interface/.test(err.message)) { |
| 67 | + return callback(null, false); |
| 68 | + } |
| 69 | + callback(err); |
| 70 | + }); |
| 71 | +} |
| 72 | + |
0 commit comments