Author: j16sdiz
Date: 2008-04-11 11:39:43 +0000 (Fri, 11 Apr 2008)
New Revision: 19175

Modified:
   trunk/freenet/src/freenet/support/Base64.java
   trunk/freenet/test/freenet/support/Base64Test.java
Log:
move unit test to where it belongs


Modified: trunk/freenet/src/freenet/support/Base64.java
===================================================================
--- trunk/freenet/src/freenet/support/Base64.java       2008-04-11 11:22:59 UTC 
(rev 19174)
+++ trunk/freenet/src/freenet/support/Base64.java       2008-04-11 11:39:43 UTC 
(rev 19175)
@@ -19,33 +19,6 @@
  */
 public class Base64
 {
-    // Unit test
-  public static void main(String[] args)
-    throws IllegalBase64Exception
-  {
-    int iter;
-    Random r = new Random();
-    for (iter = 0; iter < 1000; iter++) {
-      byte[] b = new byte[r.nextInt(64)];
-      for (int i = 0; i < b.length; i++)
-        b[i] = (byte) (r.nextInt(256));
-      String encoded = encode(b);
-     System.out.println(encoded);
-      byte[] decoded = decode(encoded);
-      if (decoded.length != b.length) {
-        System.out.println("length mismatch");
-        return;
-      }
-      for (int i = 0; i < b.length; i++)
-        if (b[i] != decoded[i]) {
-          System.out.println("data mismatch: index "+i+" of "+b.length+" 
should be 0x"+Integer.toHexString(b[i] & 0xFF)+
-            " was 0x"+Integer.toHexString(decoded[i] & 0xFF));
-          return;
-        }
-    }
-    System.out.println("passed "+iter+" tests");
-  }
-
   private static char[] base64Alphabet = {
     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
     'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',

Modified: trunk/freenet/test/freenet/support/Base64Test.java
===================================================================
--- trunk/freenet/test/freenet/support/Base64Test.java  2008-04-11 11:22:59 UTC 
(rev 19174)
+++ trunk/freenet/test/freenet/support/Base64Test.java  2008-04-11 11:39:43 UTC 
(rev 19175)
@@ -18,6 +18,7 @@

 import junit.framework.TestCase;
 import java.util.Arrays;
+import java.util.Random;

 /**
  * Test case for {@link freenet.support.Base64} class.
@@ -156,4 +157,27 @@
                catch (IllegalBase64Exception exception) {
                        assertSame("illegal Base64 
length",exception.getMessage()); }
        }
+       
+       /**
+        * Random test
+        * 
+        * @throws IllegalBase64Exception
+        */
+       public void testRandom() throws IllegalBase64Exception {
+               int iter;
+               Random r = new Random();
+               for (iter = 0; iter < 1000; iter++) {
+                       byte[] b = new byte[r.nextInt(64)];
+                       for (int i = 0; i < b.length; i++)
+                               b[i] = (byte) (r.nextInt(256));
+                       String encoded = Base64.encode(b);
+                       byte[] decoded = Base64.decode(encoded);
+                       assertEquals("length mismatch", decoded.length, 
b.length);
+
+                       for (int i = 0; i < b.length; i++)
+                               assertEquals("data mismatch: index " + i + " of 
" + b.length + " should be 0x"
+                                       + Integer.toHexString(b[i] & 0xFF) + " 
was 0x" + Integer.toHexString(decoded[i] & 0xFF), b[i],
+                                       decoded[i]);
+               }
+       }
 }
\ No newline at end of file


Reply via email to