|
From: <pe...@us...> - 2004-01-19 23:49:32
|
Update of /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/crypto
In directory sc8-pr-cvs1:/tmp/cvs-serv9201/src/test/org/neuclear/commons/crypto
Modified Files:
Base32Tests.java
Log Message:
Unit testing uncovered further issues with Base32
NSTools is now uptodate as are many other classes. All transactional builders habe been updated.
Well on the way towards full "green" on Junit.
Index: Base32Tests.java
===================================================================
RCS file: /cvsroot/neuclear/neuclear-commons/src/test/org/neuclear/commons/crypto/Base32Tests.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** Base32Tests.java 19 Jan 2004 17:53:14 -0000 1.3
--- Base32Tests.java 19 Jan 2004 23:49:29 -0000 1.4
***************
*** 23,26 ****
--- 23,31 ----
$Id$
$Log$
+ Revision 1.4 2004/01/19 23:49:29 pelle
+ Unit testing uncovered further issues with Base32
+ NSTools is now uptodate as are many other classes. All transactional builders habe been updated.
+ Well on the way towards full "green" on Junit.
+
Revision 1.3 2004/01/19 17:53:14 pelle
Various clean ups
***************
*** 45,49 ****
}
! public void testBase32() throws CryptoException {
assertEquals(32,Base32.encode(CryptoTools.digest("hello")).length());
assertEquals(8,Base32.encode("hello").length());
--- 50,54 ----
}
! public void testLength() throws CryptoException {
assertEquals(32,Base32.encode(CryptoTools.digest("hello")).length());
assertEquals(8,Base32.encode("hello").length());
***************
*** 55,67 ****
assertEquals(18,Base32.encode("hello123456").length());
for (int i=0;i<TESTSTRINGS.length;i++){
// System.out.print("Encoding: "+TESTSTRINGS[i]+" ...");
final String encoded = Base32.encode(TESTSTRINGS[i]);
// System.out.println(" ->"+encoded);
! assertEquals(TESTSTRINGS[i],new String(Base32.decode(encoded)));
}
}
static final String TESTSTRINGS[] =new String[]{
! // "",
"0",
"01",
--- 60,121 ----
assertEquals(18,Base32.encode("hello123456").length());
+ }
+ public void testBase32Codec() throws CryptoException {
+
for (int i=0;i<TESTSTRINGS.length;i++){
// System.out.print("Encoding: "+TESTSTRINGS[i]+" ...");
final String encoded = Base32.encode(TESTSTRINGS[i]);
// System.out.println(" ->"+encoded);
! assertEquals("TESTSTRINGS["+i+"]",TESTSTRINGS[i].getBytes(),Base32.decode(encoded));
! }
! }
!
! public void testSHABase32() throws CryptoException {
! for (int i=0;i<TESTSTRINGS.length;i++){
! // System.out.print("Encoding: "+TESTSTRINGS[i]+" ...");
! final String hash = com.waterken.url.Base32.encode(CryptoTools.digest(TESTSTRINGS[i]));
! assertEquals(32, hash.length());
! // System.out.println(" ->"+hash);
! assertTrue("TESTSTRINGS["+i+"]",CryptoTools.equalByteArrays(CryptoTools.digest(TESTSTRINGS[i]),Base32.decode(hash)));
! }
! }
! public void testSHABase32vsTyler() throws CryptoException {
! for (int i=0;i<TESTSTRINGS.length;i++){
! // System.out.print("Encoding: "+TESTSTRINGS[i]+" ...");
! final String hash = com.waterken.url.Base32.encode(CryptoTools.digest(TESTSTRINGS[i]));
! assertEquals(32, hash.length());
! // System.out.println(" ->"+hash);
! assertTrue("TESTSTRINGS["+i+"]",CryptoTools.equalByteArrays(CryptoTools.digest(TESTSTRINGS[i]),Base32.decode(hash)));
}
}
+
+ public void testBase32vsTyler() throws CryptoException {
+
+ for (int i=0;i<TESTSTRINGS.length;i++){
+ // System.out.print("Encoding: "+TESTSTRINGS[i]+" ...");
+ final String encoded = Base32.encode(TESTSTRINGS[i]);
+ // System.out.println(" ->"+encoded);
+ assertEquals("TESTSTRINGS["+i+"]",com.waterken.url.Base32.encode(TESTSTRINGS[i].getBytes()),encoded);
+ }
+ }
+
+ public void testDecodeTyler() throws CryptoException {
+
+ for (int i=0;i<TESTSTRINGS.length;i++){
+ // System.out.print("Encoding: "+TESTSTRINGS[i]+" ...");
+ // final String encoded = Base32.encode(TESTSTRINGS[i]);
+ // System.out.println(" ->"+encoded);
+ final byte decoded[] = Base32.decode(com.waterken.url.Base32.encode(TESTSTRINGS[i].getBytes()));
+ assertEquals("TESTSTRINGS["+i+"]",TESTSTRINGS[i].getBytes(),decoded);
+ }
+ }
+ public void assertEquals(String description,byte a[],byte b[]) {
+ assertEquals(description+" length",a.length,b.length);
+ for (int i=0;i<a.length;i++)
+ assertEquals(description+"["+i+"]",a[i],b[i]);
+
+ }
static final String TESTSTRINGS[] =new String[]{
! "",
"0",
"01",
***************
*** 75,78 ****
--- 129,135 ----
"0123456789",
"0123456789A",
+ "0123456789A0123456789As0123456789A",
+ new String(CryptoTools.digest("0123456"))
+
};
|