Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanValue/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.BooleanValue.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* BooleanValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.BooleanValue.equals()</code> <BR>39* complies with its spec. <BR>40* The cases for testing are as follows : <BR>41* <BR>42* when a gebuggee executes the following : <BR>43* public static boolean bTrue1 = true; <BR>44* public static boolean bTrue2 = true; <BR>45* public static boolean bFalse1 = false; <BR>46* public static boolean bFalse2 = false; <BR>47* <BR>48* which a debugger mirros as : <BR>49* <BR>50* BooleanValue bvTrue1; <BR>51* BooleanValue bvTrue2; <BR>52* BooleanValue bvFalse1; <BR>53* BooleanValue bvFalse2; <BR>54* <BR>55* the following is true: <BR>56* <BR>57* bvTrue1.equals(bvTrue2) <BR>58* !bvTrue1.equals(bvFalse1) <BR>59* bvFalse1.equals(bvFalse2) <BR>60* !bvFalse1.equals(bvTrue1) <BR>61* <BR>62* !bvTrue1.equals(IntegerValue i0) <BR>63* !bvFalse1.equals(IntegerValue i1) <BR>64* <BR>65*/6667public class equals001 {6869//----------------------------------------------------- templete section70static final int PASSED = 0;71static final int FAILED = 2;72static final int PASS_BASE = 95;7374//----------------------------------------------------- templete parameters75static final String76sHeader1 = "\n==> nsk/jdi/BooleanValue/equals/equals001",77sHeader2 = "--> equals001: ",78sHeader3 = "##> equals001: ";7980//----------------------------------------------------- main method8182public static void main (String argv[]) {83int result = run(argv, System.out);84System.exit(result + PASS_BASE);85}8687public static int run (String argv[], PrintStream out) {88return new equals001().runThis(argv, out);89}9091//-------------------------------------------------- log procedures9293private static boolean verbMode = false;9495private static Log logHandler;9697private static void log1(String message) {98logHandler.display(sHeader1 + message);99}100private static void log2(String message) {101logHandler.display(sHeader2 + message);102}103private static void log3(String message) {104logHandler.complain(sHeader3 + message);105}106107// ************************************************ test parameters108109private String debuggeeName =110"nsk.jdi.BooleanValue.equals.equals001a";111112//====================================================== test program113114static ArgumentHandler argsHandler;115static int testExitCode = PASSED;116117//------------------------------------------------------ common section118119private int runThis (String argv[], PrintStream out) {120121Debugee debugee;122123argsHandler = new ArgumentHandler(argv);124logHandler = new Log(out, argsHandler);125Binder binder = new Binder(argsHandler, logHandler);126127if (argsHandler.verbose()) {128debugee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp129} else {130debugee = binder.bindToDebugee(debuggeeName); // *** tp131}132133IOPipe pipe = new IOPipe(debugee);134135debugee.redirectStderr(out);136log2("equals001a debugee launched");137debugee.resume();138139String line = pipe.readln();140if ((line == null) || !line.equals("ready")) {141log3("signal received is not 'ready' but: " + line);142return FAILED;143} else {144log2("'ready' recieved");145}146147VirtualMachine vm = debugee.VM();148149//------------------------------------------------------ testing section150log1(" TESTING BEGINS");151152for (int i = 0; ; i++) {153pipe.println("newcheck");154line = pipe.readln();155156if (line.equals("checkend")) {157log2(" : returned string is 'checkend'");158break ;159} else if (!line.equals("checkready")) {160log3("ERROR: returned string is not 'checkready'");161testExitCode = FAILED;162break ;163}164165log1("new check: #" + i);166167//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part168169List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);170if (listOfDebuggeeExecClasses.size() != 1) {171testExitCode = FAILED;172log3("ERROR: listOfDebuggeeExecClasses.size() != 1");173break ;174}175ReferenceType execClass =176(ReferenceType) listOfDebuggeeExecClasses.get(0);177178Field fTrue1 = execClass.fieldByName("bTrue1");179Field fTrue2 = execClass.fieldByName("bTrue2");180Field fFalse1 = execClass.fieldByName("bFalse1");181Field fFalse2 = execClass.fieldByName("bFalse2");182183BooleanValue bvTrue1 = (BooleanValue) execClass.getValue(fTrue1);184BooleanValue bvTrue2 = (BooleanValue) execClass.getValue(fTrue2);185BooleanValue bvFalse1 = (BooleanValue) execClass.getValue(fFalse1);186BooleanValue bvFalse2 = (BooleanValue) execClass.getValue(fFalse2);187188int i2;189190for (i2 = 0; ; i2++) {191192int expresult = 0;193194log2("new check: #" + i2);195196switch (i2) {197198case 0: if (!bvTrue1.equals(bvTrue2))199expresult = 1;200break;201202case 1: if (bvTrue1.equals(bvFalse1))203expresult = 1;204break;205206case 2: if (!bvFalse1.equals(bvFalse2))207expresult = 1;208break;209210case 3: if (bvFalse1.equals(bvTrue1))211expresult = 1;212break;213214case 4: IntegerValue i0 = vm.mirrorOf(0);215if (bvTrue1.equals(i0))216expresult = 1;217break;218219case 5: IntegerValue i1 = vm.mirrorOf(1);220if (bvFalse1.equals(i1))221expresult = 1;222break;223224225default: expresult = 2;226break ;227}228229if (expresult == 2) {230log2(" test cases finished");231break ;232} else if (expresult == 1) {233log3("ERROR: expresult != 1; check # = " + i2);234testExitCode = FAILED;235}236}237//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~238}239log1(" TESTING ENDS");240241//-------------------------------------------------- test summary section242243//------------------------------------------------- standard end section244245pipe.println("quit");246log2("waiting for the debugee finish ...");247debugee.waitFor();248249int status = debugee.getStatus();250if (status != PASSED + PASS_BASE) {251log3("debugee returned UNEXPECTED exit status: " +252status + " != PASS_BASE");253testExitCode = FAILED;254} else {255log2("debugee returned expected exit status: " +256status + " == PASS_BASE");257}258259if (testExitCode != PASSED) {260logHandler.complain("TEST FAILED");261}262return testExitCode;263}264}265266267