On 08/15/2012 06:57 PM, Jiri Vanek wrote:
> On 08/14/2012 05:50 PM, Adam Domurad wrote:
>> On Tue, 2012-08-14 at 17:06 +0200, Jiri Vanek wrote:
>>> This idea should speed up browser tests a lot. When all conditions for pass/failure are done,
>>> browser is terminated and is not waiting for time-out any more.
>>> It is bringing some more load to tester, but its usage is mandatory.
>> Thanks very much for the ideas!
>>
>> It would have been nice if it were like this from the beginning - but
>> nevertheless this would be a great improvement.
>>
>> I'm 100% for converting all tests to this form, and mandating it for
>> future applet tests. I'm sure as the most frequent runner of the test
>> suite you can agree, at least for mandating it for future tests :)
>
> Definitely! I will need some helpt to get it to tests in head ;)
>>
>>>
>>> Usage here is demonstrated on simple applet test.
>>> Any ideas (especially how to avoid doubled "contains" or "matches") welcomed.
>>>
>>> J.
>>>
>>> * tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java: Integrated ClosingListener
>>> speed-up.
>>> * tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java: New file, interface for all
>>> ClosingListeners.
>>> * tests/test-extensions/net/sourceforge/jnlp/CountingClosingListener.java: Implementation of
>>> ClsoingListeners which is storing copy of complete output of program.
>>> * tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java: added (setTimeout) method as
>>> cleanest possibility to terminate process immediately
>>> * tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java: new method (setUpClosingListener)
>>> for setting necessary variables in ClosingListener
>>
>> This method is nice enough, although is it possible to have a
>> standardized way to see if an exception has caused the applet to stop ?
>>
>> I'm very much in favour of adding a clear end marker to the end of tests
>> rather than duplicating contains/matches. If you don't like a hardcoded
>> ending message, then, what if we had a closing listener implementation
>> that takes a single string as an argument, and a string is printed at
>> the end of the applet. Custom closing listeners could always also be
>> created.
>>
>
> I'm little bit against using such a constants (which must be copy pasted into reproducer to complete
> the evil ) but I admit it canhel a lot. But I would recommend to be careful with such a simple
> "terminator" - as exception can be thrown "later".
>
> Anyway some idea how to integrate this is in this updated patch.
>
> I have posted also one more idea to patch, and although it eliminates duplicity, it have quite a lot
> of code :-/.
>
> Both new apporaches shown in AppletTestSigned
>
> thanx for discussion,
>
> J.
>
>
> Ps - I have not tested this new code due to lack of time today so be patient with it. I will do in
> friday. I'm posting it for you to get the feedback for more ideas!
No ideas ? Never mind - debugged version of above attached There was serious error in listeners
(also was caused your listeners in previous reproducer not working). It is included here but I'm
going to fix this separately.
J.
[closingListener_3.diff]
diff -r 04eddc48a74f tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned.html
--- a/tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned.html Tue Aug 14 16:06:38 2012 -0400
+++ b/tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned.html Fri Aug 17 12:14:06 2012 +0200
@@ -37,7 +37,7 @@
-->
<html><head></head><body bgcolor="red">
<p>
- <applet code="AppletTestSigned.class" archive="XslowXAppletTestSigned.jar" codebase="." width="100" height="100">
+ <applet code="AppletTestSigned.class" archive="AppletTestSigned.jar" codebase="." width="100" height="100">
<param name="key1" value="value1">
<param name="key2" value="#value2">
</applet>
diff -r 04eddc48a74f tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned2.html
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/reproducers/signed/AppletTestSigned/resources/AppletTestSigned2.html Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,46 @@
+<!--
+
+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; either version 2, or (at your option)
+any later version.
+
+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.
+
+ -->
+<html><head></head><body bgcolor="red">
+<p>
+ <applet code="AppletTestSigned.class" archive="XslowXAppletTestSigned.jar" codebase="." width="100" height="100">
+ <param name="key1" value="value1">
+ <param name="key2" value="#value2">
+ </applet>
+</p>
+</body>
+</html>
diff -r 04eddc48a74f tests/reproducers/signed/AppletTestSigned/srcs/AppletTestSigned.java
--- a/tests/reproducers/signed/AppletTestSigned/srcs/AppletTestSigned.java Tue Aug 14 16:06:38 2012 -0400
+++ b/tests/reproducers/signed/AppletTestSigned/srcs/AppletTestSigned.java Fri Aug 17 12:14:06 2012 +0200
@@ -48,6 +48,7 @@
try {
Thread.sleep(n);
System.out.println("AppletTestSigned killing himself after " + n + " ms of life");
+ System.out.println("*** APPLET FINISHED ***");
System.exit(0);
} catch (Exception ex) {
}
diff -r 04eddc48a74f tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java
--- a/tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java Tue Aug 14 16:06:38 2012 -0400
+++ b/tests/reproducers/signed/AppletTestSigned/testcases/AppletTestSignedTests.java Fri Aug 17 12:14:06 2012 +0200
@@ -43,6 +43,8 @@
import net.sourceforge.jnlp.browsertesting.BrowserTest;
import net.sourceforge.jnlp.browsertesting.Browsers;
import net.sourceforge.jnlp.annotations.TestInBrowsers;
+import net.sourceforge.jnlp.closinglisteners.Rule;
+import net.sourceforge.jnlp.closinglisteners.RulesFolowingClosingListener;
import org.junit.Assert;
import org.junit.Test;
@@ -50,8 +52,22 @@
public class AppletTestSignedTests extends BrowserTest {
private final List<String> l = Collections.unmodifiableList(Arrays.asList(new String[]{"-Xtrustall"}));
+ private static final String ss = "xception";
+ private static final String s0 = "AppletTestSigned was started";
+ private static final String s1 = "value1";
+ private static final String s2 = "value2";
+ private static final String s3 = "AppletTestSigned was initialised";
+ private static final String s7 = "AppletTestSigned killing himself after 2000 ms of life";
+ private static final RulesFolowingClosingListener.ContainsRule crss = new RulesFolowingClosingListener.ContainsRule(ss);
+ private static final RulesFolowingClosingListener.ContainsRule s0ss = new RulesFolowingClosingListener.ContainsRule(s0);
+ private static final RulesFolowingClosingListener.ContainsRule s1ss = new RulesFolowingClosingListener.ContainsRule(s1);
+ private static final RulesFolowingClosingListener.ContainsRule s2ss = new RulesFolowingClosingListener.ContainsRule(s2);
+ private static final RulesFolowingClosingListener.ContainsRule s3ss = new RulesFolowingClosingListener.ContainsRule(s3);
+ private static final RulesFolowingClosingListener.ContainsRule s7ss = new RulesFolowingClosingListener.ContainsRule(s7);
+ private static final Rule[] okRules = new Rule[]{s0ss, s1ss, s2ss, s3ss, s7ss};
+ private static final Rule[] errorRrules = new Rule[]{crss};
- @Test
+ // @Test
public void AppletTestSignedTest() throws Exception {
ProcessResult pr = server.executeJavawsHeadless(l, "/AppletTestSigned.jnlp");
evaluateSignedApplet(pr, true);
@@ -60,18 +76,12 @@
}
private void evaluateSignedApplet(ProcessResult pr, boolean javawsApplet) {
- String s3 = "AppletTestSigned was initialised";
- Assert.assertTrue("AppletTestSigned stdout should contain " + s3 + " but didn't", pr.stdout.contains(s3));
- String s0 = "AppletTestSigned was started";
- Assert.assertTrue("AppletTestSigned stdout should contain " + s0 + " but didn't", pr.stdout.contains(s0));
- String s1 = "value1";
- Assert.assertTrue("AppletTestSigned stdout should contain " + s1 + " but didn't", pr.stdout.contains(s1));
- String s2 = "value2";
- Assert.assertTrue("AppletTestSigned stdout should contain " + s2 + " but didn't", pr.stdout.contains(s2));
- String ss = "xception";
- Assert.assertFalse("AppletTestSigned stderr should not contain " + ss + " but did", pr.stderr.contains(ss));
- String s7 = "AppletTestSigned killing himself after 2000 ms of life";
- Assert.assertTrue("AppletTestSigned stdout should contain " + s7 + " but didn't", pr.stdout.contains(s7));
+ Assert.assertTrue("AppletTestSigned stdout " + s3ss.toString() + " but didn't", s3ss.evaluate(pr.stdout));
+ Assert.assertTrue("AppletTestSigned stdout " + s0ss.toString() + " but didn't", s0ss.evaluate(pr.stdout));
+ Assert.assertTrue("AppletTestSigned stdout " + s1ss.toString() + " but didn't", s1ss.evaluate(pr.stdout));
+ Assert.assertTrue("AppletTestSigned stdout " + s2ss.toString() + " but didn't", s2ss.evaluate(pr.stdout));
+ Assert.assertFalse("AppletTestSigned stderr " + crss.toNotString() + " but did", crss.evaluate(pr.stderr));
+ Assert.assertTrue("AppletTestSigned stdout " + s7ss.toString() + " but didn't", s7ss.evaluate(pr.stdout));
if (!javawsApplet) {
/*this is working correctly in most browser, but not in all. temporarily disabling
String s4 = "AppletTestSigned was stopped";
@@ -84,15 +94,24 @@
@Test
@TestInBrowsers(testIn = {Browsers.all})
- public void AppletTestSignedFirefoxTest() throws Exception {
+ public void AppletTestSignedFirefoxTestXslowX() throws Exception {
ServerAccess.PROCESS_TIMEOUT = 30 * 1000;
try {
- ProcessResult pr = server.executeBrowser("/AppletTestSigned.html");
+ ProcessResult pr = server.executeBrowser("/AppletTestSigned2.html",new RulesFolowingClosingListener(okRules),new RulesFolowingClosingListener(errorRrules));
evaluateSignedApplet(pr, false);
- Assert.assertTrue(pr.wasTerminated);
+ //Assert.assertTrue(pr.wasTerminated);
//Assert.assertEquals((Integer) 0, pr.returnValue); due to destroy is null
} finally {
ServerAccess.PROCESS_TIMEOUT = 20 * 1000; //back to normal
}
}
+
+ @Test
+ @TestInBrowsers(testIn = {Browsers.all})
+ public void AppletTestSignedFirefoxTest() throws Exception {
+ ProcessResult pr = server.executeBrowser("/AppletTestSigned.html", ServerAccess.AutoClose.CLOSE_ON_BOTH);
+ evaluateSignedApplet(pr, false);
+ //Assert.assertTrue(pr.wasTerminated);
+ //Assert.assertEquals((Integer) 0, pr.returnValue); due to destroy is null
+ }
}
diff -r 04eddc48a74f tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java
--- a/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java Tue Aug 14 16:06:38 2012 -0400
+++ b/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java Fri Aug 17 12:14:06 2012 +0200
@@ -35,6 +35,7 @@
exception statement from your version.
*/
+import net.sourceforge.jnlp.closinglisteners.CountingClosingListener;
import net.sourceforge.jnlp.ProcessResult;
import net.sourceforge.jnlp.ServerAccess;
import net.sourceforge.jnlp.browsertesting.BrowserTest;
@@ -47,6 +48,24 @@
public class AppletTestTests extends BrowserTest {
+ private final String s7 = "Aplet killing himself after 2000 ms of life";
+ private final String ss = "xception";
+ private final String s2 = "value2";
+ private final String s1 = "value1";
+ private final String s0 = "applet was started";
+ private final String s3 = "applet was initialised";
+
+ private class CountingClosingListenerImpl extends CountingClosingListener {
+
+ @Override
+ protected boolean isAlowedToFinish(String s) {
+ if (s.contains(ss)) {
+ return true;
+ }
+ return (s.contains(s0) && s.contains(s1) && s.contains(s2) && s.contains(s3) && s.contains(s7));
+ }
+ }
+
@Test
@TestInBrowsers(testIn = {Browsers.googleChrome})
@NeedsDisplay
@@ -55,7 +74,7 @@
try {
//System.out.println("connecting AppletInFirefoxTest request in " + getBrowser().toString());
//just verify loging is recording browser
- ProcessResult pr1 = server.executeBrowser("/appletAutoTests.html");
+ ProcessResult pr1 = server.executeBrowser("/appletAutoTests2.html", new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
if (pr1.process == null) {
Assert.assertTrue("If proces was null here, then google-chrome had to not exist, and so "
+ ServerAccess.UNSET_BROWSER
@@ -64,12 +83,12 @@
pr1.deadlyException.getMessage().contains(ServerAccess.UNSET_BROWSER));
return;
}
- evaluateApplet(pr1,false);
+ evaluateApplet(pr1, false);
Assert.assertTrue(pr1.wasTerminated);
//System.out.println("connecting AppletInFirefoxTest request in " + getBrowser().toString());
// just verify loging is recording browser
- ServerAccess.ProcessResult pr = server.executeBrowser("/appletAutoTests.html");
- evaluateApplet(pr,false);
+ ServerAccess.ProcessResult pr = server.executeBrowser("/appletAutoTests2.html", new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
+ evaluateApplet(pr, false);
Assert.assertTrue(pr.wasTerminated);
} finally {
ServerAccess.PROCESS_TIMEOUT = 20 * 1000; //back to normal
@@ -80,30 +99,24 @@
@NeedsDisplay
public void AppletTest() throws Exception {
ProcessResult pr = server.executeJavawsHeadless(null, "/AppletTest.jnlp");
- evaluateApplet(pr,true);
+ evaluateApplet(pr, true);
Assert.assertFalse(pr.wasTerminated);
Assert.assertEquals((Integer) 0, pr.returnValue);
}
private void evaluateApplet(ProcessResult pr, boolean javawsApplet) {
- String s3 = "applet was initialised";
Assert.assertTrue("AppletTest stdout should contains " + s3 + " bud didn't", pr.stdout.contains(s3));
- String s0 = "applet was started";
Assert.assertTrue("AppletTest stdout should contains " + s0 + " bud didn't", pr.stdout.contains(s0));
- String s1 = "value1";
Assert.assertTrue("AppletTest stdout should contains " + s1 + " bud didn't", pr.stdout.contains(s1));
- String s2 = "value2";
Assert.assertTrue("AppletTest stdout should contains " + s2 + " bud didn't", pr.stdout.contains(s2));
- String ss = "xception";
Assert.assertFalse("AppletTest stderr should not contains " + ss + " but did", pr.stderr.contains(ss));
- String s7 = "Aplet killing himself after 2000 ms of life";
Assert.assertTrue("AppletTest stdout should contains " + s7 + " bud didn't", pr.stdout.contains(s7));
if (!javawsApplet) {
/*this is working correctly in most browser, but not in all. temporarily disabling
- String s4 = "applet was stopped";
- Assert.assertTrue("AppletTest stdout should contains " + s4 + " bud did't", pr.stdout.contains(s4));
- String s5 = "applet will be destroyed";
- Assert.assertTrue("AppletTest stdout should contains " + s5 + " bud did't", pr.stdout.contains(s5));
+ String s4 = "applet was stopped";
+ Assert.assertTrue("AppletTest stdout should contains " + s4 + " bud did't", pr.stdout.contains(s4));
+ String s5 = "applet will be destroyed";
+ Assert.assertTrue("AppletTest stdout should contains " + s5 + " bud did't", pr.stdout.contains(s5));
*/
}
}
@@ -116,8 +129,8 @@
//just verify loging is recordingb rowser
ServerAccess.PROCESS_TIMEOUT = 30 * 1000;
try {
- ProcessResult pr = server.executeBrowser("/appletAutoTests2.html");
- evaluateApplet(pr,false);
+ ProcessResult pr = server.executeBrowser("/appletAutoTests2.html", new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
+ evaluateApplet(pr, false);
Assert.assertTrue(pr.wasTerminated);
//Assert.assertEquals((Integer) 0, pr.returnValue); due to destroy is null
} finally {
@@ -132,9 +145,9 @@
//just verify loging is recording browser
ServerAccess.PROCESS_TIMEOUT = 30 * 1000;
try {
- ProcessResult pr = server.executeBrowser("/appletAutoTests.html");
+ ProcessResult pr = server.executeBrowser("/appletAutoTests.html", new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
pr.process.destroy();
- evaluateApplet(pr,false);
+ evaluateApplet(pr, false);
Assert.assertTrue(pr.wasTerminated);
//Assert.assertEquals((Integer) 0, pr.returnValue); due to destroy is null
} finally {
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,55 @@
+/* ClosingListener.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;
+
+public abstract class ClosingListener implements ContentReaderListener {
+
+ private ThreadedProcess process;
+ private ProcessAssasin assasin;
+
+ void setProcess(ThreadedProcess p) {
+ this.process = p;
+ }
+
+ void setAssasin(ProcessAssasin assasin) {
+ this.assasin = assasin;
+ }
+
+ public void terminate() {
+ assasin.setTimeout(Long.MIN_VALUE);
+ }
+}
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java
--- a/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java Tue Aug 14 16:06:38 2012 -0400
+++ b/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java Fri Aug 17 12:14:06 2012 +0200
@@ -98,6 +98,11 @@
return skipInstedOfDesroy;
}
+ void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
+
+
@Override
public void run() {
long startTime = System.nanoTime() / ServerAccess.NANO_TIME_DELIMITER;
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java
--- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java Tue Aug 14 16:06:38 2012 -0400
+++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java Fri Aug 17 12:14:06 2012 +0200
@@ -1,5 +1,5 @@
/* ServerAccess.java
-Copyright (C) 2011 Red Hat, Inc.
+Copyright (C) 2011, 2012 Red Hat, Inc.
This file is part of IcedTea.
@@ -58,6 +58,8 @@
import net.sourceforge.jnlp.browsertesting.Browser;
import net.sourceforge.jnlp.browsertesting.BrowserFactory;
import net.sourceforge.jnlp.browsertesting.Browsers;
+import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener;
+import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener;
import org.junit.Assert;
/**
@@ -77,6 +79,11 @@
*/
public class ServerAccess {
+ public enum AutoClose {
+
+ CLOSE_ON_EXCEPTION, CLOSE_ON_CORRECT_END, CLOSE_ON_BOTH
+ }
+
public static final long NANO_TIME_DELIMITER=1000000l;
/**
* java property which value containing path to default (makefile by) directory with deployed resources
@@ -544,11 +551,25 @@
public ProcessResult executeJavaws(String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception {
return executeJavaws(null, resource,stdoutl,stderrl);
}
+
+ public net.sourceforge.jnlp.ProcessResult executeBrowser(String string, AutoClose autoClose) throws Exception {
+ ClosingListener errClosing = null;
+ ClosingListener outClosing = null;
+ if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose == AutoClose.CLOSE_ON_EXCEPTION){
+ errClosing=new AutoErrorClosingListener();
+ }
+ if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose == AutoClose.CLOSE_ON_CORRECT_END){
+ outClosing=new AutoOkClosingListener();
+ }
+ return executeBrowser(string, outClosing, errClosing);
+ }
+
+
public ProcessResult executeBrowser(String resource) throws Exception {
return executeBrowser(getBrowserParams(), resource);
}
public ProcessResult executeBrowser(String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception {
- return executeBrowser(getBrowserParams(), resource,stderrl,stdoutl);
+ return executeBrowser(getBrowserParams(), resource,stdoutl,stderrl);
}
/**
@@ -788,6 +809,8 @@
log(connectionMesaage, true, true);
}
ProcessAssasin pa = new ProcessAssasin(t, PROCESS_TIMEOUT);
+ setUpClosingListener(stdoutl, pa, t);
+ setUpClosingListener(stderrl, pa, t);
pa.start();
t.start();
while (t.getP() == null && t.deadlyException == null) {
@@ -825,6 +848,13 @@
return pr;
}
+ private static void setUpClosingListener(ContentReaderListener listener, ProcessAssasin pa, ThreadedProcess t) {
+ if (listener != null && (listener instanceof ClosingListener)) {
+ ((ClosingListener) listener).setAssasin(pa);
+ ((ClosingListener) listener).setProcess(t);
+ }
+ }
+
/**
* this is temprary solution until refactoring is fully done
* Use net.sourceforge.jnlp.ProcessResult instead
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,57 @@
+/* CountingClosingListener.java
+Copyright (C) 2012 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.closinglisteners;
+
+import net.sourceforge.jnlp.ClosingListener;
+
+public class AutoAllClosingListener extends ClosingListener {
+
+
+
+ @Override
+ public void charReaded(char ch) {
+
+ }
+
+ @Override
+ public void lineReaded(String s) {
+ if (s.contains(AutoErrorClosingListener.MAGICAL_ERROR_CLOSING_STRING) || s.contains(AutoOkClosingListener.MAGICAL_OK_CLOSING_STRING)){
+ terminate();
+ }
+ }
+
+}
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,57 @@
+/* AutoErrorClosingListener.java
+Copyright (C) 2012 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.closinglisteners;
+
+import net.sourceforge.jnlp.ClosingListener;
+
+public class AutoErrorClosingListener extends ClosingListener {
+
+ public static final String MAGICAL_ERROR_CLOSING_STRING = "xception";
+
+ @Override
+ public void charReaded(char ch) {
+
+ }
+
+ @Override
+ public void lineReaded(String s) {
+ if (s.contains(MAGICAL_ERROR_CLOSING_STRING)){
+ terminate();
+ }
+ }
+
+}
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,57 @@
+/* CountingClosingListener.java
+Copyright (C) 2012 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.closinglisteners;
+
+import net.sourceforge.jnlp.ClosingListener;
+
+public class AutoOkClosingListener extends ClosingListener {
+
+ public static final String MAGICAL_OK_CLOSING_STRING = "*** APPLET FINISHED ***";
+
+ @Override
+ public void charReaded(char ch) {
+
+ }
+
+ @Override
+ public void lineReaded(String s) {
+ if (s.contains(MAGICAL_OK_CLOSING_STRING)){
+ terminate();
+ }
+ }
+
+}
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/closinglisteners/CountingClosingListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/CountingClosingListener.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,60 @@
+/* CountingClosingListener.java
+Copyright (C) 2012 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.closinglisteners;
+
+import net.sourceforge.jnlp.ClosingListener;
+
+public abstract class CountingClosingListener extends ClosingListener {
+
+ protected StringBuilder sb = new StringBuilder();
+
+ @Override
+ public void charReaded(char ch) {
+ sb.append(ch);
+ if (isAlowedToFinish(sb.toString())) {
+ terminate();
+ }
+
+ }
+
+ @Override
+ public void lineReaded(String s) {
+ //nothing to do
+ }
+
+ protected abstract boolean isAlowedToFinish(String content);
+}
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/closinglisteners/Rule.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/Rule.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,44 @@
+/* Rule.java
+Copyright (C) 2012 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.closinglisteners;
+
+public interface Rule<S,T> {
+
+ public void setRule(S rule);
+ public boolean evaluate(T upon);
+
+}
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/closinglisteners/RulesFolowingClosingListener.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/RulesFolowingClosingListener.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,174 @@
+/* RulesFolowingClosingListener.java
+Copyright (C) 2012 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.closinglisteners;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class RulesFolowingClosingListener extends CountingClosingListener {
+
+ private List<Rule> rules = new ArrayList<Rule>();
+
+ public static class ContainsRule extends StringRule<String, String> {
+
+ public ContainsRule(String s) {
+ super(s);
+ }
+
+ @Override
+ public boolean evaluate(String upon) {
+ return (upon.contains(rule));
+ }
+
+ @Override
+ public String toString() {
+ return "should contains `" + rule + "`";
+ }
+
+ public String toNotString() {
+ return "should NOT contains `" + rule + "`";
+ }
+ }
+
+ public static class NotContainsRule extends StringRule<String, String> {
+
+ public NotContainsRule(String s) {
+ super(s);
+ }
+
+ @Override
+ public boolean evaluate(String upon) {
+ return !(upon.contains(rule));
+ }
+
+ @Override
+ public String toString() {
+ return "should NOT contains `" + rule + "`";
+ }
+
+ public String toNotString() {
+ return "should contains `" + rule + "`";
+ }
+ }
+
+ public static class MatchesRule extends StringRule<String, String> {
+
+ public MatchesRule(String s) {
+ super(s);
+ }
+
+ @Override
+ public boolean evaluate(String upon) {
+ return (upon.matches(rule));
+ }
+
+ @Override
+ public String toString() {
+ return "should match `" + rule + "`";
+ }
+
+ public String toNotString() {
+ return "should NOT match `" + rule + "`";
+ }
+ }
+
+ public static class NotMatchesRule extends StringRule<String, String> {
+
+ public NotMatchesRule(String s) {
+ super(s);
+ }
+
+ @Override
+ public boolean evaluate(String upon) {
+ return !(upon.matches(rule));
+ }
+
+ @Override
+ public String toString() {
+ return "should NOT match`" + rule + "`";
+ }
+
+ public String toNotString() {
+ return "should match`" + rule + "`";
+ }
+ }
+
+ public void addRule(Rule rule) {
+ this.rules.add(rule);
+ }
+
+ public RulesFolowingClosingListener() {
+ }
+
+ public RulesFolowingClosingListener(List<Rule> l) {
+ setRules(l);
+ }
+
+ public RulesFolowingClosingListener(Rule[] l) {
+ setRules(l);
+ }
+
+ public void setRules(List<Rule> rules) {
+ if (rules == null) {
+ throw new NullPointerException("rules cant be null");
+ }
+ this.rules = rules;
+ }
+
+ public void setRules(Rule[] rules) {
+ if (rules == null) {
+ throw new NullPointerException("rules cant be null");
+ }
+ this.rules = Arrays.asList(rules);
+ }
+
+ @Override
+ protected boolean isAlowedToFinish(String content) {
+ if (rules==null || rules.size()<1){
+ throw new IllegalStateException("No rules specified");
+ }
+ for (Rule rule : rules) {
+ if (!rule.evaluate(content)) {
+ return false;
+ }
+ }
+ return true;
+
+
+ }
+}
diff -r 04eddc48a74f tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringRule.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringRule.java Fri Aug 17 12:14:06 2012 +0200
@@ -0,0 +1,57 @@
+/* StringRule.java
+Copyright (C) 2012 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.closinglisteners;
+
+public abstract class StringRule<String,T> implements Rule<String, T>{
+ protected String rule;
+
+ public StringRule(String rule) {
+ setRule(rule);
+ }
+
+ public StringRule() {
+ }
+
+
+ @Override
+ public void setRule(String rule){
+ this.rule=rule;
+ }
+ @Override
+ public abstract boolean evaluate(T upon);
+
+}