01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * Portions Copyrighted 2007 Sun Microsystems, Inc.
16: */
17: package org.netbeans.modules.db.util;
18:
19: import java.io.File;
20: import java.io.FileOutputStream;
21: import java.io.PrintWriter;
22: import java.io.Serializable;
23: import java.net.MalformedURLException;
24: import java.net.URL;
25: import junit.framework.TestCase;
26:
27: public class Base64Test extends TestCase {
28:
29: public Base64Test(String testName) {
30: super (testName);
31: }
32:
33: public void testEncodeBytes() throws Exception {
34: byte[] orig = "GumbyAndPokey".getBytes("UTF-8");
35:
36: String encoded = Base64.byteArrayToBase64(orig);
37:
38: byte[] decoded = Base64.base64ToByteArray(encoded);
39:
40: assertByteArrayEquals(orig, decoded);
41: }
42:
43: public void testAlternate() throws Exception {
44: byte[] orig = "GumbyAndPokey".getBytes("UTF-8");
45:
46: String encoded = Base64.byteArrayToAltBase64(orig);
47:
48: byte[] decoded = Base64.altBase64ToByteArray(encoded);
49:
50: assertByteArrayEquals(orig, decoded);
51: }
52:
53: private static void assertByteArrayEquals(byte[] a, byte[] b) {
54: if (a == null) {
55: assertTrue(b == null);
56: }
57:
58: assertEquals(a.length, b.length);
59:
60: for (int i = 0; i < a.length; i++) {
61: assertEquals(a[i], b[i]);
62: }
63: }
64:
65: }
|