test/com/sun/javadoc/testHtmlDocument/TestHtmlDocument.java

Mon, 13 Dec 2010 13:44:47 -0800

author
bpatel
date
Mon, 13 Dec 2010 13:44:47 -0800
changeset 793
ffbf2b2a8611
parent 766
90af8d87741f
child 1410
bfec2a1cc869
permissions
-rw-r--r--

7006270: Several javadoc regression tests are failing on windows
Reviewed-by: jjg

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

mercurial