# HG changeset patch # User Danesh Dadachanji # Date 1344440886 14400 # Node ID cfad6b012cbf9205a4fde5d867d6f27378f25b7f # Parent f9ce023d1bf2922a7dd3bda7c47fc65ae5c3570d Fix PR955: regression: SweetHome3D fails to run diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +2012-08-22 Danesh Dadachanji + + Fix PR955: regression: SweetHome3D fails to run + * NEWS: Added entry for PR955 + * netx/net/sourceforge/jnlp/JNLPFile.java: New enum Match that represents + the level of precision to use when matching locales. + (localMatches): Renamed to localeMatches, added matchLevel paramater + and updated conditionals to handle the level of precision specified by it. + (getVendor): New method that returns an information's vendor text. + (getInformation): Added override methods for getTitle and getVendor + that are used by the anonymous class to filter by locale. All three + methods now go through all levels of precision to search for the best + fitted locale. + (getResources), (getResourcesDescs): Updated to check if any level of + precision matches when searching for locales. + (parse): Added call to checkForTitleVendor. + * netx/net/sourceforge/jnlp/Parser.java + (checkForTitleVendor): New method to check for availability of localized + title and vendor from the information tags. Throws ParseException. + (getInfo): Replace loop with foreach loop. + (getInformationDesc): Remove check for present title and vendor. + (getLocale): Variant returned can now use everything after the eigth + element of the locale's string. + * netx/net/sourceforge/jnlp/resources/Messages.properties: + Update missing title and vendor messages to mention localization. + * tests/reproducers/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java: + Update output string as per new changes to Messages internationalizations. + * tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java: + New unit test that checks the localesMatches method in JNLPFile. + * tests/netx/unit/net/sourceforge/jnlp/MockJNLPFile.java: + New class used to create a mock JNLPFile object. + * tests/netx/unit/net/sourceforge/jnlp/ParserTest.java: + New unit test that checks that the return of getTitle and getVendor + have localized information. + 2012-08-21 Jiri Vanek * tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java: diff --git a/NEWS b/NEWS --- a/NEWS +++ b/NEWS @@ -32,6 +32,7 @@ - RH838417: Disambiguate signed applet security prompt from certificate warning - RH838559: Disambiguate signed applet security prompt from certificate warning - RH720836: project can be compiled against GTK+ 2 or 3 librarie + - PR955: regression: SweetHome3D fails to run New in release 1.2 (2011-XX-XX): * Security updates: diff --git a/netx/net/sourceforge/jnlp/JNLPFile.java b/netx/net/sourceforge/jnlp/JNLPFile.java --- a/netx/net/sourceforge/jnlp/JNLPFile.java +++ b/netx/net/sourceforge/jnlp/JNLPFile.java @@ -99,18 +99,18 @@ /** the security descriptor */ protected SecurityDesc security; - /** the default OS */ + /** the default JVM locale */ protected Locale defaultLocale = null; - /** the default arch */ + /** the default OS */ protected String defaultOS = null; - /** the default jvm */ + /** the default arch */ protected String defaultArch = null; - + /** A signed JNLP file is missing from the main jar */ private boolean missingSignedJNLP = false; - + /** JNLP file contains special properties */ private boolean containsSpecialProperties = false; @@ -118,7 +118,7 @@ * List of acceptable properties (not-special) */ private String[] generalProperties = SecurityDesc.getJnlpRIAPermissions(); - + { // initialize defaults if security allows try { defaultLocale = Locale.getDefault(); @@ -129,6 +129,8 @@ } } + static enum Match { LANG_COUNTRY_VARIANT, LANG_COUNTRY, LANG, GENERALIZED } + /** * Empty stub, allowing child classes to override the constructor */ @@ -185,9 +187,9 @@ * @throws ParseException if the JNLP file was invalid */ public JNLPFile(URL location, Version version, boolean strict, UpdatePolicy policy) throws IOException, ParseException { - this(location, version, strict, policy, null); + this(location, version, strict, policy, null); } - + /** * Create a JNLPFile from a URL and a version, checking for updates * using the specified policy. @@ -284,7 +286,7 @@ } /** - * Returns the JNLP file's title. This method returns the same + * Returns the JNLP file's best localized title. This method returns the same * value as InformationDesc.getTitle(). */ public String getTitle() { @@ -292,6 +294,14 @@ } /** + * Returns the JNLP file's best localized vendor. This method returns the same + * value as InformationDesc.getVendor(). + */ + public String getVendor() { + return getInformation().getVendor(); + } + + /** * Returns the JNLP file's network location as specified in the * JNLP file. */ @@ -349,17 +359,52 @@ */ public InformationDesc getInformation(final Locale locale) { return new InformationDesc(this, new Locale[] { locale }) { + @Override protected List getItems(Object key) { List result = new ArrayList(); - for (int i = 0; i < info.size(); i++) { - InformationDesc infoDesc = info.get(i); + for (Match precision : Match.values()) { + for (InformationDesc infoDesc : JNLPFile.this.info) { + if (localeMatches(locale, infoDesc.getLocales(), precision)) { + result.addAll(infoDesc.getItems(key)); + } + } - if (localMatches(locale, infoDesc.getLocales())) - result.addAll(infoDesc.getItems(key)); + if (result.size() > 0) { + return result; + } + } + return result; + } + + @Override + public String getTitle() { + for (Match precision : Match.values()) { + for (InformationDesc infoDesc : JNLPFile.this.info) { + String title = infoDesc.getTitle(); + if (localeMatches(locale, infoDesc.getLocales(), precision) + && title != null && !"".equals(title)) { + return title; + } + } } - return result; + return null; + } + + @Override + public String getVendor() { + for (Match precision : Match.values()) { + for (InformationDesc infoDesc : JNLPFile.this.info) { + String vendor = infoDesc.getVendor(); + if (localeMatches(locale, infoDesc.getLocales(), precision) + && vendor != null && !"".equals(vendor)) { + return vendor; + } + } + } + + return null; } }; } @@ -393,11 +438,17 @@ */ public ResourcesDesc getResources(final Locale locale, final String os, final String arch) { return new ResourcesDesc(this, new Locale[] { locale }, new String[] { os }, new String[] { arch }) { + + @Override public List getResources(Class launchType) { List result = new ArrayList(); for (ResourcesDesc rescDesc : resources) { - if (localMatches(locale, rescDesc.getLocales()) + boolean hasUsableLocale = false; + for (Match match : Match.values()) { + hasUsableLocale |= localeMatches(locale, rescDesc.getLocales(), match); + } + if (hasUsableLocale && stringMatches(os, rescDesc.getOS()) && stringMatches(arch, rescDesc.getArch())) result.addAll(rescDesc.getResources(launchType)); @@ -408,6 +459,7 @@ return result; } + @Override public void addResource(Object resource) { // todo: honor the current locale, os, arch values sharedResources.addResource(resource); @@ -433,7 +485,11 @@ public ResourcesDesc[] getResourcesDescs(final Locale locale, final String os, final String arch) { List matchingResources = new ArrayList(); for (ResourcesDesc rescDesc: resources) { - if (localMatches(locale, rescDesc.getLocales()) + boolean hasUsableLocale = false; + for (Match match : Match.values()) { + hasUsableLocale |= localeMatches(locale, rescDesc.getLocales(), match); + } + if (hasUsableLocale && stringMatches(os, rescDesc.getOS()) && stringMatches(arch, rescDesc.getArch())) { matchingResources.add(rescDesc); @@ -546,28 +602,48 @@ * * @param requested the local * @param available the available locales + * @param precision the depth with which to match locales. 1 checks only + * language, 2 checks language and country, 3 checks language, country and + * variant for matches. Passing 0 will always return true. * @return true if requested matches any of available, or if * available is empty or null. */ - private boolean localMatches(Locale requested, Locale available[]) { - if (available == null || available.length == 0) - return true; + public boolean localeMatches(Locale requested, Locale available[], Match matchLevel) { - for (int i = 0; i < available.length; i++) { - String language = requested.getLanguage(); // "" but never null - String country = requested.getCountry(); - String variant = requested.getVariant(); + if (matchLevel == Match.GENERALIZED) + return available == null || available.length == 0; - if (!"".equals(language) && !language.equalsIgnoreCase(available[i].getLanguage())) - continue; - if (!"".equals(country) && !country.equalsIgnoreCase(available[i].getCountry())) - continue; - if (!"".equals(variant) && !variant.equalsIgnoreCase(available[i].getVariant())) - continue; + String language = requested.getLanguage(); // "" but never null + String country = requested.getCountry(); + String variant = requested.getVariant(); - return true; + for (Locale locale : available) { + switch (matchLevel) { + case LANG: + if (!language.isEmpty() + && language.equals(locale.getLanguage()) + && locale.getCountry().isEmpty() + && locale.getVariant().isEmpty()) + return true; + break; + case LANG_COUNTRY: + if (!language.isEmpty() + && language.equals(locale.getLanguage()) + && !country.isEmpty() + && country.equals(locale.getCountry()) + && locale.getVariant().isEmpty()) + return true; + break; + case LANG_COUNTRY_VARIANT: + if (language.equals(locale.getLanguage()) + && country.equals(locale.getCountry()) + && variant.equals(locale.getVariant())) + return true; + break; + default: + break; + } } - return false; } @@ -612,14 +688,15 @@ codeBase = parser.getCodeBase(); sourceLocation = parser.getFileLocation() != null ? parser.getFileLocation() : location; info = parser.getInfo(root); + parser.checkForInformation(); update = parser.getUpdate(root); resources = parser.getResources(root, false); // false == not a j2se/java resources section launchType = parser.getLauncher(root); component = parser.getComponent(root); security = parser.getSecurity(root); - + checkForSpecialProperties(); - + } catch (ParseException ex) { throw ex; } catch (Exception ex) { @@ -729,7 +806,7 @@ /** * Returns a boolean after determining if a signed JNLP warning should be * displayed in the 'More Information' panel. - * + * * @return true if a warning should be displayed; otherwise false */ public boolean requiresSignedJNLPWarning() { @@ -742,5 +819,4 @@ public void setSignedJNLPAsMissing() { missingSignedJNLP = true; } - } diff --git a/netx/net/sourceforge/jnlp/MissingInformationException.java b/netx/net/sourceforge/jnlp/MissingInformationException.java new file mode 100644 --- /dev/null +++ b/netx/net/sourceforge/jnlp/MissingInformationException.java @@ -0,0 +1,44 @@ +// Copyright (C) 2012 Red Hat, Inc. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +package net.sourceforge.jnlp; + +import static net.sourceforge.jnlp.runtime.Translator.R; + +/** + * Thrown when the required information tag is not found + * under the current JVM's locale or as a generalized element. + */ +public class MissingInformationException extends RequiredElementException { + + private static final long serialVersionUID = 1L; + private static final String message = R("PNoInfoElement"); + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String) + */ + public MissingInformationException() { + super(message); + } + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String, Throwable) + */ + public MissingInformationException(Throwable cause) { + super(message, cause); + } +} diff --git a/netx/net/sourceforge/jnlp/MissingTitleException.java b/netx/net/sourceforge/jnlp/MissingTitleException.java new file mode 100644 --- /dev/null +++ b/netx/net/sourceforge/jnlp/MissingTitleException.java @@ -0,0 +1,45 @@ +// Copyright (C) 2012 Red Hat, Inc. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +package net.sourceforge.jnlp; + +import static net.sourceforge.jnlp.runtime.Translator.R; + +/** + * Thrown when a title that is required from the information tag is not found + * under the current JVM's locale or as a generalized element. + */ +public class MissingTitleException extends RequiredElementException { + + private static final long serialVersionUID = 1L; + + private static final String message = R("PMissingElement", R("PMissingTitle")); + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String) + */ + public MissingTitleException() { + super(message); + } + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String, Throwable) + */ + public MissingTitleException(Throwable cause) { + super(message, cause); + } +} diff --git a/netx/net/sourceforge/jnlp/MissingVendorException.java b/netx/net/sourceforge/jnlp/MissingVendorException.java new file mode 100644 --- /dev/null +++ b/netx/net/sourceforge/jnlp/MissingVendorException.java @@ -0,0 +1,44 @@ +// Copyright (C) 2012 Red Hat, Inc. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +package net.sourceforge.jnlp; + +import static net.sourceforge.jnlp.runtime.Translator.R; + +/** + * Thrown when a vendor that is required from the information tag is not found + * under the current JVM's locale or as a generalized element. + */ +public class MissingVendorException extends RequiredElementException { + + private static final long serialVersionUID = 1L; + private static final String message = R("PMissingElement", R("PMissingVendor")); + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String) + */ + public MissingVendorException() { + super(message); + } + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String, Throwable) + */ + public MissingVendorException(Throwable cause) { + super(message, cause); + } +} diff --git a/netx/net/sourceforge/jnlp/Parser.java b/netx/net/sourceforge/jnlp/Parser.java --- a/netx/net/sourceforge/jnlp/Parser.java +++ b/netx/net/sourceforge/jnlp/Parser.java @@ -1,5 +1,5 @@ // Copyright (C) 2001-2003 Jon A. Maxwell (JAM) -// Copyright (C) 2009 Red Hat, Inc. +// Copyright (C) 2012 Red Hat, Inc. // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,7 @@ //import gd.xml.tiny.*; import net.sourceforge.jnlp.UpdateDesc.Check; import net.sourceforge.jnlp.UpdateDesc.Policy; +import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.nanoxml.*; /** @@ -425,6 +426,35 @@ // /** + * Make sure a title and vendor are present and nonempty and localized as + * best matching as possible for the JVM's current locale. Fallback to a + * generalized title and vendor otherwise. If none is found, throw an exception. + * + * Additionally prints homepage, description, title and vendor to stdout + * if in Debug mode. + * @throws RequiredElementException + */ + void checkForInformation() throws RequiredElementException { + if (JNLPRuntime.isDebug()) { + System.out.println("Homepage: " + file.getInformation().getHomepage()); + System.out.println("Description: " + file.getInformation().getDescription()); + } + + String title = file.getTitle(); + String vendor = file.getVendor(); + + if (title == null || title.trim().isEmpty()) + throw new MissingTitleException(); + else if (JNLPRuntime.isDebug()) + System.out.println("Acceptable title tag found, contains: " + title); + + if (vendor == null || vendor.trim().isEmpty()) + throw new MissingVendorException(); + else if (JNLPRuntime.isDebug()) + System.out.println("Acceptable vendor tag found, contains: " + vendor); + } + + /** * Returns all of the information elements under the specified * node. * @@ -438,11 +468,12 @@ // ensure that there are at least one information section present if (info.length == 0) - throw new ParseException(R("PNoInfoElement")); + throw new MissingInformationException(); // create objects from the info sections - for (int i = 0; i < info.length; i++) - result.add(getInformationDesc(info[i])); + for (Node infoNode : info) { + result.add(getInformationDesc(infoNode)); + } return result; } @@ -504,11 +535,6 @@ child = child.getNextSibling(); } - if (info.getTitle() == null || info.getTitle().trim().isEmpty()) - throw new ParseException(R("PNoTitleElement")); - if (info.getVendor() == null || info.getVendor().trim().isEmpty()) - throw new ParseException(R("PNoVendorElement")); - return info; } @@ -896,7 +922,7 @@ String language = localeStr.substring(0, 2); String country = (localeStr.length() < 5) ? "" : localeStr.substring(3, 5); - String variant = (localeStr.length() < 7) ? "" : localeStr.substring(6, 8); + String variant = (localeStr.length() > 7) ? localeStr.substring(6) : ""; // null is not allowed n locale but "" is return new Locale(language, country, variant); diff --git a/netx/net/sourceforge/jnlp/RequiredElementException.java b/netx/net/sourceforge/jnlp/RequiredElementException.java new file mode 100644 --- /dev/null +++ b/netx/net/sourceforge/jnlp/RequiredElementException.java @@ -0,0 +1,41 @@ +// Copyright (C) 2012 Red Hat, Inc. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +package net.sourceforge.jnlp; + +/** + * Thrown when a field that is required from the information tag is not found + * under the current JVM's locale or as a generalized element. + */ +public class RequiredElementException extends ParseException { + + private static final long serialVersionUID = 1L; + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String) + */ + public RequiredElementException(String message) { + super(message); + } + + /* (non-Javadoc) + * @see net.sourceforge.jnlp.ParseException(String, Throwable) + */ + public RequiredElementException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/netx/net/sourceforge/jnlp/resources/Messages.properties b/netx/net/sourceforge/jnlp/resources/Messages.properties --- a/netx/net/sourceforge/jnlp/resources/Messages.properties +++ b/netx/net/sourceforge/jnlp/resources/Messages.properties @@ -106,9 +106,10 @@ PInnerJ2SE=j2se element cannot be specified within a j2se element. PTwoMains=Duplicate main JAR defined in a resources element (there can be only one) PNativeHasMain=Cannot specify main attribute on native JARs. -PNoInfoElement=No information section defined -PNoTitleElement=The title section has not been defined in the JNLP file. -PNoVendorElement=The vendor section has not been defined in the JNLP file. +PNoInfoElement=No information section defined. +PMissingTitle=title +PMissingVendor=vendor +PMissingElement=The {0} section has not been defined for your locale nor does a default value exist in the JNLP file. PTwoDescriptions=Duplicate description of kind {0} PSharing=Element "sharing-allowed" is illegal in a standard JNLP file PTwoSecurity=Only one security element allowed per JNLPFile. diff --git a/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java b/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java new file mode 100644 --- /dev/null +++ b/tests/netx/unit/net/sourceforge/jnlp/JNLPFileTest.java @@ -0,0 +1,106 @@ +/* JNLPFileTest.java + Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + +package net.sourceforge.jnlp; + +import java.util.Locale; + +import net.sourceforge.jnlp.JNLPFile.Match; +import net.sourceforge.jnlp.mock.MockJNLPFile; + +import org.junit.Assert; +import org.junit.Test; + +public class JNLPFileTest { + Locale jvmLocale = new Locale("en", "CA", "utf8"); + MockJNLPFile file = new MockJNLPFile(jvmLocale); + + @Test + public void testCompareAll() { + Locale[] correctAvailable = { new Locale("en", "CA", "utf8") }; + Assert.assertTrue("Entire locale should match but did not.", + file.localeMatches(jvmLocale, correctAvailable, Match.LANG_COUNTRY_VARIANT)); + + Locale[] mismatchedAvailable = { new Locale("en", "CA", "utf16") }; + Assert.assertFalse("Should not match variant but did.", + file.localeMatches(jvmLocale, mismatchedAvailable, Match.LANG_COUNTRY_VARIANT)); + } + + @Test + public void testLangAndCountry() { + Locale[] correctAvailable = { new Locale("en", "CA") }; + Assert.assertTrue("Should match language and country, ignoring variant but did not.", + file.localeMatches(jvmLocale, correctAvailable, Match.LANG_COUNTRY)); + + Locale[] mismatchedAvailable = { new Locale("en", "EN") }; + Assert.assertFalse("Should not match country but did.", + file.localeMatches(jvmLocale, mismatchedAvailable, Match.LANG_COUNTRY)); + + Locale[] extraMismatched = { new Locale("en", "CA", "utf16") }; + Assert.assertFalse("Should not match because of extra variant but did.", + file.localeMatches(jvmLocale, extraMismatched, Match.LANG_COUNTRY)); + } + + @Test + public void testLangOnly() { + Locale[] correctAvailable = { new Locale("en") }; + Assert.assertTrue("Should match only language but did not.", + file.localeMatches(jvmLocale, correctAvailable, Match.LANG)); + + Locale[] mismatchedAvailable = { new Locale("fr", "CA", "utf8") }; + Assert.assertFalse("Should not match language but did.", + file.localeMatches(jvmLocale, mismatchedAvailable, Match.LANG)); + + Locale[] extraMismatched = { new Locale("en", "EN") }; + Assert.assertFalse("Should not match because of extra country but did.", + file.localeMatches(jvmLocale, extraMismatched, Match.LANG)); + } + + @Test + public void testNoLocalAvailable() { + Assert.assertTrue("Null locales should match but did not.", + file.localeMatches(jvmLocale, null, Match.GENERALIZED)); + + Locale[] emptyAvailable = {}; + Assert.assertTrue("Empty locales list should match but did not.", + file.localeMatches(jvmLocale, emptyAvailable, Match.GENERALIZED)); + + Locale[] mismatchAvailable = { new Locale("fr", "FR", "utf16") }; + Assert.assertFalse("Locales list should not match generalized case but did.", + file.localeMatches(jvmLocale, mismatchAvailable, Match.GENERALIZED)); + } +} diff --git a/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java b/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java new file mode 100644 --- /dev/null +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserTest.java @@ -0,0 +1,1358 @@ +/* ParserTest.java + Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + +package net.sourceforge.jnlp; + +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; + +import net.sourceforge.jnlp.mock.MockJNLPFile; + +import org.junit.Assert; +import org.junit.Test; + +/** Test various corner cases of the parser */ +public class ParserTest { + + private static final String LANG = "en"; + private static final String COUNTRY = "CA"; + private static final String VARIANT = "utf8"; + private static final Locale LANG_LOCALE = new Locale(LANG); + private static final Locale LANG_COUNTRY_LOCALE = new Locale(LANG, COUNTRY); + private static final Locale ALL_LOCALE = new Locale(LANG, COUNTRY, VARIANT); + + @Test(expected = MissingInformationException.class) + public void testMissingInfoFullLocale() throws ParseException { + String data = "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + parser.getInfo(root); + } + + @Test(expected = MissingTitleException.class) + public void testEmptyLocalizedInfoFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test + public void testOneFullyLocalizedInfoFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " English_CA_utf8_T\n" + + " English_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + + Assert.assertEquals("Title should be `English_CA_utf8_T' but wasn't", + "English_CA_utf8_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_utf8_V' but wasn't", + "English_CA_utf8_V", file.getVendor()); + } + + @Test + public void testOneLangCountryLocalizedInfoFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_CA_T' but wasn't", + "English_CA_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test + public void testOneLangLocalizedInfoFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_V' but wasn't", + "English_V", file.getVendor()); + } + + @Test + public void testGeneralizedInfoFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `Generalized_T' but wasn't", + "Generalized_T", file.getTitle()); + Assert.assertEquals("Vendor should be `Generalized_V' but wasn't", + "Generalized_V", file.getVendor()); + } + + @Test + public void testTwoDifferentLocalizedInfoFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " French_T\n" + + " French_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_V' but wasn't", + "English_V", file.getVendor()); + } + + @Test + public void testTwoLocalizedWithSameLangInfoFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_CA_T' but wasn't", + "English_CA_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test + public void testTwoSameLangOneMissingTitleFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test + public void testTwoSameLangWithGeneralizedTitleFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `Generalized_T' but wasn't", + "Generalized_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test(expected = MissingTitleException.class) + public void testMissingTitleFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testMissingVendorFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " \n" + + " \n" + + " English_T\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testMissingLocalizedTitleFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testMissingLocalizedVendorFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly two info descs should be found",infoDescs.size() == 2); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testEmptyLocalizedTitleFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " \n" + + " English_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testEmptyLocalizedVendorFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " English_CA_utf8_T\n" + + " \n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test + public void testFallbackEmptyLocalizedTitleVendorFullLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " French_CA_utf8_T\n" + + " French_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(ALL_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + + Assert.assertTrue("Exactly five info descs should be found", infoDescs.size() == 5); + + file.setInfo(infoDescs); + + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `Generalized_V' but wasn't", + "Generalized_V", file.getVendor()); + + parser.checkForInformation(); + } + + @Test(expected = MissingInformationException.class) + public void testMissingInfoLangCountryLocale() throws ParseException { + String data = "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + parser.getInfo(root); + } + + @Test(expected = MissingTitleException.class) + public void testEmptyLocalizedInfoLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testOneFullyLocalizedInfoLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " English_CA_utf8_T\n" + + " English_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test + public void testOneLangCountryLocalizedInfoLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_CA_T' but wasn't", + "English_CA_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test + public void testOneLangLocalizedInfoLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_V' but wasn't", + "English_V", file.getVendor()); + } + + @Test + public void testGeneralizedInfoLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `Generalized_T' but wasn't", + "Generalized_T", file.getTitle()); + Assert.assertEquals("Vendor should be `Generalized_V' but wasn't", + "Generalized_V", file.getVendor()); + } + + @Test + public void testTwoDifferentLocalizedInfoLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " French_T\n" + + " French_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_V' but wasn't", + "English_V", file.getVendor()); + } + + @Test + public void testTwoLocalizedWithSameLangInfoLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_CA_T' but wasn't", + "English_CA_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test + public void testTwoSameLangOneMissingTitleLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test + public void testTwoSameLangWithGeneralizedTitleLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `Generalized_T' but wasn't", + "Generalized_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_CA_V' but wasn't", + "English_CA_V", file.getVendor()); + } + + @Test(expected = MissingTitleException.class) + public void testMissingTitleLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testMissingVendorLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " \n" + + " \n" + + " English_T\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testMissingLocalizedTitleLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testMissingLocalizedVendorLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly two info descs should be found",infoDescs.size() == 2); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testEmptyLocalizedTitleLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " \n" + + " English_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testEmptyLocalizedVendorLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " English_CA_utf8_T\n" + + " \n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test + public void testFallbackEmptyLocalizedTitleVendorLangCountryLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " French_CA_utf8_T\n" + + " French_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_COUNTRY_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + + Assert.assertTrue("Exactly five info descs should be found", infoDescs.size() == 5); + + file.setInfo(infoDescs); + + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `Generalized_V' but wasn't", + "Generalized_V", file.getVendor()); + + parser.checkForInformation(); + } + + @Test(expected = MissingInformationException.class) + public void testMissingInfoLangLocale() throws ParseException { + String data = "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + parser.getInfo(root); + } + + @Test(expected = MissingTitleException.class) + public void testEmptyLocalizedInfoLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testOneFullyLocalizedInfoLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " English_CA_utf8_T\n" + + " English_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testOneLangCountryLocalizedInfoLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " English_CA_T\n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test + public void testOneLangLocalizedInfoLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_V' but wasn't", + "English_V", file.getVendor()); + } + + @Test + public void testGeneralizedInfoLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `Generalized_T' but wasn't", + "Generalized_T", file.getTitle()); + Assert.assertEquals("Vendor should be `Generalized_V' but wasn't", + "Generalized_V", file.getVendor()); + } + + @Test + public void testTwoDifferentLocalizedInfoLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " French_T\n" + + " French_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_V' but wasn't", + "English_V", file.getVendor()); + } + + @Test + public void testTwoLocalizedWithSameLangInfoLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `English_V' but wasn't", + "English_V", file.getVendor()); + } + + @Test + public void testTwoSameLangOneMissingTitleLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `Generalized_V' but wasn't", + "Generalized_V", file.getVendor()); + } + + @Test(expected = MissingTitleException.class) + public void testMissingTitleLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testMissingVendorLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " \n" + + " \n" + + " English_T\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly three info descs should be found", infoDescs.size() == 3); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testMissingLocalizedTitleLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_CA_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly two info descs should be found", infoDescs.size() == 2); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testMissingLocalizedVendorLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " \n" + + " \n" + + " English_CA_T\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly two info descs should be found",infoDescs.size() == 2); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingTitleException.class) + public void testEmptyLocalizedTitleLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " \n" + + " English_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test(expected = MissingVendorException.class) + public void testEmptyLocalizedVendorLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " English_CA_utf8_T\n" + + " \n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = new ArrayList(); + infoDescs.addAll(parser.getInfo(root)); + + Assert.assertTrue("Exactly one info desc should be found", infoDescs.size() == 1); + + file.setInfo(infoDescs); + parser.checkForInformation(); + } + + @Test + public void testFallbackEmptyLocalizedTitleVendorLangLocale() throws ParseException { + String data = "\n" + + " \n" + + " Generalized_T\n" + + " Generalized_V\n" + + " \n" + + " \n" + + " English_T\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " French_CA_utf8_T\n" + + " French_CA_utf8_V\n" + + " \n" + + "\n"; + + Node root = Parser.getRootNode(new ByteArrayInputStream(data.getBytes())); + Assert.assertEquals("Root name is not jnlp", "jnlp", root.getNodeName()); + + MockJNLPFile file = new MockJNLPFile(LANG_LOCALE); + Parser parser = new Parser(file, null, root, false, false); + List infoDescs = parser.getInfo(root); + + Assert.assertTrue("Exactly five info descs should be found", infoDescs.size() == 5); + + file.setInfo(infoDescs); + + Assert.assertEquals("Title should be `English_T' but wasn't", + "English_T", file.getTitle()); + Assert.assertEquals("Vendor should be `Generalized_V' but wasn't", + "Generalized_V", file.getVendor()); + + parser.checkForInformation(); + } +} diff --git a/tests/reproducers/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java b/tests/reproducers/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java --- a/tests/reproducers/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java +++ b/tests/reproducers/simple/InformationTitleVendorParser/testcases/InformationTitleVendorParserTest.java @@ -36,6 +36,9 @@ */ +import java.util.Arrays; +import java.util.List; + import net.sourceforge.jnlp.ServerAccess; import org.junit.Assert; import org.junit.Test; @@ -44,34 +47,33 @@ private static ServerAccess server = new ServerAccess(); - public void runTest(String jnlpName, String exceptionMessage) throws Exception { - ServerAccess.ProcessResult pr=server.executeJavawsHeadless(null,"/" + jnlpName + ".jnlp"); + public void runTest(String jnlpName, String exception) throws Exception { + List verbosed = Arrays.asList(new String[] { "-verbose" }); + ServerAccess.ProcessResult pr=server.executeJavawsHeadless(verbosed, "/" + jnlpName + ".jnlp"); String s1 = "Good simple javaws exapmle"; Assert.assertFalse("test" + jnlpName + " stdout should not contain " + s1 + " but did.", pr.stdout.contains(s1)); - // Looking for "Could not read or parse the JNLP file. (${DESCRIPTION})" - String s2 = "(?s).*Could not read or parse the JNLP file.{0,5}" + exceptionMessage + "(?s).*"; - Assert.assertTrue("testForTitle stderr should match " + s2 + " but did not.", pr.stderr.matches(s2)); + Assert.assertTrue("testForTitle stderr should contain " + exception + " but did not.", pr.stderr.contains(exception)); Assert.assertFalse(pr.wasTerminated); Assert.assertEquals((Integer)0, pr.returnValue); } @Test public void testInformationeParser() throws Exception { - runTest("InformationParser", "No information section defined"); + runTest("InformationParser", "net.sourceforge.jnlp.MissingInformationException"); } @Test public void testTitleParser() throws Exception { - runTest("TitleParser", "The title section has not been defined in the JNLP file."); + runTest("TitleParser", "net.sourceforge.jnlp.MissingTitleException"); } @Test public void testVendorParser() throws Exception { - runTest("VendorParser", "The vendor section has not been defined in the JNLP file."); + runTest("VendorParser", "net.sourceforge.jnlp.MissingVendorException"); } @Test public void testTitleVendorParser() throws Exception { // Note that the title message missing causes an immediate exception, regardless of Vendor. - runTest("TitleVendorParser", "The title section has not been defined in the JNLP file."); + runTest("TitleVendorParser", "net.sourceforge.jnlp.MissingTitleException"); } } diff --git a/tests/test-extensions/net/sourceforge/jnlp/mock/MockJNLPFile.java b/tests/test-extensions/net/sourceforge/jnlp/mock/MockJNLPFile.java new file mode 100644 --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/mock/MockJNLPFile.java @@ -0,0 +1,55 @@ +/* MockJNLPFile.java + Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + +package net.sourceforge.jnlp.mock; + +import java.util.List; +import java.util.Locale; + +import net.sourceforge.jnlp.InformationDesc; +import net.sourceforge.jnlp.JNLPFile; + +public class MockJNLPFile extends JNLPFile { + + public MockJNLPFile(Locale locale) { + defaultLocale = locale; + } + + public void setInfo(List infoList) { + info = infoList; + } +} # HG changeset patch # User Jiri Vanek # Date 1344854942 -7200 # Node ID 2359b7014c64487aebd96a81622f2c586f7c7990 # Parent cfad6b012cbf9205a4fde5d867d6f27378f25b7f Reproducers of PR955 diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2012-08-13 Jiri Vanek + + Reproducers of PR955 + * tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement1.jnlp: + * tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement2.jnlp: + * tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement3.jnlp: + * tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement4.jnlp: + Test jnlp files with various combinations of locales, reproducers of PR955. + * tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement_noLoc.jnlp + Jnlp file with which is not affected by PR955 and is helping to catch error in LOCALE changing hack + * tests/reproducers/simple/LocalisedInformationElement/srcs/LocalisedInformationElement.java: + Reproducer main class, after loading prints out default locale. + * tests/reproducers/simple/LocalisedInformationElement/testcases/LocalisedInformationElementTest.java: + Testcases launching above jnlps under various locales. + * tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java: + Added set of methods allowing passing of custom variables to ThreadedProcess. + * tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java: + Added processing of custom variables. + 2012-08-22 Danesh Dadachanji Fix PR955: regression: SweetHome3D fails to run diff --git a/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement1.jnlp b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement1.jnlp new file mode 100644 --- /dev/null +++ b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement1.jnlp @@ -0,0 +1,72 @@ + + + + + localisedJnlp1.jnlp1 + IcedTea + + LocalisedInformationElement1.jnlp + + + + LocalisedInformationElement1.jnlp la francee + La LocalisedInformationElement1.jnlp + + + + LocalisedInformationElement1.jnlp la francee BE + + + + LocalisedInformationElement1.jnlp la francee BE iso88591 + + + + LocalisedInformationElement1.jnlp po cesky + IcedTea CZ + Muj vlastni LocalisedInformationElement1.jnlp + + + + + + + + + diff --git a/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement2.jnlp b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement2.jnlp new file mode 100644 --- /dev/null +++ b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement2.jnlp @@ -0,0 +1,70 @@ + + + + + localisedJnlp1.jnlp1 + + + LocalisedInformationElement1.jnlp + + + + LocalisedInformationElement1.jnlp la francee + IcedTea + La LocalisedInformationElement1.jnlp + + + + LocalisedInformationElement1.jnlp la francee BE + + + + + LocalisedInformationElement1.jnlp po cesky + + Muj vlastni LocalisedInformationElement1.jnlp + + + + + + + + + diff --git a/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement3.jnlp b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement3.jnlp new file mode 100644 --- /dev/null +++ b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement3.jnlp @@ -0,0 +1,69 @@ + + + + + localisedJnlp1.jnlp1 + IcedTea + + D_DEF + + + + LocalisedInformationElement1.jnlp la francee + D_DEF_FR + + + + LocalisedInformationElement1.jnlp la francee BE + D_FR_BE + + + + LocalisedInformationElement1.jnlp po cesky + IcedTea CZ + D_DEF_CS + + + + + + + + + diff --git a/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement4.jnlp b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement4.jnlp new file mode 100644 --- /dev/null +++ b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement4.jnlp @@ -0,0 +1,70 @@ + + + + + localisedJnlp1.jnlp1 + + + D_DEF + + + + LocalisedInformationElement1.jnlp la francee + IcedTea + D_DEF_FR + + + + LocalisedInformationElement1.jnlp la francee BE + + + + + LocalisedInformationElement1.jnlp po cesky + + D_DEF_CS + + + + + + + + + diff --git a/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement_noLoc.jnlp b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement_noLoc.jnlp new file mode 100644 --- /dev/null +++ b/tests/reproducers/simple/LocalisedInformationElement/resources/LocalisedInformationElement_noLoc.jnlp @@ -0,0 +1,53 @@ + + + + + localisedJnlp_noLoc.jnlp1 + IcedTea + + LocalisedInformationElement_noLoc.jnlp + + + + + + + + + diff --git a/tests/reproducers/simple/LocalisedInformationElement/srcs/LocalisedInformationElement.java b/tests/reproducers/simple/LocalisedInformationElement/srcs/LocalisedInformationElement.java new file mode 100644 --- /dev/null +++ b/tests/reproducers/simple/LocalisedInformationElement/srcs/LocalisedInformationElement.java @@ -0,0 +1,52 @@ +/* LocalisedInformationElement.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + +import java.util.Locale; + +public class LocalisedInformationElement{ + + public static void main(String[] args){ + System.out.println("LocalisedInformationElement launched"); + System.out.println("*******************"); +// This needs signed code +// String locale = System.getProperty("user.language"); +// System.out.println("value of user.language: "+locale); + Locale loc=Locale.getDefault(); + System.out.println("default locale: "+loc.toString()); + System.out.println("*******************"); + } +} diff --git a/tests/reproducers/simple/LocalisedInformationElement/testcases/LocalisedInformationElementTest.java b/tests/reproducers/simple/LocalisedInformationElement/testcases/LocalisedInformationElementTest.java new file mode 100644 --- /dev/null +++ b/tests/reproducers/simple/LocalisedInformationElement/testcases/LocalisedInformationElementTest.java @@ -0,0 +1,356 @@ +/* LocalisedInformationElementTest.java +Copyright (C) 2012 Red Hat, Inc. + +This file is part of IcedTea. + +IcedTea is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as published by +the Free Software Foundation, version 2. + +IcedTea is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with IcedTea; see the file COPYING. If not, write to +the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import net.sourceforge.jnlp.ProcessResult; +import net.sourceforge.jnlp.ServerAccess; +import net.sourceforge.jnlp.annotations.Bug; +import org.junit.Assert; +import org.junit.Test; + +public class LocalisedInformationElementTest { + + private static ServerAccess server = new ServerAccess(); + + /** + * this will prepare new set of varibales with wanted locale, which + * can be then passed to subprocess + * @param locale - locale to be set to LANG variable, eg cs_CZ.UTF-8 + */ + public static String[] getChangeLocalesForSubproces(String locale) { + ServerAccess.logOutputReprint("Setting locales"); + Map p = System.getenv(); + Set> r = p.entrySet(); + List> rr = new ArrayList(r); + Collections.sort(rr, new Comparator>() { + + @Override + public int compare(Entry o1, Entry o2) { + return o1.getKey().compareTo(o2.getKey()); + } + }); + String[] l = new String[rr.size()]; + int i = -1; + for (Iterator> it = rr.iterator(); it.hasNext();) { + i++; + Entry entry = it.next(); + String v = entry.getValue(); + String s = entry.getKey() + "=" + v; + //System.out.println(s); + if (entry.getKey().equals("LANG")) { + ServerAccess.logOutputReprint("was " + v); + v = locale; + ServerAccess.logOutputReprint("set " + v); + } + s = entry.getKey() + "=" + v; + l[i] = s; + } + return l; + } + + public static ProcessResult evaluateLocalisedInformationElementTest(String id, String[] variables, boolean verbose) throws Exception { + ProcessResult pr = executeJavaws(verbose, variables, id); + String s = "LocalisedInformationElement launched"; + Assert.assertTrue(id + " stdout should contains " + s + " bud didn't", pr.stdout.contains(s)); + //to strict? + //String ss = "xception"; + //Assert.assertFalse(id + " stderr should not contains " + ss + " but did", pr.stderr.contains(ss)); + String locMatch = "(?s).*default locale: \\w{2}.*"; + Assert.assertTrue(id + " stdout should match " + locMatch + " bud didn't", pr.stdout.matches(locMatch)); + return pr; + } + + public static ProcessResult evaluateLocalisedInformationElementTestNotLaunched(String id, String[] variables, boolean verbose) throws Exception { + ProcessResult pr = executeJavaws(verbose, variables, id); + String s = "LocalisedInformationElement launched"; + Assert.assertFalse(id + " stdout should not contains " + s + " bud didn't", pr.stdout.contains(s)); + String ss = "xception"; + Assert.assertTrue(id + " stderr should contains " + ss + " but didn't", pr.stderr.contains(ss)); + String locMatch = "(?s).*default locale: \\w{2}.*"; + Assert.assertFalse(id + " stdout should not match " + locMatch + " bud didn't", pr.stdout.matches(locMatch)); + String sss = "MissingVendorException"; + Assert.assertTrue(id + " stderr should contains " + sss + " but didn't", pr.stderr.contains(sss)); + return pr; + } + + private static ProcessResult executeJavaws(boolean verbose, String[] variables, String id) throws Exception { + List oa = new ArrayList(1); + if (verbose) { + oa.add("-verbose"); + } + final ProcessResult pr; + if (variables == null) { + pr = server.executeJavawsHeadless(oa, "/" + id + ".jnlp"); + } else { + pr = server.executeJavawsHeadless(oa, "/" + id + ".jnlp", variables); + } + return pr; + } + + + //the description checkis disabled for all PR955, so it is representing just + //PR955 issue. Tests with enable description check are introduced later + private final boolean w1=false; + + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation1() throws Exception { + String[] l = getChangeLocalesForSubproces("en_US.UTF-8"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement1", l, true); + assertTiVeDe(pr, "localisedJnlp1.jnlp1", "IcedTea", "LocalisedInformationElement1.jnlp", w1); + } + +//LANG variable do not 'accept' nationales without regions :( +// @Test +// @Bug(id = "PR955") +// public void testLocalisedInformationElementLaunchWithLocalisedInformation2() throws Exception { +// String[] l = getChangeLocalesForSubproces("cs"); +// ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement1", l,true); +// assertTiVeDe(pr,"LocalisedInformationElement1.jnlp po cesky","IcedTea CZ","Muj vlastni LocalisedInformationElement1.jnlp",w1); +// } + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation22() throws Exception { + String[] l = getChangeLocalesForSubproces("cs_CZ"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement1", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp po cesky", "IcedTea CZ", "Muj vlastni LocalisedInformationElement1.jnlp", w1); + } + + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation33_1() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_BE"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement1", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee BE", "IcedTea", "La LocalisedInformationElement1.jnlp", w1); + } + +// java is ignoring set encoding :( +// @Test +// @Bug(id = "PR955") +// public void testLocalisedInformationElementLaunchWithLocalisedInformation33_2() throws Exception { +// String[] l = getChangeLocalesForSubproces("fr_BE.iso88591"); +// ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement1", l, true); +// assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee BE iso88591", "IcedTea", "La LocalisedInformationElement1.jnlp",false); +// } + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation33_() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_CH"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement1", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee", "IcedTea", "La LocalisedInformationElement1.jnlp", w1); + } + + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation1_withPieceMissing() throws Exception { + String[] l = getChangeLocalesForSubproces("en_US.UTF-8"); + ProcessResult pr = evaluateLocalisedInformationElementTestNotLaunched("LocalisedInformationElement2", l, true); + + } + + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation22_withPieceMissing() throws Exception { + String[] l = getChangeLocalesForSubproces("cs_CZ"); + ProcessResult pr = evaluateLocalisedInformationElementTestNotLaunched("LocalisedInformationElement2", l, true); + } + + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation33_1_withPieceMissing() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_BE"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement2", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee BE", "IcedTea", "La LocalisedInformationElement1.jnlp", w1); + } + + @Test + @Bug(id = "PR955") + public void testLocalisedInformationElementLaunchWithLocalisedInformation33_withPieceMissing() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_CH"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement2", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee", "IcedTea", "La LocalisedInformationElement1.jnlp", w1); + } + + //thsoe 11 methods are jsut for printing of locales passed to javaws + //so actually testing the LOCALE hack + @Test + public void printLocales() throws Exception { + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", null, false); + } + + @Test + public void printLocalesChanged1() throws Exception { + String[] l = getChangeLocalesForSubproces("cs_CZ.UTF-8"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertTrue(pr.stdout.contains("cs_CZ")); + } +// the following four have acepted iso encoding, but not used it + + @Test + public void printLocalesChanged2() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.ISO-8859-1"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertTrue(pr.stdout.contains("en_AU")); + } + + @Test + public void printLocalesChanged22() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.ISO88591"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertTrue(pr.stdout.contains("en_AU")); + } + + @Test + public void printLocalesChanged2222() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.iso-8859-1"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertTrue(pr.stdout.contains("en_AU")); + } + + @Test + public void printLocalesChanged3() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.UTF-8"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertTrue(pr.stdout.contains("en_AU")); + } + + // the following five have NOTacepted iso encoding at all + @Test + public void printLocalesChanged2_X() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.ISO-8859-2"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertFalse(pr.stdout.contains("en_AU")); + } + + @Test + public void printLocalesChanged22_X() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.ISO88592"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertFalse(pr.stdout.contains("en_AU")); + } + + @Test + public void printLocalesChanged2222_X() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.iso-8859-2"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertFalse(pr.stdout.contains("en_AU")); + } + + @Test + public void printLocalesChanged3_X() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.UTF-16"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertFalse(pr.stdout.contains("en_AU")); + } + + @Test + public void printLocalesChanged4_X() throws Exception { + String[] l = getChangeLocalesForSubproces("en_AU.jklukl56489jkyk"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement_noLoc", l, false); + Assert.assertFalse(pr.stdout.contains("en_AU")); + } + private static final String DEFAULT_HOMEPAGE = "http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"; + + public static void assertTiVeDe(ProcessResult pr, String title, String vendor, String description, boolean descTests) { + assertTiHpVeDe(pr, title, DEFAULT_HOMEPAGE, vendor, description, descTests); + } + + public static void assertTiHpVeDe(ProcessResult pr, String title, String homepage, String vendor, String description, boolean descTests) { + Assert.assertTrue("call shuld evaluate homepage as: " + homepage + " but did not", pr.stdout.contains("Homepage: " + homepage)); + Assert.assertTrue("call shuld evaluate title as: " + title + " but did not", pr.stdout.contains("Acceptable title tag found, contains: " + title)); + Assert.assertTrue("call shuld evaluate vendor as: " + " but did not", pr.stdout.contains("Acceptable vendor tag found, contains: " + vendor)); + if (descTests) { + Assert.assertTrue("call shuld evaluate description as: " + description + " but did not", pr.stdout.contains("Description: " + description)); + } + } + + + //following tests are testing also localisation of description + private final boolean w2=true; + + @Test + public void testLocalisedInformationElementLaunchWithLocalisedInformation1_withDescription() throws Exception { + String[] l = getChangeLocalesForSubproces("en_US.UTF-8"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement3", l, true); + assertTiVeDe(pr, "localisedJnlp1.jnlp1", "IcedTea", "D_DEF", w2); + } + + @Test + public void testLocalisedInformationElementLaunchWithLocalisedInformation22_withDescription() throws Exception { + String[] l = getChangeLocalesForSubproces("cs_CZ"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement3", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp po cesky", "IcedTea CZ", "D_DEF_CS", w2); + } + + @Test + public void testLocalisedInformationElementLaunchWithLocalisedInformation33_1_withDescription() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_BE"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement3", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee BE", "IcedTea", "D_FR_BE", w2); + } + + @Test + public void testLocalisedInformationElementLaunchWithLocalisedInformation33__withDescription() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_CH"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement3", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee", "IcedTea", "D_DEF_FR", w2); + } + + @Test + public void testLocalisedInformationElementLaunchWithLocalisedInformation33_1_withPieceMissing_withDescription() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_BE"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement4", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee BE", "IcedTea", "D_DEF_FR", w2); + } + + @Test + public void testLocalisedInformationElementLaunchWithLocalisedInformation33_withPieceMissing_withDescription() throws Exception { + String[] l = getChangeLocalesForSubproces("fr_CH"); + ProcessResult pr = evaluateLocalisedInformationElementTest("LocalisedInformationElement4", l, true); + assertTiVeDe(pr, "LocalisedInformationElement1.jnlp la francee", "IcedTea", "D_DEF_FR", w2); + } + + //following tests are testing localisation of homepage + //to lazy to do... +} diff --git a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java --- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java +++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java @@ -54,9 +54,7 @@ import java.net.ServerSocket; import java.net.URL; import java.util.ArrayList; -import java.util.HashSet; import java.util.List; -import java.util.Set; import net.sourceforge.jnlp.browsertesting.Browser; import net.sourceforge.jnlp.browsertesting.BrowserFactory; import net.sourceforge.jnlp.browsertesting.Browsers; @@ -505,7 +503,7 @@ return executeJavawsHeadless(null, resource); } public ProcessResult executeJavawsHeadless(String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { - return executeJavawsHeadless(null, resource,stdoutl,stderrl); + return executeJavawsHeadless(null, resource,stdoutl,stderrl,null); } /** @@ -518,15 +516,19 @@ * @throws Exception */ public ProcessResult executeJavawsHeadless(List otherargs, String resource) throws Exception { - return executeJavawsHeadless(otherargs, resource,null,null); + return executeJavawsHeadless(otherargs, resource,null,null,null); } - public ProcessResult executeJavawsHeadless(List otherargs, String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { + public ProcessResult executeJavawsHeadless(List otherargs, String resource, String[] vars) throws Exception { + return executeJavawsHeadless(otherargs, resource,null,null,vars); + } + + public ProcessResult executeJavawsHeadless(List otherargs, String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl,String[] vars) throws Exception { if (otherargs == null) { otherargs = new ArrayList(1); } List headlesList = new ArrayList(otherargs); headlesList.add(HEADLES_OPTION); - return executeJavaws(headlesList, resource,stdoutl,stderrl); + return executeJavaws(headlesList, resource,stdoutl,stderrl,vars); } @@ -564,6 +566,9 @@ public ProcessResult executeJavaws(List otherargs, String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { return executeProcessUponURL(getJavawsLocation(), otherargs, getUrlUponThisInstance(resource),stdoutl,stderrl); } + public ProcessResult executeJavaws(List otherargs, String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl,String[] vars) throws Exception { + return executeProcessUponURL(getJavawsLocation(), otherargs, getUrlUponThisInstance(resource),stdoutl,stderrl,vars); + } public ProcessResult executeBrowser(List otherargs, String resource) throws Exception { return executeProcessUponURL(getBrowserLocation(), otherargs, getUrlUponThisInstance(resource)); @@ -621,6 +626,9 @@ } public static ProcessResult executeProcessUponURL(String toBeExecuted, List otherargs, URL u,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { + return executeProcess(otherargs, null, stdoutl, stderrl, null); + } + public static ProcessResult executeProcessUponURL(String toBeExecuted, List otherargs, URL u,ContentReaderListener stdoutl,ContentReaderListener stderrl,String[] vars) throws Exception { Assert.assertNotNull(u); Assert.assertNotNull(toBeExecuted); Assert.assertTrue(toBeExecuted.trim().length() > 1); @@ -630,7 +638,7 @@ List urledArgs = new ArrayList(otherargs); urledArgs.add(0, toBeExecuted); urledArgs.add(u.toString()); - return executeProcess(urledArgs, stdoutl, stderrl); + return executeProcess(urledArgs, stdoutl, stderrl,vars); } public static ProcessResult executeProcess(final List args) throws Exception { @@ -639,6 +647,9 @@ public static ProcessResult executeProcess(final List args,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { return executeProcess(args, null,stdoutl,stderrl); } + public static ProcessResult executeProcess(final List args,ContentReaderListener stdoutl,ContentReaderListener stderrl,String[] vars) throws Exception { + return executeProcess(args, null,stdoutl,stderrl,vars); + } /** * utility method to lunch process, get its stdout/stderr, its return value and to kill it if running to long (@see PROCESS_TIMEOUT) * @@ -768,7 +779,11 @@ } public static ProcessResult executeProcess(final List args, File dir, ContentReaderListener stdoutl, ContentReaderListener stderrl) throws Exception { - ThreadedProcess t = new ThreadedProcess(args, dir); + return executeProcess(args, dir, stdoutl, stderrl,null); + + } + public static ProcessResult executeProcess(final List args, File dir, ContentReaderListener stdoutl, ContentReaderListener stderrl,String[] vars) throws Exception { + ThreadedProcess t = new ThreadedProcess(args, dir,vars); if (PROCESS_LOG) { String connectionMesaage = createConnectionMessage(t); log(connectionMesaage, true, true); diff --git a/tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java b/tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java --- a/tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java +++ b/tests/test-extensions/net/sourceforge/jnlp/ThreadedProcess.java @@ -51,6 +51,7 @@ List args; Integer exitCode; Boolean running; + String[] variables; File dir; Throwable deadlyException = null; /* @@ -75,15 +76,36 @@ return exitCode; } + public void setVariables(String[] variables) { + this.variables = variables; + } + + public String[] getVariables() { + return variables; + } + + + public ThreadedProcess(List args) { this.args = args; } public ThreadedProcess(List args, File dir) { - this.args = args; + this(args); this.dir = dir; } + public ThreadedProcess(List args,String[] vars) { + this(args); + this.variables = vars; + } + + public ThreadedProcess(List args, File dir,String[] vars) { + this(args,dir); + this.variables = vars; + } + + public String getCommandLine() { String commandLine = "unknown command"; try { @@ -110,9 +132,13 @@ running = true; Runtime r = Runtime.getRuntime(); if (dir == null) { - p = r.exec(args.toArray(new String[0])); + if (variables == null) { + p = r.exec(args.toArray(new String[0])); + } else { + p = r.exec(args.toArray(new String[0]), variables); + } } else { - p = r.exec(args.toArray(new String[0]), new String[0], dir); + p = r.exec(args.toArray(new String[0]), variables, dir); } try { exitCode = p.waitFor(); # HG changeset patch # User Jiri Vanek # Date 1344865323 -7200 # Node ID a33517a5a85d22258b7f96d2d2046eeb7486371b # Parent 2359b7014c64487aebd96a81622f2c586f7c7990 Fixed wrong call in previous commit which was causing null process name diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2012-08-13 Jiri Vanek + + * tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java: + (executeProcessUponURL)Fixed wrong call in previous commit which was + causing null process name. + * tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java: + Removed unused import. + 2012-08-13 Jiri Vanek Reproducers of PR955 diff --git a/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java b/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java --- a/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java +++ b/tests/reproducers/simple/AppletTest/testcases/AppletTestTests.java @@ -39,7 +39,6 @@ import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.browsertesting.BrowserTest; import net.sourceforge.jnlp.browsertesting.Browsers; -import net.sourceforge.jnlp.annotations.Bug; import net.sourceforge.jnlp.annotations.NeedsDisplay; import net.sourceforge.jnlp.annotations.TestInBrowsers; import org.junit.Assert; diff --git a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java --- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java +++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java @@ -626,7 +626,7 @@ } public static ProcessResult executeProcessUponURL(String toBeExecuted, List otherargs, URL u,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { - return executeProcess(otherargs, null, stdoutl, stderrl, null); + return executeProcessUponURL(toBeExecuted, otherargs, u, stdoutl, stderrl, null); } public static ProcessResult executeProcessUponURL(String toBeExecuted, List otherargs, URL u,ContentReaderListener stdoutl,ContentReaderListener stderrl,String[] vars) throws Exception { Assert.assertNotNull(u);