| 1 |
/* JSToJGetTest.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 net.sourceforge.jnlp.annotations.KnownToFail; |
| 46 |
import org.junit.Assert; |
| 47 |
|
| 48 |
import org.junit.Test; |
| 49 |
|
| 50 |
public class JSToJGetTest extends BrowserTest { |
| 51 |
|
| 52 |
// the JS<->J tests tend to make Opera unusable |
| 53 |
public final boolean doNotRunInOpera = false; |
| 54 |
|
| 55 |
public String passStr = " - passed."; |
| 56 |
public String failValStr = " - failed, value mismatch."; |
| 57 |
public String failTypeStr = " - failed, type mismatch."; |
| 58 |
public String expStr = "expected:["; |
| 59 |
public String foundStr = "] found:["; |
| 60 |
public String endStr = "]."; |
| 61 |
|
| 62 |
private final String initStr = "JSToJGet applet initialized."; |
| 63 |
private final String setupStr = "JSToJGet applet set up for GET tests."; |
| 64 |
private final String afterStr = "afterTests"; |
| 65 |
|
| 66 |
private class CountingClosingListenerImpl extends CountingClosingListener { |
| 67 |
|
| 68 |
@Override |
| 69 |
protected boolean isAlowedToFinish(String s) { |
| 70 |
return (s.contains(initStr) && s.contains(setupStr) && s.contains(afterStr)); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
private void evaluateStdoutContents(String testStr, ProcessResult pr) { |
| 75 |
// Assert that the applet was initialized. |
| 76 |
Assert.assertTrue("JSToJGetTest stdout should contain " + initStr + " but it didnt.", pr.stdout.contains(initStr)); |
| 77 |
|
| 78 |
// Assert that the applet was set up for the GM tests. |
| 79 |
Assert.assertTrue("JSToJGetTest stdout should contain " + setupStr + " but it didnt.", pr.stdout.contains(setupStr)); |
| 80 |
|
| 81 |
// Assert that the tests have passed. |
| 82 |
String s0 = testStr + passStr; |
| 83 |
String s1 = testStr + failValStr; |
| 84 |
String s2 = testStr + failTypeStr; |
| 85 |
|
| 86 |
int ind0 = pr.stdout.indexOf(s0); |
| 87 |
int ind1 = pr.stdout.indexOf(s1); |
| 88 |
int ind2 = pr.stdout.indexOf(s2); |
| 89 |
int indBegin = pr.stdout.indexOf(setupStr); |
| 90 |
if (indBegin != -1) { |
| 91 |
indBegin += setupStr.length(); |
| 92 |
} else { |
| 93 |
indBegin = 0; |
| 94 |
} |
| 95 |
|
| 96 |
String failStr = "JSToJGet " + testStr + ": passed not found in the applet stdout."; |
| 97 |
|
| 98 |
if (ind1 != -1) { |
| 99 |
// int inde = pr.stdout.indexOf(expStr); |
| 100 |
// int indf = pr.stdout.indexOf(foundStr); |
| 101 |
// int indend = pr.stdout.indexOf(endStr); |
| 102 |
failStr = "JSToJGet: value mismatch in " + testStr; |
| 103 |
} |
| 104 |
|
| 105 |
if (ind2 != -1) { |
| 106 |
// int inde = pr.stdout.indexOf(expStr); |
| 107 |
// int indf = pr.stdout.indexOf(foundStr); |
| 108 |
// int indend = pr.stdout.indexOf(endStr); |
| 109 |
failStr = "JSToJGet: type mismatch in " + testStr; |
| 110 |
} |
| 111 |
|
| 112 |
Assert.assertTrue(failStr, (ind1 == -1));// no value mismatch |
| 113 |
Assert.assertTrue(failStr, (ind2 == -1));// no type mismatch |
| 114 |
Assert.assertTrue(failStr, (ind0 != -1));// test passed |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
private void jsToJavaGetTest(String urlEnd, String testStr) throws Exception { |
| 119 |
|
| 120 |
if (doNotRunInOpera) { |
| 121 |
if (server.getCurrentBrowser().getID() == Browsers.opera) { |
| 122 |
return; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
String strURL = "/JSToJGet.html?" + urlEnd; |
| 127 |
ProcessResult pr = server.executeBrowser(strURL, new CountingClosingListenerImpl(), new CountingClosingListenerImpl()); |
| 128 |
evaluateStdoutContents(testStr, pr); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
@Test |
| 133 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 134 |
@NeedsDisplay |
| 135 |
public void AppletJSToJGet_int_Test() throws Exception { |
| 136 |
jsToJavaGetTest("int", "Test no. 1 - (int)"); |
| 137 |
} |
| 138 |
|
| 139 |
@Test |
| 140 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 141 |
@NeedsDisplay |
| 142 |
public void AppletJSToJGet_double_Test() throws Exception { |
| 143 |
jsToJavaGetTest("double", "Test no. 2 - (double)"); |
| 144 |
} |
| 145 |
|
| 146 |
@Test |
| 147 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 148 |
@NeedsDisplay |
| 149 |
public void AppletJSToJGet_float_Test() throws Exception { |
| 150 |
jsToJavaGetTest("float", "Test no. 3 - (float)"); |
| 151 |
} |
| 152 |
|
| 153 |
@Test |
| 154 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 155 |
@NeedsDisplay |
| 156 |
public void AppletJSToJGet_long_Test() throws Exception { |
| 157 |
jsToJavaGetTest("long", "Test no. 4 - (long)"); |
| 158 |
} |
| 159 |
|
| 160 |
@Test |
| 161 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 162 |
@NeedsDisplay |
| 163 |
public void AppletJSToJGet_boolean_Test() throws Exception { |
| 164 |
jsToJavaGetTest("boolean", "Test no. 5 - (boolean)"); |
| 165 |
} |
| 166 |
|
| 167 |
@Test |
| 168 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 169 |
@NeedsDisplay |
| 170 |
public void AppletJSToJGet_char_Test() throws Exception { |
| 171 |
jsToJavaGetTest("char", "Test no. 6 - (char)"); |
| 172 |
} |
| 173 |
|
| 174 |
@Test |
| 175 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 176 |
@NeedsDisplay |
| 177 |
public void AppletJSToJGet_byte_Test() throws Exception { |
| 178 |
jsToJavaGetTest("byte", "Test no. 7 - (byte)"); |
| 179 |
} |
| 180 |
|
| 181 |
@Test |
| 182 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 183 |
@NeedsDisplay |
| 184 |
@KnownToFail |
| 185 |
public void AppletJSToJGet_intArrayElement_Test() throws Exception { |
| 186 |
jsToJavaGetTest("intArrayElement", "Test no. 8 - (int[] - element access)"); |
| 187 |
} |
| 188 |
|
| 189 |
@Test |
| 190 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 191 |
@NeedsDisplay |
| 192 |
public void AppletJSToJGet_intArrayBeyond_Test() throws Exception { |
| 193 |
jsToJavaGetTest("intArrayBeyond", "Test no. 9 - (int[] - beyond length)"); |
| 194 |
} |
| 195 |
|
| 196 |
@Test |
| 197 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 198 |
@NeedsDisplay |
| 199 |
public void AppletJSToJGet_regularString_Test() throws Exception { |
| 200 |
jsToJavaGetTest("regularString", "Test no.10 - (regular string)"); |
| 201 |
} |
| 202 |
|
| 203 |
@Test |
| 204 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 205 |
@NeedsDisplay |
| 206 |
public void AppletJSToJGet_specialCharsString_Test() throws Exception { |
| 207 |
jsToJavaGetTest("specialCharsString", "Test no.11 - (string with special characters)"); |
| 208 |
} |
| 209 |
|
| 210 |
@Test |
| 211 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 212 |
@NeedsDisplay |
| 213 |
public void AppletJSToJGet_null_Test() throws Exception { |
| 214 |
jsToJavaGetTest("null", "Test no.12 - (null)"); |
| 215 |
} |
| 216 |
|
| 217 |
@Test |
| 218 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 219 |
@NeedsDisplay |
| 220 |
@KnownToFail |
| 221 |
public void AppletJSToJGet_Integer_Test() throws Exception { |
| 222 |
jsToJavaGetTest("Integer", "Test no.13 - (Integer)"); |
| 223 |
} |
| 224 |
|
| 225 |
@Test |
| 226 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 227 |
@NeedsDisplay |
| 228 |
@KnownToFail |
| 229 |
public void AppletJSToJGet_Double_Test() throws Exception { |
| 230 |
jsToJavaGetTest("Double", "Test no.14 - (Double)"); |
| 231 |
} |
| 232 |
|
| 233 |
@Test |
| 234 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 235 |
@NeedsDisplay |
| 236 |
@KnownToFail |
| 237 |
public void AppletJSToJGet_Float_Test() throws Exception { |
| 238 |
jsToJavaGetTest("Float", "Test no.15 - (Float)"); |
| 239 |
} |
| 240 |
|
| 241 |
@Test |
| 242 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 243 |
@NeedsDisplay |
| 244 |
@KnownToFail |
| 245 |
public void AppletJSToJGet_Long_Test() throws Exception { |
| 246 |
jsToJavaGetTest("Long", "Test no.16 - (Long)"); |
| 247 |
} |
| 248 |
|
| 249 |
@Test |
| 250 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 251 |
@NeedsDisplay |
| 252 |
@KnownToFail |
| 253 |
public void AppletJSToJGet_Boolean_Test() throws Exception { |
| 254 |
jsToJavaGetTest("Boolean", "Test no.17 - (Boolean)"); |
| 255 |
} |
| 256 |
|
| 257 |
@Test |
| 258 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 259 |
@NeedsDisplay |
| 260 |
@KnownToFail |
| 261 |
public void AppletJSToJGet_Character_Test() throws Exception { |
| 262 |
jsToJavaGetTest("Character", "Test no.18 - (Character)"); |
| 263 |
} |
| 264 |
|
| 265 |
@Test |
| 266 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 267 |
@NeedsDisplay |
| 268 |
@KnownToFail |
| 269 |
public void AppletJSToJGet_Byte_Test() throws Exception { |
| 270 |
jsToJavaGetTest("Byte", "Test no.19 - (Byte)"); |
| 271 |
} |
| 272 |
|
| 273 |
@Test |
| 274 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 275 |
@NeedsDisplay |
| 276 |
@KnownToFail |
| 277 |
public void AppletJSToJGet_DoubleArrayElement_Test() throws Exception { |
| 278 |
jsToJavaGetTest("DoubleArrayElement", "Test no.20 - (Double[] - element access)"); |
| 279 |
} |
| 280 |
|
| 281 |
@Test |
| 282 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 283 |
@NeedsDisplay |
| 284 |
@KnownToFail |
| 285 |
public void AppletJSToJGet_DoubleFullArray_Test() throws Exception { |
| 286 |
jsToJavaGetTest("DoubleFullArray", "Test no.21 - (Double[] - full array)"); |
| 287 |
} |
| 288 |
|
| 289 |
@Test |
| 290 |
@TestInBrowsers(testIn = { Browsers.all }) |
| 291 |
@NeedsDisplay |
| 292 |
public void AppletJSToJGet_JSObject_Test() throws Exception { |
| 293 |
jsToJavaGetTest("JSObject", "Test no.22 - (JSObject)"); |
| 294 |
} |
| 295 |
} |