dns-suite.js/test/packer.type.a.js

31 lines
709 B
JavaScript

'use strict';
var packer = require('../dns.packer.type.a.js').DNS_PACKER_TYPE_A;
var ab = new ArrayBuffer(4);
var dv = new DataView(ab);
var total;
// just to see that bytes are changed as a marker
dv.setUint32(0x0, 0xDDDDDDDD, false);
[ '0.0.0.0'
, '127.0.0.1'
, '192.168.1.100'
, '216.21.170.44'
, '255.255.255.255'
].forEach(function (ipv4) {
total = 0;
total = packer(ab, dv, total, { address: ipv4 });
if (0x04 !== total) {
console.error('unexpected total ' + total);
process.exit(1);
}
if (ipv4 !== new Uint8Array(ab).join('.')) {
console.error("expected: ", ipv4);
console.error("actual: ", new Uint8Array(ab).join('.'));
process.exit(1);
}
});
console.log('PASS');