Debian Codegraph @

tests/reproducers/simple/JSToJTypeConv/testcases/JSToJTypeConvTest.java

raw
1 /* JSToJTypeConvTest.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.NeedsDisplay;
44 import net.sourceforge.jnlp.annotations.TestInBrowsers;
45 import org.junit.Assert;
46
47 import org.junit.Test;
48
49 public class JSToJTypeConvTest extends BrowserTest {
50
51 //the JS<->J tests tend to make Opera unusable
52 public final boolean doNotRunInOpera = false;
53
54 private final String initStr = "JSToJTypeConv applet initialized.";
55 private final String afterStr = "afterTests";
56
57 private class CountingClosingListenerImpl extends CountingClosingListener {
58
59 @Override
60 protected boolean isAlowedToFinish(String s) {
61 return (s.contains(initStr) && s.contains(afterStr));
62 }
63 }
64
65 private void evaluateStdoutContents(String[] expectedStdouts, ProcessResult pr) {
66 // Assert that the applet was initialized.
67 Assert.assertTrue("JSToJTypeConv: the stdout should contain " + initStr
68 + ", but it didnt.", pr.stdout.contains(initStr));
69
70 // Assert that the values set by JavaScript are ok
71 for(String str : expectedStdouts){
72
73 String xmlStr = "new value";
74
75 if(str.contains("nonXML char"))
76 {
77 str = str.substring(12);
78 }else{
79 xmlStr = str;
80 }
81
82 Assert.assertTrue("JSToJTypeConv: the output should include "+xmlStr+", but it didnt.", pr.stdout.contains(str));
83 }
84 }
85
86 private void jsToJavaTypeConvTest(String fieldStr, String valueStr, String[] expectedValueAndOutputs) throws Exception {
87
88 if( doNotRunInOpera){
89 if(server.getCurrentBrowser().getID() == Browsers.opera){
90 return;
91 }
92 }
93
94 String strURL = "/JSToJTypeConv.html?" + fieldStr + ";" + valueStr;
95 ProcessResult pr = server.executeBrowser(strURL, new CountingClosingListenerImpl(), new CountingClosingListenerImpl());
96 String[] expectedStdouts = expectedValueAndOutputs;
97 evaluateStdoutContents(expectedStdouts, pr);
98 }
99
100 @Test
101 @TestInBrowsers(testIn = { Browsers.all })
102 @NeedsDisplay
103 public void AppletJSToJTypeConv_NumToJavaStringInteger_Test() throws Exception {
104 jsToJavaTypeConvTest("_String", "1", new String[] {"1"});
105 }
106
107 @Test
108 @TestInBrowsers(testIn = { Browsers.all })
109 @NeedsDisplay
110 public void AppletJSToJTypeConv_NumToJavaStringDouble_Test() throws Exception {
111 jsToJavaTypeConvTest("_String", "1.1", new String[] {"1.1"});
112 }
113
114 @Test
115 @TestInBrowsers(testIn = { Browsers.all })
116 @NeedsDisplay
117 public void AppletJSToJTypeConv_NumToJavaObjectInteger_Test() throws Exception {
118 jsToJavaTypeConvTest("_Object", "1.0", new String[] {"1","superclass is java.lang.Number"});
119 }
120
121 @Test
122 @TestInBrowsers(testIn = { Browsers.all })
123 @NeedsDisplay
124 public void AppletJSToJTypeConv_NumToJavaObjectDouble_Test() throws Exception {
125 jsToJavaTypeConvTest("_Object", "1.1", new String[] {"1.1","superclass is java.lang.Number"});
126 }
127
128 @Test
129 @TestInBrowsers(testIn = { Browsers.all })
130 @NeedsDisplay
131 public void AppletJSToJTypeConv_NumToboolean0_Test() throws Exception {
132 jsToJavaTypeConvTest("_boolean", "0", new String[] {"false"});
133 }
134
135 @Test
136 @TestInBrowsers(testIn = { Browsers.all })
137 @NeedsDisplay
138 public void AppletJSToJTypeConv_NumToboolean1dot1_Test() throws Exception {
139 jsToJavaTypeConvTest("_boolean", "1.1", new String[] {"true"});
140 }
141
142 @Test
143 @TestInBrowsers(testIn = { Browsers.all })
144 @NeedsDisplay
145 public void AppletJSToJTypeConv_BoolToJavaBoolTrue_Test() throws Exception {
146 jsToJavaTypeConvTest("_Boolean", "true", new String[] {"true"});
147 }
148
149 @Test
150 @TestInBrowsers(testIn = { Browsers.all })
151 @NeedsDisplay
152 public void AppletJSToJTypeConv_BoolToJavaBoolFalse_Test() throws Exception {
153 jsToJavaTypeConvTest("_Boolean", "false", new String[] {"false"});
154 }
155
156 @Test
157 @TestInBrowsers(testIn = { Browsers.all })
158 @NeedsDisplay
159 public void AppletJSToJTypeConv_BoolToJavaObject_Test() throws Exception {
160 jsToJavaTypeConvTest("_Object", "true", new String[] {"true", "class is java.lang.Boolean"});
161 }
162
163 @Test
164 @TestInBrowsers(testIn = { Browsers.all })
165 @NeedsDisplay
166 public void AppletJSToJTypeConv_BoolToJavaString_Test() throws Exception {
167 jsToJavaTypeConvTest("_String", "true", new String[] {"true"});
168 }
169
170 @Test
171 @TestInBrowsers(testIn = { Browsers.all })
172 @NeedsDisplay
173 public void AppletJSToJTypeConv_BoolTobyteTrue_Test() throws Exception {
174 jsToJavaTypeConvTest("_byte", "true", new String[] {"1"});
175 }
176
177 @Test
178 @TestInBrowsers(testIn = { Browsers.all })
179 @NeedsDisplay
180 public void AppletJSToJTypeConv_BoolTocharTrue_Test() throws Exception {
181 jsToJavaTypeConvTest("_char", "true", new String[] { "nonXML char "+((char)1) });
182 }
183
184 @Test
185 @TestInBrowsers(testIn = { Browsers.all })
186 @NeedsDisplay
187 public void AppletJSToJTypeConv_BoolToshortTrue_Test() throws Exception {
188 jsToJavaTypeConvTest("_short", "true", new String[] {"1"});
189 }
190
191 @Test
192 @TestInBrowsers(testIn = { Browsers.all })
193 @NeedsDisplay
194 public void AppletJSToJTypeConv_BoolTointTrue_Test() throws Exception {
195 jsToJavaTypeConvTest("_int", "true", new String[] {"1"});
196 }
197
198 @Test
199 @TestInBrowsers(testIn = { Browsers.all })
200 @NeedsDisplay
201 public void AppletJSToJTypeConv_BoolTolongTrue_Test() throws Exception {
202 jsToJavaTypeConvTest("_long", "true", new String[] {"1"});
203 }
204
205 @Test
206 @TestInBrowsers(testIn = { Browsers.all })
207 @NeedsDisplay
208 public void AppletJSToJTypeConv_BoolTofloatTrue_Test() throws Exception {
209 jsToJavaTypeConvTest("_float", "true", new String[] {"1"});
210 }
211
212 @Test
213 @TestInBrowsers(testIn = { Browsers.all })
214 @NeedsDisplay
215 public void AppletJSToJTypeConv_BoolTodoubleTrue_Test() throws Exception {
216 jsToJavaTypeConvTest("_double", "true", new String[] {"1"});
217 }
218
219 @Test
220 @TestInBrowsers(testIn = { Browsers.all })
221 @NeedsDisplay
222 public void AppletJSToJTypeConv_BoolTobyteFalse_Test() throws Exception {
223 jsToJavaTypeConvTest("_byte", "false", new String[] {"0"});
224 }
225
226 @Test
227 @TestInBrowsers(testIn = { Browsers.all })
228 @NeedsDisplay
229 public void AppletJSToJTypeConv_BoolTocharFalse_Test() throws Exception {
230 jsToJavaTypeConvTest("_char", "false", new String[] { "nonXML char "+((char)0) });
231 }
232
233 @Test
234 @TestInBrowsers(testIn = { Browsers.all })
235 @NeedsDisplay
236 public void AppletJSToJTypeConv_BoolToshortFalse_Test() throws Exception {
237 jsToJavaTypeConvTest("_short", "false", new String[] {"0"});
238 }
239
240 @Test
241 @TestInBrowsers(testIn = { Browsers.all })
242 @NeedsDisplay
243 public void AppletJSToJTypeConv_BoolTointFalse_Test() throws Exception {
244 jsToJavaTypeConvTest("_int", "false", new String[] {"0"});
245 }
246
247 @Test
248 @TestInBrowsers(testIn = { Browsers.all })
249 @NeedsDisplay
250 public void AppletJSToJTypeConv_BoolTolongFalse_Test() throws Exception {
251 jsToJavaTypeConvTest("_long", "false", new String[] {"0"});
252 }
253
254 @Test
255 @TestInBrowsers(testIn = { Browsers.all })
256 @NeedsDisplay
257 public void AppletJSToJTypeConv_BoolTofloatFalse_Test() throws Exception {
258 jsToJavaTypeConvTest("_float", "false", new String[] {"0"});
259 }
260
261 @Test
262 @TestInBrowsers(testIn = { Browsers.all })
263 @NeedsDisplay
264 public void AppletJSToJTypeConv_BoolTodoubleFalse_Test() throws Exception {
265 jsToJavaTypeConvTest("_double", "false", new String[] {"0"});
266 }
267
268 @Test
269 @TestInBrowsers(testIn = { Browsers.all })
270 @NeedsDisplay
271 public void AppletJSToJTypeConv_StringToObject_Test() throws Exception {
272 jsToJavaTypeConvTest("_Object", "\"𠁎〒£$ǣ€𝍖\"", new String[] {"𠁎〒£$ǣ€𝍖"});
273 }
274
275 @Test
276 @TestInBrowsers(testIn = { Browsers.all })
277 @NeedsDisplay
278 public void AppletJSToJTypeConv_StringTobyte_Test() throws Exception {
279 jsToJavaTypeConvTest("_byte", "\'1\'", new String[] {"1"}); //JS string 'str' or "str" both ok
280 }
281
282 @Test
283 @TestInBrowsers(testIn = { Browsers.all })
284 @NeedsDisplay
285 public void AppletJSToJTypeConv_StringToshort_Test() throws Exception {
286 jsToJavaTypeConvTest("_short", "\"1\"", new String[] {"1"});
287 }
288
289 @Test
290 @TestInBrowsers(testIn = { Browsers.all })
291 @NeedsDisplay
292 public void AppletJSToJTypeConv_StringToint_Test() throws Exception {
293 jsToJavaTypeConvTest("_int", "\"1\"", new String[] {"1"});
294 }
295
296 @Test
297 @TestInBrowsers(testIn = { Browsers.all })
298 @NeedsDisplay
299 public void AppletJSToJTypeConv_StringTolong_Test() throws Exception {
300 jsToJavaTypeConvTest("_long", "\"1\"", new String[] {"1"});
301 }
302
303 @Test
304 @TestInBrowsers(testIn = { Browsers.all })
305 @NeedsDisplay
306 public void AppletJSToJTypeConv_StringTofloat_Test() throws Exception {
307 jsToJavaTypeConvTest("_float", "\"1.1\"", new String[] {"1.1"});
308 }
309
310 @Test
311 @TestInBrowsers(testIn = { Browsers.all })
312 @NeedsDisplay
313 public void AppletJSToJTypeConv_StringTodouble_Test() throws Exception {
314 jsToJavaTypeConvTest("_double", "\"1.1\"", new String[] {"1.1"});
315 }
316
317 @Test
318 @TestInBrowsers(testIn = { Browsers.all })
319 @NeedsDisplay
320 public void AppletJSToJTypeConv_StringTochar_Test() throws Exception {
321 jsToJavaTypeConvTest("_char", "\"1\"", new String[] { "nonXML char "+((char)1) });
322 }
323
324 @Test
325 @TestInBrowsers(testIn = { Browsers.all })
326 @NeedsDisplay
327 public void AppletJSToJTypeConv_StringTobooleanEmptyFalse_Test() throws Exception {
328 jsToJavaTypeConvTest("_boolean", "\"\"", new String[] {"false"});
329 }
330
331 @Test
332 @TestInBrowsers(testIn = { Browsers.all })
333 @NeedsDisplay
334 public void AppletJSToJTypeConv_StringTobooleanNonemptyTrue_Test() throws Exception {
335 jsToJavaTypeConvTest("_boolean", "\"a nonempty string\"", new String[] {"true"});
336 }
337
338 @Test
339 @TestInBrowsers(testIn = { Browsers.all })
340 @NeedsDisplay
341 public void AppletJSToJTypeConv_ArrayTobyteArr_Test() throws Exception {
342 jsToJavaTypeConvTest("_byteArray", "[1,null,2]", new String[] {"[1,0,2]"});
343 }
344
345 @Test
346 @TestInBrowsers(testIn = { Browsers.all })
347 @NeedsDisplay
348 public void AppletJSToJTypeConv_ArrayTocharArr_Test() throws Exception {
349 jsToJavaTypeConvTest("_charArray", "[97,null,98]", new String[] {"nonXML char [a,"+((char)0) +",b]"});
350 }
351
352 @Test
353 @TestInBrowsers(testIn = { Browsers.all })
354 @NeedsDisplay
355 public void AppletJSToJTypeConv_ArrayToshortArr_Test() throws Exception {
356 jsToJavaTypeConvTest("_shortArray", "[1,null,2]", new String[] {"[1,0,2]"});
357 }
358
359 @Test
360 @TestInBrowsers(testIn = { Browsers.all })
361 @NeedsDisplay
362 public void AppletJSToJTypeConv_ArrayTointArr_Test() throws Exception {
363 jsToJavaTypeConvTest("_intArray", "[1,null,2]", new String[] {"[1,0,2]"});
364 }
365
366 @Test
367 @TestInBrowsers(testIn = { Browsers.all })
368 @NeedsDisplay
369 public void AppletJSToJTypeConv_ArrayTolongArr_Test() throws Exception {
370 jsToJavaTypeConvTest("_longArray", "[1,null,2]", new String[] {"[1,0,2]"});
371 }
372
373 @Test
374 @TestInBrowsers(testIn = { Browsers.all })
375 @NeedsDisplay
376 public void AppletJSToJTypeConv_ArrayTofloatArr_Test() throws Exception {
377 jsToJavaTypeConvTest("_floatArray", "[1,null,2]", new String[] {"[1.0,0.0,2.0]"});
378 }
379
380 @Test
381 @TestInBrowsers(testIn = { Browsers.all })
382 @NeedsDisplay
383 public void AppletJSToJTypeConv_ArrayTodoubleArr_Test() throws Exception {
384 jsToJavaTypeConvTest("_doubleArray", "[1,null,2]", new String[] {"[1.0,0.0,2.0]"});
385 }
386
387 @Test
388 @TestInBrowsers(testIn = { Browsers.all })
389 @NeedsDisplay
390 public void AppletJSToJTypeConv_ArrayToStringArr_Test() throws Exception {
391 jsToJavaTypeConvTest("_StringArray", "[1,null,2]", new String[] {"[1,null,2]"});
392 }
393
394 @Test
395 @TestInBrowsers(testIn = { Browsers.all })
396 @NeedsDisplay
397 public void AppletJSToJTypeConv_ArrayTocharArrArr_Test() throws Exception {
398 jsToJavaTypeConvTest("_charArray2D", "[[\"97\",null,\"98\"],[],[\"99\",\"100\",null,\"101\"]]", new String[] {"nonXML char [[a,"+((char)0)+",b],[],[c,d,"+((char)0)+",e]]"}); //Error on Java side: array element type mismatch
399 }
400
401 @Test
402 @TestInBrowsers(testIn = { Browsers.all })
403 @NeedsDisplay
404 public void AppletJSToJTypeConv_ArrayToStringArrArr_Test() throws Exception {
405 jsToJavaTypeConvTest("_StringArray2D", "[[\"00\",null,\"02\"],[],[\"20\",\"21\",null,\"23\"]]", new String[] {"[[00,null,02],[],[20,21,null,23]]"});
406 }
407
408 @Test
409 @TestInBrowsers(testIn = { Browsers.all })
410 @NeedsDisplay
411 public void AppletJSToJTypeConv_ArrayToString_Test() throws Exception {
412 jsToJavaTypeConvTest("_String", "[[\"00\",null,\"02\"],[],[\"20\",\"21\",null,\"23\"]]", new String[] {"00,,02,,20,21,,23"}); //Error on Java side: array element type mismatch
413 }
414
415 @Test
416 @TestInBrowsers(testIn = { Browsers.all })
417 @NeedsDisplay
418 public void AppletJSToJTypeConv_JSObjectToJSObject_Test() throws Exception {
419 jsToJavaTypeConvTest("_JSObject", "window", new String[] {"[object Window]"});
420 }
421
422 @Test
423 @TestInBrowsers(testIn = { Browsers.all })
424 @NeedsDisplay
425 public void AppletJSToJTypeConv_JSObjectToString_Test() throws Exception {
426 jsToJavaTypeConvTest("_String", "window", new String[] {"[object Window]"});
427 }
428
429 @Test
430 @TestInBrowsers(testIn = { Browsers.all })
431 @NeedsDisplay
432 public void AppletJSToJTypeConv_JavaObjectToJavaObject_Test() throws Exception {
433 jsToJavaTypeConvTest("_Object", "new applet.Packages.java.lang.Float(1.1)", new String[] {"1.1","class is java.lang.Float"});
434 }
435
436 @Test
437 @TestInBrowsers(testIn = { Browsers.all })
438 @NeedsDisplay
439 public void AppletJSToJTypeConv_JavaObjectToString_Test() throws Exception {
440 jsToJavaTypeConvTest("_String", "applet.getNewDummyObject(\"dummy1\")", new String[] {"dummy1"});
441 }
442
443 @Test
444 @TestInBrowsers(testIn = { Browsers.all })
445 @NeedsDisplay
446 public void AppletJSToJTypeConv_nullToJavaObjectString_Test() throws Exception {
447 jsToJavaTypeConvTest("_String", "null", new String[] {"null"});
448 }
449
450 @Test
451 @TestInBrowsers(testIn = { Browsers.all })
452 @NeedsDisplay
453 public void AppletJSToJTypeConv_StringTobooleanFalseStr_Test() throws Exception {
454 jsToJavaTypeConvTest("_boolean", "\"false\"", new String[] {"true"});
455 }
456
457 @Test
458 @TestInBrowsers(testIn = { Browsers.all })
459 @NeedsDisplay
460 public void AppletJSToJTypeConv_StringTobooleanTrueStr_Test() throws Exception {
461 jsToJavaTypeConvTest("_boolean", "\"true\"", new String[] {"true"});
462 }
463
464 @Test
465 @TestInBrowsers(testIn = { Browsers.all })
466 @NeedsDisplay
467 public void AppletJSToJTypeConv_StringToBooleanFalseStr_Test() throws Exception {
468 jsToJavaTypeConvTest("_Boolean", "\"false\"", new String[] {"true"});
469 }
470
471 @Test
472 @TestInBrowsers(testIn = { Browsers.all })
473 @NeedsDisplay
474 public void AppletJSToJTypeConv_StringToBooleanTrueStr_Test() throws Exception {
475 jsToJavaTypeConvTest("_Boolean", "\"true\"", new String[] {"true"});
476 }
477
478 }