Debian Codegraph @

tests/reproducers/simple/JSToJFuncParam/testcases/JSToJFuncParamTest.java

raw
1 /* JSToJFuncParamTest.java
2 Copyright (C) 2012 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.closinglisteners.CountingClosingListener;
43 import net.sourceforge.jnlp.annotations.KnownToFail;
44 import net.sourceforge.jnlp.annotations.NeedsDisplay;
45 import net.sourceforge.jnlp.annotations.TestInBrowsers;
46
47 import org.junit.Assert;
48 import org.junit.Test;
49
50 public class JSToJFuncParamTest extends BrowserTest {
51
52 // the JS<->J tests tend to make Opera unusable
53 public final boolean doNotRunInOpera = false;
54
55 private final String initStr = "JSToJFuncParam applet initialized.";
56 private final String afterStr = "afterTests";
57
58 private class CountingClosingListenerImpl extends CountingClosingListener {
59
60 @Override
61 protected boolean isAlowedToFinish(String s) {
62 return (s.contains(initStr) && s.contains(afterStr));
63 }
64 }
65
66 private void evaluateStdoutContents(String expectedStdout, ProcessResult pr) {
67 // Assert that the applet was initialized.
68 Assert.assertTrue("JSToJFuncParam: the stdout should contain " + initStr + ", but it didnt.", pr.stdout.contains(initStr));
69
70 // Assert that the values set by JavaScript are ok
71 Assert.assertTrue("JSToJFuncParam: the output should include: " + expectedStdout + ", but it didnt.", pr.stdout.contains(expectedStdout));
72
73 }
74
75 private void jsToJavaFuncParamTest(String funcStr, String paramStr, String expectedVal) throws Exception {
76
77 if (doNotRunInOpera) {
78 if (server.getCurrentBrowser().getID() == Browsers.opera) {
79 return;
80 }
81 }
82
83 String strURL = "/JSToJFuncParam.html?" + funcStr + ";" + paramStr;
84 ProcessResult pr = server.executeBrowser(strURL, new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
85 String expectedStdout = funcStr + " " + expectedVal;
86 evaluateStdoutContents(expectedStdout, pr);
87 }
88
89 @Test
90 @TestInBrowsers(testIn = { Browsers.all })
91 @NeedsDisplay
92 public void AppletJSToJFuncParam_int_Test() throws Exception {
93 jsToJavaFuncParamTest("intParam", "1", "1");
94 }
95
96 @Test
97 @TestInBrowsers(testIn = { Browsers.all })
98 @NeedsDisplay
99 public void AppletJSToJFuncParam_double_Test() throws Exception {
100 jsToJavaFuncParamTest("doubleParam", "1.1", "1.1");
101 }
102
103 @Test
104 @TestInBrowsers(testIn = { Browsers.all })
105 @NeedsDisplay
106 public void AppletJSToJFuncParam_float_Test() throws Exception {
107 jsToJavaFuncParamTest("floatParam", "1.1", "1.1");
108 }
109
110 @Test
111 @TestInBrowsers(testIn = { Browsers.all })
112 @NeedsDisplay
113 public void AppletJSToJFuncParam_long_Test() throws Exception {
114 jsToJavaFuncParamTest("longParam", "10000", "10000");
115 }
116
117 @Test
118 @TestInBrowsers(testIn = { Browsers.all })
119 @NeedsDisplay
120 public void AppletJSToJFuncParam_boolean_Test() throws Exception {
121 jsToJavaFuncParamTest("booleanParam", "true", "true");
122 }
123
124 @Test
125 @TestInBrowsers(testIn = { Browsers.all })
126 @NeedsDisplay
127 public void AppletJSToJFuncParam_char_Test() throws Exception {
128 jsToJavaFuncParamTest("charParam", "97", "a");
129 }
130
131 @Test
132 @TestInBrowsers(testIn = { Browsers.all })
133 @NeedsDisplay
134 public void AppletJSToJFuncParam_byte_Test() throws Exception {
135 jsToJavaFuncParamTest("byteParam", "10", "10");
136 }
137
138 @Test
139 @TestInBrowsers(testIn = { Browsers.all })
140 @NeedsDisplay
141 public void AppletJSToJFuncParam_charArray_Test() throws Exception {
142 jsToJavaFuncParamTest("charArrayParam", "[97,98,99]", "[a, b, c]");
143 }
144
145 @Test
146 @TestInBrowsers(testIn = { Browsers.all })
147 @NeedsDisplay
148 public void AppletJSToJFuncParam_String_Test() throws Exception {
149 jsToJavaFuncParamTest("StringParam", "\"test\"", "test");
150 }
151
152 @Test
153 @TestInBrowsers(testIn = { Browsers.all })
154 @NeedsDisplay
155 public void AppletJSToJFuncParam_Integer_Test() throws Exception {
156 jsToJavaFuncParamTest("IntegerParam", "1", "1");
157 }
158
159 @Test
160 @TestInBrowsers(testIn = { Browsers.all })
161 @NeedsDisplay
162 public void AppletJSToJFuncParam_Double_Test() throws Exception {
163 jsToJavaFuncParamTest("DoubleParam", "1.1", "1.1");
164 }
165
166 @Test
167 @TestInBrowsers(testIn = { Browsers.all })
168 @NeedsDisplay
169 @KnownToFail
170 public void AppletJSToJFuncParam_Float_Test() throws Exception {
171 jsToJavaFuncParamTest("FloatParam", "1.1", "1.1");
172 }
173
174 //
175 @Test
176 @TestInBrowsers(testIn = { Browsers.all })
177 @NeedsDisplay
178 @KnownToFail
179 public void AppletJSToJFuncParam_Long_Test() throws Exception {
180 jsToJavaFuncParamTest("LongParam", "10000", "10000");
181 }
182
183 @Test
184 @TestInBrowsers(testIn = { Browsers.all })
185 @NeedsDisplay
186 public void AppletJSToJFuncParam_Boolean_Test() throws Exception {
187 jsToJavaFuncParamTest("BooleanParam", "true", "true");
188 }
189
190 @Test
191 @TestInBrowsers(testIn = { Browsers.all })
192 @NeedsDisplay
193 public void AppletJSToJFuncParam_Character_Test() throws Exception {
194 jsToJavaFuncParamTest("CharacterParam", "new applet.Packages.java.lang.Character(65)", "A");
195 }
196
197 @Test
198 @TestInBrowsers(testIn = { Browsers.all })
199 @NeedsDisplay
200 @KnownToFail
201 public void AppletJSToJFuncParam_Byte_Test() throws Exception {
202 jsToJavaFuncParamTest("ByteParam", "10", "10");
203 }
204
205 @Test
206 @TestInBrowsers(testIn = { Browsers.all })
207 @NeedsDisplay
208 public void AppletJSToJFuncParam_StringIntMixed_Test() throws Exception {
209 jsToJavaFuncParamTest("StringIntMixedParam", "[\"test\",123]", "[test, 123]");
210 }
211
212 @Test
213 @TestInBrowsers(testIn = { Browsers.all })
214 @NeedsDisplay
215 public void AppletJSToJFuncParam_DummyObjectArray_Test() throws Exception {
216 jsToJavaFuncParamTest("DummyObjectArrayParam", "[applet.getNewDummyObject(\"Dummy1\"),applet.getNewDummyObject(\"Dummy2\")]", "[Dummy1, Dummy2]");
217 }
218
219 @Test
220 @TestInBrowsers(testIn = { Browsers.all })
221 @NeedsDisplay
222 public void AppletJSToJFuncParam_JSObject_Test() throws Exception {
223 jsToJavaFuncParamTest("JSObjectParam", "new JSCar(100,\"red\")", "100, red");
224 }
225
226 @Test
227 @TestInBrowsers(testIn = { Browsers.all })
228 @NeedsDisplay
229 public void AppletJSToJFuncParam_booleanFalseStr_Test() throws Exception {
230 jsToJavaFuncParamTest("booleanParam", "false", "false");
231 }
232
233 //
234 @Test
235 @TestInBrowsers(testIn = { Browsers.all })
236 @NeedsDisplay
237 public void AppletJSToJFuncParam_BooleanFalseStr_Test() throws Exception {
238 jsToJavaFuncParamTest("BooleanParam", "false", "false");
239 }
240 }