1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/tools/javac/6917288/GraphicalInstallerTest.java Wed Apr 27 01:34:52 2016 +0800 1.3 @@ -0,0 +1,106 @@ 1.4 +/* 1.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + */ 1.26 + 1.27 + 1.28 +/* @test 1.29 + * @bug 6917288 1.30 + * @summary Unnamed nested class is not generated 1.31 + */ 1.32 + 1.33 +import java.io.*; 1.34 +import java.util.*; 1.35 + 1.36 +public class GraphicalInstallerTest { 1.37 + public static void main(String... args) throws Exception { 1.38 + new GraphicalInstallerTest().run(); 1.39 + } 1.40 + 1.41 + void run() throws Exception { 1.42 + File testSrc = new File(System.getProperty("test.src")); 1.43 + File classes = new File("classes"); 1.44 + classes.mkdirs(); 1.45 + List<String> opts = Arrays.asList("-d", classes.getPath()); 1.46 + int rc = compile(opts, new File(testSrc, "GraphicalInstaller.java")); 1.47 + if (rc != 0) { 1.48 + error("compilation failed: rc=" + rc); 1.49 + return; 1.50 + } 1.51 + 1.52 + check(classes, 1.53 + "GraphicalInstaller$1.class", 1.54 + "GraphicalInstaller$1X$1.class", 1.55 + "GraphicalInstaller$1X.class", 1.56 + "GraphicalInstaller$BackgroundInstaller.class", 1.57 + "GraphicalInstaller.class"); 1.58 + 1.59 + if (errors > 0) 1.60 + throw new Exception(errors + " errors occurred"); 1.61 + } 1.62 + 1.63 + /** 1.64 + * Compile files with given options. 1.65 + * Display any output from compiler, and return javac return code. 1.66 + */ 1.67 + int compile(List<String> opts, File... files) { 1.68 + List<String> args = new ArrayList<String>(); 1.69 + args.addAll(opts); 1.70 + for (File f: files) 1.71 + args.add(f.getPath()); 1.72 + StringWriter sw = new StringWriter(); 1.73 + PrintWriter pw = new PrintWriter(sw); 1.74 + int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); 1.75 + pw.close(); 1.76 + String out = sw.toString(); 1.77 + if (out.length() > 0) 1.78 + System.err.println(out); 1.79 + return rc; 1.80 + } 1.81 + 1.82 + /** 1.83 + * Check that a directory contains the expected files. 1.84 + */ 1.85 + void check(File dir, String... paths) { 1.86 + Set<String> found = new TreeSet<String>(Arrays.asList(dir.list())); 1.87 + Set<String> expect = new TreeSet<String>(Arrays.asList(paths)); 1.88 + if (found.equals(expect)) 1.89 + return; 1.90 + for (String f: found) { 1.91 + if (!expect.contains(f)) 1.92 + error("Unexpected file found: " + f); 1.93 + } 1.94 + for (String e: expect) { 1.95 + if (!found.contains(e)) 1.96 + error("Expected file not found: " + e); 1.97 + } 1.98 + } 1.99 + 1.100 + /** 1.101 + * Record an error message. 1.102 + */ 1.103 + void error(String msg) { 1.104 + System.err.println(msg); 1.105 + errors++; 1.106 + } 1.107 + 1.108 + int errors; 1.109 +}