-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_eibd.js
104 lines (98 loc) · 2.71 KB
/
test_eibd.js
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
var assert = require('assert'),
eibd = require('../main');
var port = 6721
var opts = { host: 'localhost', port: port }
var TestServer = new require('./support/server');
var server = null;
describe('EIBConnection', function() {
beforeEach(function(done) {
server = new TestServer(port, function() {
done();
});
});
afterEach(function(done) {
server.end();
done();
});
describe('socketRemote', function() {
it('should open a connection', function(done) {
var conn = new eibd();
conn.socketRemote(opts, function() {
assert.equal(true, true);
done();
});
}),
it('should catch error if server is not reachable', function(done) {
server.end();
var conn = new eibd();
conn.socketRemote(opts, function(err) {
assert.equal(err.code, 'ECONNREFUSED');
server = new TestServer(port);
done();
});
}),
it('should notice if host or port is not given', function(done) {
var conn = new eibd();
try {
conn.socketRemote(port);
} catch(err) {
assert.equal(true, err instanceof Error);
done();
}
});
}),
describe('openTGroup', function() {
it('should work without error', function(done) {
var conn = new eibd();
conn.socketRemote(opts, function() {
var dest = conn.str2addr('0/1/0');
conn.openTGroup(dest, 0, function(err) {
assert.equal(null, err);
done();
});
});
})
}),
describe('sendAPDU', function() {
it('should work without error', function(done) {
var conn = new eibd();
conn.socketRemote(opts, function() {
conn.sendAPDU([0,0],function(err) {
assert.equal(undefined, err);
done();
});
});
});
}),
describe('sendRequest', function() {
it('should work without error', function(done) {
var conn = new eibd();
conn.socketRemote(opts, function() {
conn.sendRequest([0,0],function(err) {
assert.equal(undefined, err);
done();
});
});
});
}),
describe('openGroupSocket', function() {
it('should get called three times', function(done) {
var conn = new eibd();
conn.socketRemote(opts, function() {
var i = 0;
conn.openGroupSocket(0, function(action, src, dest, val) {
i++;
if(i === 2) done();
});
});
// send command for socket listen
var groupswrite = new eibd();
groupswrite.socketRemote(opts, function() {
var dest = conn.str2addr('0/1/0');
groupswrite.openTGroup(dest, 1, function(err) {
groupswrite.sendAPDU([0, 0xff&1]);
});
});
})
})
});