Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Argument/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.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, that is, <BR>47* "Returns: true if the value is valid to be used in setValue(String)" <BR>48* in case when Argument implements StringArgument <BR>49* and its parameter is a null-string. <BR>50* <BR>51* In case of a wrong boolean value 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*/575859public class isvalid003 {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.StringArgument stringArg = 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 {102argument = (Connector.Argument)103defaultArguments.get(argName);104//105try {106stringArg = (Connector.StringArgument)107defaultArguments.get(argName);108break ;109} catch ( ClassCastException e) {110}111} catch ( ClassCastException e) {112}113} catch ( NoSuchElementException e) {114break ;115}116}117//118if (stringArg != null) {119break ;120}121} catch ( NoSuchElementException e) {122out.println(sErr1 +123"no Connector with StringArgument found\n");124return exitCode0;125}126}127128String sNull = null;129try {130if (!argument.isValid(sNull)) {131exitCode = exitCode2;132out.println(sErr2 +133"check: isValid(sNull)\n" +134//135"error: returned value != true\n");136}137} catch ( NullPointerException e ) {138exitCode = exitCode2;139out.println(sErr2 +140"check: isValid(sNull)\n" +141"error: NullPointerException\n");142}143144if (exitCode != exitCode0)145out.println("TEST FAILED");146147return exitCode;148}149}150151152