aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2014-01-06 10:42:52 +0100
committerJiri Vanek <[email protected]>2014-01-06 10:42:52 +0100
commit3261e3454f94f66082d97c2ba8a10cbe603dcc01 (patch)
treed67fd0172b61b28a32349b84caefd77c126a1679 /tests
parent627fcfb530c25c5ca05be55042bdc841d7f27aa4 (diff)
Removed depndence on sun.misc.BASE64Decoder
Diffstat (limited to 'tests')
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64DecoderTest.java99
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java30
2 files changed, 118 insertions, 11 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64DecoderTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64DecoderTest.java
new file mode 100644
index 0000000..8c98146
--- /dev/null
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64DecoderTest.java
@@ -0,0 +1,99 @@
+/* BASE64EncoderTest.java
+Copyright (C) 2011 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as published by
+the Free Software Foundation, version 2.
+
+IcedTea 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
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version.
+ */
+package net.sourceforge.jnlp.util.replacements;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import org.junit.Assert;
+import org.junit.Test;
+
+/** Test various corner cases of the parser */
+public class BASE64DecoderTest {
+
+ private static final String sunClassE = "sun.misc.BASE64Encoder";
+
+ @Test
+ public void testEmbededBase64Decoder() throws Exception {
+ final byte[] data = BASE64EncoderTest.encoded;
+ ByteArrayOutputStream out2 = new ByteArrayOutputStream();
+ BASE64Decoder e2 = new BASE64Decoder();
+ e2.decodeBuffer(new ByteArrayInputStream(data), out2);
+ byte[] decoded = out2.toByteArray();
+ Assert.assertEquals(BASE64EncoderTest.sSrc, new String(decoded, "utf-8"));
+
+
+
+ }
+
+ @Test
+ /*
+ * This test will fail, in case taht sun.misc.BASE64Encoder will be removed from builders java
+ */
+ public void testEmbededBase64DecoderAgainstSunOne() throws Exception {
+ final byte[] data = BASE64EncoderTest.encoded;
+ ByteArrayOutputStream out2 = new ByteArrayOutputStream();
+ BASE64Decoder e2 = new BASE64Decoder();
+ e2.decodeBuffer(new ByteArrayInputStream(data), out2);
+ byte[] encoded2 = out2.toByteArray();
+ Object encoder = BASE64EncoderTest.createInsatnce(sunClassE);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ BASE64EncoderTest.getAndInvokeMethod(encoder, "encodeBuffer", encoded2, out);
+ Assert.assertArrayEquals(data, out.toByteArray());
+ Assert.assertArrayEquals(BASE64EncoderTest.encoded, out.toByteArray());
+
+ }
+
+ @Test
+ public void testEmbededBase64DecoderAgainstEmbededEncoder() throws Exception {
+ final byte[] data = BASE64EncoderTest.encoded;
+ ByteArrayOutputStream out2 = new ByteArrayOutputStream();
+ BASE64Decoder e2 = new BASE64Decoder();
+ e2.decodeBuffer(new ByteArrayInputStream(data), out2);
+ byte[] encoded2 = out2.toByteArray();
+ BASE64Encoder encoder = new BASE64Encoder();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ encoder.encodeBuffer(encoded2, out);
+ Assert.assertArrayEquals(data, out.toByteArray());
+ Assert.assertArrayEquals(BASE64EncoderTest.encoded, out.toByteArray());
+
+ }
+
+
+}
diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java
index 27ee230..7febee2 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/replacements/BASE64EncoderTest.java
@@ -48,10 +48,10 @@ import org.junit.Test;
/** Test various corner cases of the parser */
public class BASE64EncoderTest {
- private static final String sSrc = "abcdefgHIJKLMNOPQrstuvwxyz1234567890\r\n"
+ static final String sSrc = "abcdefgHIJKLMNOPQrstuvwxyz1234567890\r\n"
+ "-=+_))(**&&&^^%%$$##@@!!~{}][\":'/\\.,><\n"
+ "+ěšěčřžýáíé=ů/úěřťšďňéíáč";
- private static final byte[] encoded = {89, 87, 74, 106, 90, 71, 86, 109, 90,
+ static final byte[] encoded = {89, 87, 74, 106, 90, 71, 86, 109, 90,
48, 104, 74, 83, 107, 116, 77, 84, 85, 53, 80, 85, 70, 70, 121, 99, 51,
82, 49, 100, 110, 100, 52, 101, 88, 111, 120, 77, 106, 77, 48, 78, 84,
89, 51, 79, 68, 107, 119, 68, 81, 111, 116, 80, 83, 116, 102, 75, 83,
@@ -63,8 +63,7 @@ public class BASE64EncoderTest {
69, 109, 56, 87, 90, 120, 97, 88, 70, 111, 99, 83, 80, 10, 120, 89, 106,
68, 113, 99, 79, 116, 119, 54, 72, 69, 106, 81, 61, 61, 10};
- public static final String sunClassE = "sun.misc.BASE64Encoder";
- public static final String sunClassD = "sun.misc.BASE64Decoder";
+ private static final String sunClassD = "sun.misc.BASE64Decoder";
@Test
public void testEmbededBase64Encoder() throws Exception {
@@ -97,23 +96,32 @@ public class BASE64EncoderTest {
e2.encodeBuffer(data, out2);
byte[] encoded2 = out2.toByteArray();
Object decoder = createInsatnce(sunClassD);
- byte[] decoded = (byte[]) (getAndInvokeMethod(decoder, "decodeBuffer", new String(encoded, "utf-8")));
+ byte[] decoded = (byte[]) (getAndInvokeMethod(decoder, "decodeBuffer", new String(encoded2, "utf-8")));
+ Assert.assertArrayEquals(data, decoded);
+ Assert.assertEquals(sSrc, new String(decoded, "utf-8"));
+ }
+
+ @Test
+ public void testEmbededBase64EncoderAgainstEbededDecoder() throws Exception {
+ final byte[] data = sSrc.getBytes("utf-8");
+ ByteArrayOutputStream out2 = new ByteArrayOutputStream();
+ BASE64Encoder e2 = new BASE64Encoder();
+ e2.encodeBuffer(data, out2);
+ byte[] encoded2 = out2.toByteArray();
+ BASE64Decoder decoder = new BASE64Decoder();
+ byte[] decoded = decoder.decodeBuffer(new String(encoded2, "utf-8"));
Assert.assertArrayEquals(data, decoded);
Assert.assertEquals(sSrc, new String(decoded, "utf-8"));
-
-
-
-
}
- private static Object createInsatnce(String ofCalss) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
+ static Object createInsatnce(String ofCalss) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
Class<?> classDefinition = Class.forName(ofCalss);
return classDefinition.newInstance();
}
- private static Object getAndInvokeMethod(Object instance, String methodName, Object... params) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+ static Object getAndInvokeMethod(Object instance, String methodName, Object... params) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Class<?>[] cs = new Class<?>[params.length];
for (int i = 0; i < params.length; i++) {
Object object = params[i];