blob: a88f518731f54f2db1d7f598083d7292ec528e96 (
plain)
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
|
new sjcl.test.TestCase("arrayBuffer codec tests", function (cb) {
if (!sjcl.codec.arrayBuffer) {
this.unimplemented();
cb && cb();
return;
}
var test_bytes = [];
var zeropad_hex = function(number){
var hex = number.toString(16);
while ( hex.length%2 != 0 ){
hex = "0"+hex;
}
return hex;
};
for (var i = 0; i <= 0xffff; i++){
test_bytes.push(zeropad_hex(i));
}
var that = this;
test_bytes.map(function(test_byte, index){
var bitArray = sjcl.codec.hex.toBits(test_byte),
arrayBuffer = sjcl.codec.arrayBuffer.fromBits(bitArray, false),
roundTripArrayBuffer = sjcl.codec.arrayBuffer.toBits(arrayBuffer),
roundTripHex = sjcl.codec.hex.fromBits(roundTripArrayBuffer);
if (roundTripHex !== test_byte){
that.fail("Failed test, expected " + roundTripHex + "to be" + test_byte + "(at: " + i + ")");
}
});
cb();
});
|