Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/CharValue/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.CharValue.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* CharValue. <BR>36* <BR>37* The test checks up that results of the method <BR>38* <code>com.sun.jdi.CharValue.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 char smallest = Character.MIN_VALUE; <BR>45* public static char largest = Character.MAX_VALUE; <BR>46* <BR>47* which a debugger mirros as : <BR>48* <BR>49* CharValue cvchar_smallest; <BR>50* CharValue cvchar_largest; <BR>51* <BR>52* the following is true: <BR>53* <BR>54* cvchar_smallest.value() == Character.MIN_VALUE <BR>55* cvchar_largest.value() == Character.MAX_VALUE <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/CharValue/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.CharValue.value.value001a";103104//====================================================== test program105106static ArgumentHandler argsHandler;107static int testExitCode = PASSED;108109//------------------------------------------------------ common section110111private int runThis (String argv[], PrintStream out) {112113Debugee debuggee;114115argsHandler = new ArgumentHandler(argv);116logHandler = new Log(out, argsHandler);117Binder binder = new Binder(argsHandler, logHandler);118119if (argsHandler.verbose()) {120debuggee = binder.bindToDebugee(debuggeeName + " -vbs"); // *** tp121} else {122debuggee = binder.bindToDebugee(debuggeeName); // *** tp123}124125IOPipe pipe = new IOPipe(debuggee);126127debuggee.redirectStderr(out);128log2("value001a debuggee launched");129debuggee.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 = debuggee.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 fcchar_smallest = execClass.fieldByName("smallest");171Field fcchar_largest = execClass.fieldByName("largest");172173CharValue cvchar_smallest =174(CharValue) execClass.getValue(fcchar_smallest);175CharValue cvchar_largest =176(CharValue) execClass.getValue(fcchar_largest);177178int i2;179180for (i2 = 0; ; i2++) {181182int expresult = 0;183184log2("new check: #" + i2);185186switch (i2) {187188case 0: if (cvchar_smallest.value() != Character.MIN_VALUE)189expresult = 1;190break;191192case 1: if (cvchar_largest.value() != Character.MAX_VALUE)193expresult = 1;194break;195196197default: expresult = 2;198break ;199}200201if (expresult == 2) {202log2(" test cases finished");203break ;204} else if (expresult == 1) {205log3("ERROR: expresult != true; check # = " + i);206testExitCode = FAILED;207}208}209//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~210}211log1(" TESTING ENDS");212213//-------------------------------------------------- test summary section214//------------------------------------------------- standard end section215216pipe.println("quit");217log2("waiting for the debuggee finish ...");218debuggee.waitFor();219220int status = debuggee.getStatus();221if (status != PASSED + PASS_BASE) {222log3("debuggee returned UNEXPECTED exit status: " +223status + " != PASS_BASE");224testExitCode = FAILED;225} else {226log2("debuggee returned expected exit status: " +227status + " == PASS_BASE");228}229230if (testExitCode != PASSED) {231logHandler.complain("TEST FAILED");232}233return testExitCode;234}235}236237238