Diffstat (limited to 'frontend/gamma/tests/tests/Clipperz/ByteArray.test.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/tests/tests/Clipperz/ByteArray.test.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/gamma/tests/tests/Clipperz/ByteArray.test.js b/frontend/gamma/tests/tests/Clipperz/ByteArray.test.js index 43d74a0..643bbf8 100644 --- a/frontend/gamma/tests/tests/Clipperz/ByteArray.test.js +++ b/frontend/gamma/tests/tests/Clipperz/ByteArray.test.js @@ -1,214 +1,212 @@ /* -Copyright 2008-2011 Clipperz Srl +Copyright 2008-2013 Clipperz Srl -This file is part of Clipperz Community Edition. -Clipperz Community Edition is an online password manager. +This file is part of Clipperz, the online password manager. For further information about its features and functionalities please refer to http://www.clipperz.com. -* Clipperz Community Edition is free software: you can redistribute - it and/or modify it under the terms of the GNU Affero General Public - License as published by the Free Software Foundation, either version - 3 of the License, or (at your option) any later version. +* Clipperz is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. -* Clipperz Community Edition is distributed in the hope that it will - be useful, but WITHOUT ANY WARRANTY; without even the implied - warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +* Clipperz is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. * You should have received a copy of the GNU Affero General Public - License along with Clipperz Community Edition. If not, see - <http://www.gnu.org/licenses/>. + License along with Clipperz. If not, see http://www.gnu.org/licenses/. */ Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); var tests = { //------------------------------------------------------------------------- 'core_tests': function (someTestArgs) { // var deferredResult; // deferredResult = new Clipperz.Async.Deferred("core_tests", someTestArgs); // deferredResult.addCallback(function() { var byteArray; byteArray = new Clipperz.ByteArray(); try { byteArray.checkByteValue(512); is(false, true, "a value greater that a byte (0x200) should have raised an exception - NO Exception"); } catch(e) { // is( e.name, // "Clipperz.ByteArray.exception.InvalidValue", // "appending a value greater that a byte (0x200) should have raised an exception - EXCEPTION HANDLER") ok( /Clipperz\.ByteArray\.exception\.InvalidValue.*/.test(e.name), "appending a value greater that a byte (0x200) should have raised an exception - EXCEPTION HANDLER") }; // }); // deferredResult.callback(); // return deferredResult; }, //------------------------------------------------------------------------- 'basic_tests': function (someTestArgs) { var deferredResult; deferredResult = new Clipperz.Async.Deferred("simple_tests", someTestArgs); deferredResult.addCallback(function() { var byteArray; var byteArray2; var byteArrayIterator; var nextBlock; byteArray = new Clipperz.ByteArray(); is(byteArray.length(), 0, "before adding any element the length is 0"); byteArray.appendByte(10); is(byteArray.length(), 1, "adding a single byte the length == 1"); is(byteArray.byteAtIndex(0), 10, "the first element is correct"); byteArrayIterator = new Clipperz.ByteArrayIterator({byteArray:byteArray, blockSize:(8/8), finalPadding:true}); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock.constructor, Array, "ByteArrayIterator.nextBlock returns an array of byte values"); is(nextBlock.length, 1, "as the block size is 8bit, the returned array has only one element"); is(nextBlock[0], 10, "the element of the returned block is correct"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock, null, "after the last element, the nextBlock returns null"); byteArray = new Clipperz.ByteArray(); byteArray.appendBytes(10, 20, 45, 38); is(byteArray.length(), 4, "Appending more bytes, returns the right length"); is(byteArray.byteAtIndex(0), 10, "and all the elements are right [0]"); is(byteArray.byteAtIndex(1), 20, "and all the elements are right [1]"); is(byteArray.byteAtIndex(2), 45, "and all the elements are right [2]"); is(byteArray.byteAtIndex(3), 38, "and all the elements are right [3]"); byteArray2 = new Clipperz.ByteArray(); byteArray2.appendBytes([10, 20, 45, 38]); is(byteArray.equals(byteArray2), true, "equals method tested with a byteArray created with the same values"); byteArray2 = new Clipperz.ByteArray(); byteArray2.appendBytes([20, 11, 3, 22]); is(byteArray.equals(byteArray2), false, "equals method tested with a byteArray created with different values"); byteArrayIterator = new Clipperz.ByteArrayIterator({byteArray:byteArray, blockSize:(8/8), finalPadding:true}); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock.length, 1, "the size of the block returned by the byteArrayIterator match with the configured blockedSize"); is(nextBlock[0], 10, "the values returned by nextBlock are right [1]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock[0], 20, "the values returned by nextBlock are right [2]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock[0], 45, "the values returned by nextBlock are right [3]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock[0], 38, "the values returned by nextBlock are right [4]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock, null, "after the last block the nextBlock method returns null"); byteArrayIterator = new Clipperz.ByteArrayIterator({byteArray:byteArray, blockSize:(16/8), finalPadding:true}); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock.length, 2, "on the same data, using a different block size, returns the right length"); is(nextBlock[0], 10, "and also the data are fine [1][0]"); is(nextBlock[1], 20, "and also the data are fine [1][1]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock.length, 2, "also the second block size is right"); is(nextBlock[0], 45, "and also the data are fine [2][0]"); is(nextBlock[1], 38, "and also the data are fine [2][1]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock, null, "even with a bigger blockSize, at the end the returned value is null"); byteArray = new Clipperz.ByteArray(11,22,33,44,55,66,77,88,99); is(byteArray.length(), 9, ""); byteArrayIterator = new Clipperz.ByteArrayIterator({byteArray:byteArray, blockSize:(16/8), finalPadding:true}); nextBlock = byteArrayIterator.nextBlock(); nextBlock = byteArrayIterator.nextBlock(); nextBlock = byteArrayIterator.nextBlock(); nextBlock = byteArrayIterator.nextBlock(); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock.length, 2, "the last block of an odd byte array has always the same size"); is(nextBlock[0], 99, "the last element is returned"); is(nextBlock[1], 0, "and a 0 is return for the extra values"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock, null, "even with odd blockSize, after returning all the values, null is returned"); byteArrayIterator = new Clipperz.ByteArrayIterator({byteArray:byteArray, blockSize:(32/8), finalPadding:true}); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock[0], 11, "32 bit blockSize [1][0]"); is(nextBlock[1], 22, "32 bit blockSize [1][1]"); is(nextBlock[2], 33, "32 bit blockSize [1][2]"); is(nextBlock[3], 44, "32 bit blockSize [1][3]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock[0], 55, "32 bit blockSize [2][0]"); is(nextBlock[1], 66, "32 bit blockSize [2][1]"); is(nextBlock[2], 77, "32 bit blockSize [2][2]"); is(nextBlock[3], 88, "32 bit blockSize [2][3]"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock.length, 4, "the last block of an odd byte array has always the same size"); is(nextBlock[0], 99, "the last element is returned (2)"); is(nextBlock[1], 0, "and a 0 is return for the extra values (2.1)"); is(nextBlock[2], 0, "and a 0 is return for the extra values (2.2)"); is(nextBlock[3], 0, "and a 0 is return for the extra values (2.3)"); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock, null, "even with odd blockSize, after returning all the values, null is returned (2)"); byteArray = new Clipperz.ByteArray([11,22,33,44,55,66,77,88,99,100, 111, 122, 133, 144, 155, 166, 177]); byteArrayIterator = new Clipperz.ByteArrayIterator({byteArray:byteArray, blockSize:(128/8), finalPadding:true}); nextBlock = byteArrayIterator.nextBlock(); is(nextBlock.length, 16, "using a blockSize of 128 bit, the nextBlock return a 16 elements array"); byteArray = new Clipperz.ByteArray(); try { byteArray.appendByte(512); is(false, true, "appending a value greater that a byte (0x200) should have raised an exception - NO Exception"); } catch(e) { // is( e.name, // "Clipperz.ByteArray.exception.InvalidValue", // "appending a value greater that a byte (0x200) should have raised an exception - EXCEPTION HANDLER") ok( /Clipperz\.ByteArray\.exception\.InvalidValue.*/.test(e.name), "appending a value greater that a byte (0x200) should have raised an exception - EXCEPTION HANDLER") }; try { byteArray.appendByte(256); is(false, true, "appending a value greater that a byte (0x100) should have raised an exception - NO Exception"); } catch(e) { // is( e.name, // "Clipperz.ByteArray.exception.InvalidValue", // "appending a value greater that a byte (0x100) should have raised an exception - EXCEPTION HANDLER") ok( /Clipperz\.ByteArray\.exception\.InvalidValue.*/.test(e.name), "appending a value greater that a byte (0x100) should have raised an exception - EXCEPTION HANDLER") }; byteArray.appendByte(255); is(byteArray.length(), 1, "appending a value that feets a single byte does not raise any exception"); byteArray = new Clipperz.ByteArray(10, 20, 30, 40, 50); byteArray2 = new Clipperz.ByteArray("0x0a141e2832"); is(byteArray.equals(byteArray2), true, "the hex constructor works fine"); byteArray2 = byteArray.clone(); is(byteArray.equals(byteArray2), true, "the clone method works fine"); }); deferredResult.callback(); return deferredResult; }, //------------------------------------------------------------------------- 'compare_tests': function (someTestArgs) { var deferredResult; deferredResult = new Clipperz.Async.Deferred("compare_tests", someTestArgs); deferredResult.addCallback(function() { var byteArray1; var byteArray2; var result; byteArray1 = new Clipperz.ByteArray("0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", 16); |