summaryrefslogtreecommitdiffstats
path: root/test/codec_arraybuffer_test.js
diff options
context:
space:
mode:
authorSteve Thomas <Sc00bz@users.noreply.github.com>2015-11-01 14:36:28 -0600
committerSteve Thomas <Sc00bz@users.noreply.github.com>2015-11-01 14:36:28 -0600
commitdb7e40d449ab4ae65bacf267b38d1bf836b4fe54 (patch)
treef6f815673f56490c8ae3bfdc8ed9a5f4d9996f76 /test/codec_arraybuffer_test.js
parent025908ef2b091faab75f60188654f789b691ff0d (diff)
parentf9a2494fae0dcddef493de453aa6ab69caa987cf (diff)
downloadsjcl-db7e40d449ab4ae65bacf267b38d1bf836b4fe54.zip
sjcl-db7e40d449ab4ae65bacf267b38d1bf836b4fe54.tar.gz
sjcl-db7e40d449ab4ae65bacf267b38d1bf836b4fe54.tar.bz2
Merge pull request #1 from bitwiseshiftleft/master
Update
Diffstat (limited to 'test/codec_arraybuffer_test.js')
-rw-r--r--test/codec_arraybuffer_test.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/codec_arraybuffer_test.js b/test/codec_arraybuffer_test.js
new file mode 100644
index 0000000..a88f518
--- /dev/null
+++ b/test/codec_arraybuffer_test.js
@@ -0,0 +1,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();
+}); \ No newline at end of file