Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/FloatValue/equals/equals001.java
41161 views
/*1* Copyright (c) 2000, 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.FloatValue.equals;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import java.util.*;31import java.io.*;3233/**34* The test for the implementation of an object of the type <BR>35* FloatValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.FloatValue.equals()</code> <BR>39* <BR>40* The cases for testing are as follows : <BR>41* <BR>42* when a gebuggee executes the following : <BR>43* public static float plus1_1 = +1f; <BR>44* public static float plus1_2 = +1f; <BR>45* public static float minus1 = -1f; <BR>46* public static double double_plus1 = +1d; <BR>47* <BR>48* which a debugger mirros as : <BR>49* <BR>50* FloatValue fvplus1_1; <BR>51* FloatValue fvplus1_2; <BR>52* FloatValue fvminus1; <BR>53* DoubleValue dvplus1; <BR>54* <BR>55* the following is true: <BR>56* <BR>57* fvplus1_1 == fvplus1_2 <BR>58* fvplus1_1 != fvminus1 <BR>59* fvplus1_1 != dvplus1 <BR>60* <BR>61*/6263public class equals001 {6465//----------------------------------------------------- templete section66static final int PASSED = 0;67static final int FAILED = 2;68static final int PASS_BASE = 95;6970//----------------------------------------------------- templete parameters71static final String72sHeader1 = "\n==> nsk/jdi/FloatValue/equals/equals001",73sHeader2 = "--> equals001: ",74sHeader3 = "##> equals001: ";7576//----------------------------------------------------- main method7778public static void main (String argv[]) {79int result = run(argv, System.out);80System.exit(result + PASS_BASE);81}8283public static int run (String argv[], PrintStream out) {84return new equals001().runThis(argv, out);85}8687//-------------------------------------------------- log procedures8889private static boolean verbMode = false;9091private static Log logHandler;9293private static void log1(String message) {94logHandler.display(sHeader1 + message);95}96private static void log2(String message) {97logHandler.display(sHeader2 + message);98}99private static void log3(String message) {100logHandler.complain(sHeader3 + message);101}102103// ************************************************ test parameters104105private String debuggeeName =106"nsk.jdi.FloatValue.equals.equals001a";107108//====================================================== test program109110static ArgumentHandler argsHandler;111static int testExitCode = PASSED;112113//------------------------------------------------------ common section114115private int runThis (String argv[], PrintStream out) {116117Debugee debuggee;118119argsHandler = new ArgumentHandler(argv);120logHandler = new Log(out, argsHandler);121Binder binder = new Binder(argsHandler, logHandler);122123if (argsHandler.verbose()) {124debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp125} else {126debuggee = binder.bindToDebugee(debuggeeName); // *** tp127}128129IOPipe pipe = new IOPipe(debuggee);130131debuggee.redirectStderr(out);132log2("equals001a debuggee launched");133debuggee.resume();134135String line = pipe.readln();136if ((line == null) || !line.equals("ready")) {137log3("signal received is not 'ready' but: " + line);138return FAILED;139} else {140log2("'ready' recieved");141}142143VirtualMachine vm = debuggee.VM();144145//------------------------------------------------------ testing section146log1(" TESTING BEGINS");147148for (int i = 0; ; i++) {149pipe.println("newcheck");150line = pipe.readln();151152if (line.equals("checkend")) {153log2(" : returned string is 'checkend'");154break ;155} else if (!line.equals("checkready")) {156log3("ERROR: returned string is not 'checkready'");157testExitCode = FAILED;158break ;159}160161log1("new check: #" + i);162163//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part164165List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);166if (listOfDebuggeeExecClasses.size() != 1) {167testExitCode = FAILED;168log3("ERROR: listOfDebuggeeExecClasses.size() != 1");169break ;170}171ReferenceType execClass =172(ReferenceType) listOfDebuggeeExecClasses.get(0);173174Field ffplus1_1 = execClass.fieldByName("plus1_1");175Field ffplus1_2 = execClass.fieldByName("plus1_2");176Field ffminus1 = execClass.fieldByName("minus1");177Field fdplus1 = execClass.fieldByName("double_plus1");178179FloatValue fvplus1_1 = (FloatValue) execClass.getValue(ffplus1_1);180FloatValue fvplus1_2 = (FloatValue) execClass.getValue(ffplus1_2);181FloatValue fvminus1 = (FloatValue) execClass.getValue(ffminus1);182DoubleValue dvplus1 = (DoubleValue) execClass.getValue(fdplus1);183184int i2;185186for (i2 = 0; ; i2++) {187188int expresult = 0;189190log2("new check: #" + i2);191192switch (i2) {193194case 0: if (!fvplus1_1.equals(fvplus1_2))195expresult = 1;196break;197198case 1: if (fvplus1_1.equals(fvminus1))199expresult = 1;200break;201202case 2: if (fvplus1_1.equals(dvplus1))203expresult = 1;204break;205206207default: expresult = 2;208break ;209}210211if (expresult == 2) {212log2(" test cases finished");213break ;214} else if (expresult == 1) {215log3("ERROR: expresult != true; check # = " + i);216testExitCode = FAILED;217}218}219//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~220}221log1(" TESTING ENDS");222223//-------------------------------------------------- test summary section224//------------------------------------------------- standard end section225226pipe.println("quit");227log2("waiting for the debuggee to finish ...");228debuggee.waitFor();229230int status = debuggee.getStatus();231if (status != PASSED + PASS_BASE) {232log3("debuggee returned UNEXPECTED exit status: " +233status + " != PASS_BASE");234testExitCode = FAILED;235} else {236log2("debuggee returned expected exit status: " +237status + " == PASS_BASE");238}239240if (testExitCode != PASSED) {241logHandler.complain("TEST FAILED");242}243return testExitCode;244}245}246247248