aboutsummaryrefslogtreecommitdiffstats
path: root/tests/netx/unit/net/sourceforge/jnlp
diff options
context:
space:
mode:
authorOmair Majid <[email protected]>2012-03-22 13:12:44 -0400
committerOmair Majid <[email protected]>2012-03-22 13:12:44 -0400
commit554326d2e7207e1ecab10a6c5bdd8bde6bbf0307 (patch)
treec59c27f5688289e5bc897fb5f8cb1b3432182f66 /tests/netx/unit/net/sourceforge/jnlp
parente1c4e1586266d36cce6e5b075c01ff366063daff (diff)
PR898: signed applications with big jnlp-file doesn't start
JNLPMatcher was using PipedInputStream and PipedOutputStream without threads which was deadlocking on large files. Use ByteArrayOutputStream instead to avoid this.
Diffstat (limited to 'tests/netx/unit/net/sourceforge/jnlp')
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java39
1 files changed, 36 insertions, 3 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java b/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java
index d767343..387f4fc 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPMatcherTest.java
@@ -37,12 +37,13 @@ exception statement from your version.
package net.sourceforge.jnlp;
-import static org.junit.Assert.fail;
-
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import junit.framework.Assert;
+import java.io.StringReader;
+import java.util.Random;
+
+import org.junit.Assert;
import org.junit.Test;
public class JNLPMatcherTest {
@@ -461,4 +462,36 @@ public class JNLPMatcherTest {
fileReader.close();
launchReader.close();
}
+
+ @Test (timeout=1000 /*ms*/)
+ public void testIsMatchDoesNotHangOnLargeData() throws JNLPMatcherException {
+ /* construct an alphabet containing characters 'a' to 'z' */
+ final int ALPHABET_SIZE = 26;
+ char[] alphabet = new char[ALPHABET_SIZE];
+ for (int i = 0; i < ALPHABET_SIZE; i++) {
+ alphabet[i] = (char)('a' + i);
+ }
+ /* generate a long but random string using the alphabet */
+ final Random r = new Random();
+ final int STRING_SIZE = 1024 * 1024; // 1 MB
+ StringBuilder descriptionBuilder = new StringBuilder(STRING_SIZE);
+ for (int i = 0; i < STRING_SIZE; i++) {
+ descriptionBuilder.append(alphabet[r.nextInt(ALPHABET_SIZE)]);
+ }
+ String longDescription = descriptionBuilder.toString();
+
+ String file =
+ "<jnlp>\n" +
+ " <information>\n" +
+ " <title>JNLPMatcher hanges on large file size</title>\n" +
+ " <vendor>IcedTea</vendor>\n" +
+ " <description>" + longDescription + "</description>\n" +
+ " </information>\n" +
+ "</jnlp>\n";
+
+ StringReader reader1 = new StringReader(file);
+ StringReader reader2 = new StringReader(file);
+ JNLPMatcher matcher = new JNLPMatcher(reader1, reader2, false);
+ Assert.assertTrue(matcher.isMatch());
+ }
}