Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/IntegerArgument/isValid/isvalid003.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.IntegerArgument.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>Connector.IntegerArgument.isValid(String value)</code> <BR>46* complies with the following requirements: <BR>47* "true if value represents an int that is <BR>48* min() <= value <= max()" <BR>49* when the value is one of the following strings: <BR>50* "a" <BR>51* "" <BR>52* (String) null <BR>53* a null-string <BR>54* to which expected results are false. <BR>55* <BR>56* In case of a wrong result returned, <BR>57* the test produces the return value 97 and <BR>58* a corresponding error message. <BR>59* Otherwise, the test is passed and produces <BR>60* the return value 95 and no message. <BR>61*/6263//64public class isvalid003 {6566public static void main(String argv[]) {67System.exit(run(argv, System.out) + 95); // JCK-compatible exit status68}6970public static int run(String argv[], PrintStream out) {7172int exitCode = 0;73int exitCode0 = 0;74int exitCode2 = 2;75//76String sErr1 = "WARNING\n" +77"Method tested: " +78"jdi.Connector.IntegerArgument.isValid\n" ;79//80String sErr2 = "ERROR\n" +81"Method tested: " +82"jdi.Connector.IntegerArgument.isValid\n" ;8384VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8586List connectorsList = vmm.allConnectors();87Iterator connectorsListIterator = connectorsList.iterator();88//89Connector.IntegerArgument intArgument = null;9091for ( ; ; ) {92try {93Connector connector =94(Connector) connectorsListIterator.next();9596Map defaultArguments = connector.defaultArguments();97Set keyset = defaultArguments.keySet();98int keysetSize = defaultArguments.size();99Iterator keysetIterator = keyset.iterator();100101for ( ; ; ) {102try {103String argName = (String) keysetIterator.next();104105try {106//107intArgument = (Connector.IntegerArgument)108defaultArguments.get(argName);109break ;110} catch ( ClassCastException e) {111}112} catch ( NoSuchElementException e) {113break ;114}115}116if (intArgument != null) {117break ;118}119} catch ( NoSuchElementException e) {120out.println(sErr1 +121//122"no Connector with IntegerArgument found\n");123return exitCode0;124}125}126127if (!intArgument.isValid("")) {128} else {129exitCode = exitCode2;130out.println(sErr2 +131"check: isValid('')\n" +132"result: true\n");133}134135if (!intArgument.isValid("a")) {136} else {137exitCode = exitCode2;138out.println(sErr2 +139"check: isValid('a')\n" +140"result: true\n");141}142143if (!intArgument.isValid((String) null)) {144} else {145exitCode = exitCode2;146out.println(sErr2 +147"check: isValid((String) null))\n" +148"result: true\n");149}150151String s = null;152if (!intArgument.isValid(s)) {153} else {154exitCode = exitCode2;155out.println(sErr2 +156"check: isValid(String s = null)\n" +157"result: true\n");158}159160if (exitCode != exitCode0) {161out.println("TEST FAILED");162}163return exitCode;164}165}166167168