Path: blob/master/test/jdk/javax/xml/jaxp/XPath/8015978/XPathNegativeZero.java
41155 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 801597826* @summary Incorrect transformation of XPath expression "string(-0)"27* @run main XPathNegativeZero28* @author [email protected]29*/3031import java.io.File;32import java.io.StringWriter;33import javax.xml.transform.TransformerFactory;34import javax.xml.transform.Templates;35import javax.xml.transform.Transformer;36import javax.xml.transform.Source;37import javax.xml.transform.Result;38import javax.xml.transform.stream.StreamSource;39import javax.xml.transform.stream.StreamResult;404142public class XPathNegativeZero {4344static final String EXPECTEDXML = "<newtop>\"0\"</newtop>";4546public static void main(final String[] args) throws Exception {47//file name of XML file to transform48final String xml = System.getProperty("test.src", ".")+"/dummy.xml";49//file name of XSL file w/ transformation50final String xsl = System.getProperty("test.src", ".")+"/negativezero.xsl";51final String result = xform(xml, xsl).trim();5253System.out.println("transformed XML: '"+result+ "' expected XML: '"+EXPECTEDXML+"'");54if (!result.equals(EXPECTEDXML))55throw new Exception("Negative zero was incorrectly transformed");56}5758private static String xform(final String xml, final String xsl) throws Exception {59final TransformerFactory tf = TransformerFactory.newInstance();60final Source xslsrc = new StreamSource(new File(xsl));61final Templates tmpl = tf.newTemplates(xslsrc);62final Transformer t = tmpl.newTransformer();6364StringWriter writer = new StringWriter();65final Source src = new StreamSource(new File(xml));66final Result res = new StreamResult(writer);6768t.transform(src, res);69return writer.toString();70}71}727374