GraphicalInstallerTest.java revision 3170:dc017a37aac5
1104478Ssam/* 2104630Ssam * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved. 3104478Ssam * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4139749Simp * 5104478Ssam * This code is free software; you can redistribute it and/or modify it 6104478Ssam * under the terms of the GNU General Public License version 2 only, as 7104478Ssam * published by the Free Software Foundation. 8104478Ssam * 9104478Ssam * This code is distributed in the hope that it will be useful, but WITHOUT 10104478Ssam * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11104478Ssam * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12104478Ssam * version 2 for more details (a copy is included in the LICENSE file that 13104478Ssam * accompanied this code). 14104478Ssam * 15104478Ssam * You should have received a copy of the GNU General Public License version 16104478Ssam * 2 along with this work; if not, write to the Free Software Foundation, 17104478Ssam * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18104478Ssam * 19104478Ssam * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20104478Ssam * or visit www.oracle.com if you need additional information or have any 21104478Ssam * questions. 22104478Ssam */ 23104478Ssam 24104478Ssam/* @test 25104478Ssam * @bug 6917288 26104478Ssam * @summary Unnamed nested class is not generated 27104478Ssam * @modules jdk.compiler 28104478Ssam */ 29104478Ssam 30104478Ssamimport java.io.*; 31104478Ssamimport java.util.*; 32104478Ssam 33104478Ssampublic class GraphicalInstallerTest { 34104478Ssam public static void main(String... args) throws Exception { 35104478Ssam new GraphicalInstallerTest().run(); 36104478Ssam } 37104478Ssam 38104478Ssam void run() throws Exception { 39104478Ssam File testSrc = new File(System.getProperty("test.src")); 40104478Ssam File classes = new File("classes"); 41104478Ssam classes.mkdirs(); 42104478Ssam List<String> opts = Arrays.asList("-d", classes.getPath()); 43104478Ssam int rc = compile(opts, new File(testSrc, "GraphicalInstaller.java")); 44104478Ssam if (rc != 0) { 45104478Ssam error("compilation failed: rc=" + rc); 46104478Ssam return; 47104478Ssam } 48104478Ssam 49104478Ssam check(classes, 50104478Ssam "GraphicalInstaller$1.class", 51104478Ssam "GraphicalInstaller$1X$1.class", 52104478Ssam "GraphicalInstaller$1X.class", 53104478Ssam "GraphicalInstaller$BackgroundInstaller.class", 54104478Ssam "GraphicalInstaller.class"); 55104478Ssam 56110519Ssam if (errors > 0) 57110519Ssam throw new Exception(errors + " errors occurred"); 58104478Ssam } 59104478Ssam 60104478Ssam /** 61108823Ssam * Compile files with given options. 62104478Ssam * Display any output from compiler, and return javac return code. 63104478Ssam */ 64104478Ssam int compile(List<String> opts, File... files) { 65104478Ssam List<String> args = new ArrayList<String>(); 66104478Ssam args.addAll(opts); 67104478Ssam for (File f: files) 68104478Ssam args.add(f.getPath()); 69104478Ssam StringWriter sw = new StringWriter(); 70104478Ssam PrintWriter pw = new PrintWriter(sw); 71104478Ssam int rc = com.sun.tools.javac.Main.compile(args.toArray(new String[args.size()]), pw); 72104478Ssam pw.close(); 73104478Ssam String out = sw.toString(); 74104478Ssam if (out.length() > 0) 75104478Ssam System.err.println(out); 76104478Ssam return rc; 77104478Ssam } 78104478Ssam 79104478Ssam /** 80104478Ssam * Check that a directory contains the expected files. 81104478Ssam */ 82104478Ssam void check(File dir, String... paths) { 83104478Ssam Set<String> found = new TreeSet<String>(Arrays.asList(dir.list())); 84104478Ssam Set<String> expect = new TreeSet<String>(Arrays.asList(paths)); 85104478Ssam if (found.equals(expect)) 86104478Ssam return; 87104478Ssam for (String f: found) { 88104478Ssam if (!expect.contains(f)) 89104478Ssam error("Unexpected file found: " + f); 90104478Ssam } 91104478Ssam for (String e: expect) { 92104478Ssam if (!found.contains(e)) 93104478Ssam error("Expected file not found: " + e); 94104478Ssam } 95104630Ssam } 96104478Ssam 97104478Ssam /** 98104478Ssam * Record an error message. 99104478Ssam */ 100104478Ssam void error(String msg) { 101104478Ssam System.err.println(msg); 102104478Ssam errors++; 103104478Ssam } 104104478Ssam 105104478Ssam int errors; 106104478Ssam} 107104478Ssam