/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * See LICENSE.txt included in this distribution for the specific * language governing permissions and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at LICENSE.txt. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ package org.opensolaris.opengrok.analysis.plain; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; import org.junit.Test; import org.opensolaris.opengrok.analysis.XrefWriter; public class XMLAnalyzerTest { @Test public void bug2225() throws IOException { String xmlText = "\n" + "\n" + " \n" + " \n" + ""; StringReader sr = new StringReader(xmlText); StringWriter sw = new StringWriter(); XMLAnalyzer.writeXref(sr, new XrefWriter(sw), null, null, null); String[] xref = sw.toString().split("\n"); // Reference to a Java class should have / instead of . in the path assertTrue(xref[3].contains("path=com/foo/bar/MyClass")); // Ordinary file names should not have .'s replaced assertTrue(xref[4].contains("path=README.txt")); } /** * XML special chars inside a string were not escaped if single quotes * were used around the string. Bug #15859. */ @Test public void xrefWithSpecialCharsInStringLiterals() throws IOException { StringReader input = new StringReader(" "); StringWriter output = new StringWriter(); XMLAnalyzer.writeXref(input, new XrefWriter(output), null, null, null); assertTrue(output.toString().contains("<betweensinglequotes>")); input = new StringReader("\"> "); output = new StringWriter(); XMLAnalyzer.writeXref(input, new XrefWriter(output), null, null, null); assertTrue(output.toString().contains("<betweendoublequotes>")); } }