Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/BooleanArgument/isValid/isvalid001.java
41161 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.BooleanArgument.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.LaunchingConnector;383940/**41* The test for the implementation of an object of the type <BR>42* Connector.BooleanArgument. <BR>43* <BR>44* The test checks up that results of the method <BR>45* <code>com.sun.jdi.connect.Connector.BooleanArgument.isValid()</code> <BR>46* complies with its specification, that is, returns <BR>47* true for the String values "true" and "false", and <BR>48* false for another String value which, however, is not null, and <BR>49* for the empty 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 isvalid001 {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.BooleanArgument.isValid\n" ;74//75String sErr2 = "ERROR\n" +76"Method tested: " +77"jdi.Connector.BooleanArgument.isValue()\n" ;7879VirtualMachineManager vmm = Bootstrap.virtualMachineManager();8081List connectorsList = vmm.allConnectors();82Iterator connectorsListIterator = connectorsList.iterator();83//84Connector.BooleanArgument argument = 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 {101//102argument = (Connector.BooleanArgument)103defaultArguments.get(argName);104break ;105} catch ( ClassCastException e) {106}107} catch ( NoSuchElementException e) {108break ;109}110}111if (argument != null) {112break ;113}114} catch ( NoSuchElementException e) {115out.println(sErr1 +116"no Connecter with needed Argument found\n");117return exitCode0;118}119}120121if (!argument.isValid("true")) {122exitCode = exitCode2;123out.println(sErr2 +124"check: isValid('true')\n" +125"error: returned value != true\n");126}127128if (!argument.isValid("false")) {129exitCode = exitCode2;130out.println(sErr2 +131"check: isValid('false')\n" +132"error: returned value != true\n");133}134135if (argument.isValid("fals")) {136exitCode = exitCode2;137out.println(sErr2 +138"check: isValid('fals')\n" +139"error: returned value == true\n");140}141142if (argument.isValid("")) {143exitCode = exitCode2;144out.println(sErr2 +145"check: isValid(<empty_string>)\n" +146"error: returned value == true\n");147}148149if (exitCode != exitCode0)150out.println("TEST FAILED");151152return exitCode;153}154}155156157