2015-11-29 02:52:17 +00:00
|
|
|
/*
|
2019-01-30 11:09:26 +00:00
|
|
|
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
|
2015-11-29 02:52:17 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 6851834
|
|
|
|
* @summary This test verifies the HTML document generation for javadoc output.
|
2018-12-21 18:38:33 +00:00
|
|
|
* @library ../../lib
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
* @modules jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.markup
|
|
|
|
* jdk.javadoc/jdk.javadoc.internal.doclets.toolkit.util
|
|
|
|
* jdk.javadoc/jdk.javadoc.internal.tool
|
2018-12-21 18:38:33 +00:00
|
|
|
* @build javadoc.tester.*
|
2015-11-29 02:52:17 +00:00
|
|
|
* @run main TestHtmlDocument
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import jdk.javadoc.internal.doclets.formats.html.markup.*;
|
|
|
|
|
|
|
|
import static jdk.javadoc.internal.doclets.toolkit.util.DocletConstants.NL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The class reads each file, complete with newlines, into a string to easily
|
|
|
|
* compare the existing markup with the generated markup.
|
|
|
|
*/
|
2018-12-21 18:38:33 +00:00
|
|
|
import javadoc.tester.JavadocTester;
|
|
|
|
|
2015-11-29 02:52:17 +00:00
|
|
|
public class TestHtmlDocument extends JavadocTester {
|
|
|
|
|
|
|
|
// Entry point
|
|
|
|
public static void main(String... args) throws Exception {
|
|
|
|
TestHtmlDocument tester = new TestHtmlDocument();
|
|
|
|
tester.runTests();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-12-21 18:38:33 +00:00
|
|
|
public void test() {
|
2015-11-29 02:52:17 +00:00
|
|
|
checking("markup");
|
|
|
|
// Check whether the generated markup is same as the existing markup.
|
|
|
|
String expected = readFile(testSrc, "testMarkup.html").replace("\n", NL);
|
|
|
|
String actual = generateHtmlTree();
|
|
|
|
if (actual.equals(expected)) {
|
|
|
|
passed("");
|
|
|
|
} else {
|
|
|
|
failed("expected content in " + testSrc("testMarkup.html") + "\n"
|
|
|
|
+ "Actual output:\n"
|
|
|
|
+ actual);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the HTML output using the HTML document generation within doclet.
|
|
|
|
public static String generateHtmlTree() {
|
|
|
|
// Document type for the HTML document
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree html = new HtmlTree(TagName.HTML);
|
|
|
|
HtmlTree head = new HtmlTree(TagName.HEAD);
|
|
|
|
HtmlTree title = new HtmlTree(TagName.TITLE);
|
2015-11-29 02:52:17 +00:00
|
|
|
// String content within the document
|
2021-02-23 19:29:41 +00:00
|
|
|
TextBuilder titleContent = new TextBuilder("Markup test");
|
2019-03-11 19:59:45 +00:00
|
|
|
title.add(titleContent);
|
|
|
|
head.add(title);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Test META tag
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree meta = new HtmlTree(TagName.META);
|
2019-03-11 19:59:45 +00:00
|
|
|
meta.put(HtmlAttr.NAME, "keywords");
|
|
|
|
meta.put(HtmlAttr.CONTENT, "testContent");
|
|
|
|
head.add(meta);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Test invalid META tag
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree invmeta = new HtmlTree(TagName.META);
|
2019-03-11 19:59:45 +00:00
|
|
|
head.add(invmeta);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Test LINK tag
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree link = new HtmlTree(TagName.LINK);
|
2019-03-11 19:59:45 +00:00
|
|
|
link.put(HtmlAttr.REL, "testRel");
|
|
|
|
link.put(HtmlAttr.HREF, "testLink.html");
|
|
|
|
head.add(link);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Test invalid LINK tag
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree invlink = new HtmlTree(TagName.LINK);
|
2019-03-11 19:59:45 +00:00
|
|
|
head.add(invlink);
|
|
|
|
html.add(head);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Comment within the document
|
|
|
|
Comment bodyMarker = new Comment("======== START OF BODY ========");
|
2019-03-11 19:59:45 +00:00
|
|
|
html.add(bodyMarker);
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree body = new HtmlTree(TagName.BODY);
|
2015-11-29 02:52:17 +00:00
|
|
|
Comment pMarker = new Comment("======== START OF PARAGRAPH ========");
|
2019-03-11 19:59:45 +00:00
|
|
|
body.add(pMarker);
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree p = new HtmlTree(TagName.P);
|
2021-02-23 19:29:41 +00:00
|
|
|
TextBuilder bodyContent = new TextBuilder(
|
2015-11-29 02:52:17 +00:00
|
|
|
"This document is generated from sample source code and HTML " +
|
|
|
|
"files with examples of a wide variety of Java language constructs: packages, " +
|
|
|
|
"subclasses, subinterfaces, nested classes, nested interfaces," +
|
|
|
|
"inheriting from other packages, constructors, fields," +
|
|
|
|
"methods, and so forth. ");
|
2019-03-11 19:59:45 +00:00
|
|
|
p.add(bodyContent);
|
2021-02-23 19:29:41 +00:00
|
|
|
TextBuilder anchorContent = new TextBuilder("Click Here");
|
2019-03-11 19:59:45 +00:00
|
|
|
p.add(HtmlTree.A("testLink.html", anchorContent));
|
2021-02-23 19:29:41 +00:00
|
|
|
TextBuilder pContent = new TextBuilder(" to <test> out a link.");
|
2019-03-11 19:59:45 +00:00
|
|
|
p.add(pContent);
|
|
|
|
body.add(p);
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree p1 = new HtmlTree(TagName.P);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Test another version of A tag.
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree anchor = new HtmlTree(TagName.A);
|
2019-03-11 19:59:45 +00:00
|
|
|
anchor.put(HtmlAttr.HREF, "testLink.html");
|
|
|
|
anchor.put(HtmlAttr.ID, "Another version of a tag");
|
|
|
|
p1.add(anchor);
|
|
|
|
body.add(p1);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Test for empty tags.
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree dl = new HtmlTree(TagName.DL);
|
2019-03-11 19:59:45 +00:00
|
|
|
html.add(dl);
|
2015-11-29 02:52:17 +00:00
|
|
|
// Test for empty nested tags.
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree dlTree = new HtmlTree(TagName.DL);
|
|
|
|
dlTree.add(new HtmlTree(TagName.DT));
|
|
|
|
dlTree.add(new HtmlTree (TagName.DD));
|
2019-03-11 19:59:45 +00:00
|
|
|
html.add(dlTree);
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree dlDisplay = new HtmlTree(TagName.DL);
|
|
|
|
dlDisplay.add(new HtmlTree(TagName.DT));
|
|
|
|
HtmlTree dd = new HtmlTree (TagName.DD);
|
2021-02-23 19:29:41 +00:00
|
|
|
TextBuilder ddContent = new TextBuilder("Test DD");
|
2019-03-11 19:59:45 +00:00
|
|
|
dd.add(ddContent);
|
|
|
|
dlDisplay.add(dd);
|
|
|
|
body.add(dlDisplay);
|
2021-02-23 19:29:41 +00:00
|
|
|
TextBuilder emptyString = new TextBuilder("");
|
2019-03-11 19:59:45 +00:00
|
|
|
body.add(emptyString);
|
2015-11-29 02:52:17 +00:00
|
|
|
Comment emptyComment = new Comment("");
|
2019-03-11 19:59:45 +00:00
|
|
|
body.add(emptyComment);
|
2020-03-18 20:20:13 +00:00
|
|
|
HtmlTree hr = new HtmlTree(TagName.HR);
|
2019-03-11 19:59:45 +00:00
|
|
|
body.add(hr);
|
|
|
|
html.add(body);
|
2019-01-30 11:09:26 +00:00
|
|
|
HtmlDocument htmlDoc = new HtmlDocument(html);
|
2015-11-29 02:52:17 +00:00
|
|
|
return htmlDoc.toString();
|
|
|
|
}
|
|
|
|
}
|