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