| 1 |
/* EncodingTestTest.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 java.io.File; |
| 39 |
import java.io.FileInputStream; |
| 40 |
import java.io.FilenameFilter; |
| 41 |
import java.util.Arrays; |
| 42 |
import java.util.List; |
| 43 |
import net.sourceforge.jnlp.ProcessResult; |
| 44 |
import net.sourceforge.jnlp.ServerAccess; |
| 45 |
import net.sourceforge.jnlp.annotations.Bug; |
| 46 |
import net.sourceforge.jnlp.annotations.KnownToFail; |
| 47 |
import net.sourceforge.jnlp.annotations.NeedsDisplay; |
| 48 |
import net.sourceforge.jnlp.annotations.TestInBrowsers; |
| 49 |
import net.sourceforge.jnlp.browsertesting.BrowserTest; |
| 50 |
import net.sourceforge.jnlp.browsertesting.Browsers; |
| 51 |
import org.junit.Assert; |
| 52 |
import org.junit.Test; |
| 53 |
|
| 54 |
public class EncodingTestTest extends BrowserTest { |
| 55 |
|
| 56 |
List<String> verboseArg = Arrays.asList(new String[]{ServerAccess.VERBOSE_OPTION}); |
| 57 |
private static final String arg = "ěščřžýáíé=!@#$%^*()_+ú)ů§.-?:_\"!'(/ěéřťÝúíóášďźžčň;+ĚŠČŘŽÝÁÍÉĚÉŘŤÝÚŮÍÓÁŠĎŽŹŇ1"; |
| 58 |
private static final String argEscaped = arg.replace("\"", """); |
| 59 |
private static final String utf = "UTF8"; |
| 60 |
private static final String iso88592 = "ISO88592"; |
| 61 |
private FileInputStream is; |
| 62 |
File[] utf8Files = server.getDir().listFiles(new FilenameFilter() { |
| 63 |
|
| 64 |
@Override |
| 65 |
public boolean accept(File dir, String name) { |
| 66 |
return name.contains(utf); |
| 67 |
} |
| 68 |
}); |
| 69 |
File[] iso88592Files = server.getDir().listFiles(new FilenameFilter() { |
| 70 |
|
| 71 |
@Override |
| 72 |
public boolean accept(File dir, String name) { |
| 73 |
return name.contains(iso88592); |
| 74 |
} |
| 75 |
}); |
| 76 |
|
| 77 |
@Test |
| 78 |
public void iso88592FileCanBeDecodedCorrectly() throws Exception { |
| 79 |
Assert.assertTrue("there must be more then 1 iso file in server's directory", iso88592Files.length > 0); |
| 80 |
for (int i = 0; i < iso88592Files.length; i++) { |
| 81 |
File f = iso88592Files[i]; |
| 82 |
is = new FileInputStream(f); |
| 83 |
String ff = ServerAccess.getContentOfStream(is, "ISO-8859-2"); |
| 84 |
ServerAccess.logOutputReprint(f.getName()); |
| 85 |
ServerAccess.logOutputReprint(ff); |
| 86 |
Assert.assertTrue("file " + f.getName() + " should contain " + arg + " bud didn't", ff.contains(arg) || ff.contains(argEscaped)); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
@Test |
| 91 |
public void iso88592FileCanBeDecodedWrongly() throws Exception { |
| 92 |
Assert.assertTrue("there must be more then 1 iso file in server's directory", iso88592Files.length > 0); |
| 93 |
for (int i = 0; i < iso88592Files.length; i++) { |
| 94 |
File f = iso88592Files[i]; |
| 95 |
is = new FileInputStream(f); |
| 96 |
String ff = ServerAccess.getContentOfStream(is, "UTF-8"); |
| 97 |
ServerAccess.logOutputReprint(f.getName()); |
| 98 |
ServerAccess.logOutputReprint(ff); |
| 99 |
Assert.assertFalse("file " + f.getName() + " should NOT contain " + arg + " bud did", ff.contains(arg) || ff.contains(argEscaped)); |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
@Test |
| 104 |
public void utf8FileCanBeDecodedCorrectly() throws Exception { |
| 105 |
Assert.assertTrue("there must be more then 1 utf file in server's directory", utf8Files.length > 0); |
| 106 |
for (int i = 0; i < utf8Files.length; i++) { |
| 107 |
File f = utf8Files[i]; |
| 108 |
is = new FileInputStream(f); |
| 109 |
String ff = ServerAccess.getContentOfStream(is, "UTF-8"); |
| 110 |
ServerAccess.logOutputReprint(f.getName()); |
| 111 |
ServerAccess.logOutputReprint(ff); |
| 112 |
Assert.assertTrue("file " + f.getName() + " should contain " + arg + " bud didn't", ff.contains(arg) || ff.contains(argEscaped)); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
@Test |
| 117 |
public void utf8FileCanBeDecodedWrongly() throws Exception { |
| 118 |
Assert.assertTrue("there must be more then 1 utf file in server's directory", utf8Files.length > 0); |
| 119 |
for (int i = 0; i < utf8Files.length; i++) { |
| 120 |
File f = utf8Files[i]; |
| 121 |
is = new FileInputStream(f); |
| 122 |
String ff = ServerAccess.getContentOfStream(is, "ISO-8859-2"); |
| 123 |
ServerAccess.logOutputReprint(f.getName()); |
| 124 |
ServerAccess.logOutputReprint(ff); |
| 125 |
Assert.assertFalse("file " + f.getName() + " should NOT contain " + arg + " bud did", ff.contains(arg) || ff.contains(argEscaped)); |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
@Test |
| 130 |
public void testEncodingTest1Utf8() throws Exception { |
| 131 |
testEncodingTest1(utf); |
| 132 |
} |
| 133 |
|
| 134 |
@Test |
| 135 |
@KnownToFail |
| 136 |
@Bug(id = "PR1108") |
| 137 |
public void testEncodingTest1Iso88592() throws Exception { |
| 138 |
testEncodingTest1(iso88592); |
| 139 |
} |
| 140 |
|
| 141 |
@Test |
| 142 |
public void testEncodingTest2Utf8() throws Exception { |
| 143 |
testEncodingTest2(utf); |
| 144 |
} |
| 145 |
|
| 146 |
@Test |
| 147 |
@KnownToFail |
| 148 |
@Bug(id = "PR1108") |
| 149 |
public void testEncodingTest2Iso88592() throws Exception { |
| 150 |
testEncodingTest2(iso88592); |
| 151 |
} |
| 152 |
|
| 153 |
@Test |
| 154 |
public void testEncodingTest3Utf8() throws Exception { |
| 155 |
testEncodingTest3(utf); |
| 156 |
} |
| 157 |
|
| 158 |
@Test |
| 159 |
@KnownToFail |
| 160 |
@Bug(id = "PR1108") |
| 161 |
public void testEncodingTest3Iso88592() throws Exception { |
| 162 |
testEncodingTest3(iso88592); |
| 163 |
} |
| 164 |
|
| 165 |
@Test |
| 166 |
@NeedsDisplay |
| 167 |
@TestInBrowsers(testIn = Browsers.one) |
| 168 |
public void testEncodingTest4Utf8() throws Exception { |
| 169 |
testEncodingTest4(utf); |
| 170 |
} |
| 171 |
|
| 172 |
@Test |
| 173 |
@NeedsDisplay |
| 174 |
@TestInBrowsers(testIn = Browsers.one) |
| 175 |
public void testEncodingTest4Iso88592() throws Exception { |
| 176 |
testEncodingTest4(iso88592); |
| 177 |
} |
| 178 |
|
| 179 |
@Test |
| 180 |
public void testEncodingTest5Utf8() throws Exception { |
| 181 |
testEncodingTest5(utf); |
| 182 |
} |
| 183 |
|
| 184 |
@Test |
| 185 |
@Bug(id = "PR1108") |
| 186 |
@KnownToFail |
| 187 |
public void testEncodingTest5Iso88592() throws Exception { |
| 188 |
testEncodingTest5(iso88592); |
| 189 |
} |
| 190 |
|
| 191 |
/** |
| 192 |
* launching simpletest1.jar from encoding encoded jnlp |
| 193 |
*/ |
| 194 |
public void testEncodingTest1(String encoding) throws Exception { |
| 195 |
ProcessResult pr = server.executeJavawsHeadless(verboseArg, "/encodingTest1-" + encoding + ".jnlp"); |
| 196 |
String s = "Good simple javaws exapmle"; |
| 197 |
Assert.assertTrue("encodingTest1 (in " + encoding + ") stdout should contain " + s + " bud didn't", pr.stdout.contains(s)); |
| 198 |
//javaws in verbose mode is printing out readed jnlp. I'm no sure if the following test is relevant |
| 199 |
Assert.assertTrue("encodingTest1 (in " + encoding + ") stdout should contain " + arg + " bud didn't", pr.stdout.contains(arg)); |
| 200 |
} |
| 201 |
|
| 202 |
/** |
| 203 |
* launching simpletest1.jar fromencoding file with utf8/ISO-8859-2 uncompatible characters |
| 204 |
*/ |
| 205 |
public void testEncodingTest2(String encoding) throws Exception { |
| 206 |
ProcessResult pr = server.executeJavawsHeadless(verboseArg, "/encodingTest2ĚŠČŘŽÝÁÍÉĚÉŘŤÝÚŮÍÓÁŠĎŽŹŇ-" + encoding + ".jnlp"); |
| 207 |
String s = "Good simple javaws exapmle"; |
| 208 |
Assert.assertTrue("encodingTest2ĚŠČŘŽÝÁÍÉĚÉŘŤÝÚŮÍÓÁŠĎŽŹŇ (in " + encoding + ") stdout should contain " + s + " bud didn't", pr.stdout.contains(s)); |
| 209 |
//javaws in verbose mode is printing out readed jnlp. I'm no sure if the following test is relevant |
| 210 |
Assert.assertTrue("encodingTest2ĚŠČŘŽÝÁÍÉĚÉŘŤÝÚŮÍÓÁŠĎŽŹŇ (in " + encoding + ") stdout should contain " + arg + " bud didn't", pr.stdout.contains(arg)); |
| 211 |
} |
| 212 |
|
| 213 |
/** |
| 214 |
* launching encodingTestsĚŠČŘŽÝÁÍÉĚÉŘŤÝÚŮÍÓÁŠĎŽŹŇ.jar from encoding file with utf8/ISO-8859-2 uncompatible characters included also in args and jar filename |
| 215 |
*/ |
| 216 |
public void testEncodingTest3(String encoding) throws Exception { |
| 217 |
//not verbose in this case, this class is printing it's argument out |
| 218 |
ProcessResult pr = server.executeJavawsHeadless("/encodingTest3-" + encoding + ".jnlp"); |
| 219 |
String s = "Encoded jar decoded correctly"; |
| 220 |
Assert.assertTrue("encodingTest3 (in " + encoding + ") stdout should contain " + s + " bud didn't", pr.stdout.contains(s)); |
| 221 |
Assert.assertTrue("encodingTest3 (in " + encoding + ") stdout should contain " + arg + " bud didn't", pr.stdout.contains(arg)); |
| 222 |
} |
| 223 |
|
| 224 |
/** |
| 225 |
* launching encodingTestsĚŠČŘŽÝÁÍÉĚÉŘŤÝÚŮÍÓÁŠĎŽŹŇ.jar from encoding file with utf8/ISO-8859-2 uncompatible characters included also in args and jar filename in browser |
| 226 |
*/ |
| 227 |
public void testEncodingTest4(String encoding) throws Exception { |
| 228 |
ProcessResult pr = server.executeBrowser("/encodingTest4-" + encoding + ".html"); |
| 229 |
String s3 = "applet was initialised"; |
| 230 |
Assert.assertTrue("encodingTest4 stdout should contains " + s3 + " bud didn't", pr.stdout.contains(s3)); |
| 231 |
String s0 = "applet was started"; |
| 232 |
Assert.assertTrue("encodingTest4 stdout should contains " + s0 + " bud didn't", pr.stdout.contains(s3)); |
| 233 |
Assert.assertTrue("encodingTest4 (in " + encoding + ") stdout should contain " + arg + " bud didn't", pr.stdout.contains(arg)); |
| 234 |
} |
| 235 |
|
| 236 |
/** |
| 237 |
* launching encodingTestsĚŠČŘŽÝÁÍÉĚÉŘŤÝÚŮÍÓÁŠĎŽŹŇ.jar from encoding file with utf8/ISO-8859-2 uncompatible characters included also in args and jar filename as applet by jnlp |
| 238 |
*/ |
| 239 |
public void testEncodingTest5(String encoding) throws Exception { |
| 240 |
//not verbose in this case, this class is printing it's argument out |
| 241 |
ProcessResult pr = server.executeJavawsHeadless("/encodingTest5-" + encoding + ".jnlp"); |
| 242 |
String s3 = "applet was initialised"; |
| 243 |
Assert.assertTrue("encodingTest5 stdout should contains " + s3 + " bud didn't", pr.stdout.contains(s3)); |
| 244 |
String s0 = "applet was started"; |
| 245 |
Assert.assertTrue("encodingTest5 stdout should contains " + s0 + " bud didn't", pr.stdout.contains(s3)); |
| 246 |
Assert.assertTrue("encodingTest5 (in " + encoding + ") stdout should contain " + arg + " bud didn't", pr.stdout.contains(arg)); |
| 247 |
} |
| 248 |
} |