diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-20 06:01:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-11-20 06:19:39 +0000 |
commit | 56eec1de7018759c0ec251dba4455c18f73c3bbd (patch) | |
tree | 3aeb2d10356530bc2cc3f24e74f41048a13885b4 /tests/zsubpacket.js | |
parent | Initial commit. (diff) | |
download | zmodemjs-upstream/0.1.10+dfsg.tar.xz zmodemjs-upstream/0.1.10+dfsg.zip |
Adding upstream version 0.1.10+dfsg.upstream/0.1.10+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | tests/zsubpacket.js | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/zsubpacket.js b/tests/zsubpacket.js new file mode 100755 index 0000000..eaf1624 --- /dev/null +++ b/tests/zsubpacket.js @@ -0,0 +1,62 @@ +#!/usr/bin/env node + +"use strict"; + +const tape = require('blue-tape'); + +const testhelp = require('./lib/testhelp'); + +global.Zmodem = require('./lib/zmodem'); + +var zdle = new Zmodem.ZDLE( { escape_ctrl_chars: true } ); + +tape('build, encode, parse', function(t) { + let content = [1, 2, 3, 4]; + + ["end_ack", "no_end_ack", "end_no_ack", "no_end_no_ack"].forEach( end => { + var header = Zmodem.Subpacket.build( content, end ); + + t.deepEquals( + header.get_payload(), + content, + `${end}: get_payload()` + ); + + t.is( + header.frame_end(), + !/no_end/.test(end), + `${end}: frame_end()` + ); + + t.is( + header.ack_expected(), + !/no_ack/.test(end), + `${end}: ack_expected()` + ); + + [16, 32].forEach( crclen => { + var encoded = header["encode" + crclen](zdle); + var parsed = Zmodem.Subpacket["parse" + crclen](encoded); + + t.deepEquals( + parsed.get_payload(), + content, + `${end}, CRC${crclen} rount-trip: get_payload()` + ); + + t.is( + parsed.frame_end(), + header.frame_end(), + `${end}, CRC${crclen} rount-trip: frame_end()` + ); + + t.is( + parsed.ack_expected(), + header.ack_expected(), + `${end}, CRC${crclen} rount-trip: ack_expected()` + ); + } ); + } ); + + t.end(); +} ); |