Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Argument/isValid/isvalid002.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.Argument;38import com.sun.jdi.connect.Connector.BooleanArgument;3940/**41* The test for the implementation of an object of the type <BR>42* Connector.Argument. <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. <BR>47* The case for testing includes throwing NullPointerException <BR>48* if a parameter is a null-string. <BR>49* <BR>50*/515253public class isvalid002 {5455public static void main(String argv[]) {56System.exit(run(argv, System.out) + 95); // JCK-compatible exit status57}5859public static int run(String argv[], PrintStream out) {6061int exitCode = 0;62int exitCode0 = 0;63int exitCode2 = 2;64//65String sErr1 = "WARNING\n" +66"Method tested: " +67"jdi.Connector.Argument.isValid\n" ;68//69String sErr2 = "ERROR\n" +70"Method tested: " +71"jdi.Connector.Argument.isValid\n" ;7273VirtualMachineManager vmm = Bootstrap.virtualMachineManager();7475List connectorsList = vmm.allConnectors();76Iterator connectorsListIterator = connectorsList.iterator();77//78Connector.Argument argument = null;79Connector.BooleanArgument booleanArg = null;8081for ( ; ; ) {82try {83Connector connector =84(Connector) connectorsListIterator.next();8586Map defaultArguments = connector.defaultArguments();87Set keyset = defaultArguments.keySet();88int keysetSize = defaultArguments.size();89Iterator keysetIterator = keyset.iterator();9091for ( ; ; ) {92try {93String argName = (String) keysetIterator.next();9495try {96argument = (Connector.Argument)97defaultArguments.get(argName);98try {99booleanArg = (Connector.BooleanArgument)100defaultArguments.get(argName);101break ;102} catch ( ClassCastException e) {103}104} catch ( ClassCastException e) {105}106} catch ( NoSuchElementException e) {107break ;108}109}110if (booleanArg != null) {111break ;112}113} catch ( NoSuchElementException e) {114out.println(sErr1 +115"no Connector with BooleanArgument found\n");116return exitCode0;117}118}119120String sNull = null;121try {122argument.isValid(sNull);123exitCode = exitCode2;124out.println(sErr2 +125"check: isValid(sNull)\n" +126"ERROR: no NullPointerException thrown");127} catch ( NullPointerException e ) {128}129130if (exitCode != exitCode0)131out.println("TEST FAILED");132133return exitCode;134}135}136137138