test/tools/javap/T6866657.java

Thu, 25 Aug 2011 17:18:25 -0700

author
schien
date
Thu, 25 Aug 2011 17:18:25 -0700
changeset 1067
f497fac86cf9
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8-b02 for changeset b3c059de2a61

jjg@345 1 /*
ohair@554 2 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
jjg@345 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@345 4 *
jjg@345 5 * This code is free software; you can redistribute it and/or modify it
jjg@345 6 * under the terms of the GNU General Public License version 2 only, as
jjg@345 7 * published by the Free Software Foundation.
jjg@345 8 *
jjg@345 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@345 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@345 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@345 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@345 13 * accompanied this code).
jjg@345 14 *
jjg@345 15 * You should have received a copy of the GNU General Public License version
jjg@345 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@345 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@345 18 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * questions.
jjg@345 22 */
jjg@345 23
jjg@345 24
jjg@345 25 /*
jjg@345 26 * @test
jjg@345 27 * @bug 6866657
jjg@345 28 * @summary add byteLength() method to primary classfile types
jjg@345 29 */
jjg@345 30
jjg@345 31 import java.io.*;
jjg@345 32 import java.util.*;
jjg@345 33 import javax.tools.*;
jjg@345 34 import com.sun.tools.javap.*;
jjg@345 35
jjg@345 36 public class T6866657
jjg@345 37 {
jjg@345 38 public static void main(String... args) {
jjg@345 39 new T6866657().run();
jjg@345 40 }
jjg@345 41
jjg@345 42 void run() {
jjg@345 43 verify("java.lang.Object");
jjg@345 44 verify("java.lang.String");
jjg@345 45 verify("java.util.List");
jjg@345 46 verify("java.util.ArrayList");
jjg@345 47 if (errors > 0)
jjg@345 48 throw new Error(errors + " found.");
jjg@345 49 }
jjg@345 50
jjg@345 51 void verify(String className) {
jjg@345 52 try {
jjg@345 53 PrintWriter log = new PrintWriter(System.out);
jjg@345 54 JavaFileManager fileManager = JavapFileManager.create(null, log);
jjg@345 55 JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS);
jjg@345 56 if (fo == null) {
jjg@345 57 error("Can't find " + className);
jjg@345 58 } else {
jjg@345 59 JavapTask t = new JavapTask(log, fileManager, null);
jjg@345 60 t.handleOptions(new String[] { "-sysinfo", className });
jjg@345 61 JavapTask.ClassFileInfo cfInfo = t.read(fo);
jjg@345 62 expectEqual(cfInfo.cf.byteLength(), cfInfo.size);
jjg@345 63 }
jjg@345 64 } catch (Exception e) {
jjg@345 65 e.printStackTrace();
jjg@345 66 error("Exception: " + e);
jjg@345 67 }
jjg@345 68 }
jjg@345 69
jjg@345 70 void expectEqual(int found, int expected) {
jjg@345 71 if (found != expected)
jjg@345 72 error("bad value found: " + found + " expected: " + expected);
jjg@345 73 }
jjg@345 74
jjg@345 75 void error(String msg) {
jjg@345 76 System.err.println(msg);
jjg@345 77 errors++;
jjg@345 78 }
jjg@345 79
jjg@345 80 int errors;
jjg@345 81 }
jjg@345 82

mercurial