Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/ByteValue/equals/equals002.java
41160 views
/*1* Copyright (c) 2002, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223package nsk.jdi.ByteValue.equals;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import com.sun.jdi.connect.*;31import java.io.*;32import java.util.*;33import java.util.jar.*;3435/**36* The test check up case when parameter has boundary values of primitive <br>37* types and when parameter is <code>null</code>.<br>38* Analyse of the method executing is performed by <code>PerformComparing</code>39* method.<br>40* First parameter of <code>PerformComparing</code> is static field of <code>testedObj</code>,<br>41* which is placed onto debugee's side. <br>42*43* Second parameter is got from debugee too:<br>44* Debugee has array of boundary values of each primitive type, <code>execTest</code> reads<br>45* them and calls <code>PerformComparing</code> for each of them.<br>46*/47public class equals002 {4849private final static String prefix = "nsk.jdi.ByteValue.equals.";50private final static String className = "equals002";51private final static String debuggerName = prefix + className;52private final static String debugeeName = debuggerName + "a";53private final static String objectToCheck = "testedObj";54private final static String arrPrimitives = "testedFields";5556private static int exitStatus;57private static Log log;58private static Debugee debugee;59private static ReferenceType refType;6061public static void main(String argv[]) {62System.exit(Consts.JCK_STATUS_BASE + run(argv, System.out));63}6465public static int run(String argv[], PrintStream out) {6667exitStatus = Consts.TEST_FAILED;6869ArgumentHandler argHandler = new ArgumentHandler(argv);70log = new Log(out, argHandler);7172debugee = Debugee.prepareDebugee(argHandler, log, debugeeName);73execTest();74debugee.quit();7576return exitStatus;77}7879private static void display(String msg) {80log.display("debugger> " + msg);81}8283private static void complain(String msg) {84log.complain("debugger FAILURE> " + msg + "\n");85}8687private static void execTest() {8889exitStatus = Consts.TEST_FAILED;9091refType = debugee.classByName(debugeeName);92if ( refType == null ) {93complain("Class '" + debugeeName + "' not found.");94return;95}9697// getting of object to check98Field field = refType.fieldByName(objectToCheck);99if ( field == null ) {100complain("Field '" + objectToCheck + "' not found.");101return;102}103Value objectValue = refType.getValue(field);104if ( objectValue == null ) {105complain("Field '" + objectToCheck + "' not initialized.");106return;107}108109// geting of array of primitive types110field = refType.fieldByName(arrPrimitives);111if ( field == null ) {112complain("Field '" + arrPrimitives + "' not found.");113return;114}115Value arrValue = refType.getValue(field);116if ( arrValue == null || !(arrValue instanceof ArrayReference) ) {117complain("Field '" + arrValue + "' is wrong.");118return;119}120ArrayReference primitivValues = (ArrayReference )arrValue;121122List fieldList = ((ClassType )objectValue.type()).allFields();123124Value v1, currentValue;125ByteValue value;126Field fldOtherType;127String msg;128129exitStatus = Consts.TEST_PASSED;130131// comparing loop132for (int i = 0; i < fieldList.size(); i++ ) {133field = (Field )fieldList.get(i);134log.display("");135msg = "***" + field;136v1 = ((ObjectReference )objectValue).getValue(field);137if ( !(v1 instanceof ByteValue) ) {138msg += " is not ByteValue (skipped)";139exitStatus = Consts.TEST_FAILED;140continue;141}142value = (ByteValue )v1;143144// comparing with debugee's fields145for (int j = 0; j < primitivValues.length(); j++) {146arrValue = primitivValues.getValue(j);147148fldOtherType = refType.fieldByName(((StringReference )arrValue).value());149if ( fldOtherType == null ) {150complain("Field '" + arrValue + "' not found.");151exitStatus = Consts.TEST_FAILED;152continue;153}154155currentValue = refType.getValue(fldOtherType);156157if ( !PerformComparing(value, currentValue) )158exitStatus = Consts.TEST_FAILED;159}160}161}162163private static boolean PerformComparing(ByteValue value, Object object ) {164boolean res = true;165String msg = "";166try {167if ( value.equals(object) ) {168if ( object instanceof ByteValue ) {169if ( value.value() == ((PrimitiveValue )object).byteValue() ) {170msg += "--> " + value + " == " + object;171} else {172msg += "##> " + value + " == " + object;173res = false;174}175}176else {177msg += "##> " + value + " == " + object178+ " : are different types " + value.type() + " - "179+ ((Value )object).type();180res = false;181}182if ( object == null ) {183msg += " ***Wrong result!!!***";184res = false;185}186} else {187if ( object instanceof ByteValue ) {188if ( value.value() != ((PrimitiveValue )object).byteValue() ) {189msg += "--> " + value + " != " + object;190} else {191msg += "##> " + value + " != " + object;192res = false;193}194}195else {196msg += "--> " + value + " != " + object;197}198}199} catch (Exception e) {200msg += " ***Unexpected " + e + "***";201res = false;202}203204if ( !res )205complain(msg);206else207display(msg);208209return res;210}211}212213214