Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ObjectReference/SetValues/setvalues001a.java
41161 views
/*1* Copyright (c) 2001, 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.jdwp.ObjectReference.SetValues;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdwp.*;2829import java.io.*;3031/**32* This class represents debuggee part of the test.33*/34public class setvalues001a {3536public static final String OBJECT_FIELD_NAME = "object";3738static ArgumentHandler argumentHandler = null;39static Log log = null;4041public static void main(String args[]) {42setvalues001a _setvalues001a = new setvalues001a();43System.exit(setvalues001.JCK_STATUS_BASE + _setvalues001a.runIt(args, System.err));44}4546public int runIt(String args[], PrintStream out) {47// make log for debugee messages48ArgumentHandler argumentHandler = new ArgumentHandler(args);49log = new Log(out, argumentHandler);5051// make communication pipe to debugger52log.display("Creating pipe");53IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);5455// ensure tested class loaded56log.display("Creating object of all required classes");57OriginalValuesClass original = new OriginalValuesClass();58TargetValuesClass target = new TargetValuesClass();59ObjectClass.object = new TestedClass();6061// send debugger signal READY62log.display("Sending signal to debugger: " + setvalues001.READY);63pipe.println(setvalues001.READY);6465// wait for signal RUN from debugeer66log.display("Waiting for signal from debugger: " + setvalues001.RUN);67String signal = pipe.readln();68log.display("Received signal from debugger: " + signal);69// check received signal70if (signal == null || !signal.equals(setvalues001.RUN)) {71log.complain("Unexpected communication signal from debugee: " + signal72+ " (expected: " + setvalues001.RUN + ")");73log.display("Debugee FAILED");74return setvalues001.FAILED;75}7677// check assigned values78if (checkValues(ObjectClass.object)) {79log.display("Sending signal to debugger: " + setvalues001.DONE);80pipe.println(setvalues001.DONE);81} else {82log.display("Sending signal to debugger: " + setvalues001.ERROR);83pipe.println(setvalues001.ERROR);84}8586// wait for signal QUIT from debugeer87log.display("Waiting for signal from debugger: " + setvalues001.QUIT);88signal = pipe.readln();89log.display("Received signal from debugger: " + signal);90// check received signal91if (! signal.equals(setvalues001.QUIT)) {92log.complain("Unexpected communication signal from debugee: " + signal93+ " (expected: " + setvalues001.QUIT + ")");94log.display("Debugee FAILED");95return setvalues001.FAILED;96}9798// exit debugee99log.display("Debugee PASSED");100return setvalues001.PASSED;101}102103// check values of static fields for both classes104static boolean checkValues(TestedClass object) {105int different = 0;106log.display("Checking that values have been set correctly:");107108// check value of the field109if (object.booleanValue != TargetValuesClass.booleanValue) {110different++;111log.complain(" booleanValue = " + object.booleanValue + "\n"112+ " setting: " + OriginalValuesClass.booleanValue113+ " -> " + TargetValuesClass.booleanValue);114if (object.booleanValue == OriginalValuesClass.booleanValue) {115log.complain(" not changed!");116} else {117log.complain(" changed incorrectly!");118}119} else {120log.display(" booleanValue: " + OriginalValuesClass.booleanValue121+ " -> " + TargetValuesClass.booleanValue);122}123124// check value of the field125if (object.byteValue != TargetValuesClass.byteValue) {126different++;127log.complain(" byteValue = " + object.byteValue + "\n"128+ " setting: " + OriginalValuesClass.byteValue129+ " -> " + TargetValuesClass.byteValue);130if (object.byteValue == OriginalValuesClass.byteValue) {131log.complain(" not changed!");132} else {133log.complain(" changed incorrectly!");134}135} else {136log.display(" byteValue: " + OriginalValuesClass.byteValue137+ " -> " + TargetValuesClass.byteValue);138}139140// check value of the field141if (object.charValue != TargetValuesClass.charValue) {142different++;143log.complain(" charValue = " + object.charValue + "\n"144+ " setting: " + OriginalValuesClass.charValue145+ " -> " + TargetValuesClass.charValue);146if (object.charValue == OriginalValuesClass.charValue) {147log.complain(" not changed!");148} else {149log.complain(" changed incorrectly!");150}151} else {152log.display(" charValue: " + OriginalValuesClass.charValue153+ " -> " + TargetValuesClass.charValue);154}155156// check value of the field157if (object.intValue != TargetValuesClass.intValue) {158different++;159log.complain(" intValue = " + object.intValue + "\n"160+ " setting: " + OriginalValuesClass.intValue161+ " -> " + TargetValuesClass.intValue);162if (object.intValue == OriginalValuesClass.intValue) {163log.complain(" not changed!");164} else {165log.complain(" changed incorrectly!");166}167} else {168log.display(" intValue: " + OriginalValuesClass.intValue169+ " -> " + TargetValuesClass.intValue);170}171172// check value of the field173if (object.shortValue != TargetValuesClass.shortValue) {174different++;175log.complain(" shortValue = " + object.shortValue + "\n"176+ " setting: " + OriginalValuesClass.shortValue177+ " -> " + TargetValuesClass.shortValue);178if (object.shortValue == OriginalValuesClass.shortValue) {179log.complain(" not changed!");180} else {181log.complain(" changed incorrectly!");182}183} else {184log.display(" shortValue: " + OriginalValuesClass.shortValue185+ " -> " + TargetValuesClass.shortValue);186}187188// check value of the field189if (object.longValue != TargetValuesClass.longValue) {190different++;191log.complain(" longValue = " + object.longValue + "\n"192+ " setting: " + OriginalValuesClass.longValue193+ " -> " + TargetValuesClass.longValue);194if (object.longValue == OriginalValuesClass.longValue) {195log.complain(" not changed!");196} else {197log.complain(" changed incorrectly!");198}199} else {200log.display(" longValue: " + OriginalValuesClass.longValue201+ " -> " + TargetValuesClass.longValue);202}203204// check value of the field205if (object.floatValue != TargetValuesClass.floatValue) {206different++;207log.complain(" floatValue = " + object.floatValue + "\n"208+ " setting: " + OriginalValuesClass.floatValue209+ " -> " + TargetValuesClass.floatValue);210if (object.floatValue == OriginalValuesClass.floatValue) {211log.complain(" not changed!");212} else {213log.complain(" changed incorrectly!");214}215} else {216log.display(" floatValue: " + OriginalValuesClass.floatValue217+ " -> " + TargetValuesClass.floatValue);218}219220// check value of the field221if (object.doubleValue != TargetValuesClass.doubleValue) {222different++;223log.complain(" doubleValue = " + object.doubleValue + "\n"224+ " setting: " + OriginalValuesClass.doubleValue225+ " -> " + TargetValuesClass.doubleValue);226if (object.doubleValue == OriginalValuesClass.doubleValue) {227log.complain(" not changed!");228} else {229log.complain(" changed incorrectly!");230}231} else {232log.display(" doubleValue: " + OriginalValuesClass.doubleValue233+ " -> " + TargetValuesClass.doubleValue);234}235236// check value of the field237if (object.stringValue != TargetValuesClass.stringValue) {238different++;239log.complain(" stringValue = " + object.stringValue + "\n"240+ " setting: " + OriginalValuesClass.stringValue241+ " -> " + TargetValuesClass.stringValue);242if (object.stringValue == OriginalValuesClass.stringValue) {243log.complain(" not changed!");244} else {245log.complain(" changed incorrectly!");246}247} else {248log.display(" stringValue: " + OriginalValuesClass.stringValue249+ " -> " + TargetValuesClass.stringValue);250}251252// check value of the field253if (object.objectValue != TargetValuesClass.objectValue) {254different++;255log.complain(" objectValue = " + object.objectValue + "\n"256+ " setting: " + OriginalValuesClass.objectValue257+ " -> " + TargetValuesClass.objectValue);258if (object.objectValue == OriginalValuesClass.objectValue) {259log.complain(" not changed!");260} else {261log.complain(" changed incorrectly!");262}263} else {264log.display(" objectValue: " + OriginalValuesClass.objectValue265+ " -> " + TargetValuesClass.objectValue);266}267268/*269// check value of the field270if (object.Value != TargetValuesClass.Value) {271different++;272log.complain(" Value = " + object.Value + "\n"273+ " setting: " + OriginalValuesClass.Value274+ " -> " + TargetValuesClass.Value);275if (object.Value == OriginalValuesClass.Value) {276log.complain(" not changed!");277} else {278log.complain(" changed incorrectly!");279}280} else {281log.display(" Value: " + OriginalValuesClass.Value282+ " -> " + TargetValuesClass.Value);283}284*/285286// check taht no any changed value differs from target287if (different > 0) {288log.complain("Values of " + different + " fields have not been set correctly");289return false;290}291292log.display("Values of all fields have been set correctly");293return true;294}295296// class with the original values of static fields297public static class OriginalValuesClass {298static final boolean booleanValue = true;299static final byte byteValue = (byte)0x01;300static final char charValue = 'Z';301static final int intValue = 100;302static final short shortValue = (short)10;303static final long longValue = (long)1000000;304static final float floatValue = (float)3.14;305static final double doubleValue = (double)2.8e-12;306static final String stringValue = "text";307static final Object objectValue = new OriginalValuesClass();308}309310// class with the original values of static fields311public static class TargetValuesClass {312static final boolean booleanValue = false;313static final byte byteValue = (byte)0x0F;314static final char charValue = 'A';315static final int intValue = 999;316static final short shortValue = (short)88;317static final long longValue = (long)11111111;318static final float floatValue = (float)7.19;319static final double doubleValue = (double)4.6e24;320static final String stringValue = "new text";321static final Object objectValue = new TargetValuesClass();322}323324// tested class with own static fields values325public static class TestedClass {326private boolean booleanValue = OriginalValuesClass.booleanValue;327private byte byteValue = OriginalValuesClass.byteValue;328protected char charValue = OriginalValuesClass.charValue;329protected int intValue = OriginalValuesClass.intValue;330public short shortValue = OriginalValuesClass.shortValue;331public long longValue = OriginalValuesClass.longValue;332float floatValue = OriginalValuesClass.floatValue;333double doubleValue = OriginalValuesClass.doubleValue;334String stringValue = OriginalValuesClass.stringValue;335Object objectValue = OriginalValuesClass.objectValue;336}337338// class with static field with the tested object339public static class ObjectClass {340// static field with the tested object341public static TestedClass object = null;342}343344}345346347