Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Argument/isValid/isvalid004.java
41160 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.Argument.isValid;2425import java.io.PrintStream;26import java.io.Serializable;2728import java.util.Map;29import java.util.Set;30import java.util.List;31import java.util.Iterator;32import java.util.NoSuchElementException;3334import com.sun.jdi.VirtualMachineManager;35import com.sun.jdi.Bootstrap;36import com.sun.jdi.connect.Connector;37import com.sun.jdi.connect.Connector.IntegerArgument;383940/**41* The test for the implementation of an object of the type <BR>42* Connector_IntegerArgument. <BR>43* <BR>44* The test checks up that results of the method <BR>45* <code>com.sun.jdi.connect.Connector.Argument.isValid()</code> <BR>46* complies with its specification, that is, <BR>47* "Returns: true if the value is valid to be used in setValue(String)" <BR>48* in case when Argument implements IntegerArgument <BR>49* and its parameter is a string representing one of min(), max(), <BR>50* min()-1, min()+1, max()+1. <BR>51* <BR>52* In case of a wrong result returned, <BR>53* the test produces the return value 97 and <BR>54* a corresponding error message. <BR>55* Otherwise, the test is passed and produces <BR>56* the return value 95 and no message. <BR>57*/5859//60public class isvalid004 {6162public static void main(String argv[]) {63System.exit(run(argv, System.out) + 95); // JCK-compatible exit status64}6566public static int run(String argv[], PrintStream out) {6768int exitCode = 0;69int exitCode0 = 0;70int exitCode2 = 2;71//72String sErr1 = "WARNING\n" +73"Method tested: " +74"jdi.Connector.Argument.isValid\n" ;75//76String sErr2 = "ERROR\n" +77"Method tested: " +78"jdi.Connector.Argument.isValid\n" ;7980VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8182List connectorsList = vmm.allConnectors();83Iterator connectorsListIterator = connectorsList.iterator();84//85Connector.Argument argument = null;86Connector.IntegerArgument intArgument = null;8788for ( ; ; ) {89try {90Connector connector =91(Connector) connectorsListIterator.next();9293Map defaultArguments = connector.defaultArguments();94Set keyset = defaultArguments.keySet();95int keysetSize = defaultArguments.size();96Iterator keysetIterator = keyset.iterator();9798for ( ; ; ) {99try {100String argName = (String) keysetIterator.next();101102try {103//104argument = (Connector.IntegerArgument)105defaultArguments.get(argName);106try {107intArgument = (Connector.IntegerArgument)108defaultArguments.get(argName);109break ;110} catch ( ClassCastException e) {111}112} catch ( ClassCastException e) {113}114} catch ( NoSuchElementException e) {115break ;116}117}118if (intArgument != null) {119break ;120}121} catch ( NoSuchElementException e) {122out.println(sErr1 +123//124"no Connector with IntegerArgument found\n");125return exitCode0;126}127}128129Integer intI = null;130131if (argument.isValid(intArgument.stringValueOf(intArgument.min()))) {132} else {133exitCode = exitCode2;134out.println(sErr2 +135"check: super.isValid(stringValueOf(min()))\n" +136"result: false\n");137}138139if (argument.isValid(intArgument.stringValueOf(intArgument.max()))) {140} else {141exitCode = exitCode2;142out.println(sErr2 +143"check: super.isValid(stringValueOf(max()))\n" +144"result: false\n");145}146147if (intArgument.min() < intArgument.max()) {148if (argument.isValid(149intArgument.stringValueOf(intArgument.min() + 1))) {150} else {151exitCode = exitCode2;152out.println(sErr2 +153"check: super.isValid(stringValueOf(min()+1))\n" +154"result: false\n");155}156}157158if (intArgument.min() > intI.MIN_VALUE) {159if (!argument.isValid(160intArgument.stringValueOf(intArgument.min() - 1))) {161} else {162exitCode = exitCode2;163out.println(sErr2 +164"check: super.isValid(stringValueOf(min()-1))\n" +165"result: true\n");166}167}168169if (intArgument.max() < intI.MAX_VALUE) {170if (!argument.isValid(171intArgument.stringValueOf(intArgument.max() + 1))) {172} else {173exitCode = exitCode2;174out.println(sErr2 +175"check: super.isValid(stringValueOf(max()+1))\n" +176"result: true\n");177}178}179180181if (exitCode != exitCode0) {182out.println("TEST FAILED");183}184return exitCode;185}186}187188189