Author: ltheussl Date: Tue Apr 7 11:58:36 2009 New Revision: 762718 URL: http://svn.apache.org/viewvc?rev=762718&view=rev Log: Improve test coverage
Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptUtilsTest.java (with props) Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java?rev=762718&r1=762717&r2=762718&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptParser.java Tue Apr 7 11:58:36 2009 @@ -1759,7 +1759,7 @@ public ListBreak( int indent, String firstLine ) throws AptParseException { - super( AptParser.LIST_BREAK, indent ); + super( AptParser.LIST_BREAK, indent, firstLine ); } /** {...@inheritdoc} */ @@ -2674,7 +2674,7 @@ public HorizontalRule( int indent, String firstLine ) throws AptParseException { - super( HORIZONTAL_RULE, indent ); + super( HORIZONTAL_RULE, indent, firstLine ); } /** {...@inheritdoc} */ @@ -2699,7 +2699,7 @@ public PageBreak( int indent, String firstLine ) throws AptParseException { - super( PG_BREAK, indent ); + super( PG_BREAK, indent, firstLine ); } /** {...@inheritdoc} */ Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java?rev=762718&r1=762717&r2=762718&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/main/java/org/apache/maven/doxia/module/apt/AptSink.java Tue Apr 7 11:58:36 2009 @@ -667,21 +667,19 @@ /** {...@inheritdoc} */ public void tableCell_() { - tableCell_( false ); + endTableCell(); } /** {...@inheritdoc} */ public void tableHeaderCell_() { - tableCell_( true ); + endTableCell(); } /** * Ends a table cell. - * - * @param headerRow If this cell is part of a header row. */ - private void tableCell_( boolean headerRow ) + private void endTableCell() { buffer.append( TABLE_CELL_SEPARATOR_MARKUP ); cellCount++; Added: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptUtilsTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptUtilsTest.java?rev=762718&view=auto ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptUtilsTest.java (added) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptUtilsTest.java Tue Apr 7 11:58:36 2009 @@ -0,0 +1,162 @@ +package org.apache.maven.doxia.module.apt; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import junit.framework.TestCase; + +/** + * Test AptUtils. + * + * @author ltheussl + * @version $Id$ + */ +public class AptUtilsTest + extends TestCase +{ + /** + * Test of isExternalLink method, of class AptUtils. + */ + public void testIsExternalLink() + { + String link = "http://maven.apache.org/"; + assertTrue( "Should be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "https://maven.apache.org/"; + assertTrue( "Should be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "HTTPS://MAVEN.APACHE.ORG/"; + assertTrue( "Should be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "ftp:/maven.apache.org/"; + assertTrue( "Should be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "mailto:ma...@apache.org"; + assertTrue( "Should be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "file:/index.html"; + assertTrue( "Should be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "resource_type://domain:port/filepathname?query_string#anchor"; + assertTrue( "Should be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "index.html"; + assertFalse( "Should NOT be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "example.pdf"; + assertFalse( "Should NOT be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "./index.html"; + assertFalse( "Should NOT be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "../index.html"; + assertFalse( "Should NOT be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + // Windows style separators "\" are not allowed + + link = "file:\\index.html"; + assertFalse( "Should NOT be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = ".\\index.html"; + assertFalse( "Should NOT be an external link: " + link, + AptUtils.isExternalLink( link ) ); + + link = "..\\index.html"; + assertFalse( "Should NOT be an external link: " + link, + AptUtils.isExternalLink( link ) ); + } + + /** + * Test of isInternalLink method, of class AptUtils. + */ + public void testIsInternalLink() + { + String link = "index.html"; + assertTrue( "Should be an internal link: " + link, AptUtils.isInternalLink( link ) ); + link = "file:/index.html"; + assertFalse( "Should NOT be an internal link: " + link, AptUtils.isInternalLink( link ) ); + link = "./index.html"; + assertFalse( "Should NOT be an internal link: " + link, AptUtils.isInternalLink( link ) ); + } + + /** + * Test of isLocalLink method, of class AptUtils. + */ + public void testIsLocalLink() + { + String link = "/index.html"; + assertTrue( "Should be a local link: " + link, AptUtils.isLocalLink( link ) ); + + link = "./index.html"; + assertTrue( "Should be a local link: " + link, AptUtils.isLocalLink( link ) ); + + link = "../index.html"; + assertTrue( "Should be a local link: " + link, AptUtils.isLocalLink( link ) ); + + link = "index.html"; + assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) ); + + link = ".\\index.html"; + assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) ); + + link = "\\index.html"; + assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) ); + + link = "..\\index.html"; + assertFalse( "Should NOT be a local link: " + link, AptUtils.isLocalLink( link ) ); + } + + /** + * Test of encodeAnchor method, of class AptUtils. + */ + public void testEncodeAnchor() + { + assertNull( AptUtils.encodeAnchor( null ) ); + assertEquals( "a123_:_.-aBc", AptUtils.encodeAnchor( " 12!3 :_.&-a)Bc " ) ); + } + + /** + * Test of encodeFragment method, of class AptUtils. + */ + public void testEncodeFragment() + { + assertNull( AptUtils.encodeFragment( null ) ); + assertEquals( "abc0d", AptUtils.encodeFragment( "a B&c0)D" ) ); + } + + /** + * Test of linkToKey method, of class AptUtils. + */ + public void testLinkToKey() + { + assertEquals( "abc56au", AptUtils.linkToKey( "aB$%C56 a&\\/'U" ) ); + } +} Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptUtilsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/doxia/doxia/trunk/doxia-modules/doxia-module-apt/src/test/java/org/apache/maven/doxia/module/apt/AptUtilsTest.java ------------------------------------------------------------------------------ svn:keywords = "Author Date Id Revision" Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java?rev=762718&r1=762717&r2=762718&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/main/java/org/apache/maven/doxia/module/xdoc/XdocSink.java Tue Apr 7 11:58:36 2009 @@ -457,13 +457,13 @@ MutableAttributeSet att = new SinkEventAttributeSet(); + att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) ); + if ( target != null ) { att.addAttribute( Attribute.TARGET, target ); } - att.addAttribute( Attribute.HREF, HtmlTools.escapeHTML( name ) ); - writeStartTag( Tag.A, att ); } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java?rev=762718&r1=762717&r2=762718&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocParserTest.java Tue Apr 7 11:58:36 2009 @@ -27,6 +27,7 @@ import java.util.Iterator; import org.apache.maven.doxia.parser.AbstractParserTest; +import org.apache.maven.doxia.parser.ParseException; import org.apache.maven.doxia.parser.Parser; import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkEventElement; @@ -168,6 +169,16 @@ assertEquals( "author_", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "head_", ( (SinkEventElement) it.next() ).getName() ); assertFalse( it.hasNext() ); + + text = "<head><meta name=\"security\" content=\"low\"/></head>"; + sink.reset(); + parser.parse( text, sink ); + it = sink.getEventList().iterator(); + + assertEquals( "head", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "head_", ( (SinkEventElement) it.next() ).getName() ); + assertFalse( it.hasNext() ); } /** @throws Exception */ @@ -322,7 +333,8 @@ public void testSectionIdAnchor() throws Exception { - String text = "<section name=\"test\" id=\"test-id\">This is a test.</section>"; + String text = "<section name=\"test\" id=\"test-id\">This is a test." + + "<subsection name=\"sub-test\" id=\"sub-id\">Sub-section</subsection></section>"; SinkEventTestingSink sink = new SinkEventTestingSink(); @@ -334,15 +346,98 @@ assertEquals( "anchor", anchorEvt.getName() ); assertEquals( "test-id", anchorEvt.getArgs()[0] ); - assertEquals( "anchor_", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "section1", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "sectionTitle1", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "text", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "sectionTitle1_", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "text", ( (SinkEventElement) it.next() ).getName() ); + + anchorEvt = (SinkEventElement) it.next(); + assertEquals( "anchor", anchorEvt.getName() ); + assertEquals( "sub-id", anchorEvt.getArgs()[0] ); + assertEquals( "anchor_", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "section2", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "sectionTitle2", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "text", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "sectionTitle2_", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "text", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "section2_", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "section1_", ( (SinkEventElement) it.next() ).getName() ); assertFalse( it.hasNext() ); } + /** + * Test script block. + * + * @throws java.lang.Exception if any. + */ + public void testJavaScript() + throws Exception + { + String text = "<script type=\"text/javascript\"><![CDATA[alert(\"Hello!\");]]></script>"; + + SinkEventTestingSink sink = new SinkEventTestingSink(); + + parser.parse( text, sink ); + + Iterator it = sink.getEventList().iterator(); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "rawText", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertFalse( it.hasNext() ); + } + + /** + * Test unknown tags. + * + * @throws java.lang.Exception if any. + */ + public void testUnknown() + throws Exception + { + String text = "<applet><param name=\"name\" value=\"value\"/><unknown/></applet>"; + + SinkEventTestingSink sink = new SinkEventTestingSink(); + + parser.parse( text, sink ); + + Iterator it = sink.getEventList().iterator(); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertFalse( it.hasNext() ); + } + + /** + * Test invalid macro tags. + */ + public void testMacroExceptions() + { + SinkEventTestingSink sink = new SinkEventTestingSink(); + assertParseException( sink, "<macro/>" ); + assertParseException( sink, "<macro name=\"\"/>" ); + assertParseException( sink, "<macro name=\"name\"><param name=\"\" value=\"value\"/></macro>" ); + assertParseException( sink, "<macro name=\"name\"><param name=\"name\" value=\"\"/></macro>" ); + assertParseException( sink, "<macro name=\"name\"><param value=\"value\"/></macro>" ); + assertParseException( sink, "<macro name=\"name\"><param name=\"name\"/></macro>" ); + assertParseException( sink, "<macro name=\"unknown\"></macro>" ); + } + + private void assertParseException( Sink sink, String text ) + { + try + { + parser.parse( text, sink ); + + fail( "Should not be parseable: '" + text + "'" ); + } + catch ( ParseException ex ) + { + assertNotNull( ex ); + } + } } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java?rev=762718&r1=762717&r2=762718&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xdoc/src/test/java/org/apache/maven/doxia/module/xdoc/XdocSinkTest.java Tue Apr 7 11:58:36 2009 @@ -23,7 +23,9 @@ import org.apache.maven.doxia.sink.AbstractSinkTest; import org.apache.maven.doxia.util.HtmlTools; +import java.io.StringWriter; import java.io.Writer; +import org.apache.maven.doxia.sink.SinkEventAttributeSet; /** * @author <a href="mailto:ja...@maven.org">Jason van Zyl</a> @@ -231,5 +233,55 @@ return "~,_=,_-,_+,_*,_[,_],_<,_>,_{,_},_\\"; } + /** + * Test verbatim. + */ + public void testBoxedVerbatim() + { + Writer writer = new StringWriter(); + XdocSink sink = null; + + try + { + sink = new XdocSink( writer ); + + sink.verbatim( null ); + sink.verbatim_(); + sink.verbatim( SinkEventAttributeSet.BOXED ); + sink.verbatim_(); + sink.verbatim( new SinkEventAttributeSet( new String[] {SinkEventAttributeSet.WIDTH, "20%"} ) ); + sink.verbatim_(); + } + finally + { + sink.close(); + } + + assertEquals( "<pre></pre><source></source><pre width=\"20%\"></pre>", writer.toString() ); + } + + /** + * Test link. + */ + public void testLinkWithTarget() + { + Writer writer = new StringWriter(); + XdocSink sink = null; + + try + { + sink = new XdocSink( writer ); + + sink.link( "name", (String) null ); + sink.link_(); + sink.link( "name", "nirvana" ); + sink.link_(); + } + finally + { + sink.close(); + } + assertEquals( "<a href=\"name\"></a><a href=\"name\" target=\"nirvana\"></a>", writer.toString() ); + } } Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java?rev=762718&r1=762717&r2=762718&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/main/java/org/apache/maven/doxia/module/xhtml/XhtmlParser.java Tue Apr 7 11:58:36 2009 @@ -94,6 +94,10 @@ sink.date_(); } + else + { + sink.unknown( "meta", new String[] {name, content}, attribs ); + } } /* * The ADDRESS element may be used by authors to supply contact information Modified: maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java URL: http://svn.apache.org/viewvc/maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java?rev=762718&r1=762717&r2=762718&view=diff ============================================================================== --- maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java (original) +++ maven/doxia/doxia/trunk/doxia-modules/doxia-module-xhtml/src/test/java/org/apache/maven/doxia/module/xhtml/XhtmlParserTest.java Tue Apr 7 11:58:36 2009 @@ -19,12 +19,10 @@ * under the License. */ -import java.io.StringWriter; import java.util.Iterator; import org.apache.maven.doxia.parser.AbstractParserTest; import org.apache.maven.doxia.parser.Parser; -import org.apache.maven.doxia.sink.Sink; import org.apache.maven.doxia.sink.SinkEventElement; import org.apache.maven.doxia.sink.SinkEventTestingSink; @@ -70,7 +68,7 @@ throws Exception { String text = "<head><title>Title</title><meta name=\"author\" content=\"Author\" />" - + "<meta name=\"date\" content=\"Date\" /></head>"; + + "<meta name=\"date\" content=\"Date\" /><meta name=\"security\" content=\"low\"/></head>"; SinkEventTestingSink sink = new SinkEventTestingSink(); @@ -88,6 +86,7 @@ assertEquals( "date", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "text", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "date_", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); assertEquals( "head_", ( (SinkEventElement) it.next() ).getName() ); assertFalse( it.hasNext() ); } @@ -108,4 +107,26 @@ assertEquals( "verbatim_", ( (SinkEventElement) it.next() ).getName() ); assertFalse( it.hasNext() ); } + + /** + * Test unknown tags. + * + * @throws java.lang.Exception if any. + */ + public void testUnknown() + throws Exception + { + String text = "<applet><param name=\"name\" value=\"value\"/><unknown/></applet>"; + + SinkEventTestingSink sink = new SinkEventTestingSink(); + + ( (XhtmlParser) createParser() ).parse( text, sink ); + + Iterator it = sink.getEventList().iterator(); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertEquals( "unknown", ( (SinkEventElement) it.next() ).getName() ); + assertFalse( it.hasNext() ); + } }