Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Argument/isValid/isvalid005.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 one of the following: "a", "", null, null-string. <BR> <BR>50* <BR>51* In case of a wrong result returned, <BR>52* the test produces the return value 97 and <BR>53* a corresponding error message. <BR>54* Otherwise, the test is passed and produces <BR>55* the return value 95 and no message. <BR>56*/5758//59public class isvalid005 {6061public static void main(String argv[]) {62System.exit(run(argv, System.out) + 95); // JCK-compatible exit status63}6465public static int run(String argv[], PrintStream out) {6667int exitCode = 0;68int exitCode0 = 0;69int exitCode2 = 2;70//71String sErr1 = "WARNING\n" +72"Method tested: " +73"jdi.Connector.Argument.isValid\n" ;74//75String sErr2 = "ERROR\n" +76"Method tested: " +77"jdi.Connector.Argument.isValid\n" ;7879VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8081List connectorsList = vmm.allConnectors();82Iterator connectorsListIterator = connectorsList.iterator();83//84Connector.Argument argument = null;85Connector.IntegerArgument intArgument = null;8687for ( ; ; ) {88try {89Connector connector =90(Connector) connectorsListIterator.next();9192Map defaultArguments = connector.defaultArguments();93Set keyset = defaultArguments.keySet();94int keysetSize = defaultArguments.size();95Iterator keysetIterator = keyset.iterator();9697for ( ; ; ) {98try {99String argName = (String) keysetIterator.next();100101try {102//103argument = (Connector.IntegerArgument)104defaultArguments.get(argName);105try {106intArgument = (Connector.IntegerArgument)107defaultArguments.get(argName);108break ;109} catch ( ClassCastException e) {110}111} catch ( ClassCastException e) {112}113} catch ( NoSuchElementException e) {114break ;115}116}117if (intArgument != null) {118break ;119}120} catch ( NoSuchElementException e) {121out.println(sErr1 +122//123"no Connector with IntegerArgument found\n");124return exitCode0;125}126}127128if (!argument.isValid("")) {129} else {130exitCode = exitCode2;131out.println(sErr2 +132"check: super.isValid('')\n" +133"result: true\n");134}135136if (!argument.isValid("a")) {137} else {138exitCode = exitCode2;139out.println(sErr2 +140"check: super.isValid('a')\n" +141"result: true\n");142}143144if (!argument.isValid((String) null)) {145} else {146exitCode = exitCode2;147out.println(sErr2 +148"check: super.isValid((String) null))\n" +149"result: true\n");150}151152String s = null;153if (!argument.isValid(s)) {154} else {155exitCode = exitCode2;156out.println(sErr2 +157"check: super.isValid(String s = null)\n" +158"result: true\n");159}160161162if (exitCode != exitCode0) {163out.println("TEST FAILED");164}165return exitCode;166}167}168169170