1 /* 2 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 package nsk.jdi.TypeComponent.isFinal; 25 26 import nsk.share.*; 27 import nsk.share.jpda.*; 28 import nsk.share.jdi.*; 29 30 import com.sun.jdi.*; 31 32 import java.io.*; 33 import java.util.*; 34 35 /** 36 * The debugger application of the test. 37 */ 38 public class isfinal004 { 39 40 //------------------------------------------------------- immutable common fields 41 42 final static String SIGNAL_READY = "ready"; 43 final static String SIGNAL_GO = "go"; 44 final static String SIGNAL_QUIT = "quit"; 45 46 private static int waitTime; 47 private static int exitStatus; 48 private static ArgumentHandler argHandler; 49 private static Log log; 50 private static Debugee debuggee; 51 private static ReferenceType debuggeeClass; 52 53 //------------------------------------------------------- mutable common fields 54 55 private final static String prefix = "nsk.jdi.TypeComponent.isFinal."; 56 private final static String className = "isfinal004"; 57 private final static String debuggerName = prefix + className; 58 private final static String debuggeeName = debuggerName + "a"; 59 60 //------------------------------------------------------- test specific fields 61 62 private final static String[] expectedFieldNames = {"f1", "f2", "f3"}; 63 private final static String[] expectedEnumFieldsNames = { "e1", "e2" }; 64 65 //------------------------------------------------------- immutable common methods 66 main(String argv[])67 public static void main(String argv[]) { 68 System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out)); 69 } 70 display(String msg)71 private static void display(String msg) { 72 log.display("debugger > " + msg); 73 } 74 complain(String msg)75 private static void complain(String msg) { 76 log.complain("debugger FAILURE > " + msg); 77 } 78 run(String argv[], PrintStream out)79 public static int run(String argv[], PrintStream out) { 80 81 exitStatus = Consts.TEST_PASSED; 82 83 argHandler = new ArgumentHandler(argv); 84 log = new Log(out, argHandler); 85 waitTime = argHandler.getWaitTime() * 60000; 86 87 debuggee = Debugee.prepareDebugee(argHandler, log, debuggeeName); 88 89 debuggeeClass = debuggee.classByName(debuggeeName); 90 if ( debuggeeClass == null ) { 91 complain("Class '" + debuggeeName + "' not found."); 92 exitStatus = Consts.TEST_FAILED; 93 } 94 95 execTest(); 96 97 debuggee.quit(); 98 99 return exitStatus; 100 } 101 102 //------------------------------------------------------ mutable common method 103 execTest()104 private static void execTest() { 105 //debuggee.receiveExpectedSignal(SIGNAL_GO); 106 107 for (int i=0; i < expectedFieldNames.length; i++) { 108 check(expectedFieldNames[i]); 109 display(""); 110 } 111 112 display("Checking completed!"); 113 } 114 115 //--------------------------------------------------------- test specific methods 116 check(String fieldName)117 private static void check (String fieldName) { 118 try { 119 ClassType checkedClass = (ClassType)debuggeeClass.fieldByName(fieldName).type(); 120 String className = checkedClass.name(); 121 122 for (int i = 0; i < expectedEnumFieldsNames.length; i++) { 123 Field foundField = checkedClass.fieldByName(expectedEnumFieldsNames[i]); 124 if (foundField != null) { 125 if (foundField.isFinal()) { 126 display("enum " + className + " has final field " + expectedEnumFieldsNames[i]); 127 display("\t of type " + className); 128 } else { 129 complain("enum " + className + " has not-final field " + expectedEnumFieldsNames[i]); 130 complain("\t of type " + className); 131 exitStatus = Consts.TEST_FAILED; 132 } 133 } else { 134 complain("enum " + className + " does not have field " + expectedEnumFieldsNames[i]); 135 complain("\t of type " + className); 136 exitStatus = Consts.TEST_FAILED; 137 } 138 } 139 } catch (Exception e) { 140 complain("Unexpected exception while checking of " + className + ": " + e); 141 e.printStackTrace(System.out); 142 exitStatus = Consts.TEST_FAILED; 143 } 144 } 145 } 146 //--------------------------------------------------------- test specific classes 147