Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Argument/isValid/isvalid001.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 BooleanArgument . <BR>49* <BR>50* In case of a wrong boolean value returned, <BR>51* the test produces the return value 97 and <BR>52* a corresponding error message. <BR>53* Otherwise, the test is passed and produces <BR>54* the return value 95 and no message. <BR>55*/565758public class isvalid001 {5960public static void main(String argv[]) {61System.exit(run(argv, System.out) + 95); // JCK-compatible exit status62}6364public static int run(String argv[], PrintStream out) {6566int exitCode = 0;67int exitCode0 = 0;68int exitCode2 = 2;69//70String sErr1 = "WARNING\n" +71"Method tested: " +72"jdi.Connector.Argument.isValid\n" ;73//74String sErr2 = "ERROR\n" +75"Method tested: " +76"jdi.Connector.Argument.isValid\n" ;7778VirtualMachineManager vmm = Bootstrap.virtualMachineManager();7980List connectorsList = vmm.allConnectors();81Iterator connectorsListIterator = connectorsList.iterator();82//83Connector.Argument argument = null;84Connector.BooleanArgument booleanArg = null;8586for ( ; ; ) {87try {88Connector connector =89(Connector) connectorsListIterator.next();9091Map defaultArguments = connector.defaultArguments();92Set keyset = defaultArguments.keySet();93int keysetSize = defaultArguments.size();94Iterator keysetIterator = keyset.iterator();9596for ( ; ; ) {97try {98String argName = (String) keysetIterator.next();99100try {101argument = (Connector.Argument)102defaultArguments.get(argName);103try {104booleanArg = (Connector.BooleanArgument)105defaultArguments.get(argName);106break ;107} catch ( ClassCastException e) {108}109} catch ( ClassCastException e) {110}111} catch ( NoSuchElementException e) {112break ;113}114}115if (booleanArg != null) {116break ;117}118} catch ( NoSuchElementException e) {119out.println(sErr1 +120"no Connector with BooleanArgument found\n");121return exitCode0;122}123}124125if (!argument.isValid("true")) {126exitCode = exitCode2;127out.println(sErr2 +128"check: isValid('true')\n" +129"error: returned value != true\n");130}131132if (!argument.isValid("false")) {133exitCode = exitCode2;134out.println(sErr2 +135"check: isValid('false')\n" +136"error: returned value != true\n");137}138139if (argument.isValid("fals")) {140exitCode = exitCode2;141out.println(sErr2 +142"check: isValid('fals')\n" +143"error: returned value == true\n");144}145146if (argument.isValid("")) {147exitCode = exitCode2;148out.println(sErr2 +149"check: isValid(<empty_string>)\n" +150"error: returned value == true\n");151}152153154if (exitCode != exitCode0)155out.println("TEST FAILED");156157return exitCode;158}159}160161162