Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/com/sun/javadoc/testCRLineSeparator/TestCRLineSeparator.java
48505 views
/*1* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 497948626* @summary Make sure tool parses CR line separators properly.27* @author jamieh28* @library ../lib/29* @build JavadocTester30* @build TestCRLineSeparator31* @run main TestCRLineSeparator32*/3334import java.io.*;35import java.util.*;3637public class TestCRLineSeparator extends JavadocTester {3839//Test information.40private static final String BUG_ID = "4979486-8014636";4142//Javadoc arguments.43private static final String[] ARGS = new String[] {44"-d", BUG_ID, "-sourcepath", ".", "pkg"45};4647//Input for string search tests.48private static final String[][] TEST = {49{BUG_ID + FS + "pkg" + FS + "MyClass.html", "Line 1" + NL + " Line 2"}50};5152private static final String[][] NEGATED_TEST = NO_TEST;5354/**55* The entry point of the test.56* @param args the array of command line arguments.57*/58public static void main(String[] args) throws Exception {59initFiles(new File(SRC_DIR), new File("."), "pkg");60TestCRLineSeparator tester = new TestCRLineSeparator();61run(tester, ARGS, TEST, NEGATED_TEST);62tester.printSummary();63}6465/**66* {@inheritDoc}67*/68public String getBugId() {69return BUG_ID;70}7172/**73* {@inheritDoc}74*/75public String getBugName() {76return getClass().getName();77}7879// recursively copy files from fromDir to toDir, replacing newlines80// with \r81static void initFiles(File fromDir, File toDir, String f) throws IOException {82File from_f = new File(fromDir, f);83File to_f = new File(toDir, f);84if (from_f.isDirectory()) {85to_f.mkdirs();86for (String child: from_f.list()) {87initFiles(from_f, to_f, child);88}89} else {90List<String> lines = new ArrayList<String>();91BufferedReader in = new BufferedReader(new FileReader(from_f));92try {93String line;94while ((line = in.readLine()) != null)95lines.add(line);96} finally {97in.close();98}99BufferedWriter out = new BufferedWriter(new FileWriter(to_f));100try {101for (String line: lines) {102out.write(line);103out.write("\r");104}105} finally {106out.close();107}108}109}110}111112113