1/* 2 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 6851834 27 * @summary This test verifies the HTML document generation for javadoc output. 28 * @library ../lib 29 * @modules jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.markup 30 * jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util 31 * jdk.javadoc/jdk.javadoc.internal.tool 32 * @build JavadocTester 33 * @author Bhavesh Patel 34 * @run main TestHtmlDocument 35 */ 36 37 38import jdk.javadoc.internal.doclets.formats.html.markup.*; 39 40import static jdk.javadoc.internal.doclets.toolkit.util.DocletConstants.NL; 41 42/** 43 * The class reads each file, complete with newlines, into a string to easily 44 * compare the existing markup with the generated markup. 45 */ 46public class TestHtmlDocument extends JavadocTester { 47 48 // Entry point 49 public static void main(String... args) throws Exception { 50 TestHtmlDocument tester = new TestHtmlDocument(); 51 tester.runTests(); 52 } 53 54 @Test 55 void test() { 56 checking("markup"); 57 // Check whether the generated markup is same as the existing markup. 58 String expected = readFile(testSrc, "testMarkup.html").replace("\n", NL); 59 String actual = generateHtmlTree(); 60 if (actual.equals(expected)) { 61 passed(""); 62 } else { 63 failed("expected content in " + testSrc("testMarkup.html") + "\n" 64 + "Actual output:\n" 65 + actual); 66 } 67 } 68 69 // Generate the HTML output using the HTML document generation within doclet. 70 public static String generateHtmlTree() { 71 // Document type for the HTML document 72 DocType htmlDocType = DocType.TRANSITIONAL; 73 HtmlTree html = new HtmlTree(HtmlTag.HTML); 74 HtmlTree head = new HtmlTree(HtmlTag.HEAD); 75 HtmlTree title = new HtmlTree(HtmlTag.TITLE); 76 // String content within the document 77 StringContent titleContent = new StringContent("Markup test"); 78 title.addContent(titleContent); 79 head.addContent(title); 80 // Test META tag 81 HtmlTree meta = new HtmlTree(HtmlTag.META); 82 meta.addAttr(HtmlAttr.NAME, "keywords"); 83 meta.addAttr(HtmlAttr.CONTENT, "testContent"); 84 head.addContent(meta); 85 // Test invalid META tag 86 HtmlTree invmeta = new HtmlTree(HtmlTag.META); 87 head.addContent(invmeta); 88 // Test LINK tag 89 HtmlTree link = new HtmlTree(HtmlTag.LINK); 90 link.addAttr(HtmlAttr.REL, "testRel"); 91 link.addAttr(HtmlAttr.HREF, "testLink.html"); 92 head.addContent(link); 93 // Test invalid LINK tag 94 HtmlTree invlink = new HtmlTree(HtmlTag.LINK); 95 head.addContent(invlink); 96 html.addContent(head); 97 // Comment within the document 98 Comment bodyMarker = new Comment("======== START OF BODY ========"); 99 html.addContent(bodyMarker); 100 HtmlTree body = new HtmlTree(HtmlTag.BODY); 101 Comment pMarker = new Comment("======== START OF PARAGRAPH ========"); 102 body.addContent(pMarker); 103 HtmlTree p = new HtmlTree(HtmlTag.P); 104 StringContent bodyContent = new StringContent( 105 "This document is generated from sample source code and HTML " + 106 "files with examples of a wide variety of Java language constructs: packages, " + 107 "subclasses, subinterfaces, nested classes, nested interfaces," + 108 "inheriting from other packages, constructors, fields," + 109 "methods, and so forth. "); 110 p.addContent(bodyContent); 111 StringContent anchorContent = new StringContent("Click Here"); 112 p.addContent(HtmlTree.A("testLink.html", anchorContent)); 113 StringContent pContent = new StringContent(" to <test> out a link."); 114 p.addContent(pContent); 115 body.addContent(p); 116 HtmlTree p1 = new HtmlTree(HtmlTag.P); 117 // Test another version of A tag. 118 HtmlTree anchor = new HtmlTree(HtmlTag.A); 119 anchor.addAttr(HtmlAttr.HREF, "testLink.html"); 120 anchor.addAttr(HtmlAttr.ID, "Another version of a tag"); 121 p1.addContent(anchor); 122 body.addContent(p1); 123 // Test for empty tags. 124 HtmlTree dl = new HtmlTree(HtmlTag.DL); 125 html.addContent(dl); 126 // Test for empty nested tags. 127 HtmlTree dlTree = new HtmlTree(HtmlTag.DL); 128 dlTree.addContent(new HtmlTree(HtmlTag.DT)); 129 dlTree.addContent(new HtmlTree (HtmlTag.DD)); 130 html.addContent(dlTree); 131 HtmlTree dlDisplay = new HtmlTree(HtmlTag.DL); 132 dlDisplay.addContent(new HtmlTree(HtmlTag.DT)); 133 HtmlTree dd = new HtmlTree (HtmlTag.DD); 134 StringContent ddContent = new StringContent("Test DD"); 135 dd.addContent(ddContent); 136 dlDisplay.addContent(dd); 137 body.addContent(dlDisplay); 138 StringContent emptyString = new StringContent(""); 139 body.addContent(emptyString); 140 Comment emptyComment = new Comment(""); 141 body.addContent(emptyComment); 142 HtmlTree hr = new HtmlTree(HtmlTag.HR); 143 body.addContent(hr); 144 html.addContent(body); 145 HtmlDocument htmlDoc = new HtmlDocument(htmlDocType, html); 146 return htmlDoc.toString(); 147 } 148} 149