forked from BiancoRoyal/node-bacstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice-atomic-read-file.spec.js
More file actions
57 lines (52 loc) · 1.96 KB
/
Copy pathservice-atomic-read-file.spec.js
File metadata and controls
57 lines (52 loc) · 1.96 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
'use strict';
const expect = require('chai').expect;
const utils = require('./utils');
const baServices = require('../../lib/services');
describe('bacnet - Services layer AtomicReadFile unit', () => {
it('should successfully encode and decode as stream', () => {
const buffer = utils.getBuffer();
baServices.atomicReadFile.encode(buffer, true, {type: 13, instance: 5000}, -50, 12);
const result = baServices.atomicReadFile.decode(buffer.buffer, 0);
delete result.len;
expect(result).to.deep.equal({
objectId: {type: 13, instance: 5000},
count: 12,
isStream: true,
position: -50
});
});
it('should successfully encode and decode as non-stream', () => {
const buffer = utils.getBuffer();
baServices.atomicReadFile.encode(buffer, false, {type: 14, instance: 5001}, 60, 13);
const result = baServices.atomicReadFile.decode(buffer.buffer, 0);
delete result.len;
expect(result).to.deep.equal({
objectId: {type: 14, instance: 5001},
count: 13,
isStream: false,
position: 60
});
});
});
describe('AtomicReadFileAcknowledge', () => {
it('should successfully encode and decode as stream', () => {
const buffer = utils.getBuffer();
baServices.atomicReadFile.encodeAcknowledge(buffer, true, false, 0, 90, [[12, 12, 12]], [3]);
const result = baServices.atomicReadFile.decodeAcknowledge(buffer.buffer, 0);
delete result.len;
expect(result).to.deep.equal({
isStream: true,
position: 0,
endOfFile: false,
buffer: Buffer.from([12, 12, 12])
});
});
it('should successfully encode and decode as non-stream', () => {
const buffer = utils.getBuffer();
baServices.atomicReadFile.encodeAcknowledge(buffer, false, false, 0, 90, [12, 12, 12], 3);
// TODO: AtomicReadFileAcknowledge as non-stream not yet implemented
expect(() => {
baServices.atomicReadFile.decodeAcknowledge(buffer.buffer, 0);
}).to.throw('NotImplemented');
});
});