diff options
author | Nils Kenneweg <nk@ovt.me> | 2014-09-28 12:49:36 +0200 |
---|---|---|
committer | Nils Kenneweg <nk@ovt.me> | 2014-09-28 12:49:36 +0200 |
commit | 1a633153c43fbac8c2f78fd8c50f6e2d8f161388 (patch) | |
tree | e7298cf72c10c1461757b49c59d63d124188afed /test/codec_arraybuffer_test.js | |
parent | 6aeda8e79b284548be57c988d2ff214b3dd3a65c (diff) | |
download | sjcl-1a633153c43fbac8c2f78fd8c50f6e2d8f161388.zip sjcl-1a633153c43fbac8c2f78fd8c50f6e2d8f161388.tar.gz sjcl-1a633153c43fbac8c2f78fd8c50f6e2d8f161388.tar.bz2 |
use sjcl test suite.
Diffstat (limited to 'test/codec_arraybuffer_test.js')
-rw-r--r-- | test/codec_arraybuffer_test.js | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/test/codec_arraybuffer_test.js b/test/codec_arraybuffer_test.js index 3bec743..a88f518 100644 --- a/test/codec_arraybuffer_test.js +++ b/test/codec_arraybuffer_test.js @@ -1,36 +1,37 @@ -//Run using phantomjs, since rhino doesn't support array buffers, and node has an issue with create dataviews with a bytelength of 0 -console.log("Running ArrayBuffer Codec tests"); -var start_time = +(new Date()); +new sjcl.test.TestCase("arrayBuffer codec tests", function (cb) { + if (!sjcl.codec.arrayBuffer) { + this.unimplemented(); + cb && cb(); + return; + } -//This ccm implementation is only defined for IV Lengths of 8 bytes -var test_bytes = []; + var test_bytes = []; -var zeropad_hex = function(number){ - var hex = number.toString(16); - while ( hex.length%2 != 0 ){ - hex = "0"+hex; - } - return hex; -}; + 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)); -} + 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); + 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){ - console.error("Failed test, expected ",roundTripHex,"to be",test_byte); - console.error("Failed at: "+i); - phantom.exit(1); - } -}); + if (roundTripHex !== test_byte){ + that.fail("Failed test, expected " + roundTripHex + "to be" + test_byte + "(at: " + i + ")"); + } + }); -var total_time = parseInt(+(new Date())-start_time); -console.log(" + passed all",test_bytes.length,"tests. ("+ total_time, "ms)");
\ No newline at end of file + cb(); +});
\ No newline at end of file |