Debian Codegraph @

tests/reproducers/simple/CountingApplet1/testcases/ParallelAppletsTest.java

raw
1 /* ParallelAppletsTest.java
2 Copyright (C) 2011 Red Hat, Inc.
3
4 This file is part of IcedTea.
5
6 IcedTea is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 2.
9
10 IcedTea is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with IcedTea; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
19
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library. Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
24
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module. An independent module is a module which is not derived from
32 or based on this library. If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so. If you do not wish to do so, delete this
35 exception statement from your version.
36 */
37
38 import net.sourceforge.jnlp.ProcessResult;
39 import net.sourceforge.jnlp.ServerAccess;
40 import net.sourceforge.jnlp.browsertesting.BrowserTest;
41 import net.sourceforge.jnlp.browsertesting.Browsers;
42 import net.sourceforge.jnlp.annotations.NeedsDisplay;
43 import net.sourceforge.jnlp.annotations.TestInBrowsers;
44 import org.junit.Assert;
45
46 import org.junit.Test;
47
48 public class ParallelAppletsTest extends BrowserTest {
49
50 @Test
51 @TestInBrowsers(testIn = {Browsers.one})
52 @NeedsDisplay
53 public void testParallelAppletsTest1Ex2s() throws Exception {
54 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1EE_x_2s.html");
55 checkSimpleSignedStarted(pr);
56 checkNotInitialised(pr);
57 }
58
59 @Test
60 @TestInBrowsers(testIn = {Browsers.one})
61 @NeedsDisplay
62 public void testParallelAppletsTest1x2E() throws Exception {
63 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1_x_2EE.html");
64 checkExactCounts(1, 7, pr);
65 checkNotInitialised(pr);
66
67 }
68
69 @Test
70 @TestInBrowsers(testIn = {Browsers.one})
71 @NeedsDisplay
72 public void testParallelAppletsTest1x2e() throws Exception {
73 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1_x_2e.html");
74 checkExactCounts(1, 7, pr);
75 checkException(pr);
76 }
77
78 @Test
79 @TestInBrowsers(testIn = {Browsers.one})
80 @NeedsDisplay
81 public void testParallelAppletsTest1ex2s() throws Exception {
82 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1e_x_2s.html");
83 checkSimpleSignedStarted(pr);
84 checkException(pr);
85 }
86
87 @Test
88 @TestInBrowsers(testIn = {Browsers.one})
89 @NeedsDisplay
90 public void testParallelAppletsTest1sx2() throws Exception {
91 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1s_x_2.html");
92 checkAppletStarted(pr);
93 checkSimpleSignedStarted(pr);
94 }
95
96 @Test
97 @TestInBrowsers(testIn = {Browsers.one})
98 @NeedsDisplay
99 public void testParallelAppletsTest1sx2s() throws Exception {
100 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1s_x_2s.html");
101 int found=countCounts(SimpleSignedStarted, pr.stdout);
102 assertExactCount(SimpleSignedStarted, 2, found);
103
104
105 }
106
107 @Test
108 @TestInBrowsers(testIn = {Browsers.one})
109 @NeedsDisplay
110 public void testParallelAppletsTest1sx2ssk() throws Exception {
111 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1s_x_2ss.html");
112 checkSimpleSigned2Started(pr);
113 checkSimpleSignedStarted(pr);
114 }
115
116 @Test
117 @TestInBrowsers(testIn = {Browsers.one})
118 @NeedsDisplay
119 public void testParallelAppletsTest1x2sk() throws Exception {
120 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1_x_2sk.html");
121 checkExitNotAllowed(pr);
122 checkAtLeastCounts(1, 7, pr);
123 checkExactCounts(2, 5, pr);
124
125 }
126
127 @Test
128 @TestInBrowsers(testIn = {Browsers.one})
129 @NeedsDisplay
130 public void testParallelAppletsTest1kx2() throws Exception {
131 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1k_x_2.html");
132 checkExitNotAllowed(pr);
133 checkAtLeastCounts(1, 7, pr);
134 checkExactCounts(2, 5, pr);
135
136 }
137
138 @Test
139 @TestInBrowsers(testIn = {Browsers.one})
140 @NeedsDisplay
141 public void testParallelAppletsTest1x2() throws Exception {
142 long back = ServerAccess.PROCESS_TIMEOUT;
143 ServerAccess.PROCESS_TIMEOUT = 40 * 1000;//ms
144 try{
145 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1_x_2.html");
146 checkExactCounts(2, 7, pr);
147 }finally {
148 ServerAccess.PROCESS_TIMEOUT = back;
149 }
150 }
151
152 @Test
153 @TestInBrowsers(testIn = {Browsers.one})
154 @NeedsDisplay
155 public void testParallelAppletsTest1x1() throws Exception {
156 ProcessResult pr = server.executeBrowser("ParallelAppletsTest_1_x_1.html");
157 checkExactCounts(2, 7, pr);
158 }
159 private static final String ACE = "java.security.AccessControlException";
160 private static final String Sexit = "System.exit()";
161 private static final String LE1 = "net.sourceforge.jnlp.LaunchException";
162 private static final String LE2 = "Fatal: Initialization Error";
163 private static final String Cinit = "Could not initialize applet";
164 private static final String CountStub = "counting... ";
165 private static final String SimpleSignedStarted = "AppletTestSigned was started";
166 private static final String SimpleSigned2Started = "AppletTestSigned2 was started";
167 private static final String AppletStarted = "applet was started";
168 private static final String AppletThrowedException = "java.lang.RuntimeException: Correct exception";
169
170
171
172
173 private void checkExitNotAllowed(ProcessResult pr) {
174 Assert.assertTrue("Applets cant call " + Sexit, pr.stderr.contains(ACE));
175 Assert.assertTrue("Applets cant call " + Sexit, pr.stderr.contains(Sexit));
176 }
177
178 private void checkNotInitialised(ProcessResult pr) {
179 Assert.assertTrue("Applets should not be initialised ", pr.stderr.matches("(?s).*" + LE1 + ".*" + LE2 + ".*" + Cinit + ".*"));
180 }
181
182 private void checkSimpleSignedStarted(ProcessResult pr) {
183 Assert.assertTrue("Applet's start should be confirmed by " + SimpleSignedStarted, pr.stdout.contains(SimpleSignedStarted));
184 }
185 private void checkSimpleSigned2Started(ProcessResult pr) {
186 Assert.assertTrue("Applet's start should be confirmed by " + SimpleSigned2Started, pr.stdout.contains(SimpleSigned2Started));
187 }
188 private void checkAppletStarted(ProcessResult pr) {
189 Assert.assertTrue("Applet's start should be confirmed by " + AppletStarted, pr.stdout.contains(AppletStarted));
190 }
191 private void checkException(ProcessResult pr) {
192 Assert.assertTrue("Applet's exception should be confirmed by " + AppletThrowedException, pr.stderr.contains(AppletThrowedException));
193 }
194
195 //appelt is counting to ten, but last shouts are very often consumated during termination,
196 //so the chek is now called with "7" instead of "10"
197 private void checkExactCounts(int howManyTimes, int countIdTill, ProcessResult pr) {
198 for (int i = 0; i <= countIdTill; i++) {
199 String countId = CountStub + i+"\n";
200 int found = countCounts(countId, pr.stdout);
201 assertExactCount(countId, howManyTimes, found);
202 }
203
204 }
205
206 private void assertExactCount(String what, int howManyTimes, int found) {
207 Assert.assertEquals(what + " was expected exactly " + howManyTimes + " but was found " + found, howManyTimes, found);
208 }
209
210 private void checkAtLeastCounts(int howManyTimes, int countIdTill, ProcessResult pr) {
211 for (int i = 0; i <= countIdTill; i++) {
212 String countId = CountStub + i;
213 int found = countCounts(countId, pr.stdout);
214 Assert.assertTrue(countId + " was expected et least " + howManyTimes + " but was found " + found, found >= howManyTimes);
215 }
216
217 }
218
219 private int countCounts(String what, String where) {
220 int lastIndex = 0;
221 int count = 0;
222
223 while (lastIndex != -1) {
224
225 lastIndex = where.indexOf(what, lastIndex);
226
227 if (lastIndex != -1) {
228 count++;
229 lastIndex += what.length();
230 }
231 }
232 return count;
233
234 }
235
236
237 }