Merge commit '42b2e5ca519766e37ce6941ba4faecc9691cc403' into upstream
[debian/openrocket] / core / test / net / sf / openrocket / util / Base64Test.java
diff --git a/core/test/net/sf/openrocket/util/Base64Test.java b/core/test/net/sf/openrocket/util/Base64Test.java
new file mode 100644 (file)
index 0000000..edf1300
--- /dev/null
@@ -0,0 +1,42 @@
+package net.sf.openrocket.util;
+
+import java.util.Arrays;
+import java.util.Random;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class Base64Test {
+
+       @Test
+       public void oldMainTest() throws Exception {
+
+               // TODO - this test case should probably be less random and more targeted to
+               // special cases such as:
+               // null input
+               // empty input
+               // decoding bad string
+               
+               Random rnd = new Random();
+
+               for (int round=0; round < 1000; round++) {
+                       int n = rnd.nextInt(1000);
+                       n = 100000;
+
+                       byte[] array = new byte[n];
+                       rnd.nextBytes(array);
+
+                       String encoded = Base64.encode(array);
+
+                       byte[] decoded = null;
+                       decoded = Base64.decode(encoded);
+
+                       if (!Arrays.equals(array, decoded)) {
+                               fail("Data differs!  n="+n);
+                       }
+                       System.out.println("n="+n+" ok!");
+
+               }
+       }
+}
\ No newline at end of file