Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanValue/value/value001.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.value;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.value()</code> <BR>39* complies with its spec. <BR>40* <BR>41* The cases for testing are as follows : <BR>42* <BR>43* when a gebuggee executes the following : <BR>44* public static boolean bTrue1 = true; <BR>45* public static boolean bFalse1 = false; <BR>46* <BR>47* which a debugger mirros as : <BR>48* <BR>49* BooleanValue bvTrue1; <BR>50* BooleanValue bvFalse1; <BR>51* <BR>52* the following is true: <BR>53* <BR>54* BooleanValue bvTrue.value() == true <BR>55* BooleanValue bvFalse.value() == false <BR>56* <BR>57*/5859public class value001 {6061//----------------------------------------------------- templete section62static final int PASSED = 0;63static final int FAILED = 2;64static final int PASS_BASE = 95;6566//----------------------------------------------------- templete parameters67static final String68sHeader1 = "\n==> nsk/jdi/BooleanValue/value/value001",69sHeader2 = "--> value001: ",70sHeader3 = "##> value001: ";7172//----------------------------------------------------- main method7374public static void main (String argv[]) {75int result = run(argv, System.out);76System.exit(result + PASS_BASE);77}7879public static int run (String argv[], PrintStream out) {80return new value001().runThis(argv, out);81}8283//-------------------------------------------------- log procedures8485private static boolean verbMode = false;8687private static Log logHandler;8889private static void log1(String message) {90logHandler.display(sHeader1 + message);91}92private static void log2(String message) {93logHandler.display(sHeader2 + message);94}95private static void log3(String message) {96logHandler.complain(sHeader3 + message);97}9899// ************************************************ test parameters100101private String debuggeeName =102"nsk.jdi.BooleanValue.value.value001a";103104//====================================================== test program105106static ArgumentHandler argsHandler;107static int testExitCode = PASSED;108109//------------------------------------------------------ common section110111private int runThis (String argv[], PrintStream out) {112113Debugee debugee;114115argsHandler = new ArgumentHandler(argv);116logHandler = new Log(out, argsHandler);117Binder binder = new Binder(argsHandler, logHandler);118119if (argsHandler.verbose()) {120debugee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp121} else {122debugee = binder.bindToDebugee(debuggeeName); // *** tp123}124125IOPipe pipe = new IOPipe(debugee);126127debugee.redirectStderr(out);128log2("value001a debugee launched");129debugee.resume();130131String line = pipe.readln();132if ((line == null) || !line.equals("ready")) {133log3("signal received is not 'ready' but: " + line);134return FAILED;135} else {136log2("'ready' recieved");137}138139VirtualMachine vm = debugee.VM();140141//------------------------------------------------------ testing section142log1(" TESTING BEGINS");143144for (int i = 0; ; i++) {145pipe.println("newcheck");146line = pipe.readln();147148if (line.equals("checkend")) {149log2(" : returned string is 'checkend'");150break ;151} else if (!line.equals("checkready")) {152log3("ERROR: returned string is not 'checkready'");153testExitCode = FAILED;154break ;155}156157log1("new check: #" + i);158159//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ variable part160161List listOfDebuggeeExecClasses = vm.classesByName(debuggeeName);162if (listOfDebuggeeExecClasses.size() != 1) {163testExitCode = FAILED;164log3("ERROR: listOfDebuggeeExecClasses.size() != 1");165break ;166}167ReferenceType execClass =168(ReferenceType) listOfDebuggeeExecClasses.get(0);169170Field fTrue1 = execClass.fieldByName("bTrue1");171// Field fTrue2 = execClass.fieldByName("bTrue2");172Field fFalse1 = execClass.fieldByName("bFalse1");173// Field fFalse2 = execClass.fieldByName("bFalse2");174175BooleanValue bvTrue1 = (BooleanValue) execClass.getValue(fTrue1);176// BooleanValue bvTrue2 = (BooleanValue) execClass.getValue(fTrue2);177BooleanValue bvFalse1 = (BooleanValue) execClass.getValue(fFalse1);178// BooleanValue bvFalse2 = (BooleanValue) execClass.getValue(fFalse2);179180int i2;181182for (i2 = 0; ; i2++) {183184int expresult = 0;185186log2("new check: #" + i2);187188switch (i2) {189190case 0: if (bvTrue1.value() != true)191expresult = 1;192break;193194case 1: if (bvFalse1.value() != false)195expresult = 1;196break;197198default: expresult = 2;199break ;200}201202if (expresult == 2) {203log2(" test cases finished");204break ;205} else if (expresult == 1) {206log3("ERROR: expresult != 1; check # = " + i2);207testExitCode = FAILED;208}209}210//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~211}212log1(" TESTING ENDS");213214//-------------------------------------------------- test summary section215216//------------------------------------------------- standard end section217218pipe.println("quit");219log2("waiting for the debugee finish ...");220debugee.waitFor();221222int status = debugee.getStatus();223if (status != PASSED + PASS_BASE) {224log3("debugee returned UNEXPECTED exit status: " +225status + " != PASS_BASE");226testExitCode = FAILED;227} else {228log2("debugee returned expected exit status: " +229status + " == PASS_BASE");230}231232if (testExitCode != PASSED) {233logHandler.complain("TEST FAILED");234}235return testExitCode;236}237}238239240