1 /* 2 * Copyright (c) 2000, 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 25 package nsk.jdi.Field.equals; 26 27 import nsk.share.*; 28 import nsk.share.jpda.*; 29 import nsk.share.jdi.*; 30 31 import com.sun.jdi.*; 32 import java.util.*; 33 import java.io.*; 34 35 public class equals005 { 36 private static Log log; 37 private final static String prefix = "nsk.jdi.Field.equals."; 38 private final static String className = "equals005"; 39 private final static String debugerName = prefix + className; 40 private final static String debugeeName = debugerName + "a"; 41 main(String argv[])42 public static void main(String argv[]) { 43 System.exit(95 + run(argv, System.out)); 44 } 45 run(String argv[], PrintStream out)46 public static int run(String argv[], PrintStream out) { 47 ArgumentHandler argHandler = new ArgumentHandler(argv); 48 log = new Log(out, argHandler); 49 Binder binder = new Binder(argHandler, log); 50 Debugee debugee = binder.bindToDebugee(debugeeName 51 + (argHandler.verbose() ? " -verbose" : "")); 52 IOPipe pipe = new IOPipe(debugee); 53 boolean testFailed = false; 54 List fields; 55 56 // Connect with debugee and resume it 57 debugee.redirectStderr(out); 58 debugee.resume(); 59 String line = pipe.readln(); 60 if (line == null) { 61 log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null"); 62 return 2; 63 } 64 if (!line.equals("ready")) { 65 log.complain("debuger FAILURE> UNEXPECTED debugee's signal - " 66 + line); 67 return 2; 68 } 69 else { 70 log.display("debuger> debugee's \"ready\" signal recieved."); 71 } 72 73 // Get all fields from debugee 74 ReferenceType refType = debugee.classByName(debugeeName); 75 if (refType == null) { 76 log.complain("debuger FAILURE> Class " + debugeeName 77 + " not found."); 78 return 2; 79 } 80 try { 81 fields = refType.allFields(); 82 } catch (Exception e) { 83 log.complain("debuger FAILURE> Can't get fields from class"); 84 log.complain("debuger FAILURE> Exception: " + e); 85 return 2; 86 } 87 int totalFields = fields.size(); 88 if (totalFields < 1) { 89 log.complain("debuger FAILURE> Total number of fields read " 90 + totalFields); 91 return 2; 92 } 93 log.display("debuger> Total fields found: " + totalFields); 94 Iterator fieldsIterator = fields.iterator(); 95 for (int i = 0; fieldsIterator.hasNext(); i++) { 96 Field srcField = (Field)fieldsIterator.next(); 97 String name = srcField.name(); 98 Field checkField; 99 boolean fieldsEqual; 100 101 if (name == null) { 102 log.complain("debuger FAILURE 1> Name is null for " + i 103 + " field"); 104 testFailed = true; 105 continue; 106 } 107 try { 108 checkField = refType.fieldByName(name); 109 } catch (Exception e) { 110 log.complain("debuger FAILURE 2> Can't create field to check " 111 + "for field " + name); 112 testFailed = true; 113 continue; 114 } 115 fieldsEqual = srcField.equals(checkField); 116 log.display("debuger> Fields " + name + " and " + checkField.name() 117 + " compared, result " + fieldsEqual); 118 if (!fieldsEqual) { 119 // Fields declared in the same class and mirror the same 120 // fields are equal 121 log.complain("debuger FAILURE 3> Same fields with name " + name 122 + " are not equal. Expected result: equal."); 123 testFailed = true; 124 continue; 125 } 126 } 127 pipe.println("quit"); 128 debugee.waitFor(); 129 int status = debugee.getStatus(); 130 if (testFailed) { 131 log.complain("debuger FAILURE> TEST FAILED"); 132 return 2; 133 } else { 134 if (status == 95) { 135 log.display("debuger> expected Debugee's exit " 136 + "status - " + status); 137 return 0; 138 } else { 139 log.complain("debuger FAILURE> UNEXPECTED Debugee's exit " 140 + "status (not 95) - " + status); 141 return 2; 142 } 143 } 144 } 145 } 146